MeeGo 1.2 Harmattan Developer Documentation Develop for the Nokia N9

Using GDB

The GNU Project Debugger (GDB) allows you to see what is going on inside an application while it executes, or what an application was doing at the moment it crashed.

To detect bugs, use the following main functions provided by GDB:

  • Start your program and specify anything that can affect its behaviour.
  • Make your program stop on specified conditions.
  • Examine what has happened when your program has stopped.
  • Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.


source: gdb

binary: gdb

Installing GDB on the Harmattan device

Install GDB through the developer mode applet.

Prerequisite: Developer mode must be enabled.

  1. Select Settings > Security > Developer mode.
  2. Install the Debugging bundle package by clicking Install.
  3. You get a notification screen that lists all the applications to be installed in the bundle package. To install, click OK.
  4. A dependency notice appears. Click Accept.

For more information on developer mode and installable tools, see Activating developer mode.

Installing debug symbols

In order to view any useful profiling information at functions level, you have to install debugging symbols. Debug symbols normally come with debugging (-dbg) packages. The easiest way to install all dbg packages required for a given binary is to use debug-dep-install script which comes with the maemo-debug-scripts package. Install maemo-debug-scripts with the developer mode applet. For more information, see maemo-debug-scripts.

Using the tool

You can use the GDB tool both in Qt Creator and Scratchbox environments.

Qt Creator has a debugger plugin that acts as an interface between Qt Creator and GDB. For instructions on debugging in Qt Creator, see Qt documentation.

For instructions on how to debug Harmattan applications in the Scratchbox environment, see Debugging with GDB in Scratchbox.

  • To trace how many calls to a specific function or method have occurred and their origin, set a breakpoint on the function or method and ask GDB to show backtrace and continue whenever that breakpoint is hit. Enter the following command:
 (gdb) set pagination 0              # do not stop after every screenful
 (gdb) break QObject::deleteLater
 Breakpoint 1, QObject::deleteLater (this=0x2c6040) at kernel/qobject.cpp:2129
 (gdb) commands 1                    # commands to execute on hitting breakpoint 1
 Type commands for breakpoint(s) 1, one per line.
 End with a line saying just "end".
 >bt 3                               # show only topmost 3 callers for breakpoint
 >cont                               # ...then continue
 (gdb) cont

Note: If you also need call graphs, use, for example, functracer -a option and post-process the result with sp-rtrace utilities.

  • To print out arbitrary information on a given function entry points:
1. Enter the following command:
  (gdb) commands 1
  Type commands for breakpoint(s) 1, one per line.
  End with a line saying just "end".
  >shell pmap -x $(pidof widgetsgallery)|grep heap
  (gdb) cont
2. Complete a use case and look at the relevant information.
3. Press Enter on the console to separate the output from different use cases:
 000af000    2624    2336    2336       0  rw-p  [heap]
 000af000    2624    2360    2360       0  rw-p  [heap]
 000af000    2624    2360    2360       0  rw-p  [heap]
 000af000    2624    2380    2380       0  rw-p  [heap]
 000af000    2624    2380    2380       0  rw-p  [heap]
 000af000    2624    2404    2404       0  rw-p  [heap]
 000af000    2624    2400    2400       4  rw-p  [heap]
  • To view the information when returning to the GDB prompt, enter the following command:
 (gdb) define hookpost-next
 Type commands for definition of "hookpost-next".
 End with a line saying just "end".
 >shell pmap -x $(pidof widgetsgallery)|grep heap

If you want to set breakpoints on all functions matching a regular expression, use rbreak.

Further information

For more information on the tool, see the following links: