Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb debugger multiple source files

Tags:

c

gdb

When I attach gdb to a process that uses many source files, such as PHP, sometimes I want to set a breakpoint on line x of file y. How do I specify the file for gdb?

like image 937
Bhubhu Hbuhdbus Avatar asked Jun 03 '12 17:06

Bhubhu Hbuhdbus


People also ask

How does GDB find source files?

GDB has a list of directories to search for source files; this is called the source path. Each time GDB wants a source file, it tries all the directories in the list, in the order they are present in the list, until it finds a file with the desired name.

Can GDB debug assembly?

gdb will work in an ordinary terminal window, and this is fine for debugging assembly code. For use with higher-level source code, it is more convenient to use gdb from within the emacs editor (a good one to learn!) or using a graphical front-end like xxgdb or /pkgs/gnu/bin/ddd. The basic commands remain the same.

What is ESP in GDB?

The following registers are mentioned in the article: ESP (points to the top of the stack) EBP (is used as a reference when accessing local variables and arguments of the function) EIP (points to the address of the next instruction)


2 Answers

  1. gdb ./test.exe //test.exe is create by you program.
  2. b 117 //if only single file and line 117 is the function you want to run into b filename.c:110 //filename:line NO
  3. r //running the prog
  4. n
  5. c //continue
  6. s //sign in the function you want to test
  7. until 1120 //if there is for branch and you want to skip the brand, given 1120 is after the for branch

You can shorten almost all commands in GDB up to the point where they remain unambiguous.

like image 24
Victory2012 Avatar answered Oct 25 '22 02:10

Victory2012


It's as simple as:

b filename.c:XYZ

See the documentation for more info.

like image 90
Oliver Charlesworth Avatar answered Oct 25 '22 03:10

Oliver Charlesworth