Bug 31511 - gdbserver doesn't work on x32
Summary: gdbserver doesn't work on x32
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: server (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 15.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-03-19 15:21 UTC by H.J. Lu
Modified: 2024-05-07 16:07 UTC (History)
1 user (show)

See Also:
Host:
Target: x86-64
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2024-03-19 15:21:32 UTC
(gdb) r :12345 ../../x32
Starting program: /export/build/gnu/tools-build/gdb-gitlab/build-x86_64-linux/gdbserver/gdbserver :12345 ../../x32
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[Detaching after fork from child process 45049]
[Detaching after fork from child process 45050]
[Detaching after vfork from child process 45051]
Process ../../x32 created; pid = 45051
Listening on port 12345
Remote debugging from host ::1, port 59214
/export/gnu/import/git/gitlab/x86-gdb/gdbserver/regcache.cc:273: A problem internal to GDBserver has been detected.
Unknown register bnd0raw requested

Program received signal SIGABRT, Aborted.
0x00007ffff7aae804 in __pthread_kill_implementation () from /lib64/libc.so.6
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.38-16.0.fc39.x86_64 libgcc-13.2.1-7.0.fc39.x86_64 libstdc++-13.2.1-7.0.fc39.x86_64
(gdb) bt
#0  0x00007ffff7aae804 in __pthread_kill_implementation ()
   from /lib64/libc.so.6
#1  0x00007ffff7a5c8de in raise () from /lib64/libc.so.6
#2  0x00007ffff7a448bc in abort () from /lib64/libc.so.6
#3  0x00000000004068f7 in abort_or_exit ()
    at /export/gnu/import/git/gitlab/x86-gdb/gdbserver/utils.cc:39
#4  internal_verror (file=<optimized out>, line=<optimized out>, 
    fmt=<optimized out>, args=args@entry=0x7fffffffb4e8)
    at /export/gnu/import/git/gitlab/x86-gdb/gdbserver/utils.cc:86
#5  0x000000000044ec92 in internal_error_loc (
    file=file@entry=0x463b50 "/export/gnu/import/git/gitlab/x86-gdb/gdbserver/regcache.cc", line=line@entry=273, 
    fmt=fmt@entry=0x45c6ec "Unknown register %s requested")
    at /export/gnu/import/git/gitlab/x86-gdb/gdbsupport/errors.cc:58
#6  0x000000000040fa0d in find_regno (name=name@entry=0x45ff71 "bnd0raw", 
    tdesc=<optimized out>)
    at /export/gnu/import/git/gitlab/x86-gdb/gdbserver/regcache.cc:273
#7  0x000000000041027f in find_regno (tdesc=<optimized out>, 
    name=name@entry=0x45ff71 "bnd0raw")
    at /export/gnu/import/git/gitlab/x86-gdb/gdbserver/regcache.cc:274
#8  0x0000000000443dc1 in i387_xsave_to_cache (regcache=0x4b31e0, 
    buf=<optimized out>)
    at /export/gnu/import/git/gitlab/x86-gdb/gdbserver/i387-fp.cc:814
--Type <RET> for more, q to quit, c to continue without paging--
#9  0x000000000042bce2 in regsets_fetch_inferior_registers (
    regsets_info=0x487a60 <x86_regsets_info>, regcache=regcache@entry=0x4b31e0)
    at /export/gnu/import/git/gitlab/x86-gdb/gdbserver/linux-low.cc:5089
#10 0x000000000043347d in linux_process_target::fetch_registers (
    this=0x487ba0 <the_x86_target>, regcache=0x4b31e0, regno=<optimized out>)
    at /export/gnu/import/git/gitlab/x86-gdb/gdbserver/linux-low.cc:5388
#11 0x000000000040fe83 in get_thread_regcache (thread=0x4af860, 
    fetch=fetch@entry=1)
    at /export/gnu/import/git/gitlab/x86-gdb/gdbserver/regcache.cc:60
#12 0x00000000004124f2 in prepare_resume_reply (buf=0x7ffff7e7b013 "", 
    ptid=..., status=...)
    at /export/gnu/import/git/gitlab/x86-gdb/gdbserver/remote-utils.cc:1175
#13 0x000000000041bfcf in handle_status (own_buf=0x7ffff7e7b010 "T05")
    at /export/gnu/import/git/gitlab/x86-gdb/gdbserver/server.cc:3757
