Skip to content

Commit

Permalink
Add workstatus error conditions
Browse files Browse the repository at this point in the history
The processing of perf event output buffer data can fail in a few
different ways, all leading to returning DTRACE_WORKSTATUS_ERROR.
In order to better troubleshoot such issues we add two new DTrace
error codes:

- EDT_DSIZE: Data record has an incorrect size
- EDT_BADEPID: Data record contains an invalid EPID

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
  • Loading branch information
kvanhees committed Feb 8, 2021
1 parent 54f9e7e commit 1c789f4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
15 changes: 7 additions & 8 deletions libdtrace/dt_consume.c
Original file line number Diff line number Diff line change
Expand Up @@ -1951,13 +1951,13 @@ dt_consume_one(dtrace_hdl_t *dtp, FILE *fp, char *buf,
* (Note that 'n' may be 0.)
*/
if (ptr > buf + hdr->size)
return DTRACE_WORKSTATUS_ERROR;
return dt_set_errno(dtp, EDT_DSIZE);

size = *(uint32_t *)data;
data += sizeof(size);
ptr += sizeof(size) + size;
if (ptr != buf + hdr->size)
return DTRACE_WORKSTATUS_ERROR;
return dt_set_errno(dtp, EDT_DSIZE);

data += sizeof(uint32_t); /* skip padding */
size -= sizeof(uint32_t);
Expand All @@ -1977,7 +1977,7 @@ dt_consume_one(dtrace_hdl_t *dtp, FILE *fp, char *buf,
rval = dt_epid_lookup(dtp, epid, &pdat->dtpda_ddesc,
&pdat->dtpda_pdesc);
if (rval != 0)
return DTRACE_WORKSTATUS_ERROR;
return dt_set_errno(dtp, EDT_BADEPID);

if (flow)
dt_flowindent(dtp, pdat, *last, DTRACE_EPIDNONE);
Expand Down Expand Up @@ -2020,7 +2020,7 @@ dt_consume_one(dtrace_hdl_t *dtp, FILE *fp, char *buf,
switch (rec->dtrd_arg) {
case DT_ACT_DENORMALIZE:
if (dt_normalize(dtp, data, rec) != 0)
return -1;
return DTRACE_WORKSTATUS_ERROR;

continue;
case DT_ACT_NORMALIZE:
Expand All @@ -2029,7 +2029,7 @@ dt_consume_one(dtrace_hdl_t *dtp, FILE *fp, char *buf,
EDT_BADNORMAL);

if (dt_normalize(dtp, data, rec) != 0)
return -1;
return DTRACE_WORKSTATUS_ERROR;

i++;
continue;
Expand Down Expand Up @@ -2075,7 +2075,7 @@ dt_consume_one(dtrace_hdl_t *dtp, FILE *fp, char *buf,
n = (*func)(dtp, fp, rec->dtrd_format, pdat,
rec, nrecs, data, size);
if (n < 0)
return -1;
return DTRACE_WORKSTATUS_ERROR;
if (n > 0)
i += n - 1;

Expand All @@ -2084,9 +2084,8 @@ dt_consume_one(dtrace_hdl_t *dtp, FILE *fp, char *buf,

n = dt_print_trace(dtp, fp, rec, pdat->dtpda_data,
quiet);

if (n < 0)
return -1;
return DTRACE_WORKSTATUS_ERROR;
}

/*
Expand Down
4 changes: 3 additions & 1 deletion libdtrace/dt_error.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2021, 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.
*/
Expand Down Expand Up @@ -52,6 +52,8 @@ static const struct {
{ EDT_DMISMATCH, "Data record list does not match statement" },
{ EDT_DOFFSET, "Data record offset exceeds buffer boundary" },
{ EDT_DALIGN, "Data record has inappropriate alignment" },
{ EDT_DSIZE, "Data record has incorrect size" },
{ EDT_BADEPID, "Invalid EPID" },
{ EDT_BADOPTNAME, "Invalid option name" },
{ EDT_BADOPTVAL, "Invalid value for specified option" },
{ EDT_BADOPTCTX, "Option cannot be used from within a D program" },
Expand Down
4 changes: 3 additions & 1 deletion libdtrace/dt_impl.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2021, 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.
*/
Expand Down Expand Up @@ -585,6 +585,8 @@ enum {
EDT_DMISMATCH, /* record list does not match statement */
EDT_DOFFSET, /* record data offset error */
EDT_DALIGN, /* record data alignment error */
EDT_DSIZE, /* record data size error */
EDT_BADEPID, /* invalid enabled probe id */
EDT_BADOPTNAME, /* invalid dtrace_setopt option name */
EDT_BADOPTVAL, /* invalid dtrace_setopt option value */
EDT_BADOPTCTX, /* invalid dtrace_setopt option context */
Expand Down

0 comments on commit 1c789f4

Please sign in to comment.