From d59ae31360bec1de672008178be310a61438b60e Mon Sep 17 00:00:00 2001 From: OBarronCS <55004530+OBarronCS@users.noreply.github.com> Date: Mon, 19 Aug 2024 17:13:46 -0700 Subject: [PATCH] ARM Cortex-M detection (#2381) * Fix detection of Arm Cortex-M * lint * order of operations * add comment for cortex-m --- pwndbg/gdblib/arch.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pwndbg/gdblib/arch.py b/pwndbg/gdblib/arch.py index 58760e384..f770f2aa5 100644 --- a/pwndbg/gdblib/arch.py +++ b/pwndbg/gdblib/arch.py @@ -96,7 +96,13 @@ def _get_arch(ptrsize: int): for match in ARCHS: if match in arch: # Distinguish between Cortex-M and other ARM - if match == "arm" and "-m" in arch: + # When GDB detects correctly Cortex-M processes, it will label them with `arm*-m`, such as armv7e-m + # However, GDB will sometimes fail to correctly label Cortex-M binaries properly, and says it's simply 'arm'. + # Internally, GDB still detects the processes as Cortex-M, as it can access .xpsr, but it doesn't + # appear to expose this in information through any command/API. Since Cortex-M has the .xpsr flags register + # instead of .cpsr, we will check if it's present. + # See: https://github.com/pwndbg/pwndbg/issues/2153 + if match == "arm" and ("-m" in arch or pwndbg.gdblib.regs.xpsr is not None): match = "armcm" elif match.startswith("riscv:"): match = match[6:]