Commit graph

1025 commits

Author SHA1 Message Date
Ed Maste 95ca89cda1 ctfmerge: demote "No ctf sections found" to a warning
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
2024-02-14 15:53:11 -05:00
Minsoo Choo f73124b077 ctfmerge: Remove function cast of strcompare() for qsort()
Reviewed by:	emaste
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43715
2024-02-03 14:09:52 -05:00
Mark Johnston ba10366037 dtrace tests: Catch up with ping(8) output changes
MFC after:	1 week
2024-01-10 18:19:00 -05:00
Mark Johnston 9f5dd61e14 dtrace tests: Stop hard-coding an incorrect path to sleep(1)
MFC after:	1 week
2024-01-10 18:18:01 -05:00
Mark Johnston e25922b34e dtrace tests: Run ksh with -p
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
2024-01-10 18:17:59 -05:00
Domagoj Stolfa 93f27766a7 dtrace: Add the 'oformat' libdtrace option
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
2024-01-10 18:14:26 -05:00
Mark Johnston 78cd75393e ctfconvert: Handle DW_AT_data_bit_offset
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
2024-01-01 23:12:29 -05:00
Mark Johnston ad3174ecea libdtrace: Fix line number reporting in error messages
MFC after:	1 week
2023-12-31 12:47:30 -05:00
John Baldwin f53355131f Trim various $FreeBSD$
Approved by:	markj (cddl/contrib changes)
Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D41961
2023-10-10 10:34:43 -07:00
Eric van Gyzen 1112883e19 dtrace: remove dead code for PR_REQUESTED
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
2023-08-01 12:28:50 -05:00
Eric van Gyzen bcbce2a29b dtrace: do not overload libproc flags
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
2023-08-01 12:28:50 -05:00
Eric van Gyzen 837f6ecd88 dtrace: remove illumos code from dt_proc.c
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
2023-08-01 12:28:50 -05:00
Eric van Gyzen dad11f990e dtrace: prevent forked child from running after an error condition
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
2023-07-12 10:33:28 -05:00
Christos Margiolis 911f026039 dtrace: move kinst tests to common
Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40414
2023-07-04 18:46:59 +03:00
Mark Johnston 258a0d760a ctfconvert: Integer encoding types are unsigned
Before this change, encodings in the user-defined range were being
sign-extended.

MFC after:	1 week
Sponsored by:	Innovate UK
2023-06-28 16:29:49 -04:00
Christos Margiolis 5c134fba22 kinst: fix memcpy() tracing crash
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
2023-05-26 18:43:37 +03:00
Christos Margiolis ed35c7cf77 dtrace.1: fix mandoc -Tlint
Reviewed by:	markj
Approved by:	markj (mentor)
Differential Revision:	https://reviews.freebsd.org/D40230
2023-05-23 17:29:19 +03:00
Christos Margiolis 1e136a9cbd dtrace(1): add -d flag to dump D script post-dt_sugar
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
2023-05-23 17:18:39 +03:00
Christos Margiolis 6265da14c9 libdtrace: get rid of illumos ifdefs in dt_module_update(), fix dm_file and 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
2023-05-23 15:54:58 +03:00
Mark Johnston 27f35b7dd4 libdtrace: Do not set SHF_ALLOC on SUNW_dof relocation sections
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
2023-04-04 14:08:16 -04:00
Christos Margiolis 3afba490c1 libdtrace: fix indendation in dt_printd()
No functional change.

Reviewed by:	markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39145
2023-03-20 09:34:20 -04:00
Zhenlei Huang f8e1aa85fe ctf: Remove unused function prototype for getpname()
This function prototype should have been removed along with the
implementation.

Fixes:		3dd5524264 ctfdump: Use getprogname()
MFC after:	1 day
2023-02-26 12:18:25 +08:00
Mark Johnston 49e3972afc lockstat: Use gelf.h instead of playing games with the preprocessor
This reverts a portion of 1477dd823e ("Merge OpenZFS support in to
HEAD.").  No functional change intended.

MFC after:	1 week
2023-02-24 20:16:51 -05:00
Mark Johnston f4f5e69c84 lockstat: Use the correct type for a symbol size
No functional change intended.

MFC after:	1 week
2023-02-24 20:11:08 -05:00
Zhenlei Huang 3dd5524264 ctfdump: Use getprogname()
Also remove no longer used function `getpname()`.

Reviewed by:	markj
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D38740
2023-02-24 00:28:35 +08:00
Mitchell Horne f711d5c3d0 libdtrace: add riscv support
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
2023-02-06 15:26:53 -04:00
Mitchell Horne 2166649fa1 libdtrace: drop remaining mips support
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D38300
2023-02-06 15:26:53 -04:00
Kristof Provost ecdd0b48cb dtrace: remove stray {
Fixes:	da81cc6035
PR:	269128
2023-01-24 08:39:37 +01:00
Andrew Gallatin da81cc6035 dtrace: conditionally load the systrace_linux klds when loading dtrace.
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
2023-01-23 20:36:24 -05:00
Mark Johnston be39466a10 libdtrace: Change the binding of USDT probe symbols to STB_WEAK
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
2022-12-11 11:27:22 -05:00
Mark Johnston add8a6c9ac dtrace tests: Extend the kinst regression test
Trace a function which disables interrupts.
2022-12-08 15:07:48 -05:00
Mark Johnston 19a847e5f2 kinst: Add a rudimentary regression test case
The test instruments a number of large, frequently called kernel
functions while generating load in the background.

MFC after:	3 months
2022-10-11 18:19:55 -04:00
Christos Margiolis 2179a159ea libdtrace: Add kinst support
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
2022-10-11 18:19:08 -04:00
Mark Johnston bdd101c4d4 dtrace: Add a "regs" variable
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
2022-10-04 13:05:54 -04:00
Mark Johnston 6237c3e74f ctfconvert: Actually use the asprintf() helper
Fixes:	1165fc9a52 ("ctfconvert: Give bitfield types names distinct from the base type")
2022-08-02 20:49:50 -04:00
Mark Johnston 1165fc9a52 ctfconvert: Give bitfield types names distinct from the base type
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
2022-08-02 20:32:17 -04:00
Mark Johnston 6a05f14381 dtrace tests: Rename some test type names to avoid a conflict
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2022-08-02 20:32:08 -04:00
Mark Johnston e1700a36a9 dtrace tests: Override RLIMIT_CORE for a test which triggers a core dump
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2022-08-02 20:32:04 -04:00
Kornel Dulęba 9dbacce2d4 lockstat: Fix construction of comparision predicates
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
2022-07-04 16:22:22 +02:00
Brooks Davis 711d50bd9e dtrace: Remove local mips support
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
2022-07-01 08:33:17 +01:00
Mark Johnston 45dd2eaac3 ctfdump: Remove definitions of warn() and vwarn()
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
2022-04-21 11:18:53 -04:00
Mark Johnston 6e563a1b60 libctf: Fix recursive descent into anonymous SOU fields
PR:		262412
Tested by:	dhw, gallatin
Fixes:		a6fb869173 ("libctf: Handle CTFv3 containers")
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
2022-04-12 17:29:53 -04:00
Li-Wen Hsu 16e02ae401
dtrace tests: Fix expected outout for tst.system.d
This is follow up of d500a85e64

PR:		262415
Sponsored by:	The FreeBSD Foundation
2022-03-09 11:39:12 +08:00
Martin Matuska c03c5b1c80 zfs: merge openzfs/zfs@a86e08941 (master) into main
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:	a86e089415
2022-03-08 18:53:02 +01:00
Mark Johnston 3fe1f21fb3 ctf: Avoid passing a caddr_t to roundup2()
For some reason I can't reproduce this locally, but Jenkins complains.

Reported by:	Jenkins
Fixes:		bdf290cd3e ("ctf: Add v3 support to CTF tools, ctf{convert,dump,merge}")
2022-03-07 11:20:57 -05:00
Mark Johnston cb6f722562 ctf: Fix a -Wunused-but-set-variable warning
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2022-03-07 10:43:19 -05:00
Mark Johnston bdf290cd3e ctf: Add v3 support to CTF tools, ctf{convert,dump,merge}
ctfdump handles v2 and v3.  ctfconvert now emits only CTFv3, whereas
ctfmerge can merge v2 and v3 containers into v3 containers.

MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34364
2022-03-07 10:43:19 -05:00
Mark Johnston a6fb869173 libctf: Handle CTFv3 containers
In general, the patch adds indirection to minimize the amount of code
that needs to know about differences between v2 and v3.  Specifically,
some new ctf_get_ctt_* functions are added, and new LCTF_* macros are
added to use the underlying container's version to do the right thing.

CTF containers can have parent/child relationships, wherein a type ID in
one container refers to a type in the parent.  It is permitted for the
parent and child to have different versions.

MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34363
2022-03-07 10:43:19 -05:00
Mark Johnston 994297b01b ctf: Add definitions for CTFv3
These are based on definitions added to binutils' libctf.  Specifically:
- Type IDs are now encoded in 32 bits rather than 16, changing the
  layout of ctf_type_t, ctf_array_t, ctf_member_t and ctf_lmember_t.
- Type info is encoded in 32 bits rather than 16.  The type "kind" is
  extended from 5 bits to 6, and the type "vlen" is extended from 10
  bits to 25.

The main upside is that we remove the current limit, imposed by CTFv2,
of 2^{15} distinct types in the main kernel executable.  Other limits,
such as that on the number of elements in an enum, imposed by the vlen
limit, are also raised.

This change adds v2 and v3 flavours of macros and type definitions which
differ between the two versions.  Compatibility is preserved for now by
having generic names refer to the v2 definitions, so, e.g., ctf_type_t
is still a v2 type.

No functional change intended.

Reviewed by:	Domagoj Stolfa
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34360
2022-03-07 10:43:18 -05:00
Mark Johnston 2d5d2a986c ctf: Import ctf.h from OpenBSD
Use it instead of the existing ctf.h from OpenSolaris.  This makes it
easier to use CTF in the core kernel, and to extend the CTF format to
support wider type IDs.

The imported ctf.h is modified to depend only on _types.h, and also to
provide macros which use the "parent" bit of a type ID to refer to types
in a parent CTF container.

No functional change intended.

Reviewed by:	Domagoj Stolfa, emaste
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34358
2022-03-07 10:43:18 -05:00