views:

98

answers:

3

Hello!

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 things to keep in mind, ways to do it, etc...

A: 

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.

utnapistim
+1  A: 

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

Max
+1  A: 

Hi Tony,

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

Fanatic23