Search code examples
c++cgdbmemory-corruption

How to debug global variable corruption in c program in arm platform?


Somewhere in my code an integer global variable is getting corrupted and it is actually causing a failure in an if condition check.The condition check is failing due to junk value assigned to the variable.

Which would be the best approach to solve this problem?

Since my target platform is arm,im really not finding any options to debug this issue.I have already created a memory map file using -Wl,-Map=transport.map option but the map file genereated is giving only very limited information about the variables.

Can someone guide me to solve this problem?

GDB debugger is not available in the target board but GDB server is present.

If possible can someone help to check it also with deadbeef instruction?


Solution

  • Use good old hard core debugging:

    Disable half of your code and see if it still happens.

    If this half works, disable the other half.

    Be creative in finding good "halves"

    Iterate: If you spotted the bad "half", you divide this in "quarters", and so on.

    Finally you'll find the line of code which causes the trouble.