Skip to content

Commit

Permalink
Add support for indexed built-in variables lookup
Browse files Browse the repository at this point in the history
Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
  • Loading branch information
kvanhees committed Jun 7, 2022
1 parent 515b27b commit 8cedded
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion bpf/get_bvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern uint64_t BOOTTM;
-1; \
})

noinline uint64_t dt_get_bvar(const dt_dctx_t *dctx, uint32_t id)
noinline uint64_t dt_get_bvar(const dt_dctx_t *dctx, uint32_t id, uint32_t idx)
{
dt_mstate_t *mst = dctx->mst;

Expand All @@ -54,6 +54,11 @@ noinline uint64_t dt_get_bvar(const dt_dctx_t *dctx, uint32_t id)
case DIF_VAR_ARG6: case DIF_VAR_ARG7: case DIF_VAR_ARG8:
case DIF_VAR_ARG9:
return mst->argv[id - DIF_VAR_ARG0];
case DIF_VAR_ARGS:
if (idx >= sizeof(mst->argv) / sizeof(mst->argv[0]))
return error(dctx, DTRACEFLT_ILLOP, 0);

return mst->argv[idx];
case DIF_VAR_STACKDEPTH:
case DIF_VAR_USTACKDEPTH: {
uint32_t bufsiz = (uint32_t) (uint64_t) (&STKSIZ);
Expand Down
1 change: 1 addition & 0 deletions libdtrace/dt_cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2232,6 +2232,7 @@ dt_cg_load_var(dt_node_t *dst, dt_irlist_t *dlp, dt_regset_t *drp)

emit(dlp, BPF_LOAD(BPF_DW, BPF_REG_1, BPF_REG_FP, DT_STK_DCTX));
emit(dlp, BPF_MOV_IMM(BPF_REG_2, idp->di_id));
emit(dlp, BPF_MOV_IMM(BPF_REG_3, 0));
idp = dt_dlib_get_func(yypcb->pcb_hdl, "dt_get_bvar");
assert(idp != NULL);
dt_regset_xalloc(drp, BPF_REG_0);
Expand Down
9 changes: 5 additions & 4 deletions libdtrace/dt_dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,12 @@ dt_dis_bpf_args(const dtrace_difo_t *dp, const char *fn,
{
if (strcmp(fn, "dt_get_bvar") == 0) {
/*
* We know that the previous instruction exists and moves
* the variable id to a register (because we wrote the code
* generator to emit the instructions in this exact order.)
* We know that the previous two instructions exist and move
* the variable id to a register in the first instruction of
* that sequence (because we wrote the code generator to emit
* the instructions in this exact order.)
*/
in--;
in -= 2;
snprintf(buf, len, "%s",
dt_dis_varname_id(dp, in->imm, DIFV_SCOPE_GLOBAL, addr));
return buf;
Expand Down

0 comments on commit 8cedded

Please sign in to comment.