mgorny created this revision.
mgorny added reviewers: labath, emaste, krytarowski, espindola.
Herald added subscribers: dexonsmith, hiraditya, arichardson.
Herald added a project: LLVM.
mgorny requested review of this revision.

When LLDB Python bindings are used and stack backtraces are enabled
for logging, getMainExecutable() is called with argv0 being null.
This caused the fallback function getprogpath() (used on FreeBSD, NetBSD
and Linux) to segfault.  Make it handle null executable name gracefully.


https://reviews.llvm.org/D91012

Files:
  lldb/test/API/commands/log/basic/TestLogging.py
  llvm/lib/Support/Unix/Path.inc


Index: llvm/lib/Support/Unix/Path.inc
===================================================================
--- llvm/lib/Support/Unix/Path.inc
+++ llvm/lib/Support/Unix/Path.inc
@@ -147,6 +147,9 @@
 static char *
 getprogpath(char ret[PATH_MAX], const char *bin)
 {
+  if (bin == nullptr)
+    return nullptr;
+
   /* First approach: absolute path. */
   if (bin[0] == '/') {
     if (test_dir(ret, "/", bin) == 0)
Index: lldb/test/API/commands/log/basic/TestLogging.py
===================================================================
--- lldb/test/API/commands/log/basic/TestLogging.py
+++ lldb/test/API/commands/log/basic/TestLogging.py
@@ -93,8 +93,6 @@
 
     # Enable all log options and check that nothing crashes.
     @skipIfWindows
-    # TODO: figure out why it segfaults
-    @skipIfFreeBSD
     def test_all_log_options(self):
         if (os.path.exists(self.log_file)):
             os.remove(self.log_file)


Index: llvm/lib/Support/Unix/Path.inc
===================================================================
--- llvm/lib/Support/Unix/Path.inc
+++ llvm/lib/Support/Unix/Path.inc
@@ -147,6 +147,9 @@
 static char *
 getprogpath(char ret[PATH_MAX], const char *bin)
 {
+  if (bin == nullptr)
+    return nullptr;
+
   /* First approach: absolute path. */
   if (bin[0] == '/') {
     if (test_dir(ret, "/", bin) == 0)
Index: lldb/test/API/commands/log/basic/TestLogging.py
===================================================================
--- lldb/test/API/commands/log/basic/TestLogging.py
+++ lldb/test/API/commands/log/basic/TestLogging.py
@@ -93,8 +93,6 @@
 
     # Enable all log options and check that nothing crashes.
     @skipIfWindows
-    # TODO: figure out why it segfaults
-    @skipIfFreeBSD
     def test_all_log_options(self):
         if (os.path.exists(self.log_file)):
             os.remove(self.log_file)
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to