Comments (5)
Note that the one-liner that should work may really be this:
./src/bpftrace -e 'kprobe:do_nanosleep { printf("%x\n", *kaddr("avenrun")); }'
I missed the dereference earlier.
from bpftrace.
This function reads the memory address just like # grep -w avenrun /proc/kallsyms
.
My question is where or if I should print the output?
uint64_t BPFtrace::resolve_kname(const char *name)
{
uint64_t addr = 0;
std::string file_name = "/proc/kallsyms";
std::ifstream file(file_name);
if (file.fail())
{
std::cerr << strerror(errno) << ": " << file_name << std::endl;
return addr;
}
std::string line;
std::string search = "\\b( ";
search += name;
std::regex e (search + ")");
std::smatch match;
while (std::getline(file, line) && addr == 0)
{
auto found = std::regex_search (line, match, e);
if (found)
{
std::string first_word = line.substr(0, line.find(" "));
addr = std::stoull(first_word, 0, 16);
}
}
return addr;
}```
from bpftrace.
I don't understand your question. I think if you drop that function into the earlier patch, it should all work, right? BPFtrace::resolve_kname() doesn't need to print anything itself, it just needs to return the address.
This should print avenrun's location (as seen in /proc):
# ./src/bpftrace -e 'kprobe:do_nanosleep { printf("%llx\n", kaddr("avenrun")); }'
And this should print the value of avenrun:
# ./src/bpftrace -e 'kprobe:do_nanosleep { printf("%x\n", *kaddr("avenrun")); }'
Shouldn't you call close on file at the end?
from bpftrace.
Ok, # ./src/bpftrace -e 'kprobe:do_nanosleep { printf("%llx\n", kaddr("avenrun")); }'
prints what I was expecting.
And yes, I forgot to close the file.
from bpftrace.
I realized the tests/codegen.cpp call_kaddr test may always fail, since it would embed the avenrun location into the test output, which would change between systems. Hm. Unless there's a simple way to fix this, I'd be inclined to delete the call_kaddr test and replace it with a // TODO: test kaddr()
.
from bpftrace.
Related Issues (20)
- Support calling kfuncs
- Add new runtime tests to validate the order of probe firing
- Assigning string literals to variables of different size doesn't clear old data HOT 1
- uprobe DWARF location attachment does not work with uprobe_multi HOT 5
- Increment operator cause unnecessary data races by always calling bpf_map_update_elem HOT 3
- subprogram support causes problems accessing fentry args named 'fn' HOT 3
- Incorrect number of probes being attached reported with kprobe globbing HOT 3
- For-loops do not handle BPF context HOT 1
- Specialize non-associative maps to be BPF_MAP_TYPE_ARRAY
- Support synchronously printing special map types HOT 1
- Data corruption when using `printf` and/or `if` on an associative-array map HOT 5
- Can't trace a uprobe set with perf: `ioctl(PERF_EVENT_IOC_SET_BPF): Invalid argument` HOT 3
- Clarify install & supported distros HOT 2
- flex scanner push-back overflow HOT 2
- Crash when looping over map containing avg() HOT 5
- Crash when assigning a record type to map
- btf_type_tag attributes cause problems with member dereferencing HOT 3
- "liblldb not available" warning is to noisy for release or non-verbose builds
- Fully remove BPFTRACE_MAX_STRLEN config HOT 3
- CI should be building most workflows in debug mode
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bpftrace.