开发者

C++ finding pointer errors

I am currently on a project which has been buggy for a long while, now I suspect, among other things, that there is pointer errors in the code.

The program is written in native C++ using COM and uses out-of-process COM servers.

Can anybody give me some tips as how one would go about finding these errors?

Is there specific thing开发者_StackOverflow社区s to keep in mind, ways to do it, etc...


I have a couple of suggestions here:

  1. How did you figure out there was a pointer error? Why don't you put it in the debugger and then see where the program crashes? That'd be a start. Put a watch on the offending variable(s).
  2. What makes you think something is messed up in the COM part of the code? On the contrary, I imagine that there are 2 processes running here (may or may not be on same machine) and you should run these in parallel and then see how they respond to each other -- I am mostly sure something would be wrong in the handling of data in application code. COM is a fairly mature technology.
  3. Perhaps you are making incorrect API calls, or as is the usual case with all things Microsoft there are 1000s of arguments, may be you need to tweak there.

Hope this helps. You can also try things like remote debugging and all, or instrument the code with Vtune or something but lets keep things simple for a start.

Arpan


You can try using a memory profiler like AQTime, DevPartner or IBM Rational Purify. I think there are plenty of others.


BoundsChecker has a runtime mode called Wait for Process. This lets you arm BC to wait until your DLLHOST process starts and attaches the BC core when the process comes up. For pointer errors you would use BC's Final Check mode. This means you add compile time native instrumentation which can be annoyingly slow if you instrument your whole app, but can be extremely effective if you instrument just your COM server and its dependencies. Look on http://www.microfocus.com under MF Developer for news regarding the DPS 10.5 launch in early February. Disclaimer, I work on the DevPartner team, so consider this my shameless plug. Our intention with the 10.5 release and its 64-bit support was to ensure we could handle pure C++ x64 apps foremost, mixed .NET apps second, and pure .NET apps last under BC. The other profilers in the suite went the other way, with pure .NET foremost. Hopefully you find 10.5 suits your dev environment and troubleshooting needs.


That's a very broad subject.

The best thing you could do is to use an instrumenting and tracking platform that allows you to see all allocations, memory leaks and memory corruptions but that can be very difficult to setup and time-consuming, depending on the size of your project and the complexity of your build system.

You could also plugin custom allocation and deallocation code (look at microsoft's debug_new (I think) for an example.

For COM-specific tracking I'm not sure if there are any already-made solutions. If you use ATL you could plug-in/replace/extend the smart pointer classes (like CComPtr) with your own.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