1 Star 0 Fork 1.2K

zzsj/LiteOS

forked from Huawei LiteOS/LiteOS 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.gitee
arch
build
compat
components
demos
doc
LiteOS_Build_and_IDE_en
LiteOS_Introduction_en
LiteOS_Kernel_Developer_Guide_en
figures
public_sys-resources
resource
README_EN.md
atomic-operation.md
bit-operation.md
c++-support.md
constraints.md
development-guide-41.md
development-guide.md
development-guidelines-1.md
development-guidelines-14.md
development-guidelines-21.md
development-guidelines-25.md
development-guidelines-29.md
development-guidelines-33.md
development-guidelines-37.md
development-guidelines-4.md
development-guidelines-44.md
development-guidelines-48.md
development-guidelines-52.md
development-guidelines-56.md
development-guidelines-8.md
development-guidelines.md
doubly-linked-list.md
dynamic-memory.md
error-handling.md
event.md
exception-management.md
interrupt.md
introduction-to-each-module.md
kernel-architecture.md
kernel-startup-process.md
kernel.md
memory.md
mutex.md
others.md
overview-0.md
overview-11.md
overview-13.md
overview-17.md
overview-20.md
overview-24.md
overview-28.md
overview-32.md
overview-36.md
overview-40.md
overview-43.md
overview-47.md
overview-51.md
overview-55.md
overview-7.md
overview.md
precautions-12.md
precautions-15.md
precautions-18.md
precautions-2.md
precautions-22.md
precautions-26.md
precautions-30.md
precautions-34.md
precautions-38.md
precautions-42.md
precautions-45.md
precautions-49.md
precautions-5.md
precautions-53.md
precautions-57.md
precautions-9.md
precautions.md
problem-locating-example.md
programming-example-(smp).md
programming-example-10.md
programming-example-16.md
programming-example-19.md
programming-example-23.md
programming-example-27.md
programming-example-3.md
programming-example-31.md
programming-example-35.md
programming-example-39.md
programming-example-46.md
programming-example-50.md
programming-example-54.md
programming-example-58.md
programming-example-6.md
programming-example.md
programming-instance.md
protocols.md
queue.md
semaphore.md
software-timer.md
spinlock.md
static-memory.md
task.md
time-management.md
usage-guidelines.md
LiteOS_Maintenance_Guide_en
LiteOS_Porting_Guide_en
LiteOS_Quick_Start_en
figures
figures_en/contribute
public_sys-resources
resource
LiteOS_Build_and_IDE.md
LiteOS_Code_Info.md
LiteOS_Code_Info_en.md
LiteOS_Contribute_Guide.md
LiteOS_Contribute_Guide_en.md
LiteOS_Introduction.md
LiteOS_Kernel_Developer_Guide.md
LiteOS_Maintenance_Guide.md
LiteOS_Porting_Guide.md
LiteOS_Quick_Start.md
LiteOS_Standard_Library.md
drivers
include/osdepends
kernel
lib
osdepends
shell
targets
test
tests
tools
.config
.gitignore
LICENSE
Makefile
NOTICE
README.md
README_EN.md
config.mk
克隆/下载
problem-locating-example.md 3.61 KB
一键复制 编辑 原始数据 按行查看 历史

Problem Locating Example

On an ARM32 platform, the memory is released through an error, which triggers a system exception. After the system is suspended due to the exception, the information about the exception call stack and key registers can be viewed through the serial port, shown as below. excType indicates the exception type. The value 4 indicates that the data is terminated abnormally. For other values, see the chip manual. The information will help you locate the function where the exception occurs and call stack relations of the function.

excType: 4
taskName = MNT_send
taskId = 6
task stackSize = 12288
excBuffAddr pc = 0x8034d3cc
excBuffAddr lr = 0x8034d3cc
excBuffAddr sp = 0x809ca358
excBuffAddr fp = 0x809ca36c
*******backtrace begin*******
traceback 0 -- lr = 0x803482fc
traceback 0 -- fp = 0x809ca38c
traceback 1 -- lr = 0x80393e34
traceback 1 -- fp = 0x809ca3a4
traceback 2 -- lr = 0x8039e0d0
traceback 2 -- fp = 0x809ca3b4
traceback 3 -- lr = 0x80386bec
traceback 3 -- fp = 0x809ca424
traceback 4 -- lr = 0x800a6210
traceback 4 -- fp = 0x805da164

To locate the exception, perform the following steps:

  1. Open the .asm disassembly file generated after compilation. By default, the file is generated in the Huawei_LiteOS/out/<Platform name> directory.

  2. Search for the position of the PC 8034d3cc, in the ASM file. (0x needs to be removed.)

    The PC address points to the command that the program is executing when the exception occurs. In the ASM file of the currently executed binary file, search for the PC value 8034d3cc and find the command line that is being executed by the CPU. The result is shown in the following figure.

    You can obtain the following information from the figure above:

    1. The CPU is executing the ldrh r2, [r4, #-4] command when the exception occurs.
    2. The exception occurs in the osSlabMemFree function.

    According to the analysis, the ldrh command is used to read a value from the memory address (r4-4) and load the value to the register r2. Then, check the value of r4 based on the register information printed when the exception occurs. The following figure shows the register information printed when the exception occurs. The value of r4 is 0xffffffff.

    The r4 value exceeds the memory range, and therefore a data termination exception occurs while the CPU is executing the command. According to the ASM file, r4 is moved from r1, and r1 is the second input parameter of the function. Therefore, the incorrect input parameter 0xffffffff (or -1) is input when the osSlabMemFree function is called.

    Next, you need to find out the caller of the osSlabMemFree function.

  3. Search for the call stack based on the LR value.

    The call stack information starts from backtrace begin of the printed exception information. Search for the LR corresponding to backtrace 0 in the ASM file, as shown in the following figure.

    The figure shows that the LOS_MemFree function calls the osSlabMemFree function. By using this method, you can find that the call relationships between functions are MNT_buf_send (service function) -> free -> LOS_MemFree -> osSlabMemFree.

    By checking the implementation of MNT_buf_send, the problem of incorrectly using a pointer is found. This problem causes an incorrect address to be freed. As a result, the exception occurs.

Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/zzsj_run/LiteOS.git
git@gitee.com:zzsj_run/LiteOS.git
zzsj_run
LiteOS
LiteOS
master

搜索帮助