debugging under linux
DESCRIPTION
Debugging Under Linux. Sebastien Ponce Friday, 8 March 2002. Overview. When to use a debugger ? Available debuggers Very short introduction to gvd (GNU Visual Debugger) Some hints on debugging Gaudi Jobs Demo. When to Use a Debugger ?. If you compiled in debug mode : - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/1.jpg)
04/22/23 S. Ponce / EP-LBC 1
Debugging Under Linux
Sebastien PonceSebastien Ponce
Friday, 8 March 2002Friday, 8 March 2002
![Page 2: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/2.jpg)
08/03/2002 S. Ponce / EP-LBC 2
OverviewOverview
When to use a debugger ?When to use a debugger ? Available debuggersAvailable debuggers Very short introduction to gvdVery short introduction to gvd
(GNU Visual Debugger) (GNU Visual Debugger) Some hints on debugging Gaudi JobsSome hints on debugging Gaudi Jobs DemoDemo
![Page 3: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/3.jpg)
08/03/2002 S. Ponce / EP-LBC 3
When to Use a Debugger ?When to Use a Debugger ?
If you compiled in debug mode :If you compiled in debug mode :• When you want to trace an application When you want to trace an application
execution (breakpoints, step in, ...)execution (breakpoints, step in, ...)• When you want to know where the When you want to know where the
execution crashes (segmentation fault is execution crashes (segmentation fault is handled)handled)
If you compiled in optimize mode :If you compiled in optimize mode :• You can still know which functions were You can still know which functions were
called and which one failedcalled and which one failed
![Page 4: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/4.jpg)
08/03/2002 S. Ponce / EP-LBC 4
What to Do With a Core ?What to Do With a Core ?
You can still debug a program after a You can still debug a program after a segmentation fault if you have a core filesegmentation fault if you have a core file
You can learn aboutYou can learn about• Where it failedWhere it failed• What were the values of variables at this timeWhat were the values of variables at this time• What was the call stack at this timeWhat was the call stack at this time
![Page 5: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/5.jpg)
08/03/2002 S. Ponce / EP-LBC 5
Available DebuggersAvailable Debuggers
GDBGDB Default linux debugger Powerfull & stable Installed on lxplus BUT for experts only
DDDDDD Based on gdb Installed on lxplus Allow Visual debugging BUT not stable
GVDGVD Based on gdb Installed in LHCb Allow visual debug Stable Can be found for free at
http://libre.act-europe.fr/gvd/ Very easy to install locally
PREFERED CHOICEPREFERED CHOICE
![Page 6: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/6.jpg)
08/03/2002 S. Ponce / EP-LBC 6
Launching gvdLaunching gvd
Launching gvd :Launching gvd :source setup.csh
gvd <executable> Inside gvd :Inside gvd :
[set breaking points]
run <options>
In case of core dump :In case of core dump :source setup.csh
gvd <executable> Inside gvd :Inside gvd :
FileOpen Core Dump <core>
![Page 7: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/7.jpg)
08/03/2002 S. Ponce / EP-LBC 7
gvd Basicsgvd Basics
Menu bar
Tool bar
Call stack
Source files
Gdb window
Data display
Current Line
Source code
![Page 8: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/8.jpg)
08/03/2002 S. Ponce / EP-LBC 8
Some Hints for Gaudi JobsSome Hints for Gaudi Jobs
Gaudi is using shared librariesGaudi is using shared libraries The source files of these do no appear in gvd The source files of these do no appear in gvd
before the libraries are loadedbefore the libraries are loaded The trick is :The trick is :
gvd <executable>gvd <executable>
break mainbreak main
run <options>run <options>
next next here we loaded the ApplicationMgr here we loaded the ApplicationMgr
break ApplicationMgr::configurebreak ApplicationMgr::configure
contcont
finish finish now every dll is loaded now every dll is loaded
![Page 9: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/9.jpg)
08/03/2002 S. Ponce / EP-LBC 9
Demo (1)Demo (1)
Launch :Launch :tar xvf demo.tar
cd demo
make
./hello
Segmentation Fault
gvd hello
![Page 10: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/10.jpg)
08/03/2002 S. Ponce / EP-LBC 10
Demo (2)Demo (2)
gdb windows :gdb windows :(gdb) run
Starting Program: /home/sponce/demo/hello
Program received signal SIGSEGV, Segmentation fault
0x400e1630 in strcmp() from /lib/libc.so.6
(gdb) In menuIn menu
Data Call Stack In Tool BarIn Tool Bar
Up
![Page 11: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/11.jpg)
08/03/2002 S. Ponce / EP-LBC 11
Demo (3)Demo (3)
argument line was 0x0
strcmp called from Hello::print
Click "Up" once more to see where the line argument was set to 0x0
![Page 12: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/12.jpg)
08/03/2002 S. Ponce / EP-LBC 12
Demo (4)Demo (4)
Hello::print called from Hello::displayMessage 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
![Page 13: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/13.jpg)
08/03/2002 S. Ponce / EP-LBC 13
Demo (5)Demo (5)
Edition of Hello.h :Edition of Hello.h :static void print (char* line = 0);
becomes :
static void print (char* line = "");
In a shell :In a shell :make
./hello
Segmentation Fault
gvd hello In gvdIn gvd
run
There is another bug !There is another bug !
![Page 14: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/14.jpg)
08/03/2002 S. Ponce / EP-LBC 14
Demo (6)Demo (6)
In gvd :In gvd :display Call Stack
“Up" The bug is still in strcmp, line is still 0x0The bug is still in strcmp, line is still 0x0 In gvd :In gvd :
“Up"
DataDisplay Any Expression ”this”
Then click on the fields of this to see the internal values
![Page 15: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/15.jpg)
08/03/2002 S. Ponce / EP-LBC 15
Demo (7)Demo (7)
thism_message is 0x0
We'll try to place a breakpoint where the initialization of m_message is done, i.e. In the constructor of Hello.
![Page 16: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/16.jpg)
08/03/2002 S. Ponce / EP-LBC 16
Demo (8)Demo (8)
In gvd :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 4gvd stops when the program reaches line 4
obviously the constructor was called with message = 0x0
Click "Up" to see where we came from
![Page 17: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/17.jpg)
08/03/2002 S. Ponce / EP-LBC 17
Demo (9)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 !
![Page 18: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/18.jpg)
08/03/2002 S. Ponce / EP-LBC 18
Demo (10)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
![Page 19: Debugging Under Linux](https://reader036.vdocuments.us/reader036/viewer/2022062500/568159a4550346895dc6fdff/html5/thumbnails/19.jpg)
08/03/2002 S. Ponce / EP-LBC 19
Demo (11)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