GDB and gdbserver of Linux kernel debugging technology

Source: Internet
Author: User
Tags bz2

1, debugging principle

GDB debugging is the application running on the development Board, then on the PC on the Development Board to debug the application , the PC runs GDB, the Development Board runs Gdbserver. When debugging the application, GDB on the PC sends commands to the Gdbserver on the Development Board, and the gdbserver on the board signals the application to stop or do some other work.

2. Installing GDB and Gdbserver (GDB-7.4.TAR.BZ2)

2.1. GDB1. Download: http://ftp.gnu.org/gnu/gdb/2, Decompression: Tar xvf gdb-7.4.tar.bz23. Configuration: CD gdb-7.4/./configure--target=arm-linux4. Compiling: make5. Installation: mkdir tmpMake install prefix= $PWD/tmp6. Copy: CP tmp/bin/arm-linux-gdb/bin/7. View version/bin/arm-linux-gdb-v (using GDB with absolute path)2.2, GDBServer1. CD gdb/gdbserver/2, configuration:./configure--target=arm-linux--host=arm-linux3. Compiling: Make CC=ARM-LINUX-GCC 2.3. When compiling gdbserver, the following error will occur
linux-arm-low.c:in function ' Arm_stopped_by_watchpoint':linux-arm-low.c:642: ' ERROR: ' Ptrace_getsiginfo'  undeclared (first use with this function) LINUX-ARM-LOW.C:642 is reported Oncelinux-arm-low.c:642for in.)

the error is because the PTRACE_GETSIGINFO macro could not be found, resulting in a compilation error. We go to the cross-compilation chain to search, we cross-compile the address to/work/tools/gcc-3.4.5-glibc-2.3.6

# cd/work/tools/gcc-3.4.5-glibc-2.3.6# grep"Ptrace_getsiginfo"* -Nrarm-linux/sys-include/linux/ptrace.h: -:#definePtrace_getsiginfo 0x4202Arm-linux/include/linux/ptrace.h: -:#definePtrace_getsiginfo 0x4202Distributed/arm-linux/sys-include/linux/ptrace.h: -:#definePtrace_getsiginfo 0x4202Distributed/arm-linux/include/linux/ptrace.h: -:#definePtrace_getsiginfo 0x4202

As you can see, in the cross-compilation chain, the Ptrace_getsiginfo macro is defined as 0x4202 and the header file is include<linux/ptrace.h>.

There are two solutions that can be selected as one of the following:

① add macros directly to the LINUX-ARM-LOW.C #define PTRACE_GETSIGINFO 0x4202

② Change # include <sys/ptrace.h> to #include <linux/ptrace.h> in linux-arm-low.c

Compile again and compile through.

2.4. Copy the Gdbserver to the bin directory of the Development Board
#cp Gdbserver/work/nfs_root/first_fs/bin

3. Commissioning3.1. When compiling the application to be debugged, add-GThe test procedure is as follows (TEST_DEBUG.C)   
#include <stdio.h>voidCint*p) {    *p =0x12;}voidBint*p) {C (P);}voidAint*p) {B (P);}voidA2 (int*p) {C (P);}intMainintargcChar**argv) {    intA; int*p =NULL; A2 (&AMP;A);//A2 > Cprintf"A = 0x%x\n", a);    A (P); //A > B > C    return 0;}

Compile:

#arm-linux-gcc-g-o test_debug test_debug.c
3.2, on the Development Board:Print out the following information:
#gdbserver 192.168.1.10:123./test_debug
7512345

notes: 192.168.1.10: The IP of the Development Board123: Port number, I write it casually./test_debug: The program to debug3.3, enter on the PC:
/bin/arm-linux-gdb./test-Debug           192.168.  183.127:2345
3.4, the formal commissioning! Introduce a few common commands(1) L: List all source Codes(2) Break main: Breaking point at Mainbreak test_debug.c:11: Interrupt point at line 11 of Test_debug.c(3) C: Run to break point(4) Step: Single Step execution(5) Next: Step, but step will enter the function, but next will not(6) Print a: Print the value of a variable(7) Quit: Exit, enter this command the Gdbserver on the Development Board also exits(8) Verbose gdb debug Command4, another kind of debugging methodlet the program run directly on the board, and when it is wrong, make it produce a core dump file,then use GDB to find where the error occurred based on the core dump file on the ARM board:
4.1, Ulimit-c unlimited
4.2. Execute the application: A file named core is generated in the current directory when the program fails on the PC:4.3. First copy the core file to the PCthen:/bin/arm-linux-gdb./test_debug./core Print out the following information:
GNU gdb (GDB)7.4Copyright (C) -Free software Foundation, Inc.license GPLv3+: GNU GPL version3or later //gnu.org/licenses/gpl.html>This isFree software:you is free-to-change and redistribute it. There isNO WARRANTY, to the extent permitted by law. Type"Show Copying" and"Show Warranty"  fordetails. This GDB is configured as "--host=i686-pc-linux-gnu--target=arm-linux". For bugs reporting instructions, please see://Www.gnu.org/software/gdb/bugs/>, .....Reading symbols from/home/share/jz2440/Test_debug...done. [New LWP748]warning: '/lib/libc.so.6': Shared Library architecture unknown is not compatible with target architecture arm.Warning: '/lib/ld-linux.so.2': Shared Library architecture unknown is not compatible with target architecture arm.Core is generated by './test_debug'.Program terminated with Signal One, segmentation fault.#0  0X000084AC inchC (p=0x0) at TEST_DEBUG.C:66*p =0x12;

4.4, BT: can display the call relationship
#0  0X000084AC inchC (p=0x0) at TEST_DEBUG.C:6#1  0x000084d0 inchB (p=0x0) at TEST_DEBUG.C: A#2  0x000084f0 inchA (p=0x0) at TEST_DEBUG.C: -#3  0x00008554 inchMain (argc=1, argv=0XBEB32EB4) at TEST_DEBUG.C: the

GdB and gdbserver of Linux kernel debugging technology

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.