• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 426
  • Last Modified:

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.

0
chicho12
Asked:
chicho12
  • 5
  • 2
  • 2
  • +4
3 Solutions
 
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.

0
 
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.
0
 
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
0
 
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.
0
 
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
0
 
jkrCommented:
I'd rather not change the code at large scale if not necessary...
0
 
venkaiahCommented:
i think You can acheive this through set_terminate(handler); function.
0
 
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
0
 
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.
0
 
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
0
 
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.
0
 
havman56Commented:
why cant he take emulator and connect it in customer site for debugging ?  some one aldready have solution just use it !
0
 
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.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 2
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now