[Lldb-commits] [PATCH] D129611: [lldb/crashlog] Add '-t|--target' option to interactive mode

2022-08-09 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa633c5e11b44: [lldb/crashlog] Add -t|--target 
option to interactive mode (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129611

Files:
  lldb/examples/python/crashlog.py
  lldb/examples/python/scripted_process/crashlog_scripted_process.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
@@ -2,8 +2,8 @@
 
 # RUN: mkdir -p %t.dir
 # RUN: yaml2obj %S/Inputs/interactive_crashlog/multithread-test.yaml > 
%t.dir/multithread-test
-# RUN: %lldb %t.dir/multithread-test -o 'command script import 
lldb.macosx.crashlog' \
-# RUN: -o 'crashlog -a -i %S/Inputs/interactive_crashlog/multithread-test.ips' 
\
+# 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 "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/scripted_process/crashlog_scripted_process.py
===
--- lldb/examples/python/scripted_process/crashlog_scripted_process.py
+++ lldb/examples/python/scripted_process/crashlog_scripted_process.py
@@ -13,7 +13,7 @@
 try:
 crash_log = CrashLogParser().parse(self.dbg, self.crashlog_path, 
False)
 except Exception as e:
-return
+raise e
 
 self.pid = crash_log.process_id
 self.addr_mask = crash_log.addr_mask
@@ -44,6 +44,7 @@
 super().__init__(target, args)
 
 if not self.target or not self.target.IsValid():
+# Return error
 return
 
 self.crashlog_path = None
@@ -54,6 +55,7 @@
 self.crashlog_path = crashlog_path.GetStringValue(4096)
 
 if not self.crashlog_path:
+# Return error
 return
 
 load_all_images = args.GetValueForKey("load_all_images")
Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -1017,11 +1017,22 @@
 
 crashlog = CrashLogParser().parse(debugger, crashlog_path, False)
 
-if debugger.GetNumTargets() > 0:
-target = debugger.GetTargetAtIndex(0)
-else:
+target = lldb.SBTarget()
+# 1. Try to use the user-provided target
+if options.target_path:
+target = debugger.CreateTarget(options.target_path)
+if not target:
+result.PutCString("error: couldn't create target provided by the \
+  user ({})".format(options.target_path))
+return
+# 2. If the user didn't provide a target, try to create a target using the 
symbolicator
+if not target or not target.IsValid():
 target = crashlog.create_target()
-if not target:
+# 3. If that didn't work, and a target is already loaded, use it
+if (target is None  or not target.IsValid()) and debugger.GetNumTargets() 
> 0:
+target = debugger.GetTargetAtIndex(0)
+# 4. Fail
+if target is None or not target.IsValid():
 result.PutCString("error: couldn't create target")
 return
 
@@ -1183,6 +1194,12 @@
 action='store_true',
 help='dump symbolicated stackframes without creating a debug 
session',
 default=True)
+option_parser.add_option(
+'--target',
+'-t',
+dest='target_path',
+help='the target binary path that should be used for interactive 
crashlog (optional)',
+default=None)
 return option_parser
 
 


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
@@ -2,8 +2,8 @@
 
 # RUN: mkdir -p %t.dir
 # RUN: yaml2obj %S/Inputs/interactive_crashlog/multithread-test.yaml > %t.dir/multithread-test
-# RUN: %lldb %t.dir/multithread-test -o 'command script import lldb.macosx.crashlog' \
-# RUN: -o 'crashlog -a -i %S/Inputs/interactive_crashlog/multithread-test.ips' \
+# RUN: %lldb -o 'command script import lldb.macosx.crashlog' \
+# RUN: -o 'crashlog -a -i -t %t.dir/multithread-test 

[Lldb-commits] [PATCH] D129611: [lldb/crashlog] Add '-t|--target' option to interactive mode

2022-08-08 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM modulo the `# Return error` but that's addressed in a follow up patch.


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

