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.

chicho12Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
Check out http://win32.mvps.org/misc/stackwalk.html ("StackWalk") and http://www.codeproject.com/tools/leakfinder.asp ("Memory(-Leak) and Exception Trace (CRT and COM Leaks)"). The latter allows you to write your own exception filter and just call StackwalkFilter to produce the callstack.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zultiCommented:
I would probably create a simple log class , declare it the beggining of each function, at the constructor would insert an entry to a global stack, and at the destructor, will remove that entry, this will create an image of the call-stack, but you can actually insert more than just the name of the function, you may enter the parameters of the function, or some variables, so you'll know better what was going on.
AxterCommented:
Check out the free logging code in the following link:
http://axter.com/ezlogger/

With the above logging code, you can use the EZLOGGERFUNCTRACKER macro to track function entry and exit.
Example usage:

void FunctFoo()
{
      EZLOGGERFUNCTRACKER;
      //Function Foo code here....
}

If you're using VC++ 7.x, 8.0, GNU 3.x, or 4.0, the logging code will automatically pickup the function name.
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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

Thanks
Chicho
AxterCommented:
>>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.
zultiCommented:
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
jkrCommented:
I'd rather not change the code at large scale if not necessary...
venkaiahCommented:
i think You can acheive this through set_terminate(handler); function.
havman56Commented:
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
AxterCommented:
>>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.
bhattmayankCommented:
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
AxterCommented:
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.
havman56Commented:
why cant he take emulator and connect it in customer site for debugging ?  some one aldready have solution just use it !
AxterCommented:
>>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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.