简体   繁体   English

如何在特定对象的特定方法中设置断点?

[英]How to set a breakpoint in a specific method of a specific object?

I have a nasty bug in my C++ project. 我的C ++项目中存在一个令人讨厌的错误。 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. 事实是,此后,我仅使用该特定字符串进行操作,而没有修改Poiner值。 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. 调试器显示变量some​​String具有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. 永远不会调用该指针上的delete。
  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'). 该字符串的指针值永远不会改变(调试器显示“ 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)? 因此,是否有一种方法可以在一组特定对象上对析构函数设置断点(或其他任何方法)(我正在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. 多一点的代码将有助于我们在更深入的上下文中理解问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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