https://reviews.llvm.org/D129611

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129611: [lldb/crashlog] Add '-t|--target' option to interactive mode

2022-08-03 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 449782.
mib added a comment.

Change `f-string` to `string.format`


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

https://reviews.llvm.org/D129611

Files:
  lldb/examples/python/crashlog.py
  lldb/examples/python/scripted_process/crashlog_scripted_process.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
@@ -2,8 +2,8 @@
 
 # RUN: mkdir -p %t.dir
 # RUN: yaml2obj %S/Inputs/interactive_crashlog/multithread-test.yaml > 
%t.dir/multithread-test
-# RUN: %lldb %t.dir/multithread-test -o 'command script import 
lldb.macosx.crashlog' \
-# RUN: -o 'crashlog -a -i %S/Inputs/interactive_crashlog/multithread-test.ips' 
\
+# 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 "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/scripted_process/crashlog_scripted_process.py
===
--- lldb/examples/python/scripted_process/crashlog_scripted_process.py
+++ lldb/examples/python/scripted_process/crashlog_scripted_process.py
@@ -13,7 +13,7 @@
 try:
 crash_log = CrashLogParser().parse(self.dbg, self.crashlog_path, 
False)
 except Exception as e:
-return
+raise e
 
 self.pid = crash_log.process_id
 self.addr_mask = crash_log.addr_mask
@@ -44,6 +44,7 @@
 super().__init__(target, args)
 
 if not self.target or not self.target.IsValid():
+# Return error
 return
 
 self.crashlog_path = None
@@ -54,6 +55,7 @@
 self.crashlog_path = crashlog_path.GetStringValue(4096)
 
 if not self.crashlog_path:
+# Return error
 return
 
 load_all_images = args.GetValueForKey("load_all_images")
Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -1017,11 +1017,22 @@
 
 crashlog = CrashLogParser().parse(debugger, crashlog_path, False)
 
-if debugger.GetNumTargets() > 0:
-target = debugger.GetTargetAtIndex(0)
-else:
+target = lldb.SBTarget()
+# 1. Try to use the user-provided target
+if options.target_path:
+target = debugger.CreateTarget(options.target_path)
+if not target:
+result.PutCString("error: couldn't create target provided by the \
+  user ({})".format(options.target_path))
+return
+# 2. If the user didn't provide a target, try to create a target using the 
symbolicator
+if not target or not target.IsValid():
 target = crashlog.create_target()
-if not target:
+# 3. If that didn't work, and a target is already loaded, use it
+if (target is None  or not target.IsValid()) and debugger.GetNumTargets() 
> 0:
+target = debugger.GetTargetAtIndex(0)
+# 4. Fail
+if target is None or not target.IsValid():
 result.PutCString("error: couldn't create target")
 return
 
@@ -1183,6 +1194,12 @@
 action='store_true',
 help='dump symbolicated stackframes without creating a debug 
session',
 default=True)
+option_parser.add_option(
+'--target',
+'-t',
+dest='target_path',
+help='the target binary path that should be used for interactive 
crashlog (optional)',
+default=None)
 return option_parser
 
 


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
@@ -2,8 +2,8 @@
 
 # RUN: mkdir -p %t.dir
 # RUN: yaml2obj %S/Inputs/interactive_crashlog/multithread-test.yaml > %t.dir/multithread-test
-# RUN: %lldb %t.dir/multithread-test -o 'command script import lldb.macosx.crashlog' \
-# RUN: -o 'crashlog -a -i %S/Inputs/interactive_crashlog/multithread-test.ips' \
+# 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 "thread list" -o "bt all" 2>&1 | FileCheck %s
 
 # CHECK: "crashlog" {{.*}} commands have 

[Lldb-commits] [PATCH] D129611: [lldb/crashlog] Add '-t|--target' option to interactive mode

2022-08-03 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib marked an inline comment as done.
mib added inline comments.



