Getting started with GDB debugging
Submitted by Bob Spencer, updated on 5 Aug 2009 - 1 comment
This is a very brief introduction to using gdb to debug your project. It is easy to get started. For more information, google: gdb tutorial.
Prepare the project
Source code
You can use the sample clutter code, or preferably your own project source.
Compile with debug symbols
To debug your source you must compile with debugging symbols turned on. Example command-line compilation for a C application:
$ <cd to source directory>
$ gcc -g3 -O0 -ggdb <source files> -o <output binary name>Example showing command-line build for sample clutter project:
$ gcc `pkg-config --cflags --libs clutter-0.9` -g3 -O0 -ggdb src/helloworld.c -o src/helloworld If your project is built using the automake/autoconf tools, include the debugging flags in the AM_CFLAGS variable in the Makefile.am located in the source directory. Then rebuild.
# inside the Makefile.am
AM_CFLAGS = -g3 -O0 -ggdb ...
# now rebuild from the command-line
$ ./autogen.sh
$ makeDebugging your project
The following shows starting gdb, setting a breakpoint at the first line of the project, and displaying 10 lines of the code around the breakpoint.
$ gdb src/helloworld
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"...
(gdb) b main
Breakpoint 1 at 0x8049586: file src/helloworld.c, line 185.
(gdb) r
Starting program: /home/bob/src/moblin2/sample_apps/src/helloworld
[Thread debugging using libthread_db enabled]
[New Thread 0xb772ca40 (LWP 14412)]
[Switching to Thread 0xb772ca40 (LWP 14412)]
Breakpoint 1, main (argc=1, argv=0xbf92f664) at src/helloworld.c:185
185 {
(gdb) l
180 }
181 return FALSE;
182 }
183
184 int main (int argc, char **argv)
185 {
186 const ClutterColor scn_bkgd = {0x00,0x00,0xFF,0xFF};
187 ClutterActor *stage;
188
189 srand(time(NULL)); //for random colors
(gdb) Next Steps
Running gdb from the command-line is nifty but given that you can't see your code as you step through it, it is less than optimal. Combining gdb with one of the following source editing tools is highly recommended.
- Printer-friendly version
- Login or register to post comments
Comments (1 total)
Link error
The link "Getting started developing with Anjuta DevStudio" is not correct in the page http://moblin.org/documentation/moblin-sdk/coding-tutorials/getting-star....
Report 404 error.