(windows) GDB/MI crash when using "-list-thread-groups --available"
authorJoel Brobecker <brobecker@adacore.com>
Mon, 4 Jun 2018 20:03:32 +0000 (15:03 -0500)
committerJoel Brobecker <brobecker@adacore.com>
Mon, 4 Jun 2018 20:07:33 +0000 (16:07 -0400)
commit178d6a638693d1a7a66b0553f16b1df95b4f27ee
treec95fe3a396adb32c5438b7685c62fadebb8fb44c
parent4b8e28c79356265b2c111e044142fb6d6d2db44e
(windows) GDB/MI crash when using "-list-thread-groups --available"

On Windows, using the "-list-thread-groups --available" GDB/MI command
before an inferior is being debugged:

    % gdb -q -i=mi
    =thread-group-added,id="i1"
    =cmd-param-changed,param="auto-load safe-path",value="/"
    (gdb)
    -list-thread-groups --available
    Segmentation fault

Ooops!

The SEGV happens because the -list-thread-groups --available command
triggers a windows_nat_target::xfer_partial call for a TARGET_OBJECT_OSDATA
object.  Until a program is being debugged, the target_ops layer that
gets the call is the Windows "native" layer. Except for a couple of
specific objects (TARGET_OBJECT_MEMORY and TARGET_OBJECT_LIBRARIES),
this layer's xfer_partial method delegates the xfer of other objects
to the target beneath:

    default:
      return beneath->xfer_partial (object, annex,
                                    readbuf, writebuf, offset, len,
                                    xfered_len);

Unfortunately, there is no "beneath layer" in this case, so
beneath is NULL and dereferencing it leads to the SEGV.

This patch fixes the issue by checking beneath before trying
to delegate the request.

gdb/ChangeLog:

        * windows-nat.c (windows_nat_target::xfer_partial): Return
        TARGET_XFER_E_IO if we need to delegate to the target beneath
        but BENEATH is NULL.

gdb/testsuite/ChangeLog:

        * gdb.mi/list-thread-groups-no-inferior.exp: New testcase.
gdb/ChangeLog
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.mi/list-thread-groups-no-inferior.exp [new file with mode: 0644]
gdb/windows-nat.c
This page took 0.025364 seconds and 4 git commands to generate.