-2

You come across certain cases where you would like to print the applications activity such as those cases where you have gotten to a source code and would like to get to the in order set of methods invoked, variables initialized and any activity of the program. What is the most suggested and practical tool to obtain the stack trace but also a through report of the applications activity?

  • 1
    The most used tool for such inspection is the debugger of your toolchain. – πάντα ῥεῖ Jul 11 '15 at 13:58
  • What have you tried? Show some source code relevant to your question? What tool chain are you using (what operating system, what compiler, what optimization flags)? For what kind of software are you asking your very broad question? Please **edit your question** to improve it and motivate it! – Basile Starynkevitch Jul 11 '15 at 14:13
  • BTW, I find the formulation of your question quite difficult. If you are, as I am, a non-native English speaker could you try to make several *shorter* sentences.... And explain **why** are you asking... and give much more context and details. – Basile Starynkevitch Jul 11 '15 at 14:17
  • Am I the only one to not being able to parse and understand all of the first sentence (3 lines long!!!)? – Basile Starynkevitch Jul 11 '15 at 14:23

1 Answers1

1

The first sentence of your question is too long to be understandable by me; I cannot parse it entirely and I am only guessing what you want to ask.

The appropriate tool for such things is called a debugger. Details are build-chain i.e. implementation specific. I'm focusing on Linux tools using GCC.

On Linux, you'll compile with g++ -Wall -Wextra -g3 (or just g++ -Wall -g) and use gdb as the debugger. Perhaps you want watchpoints.

Recent versions of gdb are scriptable (or extensible) in Python and even in Guile. So if your system's gdb is too old to be extensible, building a recent gdb from its downloaded source code may be worthwhile.

If your question is related to programmatic introspection by your program of its current continuation or call stack or stack trace (or other reflection-like activities), this is not easily doable in standard C++11, but you might consider the backtracing functions of GNU glibc or use the libbacktrace by Ian Taylor in GCC or maybe the return address related builtins of GCC.

You might also want to use some profiler (perf, oprofile, gprof) ...

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547