0

Can someone give an example of how to get programmatically the call stack of the currently running C++ program on Windows? From some threads (e.g. print call stack in C or C++ ) I have got a suggestion to use DbgHelp. However the library seems quite large and intended for many more features than just the call stack, so studying the library without an example can take too long time. Also the library seems obsolete because the last version of it, 6.12, is dated 01 February 2010 (7 years old as of now). Is there something new for getting call stack from C++ now?

If you are giving an example of DbgHelp usage, could you also describe how to install it, add to the project and ship with my program?

I would like to get undecorated names of all functions on the call stack, preferrably with values of the parameters.

Serge Rogatch
  • 13,865
  • 7
  • 86
  • 158

1 Answers1

0

It's not a huge amount of work to traverse the call stack yourself by popping the ebp, CaptureStackBackTrace (https://msdn.microsoft.com/en-us/library/windows/desktop/bb204633(v=vs.85).aspx) will do that for you if you don't want to do it yourself.

1stCLord
  • 860
  • 5
  • 14
  • As I understand this will only give the addresses, but not symbols (function names). – Serge Rogatch May 24 '17 at 16:35
  • 1
    Depending on how the program was compiled, the symbols may not even be present in the executable. – Solomon Slow May 24 '17 at 16:55
  • Getting the symbols is the purvue of the Debug Help Library you mentioned you didn't want to use. (https://msdn.microsoft.com/en-us/library/windows/desktop/ms679309(v=vs.85).aspx) The symbols can be located in a number of files and depending on where you get them from you will have a variable quality callstack. If you just want to get them out of an exe you will have to write partial a PE parser - https://msdn.microsoft.com/en-us/library/ms809762.aspx . pdb's have the richest source of symbols but I wouldn't recommend parsing them yourself. – 1stCLord May 25 '17 at 08:11
  • @TheSombreroKid , I don't refuse to use DbgHelp, I just need a code example to learn it. – Serge Rogatch May 25 '17 at 11:50