Convert symbol in Classname::FunctionName( Para1, Para2 )
-
28-09-2019 - |
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
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