[RFC] Correct gdbserver register packets

Pierre Muller
2002-11-26T17:29:23Z

Currently the cvs sources of gdbserver
for m68k linux have a problem.

The problem comes from the fact that the
register packet is build from the data in regformats
directory. But the m68k cpu file contains two
registers that are apparently not accessible
(or at least not fetched by current gdb).

This causes connection to remote server to
stay stucked affect
that warning.
reading register 29: Input/output error

My patch is a liitle bit more genral because I
read that there are similar problems for other configuration.

The main idea is to add a new function
int
register_present( int regno)

that by default allways returns one but
that can be implmented by the target that do
no supply all the regsiters
that are in the regformats dir.

The final patches can be separated probably, but I would first like to
get comments on the general direction.

ChangeLog entry

2002-11-26 Pierre Muller <muller@ics.u-strasbg.fr>

* config.in: Add HAVE_REGISTER_PRESENT.
* configure.srv: Set srv_register_present for m68k-linux.
* configure.in: Handle srv_register_present.
* configure.in: Handle srv_register_present.
* linux-m68k-low.c (m68k_regmap): Add missing -1.
(m68k_cannot_fetch_register): Handle -1 values.
(m68k_cannot_store_register): Handle -1 values.
(register_present): Implement m68k linux specific version.
* regcache.c (register_present): Implement default version.
(set_register_cache): Use register_present function to
compute correct size for register packet.
* server.h: Include "regdef.h" header.

Index: config.in
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/config.in,v
retrieving revision 1.5
diff -u -p -r1.5 config.in
--- config.in 24 Jul 2002 21:30:46 -0000 1.5
+++ config.in 26 Nov 2002 15:26:46 -0000
@@ -9,6 +9,9 @@
/* Define if the target supports PTRACE_GETREGS for register access. */
#undef HAVE_LINUX_REGSETS

+/* Define if the target implements its own register_present function. */
+#undef HAVE_REGISTER_PRESENT
+
/* Define if the target supports PTRACE_GETFPXREGS for extended
register access. */
#undef HAVE_PTRACE_GETFPXREGS
Index: configure
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/configure,v
retrieving revision 1.10
diff -u -p -r1.10 configure
--- configure 24 Jul 2002 21:30:46 -0000 1.10
+++ configure 26 Nov 2002 15:26:47 -0000
@@ -1155,6 +1155,13 @@ EOF

fi

+if test "${srv_register_present}" = "yes"; then
+ cat >> confdefs.h <<\EOF
+#define HAVE_REGISTER_PRESENT 1
+EOF
+
+fi
+
if test "${srv_linux_regsets}" = "yes"; then
echo $ac_n "checking for PTRACE_GETREGS""... $ac_c" 1>&6
echo "configure:1161: checking for PTRACE_GETREGS" >&5
Index: configure.in
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/configure.in,v
retrieving revision 1.11
diff -u -p -r1.11 configure.in
--- configure.in 24 Jul 2002 21:30:46 -0000 1.11
+++ configure.in 26 Nov 2002 15:26:47 -0000
@@ -39,6 +39,10 @@ if test "${srv_linux_usrregs}" = "yes";
AC_DEFINE(HAVE_LINUX_USRREGS)
fi

