简体   繁体   中英

How to set a breakpoint in a specific method of a specific object?

I have a nasty bug in my C++ project. There's a class

class SomeClass {
    ...
    std::string *someString;
    ...
}

Here's a constructor

SomeClass(...) {
    ...
    someString = new std::string("");
    ...
}

And the thing is that afterwards I operate only with that specific string, without modifying the poiner value. I assign to that string different strings all the time, like

*someString = "whatever";
someString->assign("whatever");
*someString += 'a';

Application is multithreaded and there's a really nasty glitch. At some point, application crashes. Debugger shows that variable someString has A BAD POINTER. And I have no idea how this is possible

delete someString;

IS NEVER CALLED.

I've looked to all the references of that string pointer and here's what I can tell you:

  1. delete on that pointer is never called.
  2. that pointer is never assigned to anything else (where it may be deleted later).
  3. pointer value of that string is never altered in any way (debugger shows 'Bad Ptr').
  4. other class variables seem fine like they are supposed to be.

Therefore, I need to find a way to check when a destructor is called on a specific object. In fact, array of objects.

So, is there a way to set a breakpoint on a destructor (or any other method) on a specific set of objects (I'm working on visual studio 2010 proffessional)?

If you are multithreading, consider implementing a locking mechanism ... (if you didn't do it already) for your string member. Highly possible one thread tries to write to a pointer which is being reallocated in a different thread... or something like this. A little bit more code would help us to understand the problem in a deeper context.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM