Setting a Trap in CodeLite?

General questions regarding the usage of CodeLite
User avatar
ColleenKobe
CodeLite Expert
Posts: 129
Joined: Wed Mar 30, 2016 4:31 pm
Genuine User: Yes
IDE Question: C++
Contact:

Setting a Trap in CodeLite?

Post by ColleenKobe »

Hi. I'm using Codelite v15.0.0 with MinGW, writing C and C++ code in two projects in one workspace.

In my code, I have a conditional compilation value called pm_Hxx_On.

I also have a variable defined as a Microsoft CRITICAL_SECTION.

These variables have nothing whatsoever to do with each other.

During initialization, I declare and initialize Thrd_A_CriticalSection. There are times in the program where it runs perfectly fine.

If pm_Hxx_On is defined, all is well and the program runs fine, beginning to end.

But if I change the declaration to undefine, I have problems. At first, the critical section code runs just fine. Then there comes a point where the Thrd_A_CriticalSection unintentionally and mysteriously gets set to NULL. The program dies the next time it tries to execute the critical section.

A rough overview of the flow of control looks like this, although each chunk of code is in a different procedure.

Code: Select all

//  #define pm_Hxx_On
    #undef pm_Hxx_On
...
// declaration
CRITICAL_SECTION        Thrd_A_CriticalSection;
...
// initialization
rc  = gbs_Initialize_Critical_Section   (&Thrd_A_CriticalSection,  "Thrd_A_CriticalSection");
...
// Used here.
EnterCriticalSection    (&Thrd_A_CriticalSection);
n   = thrd_A_Thrd_A_Index;
LeaveCriticalSection    (&Thrd_A_CriticalSection);
...
// And is deleted here.
gbs_Delete_Critical_Section (&Thrd_A_CriticalSection, "Thrd_A_CriticalSection");

This is all in C.

I have tried setting breakpoints at all places where Thrd_A_CriticalSection is set or used and looking at its values. That didn't tell me anything.

So the reason I'm writing is to ask, is there is a way in CodeLite to set up a trap when a value in memory is changed? I would set it to Thrd_A_CriticalSection's address and run the program, and when the value changes, I could check the call stack to find out where the write took place.

Also, how do I find out the address of a variable?

Thanks!

Colleen

DavidGH
CodeLite Plugin
Posts: 819
Joined: Wed Sep 03, 2008 7:26 pm
Contact:

Re: Setting a Trap in CodeLite?

Post by DavidGH »

is there is a way in CodeLite to set up a trap when a value in memory is changed?

See the 'watchpoint' section of https://docs.codelite.org/debuggers/gdb/#breakpoints

how do I find out the address of a variable?

If the variable is called foo, the address is &foo. Yes, you knew that already, but did you know that gdb is perfectly happy for you to edit the code while the debugger is paused; assuming foo is in scope, add the & and it will then tell you the value of &foo.

User avatar
ColleenKobe
CodeLite Expert
Posts: 129
Joined: Wed Mar 30, 2016 4:31 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Setting a Trap in CodeLite?

Post by ColleenKobe »

Terrific! Thank you very much! :D

Colleen

Post Reply