Debug Apps

cancel
Showing results for 
Search instead for 
Did you mean: 

Debug Apps

Debug Apps

This page describes a remote debug session of user space application through ethernet/tcp or serial (but not jtag), taking hello as an example. This nios2-linux-uclibc-insight uses ptrace support of Linux kernel. When it hits a breakpoint, all the other processes still running. This is very different from the nios2-elf-insight, where all processes are stopped. When you are debugging complex programs, you can even run a jtag session for kernel ,and two or more ethernet sessions for client/server. This work is contributed by Atle. Best thanks to him.

The insight/gdb are included in the BinaryToolchain.

 

To verify the insight gdb, try out,

nios2-linux-uclibc-insight -v

It should display the info,

GNU gdb 6.1

Copyright 2004 Free Software Foundation, Inc.

GDB is free software, covered by the GNU General Public License, and you are

welcome to change it and/or distribute copies of it under certain conditions.

Type "show copying" to see the conditions.

There is absolutely no warranty for GDB. Type "show warranty" for details.

This GDB was configured as "--host=i686-pc-linux-gnu --target=nios2-linux-uclibc".

 

You will need to pull the lastest git updates and select "gdbserver (old)" from "Miscellaneous Applications" in uClinux-dist config.

 

Then compile the application with debug symbols and no optimization, copy the generated hello to romfs/bin .

nios2-linux-uclibc-gcc -g hello.c -o hello -elf2flt

 

Build the image, start uClinux, and config the ethernet ip, eg 192.168.1.29 . The start the gdbserver listening on an unused port eg 9999,

gdbserver localhost:9999 /bin/hello

It will display,

Process /bin/hello created; pid = 20

Listening on port 9999

 

Next, on your Linux PC,you start gdb or the wrapper around gdb, you want to use. 

 

gdb

in the hello source dir, run gdb:

nios2-linux-uclibc-gdb hello.gdb

<p>(gdb) target remote 192.168.1.29:9999

Then it will report the target address of the program. Now you can set break points and debug.

 

The gdb supports srcipt files, so you can them to save time e.g. you can put a file .gdbinit in the hello source dir containing the line target remote 192.168.1.29:9999. Now this command is automatically executed whenever gdb starts in this directory.

 

gdbtui

in the hello source dir, run gdbtui:

nios2-linux-uclibc-gdbtui hello.gdb

(gdb) target remote 192.168.1.29:9999

Then it will report the target address of the program. Now you can set break points and debug.

The gdb supports srcipt files, so you can them to save time e.g. you can put a file .gdbinit in the hello source dir containing the line target remote 192.168.1.29:9999. Now this command is automatically executed whenever gdb starts in this directory.

 

insight

in the hello source dir, run insight:

nios2-linux-uclibc-insight hello.gdb

A source window will open and display the source hello.c .

The open a gdb console, with View--> Console. You can enter gdb commands in this window:

(gdb) target remote 192.168.1.29:9999

Then it will report the target address of the program. Now you can set break points and debug.

The gdb supports srcipt files, so you can them to save time e.g. you can

put a file .gdbinit in the hello source dir containing the line target remote 192.168.1.29:9999. Now this command is automatically executed whenever gdb starts in this directory.

 

ddd

in the hello source dir, run ddd:

ddd --debugger nios2-linux-uclibc-gdb hello.gdb

A source window will open and display the source hello.c .

The open a gdb console, with Alt-1. You can enter gdb commands in this window:

(gdb) target remote 192.168.1.29:9999

Then it will report the target address of the program. Now you can set break points and debug.

The gdb supports srcipt files, so you can them to save time e.g. you can

put a file .gdbinit in the hello source dir containing the line target remote 192.168.1.29:9999. Now this command is automatically executed whenever gdb starts in this directory.

 

Eclipse

See the appropriate article in this Wiki.

 

 

This page describes a debug session of user space application, taking boa as an example.

You will need to select "debug' from "Miscellaneous Applications" in uClinux-dist config.

This is a gdbserver helper which places a "break" instruction at the beginning of user application.

First, follow DebugKernel to setup insight gdb and start kernel, (the follow log are from gdb console, as it is easier to follow)

 

GNU gdb 6.1

Copyright 2004 Free Software Foundation, Inc.

GDB is free software, covered by the GNU General Public License, and you are

welcome to change it and/or distribute copies of it under certain conditions.

Type "show copying" to see the conditions.

There is absolutely no warranty for GDB. Type "show warranty" for details.

This GDB was configured as "--host=i686-pc-linux-gnu --target=nios2-elf".

Using cable "USB-Blaster [USB 5-1.8.2]", device 1, instance 0x00

Resetting and pausing target processor: OK

Listening on port 2342 for connection from GDB: accepted

0x02000000 in ?? ()

Loading section .text, size 0x1717e8 lma 0x0

Loading section .rodata, size 0x17374 lma 0x172000

Loading section __param, size 0x168 lma 0x189374

Loading section .data, size 0x9ba4 lma 0x18a000

Loading section .init.text, size 0xdb58 lma 0x194000

Loading section .init.data, size 0xb5c lma 0x1a1b58

Loading section .init.setup, size 0x1c8 lma 0x1a26c0

Loading section .initcall.init, size 0xf8 lma 0x1a2888

Loading section .con_initcall.init, size 0x4 lma 0x1a2980

Loading section .exit.text, size 0x310 lma 0x1a2984

Loading section .init.ramfs, size 0x8b91a lma 0x1a3000

Start address 0x0, load size 2280970

Transfer rate: 1216517 bits/sec, 511 bytes/write.

Breakpoint 1 at 0x5280: file arch/nios2nommu/kernel/start.c, line 384.

warning: No source file has been specified.

 

Breakpoint 1, main () at arch/nios2nommu/kernel/start.c:384

384    int main(void) {

 

# delete the old break point, continue booting Linux,

 

(gdb) del 1

(gdb) c

Continuing.

 

# open nios2-terminal on another shell terminal, Nios2 uClinux will boot to the prompt, enter debug <user apps>,

 

Sash command shell (version 1.1.1)

/> debug boa

DEBUG: running "boa" ...

 

# the user apps stopped at the beginning,

 

Program received signal SIGTRAP, Trace/breakpoint trap.

0x001c0050 in ?? ()

 

# remove old symbol file of kernel

 

(gdb) symbol-file

Discard symbol table from `/home/thomas/uClinux-dist/linux-2.6.x/vmlinux'? (y or n) y

No symbol file now.

 

# read symbol file of user apps, we know the address from $pc ,

 

(gdb) add-symbol-file user/boa/src/boa.gdb $pc

add symbol table from file "user/boa/src/boa.gdb" at

       .text_addr = 0x1c0050

(y or n) y

Reading symbols from user/boa/src/boa.gdb...done.

 

# set break point at boa's main()

 

(gdb) b main

Breakpoint 2 at 0x1c1198: file boa.c, line 102.

(gdb) c

Continuing.

 

Breakpoint 2, main (argc=1, argv=0x1fffa0) at boa.c:102

102            openlog("boa", LOG_PID, 0);

 

# we can debug now,

 

(gdb) l

97     int main(int argc, char **argv)

98     {

99             int c;                                         /* command line arg */

100            int s_port = 80;

101

102            openlog("boa", LOG_PID, 0);

103    #ifdef SERVER_SSL

104            while ((c = getopt(argc, argv, "p:vc:dns")) != -1) {

105    #else

106            while ((c = getopt(argc, argv, "p:vc:d")) != -1) {

(gdb) 

 

Version history
Last update:
‎11-01-2020 02:56 PM
Updated by: