@@ -36,7 +36,6 @@ void print_stacktrace(FILE* output, int start_idx, bool demangling, int maxdepth
3636 static constexpr auto ADDRESSDISPLAYLENGTH = (sizeof (long ) == 8 ) ? 12 : 8 ;
3737
3838 void *callstackArray[32 ]= {nullptr }; // the less resources the better...
39- fputs (" backtrace\n " , output);
4039 const int currentdepth = backtrace (callstackArray, static_cast <int >(getArrayLength (callstackArray)));
4140 if (currentdepth == 0 ) {
4241 fputs (" Callstack could not be obtained (backtrace)\n " , output);
@@ -45,17 +44,13 @@ void print_stacktrace(FILE* output, int start_idx, bool demangling, int maxdepth
4544 if (currentdepth == getArrayLength (callstackArray)) {
4645 fputs (" Callstack might be truncated\n " , output);
4746 }
48- fprintf (output, " currentdepth %d\n " , currentdepth);
4947 // set offset to 1 to omit the printing function itself
5048 int offset=start_idx+1 ; // some entries on top are within our own exception handling code or libc
51- fprintf (output, " offset %d\n " , offset);
5249 if (maxdepth<0 )
5350 maxdepth=currentdepth-offset;
5451 else
5552 maxdepth = std::min (maxdepth, currentdepth);
56- fprintf (output, " maxdepth %d\n " , maxdepth);
5753
58- fputs (" backtrace_symbols\n " , output);
5954 char **symbolStringList = backtrace_symbols (callstackArray, currentdepth);
6055 if (!symbolStringList) {
6156 fputs (" Callstack could not be obtained (backtrace_symbols)\n " , output);
@@ -66,22 +61,19 @@ void print_stacktrace(FILE* output, int start_idx, bool demangling, int maxdepth
6661 bool own_code = false ;
6762 char demangle_buffer[2048 ]= {0 };
6863 for (int i = offset; i < maxdepth; ++i) {
69- fprintf (output, " offset %d\n " , offset);
7064 const char * const symbolString = symbolStringList[i];
71- fprintf (output, " symbolString %p\n " , (void *)symbolString);
7265 fprintf (output, " %s\n " , symbolString);
66+ continue ;
7367 // skip all leading libc symbols so the first symbol is our code
7468 if (omit_above_own && !own_code) {
7569 if (strstr (symbolString, " /libc.so.6" ) != nullptr )
7670 continue ;
7771 own_code = true ;
7872 offset = i; // make sure the numbering is continuous if we omit frames
7973 }
80- fprintf (output, " offset %d\n " , offset);
8174 const char * realnameString = nullptr ;
8275 if (demangling) {
83- const char * const firstBracketName = strchr (symbolString, ' (' );
84- fprintf (output, " firstBracketName %p\n " , (void *)firstBracketName);
76+ const char * const firstBracketName = strchr (symbolString, ' (' ); // TODO: check
8577 const char * const plus = strchr (firstBracketName, ' +' );
8678 if (plus && (plus>(firstBracketName+1 ))) {
8779 char input_buffer[1024 ]= {0 };
@@ -97,13 +89,13 @@ void print_stacktrace(FILE* output, int start_idx, bool demangling, int maxdepth
9789 fprintf (output, " #%-2d 0x" ,
9890 ordinal);
9991
100- const char * const firstBracketAddress = strchr (symbolString, ' [' );
92+ const char * const firstBracketAddress = strchr (symbolString, ' [' );// TODO: check
10193 fprintf (output, " firstBracketAddress %p\n " , (void *)firstBracketAddress);
102- const char * const secondBracketAddress = strchr (firstBracketAddress, ' ]' );
94+ const char * const secondBracketAddress = strchr (firstBracketAddress, ' ]' ); // TODO: check
10395 fprintf (output, " secondBracketAddress %p\n " , (void *)secondBracketAddress);
10496 const int padLen = [&]() {
10597 // TODO: handle firstBracketAddress being NULL
106- const char * const beginAddress = firstBracketAddress+3 ;
98+ const char * const beginAddress = firstBracketAddress+3 ;
10799 fprintf (output, " beginAddress %p\n " , (void *)beginAddress);
108100 const int addressLen = int (secondBracketAddress-beginAddress);
109101 fprintf (output, " addressLen %d\n " , addressLen);
0 commit comments