public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug breakpoints/30385] New: SIGTRAP not attributed to breakpoint when its address has the Thumb bit set
@ 2023-04-24 17:29 hikari at noyu dot me
  2023-04-24 17:38 ` [Bug breakpoints/30385] " hikari at noyu dot me
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: hikari at noyu dot me @ 2023-04-24 17:29 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 30385
           Summary: SIGTRAP not attributed to breakpoint when its address
                    has the Thumb bit set
           Product: gdb
           Version: 13.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: breakpoints
          Assignee: unassigned at sourceware dot org
          Reporter: hikari at noyu dot me
  Target Milestone: ---

On ARMv6 and some other Arm architectures, there is a convention that setting
the lowest bit of an instruction address means it's Thumb code, and if it's
unset, it's Arm code. This is something the branch instructions (BLX, BX, etc)
understand, is expected in the link register and stack frames, etc. However the
instruction address is always aligned to two bytes for Thumb code, so you must
mask off that bit to actually read the instruction etc, and consequently the PC
won't have this “Thumb bit” set.

gdb appears to understand this. In an app with no useful symbols, I may need to
tell GDB whether the function I'm setting a breakpoint in is Arm or Thumb code.
I can do this:

  (gdb) b *0x1e41
  Breakpoint 1 at 0x1e41

I can also do this:

  (gdb) set arm force-mode thumb
  (gdb) b *0x1e40
  Breakpoint 1 at 0x1e40

Both of these seem to cause a Thumb breakpoint to be set (the resulting
instruction is distinct from Arm mode). This doesn't seem to be an accident
considering the disassembly view also seems to interpret the Thumb bit
correctly.

However, it seems to cause problems for attributing the signal caused by a
software breakpoint to its breakpoint. The first example produces:

  (gdb) c
  Continuing.

  Program received signal SIGTRAP, Trace/breakpoint trap.
  0x00001e40 in test_qsort ()

Whereas the second example produces:

  (gdb) c
  Continuing.

  Breakpoint 1, 0x00001e40 in test_qsort ()

The exact same signal (SIGTRAP) and PC is reported to GDB in either case, so I
can only assume this is an issue with GDB? Presumably, the breakpoint is
considered to be at 0x1e41, but the PC is considered to be at 0x1e40, so some
simple equality check fails. It's a bit strange that this would happen though,
considering GDB seems to know 0x1e41 is actually 0x1e40 for some purposes.

----

Reproduction context:

- touchHLE (https://github.com/hikari-no-yume/touchHLE) revision
576292d56e73f4f7bad6310c75438d68e0cdac7f is the target GDB is connected to. It
emulates an ARMv6, Darwin target and implements the GDB Remote Serial Protocol.
If you want to use a build from GitHub CI on that commit, note that it also
needs the touchHLE_dylibs directory from git.
- The app running in touchHLE is "tests/TestApp.app/TestApp" from the same
revision in that repo. It is extremely small and Free Software.

Reproduction steps:

- Run touchHLE: `touchHLE tests/TestApp.app --gdb=localhost:9001`
- Run gdb: `gdb -ex 'target remote localhost:9001' tests/TestApp.app/TestApp`

If it's relevant, I am using Homebrew's build of GDB 13.1 on macOS Monterey.

----

FWIW, I might eventually try to fix this myself.

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

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

* [Bug breakpoints/30385] SIGTRAP not attributed to breakpoint when its address has the Thumb bit set
  2023-04-24 17:29 [Bug breakpoints/30385] New: SIGTRAP not attributed to breakpoint when its address has the Thumb bit set hikari at noyu dot me
@ 2023-04-24 17:38 ` hikari at noyu dot me
  2023-04-24 17:41 ` hikari at noyu dot me
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: hikari at noyu dot me @ 2023-04-24 17:38 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #1 from hikari_no_yume <hikari at noyu dot me> ---
> Both of these seem to cause a Thumb breakpoint to be set (the resulting instruction is distinct from Arm mode).

I can also see that gdb sends a “M1e40,2:f0b5” packet in either case. The
address is unchanged so it must be masking off that Thumb bit. If it's in Arm
mode it sends a completely different packet: “M1e40,4:f0b503af”.

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

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

* [Bug breakpoints/30385] SIGTRAP not attributed to breakpoint when its address has the Thumb bit set
  2023-04-24 17:29 [Bug breakpoints/30385] New: SIGTRAP not attributed to breakpoint when its address has the Thumb bit set hikari at noyu dot me
  2023-04-24 17:38 ` [Bug breakpoints/30385] " hikari at noyu dot me
