Difference between revisions of "GDB"

From ArmadeusWiki
Jump to: navigation, search
m (Debugging on target from Host through Ethernet)
(Links)
 
(26 intermediate revisions by 5 users not shown)
Line 1: Line 1:
On this page you will find all you need to debug your applications running on your Armadeus board.
+
On this page you will find all you need to debug your userspace applications running on your Armadeus board.
  
First of all, be sure to have installed the [[Cross Compiler|Toolchain]]. During Cross Compiler configuration be sure to have choosen following options:
+
{{Note|First of all, be sure to have [[Toolchain|installed the Toolchain on your Host]].}}
Toolchain  ---> Build gdb server for the Target
+
Toolchain  ---> Build gdb for the Host
+
and optionally:
+
Toolchain  ---> Build gdb debugger for the Target
+
  
 
==Compile your program with debug symbols==
 
==Compile your program with debug symbols==
  $ export PATH=$PATH:./buildroot/build_armv4t/staging_dir/usr/bin/
+
* Use ''-g'' option of gcc:
 +
<pre class="host">
 +
$ make shell_env
 +
$ . armadeus_env.sh
 +
  $ export PATH=$PATH:$ARMADEUS_TOOLCHAIN_PATH
 +
 
 
  $ arm-linux-gcc -g -o hello hello.c
 
  $ arm-linux-gcc -g -o hello hello.c
 +
</pre>
 +
* If you have a Makefile for your project, you probably have a CFLAGS variable, so add it -g. Ex:
 +
<pre class="host">
 +
CFLAGS=-W -Wall -g
 +
</pre>
  
==Debugging on target from Host through Ethernet==
+
==Debugging a program running on your APF remotely from your Host (through Ethernet)==
 
* On the target launch your program like that:
 
* On the target launch your program like that:
 +
<pre class="apf">
 
  # gdbserver 192.168.0.2:2345 program [args]
 
  # gdbserver 192.168.0.2:2345 program [args]
192.168.0.2 is the IP address of your Host and 2345 the port number to use
+
</pre>
 +
''192.168.0.2'' is the IP address of your Host and ''2345'' the port number to use (examples).
  
* On your host launch:
+
* On your Host launch:
  [mypc]$ arm-linux-gdb program_name
+
<pre class="host">
  (gdb) set solib-absolute-prefix ./buildroot/build_armv4t/staging_dir/
+
  []$ arm-linux-gdb program
  (gdb) target remote 192.168.0.3:2345
+
  (gdb) set solib-absolute-prefix ./buildroot/output/build/staging_dir/
192.168.0.3 is the address of your target
+
  (gdb) target remote 192.168.0.10:2345
 +
</pre>
 +
''192.168.0.10'' is the address of your target
  
only ''continue (c)'' can be used to start program as it is always running when you launch GDB on your host
+
{{Note|Only ''continue / c'' can be used to start the program, because it is already running when you launch GDB on your host.}}
  
'''Core dump analysis doesn't seem to work in this use case !!'''
+
<pre class="host">
 +
(gdb) break main
 +
(gdb) continue
 +
...
 +
(gdb) next
 +
...
 +
</pre>
  
==Debugging directly on target==
+
* If the program is already running, gdbserver can attach itself to the process, if you give him its PID
You have to build gdb for the target and have a working NFS link between your target and your host.<br>
+
<pre class="apf">
On target launch GDB from your NFS mount like you do it usually:
+
# ps
  # /mnt/host/gdb your_prog
+
... get process PID
 +
# gdbserver 192.168.0.2:2345 --attach PID
 +
