How to get the root cause of memory corruption in the embedded environment?

I found memory corruption in my embedded environment (my program runs on a console with its own OS). but I could not get the root cause of this. memory corruption itself is detected after a stress test of launching and exiting the application several times. that I could not set a memory breakpoint because the damaged variable changes the address every time the application starts, is there any idea to catch the root cause of this corruption?

(A memory breakpoint is a breakpoint that is triggered when the environment changes the address value of the receiving memory)

Please also note that all my software is developed using C.

Thank you for your help.

+3
source share
7 answers

These are always complex problems in embedded systems, and there is no easy answer. Some tips:

  • Look at the value that the memory is corrupted. This may give a clear hint.
  • Look at the data structures next to memory corruption.
  • See if there is a pattern in memory corruption. Is he always at the same address?
  • See if you can set a memory checkpoint at runtime.
  • Does the embedded system provide memory allocation with a sandbox? Set up a sandbox to protect your data memory.

Good luck

+5
source

Yes, these problems can be difficult to debug with a debugger.

A few ideas:

  • ( , )
  • #if 0 , . , , .
  • /, , , .
  • , , ( , , ): , "" , "" . memcpy ( ) CRC. . .
+3

?

, . , , , . , , , , , , , , .

, , , . , , , , . , - .

, .

, , , , , .

, , . , , . .

, , ISR. , . , , ISR .

, , .. , , - . , , , .

, RTOS. . , .

, , , , , .

+3

, , , - .

, , " ". , . , . , " " . , , , , .

, , ( - , ?). , , , , , . , . , , (, , ).

, -, , , . - .

, , . , , , , ( , ).

+1

. ? , ?

, , . , .

, , , , , , , .

Printfs malloc/realloc/free proxy Electric Fence , , .

0

, ElectricFence, dmalloc .. - , - (, , ( ) ) .. - dmalloc.

0

. , , - ( , ), , (, guardmalloc, ).

The C library that you use may include some routines for detecting heap corruption (e.g. glibc). Turn them on along with any trace features you have, so you can see what happens when the heap has been corrupted.

0
source

Source: https://habr.com/ru/post/1722045/


All Articles