Results 1 to 6 of 6
Hi all;
I'm using ubuntu 9.04.
I've started using "gdb" to debug my project line by line and have not worked with command
line debugger yet. So, I'm not familiar ...
- 07-07-2010 #1Just Joined!
- Join Date
- Sep 2009
- Posts
- 27
Problem in debugging with "GDB"?
Hi all;
I'm using ubuntu 9.04.
I've started using "gdb" to debug my project line by line and have not worked with command
line debugger yet. So, I'm not familiar with this type of debugging!
When I write "gdb ./myprogram" in terminal, I see:
And when I write "b 20" to set a breakpoint at 20th line of code, I see:Code:GNU gdb 6.8-debian Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i486-linux-gnu"...
Afterwards, when I run "r" command, I expect that the program runs till 20th line and then I can write "n" command line by line to see the parameters' values and memory contents, but I face with the program's complete running without any stop on line 20!!Code:Breakpoint 1 at 0x8048150: file ../sysdeps/i386/elf/start.S, line 20.
What is the solution please?!
TIA.
- 07-07-2010 #2
Did you compile the program with debugging options?
gcc -g -O2 myprogram.c -o myprogram- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 07-08-2010 #3
As a general rule, when debugging, you should compile the program without optimizations:
As Lakshmipathi says, "-g" enables debugging symbols, which allows gdb to better connect your code and the program.Code:gcc -g -O0 myprogram.c -o myprogram
Also be aware that there's a lot more code than what you wrote in your executable (the C library, your code, and any external libraries you use). Therefore, when you set a breakpoint, specify the file:
Code:b myprogram.c:20
DISTRO=Arch
Registered Linux User #388732
- 07-18-2010 #4Just Joined!
- Join Date
- Sep 2009
- Posts
- 27
Hi and thanks of your help!
When I write "b myprogram.cpp:20" in gdb, I see the result:
(while, I'm in myprogram.cpp directory, of course!)
And then, I type the "r" command, but the program runs completely without any stop on line 20!Code:No source file named myprogram.cpp. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (myprogram.cpp:20) pending.
What is the reason please?!
THX.
- 07-20-2010 #5
That is bizarre. gdb should know about your application's source code if you compiled your program with the "-g" flag.
If you open gdb, you can run the "info sources" command to see what source code files gdb knows about. That may give you an idea to the problem.DISTRO=Arch
Registered Linux User #388732
- 07-21-2010 #6Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
You are probably running the debugger/program in a different directory from the source. Use the full path if you can, or set it to stop in the function that the line is in. You can set break points at the entry poitns to a function call, lines in source files, etc. In any case, do read the man pages for gdb with some care.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote