Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for C++ mangled symbols in uprobe names #687 #1116

Merged
merged 1 commit into from
Feb 17, 2020

Conversation

caringi
Copy link
Contributor

@caringi caringi commented Jan 29, 2020

Allow to specify uprobe names using demangled C++ format (this is done
with the help of abi::__cxa_demangle() function).

Example:

$ nm -g a.out |grep foo
0000000000401151 T _Z3fooi
0000000000401146 T _Z3foov

$ nm -g --demangle a.out |grep foo
0000000000401151 T foo(int)
0000000000401146 T foo()

$ bpftrace -e 'uprobe:./a.out:foo {printf("ok\n");}'
Attaching 2 probes...
^C

$ bpftrace -e 'uprobe:./a.out:"foo()" {printf("ok\n");}'
Attaching 1 probe...
^C

@caringi caringi force-pushed the rfc_support_cpp_mangled_symbols branch from e28ad2c to 34fad0e Compare January 29, 2020 16:53
@danobi
Copy link
Member

danobi commented Jan 30, 2020

Haven't looked too closely at the code yet, but I like this feature.

One thought: should we make bpftrace -l uprobe:/path/to/bin print demanged names as well? Sometimes it can be tricky to guess what the demangled name will be.

@caringi
Copy link
Contributor Author

caringi commented Jan 30, 2020

One thought: should we make bpftrace -l uprobe:/path/to/bin print demanged names as well? Sometimes it can be tricky to guess what the demangled name will be.

I think that's a good idea...

Maybe bpftrace -l uprobe:/path/to/bin could print mangled and demangled names side by side...

Something like:

uprobe:./a.out:foo() [_Z3foov]
uprobe:./a.out:foo(int) [_Z3fooi]

Another option would be to use -lv to print demangled names, and leave -l printing the symbols without demangling.

@caringi caringi force-pushed the rfc_support_cpp_mangled_symbols branch 2 times, most recently from 721017b to 47d486e Compare January 31, 2020 10:05
@dalehamel
Copy link
Contributor

One thought: should we make bpftrace -l uprobe:/path/to/bin print demanged names as well? Sometimes it can be tricky to guess what the demangled name will be.

I think the default behavior should be that listing uprobes this way should print demangled by default, as we also want to be able to have the list and attach syntax be consistent. (echoing what I said on #687 )

Thanks for doing this @caringi

Copy link
Member

@ajor ajor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice approach! This will be very useful

src/bpftrace.cpp Outdated Show resolved Hide resolved
Allow to specify uprobe names using demangled C++ format (this is done
with the help of abi::__cxa_demangle() function).

Example:

$ nm -g a.out |grep foo
0000000000401151 T _Z3fooi
0000000000401146 T _Z3foov

$ nm -g --demangle a.out |grep foo
0000000000401151 T foo(int)
0000000000401146 T foo()

$ bpftrace -e 'uprobe:./a.out:foo {printf("ok\n");}'
Attaching 2 probes...
^C

$ bpftrace -e 'uprobe:./a.out:"foo()" {printf("ok\n");}'
Attaching 1 probe...
^C
@caringi caringi force-pushed the rfc_support_cpp_mangled_symbols branch from 47d486e to ebc47ac Compare February 6, 2020 17:06
Copy link
Member

@ajor ajor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Is it still a RFC or ok to merge?

@caringi
Copy link
Contributor Author

caringi commented Feb 10, 2020

Looks good to me. Is it still a RFC or ok to merge?

I've added the RFC prefix to emphasize I needed feedback...

I think it's ok to merge it...

@caringi caringi changed the title [RFC] Add support for C++ mangled symbols in uprobe names #687 Add support for C++ mangled symbols in uprobe names #687 Feb 10, 2020
@dalehamel
Copy link
Contributor

this is awesome @caringi i think this is ok to merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants