[Lldb-commits] [lldb] 73b2d67 - [lldb][FreeBSD] Fix crash when execve fails with asserts enabled

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 8 09:15:18 PST 2024


Author: David Spickett
Date: 2024-03-08T17:15:11Z
New Revision: 73b2d672c1c8318cd16a02812c39ae3997b9dbcd

URL: https://github.com/llvm/llvm-project/commit/73b2d672c1c8318cd16a02812c39ae3997b9dbcd
DIFF: https://github.com/llvm/llvm-project/commit/73b2d672c1c8318cd16a02812c39ae3997b9dbcd.diff

LOG: [lldb][FreeBSD] Fix crash when execve fails with asserts enabled

535da10842c7309e9eeaf9828cf6bb034fecaf16 introduced a check, when execve fails,
to see if we are allowed to trace programs at all.

Unfortunately because we like to call Status vars "error" and "status"
in various combinations, one got misnamed. This lead to lldb-server trying
to make an error value out of a success value when you did the following:

```
$ ./bin/lldb-server gdbserver 127.0.0.1:1234 -- is_not_a_file
Assertion failed: (Err && "Cannot create Expected<T> from Error success value."), function Expected...
```

This happened because the execve fails, but the check whether we can
trace says yes we can trace, but then we use the Status from the check
to create the return value. That Status is in fact a success value not
the failed Status we got from the execve attempt.

With the name corrected you now get:
```
$ ./bin/lldb-server gdbserver 127.0.0.1:1234 -- is_not_a_file
error: failed to launch 'is_not_a_file': execve failed: No such file or directory
```

Which is what we expect to see. This also fixes the test `TestGDBRemoteLaunch.py`
when asserts are enabled.

Added: 
    

Modified: 
    lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
index 9c620e4807e344..064bddd3705205 100644
--- a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
@@ -76,9 +76,9 @@ NativeProcessFreeBSD::Manager::Launch(ProcessLaunchInfo &launch_info,
                     .GetProcessId();
   LLDB_LOG(log, "pid = {0:x}", pid);
   if (status.Fail()) {
-    auto error = CanTrace();
     LLDB_LOG(log, "failed to launch process: {0}", status);
-    if (status.Fail())
+    auto error = CanTrace();
+    if (error.Fail())
       return error.ToError();
     return status.ToError();
   }


        


More information about the lldb-commits mailing list