Search code examples
c++pointersdebugginggdbclion

debugger wont show the pointed variable


I am debugging a code and there are 2 issues.

  1. the debugger showed me the inner fields of each pointer, but suddenly it just wont, I dont know what changed or what did i click, but when i try to acsses the inner fields (like writing something into the pointed variable) it indeed shows me the correct variable, so it is saved there.

As you can see last clearly points to something, but it doesnt show the inner variable that the pointer is pointing to. 10 minutes ago it showed them though.

  1. for some reason my program runs on debugging mode but encounter some sort of an unkown infinite loop when i run it regularly. Howcome?

im using the mingw debugger (i think its called GDB) on the IDE CLion.


Solution

  • I have no idea about the first part of the question, but for the second part:

    for some reason my program runs on debugging mode but encounter some sort of an unkown infinite loop when i run it regularly. Howcome?

    This is very common.

    In 99.999% of instances this happens because your program exercises undefined behavior of some sort, such as using unitialized data, accessing array out of bounds, accessing memory after it has been deallocated, etc. etc.

    In the remaining 0.001% of the cases it's due to a compiler bug.

    On non-Widows OSes there are tools which help find such problems quickly, such as Address and Memory Sanitizers. Looks like Address Sanitizer is also available on Windows, but only under MSVC.

    Update:

    what can i usually do in order to find those memory bugs that the debugger wont pickup on?

    The usual techniques are:

    • Leave no variable uninitialized.
    • Add assert()ions to verify that indices are in bounds, etc.
    • Have a very clear model of what dynamically allocated memory is owned by which object, so it's clear that no memory is accessed after it has been deleted, etc.

    if my code is lets say 1500 lines long,

    That is a very small program. Learning how to debug such programs will serve you well.