mib updated this revision to Diff 495938.
mib added a comment.

Address @JDevlieghere feedback: rename `legacy` loading mode into `batch`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141658/new/

https://reviews.llvm.org/D141658

Files:
  lldb/examples/python/crashlog.py
  
lldb/test/Shell/ScriptInterpreter/Python/Crashlog/app_specific_backtrace_crashlog.test
  
lldb/test/Shell/ScriptInterpreter/Python/Crashlog/interactive_crashlog_invalid_target.test
  lldb/test/Shell/ScriptInterpreter/Python/Crashlog/json.test
  lldb/test/Shell/ScriptInterpreter/Python/Crashlog/no_threadState.test
  lldb/test/Shell/ScriptInterpreter/Python/Crashlog/scripted_crashlog_json.test
  
lldb/test/Shell/ScriptInterpreter/Python/Crashlog/skipped_status_interactive_crashlog.test
  lldb/test/Shell/ScriptInterpreter/Python/Crashlog/text.test

Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/text.test
===================================================================
--- lldb/test/Shell/ScriptInterpreter/Python/Crashlog/text.test
+++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/text.test
@@ -1,7 +1,7 @@
 # RUN: %clang_host -g %S/Inputs/test.c -o %t.out
 # RUN: cp %S/Inputs/a.out.crash %t.crash
 # RUN: %python %S/patch-crashlog.py --binary %t.out --crashlog %t.crash --offsets '{"main":20, "bar":9, "foo":16}'
-# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog %t.crash' 2>&1 | FileCheck %s
+# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog --mode legacy %t.crash' 2>&1 | FileCheck %s
 
 # CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands
 
Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/skipped_status_interactive_crashlog.test
===================================================================
--- lldb/test/Shell/ScriptInterpreter/Python/Crashlog/skipped_status_interactive_crashlog.test
+++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/skipped_status_interactive_crashlog.test
@@ -3,7 +3,7 @@
 # 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 'crashlog -a -s --mode interactive -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
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
@@ -3,7 +3,7 @@
 # RUN: mkdir -p %t.dir
 # RUN: yaml2obj %S/Inputs/interactive_crashlog/multithread-test.yaml > %t.dir/multithread-test
 # RUN: %lldb -o 'command script import lldb.macosx.crashlog' \
-# RUN: -o 'crashlog -a -i -t %t.dir/multithread-test %S/Inputs/interactive_crashlog/multithread-test.ips' \
+# RUN: -o 'crashlog -a --mode interactive -t %t.dir/multithread-test %S/Inputs/interactive_crashlog/multithread-test.ips' \
 # RUN: -o "thread list" -o "bt all" 2>&1 | FileCheck %s
 
 # CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands
Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/no_threadState.test
===================================================================
--- lldb/test/Shell/ScriptInterpreter/Python/Crashlog/no_threadState.test
+++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/no_threadState.test
@@ -2,7 +2,7 @@
 
 # RUN: cp %S/Inputs/no_threadState.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 %t.crash' 2>&1 | FileCheck %s
+# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog --mode batch %t.crash' 2>&1 | FileCheck %s
 
 # CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands
 
Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/json.test
===================================================================
--- lldb/test/Shell/ScriptInterpreter/Python/Crashlog/json.test
+++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/json.test
@@ -2,11 +2,11 @@
 
 # RUN: cp %S/Inputs/a.out.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 %t.crash' 2>&1 | FileCheck %s
+# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog --mode batch %t.crash' 2>&1 | FileCheck %s
 
 # RUN: cp %S/Inputs/a.out.ips %t.nometadata.crash
 # RUN: %python %S/patch-crashlog.py --binary %t.out --crashlog %t.nometadata.crash --offsets '{"main":20, "bar":9, "foo":16}' --json --no-metadata
-# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog %t.nometadata.crash' 2>&1 | FileCheck %s
+# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog --mode batch %t.nometadata.crash' 2>&1 | FileCheck %s
 
 # CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands
 
Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/interactive_crashlog_invalid_target.test
===================================================================
--- lldb/test/Shell/ScriptInterpreter/Python/Crashlog/interactive_crashlog_invalid_target.test
+++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/interactive_crashlog_invalid_target.test
@@ -2,7 +2,7 @@
 
 # RUN: %lldb -o 'command script import lldb.macosx.crashlog' \
 # RUN: -o 'crashlog -V' \
