1

Something is holding onto a shared_ptr. I'm wondering if there is a way I can set a Data Watch Breakpoint on the uses of said shared_ptr so I can see the uses increment and decrement. The codebase I'm working in is very large and since we use QT Signals and Slots I'm not 100% sure of how to track what is getting a shared ownership of this.

I've tried googling this question and haven't really found anyone trying to do this. My google fu isn't very strong so I could have missed it. I've also tried just entering the variable name for the data watch breakpoint as

ptr->_Rep->_Uses

to no avail. I just get an empty data watch breakpoint that never breaks.

1 Answers1

0

I am using Visual Studio 2019. I found a way to do this.

Step 1: Add a normal break point after 'std::shared_ptr' initialized.

Step 2: Right-click the red dot icon, select "Condition".

Step 3: Enter the shared pointer's name with a "*" before it

Step 4: select "Has Changed" option.

Finally look like this

It works well even if I do this:

    std::shared_ptr<int> p(new int(0));
    int* raw_ptr = &*p;
    while (true)             //Break point here, when "*p" "Has Changed"
    {
        (*raw_ptr)++;
    }

Hope it helps.

Bige Young
  • 25
  • 5
  • I think I've figured out the problem and I apologize for leaving out pertinent information. It's a std::shared_ptr so the *pPointer in the breakpoint doesn't work. The type was hidden by a using so I missed it when writing the initial post. – narcolepticNarwhal Jul 08 '19 at 15:15