Debugging Under Linux Sebastien Ponce Friday 8 March

Debugging Under Linux Sebastien Ponce Friday, 8 March 2002 6/19/2021 S. Ponce / EP-LBC 1

Overview § When to use a debugger ? Available debuggers Very short introduction to gvd (GNU Visual Debugger) Some hints on debugging Gaudi Jobs Demo 08/03/2002 S. Ponce / EP-LBC § § 2

When to Use a Debugger ? 1. 2. If you compiled in debug mode : 1. When you want to trace an application execution (breakpoints, step in, . . . ) 2. When you want to know where the execution crashes (segmentation fault is handled) If you compiled in optimize mode : 1. You can still know which functions were called and which one failed 08/03/2002 S. Ponce / EP-LBC 3

What to Do With a Core ? § § You can still debug a program after a segmentation fault if you have a core file You can learn about • Where it failed • What were the values of variables at this time • What was the call stack at this time 08/03/2002 S. Ponce / EP-LBC 4

Available Debuggers § § GDB § Default linux debugger § Powerfull & stable § Installed on lxplus § BUT for experts only § GVD § Based on gdb § Installed in LHCb § Allow visual debug § Stable DDD § Can be found for free at § Based on gdb http: //libre. act-europe. fr/gvd/ § Installed on lxplus § Very easy to install locally § Allow Visual debugging § BUT not stable 08/03/2002 PREFERED CHOICE S. Ponce / EP-LBC 5

Launching gvd § Launching gvd : source setup. csh gvd <executable> § Inside gvd : [set breaking points] run <options> § In case of core dump : source setup. csh gvd <executable> § Inside gvd : File Open Core Dump <core> 08/03/2002 S. Ponce / EP-LBC 6

gvd Basics Menu bar Tool bar Data display Call stack Source files Source code Current Line Gdb window 08/03/2002 S. Ponce / EP-LBC 7

Some Hints for Gaudi Jobs § § § Gaudi is using shared libraries The source files of these do no appear in gvd before the libraries are loaded The trick is : gvd <executable> break main run <options> next here we loaded the Application. Mgr break Application. Mgr: : configure cont finish now every dll is loaded 08/03/2002 S. Ponce / EP-LBC 8

Demo (1) § Launch : tar xvf demo. tar cd demo make. /hello Segmentation Fault gvd hello 08/03/2002 S. Ponce / EP-LBC 9

Demo (2) § gdb windows : (gdb) run Starting Program: /home/sponce/demo/hello Program received signal SIGSEGV, Segmentation fault 0 x 400 e 1630 in strcmp() from /libc. so. 6 (gdb) § In menu Data Call Stack § In Tool Bar Up 08/03/2002 S. Ponce / EP-LBC 10

Demo (3) strcmp called from Hello: : print argument line was 0 x 0 Click "Up" once more to see where the line argument was set to 0 x 0 08/03/2002 S. Ponce / EP-LBC 11

Demo (4) Hello: : print called from Hello: : display. Message with no argument when print argument is missing, the default is a 0 pointer and fails. The default has to be changed to empty string 08/03/2002 S. Ponce / EP-LBC 12

Demo (5) § Edition of Hello. h : static void print (char* line = 0); becomes : static void print (char* line = ""); § In a shell : make. /hello Segmentation Fault gvd hello § There is another bug ! In gvd run 08/03/2002 S. Ponce / EP-LBC 13

Demo (6) § In gvd : display Call Stack “Up" § § The bug is still in strcmp, line is still 0 x 0 In gvd : “Up" Data Display Any Expression ”this” Then click on the fields of this to see the internal values 08/03/2002 S. Ponce / EP-LBC 14

Demo (7) this m_message is 0 x 0 We'll try to place a breakpoint where the initialization of m_message is done, i. e. In the constructor of Hello. 08/03/2002 S. Ponce / EP-LBC 15

Demo (8) § In gvd : Click on the blue point in front of line 4 of Hello. cpp to set a break point there Click run Say you want to start from beginning § gvd stops when the program reaches line 4 obviously the constructor was called with message = 0 x 0 Click "Up" to see where we came from 08/03/2002 S. Ponce / EP-LBC 16

Demo (9) We were suppose to go through line 20, not 22 since we gave no argument This should have been 1 == argc !!! Fix and run. All Right ! 08/03/2002 S. Ponce / EP-LBC 17

Demo (10) This is an example of what you get in case of non debug mode You still have the call stack but not the values of the arguments 08/03/2002 S. Ponce / EP-LBC 18

Demo (11) This show you what you get from a core : gvd hello File->Open Core It’s equivalent to run the program inside the debugger 08/03/2002 S. Ponce / EP-LBC 19
- Slides: 19