Home Backend Development C++ OKMX-C GDB Remote Debugging Skills

OKMX-C GDB Remote Debugging Skills

Dec 01, 2024 pm 10:18 PM

OKMX-C GDB Remote Debugging Skills

In the field of embedded development, debugging is a critical step to ensure the stable operation of a program. For developers using the OKMX8MP-C development board, mastering GDB remote debugging techniques can significantly enhance development efficiency. GDB, short for The GNU Project Debugger, is a comprehensive debugging tool under Linux. GDB supports a variety of debugging methods, including setting breakpoints, single-step execution, printing variables, observing variables, examining registers, and viewing the call stack.

In Linux environment software development, GDB is the primary debugging tool used to debug C and C programs. OKMX8MP-C's 5.4.70 version comes with default support for gdbserver, and our provided development environment also supports gdb by default. Next, will detail how to perform GDB remote debugging on the OKMX8MP-C.

  1. Preparation Before Compilation Before performing GDB debugging, it is essential to ensure that the application has been correctly compiled and includes debugging information. This can be achieved by adding the -g option during compilation. For example:

forlinx@ubuntu:~$ $CC -g test_bug.c -o test_bug

This command will compile the test_bug.c source file and generate an executable file test_bug with debugging information included. This way, GDB can accurately locate the corresponding positions in the source code during subsequent debugging processes.

After compilation, the generated executable file needs to be copied to the development board. This is typically achieved via serial port, network, or other file transfer methods. In this example, we assume that the test_bug file has been copied to the / directory on the development board.

  1. Development Board IP and Starting gdbserver Settings Next, you need to set the IP address on the development board and start the gdbserver service. The specific steps are as follows:

Set the IP Address:

Use the ifconfig command to set the IP address for the development board. For example:

ifconfig eth0 172.16.0.109

Here, the development board's IP address is set to 172.16.0.109

Start gdbserver on the development board, specifying the listening port number and the program to be debugged. For example:

gdbserver 172.16.0.109:2345 /test_bug

This command will start gdbserver and listen on port 2345 for connection requests from the GDB client.

root@OK8MP:~# ifconfig eth0 172.16.0.109
root@OK8MP:~# gdbserver 172.16.0.109:2345 test_bug
Process /home/root/test_bug created; pid = 1356
Listening on port 2345
On the virtual machine or host, set an IP address within the same network segment as the development board and use the ping command to test connectivity with the development board.

Ensure successful pinging of the development board's IP address, which is a prerequisite for remote debugging.

  1. Starting the GDB Client and Connecting to the Development Board Start the GDB client:

On the virtual machine or host, use the aarch64-poky-linux-gdb command to start the GDB client and specify the program to be debugged. For example:

forlinx@ubuntu:~/ aarch64-poky-linux-gdb test_bug
GNU gdb (GDB) 8.3.1
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3 : GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details. This GDB was configured as "--host=x86_64-pokysdk-linux --target=aarch64-poky-linux".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from test_bug...
(gdb)
Connect to the board:

In the GDB client, use the target remote command to connect to gdbserver on the board. For example:

(gdb) target remote 172.16.0.109:2345
Remote debugging using 172.16.0.109:2345
Reading /lib/ld-linux-aarch64.so.1 from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access file s locally instead.
Reading /lib/ld-linux-aarch64.so.1 from remote target...
Reading symbols from target:/lib/ld-linux-aarch64.so.1...
Reading /lib/ld-2.30.so from remote target...
Reading /lib/.debug/ld-2.30.so from remote target...
Reading /lib/.debug/ld-2.30.so from remote target...
Reading symbols from target:/lib/.debug/ld-2.30.so...
0x0000fffff7fcf080 in _start () from target:/lib/ld-linux-aarch64.so.1
(gdb)
At this point, the GDB client connects to gdbserver on the board and is ready to begin remote debugging.

  1. Remote Debugging Upon successful connection, you can start using various GDB debugging commands for remote debugging. Below are some commonly used debugging commands:

l (list): Lists source code.

b (break): Sets a breakpoint.

n (next): Steps through the code line by line.

s (step): Steps into functions for line-by-line execution.

c (continue): Continues program execution.

p (print): Prints the value of a variable.

For example, use the l command to view the source code at the current location:

(gdb) l
12 }
13
14 void A(int *p)
15 {
16 B(p);
17 }
18
19 void A2(int *p)
20 {
21 C(p);
(gdb)

Then, you can use the B command to set a breakpoint on a line, such as line 16:

bash copy code

(gdb) b 16

Breakpoint 1 at 0x...: file test_bug.c, line 16.

Use the c command to continue executing the program. The program will pause at the breakpoint, waiting for further debugging.

  1. Debugging Techniques and Precautions Breakpoint Management: Setting breakpoints appropriately can significantly improve debugging efficiency. Use the d command to delete breakpoints. Use the info b command to view all current breakpoints.

Variable Monitoring: Use the watch command to monitor variable changes. GDB will automatically pause execution when the variable's value changes.

Multithreaded Debugging: If program is multithreaded, use thread command to switch threads for debugging.

Security Considerations: Ensuring network environment security is crucial during remote debugging. Use SSH tunnels or other encryption methods to protect debugging data transmission.

That's all OKMX8MP-C GDB remote debugging skills. This powerful tool enables efficient issue resolution and development enhancement.

The above is the detailed content of OKMX-C GDB Remote Debugging Skills. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

C language data structure: data representation and operation of trees and graphs C language data structure: data representation and operation of trees and graphs Apr 04, 2025 am 11:18 AM

C language data structure: The data representation of the tree and graph is a hierarchical data structure consisting of nodes. Each node contains a data element and a pointer to its child nodes. The binary tree is a special type of tree. Each node has at most two child nodes. The data represents structTreeNode{intdata;structTreeNode*left;structTreeNode*right;}; Operation creates a tree traversal tree (predecision, in-order, and later order) search tree insertion node deletes node graph is a collection of data structures, where elements are vertices, and they can be connected together through edges with right or unrighted data representing neighbors.

The truth behind the C language file operation problem The truth behind the C language file operation problem Apr 04, 2025 am 11:24 AM

The truth about file operation problems: file opening failed: insufficient permissions, wrong paths, and file occupied. Data writing failed: the buffer is full, the file is not writable, and the disk space is insufficient. Other FAQs: slow file traversal, incorrect text file encoding, and binary file reading errors.

What are the basic requirements for c language functions What are the basic requirements for c language functions Apr 03, 2025 pm 10:06 PM

C language functions are the basis for code modularization and program building. They consist of declarations (function headers) and definitions (function bodies). C language uses values ​​to pass parameters by default, but external variables can also be modified using address pass. Functions can have or have no return value, and the return value type must be consistent with the declaration. Function naming should be clear and easy to understand, using camel or underscore nomenclature. Follow the single responsibility principle and keep the function simplicity to improve maintainability and readability.

Function name definition in c language Function name definition in c language Apr 03, 2025 pm 10:03 PM

The C language function name definition includes: return value type, function name, parameter list and function body. Function names should be clear, concise and unified in style to avoid conflicts with keywords. Function names have scopes and can be used after declaration. Function pointers allow functions to be passed or assigned as arguments. Common errors include naming conflicts, mismatch of parameter types, and undeclared functions. Performance optimization focuses on function design and implementation, while clear and easy-to-read code is crucial.

How to calculate c-subscript 3 subscript 5 c-subscript 3 subscript 5 algorithm tutorial How to calculate c-subscript 3 subscript 5 c-subscript 3 subscript 5 algorithm tutorial Apr 03, 2025 pm 10:33 PM

The calculation of C35 is essentially combinatorial mathematics, representing the number of combinations selected from 3 of 5 elements. The calculation formula is C53 = 5! / (3! * 2!), which can be directly calculated by loops to improve efficiency and avoid overflow. In addition, understanding the nature of combinations and mastering efficient calculation methods is crucial to solving many problems in the fields of probability statistics, cryptography, algorithm design, etc.

Concept of c language function Concept of c language function Apr 03, 2025 pm 10:09 PM

C language functions are reusable code blocks. They receive input, perform operations, and return results, which modularly improves reusability and reduces complexity. The internal mechanism of the function includes parameter passing, function execution, and return values. The entire process involves optimization such as function inline. A good function is written following the principle of single responsibility, small number of parameters, naming specifications, and error handling. Pointers combined with functions can achieve more powerful functions, such as modifying external variable values. Function pointers pass functions as parameters or store addresses, and are used to implement dynamic calls to functions. Understanding function features and techniques is the key to writing efficient, maintainable, and easy to understand C programs.

CS-Week 3 CS-Week 3 Apr 04, 2025 am 06:06 AM

Algorithms are the set of instructions to solve problems, and their execution speed and memory usage vary. In programming, many algorithms are based on data search and sorting. This article will introduce several data retrieval and sorting algorithms. Linear search assumes that there is an array [20,500,10,5,100,1,50] and needs to find the number 50. The linear search algorithm checks each element in the array one by one until the target value is found or the complete array is traversed. The algorithm flowchart is as follows: The pseudo-code for linear search is as follows: Check each element: If the target value is found: Return true Return false C language implementation: #include#includeintmain(void){i

C language multithreaded programming: a beginner's guide and troubleshooting C language multithreaded programming: a beginner's guide and troubleshooting Apr 04, 2025 am 10:15 AM

C language multithreading programming guide: Creating threads: Use the pthread_create() function to specify thread ID, properties, and thread functions. Thread synchronization: Prevent data competition through mutexes, semaphores, and conditional variables. Practical case: Use multi-threading to calculate the Fibonacci number, assign tasks to multiple threads and synchronize the results. Troubleshooting: Solve problems such as program crashes, thread stop responses, and performance bottlenecks.

See all articles