From: Simon Marchi Date: Thu, 20 Nov 2025 18:39:45 +0000 (-0500) Subject: gdb/dwarf2: add dwarf2_get_symbol_read_needs selftest X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98e3eb66b734cbe9e0d00be3d191f56a2e97a459;p=thirdparty%2Fbinutils-gdb.git gdb/dwarf2: add dwarf2_get_symbol_read_needs selftest Add a test for the fix introduced by commit cc27559a20f4 ("Fix dwarf2 "assertion failed" on bra without skip dwarf expression op"). Change-Id: I3f18f1c5169a9851e9f87a18c71070486df6da5c Approved-By: Tom Tromey --- diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c index 3afb6b0abf7..73e744c8b97 100644 --- a/gdb/dwarf2/loc.c +++ b/gdb/dwarf2/loc.c @@ -45,6 +45,7 @@ #include #include "gdbsupport/underlying.h" #include "gdbsupport/byte-vector.h" +#include "gdbsupport/selftest.h" #include "extract-store-integer.h" static struct value *dwarf2_evaluate_loc_desc_full @@ -4155,6 +4156,28 @@ const struct symbol_computed_ops dwarf2_loclist_funcs = { loclist_generate_c_location }; +#if GDB_SELF_TEST +namespace selftests { + +static void +test_dwarf2_get_symbol_read_needs () +{ + /* This would cause an internal error. */ + gdb_byte expr[] = { + DW_OP_lit0, + DW_OP_lit1, + DW_OP_bra, 0, 0, + DW_OP_stack_value, + }; + symbol_needs_kind needs + = dwarf2_get_symbol_read_needs (expr, nullptr, nullptr, BFD_ENDIAN_LITTLE, + 4, 4); + SELF_CHECK (needs == SYMBOL_NEEDS_NONE); +} + +} /* namespace selftests */ +#endif /* GDB_SELF_TEST */ + INIT_GDB_FILE (dwarf2loc) { add_setshow_zuinteger_cmd ("entry-values", class_maintenance, @@ -4181,4 +4204,9 @@ conversational style, when possible."), show_dwarf_always_disassemble, &set_dwarf_cmdlist, &show_dwarf_cmdlist); + +#if GDB_SELF_TEST + selftests::register_test ("dwarf2_get_symbol_read_needs", + selftests::test_dwarf2_get_symbol_read_needs); +#endif /* GDB_SELF_TEST */ }