public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/27891] New: maintenance selftest fail when an executable is loaded
@ 2021-05-20 13:21 andrew.burgess at embecosm dot com
  2021-09-13 10:32 ` [Bug gdb/27891] " vries at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: andrew.burgess at embecosm dot com @ 2021-05-20 13:21 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27891

            Bug ID: 27891
           Summary: maintenance selftest fail when an executable is loaded
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: andrew.burgess at embecosm dot com
  Target Milestone: ---

I built GDB with --enable-targets=all, and am running on an x86-64 GNU/Linux
host.  If I start GDB and load an executable (for example GDB itself), and then
run 'maint selftest', I see 1 failure.

In contrast, if I start GDB and don't load an executable, I see 0 failures.

Here's the error(s) that I see:

 Running selftest print_one_insn.
 Self test failed: arch arm: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv2: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv2a: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv3: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv3m: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv4: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv4t: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv5: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv5t: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv5te: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch xscale: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch ep9312: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch iwmmxt: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch iwmmxt2: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv5tej: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv6: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv6kz: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv6t2: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv6k: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv7: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv6-m: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv6s-m: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv7e-m: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv8-a: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv8-r: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv8-m.base: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv8-m.main: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch armv8.1-m.main: self-test failed at
../../src/gdb/disasm-selftests.c:165
 Self test failed: arch arm_any: self-test failed at
../../src/gdb/disasm-selftests.c:165
 warning: A handler for the OS ABI "GNU/Linux" is not built into this
configuration
 of GDB.  Attempting to continue with the default cris:common_v10_v32 settings.

 Self test failed: self-test failed at ../../src/gdb/selftest-arch.c:85

I had a quick look and it appears that the ARM disassembler gets into a state
where it thinks it is disassembling in thumb mode.  When there is no executable
loaded this is not the case.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug gdb/27891] maintenance selftest fail when an executable is loaded
  2021-05-20 13:21 [Bug gdb/27891] New: maintenance selftest fail when an executable is loaded andrew.burgess at embecosm dot com
@ 2021-09-13 10:32 ` vries at gcc dot gnu.org
  2021-09-13 11:23 ` vries at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2021-09-13 10:32 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27891

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alahay01 at gcc dot gnu.org,
                   |                            |luis.machado at linaro dot org,
                   |                            |vries at gcc dot gnu.org

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Andrew Burgess from comment #0)
>  Self test failed: arch armv8.1-m.main: self-test failed at
> ../../src/gdb/disasm-selftests.c:165

The first error I run into is this one, and I've debugged it.

1. With exec.

In gdb_print_insn_arm, we run into this and set info->flags |=
USER_SPECIFIED_MACHINE_TYPE:
...
  /* GDB is able to get bfd_mach from the exe_bfd, info->mach is                
     accurate, so mark USER_SPECIFIED_MACHINE_TYPE bit.  Otherwise,             
     opcodes/arm-dis.c:print_insn reset info->mach, and it will trigger         
     the assert on the mismatch of info->mach and                               
     bfd_get_mach (current_program_space->exec_bfd ()) in                       
     default_print_insn.  */
  if (current_program_space->exec_bfd () != NULL)
    info->flags |= USER_SPECIFIED_MACHINE_TYPE;
...
and consequently we don't do this in print_insn:
...
      if ((info->flags & USER_SPECIFIED_MACHINE_TYPE) == 0)
          info->mach = bfd_mach_arm_unknown;
...
so we end up doing this in select_arm_features:
...
    case bfd_mach_arm_8_1M_MAIN:
      ARM_SET_FEATURES (ARM_ARCH_V8_1M_MAIN);
      arm_feature_set mve_all
        = ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE | ARM_EXT2_MVE_FP);
      ARM_MERGE_FEATURE_SETS (arch_fset, arch_fset, mve_all);
      force_thumb = 1;
      break;
...

With force_thumb set, we disassemble only two bytes, and the selftest fails.

2. Without exec.

- in gdb_print_insn_arm, we don't set
  info->flags |= USER_SPECIFIED_MACHINE_TYPE.
- in print_insn, we do bfd_mach_arm_unknown
- in select_arm_features, we don't set force_thumb

Without force_thumb set, we disassemble four bytes, and the selftest passes.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug gdb/27891] maintenance selftest fail when an executable is loaded
  2021-05-20 13:21 [Bug gdb/27891] New: maintenance selftest fail when an executable is loaded andrew.burgess at embecosm dot com
  2021-09-13 10:32 ` [Bug gdb/27891] " vries at gcc dot gnu.org
