aboutsummaryrefslogtreecommitdiff
path: root/cddl/contrib/opensolaris/lib/libdtrace
Commit message (Collapse)AuthorAgeFilesLines
* dtrace: fix symbol address resolutionJiacong Fang7 days1-9/+5
| | | | | | | | | | | | | | | Dtrace assumes only ELF sections of type SHT_PROGBITS or SHT_NOBITS occupy memory space. However, sections with SHF_ALLOC flag also consume memory space. Moreover, the symbol address initialization skips symbols at the very beginning of a section in ET_REL KLDs. Fix: Check section flag for calculating section offset, and disable the skipping at the beginning of a section. PR: 288000 Reviewed by: markj MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D51188
* libdtrace: Fix formatting of messages about dropsMark Johnston2025-04-152-12/+23
| | | | | | | dt_oformat_drop() should only be called when in structured output mode. Reviewed by: Domagoj Stolfa Fixes: 93f27766a7e1 ("dtrace: Add the 'oformat' libdtrace option")
* libdtrace: Fix an off-by-one in CPU ID handlingMark Johnston2025-03-105-11/+23
| | | | | | | | | | | | | | | | The illumos-specific _SC_CPUID_MAX is the largest CPU ID in the system. This was mapped to _SC_NPROCESSORS_CONF, which is the total number of CPUs recognized by the kernel. If CPU IDs are contiguous, as is the case on amd64 and arm64, this value is one greater than the maximum ID. As a result, when consuming per-CPU dtrace buffers, libdtrace tries to fetch from a non-existent CPU. This is mostly harmless in practice, but still wrong. As we don't have a sysconf value for the maximum CPU ID, add a wrapper which fetches it using the kern.smp.maxid sysctl. MFC after: 2 weeks Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D49243
* libdtrace: Fix an off-by-one in the priority queue implementationMark Johnston2025-03-101-3/+3
| | | | | | | | | | | | | | The zero'th index in the array is unused, so a priority queue of N elements needs N+1 array slots. Fix the allocation. Also fix the assertion in dt_pq_insert(): the assertion needs to be checked after incrementing the count of items in the priority queue, otherwise it can miss an overflow. Reported by: CHERI MFC after: 2 weeks Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D49242
* libdtrace: Use designators to initialize the opcode arrayMark Johnston2025-01-291-80/+80
| | | | | | | No functional change intended. MFC after: 2 weeks Sponsored by: Innovate UK
* libdtrace: Generalize handling of data models a bitMark Johnston2025-01-252-1/+8
| | | | | | | | | | Make it easier to support data models other than ILP32 and LP64 by avoiding constructs which assume that it must be one or the other. No functional change intended. MFC after: 2 weeks Sponsored by: Innovate UK
* libdtrace: Use C99 designated initializers for dt_idops_tMark Johnston2025-01-221-24/+24
| | | | | | | No functional change intended. MFC after: 1 week Sponsored by: Innovate UK
* libdtrace: Be less strict when comparing pointer typesMark Johnston2025-01-011-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | If one of two pointers refers to a forward declaration, let the pointers be compatible so long as the referred types have the same name. Otherwise we can get spurious errors. To give a specific example, this can happen when ipfw_nat.ko is loaded before ipfw.ko and /usr/lib/dtrace/ipfw.d is processed. Currently, ipfw_nat.ko does not have a definition for struct inpcb (i.e., none of its files include in_pcb.h), so in the CTF type graph, struct ip_fw_args' "inp" member refers to a forward declaration, represented in CTF with CTF_K_FORWARD. Then, when libdtrace processes the ipfw_match_info_t translator in ipfw.d, it decides that the "inp" field assignment is incorrect because the two pointers are incompatible. However, there's no harm in allowing this assignment. Add some logic to dt_node_is_ptrcompat() to detect this case and declare the pointers as compatible so long as the name of the thing they refer to is the same, similar to how any pointer is compatible with a void *. Reported by: marck Reviewed by: Domagoj Stolfa <domagoj.stolfa@gmail.com> MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D48254
* 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
* 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
* dtrace: Add the 'oformat' libdtrace optionDomagoj Stolfa2024-01-1011-156/+1612
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* libdtrace: Fix line number reporting in error messagesMark Johnston2023-12-311-0/+2
| | | | MFC after: 1 week
* 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(1): add -d flag to dump D script post-dt_sugarChristos Margiolis2023-05-232-6/+13
| | | | | | | | | | | 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
* 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
* 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
* 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
* libdtrace: Add a missing newline to an error messageMark Johnston2022-02-231-1/+1
| | | | | MFC after: 1 week Sponsored by: The FreeBSD Foundation
* dtrace: remove unnecessary fflush()Chuck Silvers2022-02-101-1/+0
| | | | | | | | | | | This call was added back in the early days of dtrace porting and no one knows why anymore. The extra flushing causes lots of unnecessary CPU overhead when a script produces lots of output, as well as easily losing output because the command can't keep up. Sponsored by: Netflix Reviewed by: imp, markj Differential Revision: https://reviews.freebsd.org/D34216
* dt_unring_buf: set dtbd_oldest to the start of the first recordAndriy Gapon2022-01-111-1/+1
| | | | | | | | | | | It was set to the start of the buffer and that can be different from the start of teh first record because of a misalignment. This change follows the example of dt_realloc_buf(). Reviewed by: tsoome, markj MFC after: 4 weeks Differential Revision: https://reviews.freebsd.org/D33649
* dtrace: fix an out of bound read and a NULL pointer incrementDomagoj Stolfa2021-06-172-2/+8
| | | | | | | | | | | | | | In dt_cc.c when the provider is an empty string, accessing strlen(pdp->dtpd_provider) - 1 will result in a pdp->dtpd_provider[-1] access. Similarly, in dt_ident.c, if p2 is a NULL pointer, doing a p2++ on it is undefined behaviour. Reviewed by: markj MFC after: 1 week Sponsored by: Google Differential Revision: https://reviews.freebsd.org/D30778
* libdtrace: Trivial style fixes to force dt_lex.c to be regeneratedMark Johnston2021-02-201-9/+10
| | | | | | | | | After commit 8ba333e02e ("libdtrace: Stop relying on lex compatibility"), there have been several reports of incremental buildworlds failing since make does not know that dt_lex.c needs to be regenerated, and I want to avoid this when merging to stable/13. MFC with: 8ba333e02e
* libdtrace: Stop relying on lex compatibilityMark Johnston2021-02-171-1/+1
| | | | | | | | | | It does not appear to be required, and as of commit 6b7e592c215f ("lex: Do not let input() return 0 when end-of-file is reached") it causes input to return 0 instead of EOF when end-of-input is reached. PR: 253440 MFC after: 3 days Sponsored by: The FreeBSD Foundation
* libdtrace: Format USDT symbols correctly based on symbol bindingMark Johnston2021-01-101-4/+10
| | | | | | | | | | | Before we did not handle weak symbols correctly, sometimes resulting in link errors from dtrace -G when processing object files where functions with weak aliases contain USDT probes. Reported by: rlibby Tested by: rlibby MFC after: 1 week Sponsored by: The FreeBSD Foundation
* Merge OpenZFS support in to HEAD.Matt Macy2020-08-254-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The primary benefit is maintaining a completely shared code base with the community allowing FreeBSD to receive new features sooner and with less effort. I would advise against doing 'zpool upgrade' or creating indispensable pools using new features until this change has had a month+ to soak. Work on merging FreeBSD support in to what was at the time "ZFS on Linux" began in August 2018. I first publicly proposed transitioning FreeBSD to (new) OpenZFS on December 18th, 2018. FreeBSD support in OpenZFS was finally completed in December 2019. A CFT for downstreaming OpenZFS support in to FreeBSD was first issued on July 8th. All issues that were reported have been addressed or, for a couple of less critical matters there are pull requests in progress with OpenZFS. iXsystems has tested and dogfooded extensively internally. The TrueNAS 12 release is based on OpenZFS with some additional features that have not yet made it upstream. Improvements include: project quotas, encrypted datasets, allocation classes, vectorized raidz, vectorized checksums, various command line improvements, zstd compression. Thanks to those who have helped along the way: Ryan Moeller, Allan Jude, Zack Welch, and many others. Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D25872 Notes: svn path=/head/; revision=364746
* Fix a typo in r364438 affecting 32-bit platforms.Mark Johnston2020-08-221-4/+4
| | | | | | | | Reported by: antoine MFC with: r364438 Notes: svn path=/head/; revision=364483
* Fix a typo in r364438.Mark Johnston2020-08-201-1/+1
| | | | | | | | Reported by: Jenkins MFC with: r364438 Notes: svn path=/head/; revision=364440
* Enable creation of static userspace probes in incremental builds.Mark Johnston2020-08-203-65/+89
| | | | | | | | | | | | | | | | | | To define USDT probes, dtrace -G makes use of relocations for undefined symbols: the target address is overwritten with NOPs and the location is recorded in the DOF section of the output object file. To avoid link errors, the original relocation is destroyed. However, this means that the same input object file cannot be processed multiple times, as happens during incremental rebuilds. Instead, only set the relocation type to NONE, so that all information required to reconstruct USDT probes is preserved. Reported by: bdrewery MFC after: 3 weeks Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=364438
* Remove non-FreeBSD ifdefs from dt_link.c.Mark Johnston2020-08-201-250/+19
| | | | | | | | | | | | This file is too complicated as it is and has diverged a fair bit from illumos due to toolchain differences, so just drop unused code (including SPARC support). MFC after: 1 week Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=364437
* Fix libdtrace build with zsh as /bin/shAlex Richardson2020-08-114-54/+46
| | | | | | | | | | | | When zsh runs in POSIX sh mode it does not support the -e flag to echo. Use printf instead of echo to avoid the "-e" characters being printed. Obtained from: CheriBSD Reviewed By: markj Differential Revision: https://reviews.freebsd.org/D26026 Notes: svn path=/head/; revision=364124
* Fix -DBUILD_WITH_STRICT_TMPPATH dtrace buildsAlex Richardson2020-08-114-0/+4
| | | | | | | | | | | | | | | | | | | Some of the scripts used for libdtrace invoke nawk instead of awk (for example cddl/contrib/opensolaris/lib/libdtrace/common/mknames.sh). When bootstrapping all tools, we get the nawk -> awk link while building usr.bin/awk, but when linking/copying the dependencies from the host we were only adding awk but not nawk. This was silently generating invalid files when building libdtrace with BUILD_WITH_STRICT_TMPPATH=1 since those scripts invoke nawk instead of awk. In addition to adding the missing link this commit also adds set -e to those scripts to catch errors like this in the future. Reviewed By: markj, emaste Differential Revision: https://reviews.freebsd.org/D26025 Notes: svn path=/head/; revision=364123
* Restore the binary compatibility for link_map l_addr.Konstantin Belousov2020-05-211-1/+7
| | | | | | | | | | | | | | | | | Keep link_map l_addr binary layout compatible, rename l_addr to l_base where rtld returns map base. Provide relocbase in newly added l_addr. This effectively reverts the patch to the initial version of D24918. Reported by: antoine (portmgr) Reviewed by: jhb, markj Tested by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D24946 Notes: svn path=/head/; revision=361349
* Do not load dtraceall.ko if dtrace.ko is already loaded.Mark Johnston2020-02-281-1/+1
| | | | | | | | | | | | This was the intent of the existing code, but instead it would unconditionally load dtraceall.ko because of a stale errno value. Reported by: pho MFC after: 1 week Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=358435
* [PowerPC] [DTrace] Add ELFv2 support in libdtraceBrandon Bergren2020-02-051-4/+10
| | | | | | | | | | | | | | | PPC64 ELFv2 acts like a "normal" platform in that it no longer needs function descriptors. So, ensure we are only enabling them on ELFv1. Additionally, ELFv2 requires that the ELF header have a nonzero e_flags, so ensure that the synthesized ELF header in dt_link.c is setting it. Reviewed by: jhibbits, markj Approved by: gnn Differential Revision: https://reviews.freebsd.org/D22403 Notes: svn path=/head/; revision=357590
* Use a deterministic hash for USDT symbol names.Mark Johnston2020-01-071-5/+22
| | | | | | | | | | | | | | Previously libdtrace used ftok(3), which hashes the inode number of the input object file. To increase reproducibility of builds that embed USDT probes, include a hash of the object file path in the symbol name instead. Reported and tested by: bdrewery Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=356477
* Add libdtrace support for arm64 USDT probes.Mark Johnston2019-12-291-8/+70
| | | | | | | | | | | | | arm64 is still lacking a fasttrap implementation, which is required to actually enable userland probes, but this at least allows USDT probes to be linked into userland applications. Submitted by: Klaus Küchemann <maciphone2@googlemail.com> (original) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D22360 Notes: svn path=/head/; revision=356187
* dtrace: avoid gcc9 Walloca-larger-thanRyan Libby2019-12-211-21/+47
| | | | | | | | | | | | gcc9 grew a new warning for unbounded allocas, such as the one in dt_options_load. Remove both uses of alloca in dt_options.c. Reviewed by: markj Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D22880 Notes: svn path=/head/; revision=355973
* MFV r344364:Mark Johnston2019-02-201-4/+3
| | | | | | | | | | | 9058 postmortem DTrace frequently broken under vmware illumos/illumos-gate@793bd7e3617ae7d3d24e8c6b7d6befe35f07ec1f MFC after: 1 week Notes: svn path=/head/; revision=344366