异常信息转储笔记-demangle函数名字符

前情

上一篇笔记留下了两个待解决问题,其中之一是输出的函数名被奇怪字符覆盖了一部分,本篇笔记即将解决这个问题(下图问题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:
  • 0: The demangling operation succeeded.
  • -1: A memory allocation failiure occurred.
  • -2: mangled_name is not a valid name under the C++ ABI mangling rules.
  • -3: One of the arguments is invalid.

返回值

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

环境隔离的原因,无法直接复制代码,懒得再敲一遍,拍个图片凑合看吧。

效果展示

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HL_LOVE_C

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值