#14 process_serial_event ()
    at /export/gnu/import/git/gitlab/x86-gdb/gdbserver/server.cc:4566
#15 handle_serial_event (err=<optimized out>, client_data=<optimized out>)
    at /export/gnu/import/git/gitlab/x86-gdb/gdbserver/server.cc:4891
#16 0x000000000044f596 in gdb_wait_for_event (block=block@entry=1)
    at /export/gnu/import/git/gitlab/x86-gdb/gdbsupport/event-loop.cc:716
#17 0x0000000000450052 in gdb_do_one_event (mstimeout=mstimeout@entry=-1)
    at /export/gnu/import/git/gitlab/x86-gdb/gdbsupport/event-loop.cc:264
#18 0x0000000000418246 in start_event_loop ()

This happens because MPX isn't available for x32.
Comment 2 Sourceware Commits 2024-03-21 19:45:16 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4bb20a6244b7091a9a7a2ae35dfbd7e8db27550a

commit 4bb20a6244b7091a9a7a2ae35dfbd7e8db27550a
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Mar 20 04:13:18 2024 -0700

    gdbserver: Clear X86_XSTATE_MPX bits in xcr0 on x32
    
    Since MPX isn't available for x32, we should clear X86_XSTATE_MPX bits
    on x32.
    
            PR server/31511
            * linux-x86-low.cc (x86_linux_read_description): Clear
            X86_XSTATE_MPX bits in xcr0 on x32.
    Reviewed-by: Felix Willgerodt <felix.willgerodt@intel.com>
Comment 3 Tom Tromey 2024-03-21 20:42:57 UTC
Fixed.
Comment 4 Sourceware Commits 2024-03-25 17:19:03 UTC
The master branch has been updated by Andrew Burgess <aburgess@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=efba976d9713a92b4507ccfef2257e4589da2798

commit efba976d9713a92b4507ccfef2257e4589da2798
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Sat Mar 23 16:17:36 2024 +0000

    gdb/arch: assert that X86_XSTATE_MPX is not set for x32
    
    While trying to merge this commit:
    
      commit 4bb20a6244b7091a9a7a2ae35dfbd7e8db27550a
      Date:   Wed Mar 20 04:13:18 2024 -0700
    
          gdbserver: Clear X86_XSTATE_MPX bits in xcr0 on x32
    
    With this patch series of mine:
    
      https://inbox.sourceware.org/gdb-patches/cover.1706801009.git.aburgess@redhat.com
    
    I worried that there could be other paths that could result in an xcr0
    value that has X86_XSTATE_MPX set in x32 mode.  As everyone eventually
    calls amd64_create_target_description to build their target
    description, I figured we could assert in here that if X86_XSTATE_MPX
    is set then we should not be an x32 target, this should uncover any
    other bugs in this area.
    
    I'm not currently able to build/run any x32 binaries, so I have no way
    to test this.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31511
Comment 5 Sourceware Commits 2024-05-07 16:07:13 UTC
The master branch has been updated by Andrew Burgess <aburgess@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=868883583e7520ff1bd99fcb224d2b33a990edff

commit 868883583e7520ff1bd99fcb224d2b33a990edff
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Sat Mar 23 16:17:36 2024 +0000

    gdb/arch: assert that X86_XSTATE_MPX is not set for x32
    
    While rebasing this series[1] past this commit:
    
      commit 4bb20a6244b7091a9a7a2ae35dfbd7e8db27550a
      Date:   Wed Mar 20 04:13:18 2024 -0700
    
          gdbserver: Clear X86_XSTATE_MPX bits in xcr0 on x32
    
    I worried that there could be other paths that might result in an xcr0
    value which has X86_XSTATE_MPX set in x32 mode.  As everyone
    eventually calls amd64_create_target_description to build their target
    description, I figured we could assert in here that if X86_XSTATE_MPX
    is set then we should not be an x32 target, this will uncover any
    other bugs in this area.
    
    I'm not currently able to build/run any x32 binaries, so I have no way
    to test this, but the author of commit 4bb20a6244b7091 did test this
    series with that assert in place and didn't see any problems.
    
    [1] https://inbox.sourceware.org/gdb-patches/cover.1714143669.git.aburgess@redhat.com
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31511
    
    Approved-By: Felix Willgerodt <felix.willgerodt@intel.com>