User Tools

Site Tools


gdb

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
gdb [2019/12/26 16:55] dblumegdb [2024/10/22 19:07] (current) – [Attaching to a remote target] dblume
Line 11: Line 11:
   product/testcode &   product/testcode &
  
-Then you can run gdb and attach to the process.+Then you can run gdb and attach to the process in one of the following ways. 
 + 
 +  $ gdb -p <pid-of-testcode> 
 +   
 +  $ gdb product/testcode <pid-of-testcode> 
 +   
 +  $ gdb 
 +  (gdb) attach <pid-of-testcode> 
 +  
  
 ===== Tips ===== ===== Tips =====
Line 86: Line 94:
     (gdb) c     (gdb) c
  
 +===== Processing a backtrace from code =====
 +
 +When using a define like this...
 +
 +<code cpp>
 +#define PRINT_BACKTRACE { void *stack[32];                                   \
 +    const int nptrs = ::backtrace(stack, sizeof(stack) / sizeof(stack[0]));  \
 +    if (nptrs) ::backtrace_symbols_fd(stack, nptrs, STDERR_FILENO);          \
 +}
 +</code>
 +
 +You might get output like this:
 +
 +    /lib/libUILib.so(_ZN12FakeSymbolDoesNotMatterEb+0x288)[0xb3831a78]
 +    Application[0x4c51d0]
 +    
 +You can get source code lines if you can calculate the offsets from each module. You can get those module base addresses from /proc/<pid>/maps
 +
 +    target:$ egrep " r-xp .*/(Application|libUILib.so)" /proc/$(ps -a | awk '/Application/{print $1}')/maps
 +    00010000-00dfb000 r-xp 00000000 00:0d 135649148  /bin/Application
 +    b3578000-b3f45000 r-xp 00000000 00:0d 68148928   /lib/libUILib.so
 +
 +So, for example, the first frame is at: libUILib.so + (0xb3831a78 - 0xb3578000). You can use addr2line to get that:
 +
 +    $ addr2line -e path/to/libUILib.so 0x2b9a78
 +    path/to/MySource.cpp:5712
gdb.1577408129.txt.gz · Last modified: 2023/04/12 20:44 (external edit)