diff --git a/libdrgn/dwarf_constants.c b/libdrgn/dwarf_constants.c index 797bfc262..170bb1fa0 100644 --- a/libdrgn/dwarf_constants.c +++ b/libdrgn/dwarf_constants.c @@ -6,16 +6,13 @@ #include "dwarf_constants.h" -#define X(name, value) case name: return #name; +#define X(name, _) if (value == name) return #name; const char *dw_tag_str(int value, char buf[static DW_TAG_STR_BUF_LEN]) { - switch (value) { DW_TAG_DEFINITIONS - default: - snprintf(buf, DW_TAG_STR_BUF_LEN, DW_TAG_STR_UNKNOWN_FORMAT, value); - return buf; - } + snprintf(buf, DW_TAG_STR_BUF_LEN, DW_TAG_STR_UNKNOWN_FORMAT, value); + return buf; } #undef X diff --git a/scripts/gen_dwarf_constants.py b/scripts/gen_dwarf_constants.py index 00d71343d..c63b036fc 100755 --- a/scripts/gen_dwarf_constants.py +++ b/scripts/gen_dwarf_constants.py @@ -202,7 +202,7 @@ def gen_dwarf_constants_c( #include "dwarf_constants.h" -#define X(name, value) case name: return #name; +#define X(name, _) if (value == name) return #name; """ ) for constant_type in dwarf_constants: @@ -211,12 +211,9 @@ def gen_dwarf_constants_c( f""" const char *{constant_type.name.lower()}_str(int value, char buf[static {constant_type.name}_STR_BUF_LEN]) {{ - switch (value) {{ {constant_type.name}_DEFINITIONS - default: - snprintf(buf, {constant_type.name}_STR_BUF_LEN, {constant_type.name}_STR_UNKNOWN_FORMAT, value); - return buf; - }} + snprintf(buf, {constant_type.name}_STR_BUF_LEN, {constant_type.name}_STR_UNKNOWN_FORMAT, value); + return buf; }} """ )