Comment at: lldb/examples/python/crashlog.py:1025
+if not target:
+result.PutCString("error: couldn't create target provided by the 
user ({option.target_path})")
+return

JDevlieghere wrote:
> This is not an f-string so this will actually print `{option.target_path}` 
> rather than the actual value. That said, we don't use those anywhere else, so 
> let's use `.format()` to be consistent. 
`.format()` was too long compared to using an f-string :p that why I went with 
that ... I'll update it



Comment at: 
lldb/test/Shell/ScriptInterpreter/Python/Crashlog/scripted_crashlog_json.test:7
+# RUN: -o 'crashlog -a -i -t %t.dir/multithread-test 
%S/Inputs/interactive_crashlog/multithread-test.ips' \
 # RUN: -o "thread list" -o "bt all" 2>&1 | FileCheck %s
 

JDevlieghere wrote:
> Can we test some of the error cases here? Should be easy enough to provide a 
> target that doesn't exist (and would've caught the f-string issue). 
I tried having a first `crashlog` command with an invalid target fail before 
the one that works but `lit` would just stop at the error. Instead, I test it 
in D129614. 


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

https://reviews.llvm.org/D129611

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129611: [lldb/crashlog] Add '-t|--target' option to interactive mode

2022-08-03 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: lldb/examples/python/crashlog.py:1025
+if not target:
+result.PutCString("error: couldn't create target provided by the 
user ({option.target_path})")
+return

This is not an f-string so this will actually print `{option.target_path}` 
rather than the actual value. That said, we don't use those anywhere else, so 
let's use `.format()` to be consistent. 



Comment at: 
lldb/test/Shell/ScriptInterpreter/Python/Crashlog/scripted_crashlog_json.test:7
+# RUN: -o 'crashlog -a -i -t %t.dir/multithread-test 
%S/Inputs/interactive_crashlog/multithread-test.ips' \
 # RUN: -o "thread list" -o "bt all" 2>&1 | FileCheck %s
 

Can we test some of the error cases here? Should be easy enough to provide a 
target that doesn't exist (and would've caught the f-string issue). 


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

https://reviews.llvm.org/D129611

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129611: [lldb/crashlog] Add '-t|--target' option to interactive mode

2022-08-02 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 449495.
mib added a comment.

Make lit run command more readable


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

https://reviews.llvm.org/D129611

Files:
  lldb/examples/python/crashlog.py
  lldb/examples/python/scripted_process/crashlog_scripted_process.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
@@ -2,8 +2,8 @@
 
 # RUN: mkdir -p %t.dir
 # RUN: yaml2obj %S/Inputs/interactive_crashlog/multithread-test.yaml > 
%t.dir/multithread-test
-# RUN: %lldb %t.dir/multithread-test -o 'command script import 
lldb.macosx.crashlog' \
-# RUN: -o 'crashlog -a -i %S/Inputs/interactive_crashlog/multithread-test.ips' 
\
+# 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 "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/scripted_process/crashlog_scripted_process.py
===
--- lldb/examples/python/scripted_process/crashlog_scripted_process.py
+++ lldb/examples/python/scripted_process/crashlog_scripted_process.py
@@ -13,7 +13,7 @@
 try:
 crash_log = CrashLogParser().parse(self.dbg, self.crashlog_path, 
False)
 except Exception as e:
-return
+raise e
 
 self.pid = crash_log.process_id
 self.addr_mask = crash_log.addr_mask
@@ -44,6 +44,7 @@
 super().__init__(target, args)
 
 if not self.target or not self.target.IsValid():
+# Return error
 return
 
 self.crashlog_path = None
@@ -54,6 +55,7 @@
 self.crashlog_path = crashlog_path.GetStringValue(4096)
 
 if not self.crashlog_path:
+# Return error
 return
 
 load_all_images = args.GetValueForKey("load_all_images")
Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -1017,11 +1017,21 @@
 
 crashlog = CrashLogParser().parse(debugger, crashlog_path, False)
 
