aboutsummaryrefslogtreecommitdiff
path: root/gdb/disasm-selftests.c
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2022-06-03 15:34:50 +0200
committerTom de Vries <tdevries@suse.de>2022-06-03 15:34:50 +0200
commit450afa9497ab57588a79f5a3d828b9773643a852 (patch)
tree5fbf64c4e3f792291a7571ba1a01238c42fbdb85 /gdb/disasm-selftests.c
parent0e02119e65b566cad575cc57fe423dadab855a56 (diff)
downloadgdb-450afa9497ab57588a79f5a3d828b9773643a852.zip
gdb-450afa9497ab57588a79f5a3d828b9773643a852.tar.gz
gdb-450afa9497ab57588a79f5a3d828b9773643a852.tar.bz2
[gdb] Fix warning in foreach_arch selftests
When running the selftests, I run into: ... $ gdb -q -batch -ex "maint selftest" ... Running selftest execute_cfa_program::aarch64:ilp32. warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default aarch64:ilp32 settings. ... and likewise for execute_cfa_program::i8086 and execute_cfa_program::ia64-elf32. The warning can easily be reproduced outside the selftests by doing: ... $ gdb -q -batch -ex "set arch aarch64:ilp32" ... and can be prevented by first doing "set osabi none". Fix the warning by setting osabi to none while doing selftests that iterate over all architectures. This causes a regression in the print_one_insn selftests for the ARC architecture. The problem is pre-existing, and can be demonstrated (already without this patch) using: ... $ gdb -q -batch -ex "set osabi none" -ex "maint selftest print_one_insn::A6" Running selftest print_one_insn::A6. Self test failed: Cannot access memory at address 0x0 Ran 1 unit tests, 1 failed $ ... For ARC, we use the generic case in print_one_insn_test, containing this code: ... int kind = gdbarch_breakpoint_kind_from_pc (gdbarch, &pc); ... insn = gdbarch_sw_breakpoint_from_kind (gdbarch, kind, &bplen); ... The problem is that with osabi linux we trigger: ... static int arc_linux_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr) { return trap_size; } ... but with osabi none: ... arc_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr) { size_t length_with_limm = gdb_insn_length (gdbarch, *pcptr); ... which needs access to memory, and will consequently fail. Fix this in print_one_insn_test, in the default case, by iterating over supported osabi's to makes sure we trigger arc_linux_breakpoint_kind_from_pc which will give us a usable instruction to disassemble. Tested on x86_64-linux.
Diffstat (limited to 'gdb/disasm-selftests.c')
-rw-r--r--gdb/disasm-selftests.c46
1 files changed, 43 insertions, 3 deletions
diff --git a/gdb/disasm-selftests.c b/gdb/disasm-selftests.c
index 928d26f..7daa013 100644
--- a/gdb/disasm-selftests.c
+++ b/gdb/disasm-selftests.c
@@ -101,12 +101,52 @@ print_one_insn_test (struct gdbarch *gdbarch)
{
/* Test disassemble breakpoint instruction. */
CORE_ADDR pc = 0;
- int kind = gdbarch_breakpoint_kind_from_pc (gdbarch, &pc);
+ int kind;
int bplen;
- insn = gdbarch_sw_breakpoint_from_kind (gdbarch, kind, &bplen);
- len = bplen;
+ struct gdbarch_info info;
+ info.bfd_arch_info = gdbarch_bfd_arch_info (gdbarch);
+
+ enum gdb_osabi it;
+ bool found = false;
+ for (it = GDB_OSABI_UNKNOWN; it != GDB_OSABI_INVALID;
+ it = static_cast<enum gdb_osabi>(static_cast<int>(it) + 1))
+ {
+ if (it == GDB_OSABI_UNKNOWN)
+ continue;
+
+ info.osabi = it;
+
+ if (it != GDB_OSABI_NONE)
+ {
+ if (!has_gdb_osabi_handler (info))
+ /* Unsupported. Skip to prevent warnings like:
+ A handler for the OS ABI <x> is not built into this
+ configuration of GDB. Attempting to continue with the
+ default <y> settings. */
+ continue;
+ }
+
+ gdbarch = gdbarch_find_by_info (info);
+ SELF_CHECK (gdbarch != NULL);
+
+ try
+ {
+ kind = gdbarch_breakpoint_kind_from_pc (gdbarch, &pc);
+ insn = gdbarch_sw_breakpoint_from_kind (gdbarch, kind, &bplen);
+ }
+ catch (...)
+ {
+ continue;
+ }
+ found = true;
+ break;
+ }
+
+ /* Assert that we have found an instruction to disassemble. */
+ SELF_CHECK (found);
+ len = bplen;
break;
}
}