Repository: pwndbg/pwndbg

Issue:
Add support for Akita ARM board
I have been working with the "akita" ARM profile in QEMU. When I try to boot from a ROM file, A "KeyError: 'iwmmxt' exception occurs. This does not happen with regular gdb-multiarch.

=Expected behavior=
It works. Here's the result in vanilla gdb-multiarch:

    (gdb) tar remote localhost:1234
    Remote debugging using localhost:1234
    warning: No executable has been specified and target does not support
    determining executable automatically.  Try using the "file" command.
    0x00000000 in ?? ()
    (gdb) x/i $pc
    => 0x0: andeq   r0, r0, r0
    (gdb) _

=Actual behavior=
KeyError. Here's the stack trace:

    pwndbg> target remote localhost:1234
    Remote debugging using localhost:1234
    warning: No executable has been specified and target does not support
    determining executable automatically.  Try using the "file" command.
    0x00000000 in ?? ()
    Exception occurred: Error: 'iwmmxt' (<class 'KeyError'>)
    For more info invoke `set exception-verbose on` and rerun the command
    or debug it by yourself with `set exception-debugger on`
    Python Exception <class 'KeyError'> 'iwmmxt':
    Exception occurred: Error: 'iwmmxt' (<class 'KeyError'>)
    For more info invoke `set exception-verbose on` and rerun the command
    or debug it by yourself with `set exception-debugger on`
    Python Exception <class 'KeyError'> 'iwmmxt':
    Exception occurred: Error: 'iwmmxt' (<class 'KeyError'>)
    For more info invoke `set exception-verbose on` and rerun the command
    or debug it by yourself with `set exception-debugger on`
    Python Exception <class 'KeyError'> 'iwmmxt':
    pwndbg> set architecture arm
    The target architecture is assumed to be arm
    Exception occurred: Error: 'iwmmxt' (<class 'KeyError'>)
    For more info invoke `set exception-verbose on` and rerun the command
    or debug it by yourself with `set exception-debugger on`
    Python Exception <class 'KeyError'> 'iwmmxt':
    pwndbg> set exception-verbose on
    Set whether to print a full stacktrace for exceptions raised in Pwndbg commands to True
    Traceback (most recent call last):
      File "/home/jjb/pwndbg/pwndbg/events.py", line 165, in caller
        func()
      File "/home/jjb/pwndbg/pwndbg/regs.py", line 447, in update_last
        M.last = {k:M[k] for k in M.common}
      File "/home/jjb/pwndbg/pwndbg/regs.py", line 340, in common
        return arch_to_regs[pwndbg.arch.current].common
    KeyError: 'iwmmxt'`

In both cases, starting up the qemu machine was done with this line:
`qemu-system-arm -M akita --bios C750DUMP.ROM -s -S`


Discussion:
I think you would have to add this architecture to pwndbg and describe its register set etc similarly to https://github.com/pwndbg/pwndbg/blob/dev/pwndbg/regs.py#L136-L153

Resolving patch:
diff --git a/pwndbg/gdblib/arch.py b/pwndbg/gdblib/arch.py
--- a/pwndbg/gdblib/arch.py
+++ b/pwndbg/gdblib/arch.py
@@ -33,6 +33,7 @@
     "powerpc": "powerpc",
     "sparc": "sparc",
     "arm": "arm",
+    "iwmmxt":"arm",
     "armcm": "thumb",
     "rv32": "riscv32",
     "rv64": "riscv64",
diff --git a/pwndbg/lib/regs.py b/pwndbg/lib/regs.py
--- a/pwndbg/lib/regs.py
+++ b/pwndbg/lib/regs.py
@@ -126,6 +126,14 @@ def __iter__(self) -> Iterator[str]:
     retval="r0",
 )
 
+iwmmxt = RegisterSet(
+    retaddr=("lr",),
+    flags={"cpsr": arm_cpsr_flags},
+    gpr=("r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12"),
+    args=("r0", "r1", "r2", "r3"),
+    retval="r0",
+)
+
 # ARM Cortex-M
 armcm = RegisterSet(
     retaddr=("lr",),
@@ -549,6 +557,7 @@ def __iter__(self) -> Iterator[str]:
     "mips": mips,
     "sparc": sparc,
     "arm": arm,
+    "iwmmxt": iwmmxt,
     "armcm": armcm,
     "aarch64": aarch64,
     "powerpc": powerpc,


Test patch: