aboutsummaryrefslogtreecommitdiff
path: root/cddl/contrib
Commit message (Collapse)AuthorAgeFilesLines
* dtrace tests: Add a test case which validates FBT probe argumentsMark Johnston2024-09-192-0/+37
| | | | | | Reviewed by: avg MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D46674
* libdtrace: Compute the relocation offset for all non-ET_REL objectsMark Johnston2024-07-101-11/+13
| | | | | | | | The use of an ifdef here most likely carries over from when the dtrace port only worked on x86 platforms. MFC after: 2 weeks Sponsored by: Innovate UK
* libdtrace: Use designated initializers for modules ops tablesMark Johnston2024-07-101-8/+8
| | | | | | | No functional change intended. MFC after: 1 week Sponsored by: Innovate UK
* sdt: Implement SDT probes using hot-patchingMark Johnston2024-06-191-6/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The idea here is to avoid a memory access and conditional branch per probe site. Instead, the probe is represented by an "unreachable" unconditional function call. asm goto is used to store the address of the probe site (represented by a no-op sled) and the address of the function call into a tracepoint record. Each SDT probe carries a list of tracepoints. When the probe is enabled, the no-op sled corresponding to each tracepoint is overwritten with a jmp to the corresponding label. The implementation uses smp_rendezvous() to park all other CPUs while the instruction is being overwritten, as this can't be done atomically in general. The compiler moves argument marshalling code and the sdt_probe() function call out-of-line, i.e., to the end of the function. Per gallatin@ in D43504, this approach has less overhead when probes are disabled. To make the implementation a bit simpler, I removed support for probes with 7 arguments; nothing makes use of this except a regression test case. It could be re-added later if need be. The approach taken in this patch enables some more improvements: 1. We can now automatically fill out the "function" field of SDT probe names. The SDT macros let the programmer specify the function and module names, but this is really a bug and shouldn't have been allowed. The intent was to be able to have the same probe in multiple functions and to let the user restrict which probes actually get enabled by specifying a function name or glob. 2. We can avoid branching on SDT_PROBES_ENABLED() by adding the ability to include blocks of code in the out-of-line path. For example: if (SDT_PROBES_ENABLED()) { int reason = CLD_EXITED; if (WCOREDUMP(signo)) reason = CLD_DUMPED; else if (WIFSIGNALED(signo)) reason = CLD_KILLED; SDT_PROBE1(proc, , , exit, reason); } could be written SDT_PROBE1_EXT(proc, , , exit, reason, int reason; reason = CLD_EXITED; if (WCOREDUMP(signo)) reason = CLD_DUMPED; else if (WIFSIGNALED(signo)) reason = CLD_KILLED; ); In the future I would like to use this mechanism more generally, e.g., to remove branches and marshalling code used by hwpmc, and generally to make it easier to add new tracepoint consumers without having to add more conditional branches to hot code paths. Reviewed by: Domagoj Stolfa, avg MFC after: 2 months Differential Revision: https://reviews.freebsd.org/D44483
* libdtrace: Work around a warning from flexMark Johnston2024-06-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When compiling dt_lex.l, flex produces warnings of the form: dt_lex.l:413: warning, trailing context made variable due to preceding '|' action dt_lex.l:412: warning, dangerous trailing context dt_lex.l:412: warning, dangerous trailing context Here, trailing context refers to the use of "$", which expands to "/\n". The meaning behind these warnings is described in the first two paragraphs of the flex manual's DEFICIENCIES/BUGS section: Some trailing context patterns cannot be properly matched and generate warning messages ("dangerous trailing context"). These are patterns where the ending of the first part of the rule matches the beginning of the second part, such as "zx*/xy*", where the 'x*' matches the 'x' at the beginning of the trailing context. (Note that the POSIX draft states that the text matched by such patterns is undefined.) For some trailing context rules, parts which are actually fixed-length are not recognized as such, leading to the above mentioned performance loss. In particular, parts using '|' or {n} (such as "foo{3}") are always considered variable-length. Here, the warnings appear to be bogus in this case. The lexer has no problem matching either of the referenced patterns, e.g., printf("foobar or # 1 "asdfasdf Introduce a small amount of code duplication to silence the warning. MFC after: 2 weeks
* ctfmerge: demote "No ctf sections found" to a warningEd Maste2024-02-141-8/+2
| | | | | | | | | | | | | | | | | | | | If there are no CTF sections then ctfmerge just has nothing to do; it should not be an error. Note that ctfmerge has an option to require CTF: -t Make sure that all object files have a CTF section. Before this change, this option explicitly exited without error if none of the object files have CTF sections, with the comment: If we're verifying that C files have CTF, it's safe to assume that in this case, we're building only from assembly inputs. PR: 276930 Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D43878
* ctfmerge: Remove function cast of strcompare() for qsort()Minsoo Choo2024-02-031-1/+1
| | | | | | Reviewed by: emaste MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D43715
* dtrace tests: Catch up with ping(8) output changesMark Johnston2024-01-101-1/+1
| | | | MFC after: 1 week
* dtrace tests: Stop hard-coding an incorrect path to sleep(1)Mark Johnston2024-01-104-4/+4
| | | | MFC after: 1 week
* dtrace tests: Run ksh with -pMark Johnston2024-01-1010-10/+10
| | | | | | | | In particular, avoid loading the user's .profile file, since that can have undesirable side effects. Most tests were already careful to do this. MFC after: 1 week
* dtrace: Add the 'oformat' libdtrace optionDomagoj Stolfa2024-01-1039-165/+3744
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This option can be used to specify a format to use in DTrace output. The following formats are supported: - json - xml - html - none (default DTrace output) This is implemented using libxo and integrated into libdtrace. Client code only works with the following API: - dtrace_oformat_setup(dtrace_hdl_t *) -- to be called when output is starting. - dtrace_oformat_teardown(dtrace_hdl_t *) -- to be called when output is finished - dtrace_oformat(dtrace_hdl_t *) -- check if oformat is enabled. - dtrace_set_outfp(FILE *) -- sets the output file for oformat. - Ensure that oformat is correctly checked in the drop handler and record processing callbacks. This commit also adds tests which check if the generated output is valid (JSON, XML) and extends the dtrace(1) describing the structured output. Reviewed by: markj Discussed with: phil MFC after: 2 months Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D41745
* ctfconvert: Handle DW_AT_data_bit_offsetMark Johnston2024-01-021-1/+3
| | | | | | | | | This attribute is new in DWARF 4 and supersedes DW_AT_bit_offset. PR: 276059 Reported by: rscheff Tested by: rscheff MFC after: 1 week
* libdtrace: Fix line number reporting in error messagesMark Johnston2023-12-311-0/+2
| | | | MFC after: 1 week
* Trim various $FreeBSD$John Baldwin2023-10-102-4/+0
| | | | | | Approved by: markj (cddl/contrib changes) Reviewed by: imp, emaste Differential Revision: https://reviews.freebsd.org/D41961
* dtrace: remove dead code for PR_REQUESTEDEric van Gyzen2023-08-011-95/+0
| | | | | | | | | | libproc's PR_REQUESTED is not implemented on FreeBSD. Remove dead code in dtrace that would handle it. Reviewed by: markj MFC after: 1 week Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D41225
* dtrace: do not overload libproc flagsEric van Gyzen2023-08-012-22/+20
| | | | | | | | | | | | | | | | | dtrace stored its PR_RLC and PR_KLC flags in the proc_handle's flags, where they collided with PATTACH_FORCE and PATTACH_RDONLY, respectively. Thus, Psetflags(PR_KLC) effectively also set the PATTACH_RDONLY flag. Since the flags are private to dtrace (at least on FreeBSD), store them in dtrace's own dt_proc structure instead. On FreeBSD, either PR_RLC or PR_KLC was always set, so remove code that would handle the case where neither was set. Reviewed by: markj MFC after: 1 week Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D41121
* dtrace: remove illumos code from dt_proc.cEric van Gyzen2023-08-011-148/+2
| | | | | | | | | | | | The illumos #ifdef's in this file make it harder to read and maintain. There is little change upstream, and increasing changes for FreeBSD. Remove the illumos code with `unifdef`. The only manual changes here are the #includes and #defines at the top, and removing blank lines. Reviewed by: markj MFC after: 1 week Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D41173
* dtrace: prevent forked child from running after an error conditionEric van Gyzen2023-07-121-3/+13
| | | | | | | | | | | | | | | The pid/killonerror test uses an invalid probe specifier to verify that the child process is killed. It occasionally fails because the "date" command is allowed to run long enough to print the date. This is harmless in this case, but is clearly not ideal. When the dt_proc_control thread is about to exit, and the dtrace command forked the child, do not make the child runnable. Reviewed by: markj MFC after: 1 week Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D40976
* dtrace: move kinst tests to commonChristos Margiolis2023-07-041-0/+0
| | | | | | | Reviewed by: markj Approved by: markj (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D40414
* ctfconvert: Integer encoding types are unsignedMark Johnston2023-06-281-3/+3
| | | | | | | | Before this change, encodings in the user-defined range were being sign-extended. MFC after: 1 week Sponsored by: Innovate UK
* kinst: fix memcpy() tracing crashChristos Margiolis2023-05-261-0/+1
| | | | | | | | | | | | Tracing memcpy() would crash the kernel, because we'd also trace the memcpy() calls from kinst_invop(). To fix this, introduce kinst_memcpy() whose arguments are 'volatile', so that we avoid having the compiler replace it with a regular memcpy(). Reviewed by: markj Approved by: markj (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D40284
* dtrace.1: fix mandoc -TlintChristos Margiolis2023-05-231-5/+5
| | | | | | Reviewed by: markj Approved by: markj (mentor) Differential Revision: https://reviews.freebsd.org/D40230
* dtrace(1): add -d flag to dump D script post-dt_sugarChristos Margiolis2023-05-234-10/+28
| | | | | | | | | | | By specifying the -d flag, libdtrace will dump the D script after it has applied syntactical sugar transformations (e.g if/else). This is useful for both understanding what dt_sugar does, as well as debugging it. Reviewed by: markj Approved by: markj (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D38732
* libdtrace: get rid of illumos ifdefs in dt_module_update(), fix dm_file and ↵Christos Margiolis2023-05-231-27/+3
| | | | | | | | | | | | | | dm_modid Because dt_module_update() is highly OS-specific, the ifdefs make it hard to read and follow what is going on. Also handle dm_modid, and remove handling of the ".filename" section, since we can easily fetch the filename from the module's pathname (k_stat->pathname). Reviewed by: markj Approved by: markj (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D39177
* libdtrace: Do not set SHF_ALLOC on SUNW_dof relocation sectionsMark Johnston2023-04-041-2/+2
| | | | | | | | | | | | | The section will contain static relocations which do not need to be preserved after linking, and moreover these relocations may reference symbols that end up getting removed. Do not set SHF_ALLOC and instead let the linker decide what needs to be done. PR: 258872 MFC after: 1 week Sponsored by: The FreeBSD Foundation
* libdtrace: fix indendation in dt_printd()Christos Margiolis2023-03-201-1/+1
| | | | | | | | No functional change. Reviewed by: markj MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D39145
* ctf: Remove unused function prototype for getpname()Zhenlei Huang2023-02-261-2/+0
| | | | | | | | This function prototype should have been removed along with the implementation. Fixes: 3dd552426409 ctfdump: Use getprogname() MFC after: 1 day
* lockstat: Use gelf.h instead of playing games with the preprocessorMark Johnston2023-02-251-13/+8
| | | | | | | This reverts a portion of 1477dd823ee ("Merge OpenZFS support in to HEAD."). No functional change intended. MFC after: 1 week
* lockstat: Use the correct type for a symbol sizeMark Johnston2023-02-251-1/+1
| | | | | | No functional change intended. MFC after: 1 week
* ctfdump: Use getprogname()Zhenlei Huang2023-02-232-25/+1
| | | | | | | | Also remove no longer used function `getpname()`. Reviewed by: markj MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D38740
* libdtrace: add riscv supportMitchell Horne2023-02-061-7/+103
| | | | | | | | | | | Largely untested, as we can't really do anything with user probes without an implementation of fasttrap. However, this is enough to generate an embedded dtrace program with `dtrace -G` and link the generated ELF file. Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D38301
* libdtrace: drop remaining mips supportMitchell Horne2023-02-062-28/+2
| | | | | | Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D38300
* dtrace: remove stray {Kristof Provost2023-01-241-1/+1
| | | | | Fixes: da81cc6035f8283b6adda1ef466977e8c1c5389e PR: 269128
* dtrace: conditionally load the systrace_linux klds when loading dtrace.Andrew Gallatin2023-01-241-0/+9
| | | | | | | | | | | | | | | | | | | When dtrace starts, it tries to detect if the dtrace klds are loaded, and if not, it loads them by loading the dtraceall kld. This module depends on most dtrace modules, including systrace for the native freebsd and freebsd32 ABIs. However, it does not depend on the systrace_linux klds, as they in turn depend on the linux ABI klds, and we don't want to load an ABI module that the user has not explicitly requested. This can leave a naive user in a state where they think all syscall providers have been loaded, yet linux ABI syscalls are "invisible" to dtrace. To fix this, check to see if the linux ABI modules are loaded. If they are, then load their systrace klds. Reviewed by: markj, (emaste & jhb, earlier versions) Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D37986
* libdtrace: Change the binding of USDT probe symbols to STB_WEAKMark Johnston2022-12-111-0/+1
| | | | | | | | | | | | | | | | Otherwise, if multiple object files contain references to the same probe, newish lld will refuse to link them by default, raising a duplicate global symbol definition error. Previously, duplicate global symbols with identical absolute st_values were permitted by both lld and GNU ld. Since dtrace has no use for probe function symbols after the relocation performed by dtrace -G, make the symbols weak as well, following a suggestion from MaskRay. Reported by: dim MFC after: 1 week Sponsored by: The FreeBSD Foundation
* dtrace tests: Extend the kinst regression testMark Johnston2022-12-081-0/+1
| | | | Trace a function which disables interrupts.
* kinst: Add a rudimentary regression test caseMark Johnston2022-10-111-0/+46
| | | | | | | The test instruments a number of large, frequently called kernel functions while generating load in the background. MFC after: 3 months
* libdtrace: Add kinst supportChristos Margiolis2022-10-113-0/+33
| | | | | | | | | | | | kinst does not instantiate its probes automatically, it only does so on demand via an ioctl interface implemented by /dev/kinst. This change modifies libdtrace to perform that work when the script references the kinst provider, similar to the way pid provider probes are implemented. Reviewed by: markj MFC after: 3 months Sponsored by: Google, Inc. (GSoC 2022) Differential Revision: https://reviews.freebsd.org/D36852
* dtrace: Add a "regs" variableMark Johnston2022-10-041-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | This allows invop-based providers (i.e., fbt and kinst) to expose the register file of the CPU at the point where the probe fired. It does not work for SDT providers because their probes are implemented as plain function calls and so don't save registers. It's not clear what semantics "regs" should have for them anyway. This is akin to "uregs", which nominally provides access to the userspace registers. In fact, DIF already had a DIF_VAR_REGS variable defined, it was simply unimplemented. Usage example: print the contents of %rdi upon each call to amd64_syscall(): fbt::amd64_syscall:entry {printf("%x", regs[R_RDI]);} Note that the R_* constants are defined in /usr/lib/dtrace/regs_x86.d. Currently there are no similar definitions for non-x86 platforms. Reviewed by: christos MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D36799
* ctfconvert: Actually use the asprintf() helperMark Johnston2022-08-031-1/+1
| | | | Fixes: 1165fc9a5266 ("ctfconvert: Give bitfield types names distinct from the base type")
* ctfconvert: Give bitfield types names distinct from the base typeMark Johnston2022-08-033-3/+19
| | | | | | | | | | | | | | | | | | CTF integers have an explicit width and so can be used to represent bitfields. Bitfield types emitted by ctfconvert(1) share the name of the base integer type, so a struct field with type "unsigned int : 15" will have a type named "unsigned int". To avoid ambiguity when looking up types by name, add a suffix to names of bitfield types to distinguish them from the base type. Then, if ctfmerge happens to order bitfield types before the corresponding base type in a CTF file, a name lookup will return the base type, which is always going to be the desired behaviour. PR: 265403 Reported by: cy MFC after: 1 week Sponsored by: The FreeBSD Foundation
* dtrace tests: Rename some test type names to avoid a conflictMark Johnston2022-08-031-6/+6
| | | | | MFC after: 1 week Sponsored by: The FreeBSD Foundation
* dtrace tests: Override RLIMIT_CORE for a test which triggers a core dumpMark Johnston2022-08-031-1/+1
| | | | | MFC after: 1 week Sponsored by: The FreeBSD Foundation
* lockstat: Fix construction of comparision predicatesKornel Dulęba2022-07-041-2/+2
| | | | | | | | | | | | | | Passing "0x%p" to sprintf results in double "0x" being printed. This causes a dtrace script compilation failure when "-d" flag is specified. Fix that by removing the extraneous "0x". Reviewed by: markj Approved by: mw(mentor) Obtained from: Semihalf Sponsored by: Alstom MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D35690
* dtrace: Remove local mips supportBrooks Davis2022-07-011-75/+0
| | | | | | | | Remove the stub pid probe and all the build glue. Reviewed by: imp, jhb Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D35541
* ctfdump: Remove definitions of warn() and vwarn()Mark Johnston2022-04-213-31/+2
| | | | | | | | | | | The presence of the latter causes a link error when building a statically linked ctfdump(1) because libc defines the same symbol. libc's warn() is defined as a weak symbol and so does not cause the same problem, but let's just use libc's version. Reported by: stephane rochoy <stephane.rochoy@stormshield.eu> MFC after: 1 week Sponsored by: The FreeBSD Foundation
* libctf: Fix recursive descent into anonymous SOU fieldsMark Johnston2022-04-121-2/+2
| | | | | | | | PR: 262412 Tested by: dhw, gallatin Fixes: a6fb86917362 ("libctf: Handle CTFv3 containers") MFC after: 3 days Sponsored by: The FreeBSD Foundation
* dtrace tests: Fix expected outout for tst.system.dLi-Wen Hsu2022-03-091-6/+6
| | | | | | | This is follow up of d500a85e640d1cd270747c12e17c511b53864436 PR: 262415 Sponsored by: The FreeBSD Foundation
* zfs: merge openzfs/zfs@a86e08941 (master) into mainMartin Matuska2022-03-081-2/+2
| | | | | | | | | | | | | | | | | | | | Notable upstream pull request merges: #9078: log xattr=sa create/remove/update to ZIL #11919: Cross-platform xattr user namespace compatibility #13014: Report dnodes with faulty bonuslen #13016: FreeBSD: Fix zvol_cdev_open locking #13019: spl: Don't check FreeBSD rwlocks for double initialization #13027: Fix clearing set-uid and set-gid bits on a file when replying a write #13031: Add enumerated vdev names to 'zpool iostat -v' and 'zpool list -v' #13074: Enable encrypted raw sending to pools with greater ashift #13076: Receive checks should allow unencrypted child datasets #13098: Avoid dirtying the final TXGs when exporting a pool #13172: Fix ENOSPC when unlinking multiple files from full pool Obtained from: OpenZFS OpenZFS commit: a86e089415679cf1b98eb424a159bb36aa2c19e3
* ctf: Avoid passing a caddr_t to roundup2()Mark Johnston2022-03-071-1/+1
| | | | | | | For some reason I can't reproduce this locally, but Jenkins complains. Reported by: Jenkins Fixes: bdf290cd3e1a ("ctf: Add v3 support to CTF tools, ctf{convert,dump,merge}")