Vladimir
Vladimir

Reputation: 510

Dubbuging C++ with VS. Track down varrible change

I have a huge program (VS project) which contains global variable. It modifies from hundreds places. Actually it standard STL container (std::vector) and question is how can I track down this particular variable modifications? In my work I use VS debugger (Prof 2017 15.9.5)

Upvotes: 1

Views: 33

Answers (1)

Michał Walenciak
Michał Walenciak

Reputation: 4369

There are a few solutions which come to my mind:

  1. Create another class which will encapsulte this vector. Then allow users to use this vector by adding getter returning reference to it. Then you can put a breakpoint in getter.

  2. Put a memory breakpoint on one of vector's members but it is plantform specific solution which may not work in all scenarios.

  3. Replace std::vector with your custom type with interface identical to std::vector's which would use original std::vector in its internals. With this solution you can monitor accesses more precisely.

P.S. remove this global ASAP.

Upvotes: 1

Related Questions