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

usdt: Fix attaching to probes in different binaries #1356

Merged
merged 8 commits into from
Jun 10, 2020

Conversation

danobi
Copy link
Member

@danobi danobi commented May 28, 2020

USDTHelper caching logic was previously incorrect. It would mark the
cache as loaded if any pid or path was processed. This would cause
scripts that place usdt probes on different binaries to silently fail
(because a default usdt_probe_entry would be returned).

See the runtime test for an example of how this can occur.

Checklist
  • Language changes are updated in docs/reference_guide.md
  • User-visible and non-trivial changes updated in CHANGELOG.md

@danobi
Copy link
Member Author

danobi commented May 28, 2020

cc @dalehamel

@danobi danobi force-pushed the usdt_multi_module branch from a50c360 to cf1b8e0 Compare June 1, 2020 22:28
@dalehamel
Copy link
Contributor

Sorry for the delay, i'll take a look shortly danobi

@@ -25,6 +25,7 @@ add_executable(bpftrace
struct.cpp
tracepoint_format_parser.cpp
types.cpp
usdt.cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

nice, much more idiomatic at this point to have it in its own file.

Copy link
Contributor

@dalehamel dalehamel left a comment

Choose a reason for hiding this comment

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

This looks great, it's more similar to how BCC modularizes their USDT code too, about time we moved out of the util.cpp, which are always a bit of an anti-pattern.

I didn't read over the new usdt.cpp line by line, but it mosty looks like a refactor. Can you point me to the spot where you fixed the bug where attach to only one binary worked? I am curious what the issue was, but I see you added a test case that seems to be passing, so looks like the reorganized code works correctly.

@dalehamel
Copy link
Contributor

USDTHelper caching logic was previously incorrect. It would mark the
cache as loaded if any pid or path was processed. This would cause
scripts that place usdt probes on different binaries to silently fail
(because a default usdt_probe_entry would be returned).

Ah there it is! Thanks for the explanation. LGTM

danobi added 8 commits June 10, 2020 15:18
This commit just cut and pastes code around. It's nicer to have
small, orthogonal modules.
Keeping unused code around is asking for bit rot and bugs. Also hide
some methods that are used for internal caching.
USDTHelper caching logic was previously incorrect. It would mark the
cache as loaded if any pid or path was processed. This would cause
scripts that place usdt probes on different binaries to silently fail
(because a default usdt_probe_entry would be returned).

This commit breaks up the cache by pid or by path. Also switch
usdt_provider_cache to an unordered_map b/c we don't need ordering and
unordered data structures are faster.

Next commit will get rid of the silent failure behavior.
It's good to have an error reporting mechanism. Returning a default
value caused a lot of headache when trying to debug usdt lookup failures
that were fixed in the previous commit.
Before:

    $ sudo ./build/src/bpftrace -e 'usdt:/usr/bin/python3:python:asdf { 1 }'
    terminate called after throwing an instance of 'std::runtime_error'
      what():  Failed to find usdt probe: usdt:/usr/bin/python3:python:asdf
    [1]    865191 abort      sudo ./build/src/bpftrace -e

After:

    $ sudo ./build/src/bpftrace -e 'usdt:/usr/bin/python3:python:asdf { 1 }'
    Failed to compile: Failed to find usdt probe:
    usdt:/usr/bin/python3:python:asdf
@danobi danobi force-pushed the usdt_multi_module branch from cf1b8e0 to 70eec47 Compare June 10, 2020 22:18
@danobi danobi merged commit 466d241 into bpftrace:master Jun 10, 2020
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.

2 participants