Demangling

Demangling

分类: The GNU C Library   204人阅读  评论(0)  收藏  举报

http://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html

http://lxr.free-electrons.com/source/tools/perf/util/symbol-elf.c#L810

Transforming C++ ABI identifiers (like RTTI symbols) into the original C++ source identifiers is calleddemangling.

If you have read the source documentation for namespace abi then you are aware of the cross-vendor C++ ABI in use by GCC. One of the exposed functions is used for demangling, abi::__cxa_demangle.

In programs like c++filt, the linker, and other tools have the ability to decode C++ ABI names, and now so can you.

(The function itself might use different demanglers, but that's the whole point of abstract interfaces. If we change the implementation, you won't notice.)

Probably the only times you'll be interested in demangling at runtime are when you're seeing typeidstrings in RTTI, or when you're handling the runtime-support exception classes. For example:

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

struct empty { };

template <typename T, int N>
  struct bar { };


int main()
{
  int     status;
  char   *realname;

  // exception classes not in <stdexcept>, thrown by the implementation
  // instead of the user
  std::bad_exception  e;
  realname = abi::__cxa_demangle(e.what(), 0, 0, &status);
  std::cout << e.what() << "\t=> " << realname << "\t: " << status << '\n';
  free(realname);


  // typeid
  bar<empty,17>          u;
  const std::type_info  &ti = typeid(u);

  realname = abi::__cxa_demangle(ti.name(), 0, 0, &status);
  std::cout << ti.name() << "\t=> " << realname << "\t: " << status << '\n';
  free(realname);

  return 0;
}
   

This prints

   
      St13bad_exception       => std::bad_exception   : 0
      3barI5emptyLi17EE       => bar<empty, 17>       : 0
   
   

The demangler interface is described in the source documentation linked to above. It is actually written in C, so you don't need to be writing C++ in order to demangle C++. (That also means we have to use crummy memory management facilities, so don't forget to free() the returned char array.)

MtpServer析构的之前会调用MtpFfsHanlde的close方法关闭所有的线程void MtpFfsHandle::close() { int count = mChildThreads.size(); for (int i = 0; i < count; i++) { mChildThreads[i].join(); } mChildThreads.clear(); io_destroy(mCtx); closeEndpoints(); closeConfig(); }为什么还会报错Abort message: 'terminating' x0 0000000000000000 x1 0000000000005348 x2 0000000000000006 x3 0000007b3d80ddd0 x4 fefefefeff666d68 x5 fefefefeff666d68 x6 fefefefeff666d68 x7 7f7f7f7f7f7f7f7f x8 00000000000000f0 x9 820a641e717328ae x10 000000ff00000020 x11 0000000000000000 x12 0000000068901993 x13 000000007fffffff x14 00000000040b024c x15 000007660641314d x16 0000007ec0efc120 x17 0000007ec0ee34c0 x18 0000007b28abc000 x19 0000000000004f09 x20 0000000000005348 x21 00000000ffffffff x22 0000007b3d80dff0 x23 ffffff80ffffffc8 x24 0000007b3d80df00 x25 0000000071426188 x26 0000000050380001 x27 0000000000000004 x28 0000007b3d80e240 x29 0000007b3d80de50 lr 0000007ec0e7e5e8 sp 0000007b3d80ddd0 pc 0000007ec0e7e60c pst 0000000000001000 20 total frames backtrace: #00 pc 000000000007160c /apex/com.android.runtime/lib64/bionic/libc.so (abort+160) (BuildId: fa559b354d38eacb06224f09a075b3e2) #01 pc 000000000007d328 /system/lib64/libc++.so (abort_message+256) (BuildId: ada37e5198285720b02f7d77fd27626c7782fe29) #02 pc 000000000007bdf4 /system/lib64/libc++.so (demangling_terminate_handler()+56) (BuildId: ada37e5198285720b02f7d77fd27626c7782fe29) #03 pc 000000000007c36c /system/lib64/libc++.so (std::__terminate(void (*)())+12) (BuildId: ada37e5198285720b02f7d77fd27626c7782fe29) #04 pc 000000000007c310 /system/lib64/libc++.so (std::terminate()+84) (BuildId: ada37e5198285720b02f7d77fd27626c7782fe29) #05 pc 00000000000a3064 /system/lib64/libc++.so (std::__1::thread::~thread()+28) (BuildId: ada37e5198285720b02f7d77fd27626c7782fe29) #06 pc 0000000000025c94 /system/lib64/libmtp.so (android::MtpFfsHandle::~MtpFfsHandle()+596) (BuildId: e6f174ed28d6dc2a3f02a2edfe49ebda) #07 pc 0000000000025a24 /system/lib64/libmtp.so (android::MtpFfsHandle::~MtpFfsHandle()+20) (BuildId: e6f174ed28d6dc2a3f02a2edfe49ebda) #08 pc 000000000002c54c /system/lib64/libmtp.so (android::MtpServer::~MtpServer()+104) (BuildId: e6f174ed28d6dc2a3f02a2edfe49ebda) #09 pc 000000000002c4c8 /system/lib64/libmtp.so (android::MtpServer::~MtpServer()+20) (BuildId: e6f174ed28d6dc2a3f02a2edfe49ebda) #10 pc 0000000000086000 /system/lib64/libmedia_jni.so (android_mtp_MtpServer_cleanup(_JNIEnv*, _jobject*)+164) (BuildId: aa49e6468054c882690c8f679f98b958)
最新发布
08-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值