Link to home
Start Free TrialLog in
Avatar of chicho12
chicho12

asked on

log the "call stack"

Hi,
I am fairly new at C++. I was just assigned to this system 1 week ago.  
At work one of our customers is having problems with our dll.  
They are using our COM version of the dll with ASP pages.  After a few minutes of using the ASP app by a few users that app hangs.
This is only happening with the latest version of the dll. The previous version works fine for the customer. The new version has a lot of changes on  a custom
String class. I think this class is causing the problem (memory leak probably). Changes on this String class were made to solve some reporting issues. the reporting issues were fixed but this particular customer cannot use the new version.

We cannot recreate the problem in our site so its very difficult to debug.

I was thinking to add some code to the program so it prints to a log file when it encounters a prblem. Hopefully I can print the call stack when an error occurs so I can have a better idea where the problem could be.
I was wondering if this is possible and if somebody has an example on how to do this.??       The dll is coded on c++ (Microsoft Visual C++)
I am not sure of other way I can troubleshoot the problem.

ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chicho12
chicho12

ASKER

Zulti,
Can you show me an example of how insert an entry to a global stack on the constructor?  and removing it

Thanks
Chicho
>>I would probably create a simple log class , declare

FYI:
If you don't know what you're doing, a logging class can add more bugs to your code, and you end up spending more time debugging your logging class, than you do debugging your real problem.

Global logging classes are not simple when used in multiple source files (*.cpp), and when you need to call them from global or static objects.
When calling a global loggging class from a global object's constructor, you have to worry about the order of initialization.

If there are no calls to the global logging class before main(), than the task can be simple.
basicly the links jkr and Axter gave you will do the same, but in more details

use the std::vector and use .push_back() at the constructor and .pop_back() at the destructor

the vector can be either global variable, or a static member of your logger class, it's up to you how to define it....

p.s. I would define a macro to declare the class
something like
#ifdef USE_STACK_LOG
#define STACK_LOG stackLog Logger ;
#else
#define STACK_LOG
#endif

and then you can add the STACK_LOG to your code, and just by removing the define USE_STACK_LOG it will be removed from the code, and will not interfere with the release version...

good luck
I'd rather not change the code at large scale if not necessary...
i think You can acheive this through set_terminate(handler); function.
use american arium emulator which logs call stack automatically . Tool is aldreay available . this works for pentium machines.

Just load your exe and run your code  and see log file automatically it logs all . whenevr exception or something happens it shows clearly the address where it failed . and u can see map file andlocate the function

This is pretty simple all u need to do is get american arium emulator

No need to change any code

havaman
>>This is pretty simple all u need to do is get american arium emulator
>>No need to change any code

This may not be possible, if the developer is trying to trouble shoot a problem that only occurs in a customer site.
And that's what the questioner is stating.
hey
If you are pretty sure that it's memory leak set new handler,
Override new and delete, or try to print memory address and count in string or other particular class  constructor and destructor.

Overriding new and delete [class constructor and destructor] solves most of my memory leak problem.

Thanks,
Mayank
If you think it's a memory leak problem, you can try using the following free leak detection code:
http://code.axter.com/leaktracker.h

You'll need the DLL that you can download from following link:
http://code.axter.com/leaktracker.zip

Using this code, you don't even need to change your source code, and you can use it to report memory leaks.
Instructions are in the leaktracker.h header.
why cant he take emulator and connect it in customer site for debugging ?  some one aldready have solution just use it !
>>why cant he take emulator and connect it in customer site for debugging ?  some one aldready have solution just use it !

Is this a free program?  If so, do you have a link for it?

If not, than in general, you just can't throw license programs on any customer's computer.