Skip to content

Commit c21dc52

Browse files
Timo Hunzikeranakryiko
authored andcommitted
libbpf: Parse usdt args without offset on x86 (e.g. 8@(%rsp))
Parse USDT arguments like "8@(%rsp)" on x86. These are emmited by SystemTap. The argument syntax is similar to the existing "memory dereference case" but the offset left out as it's zero (i.e. read the value from the address in the register). We treat it the same as the the "memory dereference case", but set the offset to 0. I've tested that this fixes the "unrecognized arg #N spec: 8@(%rsp).." error I've run into when attaching to a probe with such an argument. Attaching and reading the correct argument values works. Something similar might be needed for the other supported architectures. [0] Closes: libbpf/libbpf#559 Signed-off-by: Timo Hunziker <timo.hunziker@gmx.ch> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20221203123746.2160-1-timo.hunziker@eclipso.ch
1 parent aa67961 commit c21dc52

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tools/lib/bpf/usdt.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,14 @@ static int parse_usdt_arg(const char *arg_str, int arg_num, struct usdt_arg_spec
12331233
if (reg_off < 0)
12341234
return reg_off;
12351235
arg->reg_off = reg_off;
1236+
} else if (sscanf(arg_str, " %d @ ( %%%15[^)] ) %n", &arg_sz, reg_name, &len) == 2) {
1237+
/* Memory dereference case without offset, e.g., 8@(%rsp) */
1238+
arg->arg_type = USDT_ARG_REG_DEREF;
1239+
arg->val_off = 0;
1240+
reg_off = calc_pt_regs_off(reg_name);
1241+
if (reg_off < 0)
1242+
return reg_off;
1243+
arg->reg_off = reg_off;
12361244
} else if (sscanf(arg_str, " %d @ %%%15s %n", &arg_sz, reg_name, &len) == 2) {
12371245
/* Register read case, e.g., -4@%eax */
12381246
arg->arg_type = USDT_ARG_REG;

0 commit comments

Comments
 (0)