-# RUN: -o 'crashlog -a -i -t /this_file_does_not_exist %S/Inputs/interactive_crashlog/multithread-test.ips' 2>&1 | FileCheck %s
+# RUN: -o 'crashlog -a --mode interactive -t /this_file_does_not_exist %S/Inputs/interactive_crashlog/multithread-test.ips' 2>&1 | FileCheck %s
 
 # CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands
 
Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/app_specific_backtrace_crashlog.test
===================================================================
--- lldb/test/Shell/ScriptInterpreter/Python/Crashlog/app_specific_backtrace_crashlog.test
+++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/app_specific_backtrace_crashlog.test
@@ -3,7 +3,7 @@
 # RUN: mkdir -p %t.dir
 # RUN: yaml2obj %S/Inputs/application_specific_info/asi.yaml > %t.dir/asi
 # RUN: %lldb -o 'command script import lldb.macosx.crashlog' \
-# RUN: -o 'crashlog -a -i -t %t.dir/asi %S/Inputs/application_specific_info/asi.txt' \
+# RUN: -o 'crashlog -a --mode interactive -t %t.dir/asi %S/Inputs/application_specific_info/asi.txt' \
 # RUN: -o "thread list" -o "bt all" 2>&1 | FileCheck %s
 
 # CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands
Index: lldb/examples/python/crashlog.py
===================================================================
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -30,6 +30,7 @@
 import concurrent.futures
 import contextlib
 import datetime
+import enum
 import json
 import optparse
 import os
@@ -44,7 +45,6 @@
 import time
 import uuid
 
-
 print_lock = threading.RLock()
 
 try:
@@ -449,7 +449,12 @@
                 head, _, tail = buffer.partition('\n')
                 return json.loads(tail)
 
-        with open(path, 'r', encoding='utf-8') as f:
+        # Python's `open` function doesn't recognize user paths ('~/'), and
+        # expects either an absolute path or a relative path to the current
+        # working directory, so we need to expand the file path  ourself.
+        # The reasoning behind this is that on non-Unix systems, `~foo` is a
+        # valid filename, that wouldn't require file expansion.
+        with open(os.path.normpath(os.path.expanduser(path)), 'r', encoding='utf-8') as f:
             buffer = f.read()
         try:
             return parse_json(buffer)
@@ -1139,6 +1144,10 @@
             if error.Success():
                 debugger.RunCommandInterpreter(True, False, run_options, 0, False, True)
 
+class CrashLogLoadingMode(str, enum.Enum):
+    batch = 'batch'
+    interactive = 'interactive'
+
 def CreateSymbolicateCrashLogOptions(
         command_name,
         description,
@@ -1245,19 +1254,13 @@
         dest='source_all',
         help='show source for all threads, not just the crashed thread',
         default=False)
+    option_parser.add_option(
+        '-m',
+        '--mode',
+        type="choice",
+        choices=[mode.value for mode in CrashLogLoadingMode],
+        help="change how the symbolicated process and threads are displayed to the user (default = 'interactive')")
     if add_interactive_options:
-        option_parser.add_option(
-            '-i',
-            '--interactive',
-            action='store_true',
-            help='parse a crash log and load it in a ScriptedProcess',
-            default=False)
-        option_parser.add_option(
-            '-b',
-            '--batch',
-            action='store_true',
-            help='dump symbolicated stackframes without creating a debug session',
-            default=True)
         option_parser.add_option(
             '--target',
             '-t',
@@ -1297,6 +1300,12 @@
     except:
         return
 
+    if options.mode and options.mode != CrashLogLoadingMode.interactive and (options.target_path or options.skip_status):
+        print("Target path (-t) and skipping process status (-s) options can only used in intercative mode (-m=interactive).")
+        print("Aborting symbolication.")
+        option_parser.print_help()
+        return
+
     if options.version:
         print(debugger.GetVersionString())
         return
@@ -1312,14 +1321,12 @@
     error = lldb.SBError()
 
     def should_run_in_interactive_mode(options, ci):
-        if options.interactive:
+        if options.mode:
+            return options.mode == CrashLogLoadingMode.interactive
+        elif ci and ci.IsInteractive():
             return True
-        elif options.batch:
-            return False
-        # elif ci and ci.IsInteractive():
-        #     return True
         else:
-            return False
+            return sys.stdout.isatty()
 
     ci = debugger.GetCommandInterpreter()
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to