-if debugger.GetNumTargets() > 0:
-target = debugger.GetTargetAtIndex(0)
-else:
+target = lldb.SBTarget()
+# 1. Try to use the user-provided target
+if options.target_path:
+target = debugger.CreateTarget(options.target_path)
+if not target:
+result.PutCString("error: couldn't create target provided by the 
user ({option.target_path})")
+return
+# 2. If the user didn't provide a target, try to create a target using the 
symbolicator
+if not target or not target.IsValid():
 target = crashlog.create_target()
-if not target:
+# 3. If that didn't work, and a target is already loaded, use it
+if (target is None  or not target.IsValid()) and debugger.GetNumTargets() 
> 0:
+target = debugger.GetTargetAtIndex(0)
+# 4. Fail
+if target is None or not target.IsValid():
 result.PutCString("error: couldn't create target")
 return
 
@@ -1183,6 +1193,12 @@
 action='store_true',
 help='dump symbolicated stackframes without creating a debug 
session',
 default=True)
+option_parser.add_option(
+'--target',
+'-t',
+dest='target_path',
+help='the target binary path that should be used for interactive 
crashlog (optional)',
+default=None)
 return option_parser
 
 


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
@@ -2,8 +2,8 @@
 
 # RUN: mkdir -p %t.dir
 # RUN: yaml2obj %S/Inputs/interactive_crashlog/multithread-test.yaml > %t.dir/multithread-test
-# RUN: %lldb %t.dir/multithread-test -o 'command script import lldb.macosx.crashlog' \
-# RUN: -o 'crashlog -a -i %S/Inputs/interactive_crashlog/multithread-test.ips' \
+# 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 "thread list" -o "bt all" 2>&1 | FileCheck %s
 
 # CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on 

[Lldb-commits] [PATCH] D129611: [lldb/crashlog] Add '-t|--target' option to interactive mode

2022-07-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 448434.
mib edited the summary of this revision.
mib added a comment.

Address @JDevlieghere feedbacks.


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

https://reviews.llvm.org/D129611

Files:
  lldb/examples/python/crashlog.py
  lldb/examples/python/scripted_process/crashlog_scripted_process.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
@@ -2,7 +2,7 @@
 
 # RUN: mkdir -p %t.dir
 # RUN: yaml2obj %S/Inputs/interactive_crashlog/multithread-test.yaml > 
%t.dir/multithread-test
-# RUN: %lldb %t.dir/multithread-test -o 'command script import 
lldb.macosx.crashlog' -o 'crashlog -a -i 
%S/Inputs/interactive_crashlog/multithread-test.ips' -o "thread list" -o "bt 
all" 2>&1 | FileCheck %s
+# RUN: %lldb -o 'command script import lldb.macosx.crashlog' -o 'crashlog -a 
-i -t %t.dir/multithread-test 
%S/Inputs/interactive_crashlog/multithread-test.ips' -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/scripted_process/crashlog_scripted_process.py
===
--- lldb/examples/python/scripted_process/crashlog_scripted_process.py
+++ lldb/examples/python/scripted_process/crashlog_scripted_process.py
@@ -13,7 +13,7 @@
 try:
 crash_log = CrashLogParser().parse(self.dbg, self.crashlog_path, 
False)
 except Exception as e:
-return
+raise e
 
 self.pid = crash_log.process_id
 self.addr_mask = crash_log.addr_mask
@@ -44,6 +44,7 @@
 super().__init__(target, args)
 
 if not self.target or not self.target.IsValid():
+# Return error
 return
 
 self.crashlog_path = None
@@ -54,6 +55,7 @@
 self.crashlog_path = crashlog_path.GetStringValue(4096)
 
 if not self.crashlog_path:
+# Return error
 return
 
 load_all_images = args.GetValueForKey("load_all_images")
Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -1017,11 +1017,21 @@
 
 crashlog = CrashLogParser().parse(debugger, crashlog_path, False)
 
