Skip to content

Commit

Permalink
libdrgn: dwarf_info: expand unknown DWARF expression opcode
Browse files Browse the repository at this point in the history
Include the opcode name if known, and add the bug report link like we do
for unknown relocation types. This might give us some idea of how to
prioritize #321.

Signed-off-by: Omar Sandoval <[email protected]>
  • Loading branch information
osandov committed Sep 28, 2023
1 parent da83513 commit 4a67d34
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
7 changes: 7 additions & 0 deletions libdrgn/dwarf_constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

#define X(name, _) if (value == name) return #name;

const char *dw_op_str(int value, char buf[static DW_OP_STR_BUF_LEN])
{
DW_OP_DEFINITIONS
snprintf(buf, DW_OP_STR_BUF_LEN, DW_OP_STR_UNKNOWN_FORMAT, value);
return buf;
}

const char *dw_tag_str(int value, char buf[static DW_TAG_STR_BUF_LEN])
{
DW_TAG_DEFINITIONS
Expand Down
9 changes: 9 additions & 0 deletions libdrgn/dwarf_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,15 @@ enum { DW_MACRO_DEFINITIONS };
X(DW_OP_PGI_omp_thread_num, 0xf8) \
X(DW_OP_hi_user, 0xff)
enum { DW_OP_DEFINITIONS };
#define DW_OP_STR_UNKNOWN_FORMAT "DW_OP_<0x%x>"
#define DW_OP_STR_BUF_LEN (sizeof(DW_OP_STR_UNKNOWN_FORMAT) - 2 + 2 * sizeof(int))
/**
* Get the name of a `DW_OP` value.
*
* @return Static string if the value is known or @p buf if the value is
* unknown.
*/
const char *dw_op_str(int value, char buf[static DW_OP_STR_BUF_LEN]);

#define DW_ORD_DEFINITIONS \
X(DW_ORD_row_major, 0x0) \
Expand Down
9 changes: 7 additions & 2 deletions libdrgn/dwarf_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -3774,9 +3774,14 @@ drgn_eval_dwarf_expression(struct drgn_dwarf_expression_context *ctx,
* DW_OP_xderef_size, DW_OP_xderef_type.
*/
default:
{
char op_buf[DW_OP_STR_BUF_LEN];
return binary_buffer_error(&ctx->bb,
"unknown DWARF expression opcode %#" PRIx8,
opcode);
"unknown DWARF expression opcode %s; "
"please report this to %s",
dw_op_str(opcode, op_buf),
PACKAGE_BUGREPORT);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/gen_dwarf_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def insert_after(
return result


_DWARF_CONSTANTS_WANT_STR = {"DW_TAG"}
_DWARF_CONSTANTS_WANT_STR = {"DW_OP", "DW_TAG"}


def gen_dwarf_constants_h(
Expand Down

0 comments on commit 4a67d34

Please sign in to comment.