Top Banner
06/21/22 S. Ponce / EP-LBC 1 Debugging Under Linux Sebastien Ponce Sebastien Ponce Friday, 8 March 2002 Friday, 8 March 2002
19

17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

Jan 18, 2018

Download

Documents

08/03/2002S. Ponce / EP-LBC3 When to Use a Debugger ?  If you compiled in debug mode : When you want to trace an application execution (breakpoints, step in,...)When you want to trace an application execution (breakpoints, step in,...) When you want to know where the execution crashes (segmentation fault is handled)When you want to know where the execution crashes (segmentation fault is handled)  If you compiled in optimize mode : You can still know which functions were called and which one failedYou can still know which functions were called and which one failed
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

05/04/23 S. Ponce / EP-LBC 1

Debugging Under Linux

Sebastien PonceSebastien PonceFriday, 8 March 2002Friday, 8 March 2002

Page 2: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

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: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

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: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

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: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

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 athttp://libre.act-europe.fr/gvd/ Very easy to install locally

PREFERED CHOICEPREFERED CHOICE

Page 6: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

08/03/2002 S. Ponce / EP-LBC 6

Launching gvdLaunching gvd

Launching gvd :Launching gvd :source setup.cshgvd <executable>

Inside gvd :Inside gvd :[set breaking points]run <options>

In case of core dump :In case of core dump :source setup.cshgvd <executable>

Inside gvd :Inside gvd :FileOpen Core Dump <core>

Page 7: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

08/03/2002 S. Ponce / EP-LBC 7

gvd Basicsgvd Basics

Menu bar

Tool barCall stack

Source files

Gdb window

Data display

Current Line

Source code

Page 8: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

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 mainrun <options>run <options>next next here we loaded the ApplicationMgr here we loaded the ApplicationMgrbreak ApplicationMgr::configurebreak ApplicationMgr::configurecontcontfinish finish now every dll is loaded now every dll is loaded

Page 9: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

08/03/2002 S. Ponce / EP-LBC 9

Demo (1)Demo (1)

Launch :Launch :tar xvf demo.tarcd demomake./hello

Segmentation Fault

gvd hello

Page 10: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

08/03/2002 S. Ponce / EP-LBC 10

Demo (2)Demo (2)

gdb windows :gdb windows :(gdb) runStarting Program: /home/sponce/demo/hello

Program received signal SIGSEGV, Segmentation fault0x400e1630 in strcmp() from /lib/libc.so.6(gdb)

In menuIn menuData Call Stack

In Tool BarIn Tool BarUp

Page 11: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

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: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

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: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

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./helloSegmentation Faultgvd hello

In gvdIn gvdrun

There is another bug !There is another bug !

Page 14: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

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: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

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: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

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 thereClick runSay you want to start from beginning

gvd stops when the program reaches line 4gvd stops when the program reaches line 4obviously the constructor was called with message = 0x0Click "Up" to see where we came from

Page 17: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

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: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

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: 17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.

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