Hello,
First, awesome job on the tool ! Really appreciate it...
While trying to work on a MIPS MSB binary I had the following problem:
➜ openwrt gdb-multiarch ./mips_binary -q
[!] Failed to load `assemble`: 'radare2 Python bindings could not be loaded'
[!] Failed to load `ropgadget`: 'Missing Python `ropgadget` package. Install with `pip install ropgadget`'
gef loaded, `gef help' to start, `gef config' to configure
28 commands loaded (10 sub-commands), using Python engine 3.4
Reading symbols from ./mips_binary...done.
gef> target remote localhost:12345
Remote debugging using localhost:12345
Reading symbols from /lib/ld-uClibc.so.0...(no debugging symbols found)...done.
Loaded symbols for /lib/ld-uClibc.so.0
------------------------------------------------------------------------------------------[regs]
$zero 0x00000000 $at 0x00000000 $v0 0x00000000 $v1 0x00000000
$a0 0x00000000 $a1 0x00000000 $a2 0x00000000 $a3 0x00000000
$t0 0x00000000 $t1 0x00000000 $t2 0x00000000 $t3 0x00000000
$t4 0x00000000 $t5 0x00000000 $t6 0x00000000 $t7 0x00000000
$s0 0x00000000 $s1 0x00000000 $s2 0x00000000 $s3 0x00000000
$s4 0x00000000 $s5 0x00000000 $s6 0x00000000 $s7 0x00000000
$t8 0x00000000 $t9 0x00000000 $k0 0x00000000 $k1 0x00000000
Python Exception <class 'gdb.error'> Cannot convert value to long.:
Error while running hook_stop:
Error occurred in Python command: Cannot convert value to long.
0x767b8ab0 in _start () from /lib/ld-uClibc.so.0
gef> quit
info on the binary:
ELF 32-bit MSB executable, MIPS, MIPS-I version 1 (SYSV), dynamically linked (uses shared libs), not stripped
The way I'm executing this binary is via cross compiled libraries and qemu-mips using the -g flag for the gdb stub. The architecture and the endianess in gdb were correctly auto chosen.
After some troubleshooting of gdbinit-gef.py script, I noticed that the issue is due to the script trying to fetch the values of non-existent register names.
In gdbinit-gef.py you have
688 def mips_registers():
689 # http://vhouten.home.xs4all.nl/mipsel/r3000-isa.html
690 return ["$zero ", "$at ", "$v0 ", "$v1 ", "$a0 ", "$a1 ", "$a2 ", "$a3 ",
691 "$t0 ", "$t1 ", "$t2 ", "$t3 ", "$t4 ", "$t5 ", "$t6 ", "$t7 ",
692 "$s0 ", "$s1 ", "$s2 ", "$s3 ", "$s4 ", "$s5 ", "$s6 ", "$s7 ",
693 "$t8 ", "$t9 ", "$k0 ", "$k1 ", "$s8 ", "$status ", "$badvaddr ", "$cause ",
694 "$pc ", "$sp ", "$hi ", "$lo ", "$fir ", "$fcsr ", "$ra ", "$gp ", ]
gdb registers:
(gdb) info reg
zero at v0 v1 a0 a1 a2 a3
R0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
t0 t1 t2 t3 t4 t5 t6 t7
R8 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
s0 s1 s2 s3 s4 s5 s6 s7
R16 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
t8 t9 k0 k1 gp sp s8 ra
R24 00000000 00000000 00000000 00000000 00000000 76fff6e0 00000000 00000000
sr lo hi bad cause pc
20000010 00000000 00000000 00000000 00000000 767b8ab0
fsr fir
00000000 00739300
(gdb) quit
The function that the error is triggered is context_regs(). I noticed that there you might be anticipating issues with registers by your comments
2528 except gdb.MemoryError:
2529 # If this exception is triggered, it means that the current register
2530 # is corrupted. Just use the register "raw" value (not eval-ed)
Unfortunately the suggested solution did not work for me...
The way I got this to work is simply replace the names of the MIPS registers $status to $sr, $badvaddr to $bad and $fcsr to $fsr. It looks like this is not due to a version of gdb but to the features of the MIPS CPU, I'm not really sure why/how that's determined by gdb. Hope you find a better alternative.