debugging/gdb/example_remote_debugging
GDB (The GNU Project Debugger)
Example: GDB - Remote debugging
On the target system
Source code
division_by_zero.c++
:#include <iostream> int main(int argc, char *argv[]) { int a=1, b=0; std::cout << a/b << std::endl; }
Set up compiler environment
module add compiler/gnu
Compile (add debug symbols)
c++ -g -Wall division_by_zero.c++ -o division_by_zero
Execute with GDB server (e.g. in batch job)
gdbserver *:8080 ./division_by_zero
Process ./division_by_zero created; pid = 94989 Listening on port 8080
On the login node
Connect GDB with GDB server (e.g. from batch job)
gdb
(gdb) target remote ${NODE_NAME}:8080
Remote debugging using hkn0707:8080 Reading /hkfs/home/project/hk-project-scs/bq0742/division_by_zero from remote target... warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead. Reading /hkfs/home/project/hk-project-scs/bq0742/division_by_zero from remote target... Reading symbols from target:/hkfs/home/project/hk-project-scs/bq0742/division_by_zero...done. Reading /lib64/ld-linux-x86-64.so.2 from remote target... Reading /lib64/ld-linux-x86-64.so.2 from remote target... Reading symbols from target:/lib64/ld-linux-x86-64.so.2...Reading /lib64/ld-2.28.so.debug from remote target... Reading /lib64/.debug/ld-2.28.so.debug from remote target... Missing separate debuginfo for target:/lib64/ld-linux-x86-64.so.2 Try: yum --enablerepo='*debug*' install /usr/lib/debug/.build-id/33/d30c20d175357a3497081e95f0fa482c840b40.debug (no debugging symbols found)...done. 0x0000155555327fa0 in _start () from target:/lib64/ld-linux-x86-64.so.2
(gdb) continue
Continuing. Reading /opt/gcc/10/lib64/libstdc++.so.6 from remote target... Reading /lib64/libm.so.6 from remote target... Reading /opt/gcc/10/lib64/libgcc_s.so.1 from remote target... Reading /lib64/libc.so.6 from remote target... Reading /lib64/libm-2.28.so.debug from remote target... Reading /lib64/.debug/libm-2.28.so.debug from remote target... Missing separate debuginfo for target:/lib64/libm.so.6 Try: yum --enablerepo='*debug*' install /usr/lib/debug/.build-id/1d/b59e84916b99d6fd454683384033585d67a024.debug Reading /lib64/libc-2.28.so.debug from remote target... Reading /lib64/.debug/libc-2.28.so.debug from remote target... Missing separate debuginfo for target:/lib64/libc.so.6 Try: yum --enablerepo='*debug*' install /usr/lib/debug/.build-id/a9/1d7b51b23a64e86b82a91511c446c137d3ec8e.debug Program received signal SIGFPE, Arithmetic exception. 0x00000000004007a3 in main (argc=1, argv=0x7fffffffb2e8) at division_by_zero.c++:5 5 std::cout << a/b << std::endl;
Alternative: Graphical debugger on the client system
Tunnel local TCP port to TCP port on compute node
ssh -L8080:${NODE_NAME}:8080 hk.scc.kit.edu
Setup access to remote filesystem (for source code access)
mkdir remote sshfs hk.scc.kit.edu: remote cd remote
Or copy source code to local filesystem
scp hk.scc.kit.edu:division_by_zero.c++ .
Start graphical debugger
gdbgui
gdbgui configuration: Drop down menu: Connect to gdbserver: localhost:8080