[Lldb-commits] [lldb] 41c1a5f - [lldb/crashlog] Add `-s|--skip-status` option to interactive mode

Med Ismail Bennani via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 9 21:02:09 PDT 2022


Author: Med Ismail Bennani
Date: 2022-08-09T21:01:37-07:00
New Revision: 41c1a5f9bdc4cb6914e7971f50e4f45aeb11e087

URL: https://github.com/llvm/llvm-project/commit/41c1a5f9bdc4cb6914e7971f50e4f45aeb11e087
DIFF: https://github.com/llvm/llvm-project/commit/41c1a5f9bdc4cb6914e7971f50e4f45aeb11e087.diff

LOG: [lldb/crashlog] Add `-s|--skip-status` option to interactive mode

This patch introduces a new option for the interactive crashlog mode,
that will prevent it from dumping the `process status` & `thread backtrace`
output to the debugger console.

This is necessary when lldb in running from an IDE, to prevent flooding
the console with information that should be already present in the UI.

rdar://96813296

Differential Revision: https://reviews.llvm.org/D131036

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

Added: 
    lldb/test/Shell/ScriptInterpreter/Python/Crashlog/skipped_status_interactive_crashlog.test

Modified: 
    lldb/examples/python/crashlog.py

Removed: 
    


################################################################################
diff  --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py
index 60e375893eb5..56cdd09c5658 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -1052,27 +1052,28 @@ def load_crashlog_in_scripted_process(debugger, crash_log_file, options, result)
     if not process or error.Fail():
         raise InteractiveCrashLogException("couldn't launch Scripted Process", error)
 
