Question

I'm using the GNU extension "char** backtrace_symbols(void *buffer, int size)" to get the stack trace, when an exception is thrown. Is there a library function which converts the symbol into a "human readable" string - to redo the name mangling?

If not, I would write my own function according to this Wiki article.

Concrete:

Input:  test.exe(_ZN10CTLTestApp12ExecuteGroupEPK19CTLTestCaseRegisterNS_11EReportTypeE+0x24c) 
Output: test.exe CTLTestApp::ExecuteGroup( CTLTestCaseRegister, EReportType )

Thanks a lot,

Charly

Was it helpful?

Solution

#include <cxxabi.h> 
#include <iostream>
#include <cstdlib>

int main() {
  int status;
  const std::string name = "_ZN10CTLTestApp12ExecuteGroupEPK19CTLTestCaseRegisterNS_11EReportTypeE";
  char *realname = abi::__cxa_demangle(name.c_str(), 0, 0, &status);
  std::cout << realname << "(" << status << ")" << std::endl;
  free(realname);
}

Running gives:

CTLTestApp::ExecuteGroup(CTLTestCaseRegister const*, CTLTestApp::EReportType)(0)

See the online documentation for a more complete example and further details on this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top