[Lldb-commits] [lldb] 7b47921 - [lldb] Reinvoke crashlog under lldb when run with -i from the command line

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed Jun 7 16:21:22 PDT 2023


Author: Jonas Devlieghere
Date: 2023-06-07T16:21:16-07:00
New Revision: 7b4792159cb7990f50c839713be4dbf6b31191e9

URL: https://github.com/llvm/llvm-project/commit/7b4792159cb7990f50c839713be4dbf6b31191e9
DIFF: https://github.com/llvm/llvm-project/commit/7b4792159cb7990f50c839713be4dbf6b31191e9.diff

LOG: [lldb] Reinvoke crashlog under lldb when run with -i from the command line

Run crashlog inside lldb when invoked in interactive mode from the
command line. Currently, when passing -i to crashlog from the command
line, we symbolicate in LLDB and immediately exit right after. This
pretty much defeats the purpose of interactive mode. That said, we
wouldn't want to re-implement the driver from the crashlog script.
Re-invoking the crashlog command from inside LLDB solves the issue.

rdar://97801509

Differential revision: https://reviews.llvm.org/D152319

Added: 
    

Modified: 
    lldb/examples/python/crashlog.py

Removed: 
    


################################################################################
diff  --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py
index ea197e4f13a4a..6f69ef5bff7fc 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -1271,7 +1271,7 @@ def __init__(self, debugger, internal_dict):
         pass
 
     def __call__(self, debugger, command, exe_ctx, result):
-        SymbolicateCrashLogs(debugger, shlex.split(command), result)
+        SymbolicateCrashLogs(debugger, shlex.split(command), result, True)
 
     def get_short_help(self):
         return "Symbolicate one or more darwin crash log files."
@@ -1596,7 +1596,7 @@ def CrashLogOptionParser():
     return CreateSymbolicateCrashLogOptions("crashlog", description, True)
 
 
-def SymbolicateCrashLogs(debugger, command_args, result):
+def SymbolicateCrashLogs(debugger, command_args, result, is_command):
     option_parser = CrashLogOptionParser()
 
     if not len(command_args):
@@ -1608,6 +1608,26 @@ def SymbolicateCrashLogs(debugger, command_args, result):
     except:
         return
 
+    # Interactive mode requires running the crashlog command from inside lldb.
+    if options.interactive and not is_command:
+        lldb_exec = (
+            subprocess.check_output(["/usr/bin/xcrun", "-f", "lldb"])
+            .decode("utf-8")
+            .strip()
+        )
+        sys.exit(
+            os.execv(
+                lldb_exec,
+                [
+                    lldb_exec,
+                    "-o",
+                    "command script import lldb.macosx",
+                    "-o",
+                    "crashlog {}".format(shlex.join(command_args)),
+                ],
+            )
+        )
+
     if options.version:
         print(debugger.GetVersionString())
         return
@@ -1659,7 +1679,7 @@ def should_run_in_interactive_mode(options, ci):
     # Create a new debugger instance
     debugger = lldb.SBDebugger.Create()
     result = lldb.SBCommandReturnObject()
-    SymbolicateCrashLogs(debugger, sys.argv[1:], result)
+    SymbolicateCrashLogs(debugger, sys.argv[1:], result, False)
     lldb.SBDebugger.Destroy(debugger)
 
 


        


More information about the lldb-commits mailing list