Commit graph

999 commits

Author SHA1 Message Date
Mark Johnston 693dbc0070 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

(cherry picked from commit 78cd75393e)
2024-01-08 20:00:31 -05:00
Mark Johnston 6418d08ae4 libdtrace: Fix line number reporting in error messages
MFC after:	1 week

(cherry picked from commit ad3174ecea)
2024-01-07 11:56:42 -05:00
John Baldwin 37ba303aa0 Trim various $FreeBSD$
Approved by:	markj (cddl/contrib changes)
Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D41961

(cherry picked from commit f53355131f)
2023-10-24 11:23:57 -07:00
Mark Johnston 44ee4e90a3 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

(cherry picked from commit 258a0d760a)
2023-07-05 09:07:06 -04:00
Mark Johnston f22bd73428 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

(cherry picked from commit 27f35b7dd4)
2023-04-11 10:10:24 -04:00
Christos Margiolis 3813808b1f libdtrace: fix indendation in dt_printd()
No functional change.

Reviewed by:	markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39145

(cherry picked from commit 3afba490c1)
2023-03-27 08:49:30 -04:00
Mark Johnston 1a0e3257ca 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

(cherry picked from commit 49e3972afc)
2023-03-05 12:24:26 -05:00
Mark Johnston 04e14db224 lockstat: Use the correct type for a symbol size
No functional change intended.

MFC after:	1 week

(cherry picked from commit f4f5e69c84)
2023-03-05 12:24:17 -05:00
Zhenlei Huang eba26d0ba3 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

(cherry picked from commit f8e1aa85fe)
2023-02-27 11:12:48 +08:00
Zhenlei Huang 994eb2fb8a ctfdump: Use getprogname()
Also remove no longer used function `getpname()`.

Reviewed by:	markj
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D38740

(cherry picked from commit 3dd5524264)
2023-02-26 09:53:15 +08:00
Mark Johnston 98492960c3 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

(cherry picked from commit be39466a10)
2022-12-19 09:56:38 -05:00
Mark Johnston 247ea4381b 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

(cherry picked from commit bdd101c4d4)
2022-10-18 09:58:11 -04:00
Mark Johnston a853b4c425 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
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 1165fc9a52)
2022-08-11 10:36:11 -04:00
Mark Johnston cf63676e08 dtrace tests: Override RLIMIT_CORE for a test which triggers a core dump
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit e1700a36a9)
2022-08-11 10:36:11 -04:00
Mark Johnston 28ceed5f7a dtrace tests: Rename some test type names to avoid a conflict
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 6a05f14381)
2022-08-11 10:36:11 -04:00
Kornel Dulęba f470bff421 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

(cherry picked from commit 9dbacce2d4)
2022-07-19 11:37:03 +02:00
Mark Johnston 5def1805d1 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>
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 45dd2eaac3)
2022-04-27 20:34:39 -04:00
Mark Johnston 8b01c3026b libctf: Fix recursive descent into anonymous SOU fields
PR:		262412
Tested by:	dhw, gallatin
Fixes:		a6fb869173 ("libctf: Handle CTFv3 containers")
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 6e563a1b60)
2022-04-14 15:02:44 -04:00
Mark Johnston fb89cf93a5 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}")

(cherry picked from commit 3fe1f21fb3)
2022-04-06 20:30:45 -04:00
Mark Johnston d80faf878a ctf: Fix a -Wunused-but-set-variable warning
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit cb6f722562)
2022-04-06 20:30:45 -04:00
Mark Johnston e5b54808f7 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.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit bdf290cd3e)
2022-04-06 20:30:45 -04:00
Mark Johnston a49aa9da78 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.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit a6fb869173)
2022-04-06 20:30:45 -04:00
Mark Johnston 9818e5ebf3 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
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 994297b01b)
2022-04-06 20:30:44 -04:00
Mark Johnston 3681c4f065 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
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 2d5d2a986c)
2022-04-06 20:30:44 -04:00
Li-Wen Hsu 937d08454b
dtrace tests: Fix expected outout for tst.system.d
This is follow up of d500a85e64

PR:		262415
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 16e02ae401)
2022-03-09 11:42:23 +08:00
Mark Johnston 2d30593c24 libctf: Use const ctf_file_t references in string lookup routines
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 45c23c2608)
2022-03-02 08:59:25 -05:00
Mark Johnston 78fb81dec2 libctf: Remove checks for CTFv1
Per commit 7db423d692 ("libctf: Rip out CTFv1 support") this support
is obsolete.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 565518046c)
2022-03-02 08:58:59 -05:00
Mark Johnston afc0a40772 libdtrace: Add a missing newline to an error message
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 1ef441f699)
2022-03-02 08:58:47 -05:00
Mark Johnston 5d526e9361 libctf: Rip out CTFv1 support
CTFv1 was obsolete before libctf was imported into FreeBSD, and
ctfconvert/ctfmerge can emit only CTFv2.  Make ctf.h a bit easier to
maintain by ripping v1 support out.  No functional change intended.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 7db423d692)
2022-02-21 09:57:30 -05:00
Mark Johnston 8687a5f369 libctf: Use ctf_type_t instead of struct ctf_type
For consistency with other CTF toolchain code.  No functional change
intended.

Fixes:	105fd928b0 ("libctf: Improve check for duplicate SOU definitions in ctf_add_type()")

(cherry picked from commit 2e4311906d)
2022-02-21 09:57:22 -05:00
Mark Johnston 1dd57c72a4 ctfconvert: Rip out STABS support
It is unused on FreeBSD and complicates some efforts to modify the CTF
format to permit wider type IDs, so remove it.  No functional change
intended.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 7be9a3b453)
2022-02-21 09:57:14 -05:00
Andriy Gapon cbc3c3f0d7 dt_unring_buf: set dtbd_oldest to the start of the first record
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().

(cherry picked from commit 256c8c5df2)
2022-02-08 18:15:59 +02:00
Mark Johnston ed0748f1a8 ctfconvert: Handle arrays of empty structs
Members with such a type will legitimately have a size of zero, so don't
emit a warning.

PR:		260818
Reviewed by:	bz
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 963f5dc7a3)
2022-01-07 09:03:02 -05:00
Domagoj Stolfa 6c9c924b43 dtrace: Disable getf() as it is broken on FreeBSD
getf() on FreeBSD calls _sx_slock(), _sx_sunlock() and fget_locked().
Furthermore, it does not set the per-core fault flag, meaning it
usually ends up in a double fault panic once getf() does get called,
especially from fbt.

Reviewing the DTrace Toolkit + a number of other scripts scattered
around FreeBSD, I have not been able to find one use of getf(). Given
how broken the implementation currently is, we disable it until it
can be implemented properly.

Also comment out a test in aggs/tst.subr.d for getf().

Reviewed by:	markj

(cherry picked from commit 30ec3138ed)
2021-12-26 19:15:07 -05:00
Mark Johnston feb3289f49 libctf: Improve check for duplicate SOU definitions in ctf_add_type()
When copying a struct or union from one CTF container to another,
ctf_add_type() checks whether it matches an existing type in the
destination container.  It does so by looking for a type with the same
name and kind as the new type, and if one exists, it iterates over all
members of the source type and checks whether a member with matching
name and offset exists in the matched destination type.  This can
produce false positives, for example because member types are not
compared, but this is not expected to arise in practice.  If the match
fails, ctf_add_type() returns an error.

The procedure used for member comparison breaks down in the face of
anonymous struct and union members.  ctf_member_iter() visits each
member in the source definition and looks up the corresponding member in
the desination definition by name using ctf_member_info(), but this
function will descend into anonymous members and thus fail to match.
Fix the problem by introducing a custom comparison routine which does
not assume member names are unique.  This should also be faster for
types with many members; in the previous scheme, membcmp() would perform
a linear scan of the desination type's members to perform a lookup by
name.  The new routine steps through the members of both types in a
single loop.

PR:		258763
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 105fd928b0)
2021-10-18 09:09:02 -04:00
Mark Johnston 7ae8074df1 dtrace.1: Document a couple of preprocessor-related options
Suggested by:	swills
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit a40c4ae866)
2021-09-14 08:50:42 -04:00
Mark Johnston 7ca6b62f8d dtrace.1: Document -x ldpath
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 13d9437a60)
2021-09-14 08:50:21 -04:00
Domagoj Stolfa 1bf7ee1ab5 dtrace: fix an out of bound read and a NULL pointer increment
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
Sponsored by:	Google

