usdt typed args, translators and arg remapping
v3 cover usdt typed args, translators and arg remapping
This series adds back support for the probe foo (...) : (...) syntax in USDT provider definitions. The dtprobed side is routine, pulling in the DOF and adding it to a new set of dof_parser.h records fed through to the DOF stash and ultimately to dt_pid.c and eventually dt_prov_uprobe.c: the end result is that the DOF for a given probe's remappings ends up in the dt_uprobe_t in more or less the same form as it was in the DOF.
After that things get tricky, because we want to remap not only arg[N] but also argN references (the single existing test for USDT arg remapping verifies that this works), but the SDT machinery depends on argN being unremapped! So we do the remapping in dt_prov_uprobe.c while reshuffling things into dt_argdesc_t's, and tell the higher layers that no arg remapping is ever being performed, then do the remapping in the trampoline by physically reshuffling the arguments. This seems to work without breaking SDT on all supported architectures, and is surprisingly simple (at least, it surprised me: multiple places where I thought I'd need hundreds of lines of complex code turned out to need only three or four lines).
New tests are added to verify that USDT translators work when types change, when arg counts change, and when there are no args at all, and that dtrace -vln produces the right output (all previous tests for USDT -vln, translated or not, are currently disabled because they all use wildcards: this new one doesn't).
We also fix a couple of tiny error-related bugs encountered in the course of development, one in usdt, one related to the print action.
Changes since v2:
Populate dt_argdesc_t's in USDT probe discovery rather than in probe_info.
Changes since v1:
Adapted to review comments (all comments but the stuff around trampolines and arg mapping, which I don't understand well enough to implement); in particular track xlated args and mappings together, and move from a flags word in the dof_parser struct's DIT_PROBE record to an arg count
Nick Alcock (6):
error: add missing EDT_PRINT entry
usdt: get arg types and xlations into DTrace from the DOF
dtprobed: stop skipping zero-tracepoint probes in dof_stash.c
cg: add argument mapping in the trampoline
usdt: typed args and arg mapping
usdt: fix create_underlying error path
dtprobed/dof_stash.c | 21 +-- dtprobed/dtprobed.c | 10 +- include/dtrace/pid.h | 7 + libcommon/dof_parser.c | 150 ++++++++++++---- libcommon/dof_parser.h | 64 ++++++- libdtrace/dt_cg.c | 36 +++- libdtrace/dt_cg.h | 1 + libdtrace/dt_error.c | 3 +- libdtrace/dt_pid.c | 60 +++++++ libdtrace/dt_prov_uprobe.c | 168 +++++++++++++++++- test/triggers/usdt-tst-argmap-prov.d | 5 +- test/triggers/usdt-tst-argmap.c | 5 +- .../dtrace-util/tst.ListProbesArgsUSDT.r | 34 ++++ .../dtrace-util/tst.ListProbesArgsUSDT.r.p | 2 + .../dtrace-util/tst.ListProbesArgsUSDT.sh | 83 +++++++++ test/unittest/usdt/err.argmap-null.d | 40 +++++ test/unittest/usdt/err.argmap-null.r | 2 + test/unittest/usdt/err.argmap-null.r.p | 2 + test/unittest/usdt/tst.argmap-null.d | 32 ++++ test/unittest/usdt/tst.argmap-typed-partial.d | 49 +++++ test/unittest/usdt/tst.argmap-typed.d | 48 +++++ test/unittest/usdt/tst.argmap.d | 3 +- test/utils/showUSDT.c | 5 +- 23 files changed, 759 insertions(+), 71 deletions(-) create mode 100644 test/unittest/dtrace-util/tst.ListProbesArgsUSDT.r create mode 100755 test/unittest/dtrace-util/tst.ListProbesArgsUSDT.r.p create mode 100755 test/unittest/dtrace-util/tst.ListProbesArgsUSDT.sh create mode 100644 test/unittest/usdt/err.argmap-null.d create mode 100644 test/unittest/usdt/err.argmap-null.r create mode 100755 test/unittest/usdt/err.argmap-null.r.p create mode 100644 test/unittest/usdt/tst.argmap-null.d create mode 100644 test/unittest/usdt/tst.argmap-typed-partial.d create mode 100644 test/unittest/usdt/tst.argmap-typed.d
base-commit: 8a1264bf0e818c8624be250eb5174714b62ed93c
Signature · 1 line
2.46.0.278.g36e3a12567
PATCH v3 1/6 error: add missing EDT_PRINT entry
The lack of this made it impossible to print out the last error in the list (which is EDT_PRINT itself).
--- libdtrace/dt_error.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libdtrace/dt_error.c +2 -1
@@ -97,7 +97,8 @@ static const struct { { EDT_OBJIO, "Cannot read object file or modules.dep" }, { EDT_READMAXSTACK, "Cannot read kernel param perf_event_max_stack" }, { EDT_TRACEMEM, "Missing or corrupt tracemem() record" }, - { EDT_PCAP, "Missing or corrupt pcap() record" } + { EDT_PCAP, "Missing or corrupt pcap() record" }, + { EDT_PRINT, "Missing or corrupt print() record" } };static const int _dt_nerr =sizeof (_dt_errlist) /sizeof (_dt_errlist[0 ]);
Signature · 1 line
2.46.0.278.g36e3a12567
PATCH v3 2/6 usdt: get arg types and xlations into DTrace from the DOF
In reply to Nick AlcockThis change propagates native and xlated arg types and remapping info all the way from the DOF, through the parser and dtprobed and the DOF stash, into DTrace, where they end up in the pid_probespec_t for USDT probes. We don't do anything with them once they get there in this commit: no user-visible impacts expected.
We bump the DOF_PARSED_VERSION since we add three new types of record to the dof_parser_t, all optional, covering native and xlated args and arg mapping tables; to make life easier for consumers we emit them in a defined order (documented in dof_parser.h), and add arg counts to the DIT_PROBE record that precedes them indicating which will be present and how many args are in them. This means we retain the property that you can always tell which records within a provider are coming next purely from records you already
have: there's no need to make decisions once the records turn up. The DOF stash hardly changes: all that happens is that the parsed data written to each per-probe file gains some extra types of record (it can have DIT_ARGS_NATIVE, DIT_ARGS_XLAT and DIT_ARGS_MAP entries following the DIT_PROBE record now).
As usual with DOF_PARSED_VERSION bumps, DTraces that cross this change will refuse to read probes added by dtprobeds that are on the other side of it. (Restarting dtprobed will reparse all the probes in the stash to match the new layout, and newly-started DTraces will pick that up -- so this only affects running DTraces picking up new probes, which DTrace cannot do yet:
so no visible effects are expected.)
The code is a bit repetitive, with nargs, xargs and arg mapping all handled separately even though the code is very similar. In future maybe we could unify them (but my attempts led to code that was much harder to read than the original).
--- dtprobed/dof_stash.c | 15 +++-- dtprobed/dtprobed.c | 10 ++- include/dtrace/pid.h | 7 ++ libcommon/dof_parser.c | 150 +++++++++++++++++++++++++++++++---------- libcommon/dof_parser.h | 64 ++++++++++++++++-- libdtrace/dt_pid.c | 59 ++++++++++++++++ test/utils/showUSDT.c | 5 +- 7 files changed, 259 insertions(+), 51 deletions(-)
dtprobed/dof_stash.c +11 -4
@@ -59,8 +59,10 @@* startup if the dof_parsed_t structure changed. The file consists of a * uint64_t version number (DOF_PARSED_VERSION), then a stream of * dof_parsed_t records, the first of type DIT_PROVIDER, the second -* DIT_PROBE, then as many struct dof_parsed_t's of type DIT_TRACEPOINT as -* the DIT_PROBE record specifies. +* DIT_PROBE, then optionally some DIT_*ARGS records (if the count of native +* args in the probe is >0, you get a DIT_NATIVE_ARGS: if the count of xlated +* args is >0, you get DIT_XLAT_ARGS and DIT_MAP_ARGS), then as many struct +* dof_parsed_t's of type DIT_TRACEPOINT as the DIT_PROBE record specifies. * * /run/dtrace/probes/: Per-probe info, written by dtprobed, read by DTrace. *
@@ -640,9 +642,14 @@ dof_stash_write_parsed(pid_t pid, dev_t dev, ino_t ino, dt_list_t *accum)break ; } -/* Tracepoint: add to already-open file. */ +/* Args info or tracepoint: add to already-open file. */ +case DIT_ARGS_NATIVE : +case DIT_ARGS_XLAT : +case DIT_ARGS_MAP :case DIT_TRACEPOINT : -assert (state ==DIT_PROBE || state ==DIT_TRACEPOINT ); +assert (state ==DIT_PROBE || state ==DIT_ARGS_NATIVE || + state ==DIT_ARGS_XLAT || state ==DIT_ARGS_MAP || + state ==DIT_TRACEPOINT ); state = accump->parsed->type;if (write_chunk (parsed_fd, accump->parsed, accump->parsed->size) <0 )
dtprobed/dtprobed.c +7 -3
@@ -795,16 +795,20 @@ process_dof(pid_t pid, int out, int in, dev_t dev, ino_t inum, dev_t exec_dev,if (dof_stash_push_parsed (&accum, probe) <0 ) goto oom; -for (j =0 ; j < probe->probe.ntp; j++) { + j =0 ; +do {dof_parsed_t *tp =dof_read (pid, in); errmsg ="no tracepoints in a probe, or parse state corrupt" ; -if (!tp || tp->type !=DIT_TRACEPOINT ) +if (!tp || tp->type ==DIT_PROVIDER || tp->type ==DIT_PROBE ) goto err;if (dof_stash_push_parsed (&accum, tp) <0 ) goto oom; - } + +if (tp->type ==DIT_TRACEPOINT ) + j++; + }while (j < probe->probe.ntp); }if (!reparsing)
include/dtrace/pid.h +7 -0
@@ -35,6 +35,13 @@ typedef struct pid_probespec {ino_t pps_inum;/* object inode */ char *pps_fn;/* object full filename */ uint64_t pps_off;/* probe offset (in object) */ +int pps_nargc;/* number of native args */ +int pps_xargc;/* number of xlated and remapped args */ +char *pps_nargv;/* array of native args */ +size_t pps_nargvlen;/* (high estimate of) length of array */ +char *pps_xargv;/* array of xlated args */ +size_t pps_xargvlen;/* (high estimate of) length of array */ +int8_t *pps_argmap;/* remapped arg indexes */ /* * Fields below this point do not apply to underlying probes.
libcommon/dof_parser.c +114 -36
189 lines not on this page · raw message
libcommon/dof_parser.h +58 -6
100 lines not on this page · raw message
libdtrace/dt_pid.c +59 -0
77 lines not on this page · raw message
test/utils/showUSDT.c +3 -2
@@ -111,8 +111,9 @@ static void processProbe(int id, dof_probe_t *probe, const char *name,printf (" Probe %d: %s:%s:%s:%s\n" , id, name,"" , strtab + probe->dofpr_func, strtab + probe->dofpr_name); -printf (" argc %d noffs %d nenoffs %d\n" , - probe->dofpr_nargc, probe->dofpr_noffs, probe->dofpr_nenoffs); +printf (" nargc %d xargc %d argidx %d noffs %d nenoffs %d\n" , + probe->dofpr_nargc, probe->dofpr_xargc, probe->dofpr_argidx, + probe->dofpr_noffs, probe->dofpr_nenoffs); offs = &offtab[probe->dofpr_offidx];for (i =0 ; i < probe->dofpr_noffs; i++)
Signature · 1 line
2.46.0.278.g36e3a12567
PATCH v3 3/6 dtprobed: stop skipping zero-tracepoint probes in dof_stash.c
In reply to Nick AlcockWe already validate that they don't exist in dof_parser.c, so no such probes can ever get here. Handling this impossible, untestable case has just got harder, because we'd have to skip DIT_ARGS_{NATIVE,XLAT,MAP} records too. Just stop considering it.
--- dtprobed/dof_stash.c | 6 ------ 1 file changed, 6 deletions(-)
dtprobed/dof_stash.c +0 -6
@@ -586,12 +586,6 @@ dof_stash_write_parsed(pid_t pid, dev_t dev, ino_t ino, dt_list_t *accum)if (err !=0 ) goto err_provider; -/* -* Skip probes with zero tracepoints entirely. -*/ -if (accump->parsed->probe.ntp ==0 ) -break ; - mod = accump->parsed->probe.name;assert (accump->parsed->size > (mod - (char *) accump->parsed)); fun = mod +strlen (mod) +1 ;
Signature · 1 line
2.46.0.278.g36e3a12567
PATCH v3 4/6 cg: add argument mapping in the trampoline
In reply to Nick AlcockBefore now, argument mapping was restricted to the args[] array, and was implemented in dt_cg_array_op in the same place where we decide whether to automatically copyin() userspace strings.
But existing DTrace testcases suggest that arg mapping is also applied to argN for USDT, even though this is inconsistent with SDT and arguably less flexible than having argN be the unmapped arguments in all cases. Add a new function dt_cg_tramp_map_args(), which can be called from trampolines to apply mappings (destructively, but it keeps a copy of the old args in the save area so you can unapply them if you need to). No existing providers do any mapping, so this is not yet called, but it's about to be.
--- libdtrace/dt_cg.c | 36 +++++++++++++++++++++++++++++++++++- libdtrace/dt_cg.h | 1 + 2 files changed, 36 insertions(+), 1 deletion(-)
libdtrace/dt_cg.c +35 -1
@@ -831,6 +831,35 @@ dt_cg_tramp_restore_args(dt_pcb_t *pcb) } } +/* +* Remap arguments according to the array of mappings given. The original +* arguments are overwritten (but saved). In effect, this changes the native +* arguments: the caller should adjust the mappings array accordingly, and +* shuffle the native arg types to match. +* +* The caller must ensure that %r7 contains the value set by the +* dt_cg_tramp_prologue*() functions. +*/ +void +dt_cg_tramp_map_args (dt_pcb_t *pcb,uint8_t *mappings,size_t nmappings) +{ +dt_irlist_t *dlp = &pcb->pcb_ir; +int i; + +/* +* Work from saved args so we don't need to worry about overwriting regs +* we're about to remap. +*/ +dt_cg_tramp_save_args (pcb); + +for (i =0 ; i < nmappings; i++) { +if (mappings[i] != i) { +emit (dlp,BPF_LOAD (BPF_DW ,BPF_REG_0 ,BPF_REG_7 ,DMST_ORIG_ARG (mappings[i]))); +emit (dlp,BPF_STORE (BPF_DW ,BPF_REG_7 ,DMST_ARG (i),BPF_REG_0 )); + } + } +} + typedef struct { dt_irlist_t *dlp; dt_activity_t act;
@@ -5060,7 +5089,12 @@ dt_cg_array_op(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp)* array index according to the static argument mapping (if any), * unless the argument reference is provided by a dynamic translator. * If we're using a dynamic translator for args[], then just set dn_reg -* to an invalid reg and return: DIF_OP_XLARG will fetch the arg later. +* +* If dt_cg_tramp_remap_args is in use, you should apply the remapping +* at the probe_info stage, since the effective "native" arg positions +* will be changed. +* +* If this is a userland variable, note that we need to copy it in. */ if (idp->di_id ==DIF_VAR_ARGS ) { if ((idp->di_kind == DT_IDENT_XLPTR ||
libdtrace/dt_cg.h +1 -0
@@ -34,6 +34,7 @@ extern void dt_cg_tramp_get_var(dt_pcb_t *pcb, const char *name, int isstore,extern void dt_cg_tramp_del_var (dt_pcb_t *pcb,const char *name);extern void dt_cg_tramp_save_args (dt_pcb_t *pcb);extern void dt_cg_tramp_restore_args (dt_pcb_t *pcb); +extern void dt_cg_tramp_map_args (dt_pcb_t *pcb,uint8_t *mappings,size_t nmappings);extern void dt_cg_tramp_call_clauses (dt_pcb_t *pcb,const dt_probe_t *prp,dt_activity_t act);extern void dt_cg_tramp_return (dt_pcb_t *pcb);
Signature · 1 line
2.46.0.278.g36e3a12567
PATCH v3 5/6 usdt: typed args and arg mapping
In reply to Nick AlcockThis change propagates the arg type and mapping info we just got into the pid_probespec_t onward into the underlying dt_uprobe_t, shuffles the native types before handing off a 1:1 mapping to the dt_probe_t, and calls dt_cg_tramp_map_args() to apply the requested mappings. With this, USDT probes should now have visible types which obey the :-notation translators specified in their .d fils (this is now tested).
The probe info has been moved from the underlying probe to the overlying one as part of this: underlying probes don't have any user-visible args to get info for, and their probe_info functions are never called. We do all the arg reshuffling in a function ultimately called from USDT probe discovery via provide_underlying, so it predates trampoline setup let alone probe_info on the overlying probe and all the args info is present before it is needed. (We intentionally do not shuffle the args in dt_cg_tramp_map_args specifically so that we are not sensitive to the relative call order of trampoline() versus probe_info(), but there's no escaping the requirement for USDT probe discovery to predate all of this:
but this was already a requirement in any case.)
We make a couple of assumptions for simplicity, noted by TODOs in the source:
- overlying probes all have the same native types and mappings, so we don't need to look at more than one underlying probe to figure out what they are. DTrace always generates such a thing, but DOF specifying multiple overlapping probes seems perfectly possible for other programs to generate. This should probably be validated in dof_parser.c in future.
- any given underlying probe locus is either a PID or a USDT probe, never both, so we can just map the args at the start of the trampoline and then never touch them again. The both-at the-same-locus case, while in theory possible, is not yet implemented, and significant changes need to be made to create_underlying() to fix this.
--- libdtrace/dt_cg.c | 16 +- libdtrace/dt_cg.h | 2 +- libdtrace/dt_pid.c | 1 + libdtrace/dt_prov_uprobe.c | 166 +++++++++++++++++- test/triggers/usdt-tst-argmap-prov.d | 5 +- test/triggers/usdt-tst-argmap.c | 5 +- .../dtrace-util/tst.ListProbesArgsUSDT.r | 34 ++++ .../dtrace-util/tst.ListProbesArgsUSDT.r.p | 2 + .../dtrace-util/tst.ListProbesArgsUSDT.sh | 83 +++++++++ test/unittest/usdt/err.argmap-null.d | 40 +++++ test/unittest/usdt/err.argmap-null.r | 2 + test/unittest/usdt/err.argmap-null.r.p | 2 + test/unittest/usdt/tst.argmap-null.d | 32 ++++ test/unittest/usdt/tst.argmap-typed-partial.d | 49 ++++++ test/unittest/usdt/tst.argmap-typed.d | 48 +++++ test/unittest/usdt/tst.argmap.d | 3 +- 16 files changed, 470 insertions(+), 20 deletions(-) create mode 100644 test/unittest/dtrace-util/tst.ListProbesArgsUSDT.r create mode 100755 test/unittest/dtrace-util/tst.ListProbesArgsUSDT.r.p create mode 100755 test/unittest/dtrace-util/tst.ListProbesArgsUSDT.sh create mode 100644 test/unittest/usdt/err.argmap-null.d create mode 100644 test/unittest/usdt/err.argmap-null.r create mode 100755 test/unittest/usdt/err.argmap-null.r.p create mode 100644 test/unittest/usdt/tst.argmap-null.d create mode 100644 test/unittest/usdt/tst.argmap-typed-partial.d create mode 100644 test/unittest/usdt/tst.argmap-typed.d
libdtrace/dt_cg.c +8 -8
@@ -832,16 +832,16 @@ dt_cg_tramp_restore_args(dt_pcb_t *pcb) }/* -* Remap arguments according to the array of mappings given. The original -* arguments are overwritten (but saved). In effect, this changes the native -* arguments: the caller should adjust the mappings array accordingly, and -* shuffle the native arg types to match. +* Remap arguments according to the mappings in the array of arguments given. +* The original arguments are overwritten if necessary (but saved). In effect, +* this changes the native arguments: the caller should adjust the mappings +* array accordingly, and shuffle the native arg types to match. * * The caller must ensure that %r7 contains the value set by the * dt_cg_tramp_prologue*() functions. */ void -dt_cg_tramp_map_args (dt_pcb_t *pcb,uint8_t *mappings,size_t nmappings) +dt_cg_tramp_map_args (dt_pcb_t *pcb,dt_argdesc_t *args,size_t nargs) {dt_irlist_t *dlp = &pcb->pcb_ir;int i;
@@ -852,9 +852,9 @@ dt_cg_tramp_map_args(dt_pcb_t *pcb, uint8_t *mappings, size_t nmappings)*/ dt_cg_tramp_save_args (pcb); -for (i =0 ; i < nmappings; i++) { -if (mappings[i] != i) { -emit (dlp,BPF_LOAD (BPF_DW ,BPF_REG_0 ,BPF_REG_7 ,DMST_ORIG_ARG (mappings[i]))); +for (i =0 ; i < nargs; i++) { +if (args[i].mapping != i) { +emit (dlp,BPF_LOAD (BPF_DW ,BPF_REG_0 ,BPF_REG_7 ,DMST_ORIG_ARG (args[i].mapping)));emit (dlp,BPF_STORE (BPF_DW ,BPF_REG_7 ,DMST_ARG (i),BPF_REG_0 )); } }
libdtrace/dt_cg.h +1 -1
@@ -34,7 +34,7 @@ extern void dt_cg_tramp_get_var(dt_pcb_t *pcb, const char *name, int isstore,extern void dt_cg_tramp_del_var (dt_pcb_t *pcb,const char *name);extern void dt_cg_tramp_save_args (dt_pcb_t *pcb);extern void dt_cg_tramp_restore_args (dt_pcb_t *pcb); -extern void dt_cg_tramp_map_args (dt_pcb_t *pcb,uint8_t *mappings,size_t nmappings); +extern void dt_cg_tramp_map_args (dt_pcb_t *pcb,dt_argdesc_t *args,size_t nargs);extern void dt_cg_tramp_call_clauses (dt_pcb_t *pcb,const dt_probe_t *prp,dt_activity_t act);extern void dt_cg_tramp_return (dt_pcb_t *pcb);
libdtrace/dt_pid.c +1 -0
@@ -950,6 +950,7 @@ dt_pid_create_usdt_probes_proc(dtrace_hdl_t *dtp, dt_proc_t *dpr, p += args->size; seen_size += args->size; + args = (dof_parsed_t *) p;if (!validate_dof_record (path, args,DIT_ARGS_MAP , dof_buf_size, seen_size))
libdtrace/dt_prov_uprobe.c +159 -7
238 lines not on this page · raw message
test/triggers/usdt-tst-argmap-prov.d +4 -1
@@ -1,10 +1,13 @@ /* * Oracle Linux DTrace. - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2024, Oracle and/or its affiliates. All rights reserved. * Licensed under the Universal Permissive License v 1.0 as shown at * http://oss.oracle.com/licenses/upl. */ provider test_prov { probe place(int i, int j) : (int j, int i, int i, int j); + probe place2(int i, char *j) : (char *j, int i, int i, char *j); + probe place3(int i, char *j) : (char *j); + probe place4(int i, char *j) : (); };
test/triggers/usdt-tst-argmap.c +4 -1
@@ -1,6 +1,6 @@/* * Oracle Linux DTrace. -* Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved. +* Copyright (c) 2006, 2024, Oracle and/or its affiliates. All rights reserved. * Licensed under the Universal Permissive License v 1.0 as shown at * http://oss.oracle.com/licenses/upl. */
@@ -12,6 +12,9 @@ main(int argc, char **argv) {for (;;) {DTRACE_PROBE2 (test_prov, place,10 ,4 ); +DTRACE_PROBE (test_prov, place2,255 ,"foo" ); +DTRACE_PROBE (test_prov, place3,126 ,"bar" ); +DTRACE_PROBE (test_prov, place4,204 ,"baz" ); }return 0 ;
test/unittest/dtrace-util/tst.ListProbesArgsUSDT.r new file +34 -0
@@ -0,0 +1,34 @@ + ID PROVIDER MODULE FUNCTION NAME + XX test_provXXXX test main go + + Probe Description Attributes + Identifier Names: Private + Data Semantics: Private + Dependency Class: Unknown + + Argument Attributes + Identifier Names: Private + Data Semantics: Private + Dependency Class: Unknown + + Argument Types + args[0]: char * + args[1]: int + + ID PROVIDER MODULE FUNCTION NAME + XX test_provXXXX test main go + + Probe Description Attributes + Identifier Names: Private + Data Semantics: Private + Dependency Class: Unknown + + Argument Attributes + Identifier Names: Private + Data Semantics: Private + Dependency Class: Unknown + + Argument Types + args[0]: char * + args[1]: int +
test/unittest/dtrace-util/tst.ListProbesArgsUSDT.r.p new file +2 -0
@@ -0,0 +1,2 @@ +#!/bin/sed -rf +s,test_prov[0-9]*,test_provXXXX,g; s,^ *[0-9]+, XX,g;
test/unittest/dtrace-util/tst.ListProbesArgsUSDT.sh new file +83 -0
83 lines not on this page · raw message
test/unittest/usdt/err.argmap-null.d new file +40 -0
@@ -0,0 +1,40 @@ +/* + * Oracle Linux DTrace. + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Licensed under the Universal Permissive License v 1.0 as shown at + * http://oss.oracle.com/licenses/upl. + */ + +/* @@trigger: usdt-tst-argmap */ +/* @@trigger-timing: before */ +/* @@runtest-opts: $_pid */ + +/* + * ASSERTION: Verify that a probe with no args at all has no args. + */ + +BEGIN +{ + /* Timeout after 5 seconds */ + timeout = timestamp + 5000000000; +} + +test_prov$1:::place4 +/args[0] != 204 || args[0] == 204/ +{ + printf("this should never happen"); + exit(1); +} + +test_prov$1:::place4 +{ + printf("nor should this"); + exit(1); +} + +profile:::tick-1 +/timestamp > timeout/ +{ + trace("test timed out"); + exit(1); +}
test/unittest/usdt/err.argmap-null.r new file +2 -0
@@ -0,0 +1,2 @@ +-- @@stderr -- +dtrace: failed to compile script test/unittest/usdt/err.argmap-null.d: line 23: index 0 is out of range for test_provXXXX:::place4 args[ ]
test/unittest/usdt/err.argmap-null.r.p new file +2 -0
@@ -0,0 +1,2 @@ +#!/bin/sed -rf +s,test_prov[0-9]*,test_provXXXX,g; s,^ *[0-9]+, XX,g;
test/unittest/usdt/tst.argmap-null.d new file +32 -0
@@ -0,0 +1,32 @@ +/* + * Oracle Linux DTrace. + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Licensed under the Universal Permissive License v 1.0 as shown at + * http://oss.oracle.com/licenses/upl. + */ + +/* @@trigger: usdt-tst-argmap */ +/* @@trigger-timing: before */ +/* @@runtest-opts: $_pid */ + +/* + * ASSERTION: Verify that you can remap to no args at all. + */ + +BEGIN +{ + /* Timeout after 5 seconds */ + timeout = timestamp + 5000000000; +} + +test_prov$1:::place4 +{ + exit(0); +} + +profile:::tick-1 +/timestamp > timeout/ +{ + trace("test timed out"); + exit(1); +}
test/unittest/usdt/tst.argmap-typed-partial.d new file +49 -0
49 lines not on this page · raw message
test/unittest/usdt/tst.argmap-typed.d new file +48 -0
48 lines not on this page · raw message
test/unittest/usdt/tst.argmap.d +1 -2
@@ -1,11 +1,10 @@ /* * Oracle Linux DTrace. - * Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved. * Licensed under the Universal Permissive License v 1.0 as shown at * http://oss.oracle.com/licenses/upl. */ -/* @@xfail: dtv2 */ /* @@trigger: usdt-tst-argmap */ /* @@trigger-timing: before */ /* @@runtest-opts: $_pid */
Signature · 1 line
2.46.0.278.g36e3a12567
PATCH v3 6/6 usdt: fix create_underlying error path
In reply to Nick AlcockOn error, we were destroying the underlying probe using the wrong call, as if it were an overlying probe.
--- libdtrace/dt_prov_uprobe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libdtrace/dt_prov_uprobe.c +1 -1
@@ -316,7 +316,7 @@ static dt_probe_t *create_underlying(dtrace_hdl_t *dtp, fail:dt_dprintf ("Failed to instantiate %s:%s:%s:%s\n" , psp->pps_prv, psp->pps_mod, psp->pps_fn, psp->pps_prb); -probe_destroy (dtp, upp); +probe_destroy_underlying (dtp, upp);return NULL ; }
Signature · 1 line
2.46.0.278.g36e3a12567
Can you please rebase on github's devel? Eugene's USDT work is on there and that impacts patches 5/6 and 6/6.
Also, 1/6 is already on devel.
Please also searc hfor any occurences of /remap/ and fix those to use the more consistent "map" and "mapping" language.
Quoted 86 lines · Nick Alcock
This series adds back support for the probe foo (...) : (...) syntax in USDT provider definitions. The dtprobed side is routine, pulling in the DOF and adding it to a new set of
dof_parser.hrecords fed through to the DOF stash and ultimately todt_pid.cand eventuallydt_prov_uprobe.c: the end result is that the DOF for a given probe's remappings ends up in thedt_uprobe_tin more or less the same form as it was in the DOF.After that things get tricky, because we want to remap not only arg[N] but also argN references (the single existing test for USDT arg remapping verifies that this works), but the SDT machinery depends on argN being unremapped! So we do the remapping in
dt_prov_uprobe.cwhile reshuffling things into dt_argdesc_t's, and tell the higher layers that no arg remapping is ever being performed, then do the remapping in the trampoline by physically reshuffling the arguments. This seems to work without breaking SDT on all supported architectures, and is surprisingly simple (at least, it surprised me: multiple places where I thought I'd need hundreds of lines of complex code turned out to need only three or four lines).New tests are added to verify that USDT translators work when types change, when arg counts change, and when there are no args at all, and that dtrace -vln produces the right output (all previous tests for USDT -vln, translated or not, are currently disabled because they all use wildcards: this new one doesn't).
We also fix a couple of tiny error-related bugs encountered in the course of development, one in usdt, one related to the print action.
Changes since v2:
Populate dt_argdesc_t's in USDT probe discovery rather than inprobe_info.Changes since v1:
Adapted to review comments (all comments but the stuff around trampolines and arg mapping, which I don't understand well enough to implement); in particular track xlated args and mappings together, and move from a flags word in thedof_parserstruct'sDIT_PROBErecord to an arg countNick Alcock (6):
error: add missingEDT_PRINTentry
usdt: get arg types and xlations into DTrace from the DOF
dtprobed: stop skipping zero-tracepoint probes indof_stash.c
cg: add argument mapping in the trampoline
usdt: typed args and arg mapping
usdt: fixcreate_underlyingerror pathdtprobed/dof_stash.c | 21 +-- dtprobed/dtprobed.c | 10 +- include/dtrace/pid.h | 7 + libcommon/dof_parser.c | 150 ++++++++++++---- libcommon/dof_parser.h | 64 ++++++- libdtrace/dt_cg.c | 36 +++- libdtrace/dt_cg.h | 1 + libdtrace/dt_error.c | 3 +- libdtrace/dt_pid.c | 60 +++++++ libdtrace/dt_prov_uprobe.c | 168 +++++++++++++++++- test/triggers/usdt-tst-argmap-prov.d | 5 +- test/triggers/usdt-tst-argmap.c | 5 +- .../dtrace-util/tst.ListProbesArgsUSDT.r | 34 ++++ .../dtrace-util/tst.ListProbesArgsUSDT.r.p | 2 + .../dtrace-util/tst.ListProbesArgsUSDT.sh | 83 +++++++++ test/unittest/usdt/err.argmap-null.d | 40 +++++ test/unittest/usdt/err.argmap-null.r | 2 + test/unittest/usdt/err.argmap-null.r.p | 2 + test/unittest/usdt/tst.argmap-null.d | 32 ++++ test/unittest/usdt/tst.argmap-typed-partial.d | 49 +++++ test/unittest/usdt/tst.argmap-typed.d | 48 +++++ test/unittest/usdt/tst.argmap.d | 3 +- test/utils/showUSDT.c | 5 +- 23 files changed, 759 insertions(+), 71 deletions(-) create mode 100644 test/unittest/dtrace-util/tst.ListProbesArgsUSDT.r create mode 100755 test/unittest/dtrace-util/tst.ListProbesArgsUSDT.r.p create mode 100755 test/unittest/dtrace-util/tst.ListProbesArgsUSDT.sh create mode 100644 test/unittest/usdt/err.argmap-null.d create mode 100644 test/unittest/usdt/err.argmap-null.r create mode 100755 test/unittest/usdt/err.argmap-null.r.p create mode 100644 test/unittest/usdt/tst.argmap-null.d create mode 100644 test/unittest/usdt/tst.argmap-typed-partial.d create mode 100644 test/unittest/usdt/tst.argmap-typed.dbase-commit:
8a1264bf0e818c8624be250eb5174714b62ed93cSignature · 1 line
2.46.0.278.g36e3a12567