From 35fd2deb6916e972248d52b1bc1d584fa9059f8f Mon Sep 17 00:00:00 2001 From: Par Olsson Date: Thu, 28 Apr 2016 12:54:07 -0400 Subject: [PATCH] Fix write endianness/size problem for fast tracepoint enabled flag I am sending this fix on behalf of Par Olsson, as a follow-up of this one: https://www.sourceware.org/ml/gdb-patches/2015-10/msg00196.html This problem is exposed when enabling/disabling fast tracepoints on big endian machines. The flag is defined as an int8_t, but is written from gdbserver as an integer (usually 32 bits). When the agent code reads it as an int8_t, it only considers the most significant byte, which is always 0. Also, we were writing 32 bits in an 8 bits field, so the write would overflow, but since the following bytes are padding (the next field is an uint64_t), it luckily didn't cause any issue on little endian systems. The fix was originally tested on ARM big endian systems, but I don't have access to such a system. However, thanks to Marcin's PowerPC fast tracepoint patches and gcc110 (big endian Power7) on the gcc compile farm, I was able to reproduce the problem, test the fix and write a test (the following patch). gdb/gdbserver/ChangeLog: YYYY-MM-DD Par Olsson * tracepoint.c (write_inferior_int8): New function. (cmd_qtenable_disable): Write enable flag using write_inferior_int8. --- gdb/gdbserver/ChangeLog | 7 +++++++ gdb/gdbserver/tracepoint.c | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index c9b1e9d856..a0c90ee0a7 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,10 @@ +2016-04-28 Par Olsson +2016-04-28 Simon Marchi + + * tracepoint.c (write_inferior_int8): New function. + (cmd_qtenable_disable): Write enable flag using + write_inferior_int8. + 2016-04-25 Yao Qi * linux-low.c (lwp_signal_can_be_delivered): Adjust. diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c index 620b94f525..c07e5256d3 100644 --- a/gdb/gdbserver/tracepoint.c +++ b/gdb/gdbserver/tracepoint.c @@ -448,6 +448,12 @@ write_inferior_integer (CORE_ADDR symaddr, int val) return write_inferior_memory (symaddr, (unsigned char *) &val, sizeof (val)); } +static int +write_inferior_int8 (CORE_ADDR symaddr, int8_t val) +{ + return write_inferior_memory (symaddr, (unsigned char *) &val, sizeof (val)); +} + static int write_inferior_uinteger (CORE_ADDR symaddr, unsigned int val) { @@ -2784,7 +2790,7 @@ cmd_qtenable_disable (char *own_buf, int enable) return; } - ret = write_inferior_integer (obj_addr, enable); + ret = write_inferior_int8 (obj_addr, enable); done_accessing_memory (); if (ret)