printBacktrace_test.cc
Go to the documentation of this file.
1 
2 #include "CoreUtils/DebugUtils.h"
3 
4 // C/C++ standard libraries
5 #include <iostream>
6 #include <sstream>
7 #include <string>
8 #include <vector>
9 
10 
11 struct AClass {
12  void Do()
13  {
14  std::cout << present() << ": Do()" << std::endl;
15  gar::debug::printBacktrace(std::cout);
16  }
17 
19  {
20  std::ostringstream sstr;
21  sstr << gar::debug::demangle(this) << "[" << ((void*) this) << "]";
22  return sstr.str();
23  } // present()
24 
25 }; // AClass
26 
27 
28 struct BClass {
29  void Do()
30  {
31  std::cout << present() << ": Do()" << std::endl;
32  gar::debug::printBacktrace(std::cout);
33  a.Do();
34  }
36  {
37  std::ostringstream sstr;
38  sstr << gar::debug::demangle(this) << "[" << ((void*) this) << "]";
39  return sstr.str();
40  } // present()
41 
43 }; // BClass
44 
45 
46 struct CClass {
47  CClass() { Do(); }
48 
49  void Do()
50  {
51  std::cout << present() << ": Do()" << std::endl;
52  gar::debug::printBacktrace(std::cout);
53  a.Do();
54  }
56  {
57  std::ostringstream sstr;
58  sstr << gar::debug::demangle(this) << "[" << ((void*) this) << "]";
59  return sstr.str();
60  } // present()
61 
63 }; // CClass
64 
65 
66 int main(int /* argc */, char** /* argv */) {
67 
68  AClass a;
69  a.Do();
70 
71  BClass b;
72  b.Do();
73 
74  // create test classes in a deeper, non-local context
75  std::vector<CClass> v [[gnu::unused]] (2);
76 
77  return 0;
78 } // main()
79 
80 
std::string demangle(T const *=nullptr)
Outputs a demangled name for type T.
Definition: DebugUtils.h:56
std::string string
Definition: nybbler.cc:12
std::string present() const
int main(int, char **)
const double a
void printBacktrace(Stream &&out, unsigned int maxLines=5, std::string indent=" ", CallInfoPrinter::opt const *options=nullptr)
Prints the full backtrace into a stream.
Definition: DebugUtils.h:249
static bool * b
Definition: config.cpp:1043
std::string present() const
std::string present() const
QTextStream & endl(QTextStream &s)