Embedded system coredump analysis

This article is shared from China Mobile OneOS WeChat public account " Embedded System Coredump Analysis ", author: Bai Ling.

In the process of embedded product development, it is inevitable to encounter, after the function development is completed, the firmware is burned in, the test is taken, and then the test is tested, and the program crashes!

problem solving ideas

When encountering a program crash problem, the first thing we want to know is, where did the program crash? The easiest way is to get the program pointer register. For example, when developing with cortex-m, you only need to save the PC value when the program crashes to the flash or print it out. But when looking at the map table, it is very likely that the function pointed to by the PC is a generic function such as memcpy! It does not provide effective information for problem solving.

So for most program crash problems, it is best to get the complete call stack and temporary variables on the stack, which happens to be the main function of coredump.

eCoreDump component introduction

The main function of the eCoreDump component of OneOS is to generate the core file in elf format, and cooperate with the modified embedded gdb to complete the coredump analysis function of the embedded system. The specific process is that when there is a problem with the program, the eCoreDump component interface is called to organize the register value and memory content into a core file in elf format. The core file can be output directly from the serial port or saved to flash.

eCoreDump component workflow:

After the generated Core file is transferred to the PC and saved as a file, the format is as follows:

 Configure development and run

OneOS-Cube configuration

The eCoreDump component depends on the flash storage function and shell function of the fal component. Therefore, before enabling eCoreDump, ensure that the fal interface of the development board is available and the shell component is enabled.

Use menuconfig to enable the eCoreDump function:

(Top) → Components → Diagnose → eCoreDump
                                                        OneOS Configuration
[*] Using eCoreDump
        Select the arch (armv7m)  --->
[*]     Using example

Compile, download and run

After enabling the eCoreDump component, you can use keil or gcc to compile the firmware. For the specific compilation and download steps, refer to the OneOS development documentation .

Four new shell commands have been added to the eCoreDump component:

trigger_assert
trigger_fault
corefile_dump
corefile_count

The trigger_fault command provides a hardfault example. After execution, the hardfault is triggered, and the generated core file is saved to flash. The analysis process is described in the next section.

The trigger_assert command will trigger assert and print the generated core file to the serial port. For the analysis process, see the hardfault example.

The corefile_count command is used to check how many core files are currently stored on the flash, and the corefile_dump command prints the core files to the serial port.

Analyzing hardfaults with GDB

In order to demonstrate the function of the eCoreDump component, a piece of code that will cause hardfault is constructed below. The reason for the system crash is an illegal function pointer call.

fault_func func = (fault_func)0xFFFF0000;
int x, y;
const char * sx = "84597";
const char * sy = "35268";

float a, b, c;
const char * fsa = "1.1322";
const char * fsb = "45.2547";
const char * fsc = "7854.2";

a = atof(&fsa[0]);
b = atof(&fsb[0]);
c = atof(&fsc[0]);

x = atoi(&sx[0]);
y = atoi(&sy[0]);

func(x * a + y * b * c);

return 0;

When the hardfault occurs, restart the chip and use the shell command to view the generated core file (the file content is printed in hex format):

The process of using ecdView for coredump analysis on PC is as follows:

1) Copy the file content in hex format to the first text box of ecdView, convert the content in hex format into binary format and save it as a file.
2) Use the OpenElf button to select the program's elf file path.
3) Use the BeginGDB button to start the gdb process for core file analysis.

The result of gdb parsing is as follows:

 gdb and ecdView download address: https://gitee.com/cmcc-oneos/openOCD/releases

OneOS is a lightweight operating system launched by China Mobile for the Internet of Things. It features tailorable, cross-platform, low power consumption, and high security. It supports mainstream CPUs such as ARM Cortex-M/R/A, MIPS, and RISC-V. The architecture is compatible with POSIX, CMSIS and other standard interfaces, supports Micropython language development, and provides graphical development tools, which can effectively improve development efficiency and reduce development costs, helping customers develop stable, reliable, safe and easy-to-use IoT applications. Official website address: https://os.iot.10086.cn/
OneOS software address: http://www.oschina.net/p/cmcc-oneos
OneOS project address: https://gitee.com/cmcc-oneos/ OneOS
OneOS technical exchange group: 158631242

{{o.name}}
{{m.name}}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324030214&siteId=291194637