[Lldb-commits] [lldb] r366985 - LLGS: fix tracking execve on linux

Hans Wennborg via lldb-commits lldb-commits at lists.llvm.org
Fri Jul 26 09:36:13 PDT 2019


Merged to release_90 in r367128.

On Wed, Jul 24, 2019 at 11:37 PM Pavel Labath via lldb-commits
<lldb-commits at lists.llvm.org> wrote:
>
> Author: labath
> Date: Wed Jul 24 23:38:33 2019
> New Revision: 366985
>
> URL: http://llvm.org/viewvc/llvm-project?rev=366985&view=rev
> Log:
> 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
>
> Modified:
>     lldb/trunk/packages/Python/lldbsuite/test/functionalities/exec/TestExec.py
>     lldb/trunk/packages/Python/lldbsuite/test/functionalities/exec/main.cpp
>     lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
>
> Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/exec/TestExec.py
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/exec/TestExec.py?rev=366985&r1=366984&r2=366985&view=diff
> ==============================================================================
> --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/exec/TestExec.py (original)
> +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/exec/TestExec.py Wed Jul 24 23:38:33 2019
> @@ -18,17 +18,17 @@ class ExecTestCase(TestBase):
>
>      mydir = TestBase.compute_mydir(__file__)
>
> -    @skipUnlessDarwin
>      @expectedFailureAll(archs=['i386'], bugnumber="rdar://28656532")
>      @expectedFailureAll(oslist=["ios", "tvos", "watchos", "bridgeos"], bugnumber="rdar://problem/34559552") # this exec test has problems on ios systems
>      @skipIfSanitized # rdar://problem/43756823
> +    @skipIfWindows
>      def test_hitting_exec (self):
>          self.do_test(False)
>
> -    @skipUnlessDarwin
>      @expectedFailureAll(archs=['i386'], bugnumber="rdar://28656532")
>      @expectedFailureAll(oslist=["ios", "tvos", "watchos", "bridgeos"], bugnumber="rdar://problem/34559552") # this exec test has problems on ios systems
>      @skipIfSanitized # rdar://problem/43756823
> +    @skipIfWindows
>      def test_skipping_exec (self):
>          self.do_test(True)
>
>
> Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/exec/main.cpp
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/exec/main.cpp?rev=366985&r1=366984&r2=366985&view=diff
> ==============================================================================
> --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/exec/main.cpp (original)
> +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/exec/main.cpp Wed Jul 24 23:38:33 2019
> @@ -1,76 +1,16 @@
> -#include <errno.h>
> -#include <mach/mach.h>
> -#include <signal.h>
> -#include <stdio.h>
> -#include <stdint.h>
> -#include <stdlib.h>
> -#include <spawn.h>
> -#include <unistd.h>
> +#include <cstdio>
> +#include <cstdlib>
> +#include <cstring>
>  #include <libgen.h>
>  #include <string>
> +#include <unistd.h>
>
> -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));
> -
> -    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;
> +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();
>  }
>
> Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp?rev=366985&r1=366984&r2=366985&view=diff
> ==============================================================================
> --- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original)
> +++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Wed Jul 24 23:38:33 2019
> @@ -599,12 +599,9 @@ void NativeProcessLinux::MonitorSIGTRAP(
>      // which only copies the main thread.
>      LLDB_LOG(log, "exec received, stop tracking all but main thread");
>
> -    for (auto i = m_threads.begin(); i != m_threads.end();) {
> -      if ((*i)->GetID() == GetID())
> -        i = m_threads.erase(i);
> -      else
> -        ++i;
> -    }
> +    llvm::erase_if(m_threads, [&](std::unique_ptr<NativeThreadProtocol> &t) {
> +      return t->GetID() != GetID();
> +    });
>      assert(m_threads.size() == 1);
>      auto *main_thread = static_cast<NativeThreadLinux *>(m_threads[0].get());
>
>
>
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


More information about the lldb-commits mailing list