Community
cancel
Showing results for 
Search instead for 
Did you mean: 

Debug Kernel

Debug Kernel

You can use insight GDB GUI to debug kernel. Insight is the (same) GDB integrated with GUI interface.

You must include JTAG debug module in SOPC Builder. Using level 1 is OK. But level 2 is better, as it supports two hardware data watchpoints. (Placing a hardware data watchpoint as "awatch *(int *)0" is very useful to catch a common NULL pointer dereference bug.)

The debug info (-g) is disabled by default. To enable debug info,

 

Kernel hacking -->

[*] Kernel debugging

[*] Compile the kernel with debug info

 

To disable optimization of your driver, add rule like this to your Makefile, eg, driver/net/Makefile,

 

CFLAGS_atse.o = -O0

 

You may find more info from linux-2.6/Documentation/kbuild/makefiles.txt

 

The kernel object file is linux-2.6.x/vmlinux, which is an ELF format object containing debug information. You can not use zImage here, as the debug information is stripped off. You may use the same method to debug u-boot or others. If you want to debug kernel modules or user space programs, you need will more setup than what is described here. The debugging of user space programs will be discussed in another wiki later.

 

1. You will need USB-blaster and jtagd properly configured. Run "jtagconfig" to verify it is working. You may refer to <a href="/OperatingSystems/UClinux/QuartusforLinux">QuartusforLinux , <a href="/LinuxGdbServer">LinuxGdbServer or alteraforum for related.

 

2. Configure sof

nios2-configure-sof path_to/your_system.sof

 

3. Edit a file, say linux.gdb, containing gdb startup commands. You may add more break points to the codes which you want to debug.

This is optional, but it is handy to use a command file rather than do it by hand.

file linux-2.6.x/vmlinux

target remote localhost:2342

load linux-2.6.x/vmlinux

break *start_kernel

jump *_start

 

4. Edit a short shell script, say debuglinux.sh, to start gdb-server to listen at, say 2342 port, and start insight. Remember to do chmod +x debuglinux.sh . You can also modify nios2-debug to do the same job.

nios2-gdb-server-wrapped --reset-target --tcpport 2342 &

nios2-elf-insight --command=path_to/linux.gdb

 

5. If you use jtag uart for console, you need to start "nios2-terminal". Then start debugger.

cd uClinux-dist

path_to/debuglinux.sh

If all goes well you'll see the the following message:

Using cable "USB-Blaster [USB 4-1.2]", device 1, instance 0x00

Pausing target processor: OK

Listening on port 2342 for connection from GDB: accepted

 

6/66/Screenshot-main.c_-_Source_Window.png ( Screenshot-main.c - Source Window.png - click here to view image )

 

6. Wait about 1 minute. The insight GUI will come out with a source code window, stopped at main() in start.c . You can begin debugging now.

  • You may find more insight usage from Redhat GNUPro Debugger Tools PDF (2454 KB).
  • You may also find GDB manual at your nios2eds installation, file:///opt/altera7.2/nios2eds/documents/gnu-tools/gdb/gdb.html.

 

To debug module, see Module section offsets in /sys/module (LWN.net).

kernel config, General setup ---> [*] Configure standard kernel features (for small systems) ---> [*] Load all symbols for debugging/ksymoops

Then, you can find the section locations of module, and add symbols.

Version history
Revision #:
2 of 2
Last update:
‎11-01-2020 02:57 PM
Updated by: