binutils-gdb/gdb/common
Andrew Burgess 8ee22052f6 gdb/x86: Handle kernels using compact xsave format
For GNU/Linux on x86-64, if the target is using the xsave format for
passing the floating-point information from the inferior then there
currently exists a bug relating to the x87 control registers, and the
mxcsr register.

The xsave format allows different floating-point features to be lazily
enabled, a bit in the xsave format tells GDB which floating-point
features have been enabled, and which have not.

Currently in GDB, when reading the floating point state, we check the
xsave bit flags, if the feature is enabled then we read the feature
from the xsave buffer, and if the feature is not enabled, then we
supply the default value from within GDB.

Within GDB, when writing the floating point state, we first fetch the
xsave state from the target and then, for any feature that is not yet
enabled, we write the default values into the xsave buffer.  Next we
compare the regcache value with the value in the xsave buffer, and, if
the value has changed we update the value in the xsave buffer, and
mark the feature enabled in the xsave bit flags.

The problem then, is that the x87 control registers were not following
this pattern.  We assumed that these registers were always written out
by the kernel, and we always wrote them out to the xsave buffer (but
didn't enabled the feature).  The result of this is that if the kernel
had not yet enabled the x87 feature then within GDB we would see
random values for the x87 floating point control registers, and if the
user tried to modify one of these register, that modification would be
lost.

Finally, the mxcsr register was also broken in the same way as the x87
control registers.  The added complexity with this case is that the
mxcsr register is part of both the avx and sse floating point feature
set.  When reading or writing this register we need to check that at
least one of these features is enabled.

This bug was present in native GDB, and within gdbserver.  Both are
fixed with this commit.

gdb/ChangeLog:

	* common/x86-xstate.h (I387_FCTRL_INIT_VAL): New constant.
	(I387_MXCSR_INIT_VAL): New constant.
	* amd64-tdep.c (amd64_supply_xsave): Only read state from xsave
	buffer if it was supplied by the inferior.
	* i387-tdep.c (i387_supply_fsave): Use I387_MXCSR_INIT_VAL.
	(i387_xsave_get_clear_bv): New function.
	(i387_supply_xsave): Only read x87 control registers from the
	xsave buffer if the feature is enabled, and the state will have
	been written, otherwise, provide a suitable default.
	(i387_collect_xsave): Pre-clear all registers in xsave buffer,
	including x87 control registers.  Update control registers if they
	have changed from the default value, and mark features as enabled
	as required.
	* i387-tdep.h (i387_xsave_get_clear_bv): Declare.

gdb/gdbserver/ChangeLog:

	* i387-fp.c (i387_cache_to_xsave): Only write x87 control
	registers to the cache if their values have changed.
	(i387_xsave_to_cache): Provide default values for x87 control
	registers when these features are available, but disabled.
	* regcache.c (supply_register_by_name_zeroed): New function.
	* regcache.h (supply_register_by_name_zeroed): Declare new
	function.

gdb/testsuite/ChangeLog:

	* gdb.arch/amd64-init-x87-values.S: New file.
	* gdb.arch/amd64-init-x87-values.exp: New file.
2018-05-08 18:03:46 +01:00
..
agent.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
agent.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
array-view.h Add selftests for range_contains and insert_into_bit_range_vector 2018-04-09 15:47:12 -04:00
ax.def Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
break-common.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
btrace-common.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
btrace-common.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
buffer.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
buffer.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
byte-vector.h Make target_read_alloc & al return vectors 2018-04-07 13:19:12 -04:00
cleanups.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
cleanups.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
common-debug.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
common-debug.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
common-defs.h Create new common/pathstuff.[ch] 2018-02-28 11:34:39 -05:00
common-exceptions.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
common-exceptions.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
common-gdbthread.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
common-inferior.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
common-regcache.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
common-regcache.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
common-types.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
common-utils.c aarch64: PR 19806: watchpoints: false negatives + PR 20207 contiguous ones 2018-05-04 22:26:46 +02:00
common-utils.h aarch64: PR 19806: watchpoints: false negatives + PR 20207 contiguous ones 2018-05-04 22:26:46 +02:00
common.host Add common/ dir in build directories 2018-02-19 09:37:24 +00:00
common.m4 Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
create-version.sh Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
def-vector.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
default-init-alloc.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
diagnostics.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
enum-flags.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
environ.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
environ.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
errors.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
errors.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
fileio.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
fileio.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
filestuff.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
filestuff.h Remove do_closedir_cleanup 2018-05-04 12:20:37 -06:00
format.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
format.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
function-view.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
gdb_assert.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
gdb_locale.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
gdb_optional.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
gdb_ref_ptr.h Introduce ref_ptr::new_reference 2018-04-30 11:33:11 -06:00
gdb_setjmp.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
gdb_signals.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
gdb_splay_tree.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
gdb_string_view.h Add gdb::string_view 2018-04-09 14:20:46 -04:00
gdb_string_view.tcc Add gdb::string_view 2018-04-09 14:20:46 -04:00
gdb_sys_time.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
gdb_tilde_expand.c Create new common/pathstuff.[ch] 2018-02-28 11:34:39 -05:00
gdb_tilde_expand.h Create new common/pathstuff.[ch] 2018-02-28 11:34:39 -05:00
gdb_unique_ptr.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
gdb_unlinker.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
gdb_vecs.c Remove free_char_ptr_vec 2018-03-02 23:22:10 -05:00
gdb_vecs.h Use an std::vector for inline_states 2018-04-09 15:40:45 -04:00
gdb_wait.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
hash_enum.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
host-defs.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
job-control.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
job-control.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
mingw-strerror.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
new-op.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
observable.h Convert observers to C++ 2018-03-19 09:37:49 -06:00
offset-type.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
pathstuff.c Conditionally include "<windows.h>" on common/pathstuff.c (and unbreak build on mingw*) 2018-03-02 07:32:31 -05:00
pathstuff.h Make gdbserver work with filename-only binaries 2018-02-28 11:37:10 -05:00
poison.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
posix-strerror.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
preprocessor.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
print-utils.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
print-utils.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
ptid.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
ptid.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
queue.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
refcounted-object.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
rsp-low.c Get rid of VEC(static_tracepoint_marker_p) 2018-03-22 00:27:19 -04:00
rsp-low.h Get rid of VEC(static_tracepoint_marker_p) 2018-03-22 00:27:19 -04:00
run-time-clock.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
run-time-clock.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
scoped_fd.h common: add scoped_fd 2018-02-09 14:03:18 +01:00
scoped_mmap.h common: add scoped_mmap 2018-02-09 14:03:19 +01:00
scoped_restore.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
selftest.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
selftest.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
signals-state-save-restore.c gdb/common/signals-state-save-restore.c: Fix typos 2018-01-15 20:03:20 +00:00
signals-state-save-restore.h Fix regression: cannot start with LD_PRELOAD=libSegFault.so (PR gdb/18653#c7) 2018-01-05 18:26:18 +00:00
signals.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
symbol.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
tdesc.c Create xml from target descriptions 2018-04-18 20:44:39 +01:00
tdesc.h Remove xml file references from target descriptions 2018-04-18 20:49:37 +01:00
traits.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
underlying.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
valid-expr.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
vec.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
vec.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
version.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
x86-xstate.h gdb/x86: Handle kernels using compact xsave format 2018-05-08 18:03:46 +01:00
xml-utils.c Add xml_escape_text_append and use it 2018-03-08 18:04:46 -05:00
xml-utils.h Add xml_escape_text_append and use it 2018-03-08 18:04:46 -05:00