前情
上一篇笔记留下了两个待解决问题,其中之一是输出的函数名被奇怪字符覆盖了一部分,本篇笔记即将解决这个问题(下图问题1)。
问题描述
如上,使用libunwind输出core堆栈信息时,有部分字符被覆盖,如下图,虽然老司机能够看明白很多东西,但是观感实在不好。
解决方案
libc++在底层的abi库中提供了字符反混淆功能,需要添加cxxabi.h头文件。
函数原型
char* abi::__cxa_demangle(const char* mangled_name,
char * output_buffer,
size_t * length,
int * status
)
参数
mangled_name | A NUL-terminated character string containing the name to be demangled. | |
output_buffer | A region of memory, allocated with malloc, of *length bytes, into which the demangled name is stored. If output_buffer is not long enough, it is expanded using realloc. output_buffer may instead be NULL; in that case, the demangled name is placed in a region of memory allocated with malloc. | |
length | If length is non-NULL, the length of the buffer containing the demangled name is placed in *length. | |
status | *status is set to one of the following values:
|
返回值
A pointer to the start of the NUL-terminated demangled name, or NULL if the demangling fails. The caller is responsible for deallocating this memory using free
.
demo
环境隔离的原因,无法直接复制代码,懒得再敲一遍,拍个图片凑合看吧。