Ghidra is a software reverse engineering (SRE) framework
GP-5120: single pattern for regions GP-5120: single pattern for regions GP-5120: mismatched errors GP-5120: fix for inferior_thread is None
d-millar6be0884f1870
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/hooks.py b/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/hooks.pyindex a9cf007b83..7469e5f1b6 100644--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/hooks.py+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/hooks.py@@ -98,11 +98,11 @@ class InferiorState(object):frame, util.get_register_descs(frame.architecture(), 'general'))try:commands.putmem("$pc", "1", from_tty=False)- except MemoryError as e:+ except gdb.MemoryError as e:print(f"Couldn't record page with PC: {e}")try:commands.putmem("$sp", "1", from_tty=False)- except MemoryError as e:+ except gdb.MemoryError as e:print(f"Couldn't record page with SP: {e}")self.visited.add(hashable_frame)# NB: These commands (put_modules/put_regions) will fail if the process is running@@ -281,6 +281,11 @@ def on_register_changed(event):@log_errorsdef on_cont(event):+ if event.inferior_thread is None:+ # thread-based state computed in record_continued will+ # fail in some versions of gdb because the current_thread is None+ # and gdb fails to test for None before switching+ returnif (HOOK_STATE.check_skip_continue()):returninf = gdb.selected_inferior()diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/util.py b/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/util.pyindex 206b255c5b..9a81fc3f05 100644--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/util.py+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/util.py@@ -196,18 +196,12 @@ MODULE_INFO_READER = _choose_module_info_reader()REGIONS_CMD = 'info proc mappings'-REGION_PATTERN_V8 = re.compile("\\s*" +- "0x(?P<start>[0-9,A-F,a-f]+)\\s+" +- "0x(?P<end>[0-9,A-F,a-f]+)\\s+" +- "0x(?P<size>[0-9,A-F,a-f]+)\\s+" +- "0x(?P<offset>[0-9,A-F,a-f]+)\\s+" +- "(?P<objfile>.*)")-REGION_PATTERN_V12 = re.compile("\\s*" ++REGION_PATTERN = re.compile("\\s*" +"0x(?P<start>[0-9,A-F,a-f]+)\\s+" +"0x(?P<end>[0-9,A-F,a-f]+)\\s+" +"0x(?P<size>[0-9,A-F,a-f]+)\\s+" +"0x(?P<offset>[0-9,A-F,a-f]+)\\s+" +- "(?P<perms>[rwsxp\\-]+)\\s+" ++ "((?P<perms>[rwsxp\\-]+)?\\s+)?" +"(?P<objfile>.*)")@@ -216,6 +210,9 @@ class Region(namedtuple('BaseRegion', ['start', 'end', 'offset', 'perms', 'objficlass RegionInfoReader(object):+ cmd = REGIONS_CMD+ region_pattern = REGION_PATTERN+def region_from_line(self, line):mat = self.region_pattern.fullmatch(line)if mat is None:@@ -253,28 +250,13 @@ class RegionInfoReader(object):return False, Nonereturn True, new_regions--class RegionInfoReaderV8(RegionInfoReader):- cmd = REGIONS_CMD- region_pattern = REGION_PATTERN_V8-- def get_region_perms(self, mat):- return None---class RegionInfoReaderV12(RegionInfoReader):- cmd = REGIONS_CMD- region_pattern = REGION_PATTERN_V12-def get_region_perms(self, mat):return mat['perms']def _choose_region_info_reader():- if 8 <= GDB_VERSION.major < 12:- return RegionInfoReaderV8()- elif GDB_VERSION.major >= 12:- return RegionInfoReaderV12()+ if 8 <= GDB_VERSION.major:+ return RegionInfoReader()else:raise gdb.GdbError("GDB version not recognized by ghidragdb: " + GDB_VERSION.full)