-    @contextlib.contextmanager
-    def synchronous(debugger):
-        async_state = debugger.GetAsync()
-        debugger.SetAsync(False)
-        try:
-            yield
-        finally:
-            debugger.SetAsync(async_state)
-
-    with synchronous(debugger):
-        run_options = lldb.SBCommandInterpreterRunOptions()
-        run_options.SetStopOnError(True)
-        run_options.SetStopOnCrash(True)
-        run_options.SetEchoCommands(True)
-
-        commands_stream = lldb.SBStream()
-        commands_stream.Print("process status\n")
-        commands_stream.Print("thread backtrace\n")
-        error = debugger.SetInputString(commands_stream.GetData())
-        if error.Success():
-            debugger.RunCommandInterpreter(True, False, run_options, 0, False, True)
+    if not options.skip_status:
+        @contextlib.contextmanager
+        def synchronous(debugger):
+            async_state = debugger.GetAsync()
+            debugger.SetAsync(False)
+            try:
+                yield
+            finally:
+                debugger.SetAsync(async_state)
+
+        with synchronous(debugger):
+            run_options = lldb.SBCommandInterpreterRunOptions()
+            run_options.SetStopOnError(True)
+            run_options.SetStopOnCrash(True)
+            run_options.SetEchoCommands(True)
+
+            commands_stream = lldb.SBStream()
+            commands_stream.Print("process status\n")
+            commands_stream.Print("thread backtrace\n")
+            error = debugger.SetInputString(commands_stream.GetData())
+            if error.Success():
+                debugger.RunCommandInterpreter(True, False, run_options, 0, False, True)
 
 def CreateSymbolicateCrashLogOptions(
         command_name,
@@ -1192,6 +1193,13 @@ def CreateSymbolicateCrashLogOptions(
             dest='target_path',
             help='the target binary path that should be used for interactive crashlog (optional)',
             default=None)
+        option_parser.add_option(
+            '--skip-status',
+            '-s',
+            dest='skip_status',
+            action='store_true',
+            help='prevent the interactive crashlog to dump the process status and thread backtrace at launch',
+            default=False)
     return option_parser
 
 

diff  --git a/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/skipped_status_interactive_crashlog.test b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/skipped_status_interactive_crashlog.test
new file mode 100644
index 000000000000..f32c2d94aad7
--- /dev/null
+++ b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/skipped_status_interactive_crashlog.test
@@ -0,0 +1,43 @@
+# REQUIRES: python, native && target-aarch64 && system-darwin
+
+# RUN: mkdir -p %t.dir
+# RUN: yaml2obj %S/Inputs/interactive_crashlog/multithread-test.yaml > %t.dir/multithread-test
+# RUN: %lldb -b -o 'command script import lldb.macosx.crashlog' \
+# RUN: -o 'crashlog -a -i -s -t %t.dir/multithread-test %S/Inputs/interactive_crashlog/multithread-test.ips' \
+# RUN: -o 'command source -s 0 %s' 2>&1 | FileCheck %s
+
+# CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands
+
+process status
+# CHECK: Process 22511 stopped
+# CHECK-NEXT: * thread #3, stop reason = EXC_BAD_ACCESS
+# CHECK-NEXT:     frame #0: 0x0000000100ec58f4 multithread-test`bar
+
+thread backtrace
+# CHECK: * thread #3, stop reason = EXC_BAD_ACCESS
+# CHECK-NEXT:   * frame #0: 0x0000000100ec58f4 multithread-test`bar{{.*}} [artificial]
+# CHECK-NEXT:     frame #1: 0x0000000100ec591b multithread-test`foo{{.*}} [artificial]
+# CHECK-NEXT:     frame #2: 0x0000000100ec5a87 multithread-test`compute_pow{{.*}} [artificial]
+
+thread list
+# CHECK: Process 22511 stopped
+# CHECK-NEXT:   thread #1: tid = 0x23c7fe, 0x000000019cc40b84 libsystem_kernel.dylib`__ulock_wait{{.*}}, queue = 'com.apple.main-thread'
+# CHECK-NEXT:   thread #2: tid = 0x23c800, 0x000000019cc42c9c libsystem_kernel.dylib`{{.*}}
+# CHECK-NEXT: * thread #3: tid = 0x23c801, 0x0000000100ec58f4 multithread-test`bar{{.*}}, stop reason = EXC_BAD_ACCESS
+
+bt all
+# CHECK:  thread #1, queue = 'com.apple.main-thread'
+# CHECK:    frame #{{[0-9]+}}: 0x000000019cc40b84 libsystem_kernel.dylib`__ulock_wait{{.*}} [artificial]
+# CHECK:    frame #{{[0-9]+}}: 0x0000000100ec5b3b multithread-test`main{{.*}} [artificial]
+# CHECK:    frame #{{[0-9]+}}: 0x00000002230f8da7 dyld`start{{.*}} [artificial]
+# CHECK-NEXT:  thread #2
+# CHECK-NEXT:    frame #0: 0x000000019cc42c9c libsystem_kernel.dylib`__write_nocancel{{.*}} [artificial]
+# CHECK:    frame #{{[0-9]+}}: 0x0000000100ec5957 multithread-test`call_and_wait{{.*}} [artificial]
+# CHECK:    frame #{{[0-9]+}}: 0x000000019cc7e06b libsystem_pthread.dylib`_pthread_start{{.*}} [artificial]
+# CHECK:    frame #{{[0-9]+}}: 0x000000019cc78e2b libsystem_pthread.dylib`thread_start{{.*}} [artificial]
+# CHECK-NEXT:* thread #3, stop reason = EXC_BAD_ACCESS
+# CHECK-NEXT:  * frame #0: 0x0000000100ec58f4 multithread-test`bar{{.*}} [artificial]
+# CHECK-NEXT:    frame #1: 0x0000000100ec591b multithread-test`foo{{.*}} [artificial]
+# CHECK-NEXT:    frame #2: 0x0000000100ec5a87 multithread-test`compute_pow{{.*}} [artificial]
+# CHECK:    frame #{{[0-9]+}}: 0x000000019cc7e06b libsystem_pthread.dylib`_pthread_start{{.*}} [artificial]
+# CHECK:    frame #{{[0-9]+}}: 0x000000019cc78e2b libsystem_pthread.dylib`thread_start{{.*}} [artificial]


        


More information about the lldb-commits mailing list