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