From ee74c9e5fdd8c8bcd08d219ed6132713323113a6 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Thu, 25 Jul 2019 06:38:33 +0000 Subject: 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 --- .../lldbsuite/test/functionalities/exec/main.cpp | 82 +++------------------- 1 file changed, 11 insertions(+), 71 deletions(-) (limited to 'lldb/packages/Python/lldbsuite/test/functionalities/exec/main.cpp') diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/exec/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/exec/main.cpp index 92206b2d88e..4475bbe4452 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/exec/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/functionalities/exec/main.cpp @@ -1,76 +1,16 @@ -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include #include #include +#include -static void -exit_with_errno (int err, const char *prefix) -{ - if (err) - { - fprintf (stderr, - "%s%s", - prefix ? prefix : "", - strerror(err)); - exit (err); - } -} - -static pid_t -spawn_process (const char *progname, - const char **argv, - const char **envp, - int &err) -{ - pid_t pid = 0; - - const posix_spawn_file_actions_t *file_actions = NULL; - posix_spawnattr_t attr; - err = posix_spawnattr_init (&attr); - if (err) - return pid; - - short flags = POSIX_SPAWN_SETEXEC | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK; - err = posix_spawnattr_setflags (&attr, flags); - if (err == 0) - { - // Use the default signal masks - sigset_t no_signals; - sigset_t all_signals; - sigemptyset (&no_signals); - sigfillset (&all_signals); - posix_spawnattr_setsigmask(&attr, &no_signals); - posix_spawnattr_setsigdefault(&attr, &all_signals); - - err = posix_spawn (&pid, - progname, - file_actions, - &attr, - (char * const *)argv, - (char * const *)envp); - - posix_spawnattr_destroy(&attr); - } - return pid; -} - -int -main (int argc, char const **argv) -{ - char *buf = (char*) malloc (strlen (argv[0]) + 12); - strlcpy (buf, argv[0], strlen (argv[0]) + 1); - std::string directory_name (::dirname (buf)); +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"; - int err = 0; // Set breakpoint 1 here - spawn_process (other_program.c_str(), argv, NULL, err); - if (err) - exit_with_errno (err, "posix_spawn x86_64 error"); - return 0; + std::string other_program = directory_name + "/secondprog"; + execve(other_program.c_str(), const_cast(argv), nullptr); + perror("execve"); + abort(); } -- cgit v1.2.3