Bpftrace: Automatically mangle c++ symbols

Created on 28 May 2019  路  8Comments  路  Source: iovisor/bpftrace

Sometimes when I uprobe c++ binaries, it's easier to directly type the c++ name I want to trace, eg Foo::bar. Does it make sense to let uprobe support something like:

probe:/usr/local/bin/dynolog:*folly::EventBase::run*                                                                                                                                                                                                                                      
{                                                                                                                                                                                                                                                                                         
....                                                                                                                                                                                                                                                          
}                    
enhancement

Most helpful comment

Attempting different demangling strategies seems like it would work, but maybe we'd also want to add support for more C++ features at some point, such as the this pointer (and other features for other languages too). In that case I wouldn't want to pollute the default builtin namespace with language-specific features.

Following up on @jgkamat's idea to tell bpftrace we've got a C++ symbol, how about saying we're probing a C++ function, then all these language-specific features could be enabled. Something like:

probe:/usr/local/bin/dynolog:c++:"*folly::EventBase::run*"

All 8 comments

This would be a fantastic feature, but I'm worried how this would work with probes on other languages, that might demangle differently. If there was a way to tell bpftrace that this name is a c++ symbol, perhaps then demangling can occur automatically.

Which languages might cause problems here? Just want to know what we're working with

Alastair Robertson writes:

Which languages might cause problems here? Just want to know what we're
working with

The languages that I know might need mangling are cpp, D, ocaml, rust,
haskell, and swift. I think cpp is the one that's the most important though,
we can probably mostly ignore the others. It's also possible that most
languages use the same demangling strategy, but I'm not sure.

@jgkamat I think we can add more language support as necessary. For example when attaching a uprobe, we could:

foreach mangling_strategy:
    n = mangle(symbol)
    if canAttach(n):
        attach(n)
        break

Assuming each mangling strategy is unique (needs more research), this feature could be forwards and backwards compatible.

Attempting different demangling strategies seems like it would work, but maybe we'd also want to add support for more C++ features at some point, such as the this pointer (and other features for other languages too). In that case I wouldn't want to pollute the default builtin namespace with language-specific features.

Following up on @jgkamat's idea to tell bpftrace we've got a C++ symbol, how about saying we're probing a C++ function, then all these language-specific features could be enabled. Something like:

probe:/usr/local/bin/dynolog:c++:"*folly::EventBase::run*"

just ran into this today, kinda sucks to have to find the mangled symbol to attach to. Would be great to attach to the dymangled symbol as seen in the source code

Also if we list symbols with bpftrace -l, i would expect it to list the demangled symbols - so we should be able to attach in the same format as we list IMO.

Done in #1116

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gbansal2 picture gbansal2  路  5Comments

caringi picture caringi  路  4Comments

tty5 picture tty5  路  3Comments

brendangregg picture brendangregg  路  4Comments

brendangregg picture brendangregg  路  7Comments