(cherry picked from commit a877965fa3)
2021-06-24 09:04:54 -04:00
Mark Johnston ce6fffd965 dtrace tests: Fix tst.system.d after ping/ping6 unification
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit d500a85e64)
2021-04-30 09:21:00 -04:00
Domagoj Stolfa d6b6bd19e8 dtrace: Document the libdir, nolibs and syslibdir options
Differential Revision:	https://reviews.freebsd.org/D29541

(cherry picked from commit 7653f9317b)
2021-04-08 20:28:03 -04:00
Mark Johnston e3b1b9d625 libctf: Adjust logic to match upstream after 410556f1f
No functional change intended.

Suggested by:	jrtc27

(cherry picked from commit 3c065eeaa7)
2021-04-03 11:12:09 -04:00
Domagoj Stolfa cbadf77834 libctf: Fix an out-of-bounds read in ctf_lookup_by_name()
When prefixes such as struct, union, etc. are compared with the current
type (e.g. struct foo), a comparison is made with the prefix.  The code
currently assumes that every type is a valid C type with a prefix,
however at times, garbage ends up in this function causing an
unpredictable crash with DTrace due to the isspace(*p) call or
subsequent calls. An example that I've seen of this is the letter 's'
being passed in, comparing true with struct as the comparison size was
(q - p) == 1, but then we increment p with the length of "struct",
resulting in an out of bounds read.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D29435

(cherry picked from commit 410556f1f1)
2021-04-03 11:11:55 -04:00
Mark Johnston d69677407e libdtrace: Trivial style fixes to force dt_lex.c to be regenerated
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

(cherry picked from commit 150fc89a12)
2021-02-20 11:39:53 -05:00
Mark Johnston af80731179 libdtrace: Stop relying on lex compatibility
It does not appear to be required, and as of commit 6b7e592c21
("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
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 8ba333e02e)
2021-02-19 21:39:51 -05:00
Ryan Libby c14e17a49c dtrace tests: fix prototypes for gcc build
- quiet -Wstrict-prototypes
 - provide prototypes for weak aliases

Reviewed by:	markj
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D28036
2021-01-10 21:53:15 -08:00
Mark Johnston d00431a7bd libdtrace: Format USDT symbols correctly based on symbol binding
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
2021-01-10 17:58:38 -05:00
Andriy Gapon b946eede04 dtrace: honor LC_NUMERIC for %'d and alike, and LC_TIME for %T
Note that the public documentation on dtrace.org fails to mention %T and
incorrectly documents %Y.  The latter actually uses format "%Y %b %e %T"
where %b is always in C locale.

Discussed with:	markj
MFC after:	1 month
Sponsored by:	Panzura
2020-12-03 11:59:40 +00:00
Jonathan T. Looney 96fbe51956 When copying types from one CTF container to another, ensure that we
encode 0-length (i.e. "") structure and union member names as offset 0.
This ensures that we don't confuse other parts of the CTF code which
expect this encoding.

This resolves a Dtrace error resolving members of anonymous structs/unions
within the (struct mbuf) type which some users were seeing after r366908.

While here, update the code in ctf_add_generic() to encode 0-length type
names as offset 0.

Reviewed by:	markj
MFC after:	2 weeks
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D27246
2020-11-20 17:26:02 +00:00
Jonathan T. Looney 3cbb4cc200 When copying types from one CTF container to another, ensure that we
always copy intrinsic data types before copying bitfields which are
based on those types. This ensures the type ordering in the destination
CTF container matches the assumption made elsewhere in the CTF code
that instrinsic data types will always appear before bitfields based on
those types.

This resolves the following error message some users have seen after
r366908:
    "/usr/lib/dtrace/ipfw.d", line 121: failed to copy type of 'ip6p':
    Conflicting type is already defined

Reviewed by:	markj
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D27213
2020-11-17 14:07:27 +00:00
Mark Johnston c6989859ae Address compiler warnings in C code used by the DTrace test suite.
Reported by:	Jenkins
MFC after:	1 week
2020-09-19 16:15:22 +00:00