Skip to content

Commit

Permalink
Fix ERROR-in-BEGIN probe handling
Browse files Browse the repository at this point in the history
The handling of ERROR probe invocations during the BEGIN probe execution
was flawed.  It failed to continue processing BEGIN clauses once an
ERROR invocation took place, and it didn't provide (as required) for
processing the CPU probe data buffer twice.

The continuation of processing has been corrected by ensuring that the
correct DTrace workstatus is reported from the probe callback functions.
The double buffer processing is now supported by passing a flag to
dt_consume_cpu() to indicate whether the tail of the ring buffer ought
to be updated or not.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
  • Loading branch information
kvanhees committed Sep 1, 2021
1 parent 587dde5 commit a58bb51
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 12 additions & 11 deletions libdtrace/dt_consume.c
Original file line number Diff line number Diff line change
Expand Up @@ -2178,7 +2178,7 @@ dt_consume_one(dtrace_hdl_t *dtp, FILE *fp, char *buf,
int
dt_consume_cpu(dtrace_hdl_t *dtp, FILE *fp, dt_peb_t *peb,
dtrace_consume_probe_f *efunc, dtrace_consume_rec_f *rfunc,
void *arg)
int peek_only, void *arg)
{
struct perf_event_mmap_page *rb_page = (void *)peb->base;
struct perf_event_header *hdr;
Expand Down Expand Up @@ -2209,7 +2209,7 @@ dt_consume_cpu(dtrace_hdl_t *dtp, FILE *fp, dt_peb_t *peb,
*/
base = peb->base + pebset->page_size;

for (;;) {
do {
head = ring_buffer_read_head(rb_page);
tail = rb_page->data_tail;

Expand Down Expand Up @@ -2253,8 +2253,9 @@ dt_consume_cpu(dtrace_hdl_t *dtp, FILE *fp, dt_peb_t *peb,
tail += hdr->size;
} while (tail != head);

ring_buffer_write_tail(rb_page, tail);
}
if (!peek_only)
ring_buffer_write_tail(rb_page, tail);
} while (!peek_only);

return DTRACE_WORKSTATUS_OKAY;
}
Expand All @@ -2278,7 +2279,7 @@ dt_consume_begin_probe(const dtrace_probedata_t *data, void *arg)

if (begin->dtbgn_beginonly) {
if (!(r1 && r2))
return DTRACE_CONSUME_DONE;
return DTRACE_CONSUME_NEXT;
} else {
if (r1 && r2)
return DTRACE_CONSUME_NEXT;
Expand Down Expand Up @@ -2384,7 +2385,7 @@ dt_consume_begin(dtrace_hdl_t *dtp, FILE *fp, struct epoll_event *events,
* and return.
*/
if (!dtp->dt_stopped || cpu != dtp->dt_endedon)
return dt_consume_cpu(dtp, fp, bpeb, pf, rf, arg);
return dt_consume_cpu(dtp, fp, bpeb, pf, rf, 0, arg);

begin.dtbgn_probefunc = pf;
begin.dtbgn_recfunc = rf;
Expand All @@ -2401,7 +2402,7 @@ dt_consume_begin(dtrace_hdl_t *dtp, FILE *fp, struct epoll_event *events,
dtp->dt_errarg = &begin;

rval = dt_consume_cpu(dtp, fp, bpeb, dt_consume_begin_probe,
dt_consume_begin_record, &begin);
dt_consume_begin_record, 1, &begin);

dtp->dt_errhdlr = begin.dtbgn_errhdlr;
dtp->dt_errarg = begin.dtbgn_errarg;
Expand All @@ -2415,7 +2416,7 @@ dt_consume_begin(dtrace_hdl_t *dtp, FILE *fp, struct epoll_event *events,
if (peb == NULL || peb == bpeb)
continue;

rval = dt_consume_cpu(dtp, fp, peb, pf, rf, arg);
rval = dt_consume_cpu(dtp, fp, peb, pf, rf, 0, arg);
if (rval != 0)
return rval;
}
Expand All @@ -2435,7 +2436,7 @@ dt_consume_begin(dtrace_hdl_t *dtp, FILE *fp, struct epoll_event *events,
dtp->dt_errarg = &begin;

rval = dt_consume_cpu(dtp, fp, bpeb, dt_consume_begin_probe,
dt_consume_begin_record, &begin);
dt_consume_begin_record, 0, &begin);

dtp->dt_errhdlr = begin.dtbgn_errhdlr;
dtp->dt_errarg = begin.dtbgn_errarg;
Expand Down Expand Up @@ -2574,7 +2575,7 @@ dtrace_consume(dtrace_hdl_t *dtp, FILE *fp, dtrace_consume_probe_f *pf,
if (dtp->dt_stopped && peb->cpu == dtp->dt_endedon)
continue;

rval = dt_consume_cpu(dtp, fp, peb, pf, rf, arg);
rval = dt_consume_cpu(dtp, fp, peb, pf, rf, 0, arg);
if (rval != 0)
return rval;
}
Expand All @@ -2597,7 +2598,7 @@ dtrace_consume(dtrace_hdl_t *dtp, FILE *fp, dtrace_consume_probe_f *pf,
if (peb->cpu != dtp->dt_endedon)
continue;

return dt_consume_cpu(dtp, fp, peb, pf, rf, arg);
return dt_consume_cpu(dtp, fp, peb, pf, rf, 0, arg);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion test/unittest/error/tst.clause_scope-begin-ended.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
/* @@xfail: dtv2 */

/*
* ASSERTION: A fault that triggers the ERROR probe terminates the execution of
* the current clause, but other clauses for the same probe should
Expand Down

0 comments on commit a58bb51

Please sign in to comment.