From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id EF47038207D6; Fri, 3 Jun 2022 13:35:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF47038207D6 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb] Fix warning in foreach_arch selftests X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 0e02119e65b566cad575cc57fe423dadab855a56 X-Git-Newrev: 450afa9497ab57588a79f5a3d828b9773643a852 Message-Id: <20220603133500.EF47038207D6@sourceware.org> Date: Fri, 3 Jun 2022 13:35:00 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Jun 2022 13:35:01 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D450afa9497ab= 57588a79f5a3d828b9773643a852 commit 450afa9497ab57588a79f5a3d828b9773643a852 Author: Tom de Vries Date: Fri Jun 3 15:34:50 2022 +0200 [gdb] Fix warning in foreach_arch selftests =20 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. =20 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". =20 Fix the warning by setting osabi to none while doing selftests that ite= rate over all architectures. =20 This causes a regression in the print_one_insn selftests for the ARC architecture. =20 The problem is pre-existing, and can be demonstrated (already without t= his 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 $ ... =20 For ARC, we use the generic case in print_one_insn_test, containing thi= s code: ... int kind =3D gdbarch_breakpoint_kind_from_pc (gdbarch, &pc); ... insn =3D gdbarch_sw_breakpoint_from_kind (gdbarch, kind, &bplen); ... =20 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 =3D gdb_insn_length (gdbarch, *pcptr); ... which needs access to memory, and will consequently fail. =20 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_fr= om_pc which will give us a usable instruction to disassemble. =20 Tested on x86_64-linux. Diff: --- gdb/disasm-selftests.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- gdb/osabi.c | 35 +++++++++++++++++++++++++++++------ gdb/osabi.h | 3 +++ gdb/selftest-arch.c | 1 + 4 files changed, 76 insertions(+), 9 deletions(-) diff --git a/gdb/disasm-selftests.c b/gdb/disasm-selftests.c index 928d26f7018..7daa0138f6f 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 =3D 0; - int kind =3D gdbarch_breakpoint_kind_from_pc (gdbarch, &pc); + int kind; int bplen; =20 - insn =3D gdbarch_sw_breakpoint_from_kind (gdbarch, kind, &bplen); - len =3D bplen; + struct gdbarch_info info; + info.bfd_arch_info =3D gdbarch_bfd_arch_info (gdbarch); + + enum gdb_osabi it; + bool found =3D false; + for (it =3D GDB_OSABI_UNKNOWN; it !=3D GDB_OSABI_INVALID; + it =3D static_cast(static_cast(it) + 1)) + { + if (it =3D=3D GDB_OSABI_UNKNOWN) + continue; + + info.osabi =3D it; + + if (it !=3D GDB_OSABI_NONE) + { + if (!has_gdb_osabi_handler (info)) + /* Unsupported. Skip to prevent warnings like: + A handler for the OS ABI is not built into this + configuration of GDB. Attempting to continue with the + default settings. */ + continue; + } + + gdbarch =3D gdbarch_find_by_info (info); + SELF_CHECK (gdbarch !=3D NULL); + + try + { + kind =3D gdbarch_breakpoint_kind_from_pc (gdbarch, &pc); + insn =3D gdbarch_sw_breakpoint_from_kind (gdbarch, kind, &bplen); + } + catch (...) + { + continue; + } + found =3D true; + break; + } + + /* Assert that we have found an instruction to disassemble. */ + SELF_CHECK (found); =20 + len =3D bplen; break; } } diff --git a/gdb/osabi.c b/gdb/osabi.c index bbd7635532f..f1b7f227b87 100644 --- a/gdb/osabi.c +++ b/gdb/osabi.c @@ -332,9 +332,10 @@ can_run_code_for (const struct bfd_arch_info *a, const= struct bfd_arch_info *b) return (a =3D=3D b || a->compatible (a, b) =3D=3D a); } =20 +/* Return OS ABI handler for INFO. */ =20 -void -gdbarch_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch) +static struct gdb_osabi_handler * +gdbarch_osabi_handler (struct gdbarch_info info) { struct gdb_osabi_handler *handler; =20 @@ -367,10 +368,32 @@ gdbarch_init_osabi (struct gdbarch_info info, struct = gdbarch *gdbarch) ISA"). BFD doesn't normally consider 32-bit and 64-bit "compatible" so it doesn't succeed. */ if (can_run_code_for (info.bfd_arch_info, handler->arch_info)) - { - (*handler->init_osabi) (info, gdbarch); - return; - } + return handler; + } + + return nullptr; +} + +/* See osabi.h. */ + +bool +has_gdb_osabi_handler (struct gdbarch_info info) +{ + return gdbarch_osabi_handler (info) !=3D nullptr; +} + +void +gdbarch_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch) +{ + struct gdb_osabi_handler *handler; + + gdb_assert (info.osabi !=3D GDB_OSABI_UNKNOWN); + handler =3D gdbarch_osabi_handler (info); + + if (handler !=3D nullptr) + { + (*handler->init_osabi) (info, gdbarch); + return; } =20 if (info.osabi =3D=3D GDB_OSABI_NONE) diff --git a/gdb/osabi.h b/gdb/osabi.h index be016732cbc..478a418aac2 100644 --- a/gdb/osabi.h +++ b/gdb/osabi.h @@ -74,6 +74,9 @@ enum gdb_osabi gdbarch_lookup_osabi (bfd *); string. */ enum gdb_osabi osabi_from_tdesc_string (const char *text); =20 +/* Return true if there's an OS ABI handler for INFO. */ +bool has_gdb_osabi_handler (struct gdbarch_info info); + /* Initialize the gdbarch for the specified OS ABI variant. */ void gdbarch_init_osabi (struct gdbarch_info, struct gdbarch *); =20 diff --git a/gdb/selftest-arch.c b/gdb/selftest-arch.c index f434da718d5..1fe0b2d59b4 100644 --- a/gdb/selftest-arch.c +++ b/gdb/selftest-arch.c @@ -68,6 +68,7 @@ foreach_arch_test_generator (const std::string &name, { struct gdbarch_info info; info.bfd_arch_info =3D bfd_scan_arch (arch); + info.osabi =3D GDB_OSABI_NONE; struct gdbarch *gdbarch =3D gdbarch_find_by_info (info); SELF_CHECK (gdbarch !=3D NULL); function (gdbarch);