Skip to content

Commit

Permalink
GP-4415: Lots of lldb trace-rmi fixes
Browse files Browse the repository at this point in the history
Breakpoint Enabled atribute.
Test fixes on macOS and Linux.
Re-work value conversion a bit.
shlexify commands.
Add method display names.
  • Loading branch information
nsadeveloper789 committed Mar 22, 2024
1 parent 523f6e4 commit eb5bf45
Show file tree
Hide file tree
Showing 22 changed files with 1,830 additions and 1,224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ def ghidra_trace_sync_disable(*, is_mi, **kwargs):
"""
Cease synchronizing the current inferior with the Ghidra trace.
This is the opposite of 'ghidra trace sync-disable', except it will not
This is the opposite of 'ghidra trace sync-enable', except it will not
automatically remove hooks.
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#@menu-group local
#@icon icon.debugger
#@help TraceRmiLauncherServicePlugin#lldb
#@enum StartCmd:str run "process launch" "process launch --stop-at-entry"
#@enum StartCmd:str "process launch" "process launch --stop-at-entry"
#@arg :str "Image" "The target binary executable image"
#@args "Arguments" "Command-line arguments to pass to the target"
#@env OPT_LLDB_PATH:str="lldb" "Path to lldb" "The path to lldb. Omit the full path to resolve using the system PATH."
Expand Down
56 changes: 22 additions & 34 deletions Ghidra/Debug/Debugger-agent-lldb/src/main/py/src/ghidralldb/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
'thumbv7em': ['ARM:BE:32:Cortex', 'ARM:LE:32:Cortex'],
'armv8': ['ARM:BE:32:v8', 'ARM:LE:32:v8'],
'armv8l': ['ARM:BE:32:v8', 'ARM:LE:32:v8'],
'arm64': ['ARM:BE:64:v8', 'ARM:LE:64:v8'],
'arm64e': ['ARM:BE:64:v8', 'ARM:LE:64:v8'],
'arm64': ['AARCH64:BE:64:v8A', 'AARCH64:LE:64:AppleSilicon', 'AARCH64:LE:64:v8A'],
'arm64e': ['AARCH64:BE:64:v8A', 'AARCH64:LE:64:AppleSilicon', 'AARCH64:LE:64:v8A'],
'arm64_32': ['ARM:BE:32:v8', 'ARM:LE:32:v8'],
'mips': ['MIPS:BE:32:default', 'MIPS:LE:32:default'],
'mipsr2': ['MIPS:BE:32:default', 'MIPS:LE:32:default'],
Expand Down Expand Up @@ -141,18 +141,31 @@
}


def get_arch():
def find_host_triple():
dbg = util.get_debugger()
for i in range(dbg.GetNumPlatforms()):
platform = dbg.GetPlatformAtIndex(i)
if platform.GetName() == 'host':
return platform.GetTriple()
return 'unrecognized'


def find_triple():
triple = util.get_target().triple
if triple is None:
return "x86_64"
if triple is not None:
return triple
return find_host_triple()


def get_arch():
triple = find_triple()
return triple.split('-')[0]


def get_endian():
parm = util.get_convenience_variable('endian')
if parm != 'auto':
return parm
# Once again, we have to hack using the human-readable 'show'
order = util.get_target().GetByteOrder()
if order is lldb.eByteOrderLittle:
return 'little'
Expand All @@ -167,15 +180,11 @@ def get_osabi():
parm = util.get_convenience_variable('osabi')
if not parm in ['auto', 'default']:
return parm
# We have to hack around the fact the LLDB won't give us the current OS ABI
# via the API if it is "auto" or "default". Using "show", we can get it, but
# we have to parse output meant for a human. The current value will be on
# the top line, delimited by double quotes. It will be the last delimited
# thing on that line. ("auto" may appear earlier on the line.)
triple = util.get_target().triple
triple = find_triple()
# this is an unfortunate feature of the tests
if triple is None or '-' not in triple:
return "default"
triple = find_triple()
return triple.split('-')[2]


Expand Down Expand Up @@ -274,29 +283,8 @@ def __init__(self, byte_order):
def map_name(self, proc, name):
return name

"""
def convert_value(self, value, type=None):
if type is None:
type = value.dynamic_type.strip_typedefs()
l = type.sizeof
# l - 1 because array() takes the max index, inclusive
# NOTE: Might like to pre-lookup 'unsigned char', but it depends on the
# architecture *at the time of lookup*.
cv = value.cast(lldb.lookup_type('unsigned char').array(l - 1))
rng = range(l)
if self.byte_order == 'little':
rng = reversed(rng)
return bytes(cv[i] for i in rng)
"""

def map_value(self, proc, name, value):
try:
# TODO: this seems half-baked
av = value.to_bytes(8, "big")
except e:
raise ValueError("Cannot convert {}'s value: '{}', type: '{}'"
.format(name, value, value.type))
return RegVal(self.map_name(proc, name), av)
return RegVal(self.map_name(proc, name), value)

def map_name_back(self, proc, name):
return name
Expand Down
Loading

0 comments on commit eb5bf45

Please sign in to comment.