简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM