Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug chrooted program with gdb

I'm in the situation where the program I have to debug must be run in a chrooted environment. Right now I've installed gdb in the other root and copied the sources over, which works for a rudimentary setup, but isn't very convenient, since I have to resync the source any time I make changes and recompile and I have to copy over all my gdb settings, etc.

Is there any way I can run the debugger in my normal environment, to debug a program that runs in a chrooted environment? I'm on Arch Linux.

like image 405
Moshev Avatar asked Mar 16 '26 08:03

Moshev


1 Answers

You can use remote debugging:

In the chroot you need just your usual runtime plus the program gdbserver. Then run:

chroot$ gdbserver :8888 myprogram

In the development environment, from the source directory you run gdb and connect it to the server

$ gdb myprogram
(gdb) target remote :8888

And you can start debugging.

I like to do br main before continue because the debugger will be stopped in _start, too early to be useful.

PS: Be aware of the security concerns when using remote debugging, as the 8888 is a listening TCP port.

like image 196
rodrigo Avatar answered Mar 18 '26 21:03

rodrigo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!