+if test "${srv_register_present}" = "yes"; then
+ AC_DEFINE(HAVE_REGISTER_PRESENT)
+fi
+
if test "${srv_linux_regsets}" = "yes"; then
AC_MSG_CHECKING(for PTRACE_GETREGS)
AC_CACHE_VAL(gdbsrv_cv_have_ptrace_getregs,
Index: configure.srv
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/configure.srv,v
retrieving revision 1.5
diff -u -p -r1.5 configure.srv
--- configure.srv 11 Jun 2002 17:32:39 -0000 1.5
+++ configure.srv 26 Nov 2002 15:26:47 -0000
@@ -36,6 +36,7 @@ case "${target}" in
m68*-*-linux*) srv_regobj=reg-m68k.o
srv_tgtobj="linux-low.o linux-m68k-low.o"
srv_linux_usrregs=yes
+ srv_register_present=yes
;;
mips*-*-linux*) srv_regobj=reg-mips.o
srv_tgtobj="linux-low.o linux-mips-low.o"
Index: linux-m68k-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/linux-m68k-low.c,v
retrieving revision 1.3
diff -u -p -r1.3 linux-m68k-low.c
--- linux-m68k-low.c 9 Apr 2002 22:44:43 -0000 1.3
+++ linux-m68k-low.c 26 Nov 2002 15:26:47 -0000
@@ -45,24 +45,36 @@ static int m68k_regmap[] =
#ifdef PT_FP0
PT_FP0 * 4, PT_FP1 * 4, PT_FP2 * 4, PT_FP3 * 4,
PT_FP4 * 4, PT_FP5 * 4, PT_FP6 * 4, PT_FP7 * 4,
- PT_FPCR * 4, PT_FPSR * 4, PT_FPIAR * 4
+ PT_FPCR * 4, PT_FPSR * 4, PT_FPIAR * 4,
#else
21 * 4, 24 * 4, 27 * 4, 30 * 4, 33 * 4, 36 * 4,
- 39 * 4, 42 * 4, 45 * 4, 46 * 4, 47 * 4
+ 39 * 4, 42 * 4, 45 * 4, 46 * 4, 47 * 4,
#endif
+ -1, -1
};

static int
m68k_cannot_store_register (int regno)
{
- return (regno >= m68k_num_regs);
+ return (regno >= m68k_num_regs
+ || m68k_regmap [regno] == -1);
}

static int
m68k_cannot_fetch_register (int regno)
{
- return (regno >= m68k_num_regs);
+ return (regno >= m68k_num_regs
+ || m68k_regmap [regno] == -1);
}
+
+int
+register_present (int regno)
+{
+ return (regno >= 0
+ && regno < m68k_num_regs
+ && m68k_regmap [regno] != -1);
+}
+

struct linux_target_ops the_low_target = {
m68k_num_regs,
Index: regcache.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/regcache.c,v
retrieving revision 1.6
diff -u -p -r1.6 regcache.c
--- regcache.c 13 Jun 2002 19:29:46 -0000 1.6
+++ regcache.c 26 Nov 2002 15:26:47 -0000
@@ -20,11 +20,19 @@
Boston, MA 02111-1307, USA. */

#include "server.h"
-#include "regdef.h"

#include <stdlib.h>
#include <string.h>

+
+#ifndef HAVE_REGISTER_PRESENT
+int
+register_present (int n)
+{
+ return 1;
+}
+#endif /* not HAS_REGISTER_PRESENT */
+
/* The private data for the register cache. Note that we have one
per inferior; this is primarily for simplicity, as the performance
benefit is minimal. */
@@ -130,10 +138,11 @@ set_register_cache (struct reg *regs, in

offset = 0;
for (i = 0; i < n; i++)
- {
- regs[i].offset = offset;
- offset += regs[i].size;
- }
+ if (register_present (i))
+ {
+ regs[i].offset = offset;
+ offset += regs[i].size;
+ }

register_bytes = offset / 8;
}
Index: regcache.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/regcache.h,v
retrieving revision 1.5
diff -u -p -r1.5 regcache.h
--- regcache.h 11 Jun 2002 17:32:39 -0000 1.5
+++ regcache.h 26 Nov 2002 15:26:47 -0000
@@ -45,6 +45,10 @@ void registers_to_string (char *buf);

void registers_from_string (char *buf);

+/* Return 1 if register in packets. */
+
+extern int register_present (int n);
+
/* Return the size in bytes of a string-encoded register packet. */

int registers_length (void);
Index: server.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/server.h,v
retrieving revision 1.12
diff -u -p -r1.12 server.h
--- server.h 11 Jun 2002 17:32:40 -0000 1.12
+++ server.h 26 Nov 2002 15:26:47 -0000
@@ -70,6 +70,7 @@ struct inferior_list_entry
/* Opaque type for user-visible threads. */
struct thread_info;

+#include "regdef.h"
#include "regcache.h"
#include "gdb/signals.h"

Pierre Muller
Institut Charles Sadron
6,rue Boussingault
F 67083 STRASBOURG CEDEX (France)
mailto:muller@ics.u-strasbg.fr
Phone : (33)-3-88-41-40-07 Fax : (33)-3-88-41-40-99