teak-llvm/lldb/packages/Python/lldbsuite/test/functionalities/exec/main.cpp
Pavel Labath ee74c9e5fd LLGS: fix tracking execve on linux
Summary:
Due to a logic error, lldb-server ended up asserting/crashing every time
the debugged process attempted an execve(). This fixes the error, and
extends TestExec to work on other platforms too. The "extension"
consists of avoiding non-standard posix_spawn extensions and using the
classic execve() call, which should be available on any platform that
actually supports re-execing. I change the test decorator from
@skipUnlessDarwin to @skipIfWindows.

Reviewers: clayborg, jasonmolenda

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D65207

llvm-svn: 366985
2019-07-25 06:38:33 +00:00

17 lines
428 B
C++

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <libgen.h>
#include <string>
#include <unistd.h>
int main(int argc, char const **argv) {
char *buf = strdup(argv[0]); // Set breakpoint 1 here
std::string directory_name(::dirname(buf));
std::string other_program = directory_name + "/secondprog";
execve(other_program.c_str(), const_cast<char *const *>(argv), nullptr);
perror("execve");
abort();
}