Commit 4a048fcc authored by Augusto Caringi's avatar Augusto Caringi

Add support to list tracepoint arguments (#323)

parent 62285be0
...@@ -230,6 +230,17 @@ kprobe:hrtimer_nanosleep ...@@ -230,6 +230,17 @@ kprobe:hrtimer_nanosleep
[...] [...]
``` ```
The `-v` option when listing tracepoints will show their arguments for use from the args builtin. For example:
```
# bpftrace -lv tracepoint:syscalls:sys_enter_open
tracepoint:syscalls:sys_enter_open
int __syscall_nr;
const char * filename;
int flags;
umode_t mode;
```
## 5. `-d`: Debug Output ## 5. `-d`: Debug Output
The `-d` option produces debug output, and does not run the program. This is mostly useful for debugging issues with bpftrace itself. The `-d` option produces debug output, and does not run the program. This is mostly useful for debugging issues with bpftrace itself.
......
...@@ -77,6 +77,42 @@ void list_probes_from_list(const std::vector<ProbeListItem> &probes_list, ...@@ -77,6 +77,42 @@ void list_probes_from_list(const std::vector<ProbeListItem> &probes_list,
} }
} }
void print_tracepoint_args(const std::string &category, const std::string &event)
{
std::string format_file_path = tp_path + "/" + category + "/" + event + "/format";
std::ifstream format_file(format_file_path.c_str());
std::regex re("^ field:.*;$", std::regex::icase | std::regex::grep | std::regex::nosubs |
std::regex::optimize);
std::string line;
if (format_file.fail())
{
std::cerr << "ERROR: tracepoint format file not found: " << format_file_path << std::endl;
return;
}
// Skip lines until the first empty line
do {
getline(format_file, line);
} while (line.length() > 0);
for (; getline(format_file, line); )
{
try {
if (std::regex_match(line, re))
{
unsigned idx = line.find(":") + 1;
line = line.substr(idx);
idx = line.find(";") + 1;
line = line.substr(0, idx);
std::cout << " " << line << std::endl;
}
} catch(std::regex_error& e) {
return;
}
}
}
void list_probes(const std::string &search) void list_probes(const std::string &search)
{ {
unsigned int i, j; unsigned int i, j;
...@@ -118,9 +154,16 @@ void list_probes(const std::string &search) ...@@ -118,9 +154,16 @@ void list_probes(const std::string &search)
} }
std::cout << probe << std::endl; std::cout << probe << std::endl;
if (bt_verbose)
print_tracepoint_args(cats[i], events[j]);
} }
} }
// Optimization: If the search expression starts with "t" (tracepoint) there is
// no need to search for kprobes.
if (search.rfind("t", 0) == 0)
return;
// kprobes // kprobes
std::ifstream file(kprobe_path); std::ifstream file(kprobe_path);
if (file.fail()) if (file.fail())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment