public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/28913] New: GDB does not initialize amd64 linux abi when orig_rax register was not provided in target.xml by gdbstub
@ 2022-02-21  9:43 dominik.b.czarnota+bugzilla at gmail dot com
  0 siblings, 0 replies; only message in thread
From: dominik.b.czarnota+bugzilla at gmail dot com @ 2022-02-21  9:43 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 28913
           Summary: GDB does not initialize amd64 linux abi when orig_rax
                    register was not provided in target.xml by gdbstub
           Product: gdb
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: dominik.b.czarnota+bugzilla at gmail dot com
  Target Milestone: ---

Hello,

I am implementing support for `info proc mappings` into QEMU user-mode
emulation for which I sent a patch in [0]. While this patch makes `info proc
mappings` available when debugging targets exposed via qemu-user, this does not
work on amd64 targets where we simply get:

```
(gdb) info proc mappings
Not supported on this target.
```

This happens because QEMU does not send the "org.gnu.gdb.i386.linux" feature or
the "orig_rax" register in the target.xml XML which it sends to GDB.

However, it seems to me that those should not be required for things like `info
proc mappings` to work as a one-line change in GDB fixes this issue but the
question is if it is an appropriate fix.

The problem boils down to the amd64_linux_init_abi function which is called
when initializing amd64 targets: 

```
static void
amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
{
  // (...)
  feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
  if (feature == NULL)
    return;

  valid_p = tdesc_numbered_register (feature, tdesc_data,
                                     AMD64_LINUX_ORIG_RAX_REGNUM,
                                     "orig_rax");
  if (!valid_p)
    return;

  amd64_linux_init_abi_common (info, gdbarch, 2);
```

Here, if the "org.gnu.gdb.i386.linux" feature or the "orig_rax" register are
missing from the provided target.xml, the GDB returns early from this function
and does not call the amd64_linux_init_abi_common function.

If it called the amd64_linux_init_abi_common function, it would perform the
linux_init_abi initialization [2]:

```
static void
amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch,
                            int num_disp_step_buffers)
{
  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);

  linux_init_abi (info, gdbarch, num_disp_step_buffers);
```

Which would then perform the appropriate initialization of the `info proc
mappings` handler via the call to set_gdbarch_info_proc [3]:

```
void
linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
                int num_disp_step_buffers)
{
  // (...)
  set_gdbarch_info_proc (gdbarch, linux_info_proc);
```

I have tried to change the amd64_linux_init_abi function locally by moving the
amd64_linux_init_abi_common call before the feature/orig_rax check. When I did
it, the `info proc mappings` worked with my QEMU patch ([0]) but as I said
before, the question is such fix is sufficient and does not break anything
else.

I would appreciate if anyone more familiar with this code could look at this
and tell me if such patch would be merged to GDB or if the fix needs to be
applied on the target.xml part of QEMU. Of course I have tried to extend the
target.xml on QEMU side first, but this isn't as simple as adding the feature
and orig_rax register to the XML (it seems that some additional code would need
to be added to QEMU to add support for tracking and sending the orig_rax
register).


[0] https://lists.gnu.org/archive/html/qemu-devel/2022-02/msg04418.html
[1]
https://github.com/bminor/binutils-gdb/blob/dc5483c989f29fc9c7934965071ae1bb80cff902/gdb/amd64-linux-tdep.c#L1863-L1873
[2]
https://github.com/bminor/binutils-gdb/blob/dc5483c989f29fc9c7934965071ae1bb80cff902/gdb/amd64-linux-tdep.c#L1793
[3]
https://github.com/bminor/binutils-gdb/blob/dc5483c989f29fc9c7934965071ae1bb80cff902/gdb/linux-tdep.c#L2654-L2673

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-02-21  9:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-21  9:43 [Bug gdb/28913] New: GDB does not initialize amd64 linux abi when orig_rax register was not provided in target.xml by gdbstub dominik.b.czarnota+bugzilla at gmail dot com

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