[Lldb-commits] [PATCH] D121038: [lldb/crashlog] Make interactive mode display more user-friendly

Med Ismail Bennani via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 4 18:56:52 PST 2022


mib created this revision.
mib added a reviewer: JDevlieghere.
mib added a project: LLDB.
Herald added a project: All.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

This patch makes the crashlog interactive mode show the scripted process
status with the crashed scripted thread backtrace after launching it.

rdar://89634338

Signed-off-by: Med Ismail Bennani <medismail.bennani at gmail.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121038

Files:
  lldb/examples/python/crashlog.py
  lldb/test/Shell/ScriptInterpreter/Python/Crashlog/scripted_crashlog_json.test


Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/scripted_crashlog_json.test
===================================================================
--- lldb/test/Shell/ScriptInterpreter/Python/Crashlog/scripted_crashlog_json.test
+++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/scripted_crashlog_json.test
@@ -4,9 +4,17 @@
 
 # RUN: cp %S/Inputs/scripted_crashlog.ips %t.crash
 # RUN: %python %S/patch-crashlog.py --binary %t.out --crashlog %t.crash --offsets '{"main":20, "bar":9, "foo":16}' --json
-# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog -i %t.crash' -o 'process status' 2>&1 | FileCheck %s
+# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog -i %t.crash' 2>&1 | FileCheck %s
 
 # CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands
-# CHECK: Process 92190 stopped
-# CHECK: * thread #1, name = 'CrashLogScriptedThread.thread-0', stop reason = EXC_BAD_ACCESS
-# CHECK: frame #0: 0x0000000104a23f68 scripted_crashlog_json.test.tmp.out`foo at test.c:3:6 [artificial]
+# CHECK: (lldb) process status
+# CHECK-NEXT: Process 92190 stopped
+# CHECK-NEXT: * thread #1, name = 'CrashLogScriptedThread.thread-0', stop reason = EXC_BAD_ACCESS
+# CHECK-NEXT: frame #0: 0x0000000104a23f68 scripted_crashlog_json.test.tmp.out`foo at test.c:3:6 [artificial]
+
+# CHECK: (lldb) thread backtrace
+# CHECK-NEXT: * thread #1, name = 'CrashLogScriptedThread.thread-0', stop reason = EXC_BAD_ACCESS
+# CHECK-NEXT: * frame #0: 0x0000000104a23f68 scripted_crashlog_json.test.tmp.out`foo at test.c:3:6 [artificial]
+# CHECK-NEXT: frame #1: 0x0000000104a23f80 scripted_crashlog_json.test.tmp.out`bar at test.c:6:21 [artificial]
+# CHECK-NEXT: frame #2: 0x0000000104a23fa0 scripted_crashlog_json.test.tmp.out`main(argc=<no summary available>, argv=<unavailable>) at test.c:8:35 [artificial]
+# CHECK-NEXT: frame #3: 0x0000000104a6108c dyld`start(kernArgs=<no summary available>) at dyldMain.cpp:879:18 [opt] [artificial]
Index: lldb/examples/python/crashlog.py
===================================================================
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -1017,6 +1017,29 @@
     error = lldb.SBError()
     process = target.Launch(launch_info, error)
 
+    if not process or error.Fail():
+        return
+
+    res = lldb.SBCommandReturnObject()
+    exe_ctx = lldb.SBExecutionContext(process.GetSelectedThread())
+    cmd = "process status"
+    ci.HandleCommand(cmd, exe_ctx, res)
+    if not res.Succeeded():
+        result.PutCString("error: couldn't show scripted process status")
+        return
+    print(debugger.GetPrompt(), cmd, sep='')
+    print(res.GetOutput())
+
+    res = lldb.SBCommandReturnObject()
+    cmd = "thread backtrace"
+    ci.HandleCommand(cmd, exe_ctx, res)
+    if not res.Succeeded():
+        result.PutCString("error: couldn't show scripted thread backtrace")
+        return
+    print(debugger.GetPrompt(), cmd, sep='')
+    print(res.GetOutput())
+
+
 def CreateSymbolicateCrashLogOptions(
         command_name,
         description,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121038.413184.patch
Type: text/x-patch
Size: 3134 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220305/76f3e673/attachment.bin>


More information about the lldb-commits mailing list