</pre>
 +
 
 +
{{Note|Core dump analysis doesn't seem to work in this use case (ie on the Host with arm-linux-gdb) !!}}
 +
 
 +
==Debugging directly on your APF (may require more memory)==
 +
* You have to build gdb for the target:
 +
<pre class="host">
 +
$ make menuconfig
 +
</pre>
 +
<pre class="config">
 +
Toolchain  --->
 +
        *** Gdb Options ***
 +
    [*] Build gdb debugger for the Target
 +
</pre>
 +
<pre class="host">
 +
$ make
 +
</pre>
 +
Then you can either reflash your rootfs, or copy ''$ARMADEUS_ROOTFS_DIR/usr/bin/gdb'' to your board, to a SD or to a NFS export.
 +
 
 +
* After installation, launch gdb on your APF:
 +
<pre class="apf">
 +
  # gdb your_prog
 +
</pre>
 
If you need argument passing:
 
If you need argument passing:
  # /mnt/host/gdb --args your_prog your_args
+
<pre class="apf">
 +
  # gdb --args your_prog your_args
 +
</pre>
 
To debug a Core dump:
 
To debug a Core dump:
  # /mnt/host/gdb your_prog -c your_core
+
<pre class="apf">
 +
  # gdb your_prog -c your_core_file
 +
</pre>
 +
 
 +
==Troubleshots==
 +
===pthread debugging===
 +
* If you see that kind of error message when using gdb:
 +
<pre class="apf">
 +
dlopen failed on 'libthread_db.so.1' - File not found
 +
GDB will not be able to debug pthreads.
 +
</pre>
 +
Don't worry ! ;-)<br>
 +
''libthread_db.so'' (db == debug) is a library that is needed when you want to debug programs using pthread. You will have to reconfigure the uClibc to get it build:
 +
<pre class="host">
 +
$ make uclibc-menuconfig
 +
</pre>
 +
<pre class="config">
 +
General Library Settings  --->
 +
    ...
 +
    [*] POSIX Threading Support
 +
    [*]  Build pthreads debugging support
 +
    ...
 +
</pre>
 +
 
 +
* Save your uClibc config and make it standard for next build:
 +
<pre class="host">
 +
$ cp buildroot/output/toolchain/uClibc-0.9.30.3/.config buildroot/target/device/armadeus/apfXX/uClibc.config.arm
 +
</pre>
 +
 
 +
* Then rebuild all the toolchain ('''this will erase your local modifications !!''')
 +
<pre class="host">
 +
$ rm -rf buildroot/output
 +
$ make
 +
</pre>
  
 
==Links==
 
==Links==
* http://sources.redhat.com/gdb/current/onlinedocs/gdb_5.html
+
* [https://www.sourceware.org/gdb/current/onlinedocs/gdb/index.html Debugging with GDB manual]
 
* http://www.kegel.com/linux/gdbserver.html
 
* http://www.kegel.com/linux/gdbserver.html
* http://www.linux-france.org/article/memo/node119.html
+
* [http://www.linux-france.org/article/memo/node119.html Déboguage avec gdb]
 +
* [[DDD| DDD (GDB graphical front end)]]
 +
* [[KGDB|KGDB (for kernel debugging)]]
  
{{LanguageBar|GDB|GDB|GDB}}
 
  
 
[[Category:Debug]]
 
[[Category:Debug]]

Latest revision as of 11:40, 3 June 2016

On this page you will find all you need to debug your userspace applications running on your Armadeus board.

Note Note: First of all, be sure to have installed the Toolchain on your Host.


Compile your program with debug symbols

  • Use -g option of gcc:
 $ make shell_env
 $ . armadeus_env.sh
 $ export PATH=$PATH:$ARMADEUS_TOOLCHAIN_PATH

 $ arm-linux-gcc -g -o hello hello.c
  • If you have a Makefile for your project, you probably have a CFLAGS variable, so add it -g. Ex:
CFLAGS=-W -Wall -g

Debugging a program running on your APF remotely from your Host (through Ethernet)

  • On the target launch your program like that:
 # gdbserver 192.168.0.2:2345 program [args]

192.168.0.2 is the IP address of your Host and 2345 the port number to use (examples).

  • On your Host launch:
 []$ arm-linux-gdb program
 (gdb) set solib-absolute-prefix ./buildroot/output/build/staging_dir/
 (gdb) target remote 192.168.0.10:2345

192.168.0.10 is the address of your target

Note Note: Only continue / c can be used to start the program, because it is already running when you launch GDB on your host.


 (gdb) break main
 (gdb) continue
...
 (gdb) next
...
  • If the program is already running, gdbserver can attach itself to the process, if you give him its PID
 # ps
... get process PID
 # gdbserver 192.168.0.2:2345 --attach PID
Note Note: Core dump analysis doesn't seem to work in this use case (ie on the Host with arm-linux-gdb) !!


Debugging directly on your APF (may require more memory)

  • You have to build gdb for the target:
 $ make menuconfig
Toolchain  --->
        *** Gdb Options ***
    [*] Build gdb debugger for the Target
 $ make

Then you can either reflash your rootfs, or copy $ARMADEUS_ROOTFS_DIR/usr/bin/gdb to your board, to a SD or to a NFS export.

  • After installation, launch gdb on your APF:
 # gdb your_prog

If you need argument passing:

 # gdb --args your_prog your_args

To debug a Core dump:

 # gdb your_prog -c your_core_file

Troubleshots

pthread debugging

  • If you see that kind of error message when using gdb:
dlopen failed on 'libthread_db.so.1' - File not found
GDB will not be able to debug pthreads.

Don't worry ! ;-)
libthread_db.so (db == debug) is a library that is needed when you want to debug programs using pthread. You will have to reconfigure the uClibc to get it build:

$ make uclibc-menuconfig
General Library Settings  --->
    ...
    [*] POSIX Threading Support
    [*]   Build pthreads debugging support
    ...
  • Save your uClibc config and make it standard for next build:
$ cp buildroot/output/toolchain/uClibc-0.9.30.3/.config buildroot/target/device/armadeus/apfXX/uClibc.config.arm
  • Then rebuild all the toolchain (this will erase your local modifications !!)
$ rm -rf buildroot/output
$ make

Links