3

I'm trying to debug binaries of a a firmware running Linux with no ASLR, binaries are not compiled with PIE either so I have no issue getting the memory locations.

So after including gdbserver in the firmware and running, I connect to it from my machine and insert the breakpoint, the breakpoint is inserted successfully (sometimes gdb adjust the breakpoint location), and I continue the execution, and when the breakpoint is hit, I get the following in gdbserver:

enter image description here

I know that memory locations are correct by comparing bytes at location in gdb when debugging, and in Ghidra and they are identical.

This a mips architecture, and I compiled the gdbserver based on it, here is the file command result:

gdbserver: ELF 32-bit MSB executable, MIPS, MIPS-I version 1 (SYSV), statically linked, with debug_info, not stripped

I even tried to debug directly through gdb from the emulator, I failed to compile 7.7, 8.1 and 9.1, successfully compiled 7.9 but it crashes right after running, but I'm more interested in running gdb in the host machine, so I'm not really tried to fix this one.

Edit:

Following @Mega instructions and compiling gdb for target="mips-linux-gnu" instead of just using gdb-multiarch in host, I'm getting this error when a breakpoint is hit:

enter image description here

And on the host it says:

Program terminated with signal SIGTRAP, Trace/breakpoint trap. The program no longer exists.

1
  • Did you build the cross-target gdb as well? You only mentioned gdbserver Dec 7, 2022 at 9:34

1 Answer 1

1

I'm thinking the memory addresses are changing because you didn't build a cross-target gdb, you need to build gdb and gdbserver. This link is old but still accurate afair: https://www.linux.com/news/remote-cross-target-debugging-gdb-and-gdbserver/

4
  • Thank you for the reply. The link actually got me confused furthermore, it's clear that I need to build gdbserver for MIPS, and we're going to ignore gdb-multiarch (which I thought easiest way to achieve what I'm trying to do, but it's not wroking); I believe the next step is to build gdb with host=i686-linux-gnu and target=mips-linux-gnu so that I get an executable that is executed on the host machine and able to debug MIPS when connected to gdbserver, correct? however when I run the configure with the mentioned arguments and make, it generates a MISP executable, so what am-I doing wrong? Dec 8, 2022 at 20:24
  • nvm the preivous comment, running configure with no param other than target solve that, but now I'm getting build errors again, specifically the sim library, multiple "sim-arange.c:289: first defined here\nin function `sim_addr_range_hit_p"; why is this? Dec 8, 2022 at 20:57
  • Sorry, I'd have to try it, I'll get back to you. Dec 10, 2022 at 12:28
  • After reattempting the build on few different versions, I succeeded with 9.1, I updated the post with new issue. Dec 10, 2022 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.