@ 2023-04-24 17:41 ` hikari at noyu dot me
  2023-04-25 14:34 ` luis.machado at arm dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: hikari at noyu dot me @ 2023-04-24 17:41 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #2 from hikari_no_yume <hikari at noyu dot me> ---
Uh, sorry, those are the packets where it restores the original instructions.
The packets used to set the breakpoint instructions are “M1e40,2:bebe” and
“M1e40,4:fedeffe7”.

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

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

* [Bug breakpoints/30385] SIGTRAP not attributed to breakpoint when its address has the Thumb bit set
  2023-04-24 17:29 [Bug breakpoints/30385] New: SIGTRAP not attributed to breakpoint when its address has the Thumb bit set hikari at noyu dot me
  2023-04-24 17:38 ` [Bug breakpoints/30385] " hikari at noyu dot me
  2023-04-24 17:41 ` hikari at noyu dot me
@ 2023-04-25 14:34 ` luis.machado at arm dot com
  2023-04-25 14:34 ` [Bug tdep/30385] " luis.machado at arm dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: luis.machado at arm dot com @ 2023-04-25 14:34 UTC (permalink / raw)
  To: gdb-prs

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

Luis Machado <luis.machado at arm dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
                 CC|                            |luis.machado at arm dot com
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-04-25

--- Comment #3 from Luis Machado <luis.machado at arm dot com> ---
I'll have to investigate this. It may be an accidental feature aided by the
fact gdb checks the LSB of the address.

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

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

* [Bug tdep/30385] SIGTRAP not attributed to breakpoint when its address has the Thumb bit set
  2023-04-24 17:29 [Bug breakpoints/30385] New: SIGTRAP not attributed to breakpoint when its address has the Thumb bit set hikari at noyu dot me
                   ` (2 preceding siblings ...)
  2023-04-25 14:34 ` luis.machado at arm dot com
@ 2023-04-25 14:34 ` luis.machado at arm dot com
  2023-04-25 14:34 ` luis.machado at arm dot com
  2023-04-25 14:39 ` hikari at noyu dot me
  5 siblings, 0 replies; 7+ messages in thread
From: luis.machado at arm dot com @ 2023-04-25 14:34 UTC (permalink / raw)
  To: gdb-prs

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

Luis Machado <luis.machado at arm dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|breakpoints                 |tdep

--- Comment #4 from Luis Machado <luis.machado at arm dot com> ---
Similarly to the other bug (pr 30386), this would be a tdep issue.

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

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

* [Bug tdep/30385] SIGTRAP not attributed to breakpoint when its address has the Thumb bit set
  2023-04-24 17:29 [Bug breakpoints/30385] New: SIGTRAP not attributed to breakpoint when its address has the Thumb bit set hikari at noyu dot me
                   ` (3 preceding siblings ...)
  2023-04-25 14:34 ` [Bug tdep/30385] " luis.machado at arm dot com
@ 2023-04-25 14:34 ` luis.machado at arm dot com
  2023-04-25 14:39 ` hikari at noyu dot me
  5 siblings, 0 replies; 7+ messages in thread
From: luis.machado at arm dot com @ 2023-04-25 14:34 UTC (permalink / raw)
  To: gdb-prs

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

Luis Machado <luis.machado at arm dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at sourceware dot org   |luis.machado at arm dot com

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

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

* [Bug tdep/30385] SIGTRAP not attributed to breakpoint when its address has the Thumb bit set
  2023-04-24 17:29 [Bug breakpoints/30385] New: SIGTRAP not attributed to breakpoint when its address has the Thumb bit set hikari at noyu dot me
                   ` (4 preceding siblings ...)
  2023-04-25 14:34 ` luis.machado at arm dot com
@ 2023-04-25 14:39 ` hikari at noyu dot me
  5 siblings, 0 replies; 7+ messages in thread
From: hikari at noyu dot me @ 2023-04-25 14:39 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #5 from hikari_no_yume <hikari at noyu dot me> ---
I reproduced this now on the current binutils-gdb master
(7a29ee290307087e1749ce610207e93a15d0b78d).

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

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

end of thread, other threads:[~2023-04-25 14:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-24 17:29 [Bug breakpoints/30385] New: SIGTRAP not attributed to breakpoint when its address has the Thumb bit set hikari at noyu dot me
2023-04-24 17:38 ` [Bug breakpoints/30385] " hikari at noyu dot me
2023-04-24 17:41 ` hikari at noyu dot me
2023-04-25 14:34 ` luis.machado at arm dot com
2023-04-25 14:34 ` [Bug tdep/30385] " luis.machado at arm dot com
2023-04-25 14:34 ` luis.machado at arm dot com
2023-04-25 14:39 ` hikari at noyu dot me

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).