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

Make kaddr() report failure for unknown kernel symbols #1836

Merged
merged 1 commit into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ and this project adheres to
- [#1776](https://github.com/iovisor/bpftrace/pull/1776)
- Reduce frequency of lost stack traces
- [#1812](https://github.com/iovisor/bpftrace/pull/1812)
- Make kaddr() report failure for unknown kernel symbols
- [#1836](https://github.com/iovisor/bpftrace/pull/1836)

#### Tools

Expand Down
2 changes: 2 additions & 0 deletions src/ast/codegen_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,8 @@ void CodegenLLVM::visit(Call &call)
uint64_t addr;
auto name = bpftrace_.get_string_literal(call.vargs->at(0));
addr = bpftrace_.resolve_kname(name);
if (!addr)
throw std::runtime_error("Failed to resolve kernel symbol: " + name);
Copy link
Member

Choose a reason for hiding this comment

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

we should be able to use LOG here

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure about that. codegen isn't hooked up to check for error messages like semantic_analyser is. Could LOG(FATAL) but it'd be better if we had a nice message instead

Copy link
Member Author

Choose a reason for hiding this comment

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

Unless you mean we should in the future. In which case my suggestion would be that this shouldn't happen in codegen anyways. I'll probably clean this up as part of my AOT project

Copy link
Member

Choose a reason for hiding this comment

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

ah yeah, only FATAL works here.

expr_ = b_.getInt64(addr);
}
else if (call.func == "uaddr")
Expand Down
5 changes: 5 additions & 0 deletions tests/runtime/basic
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,8 @@ NAME disable warnings
RUN bpftrace --no-warnings -e 'BEGIN { @x = stats(10); print(@x, 2); clear(@x); exit();}' 2>&1| grep -c -E "WARNING|invalid option"
EXPECT ^0$
TIMEOUT 1

NAME kaddr fails
RUN bpftrace -e 'BEGIN { print(kaddr("asdfzzzzzzz")) }'
EXPECT Failed to resolve kernel symbol
TIMEOUT 1