summaryrefslogtreecommitdiff
path: root/usr.sbin/btrace/btrace.c
AgeCommit message (Collapse)Author
2024-07-09Read the whole buffer, not its size minus one.Martin Pieuchot
From Christian Ludwig cludwig at genua.de.
2024-05-21remove prototypes with no matching function and externs with no varJonathan Gray
partly checked by millert@
2024-03-30Implement else branching logic including 'else if'.Martin Pieuchot
Statement lists for if & else conditions are now wrapped in a new 'struct bt_cond'. Handling B_AC_TEST statements moved to stmt_eval() to handle nested conditional statements. From Christian Ludwig christian_ludwig at genua.de
2024-02-27Make it possible to check for existing string in maps.Martin Pieuchot
2024-02-24Check for builtins used inside tuple to ask the kernel to copyout specific data.Martin Pieuchot
Allow to save stacktrace and process name in tuples.
2024-02-24Implement 'store' for maps.Martin Pieuchot
A current limitation is the value read from a map is converted to an integer. To preserve the original type we have to make maps aware of the type of its elements.
2024-02-24Implement 'store' for all builtins, they are either string or integer.Martin Pieuchot
2024-02-12Fix tuple & string comparisons in maps.Martin Pieuchot
2024-02-05Print statistics on stderr to be able to redirect bt(5) script output.Martin Pieuchot
From Christian Ludwig.
2024-01-25Return 0 when accessing an argument not defined in a probe.Martin Pieuchot
Adapted from a fix from Christian Ludwig.
2024-01-23Consider the whole tuple when reading a map entry whose key is that tuple.Martin Pieuchot
Previously only the first element of the tuple was considered. This led to the introduction of new map entries. Reported by Christian Ludwig.
2023-11-10zap some unused includesJasper Lievisse Adriaanse
2023-10-22bt(5), btrace(8): execute END probe and print non-empty maps upon exit()Scott Soule Cheloha
BPFTrace's exit() statement executes the END probe (if any) and prints the contents of all non-empty maps before terminating the interpreter. Implement this in btrace(8) with a halting check after each statement. If a statement causes the program to halt, the condition bubbles up to the top-level evaluation loop and causes rules_teardown() to run immediately. btrace(8) still performs a full rules_setup() if exit() is called during the BEGIN probe, though the top-level evaluation loop is never run. One edge-like case: an exit() from the END probe is treated as an early return; END is not executed multiple times. Thread: https://marc.info/?l=openbsd-tech&m=169765169420751&w=2 ok mpi@
2023-10-12bt(5), btrace(8): add support for binary modulo operator ('%')Scott Soule Cheloha
Link: https://marc.info/?l=openbsd-tech&m=169695435209410&w=2 ok mpi@
2023-09-15Also update usage() to include [-p file].Claudio Jeker
2023-09-13Properly evaluate variables when inserting them into a map.Martin Pieuchot
Somehow missed in previous, regression reported by anton@.
2023-09-11Implement tuples, needed to export per-CPU scheduling data.Martin Pieuchot
It is now possible to save and print immutable arrays as below: ..$t = (1, 42, "something"); ..printf("%d %s\n", $t.1, $t.2); Also add support for evaluating builtin in order to save them in variables (required by tuples)
2023-09-02btrace(8): fix probe builtin in BEGIN/END.Dave Voutila
Resolves segfaults when using probe within BEGIN or END. ok mpi@
2023-08-16Backout changes for btrace(8) argN builtins.Dave Voutila
Talking with mpi@, going to rework this to be part of the parser. Reverts commit 0iIzGtIFgBXVfbNa.
2023-08-15btrace(8): fix out of bounds read using argN in BEGIN/END.Dave Voutila
The argN builtins aren't valid in BEGIN or END actions. The fake probe number btrace uses to facilitate other valid builtins caused an out of bound read of an array, producing a segfault. Change the fake probe number to 0 as it's an unsigned int and check for that condition. Adds asserts near other probe array indexing to catch future issues. ok kn@
2023-08-13Add support for storing builtin TID and PID in variables.Martin Pieuchot
2023-06-27Make it possible to store the kstack or ustack in a map (as value, not key).Claudio Jeker
Additionally fix the bacmp() function to work on integers and strings. bacmp() is used when maps are printed out since the output is sorted by value. Also adjust the rule parser to look into correctly into if branches to figure out which values to request from the kernel. OK kn@
2023-05-12btrace(8) support to symbolize utrace addresses.Claudio Jeker
This only works for a single static binary where everything was compiled with -fno-omit-frame-pointer since the stack unwinder requires the frame-pointer. A possible btrace script to capture performace of a single process is: profile:hz:100 / pid == $1 / { @[ustack] = count(); } Then using btrace -p program uprofile.bt `pgrep program` will collect the information for program. This is far from perfect but should allow other people to play with this and hopefully improve work. OK mpi@
2023-03-10btrace(8) retrieves the types of the arguments of each tracepointAlexander Bluhm
from the kernel. Add them to a cache when needed, and print them with btrace -l. If the argument is of type int, print the value as %d signed integer. This gives pretty output for refcnt changes. All other types still use %ul. The probe and argument number can be used as array index. Remove the qsort and search for probe number to simplify the code. Use array index for both probes and argument types. OK mpi@
2022-12-28spelling fixes; from paul tagliamonteJason McIntyre
any parts of his diff not taken are noted on tech
2022-11-12Add support for string comparison in filters.Martin Pieuchot
It is now possible to filter by process name, like: syscall:mmap:entry /comm == "ld"/ { ... } Currently the parser treats C-string like any other expression member even if arithmetic operations do no apply to strings.
2022-11-11Add support for storing builtins arguments into local variables.Martin Pieuchot
2022-11-11Add support for multiple statements in if () blocks.Martin Pieuchot
2022-11-11typoMartin Pieuchot
2022-06-02Let btrace(8) execute the END probe upon receiving a SIGTERM signalJeremie Courreges-Anglas
While SIGINT (already handled) makes sense for interactive use, handling SIGTERM in the same manner is less surprising for scripting. This lets you do: btrace ... & some workload; kill $! and get the expected output. ok mpi@
2022-02-22Since other exported commandnames were increased to 24 and graduated intoTheo de Raadt
proper strings, adapt dt's exported string in the same way. Old/new files/tools will not work the same way. That this interface needs to also change was pointed out by jsg
2021-12-07Delete the last emulation callbacks: we're Just ELF, so declarePhilip Guenther
exec_elf_fixup() and coredump_elf() in <sys/exec_elf.h> and call them and the MD setregs() directly in kern_exec.c and kern_sig.c Also delete e_name[] (only used by sysctl), e_errno (unused), and e_syscallnames[] (only used by SYSCALL_DEBUG) and constipate syscallnames to 'const char *const[]' ok kettenis@
2021-11-12Implement the probe variable. Can be used for example withClaudio Jeker
@map[probe] = count(); OK mpi@
2021-10-24Use unveil(2) for the possible script file, dt(4) and ksyms(4) nodes.Martin Pieuchot
btrace(8) cannot be pledge due to its use of special ioctl()s. ok deraadt@
2021-10-03bt(5)/btrace(8): add support for str()Dave Voutila
Implement initial support for the str() function, which is used primarily to truncate or NUL-terminate strings from either cli args or args to tracepoints and syscalls. Current implementation only supports cli args and is primarily for compatability with bpftrace. Future work is needed once dt(4) supports builtin args other than long values. Adds a regress test and wires in argument-based tests again. ok mpi@
2021-09-21Add NUL termination to btfile content to avoid that strlcpy(3) readsAlexander Bluhm
too much in btrace(8). OK mpi@ deraadt@
2021-09-09fix crash when passing empty cli arguments as B_AT_NIL wasn't handled as a ↵Jasper Lievisse Adriaanse
valid argument type found with afl++ ok mpi@
2021-09-09Let ba2str() handle unitialized map just like ba2long() does.Martin Pieuchot
2021-09-09Make it possible to associate multiple probes to a single rule.Martin Pieuchot
The following syntax, reducing duplication, is now allowed: END, interval:hz:2 { ... } Rule descriptors are now linked to a list of probe descriptors instead of a single one. Enabled kernel probes are now linked to btrace(8) probe descriptors. While here stop parsing filter and probe if debug is not enabled.
2021-09-09Handle new NIL type in ba_name().Martin Pieuchot
Fix filter debugging.
2021-09-09Do not treat empty map has invalid.Martin Pieuchot
2021-09-09Use a dynamic buffer to allow parsing scripts bigger than BUFSIZ.Martin Pieuchot
ok jasper@
2021-09-09Make sure all map operators work after calling clear() on a map.Martin Pieuchot
Fix assertions found by jasper@ with AFL++. ok jasper@
2021-09-08btrace(8): add initial support for cli argumentsDave Voutila
This adds initial support for passing cli args to btrace(8) for use in bt(5) scripts. Similar to bpftrace, they are referenced via $1, $2, etc. with $# being the number of command line arguments provided. Adds an initial regress test and a Makefile change to allow providing arguments to regress tests in a .args file. Currently no limit is imposed on the number of arguments, keeping a similar approach as observed in bpftrace. References to undefined arguments result in a new "nil" type that contextually acts as a zero or empty string. More work can be done here to improve bpftrace compatibility. ok mpi@, jasper@
2021-09-07Check that map/hist functions are called with the right argument.Martin Pieuchot
Change the parser to make clear() and zero() accept only local and global variables as arguments. Since the parser has no knowledge of the type of a variable abort the execution if clear() or zero() are being called with something other than a map or hist. Fix assertions found by jasper@ with AFL++ (port coming soon!). ok jasper@
2021-09-03add kprobes provider for dtJasper Lievisse Adriaanse
this allows us to dynamically trace function boundaries with btrace by patching prologues and epilogues with a breakpoint upon which the handler records the data, sends it back to userland for btrace to consume. currently it's hidden behind DDBPROF, and there is still a lot to cleanup and improve, but basic scripts that observe return codes from a probed function work. from Tom Rollet, with various changes by me feedback and ok mpi@
2021-09-02rename struct dt_evt fields to make it clear this isn't only used for ↵Jasper Lievisse Adriaanse
tracing syscalls and adjust btrace(8) accordingly. extracted from a larger diff by Tom Rollet. ok mpi@
2021-09-01Handle the case where map/hist can be read after calling clear().Martin Pieuchot
Fix a NULL-derference found by jasper@ with AFL++ (port coming soon!). ok jasper@
2021-09-01Always print non-empty map & hist on exit even if there's an END rule.Martin Pieuchot
Match bpftrace behavior.
2021-09-01Support for insert pid/tid/cpu builtins in map/hist.Martin Pieuchot