Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Embedded development / debugging aids

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Composition of development environment for development aids

Typically, the development environment consists of three parts:

Build environment: including code writing, program compilation, version control and other functions.

Debugging environment: an auxiliary toolset for locating problems

Test environment: explicit and implicit requirements used to verify that the target program meets user requirements

In embedded development, 20% of the time is spent on target construction, and 80% of the time is spent on testing, debugging and bug repair. GNU provides an auxiliary tool set (Binutils) for the GCC compiler at http://www.gnu.org/software/binutils/

Development toolset addr2line

Converts the specified address to the corresponding file name and line number, which is often used to analyze and locate memory errors

Addr2line example: location 0 address access

# include int g_global = 0tint g_test = 1bter int* gallepointerextern void func (); int main (int argc, char * argv []) {printf ("& g_global =% p\ n", & g_global); printf (& g_test =% p\ n ", & g_test); printf (" & g_pointer =% p\ n ", & g_pointer); printf (" g_pointer =% p\ n ", g_pointer) Printf (& func =% p\ n ", & func); printf (" & main =% p\ n ", & main); func (); return 0;}

Sample code func.c

# include int* glosspointerposition void func () {* g_pointer = (int) "D.T.Software"; return;}

1. Enable the core dump option.

Ulimit-c unlimited

2. Run the program and generate a crashed core file

Execute the sequencing use case that causes the program to crash, and after execution we see the generated core file

3. Read the core file and get the value of the IP register (0x08048000)

Dmesg core

In the last few lines of the file, it reads as follows:

The address 0x08048000 here is the address of the ip register.

4. Use addr2line to locate lines of code

Addr2line 0x08048000-f-e test.out

Strip

Eliminate the debugging information in the hometown file and reduce the size of the target program.

Select a book to delete the debugging information before the program is released.

Too much debugging information may affect the execution efficiency of the program.

Strip test.out

Note:

Almost all debugging aids depend on the debugging information in the object file

The use of debugging information can quickly locate the problem.

Use-g to generate debugging information when compiling a program using gcc

When releasing the program, consider whether to use strip to eliminate debugging information.

Ar

Package the target file, ar crs libname.a x.o .o

Extract the target file, ar x libname.a

Nm

List identifiers (variables, function names) in the target file

The output consists of three parts: {address, segment, identifier}

Segment identification description

Objdump

Disassemble the object file and view the mapping from assembly to source code

Objdump-d func.o

Objdump-S func.o

View the detailed segment information in the target file

Objdump-h test.out

Output description:

Here we need to explain a concept:

First, there are three addresses: virtual memory address, load address, and run address.

When we execute the executable program a.out:

1. The operating system assigns a process to the program and naturally allocates memory (virtual memory) to it.

two。 Load each segment of a.out into memory (load address), which is based on the file off in the above objdump-h

3. Execute the executable program (running address).

Size

Gets all the segment sizes in the target file, size test.out

Strings

Get all string constants in the target file, string test.out

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report