@ 2021-09-13 11:23 ` vries at gcc dot gnu.org
  2021-09-13 12:14 ` luis.machado at linaro dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2021-09-13 11:23 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27891

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #1)
>   if (current_program_space->exec_bfd () != NULL)
>     info->flags |= USER_SPECIFIED_MACHINE_TYPE;
> ...

This seems incorrect, given that exec arch can be different from the
disassembly arch.

This fixes that:
...
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index e4e7aec4e1c..ab6999ae209 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -7727,7 +7727,9 @@ gdb_print_insn_arm (bfd_vma memaddr, disassemble_info
*info)
      the assert on the mismatch of info->mach and
      bfd_get_mach (current_program_space->exec_bfd ()) in
      default_print_insn.  */
-  if (current_program_space->exec_bfd () != NULL)
+  if (current_program_space->exec_bfd () != NULL
+      && (current_program_space->exec_bfd ()->arch_info
+         == gdbarch_bfd_arch_info (gdbarch)))
     info->flags |= USER_SPECIFIED_MACHINE_TYPE;

   return default_print_insn (memaddr, info);
...
and consequently the unit test passes for me (not building with --all-targets
though) with and without exec.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug gdb/27891] maintenance selftest fail when an executable is loaded
  2021-05-20 13:21 [Bug gdb/27891] New: maintenance selftest fail when an executable is loaded andrew.burgess at embecosm dot com
  2021-09-13 10:32 ` [Bug gdb/27891] " vries at gcc dot gnu.org
  2021-09-13 11:23 ` vries at gcc dot gnu.org
@ 2021-09-13 12:14 ` luis.machado at linaro dot org
  2021-09-13 19:43 ` vries at gcc dot gnu.org
  2021-09-13 19:45 ` luis.machado at linaro dot org
  4 siblings, 0 replies; 6+ messages in thread
From: luis.machado at linaro dot org @ 2021-09-13 12:14 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27891

--- Comment #3 from Luis Machado <luis.machado at linaro dot org> ---
Looks OK with the usual NULL -> nullptr fixed.

Thanks for the patch.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug gdb/27891] maintenance selftest fail when an executable is loaded
  2021-05-20 13:21 [Bug gdb/27891] New: maintenance selftest fail when an executable is loaded andrew.burgess at embecosm dot com
                   ` (2 preceding siblings ...)
  2021-09-13 12:14 ` luis.machado at linaro dot org
@ 2021-09-13 19:43 ` vries at gcc dot gnu.org
  2021-09-13 19:45 ` luis.machado at linaro dot org
  4 siblings, 0 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2021-09-13 19:43 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27891

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |12.1

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Luis Machado from comment #3)
> Looks OK with the usual NULL -> nullptr fixed.
> 
> Thanks for the patch.

Oops, I forgot to update that before committing.  Oh well...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug gdb/27891] maintenance selftest fail when an executable is loaded
  2021-05-20 13:21 [Bug gdb/27891] New: maintenance selftest fail when an executable is loaded andrew.burgess at embecosm dot com
                   ` (3 preceding siblings ...)
  2021-09-13 19:43 ` vries at gcc dot gnu.org
@ 2021-09-13 19:45 ` luis.machado at linaro dot org
  4 siblings, 0 replies; 6+ messages in thread
From: luis.machado at linaro dot org @ 2021-09-13 19:45 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27891

--- Comment #5 from Luis Machado <luis.machado at linaro dot org> ---
Not a big deal. I'm sure we'll revisit these constants again in the future.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-09-13 19:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-20 13:21 [Bug gdb/27891] New: maintenance selftest fail when an executable is loaded andrew.burgess at embecosm dot com
2021-09-13 10:32 ` [Bug gdb/27891] " vries at gcc dot gnu.org
2021-09-13 11:23 ` vries at gcc dot gnu.org
2021-09-13 12:14 ` luis.machado at linaro dot org
2021-09-13 19:43 ` vries at gcc dot gnu.org
2021-09-13 19:45 ` luis.machado at linaro dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).