Convert character to Classname :: FunctionName (Para1, Para2)

I use 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 that converts a character to a "human readable" string - to change the name again?

If not, I would write my own function in accordance with this Wiki article .

Concrete:

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

Many thanks,

Charlie

+3
source share
1 answer
#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 more details and more on this.

+1
source

Source: https://habr.com/ru/post/1772640/


All Articles