How to "decrypt" linker method names?
Asked Answered
G

2

6

I'm using backtrace to print application's stack trace and I'm getting something like

libQtCore.so.4(_ZN11QMetaObject8activateEP7QObjectPKS_iPPv+0x843) [0x7f889d20cf33]
libQtGui.so.4(_ZN7QAction9triggeredEb+0x32) [0x7f889d76c2f2]
libQtGui.so.4(_ZN7QAction8activateENS_11ActionEventE+0xb0) [0x7f889d76d670]
libQtGui.so.4(+0x6242f4) [0x7f889db862f4]

Is there any way to convert "linker-names" to "source-names" and get code line numbers from offsets?

I want to have backtrace, looking like this:

libQtCore.so.4 (QMetaObject::activate(QObject):1022)
libQtGui.so.4  (QAction::triggered()::47) 

UPD.

I understand, this technique may work or not work or work bad because of compiler specifics. I want to "demangle" linker symbols at least in gcc and visual c++.

Goolsby answered 8/12, 2011 at 16:5 Comment(6)
@fjardon , can I use this method from source code? Is there any char * s = cpp_filt(MyStackString);Goolsby
@fjardon, c++filt will only work with gcc names, while MSVS or any other compiler may use different rules.Sieve
@Arenim, c++filt is a command line tool for Linux. It is not a function.Sieve
Yes, i see. It works for me, but I'm sure, it uses some library, capable for usage in application, right?Goolsby
@Arenim: I'd look into source code if you need it that badly :).Sieve
"it uses some library, capable for usage in application" I think what you want is this: https://mcmap.net/q/869467/-where-is-c-filt-source-codeUranous
E
7
  • Under gcc you can use c++filt to decipher the mangling.

  • Under Visual studio you can undname

Once you have the function name you at least on Windows you can use DIA SDK to get the source file line numbers etc

Embarrassment answered 8/12, 2011 at 16:30 Comment(0)
S
2

This is called name mangling. Read the article on Wikipedia please, since citing it here would be too much for an answer.

Sieve answered 8/12, 2011 at 16:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.