Bug 256468 - reaching a breakpoint on an armv7 binary on arm64 causes a SIGBUS
Summary: reaching a breakpoint on an armv7 binary on arm64 causes a SIGBUS
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: arm (show other bugs)
Version: 13.0-RELEASE
Hardware: arm64 Any
: --- Affects Only Me
Assignee: freebsd-arm (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-07 13:02 UTC by Robert Clausecker
Modified: 2022-07-13 16:55 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Clausecker freebsd_committer freebsd_triage 2021-06-07 13:02:30 UTC
It appears that debugging armv7 binaries on arm64 is broken.

I've created an armv7 jail on an arm64 FreeBSD 13.0-RELEASE system, entered it, and install gdb from ports.  Then I executed an arbitrary program under gdb, set a breakpoint and let the program run (a simple way to do this is to type "start").  The breakpoint is reached and gdb informs me that a SIGBUS was delivered to the program; attempting to continue after this breakpoint is impossible.

I suppose there's something wrong here as debugging on a native armv7 system seems to work fine.
Comment 1 Mark Johnston freebsd_committer freebsd_triage 2021-06-07 13:25:35 UTC
Any idea if this is a regression with respect to older FreeBSD versions?
Comment 2 Robert Clausecker freebsd_committer freebsd_triage 2021-06-07 13:54:17 UTC
(In reply to Mark Johnston from comment #1)

Older FreeBSD versions do not support execution of armv7 binaries on arm64.

So I suppose it is not.
Comment 3 Robert Clausecker freebsd_committer freebsd_triage 2021-09-21 11:10:36 UTC
I have noticed that with current gdb-10.2_1 installed from ports, this issue only occurs when the break point is set into thumb code.  So to reproduce, write some random C program, e.g.

    #include <stdio.h>

    int main(void)
    {
            puts("hello world");

            return (0);
    }

and compile with

    cc -mthumb -o hello hello.c

then debug with gdb:

    break main
    run

This should trigger the issue.
Comment 4 commit-hook freebsd_committer freebsd_triage 2021-09-21 13:54:00 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=2734050154927eaa63d3b65de5d46d05569b3a5b

commit 2734050154927eaa63d3b65de5d46d05569b3a5b
Author:     Olivier Houchard <cognet@FreeBSD.org>
AuthorDate: 2021-09-21 13:49:45 +0000
Commit:     Olivier Houchard <cognet@FreeBSD.org>
CommitDate: 2021-09-21 13:52:42 +0000

    arm64: Handle 32bits breakpoint exception.

    A different exception is raised when we hit a 32bits breakpoint, rather than
    a 64bits one, so handle those as well when COMPAT_FREEBSD32 is defined.
    This should fix SIGBUS at least when using breakpoints with thumb2 code.

    PR:             256468
    MFC After:      1 week

 sys/arm64/arm64/trap.c     | 3 +++
 sys/arm64/include/armreg.h | 1 +
 2 files changed, 4 insertions(+)
Comment 5 Robert Clausecker freebsd_committer freebsd_triage 2021-09-21 14:28:39 UTC
Hi Oliver,

Thanks for the commit!  Will test the changes once my ports builds for bug #257419 are done (so in a couple of days) and then close the PR if that did the trick.
Comment 6 Robert Clausecker freebsd_committer freebsd_triage 2021-09-23 12:14:28 UTC
That did the trick!

You can close this after the MFC.
Comment 7 commit-hook freebsd_committer freebsd_triage 2022-05-10 09:16:05 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=d055e974c4eeb7237cd18c3fe84a87fbd09ae43b

commit d055e974c4eeb7237cd18c3fe84a87fbd09ae43b
Author:     Olivier Houchard <cognet@FreeBSD.org>
AuthorDate: 2021-09-21 13:49:45 +0000
Commit:     Olivier Houchard <cognet@FreeBSD.org>
CommitDate: 2022-05-10 09:14:40 +0000

    arm64: Handle 32bits breakpoint exception.

    A different exception is raised when we hit a 32bits breakpoint, rather than
    a 64bits one, so handle those as well when COMPAT_FREEBSD32 is defined.
    This should fix SIGBUS at least when using breakpoints with thumb2 code.

    PR:             256468
    MFC After:      1 week

    (cherry picked from commit 2734050154927eaa63d3b65de5d46d05569b3a5b)

 sys/arm64/arm64/trap.c     | 3 +++
 sys/arm64/include/armreg.h | 1 +
 2 files changed, 4 insertions(+)
Comment 8 Robert Clausecker freebsd_committer freebsd_triage 2022-07-13 16:55:54 UTC
Seems like we are done here!