arm-linux gdb remote debugging

Generally, cross-compilation already comes with gdb and gdbserver
paths: /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin

 If the cross compiler comes with gdb and gdbserver, you only need to copy gdbserver to the
/bin directory of the root file system of the development board

write a test application
 

#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
unsigned int times = 0;
while(1) {
printf("runing times:%d\r\n", times);
times++;
sleep(1);
}
}
arm-linux-gnueabihf-gcc gdbtest.c -o gdbtest -g //Compile the test program, pay attention to the -g option

After everything is ready, you can use GDB for debugging to ensure that ubuntu and the development board can communicate over the network.
Enter the following command on the development board:
gdbserver 192.168.1.253:2001 gdbtest //Start gdbserver on the development board
 

Then enter the following command in ubuntu to start the gdb debugging tool:
arm-linux-gdb gdbtest
 

The bottom (gdb) line is used to enter commands, enter the following command to connect to the development board:
target remote 192.168.1.251:2001 //connect to the development board
 

l command
l command (list) is used to list all program source codes,


b command
The b command (break) is used to set a breakpoint, and the abbreviation "b" can also be used, followed by a specific function or line number, such as "
break main" means to set a breakpoint at the main function, "break 11" in Line 11 sets a breakpoint.

c command
The c command is used to run to the breakpoint, enter the c command and the program will run until the next breakpoint,
 

s command
The s command (step) is a single-step execution, and this function will enter the function.
 

n command
The n command (next) is also single-step operation, but the n command will not enter the function.
 

p command
The p command (print) is used to print a variable value.
 

q command
The q command (quit) is used to quit debugging, and the gdbserver on the development board will also stop.
 

Common commands:

          start: Start to execute the program and stop at the first statement of the main function, abbreviated as: s.

          list: Display multiple lines of source code, shorthand: l.

          break line number: set a breakpoint, the program will stop at the breakpoint, abbreviation: b.

          continue: Continue the program until the next breakpoint is encountered, shorthand: c.

          print: print internal variable value

          kill: terminate the program being debugged

         watch: Set a monitoring point in the program to monitor changes in variables

        display: Track and view a certain variable, and display its value every time you stop

       delete line number: delete a breakpoint or watchpoint

       step: Execute the next statement, if the statement is a function call, enter the function to execute the first statement

       finish: If you have entered a function and want to exit the function and return to its calling function, you can use this command

      next: single-step execution, not traceable to the inside of the function

      jump: multiple breakpoints are set, it will jump to another breakpoint to continue execution, and start running at another point in the source program

     whatis variable or function: displays the type of a function or variable

       set variable set the value of the variable

      backtrace bt: view the information of the function call on the stack

      backtrace n = bt n : n is a positive integer, indicating that only the stack information on the top n layers of the stack will be printed;

                                       n is a negative integer, indicating that only the stack information of the bottom n layers of the stack will be printed 

    frame n : View the stack frame, n is an integer starting from 0, which is the layer number in the stack.

   up n: means to move n layers to the top of the stack, if n is not typed, it means to move up one layer

   down n: means to move to the bottom of the stack by n layers, if n is not typed, it means to move down one layer
 

Guess you like

Origin blog.csdn.net/L1153413073/article/details/125622344