[lldb] Improve setting of program for filtering disassembly (#148823)
This changes the example command added in https://github.com/llvm/llvm-project/pull/145793 so that the fdis program does not have to be a single program name. Doing so also means we can run the test on Windows where the program needs to be "python.exe script_name". I've changed "fdis set" to treat the rest of the command as the program. Then store that as a list to be passed to subprocess. If we just use a string, Python will think that "python.exe foo" is the name of an actual program instead of a program and an argument to it. This will still break if the paths have spaces in, but I'm trying to do just enough to fix the test here without rewriting all the option handling.
This commit is contained in:
parent
584158f9ae
commit
f995bc802d
@ -11,8 +11,13 @@ a filter program. This script is intended to mimic that workflow.
|
||||
import lldb
|
||||
import subprocess
|
||||
|
||||
filter_program = "crustfilt"
|
||||
|
||||
class Program(list):
|
||||
def __str__(self):
|
||||
return " ".join(self)
|
||||
|
||||
|
||||
filter_program = Program(["crustfilt"])
|
||||
|
||||
def __lldb_init_module(debugger, dict):
|
||||
debugger.HandleCommand("command script add -f filter_disasm.fdis fdis")
|
||||
@ -51,13 +56,20 @@ def fdis(debugger, args, exe_ctx, result, dict):
|
||||
result.Clear()
|
||||
|
||||
if len(args_list) == 1 and args_list[0] == "get":
|
||||
result.PutCString(filter_program)
|
||||
result.PutCString(str(filter_program))
|
||||
result.SetStatus(lldb.eReturnStatusSuccessFinishResult)
|
||||
return
|
||||
|
||||
if len(args_list) == 2 and args_list[0] == "set":
|
||||
filter_program = args_list[1]
|
||||
result.PutCString("Filter program set to %s" % filter_program)
|
||||
if args_list[0] == "set":
|
||||
# Assume the rest is a program to run and any arguments to be passed to
|
||||
# it.
|
||||
if len(args_list) <= 1:
|
||||
result.PutCString('"set" command requires a program argument')
|
||||
result.SetStatus(lldb.eReturnStatusFailed)
|
||||
return
|
||||
|
||||
filter_program = Program(args_list[1:])
|
||||
result.PutCString('Filter program set to "{}"'.format(filter_program))
|
||||
result.SetStatus(lldb.eReturnStatusSuccessFinishResult)
|
||||
return
|
||||
|
||||
@ -70,7 +82,9 @@ def fdis(debugger, args, exe_ctx, result, dict):
|
||||
output = res.GetOutput()
|
||||
|
||||
try:
|
||||
proc = subprocess.run([filter_program], capture_output=True, text=True, input=output)
|
||||
proc = subprocess.run(
|
||||
filter_program, capture_output=True, text=True, input=output
|
||||
)
|
||||
except (subprocess.SubprocessError, OSError) as e:
|
||||
result.PutCString("Error occurred. Original disassembly:\n\n" + output)
|
||||
result.SetError(str(e))
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
# REQUIRES: riscv
|
||||
# Unsupported until we fix launching the filter program on Windows.
|
||||
# UNSUPPORTED: system-windows
|
||||
# REQUIRES: python
|
||||
|
||||
# This test verifies that disassemble -b prints out the correct bytes and
|
||||
# format for standard and unknown riscv instructions of various sizes,
|
||||
@ -11,7 +10,7 @@
|
||||
|
||||
# RUN: llvm-mc -filetype=obj -mattr=+c --triple=riscv32-unknown-unknown %s -o %t
|
||||
# RUN: %lldb -b %t "-o" "disassemble -b -n main" | FileCheck %s
|
||||
# RUN: %lldb -b %t -o "command script import %S/../../../examples/python/filter_disasm.py" -o "fdis set %S/Inputs/dis_filt.py" -o "fdis -n main" | FileCheck --check-prefix=FILTER %s
|
||||
# RUN: %lldb -b %t -o "command script import %S/../../../examples/python/filter_disasm.py" -o "fdis set %python %S/Inputs/dis_filt.py" -o "fdis -n main" | FileCheck --check-prefix=FILTER %s
|
||||
|
||||
main:
|
||||
addi sp, sp, -0x20 # 16 bit standard instruction
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user