-if debugger.GetNumTargets() > 0:
-target = debugger.GetTargetAtIndex(0)
-else:
+target = lldb.SBTarget()
+# 1. Try to use the user-provided target
+if options.target_path:
+target = debugger.CreateTarget(options.target_path)
+if not target:
+result.PutCString("error: couldn't create target provided by the 
user ({option.target_path})")
+return
+# 2. If the user didn't provide a target, try to create a target using the 
symbolicator
+if not target or not target.IsValid():
 target = crashlog.create_target()
-if not target:
+# 3. If that didn't work, and a target is already loaded, use it
+if (target is None  or not target.IsValid()) and debugger.GetNumTargets() 
> 0:
+target = debugger.GetTargetAtIndex(0)
+# 4. Fail
+if target is None or not target.IsValid():
 result.PutCString("error: couldn't create target")
 return
 
@@ -1183,6 +1193,12 @@
 action='store_true',
 help='dump symbolicated stackframes without creating a debug 
session',
 default=True)
+option_parser.add_option(
+'--target',
+'-t',
+dest='target_path',
+help='the target binary path that should be used for interactive 
crashlog (optional)',
+default=None)
 return option_parser
 
 


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
@@ -2,7 +2,7 @@
 
 # RUN: mkdir -p %t.dir
 # RUN: yaml2obj %S/Inputs/interactive_crashlog/multithread-test.yaml > %t.dir/multithread-test
-# RUN: %lldb %t.dir/multithread-test -o 'command script import lldb.macosx.crashlog' -o 'crashlog -a -i %S/Inputs/interactive_crashlog/multithread-test.ips' -o "thread list" -o "bt all" 2>&1 | FileCheck %s
+# RUN: %lldb -o 'command script import lldb.macosx.crashlog' -o 'crashlog -a -i -t %t.dir/multithread-test %S/Inputs/interactive_crashlog/multithread-test.ips' -o "thread list" -o "bt all" 2>&1 | FileCheck %s
 
 # CHECK: 

[Lldb-commits] [PATCH] D129611: [lldb/crashlog] Add '-t|--target' option to interactive mode

2022-07-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib marked 5 inline comments as done.
mib added inline comments.



Comment at: 
lldb/examples/python/scripted_process/crashlog_scripted_process.py:47-48
+if not self.target.GetExecutable() or not self.target.IsValid():
+# Return error
 return
 

JDevlieghere wrote:
> The comment says return error but we're not returning anything. Should this 
> raise an exception? 
I was thinking of adding a `SBCommandObjectReturn` to every script process init 
function so we print errors in lldb instead of raising a python exception. That 
way we could propage that into the IDEs.
I'm doing that in a follow-up patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129611

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129611: [lldb/crashlog] Add '-t|--target' option to interactive mode

2022-07-13 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: lldb/examples/python/crashlog.py:1022
+# 1. Try to use the user-provided target
+if options.target_path is not None and options.target_path != "":
+target = debugger.CreateTarget(options.target_path)





Comment at: lldb/examples/python/crashlog.py:1024
+target = debugger.CreateTarget(options.target_path)
+# 2. If that didn't work, try to create a target using the symbolicator
+if target is None or not target.IsValid():

I think if the user provided a target path and that didn't work, we should 
report and error and give up. 



Comment at: lldb/examples/python/crashlog.py:1025
+# 2. If that didn't work, try to create a target using the symbolicator
+if target is None or not target.IsValid():
 target = crashlog.create_target()





Comment at: lldb/examples/python/crashlog.py:1197
+dest='target_path',
+help='the target binary path that should be used for interactive 
crashlog')
 return option_parser

Please make it clear that this is optional and describe the fallback behavior.



Comment at: 
lldb/examples/python/scripted_process/crashlog_scripted_process.py:46
 
-if not self.target or not self.target.IsValid():
+if not self.target.GetExecutable() or not self.target.IsValid():
+# Return error

Maybe leave a comment why the executable matters here rather than just the 
target.



Comment at: 
lldb/examples/python/scripted_process/crashlog_scripted_process.py:47-48
+if not self.target.GetExecutable() or not self.target.IsValid():
+# Return error
 return
 

The comment says return error but we're not returning anything. Should this 
raise an exception? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129611

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129611: [lldb/crashlog] Add '-t|--target' option to interactive mode

2022-07-12 Thread Med Ismail Bennani via Phabricator via lldb-commits
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 introduces a new flag for the interactive crashlog mode, that
allow the user to specify, which target to use to create the scripted
process.

This can be very useful when lldb already have few targets created:
Instead of taking the first one (zeroth index), we will use that flag to
create a new target. If that fails, we rely on the symbolicator to
create a targer. If that also fails and there are already some targets
loaded in lldb, we use the first one.

rdar://94682869

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129611

Files:
  lldb/examples/python/crashlog.py
  lldb/examples/python/scripted_process/crashlog_scripted_process.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
@@ -2,7 +2,7 @@
 
 # RUN: mkdir -p %t.dir
 # RUN: yaml2obj %S/Inputs/interactive_crashlog/multithread-test.yaml > 
%t.dir/multithread-test
-# RUN: %lldb %t.dir/multithread-test -o 'command script import 
lldb.macosx.crashlog' -o 'crashlog -a -i 
%S/Inputs/interactive_crashlog/multithread-test.ips' -o "thread list" -o "bt 
all" 2>&1 | FileCheck %s
+# RUN: %lldb -o 'command script import lldb.macosx.crashlog' -o 'crashlog -a 
-i -t %t.dir/multithread-test 
%S/Inputs/interactive_crashlog/multithread-test.ips' -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/scripted_process/crashlog_scripted_process.py
===
--- lldb/examples/python/scripted_process/crashlog_scripted_process.py
+++ lldb/examples/python/scripted_process/crashlog_scripted_process.py
@@ -43,7 +43,8 @@
 def __init__(self, target: lldb.SBTarget, args : lldb.SBStructuredData):
 super().__init__(target, args)
 
-if not self.target or not self.target.IsValid():
+if not self.target.GetExecutable() or not self.target.IsValid():
+# Return error
 return
 
 self.crashlog_path = None
@@ -54,6 +55,7 @@
 self.crashlog_path = crashlog_path.GetStringValue(4096)
 
 if not self.crashlog_path:
+# Return error
 return
 
 load_all_images = args.GetValueForKey("load_all_images")
Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -1017,11 +1017,18 @@
 
 crashlog = CrashLogParser().parse(debugger, crashlog_path, False)
 
-if debugger.GetNumTargets() > 0:
-target = debugger.GetTargetAtIndex(0)
-else:
+target = lldb.SBTarget()
+# 1. Try to use the user-provided target
+if options.target_path is not None and options.target_path != "":
+target = debugger.CreateTarget(options.target_path)
+# 2. If that didn't work, try to create a target using the symbolicator
+if target is None or not target.IsValid():
 target = crashlog.create_target()
-if not target:
+# 3. If that didn't work, and a target is already loaded, use it
+if (target is None  or not target.IsValid()) and debugger.GetNumTargets() 
> 0:
+target = debugger.GetTargetAtIndex(0)
+# 4. Fail
+if target is None or not target.IsValid():
 result.PutCString("error: couldn't create target")
 return
 
@@ -1183,6 +1190,11 @@
 action='store_true',
 help='dump symbolicated stackframes without creating a debug 
session',
 default=True)
+option_parser.add_option(
+'--target',
+'-t',
+dest='target_path',
+help='the target binary path that should be used for interactive 
crashlog')
 return option_parser
 
 


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
@@ -2,7 +2,7 @@
 
 # RUN: mkdir -p %t.dir
 # RUN: yaml2obj %S/Inputs/interactive_crashlog/multithread-test.yaml > %t.dir/multithread-test
-# RUN: %lldb %t.dir/multithread-test -o 'command script import lldb.macosx.crashlog' -o 'crashlog -a -i %S/Inputs/interactive_crashlog/multithread-test.ips' -o