* [patch/rfc] Revise REGISTER_SIM_REGNO()
@ 2002-05-14 15:48 Andrew Cagney
2002-05-15 3:46 ` Richard Earnshaw
2002-05-19 21:35 ` Andrew Cagney
0 siblings, 2 replies; 9+ messages in thread
From: Andrew Cagney @ 2002-05-14 15:48 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 553 bytes --]
Hello,
The attached, per comments from RichardE, revises the definition and use
of REGISTER_SIM_REGNO. I think I've managed to preserve existing behavour.
Briefly, REGISTER_SIM_REGNO() [Hmm, do I doco `legacy' behavour?]
returns a cardinal indicating the simulators register number, or
SIM_REGNO_UNAVAILABLE/-1 when the register isn't there.
To preserve current behavour on existing targets,
LEGACY_SIM_REGNO_IGNORE is returned by the default
legacy_register_sim_regno() function.
Once I've done with testing I'll commit it (few days),
Andrew
[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 12699 bytes --]
2002-05-14 Andrew Cagney <ac131313@redhat.com>
* d10v-tdep.c: Include "sim-regno.h".
(d10v_ts2_register_sim_regno): Add legacy_regiter_sim_regno check.
(d10v_ts3_register_sim_regno): Ditto.
* Makefile.in (sim_regno_h): Define.
(remote-sim.o): Add $(sim_regno_h) to dependencies.
(gdbarch.o): Ditto.
* sim-regno.h: New file.
* remote-sim.c: Include "sim-regno.h" and "gdb_assert.h".
(legacy_register_sim_regno): New function.
(one2one_register_sim_regno): New function.
(gdbsim_fetch_register): Rewrite.
(gdbsim_store_register): Only store a register when
REGISTER_SIM_REGNO is valid.
* gdbarch.sh: Include "sim-regno.h".
(REGISTER_SIM_REGNO): Set default to legacy_register_sim_regno.
* gdbarch.h, gdbarch.c: Regenerate.
* arch-utils.h (default_register_sim_regno): Delete declaration.
* arch-utils.c (default_register_sim_regno): Delete function.
Index: arch-utils.c
===================================================================
RCS file: /cvs/src/src/gdb/arch-utils.c,v
retrieving revision 1.57
diff -u -r1.57 arch-utils.c
--- arch-utils.c 12 May 2002 03:09:11 -0000 1.57
+++ arch-utils.c 14 May 2002 22:36:20 -0000
@@ -267,13 +267,6 @@
return 0;
}
-int
-default_register_sim_regno (int num)
-{
- return num;
-}
-
-
CORE_ADDR
core_addr_identity (CORE_ADDR addr)
{
Index: arch-utils.h
===================================================================
RCS file: /cvs/src/src/gdb/arch-utils.h,v
retrieving revision 1.32
diff -u -r1.32 arch-utils.h
--- arch-utils.h 12 May 2002 03:09:11 -0000 1.32
+++ arch-utils.h 14 May 2002 22:36:21 -0000
@@ -94,11 +94,6 @@
extern int (*target_architecture_hook) (const struct bfd_arch_info *);
-
-/* Default raw->sim register re-numbering - does nothing. */
-
-extern int default_register_sim_regno (int reg_nr);
-
/* Identity function on a CORE_ADDR. Just returns its parameter. */
extern CORE_ADDR core_addr_identity (CORE_ADDR addr);
Index: d10v-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/d10v-tdep.c,v
retrieving revision 1.39
diff -u -r1.39 d10v-tdep.c
--- d10v-tdep.c 13 May 2002 14:00:35 -0000 1.39
+++ d10v-tdep.c 14 May 2002 22:36:22 -0000
@@ -41,6 +41,7 @@
#include "floatformat.h"
#include "sim-d10v.h"
+#include "sim-regno.h"
struct frame_extra_info
{
@@ -284,6 +285,8 @@
static int
d10v_ts2_register_sim_regno (int nr)
{
+ if (legacy_register_sim_regno (nr) < 0)
+ return legacy_register_sim_regno (nr);
if (nr >= TS2_IMAP0_REGNUM
&& nr < TS2_IMAP0_REGNUM + NR_IMAP_REGS)
return nr - TS2_IMAP0_REGNUM + SIM_D10V_IMAP0_REGNUM;
@@ -298,6 +301,8 @@
static int
d10v_ts3_register_sim_regno (int nr)
{
+ if (legacy_register_sim_regno (nr) < 0)
+ return legacy_register_sim_regno (nr);
if (nr >= TS3_IMAP0_REGNUM
&& nr < TS3_IMAP0_REGNUM + NR_IMAP_REGS)
return nr - TS3_IMAP0_REGNUM + SIM_D10V_IMAP0_REGNUM;
Index: gdbarch.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.c,v
retrieving revision 1.127
diff -u -r1.127 gdbarch.c
--- gdbarch.c 13 May 2002 17:20:57 -0000 1.127
+++ gdbarch.c 14 May 2002 22:36:24 -0000
@@ -39,6 +39,7 @@
#if GDB_MULTI_ARCH
#include "gdbcmd.h"
#include "inferior.h" /* enum CALL_DUMMY_LOCATION et.al. */
+#include "sim-regno.h" /* For legacy_register_sim_regno(). */
#else
/* Just include everything in sight so that the every old definition
of macro is visible. */
@@ -488,7 +489,7 @@
current_gdbarch->max_register_virtual_size = -1;
current_gdbarch->do_registers_info = do_registers_info;
current_gdbarch->print_float_info = default_print_float_info;
- current_gdbarch->register_sim_regno = default_register_sim_regno;
+ current_gdbarch->register_sim_regno = legacy_register_sim_regno;
current_gdbarch->cannot_fetch_register = cannot_register_not;
current_gdbarch->cannot_store_register = cannot_register_not;
current_gdbarch->use_generic_dummy_frames = -1;
Index: gdbarch.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.h,v
retrieving revision 1.95
diff -u -r1.95 gdbarch.h
--- gdbarch.h 13 May 2002 17:20:58 -0000 1.95
+++ gdbarch.h 14 May 2002 22:36:25 -0000
@@ -40,6 +40,7 @@
/* Pull in function declarations refered to, indirectly, via macros. */
#include "value.h" /* For default_coerce_float_to_double which is referenced by a macro. */
#include "inferior.h" /* For unsigned_address_to_pointer(). */
+#include "sim-regno.h" /* For legacy_register_sim_regno(). */
#endif
struct frame_info;
@@ -811,7 +812,7 @@
/* Default (function) for non- multi-arch platforms. */
#if (!GDB_MULTI_ARCH) && !defined (REGISTER_SIM_REGNO)
-#define REGISTER_SIM_REGNO(reg_nr) (default_register_sim_regno (reg_nr))
+#define REGISTER_SIM_REGNO(reg_nr) (legacy_register_sim_regno (reg_nr))
#endif
typedef int (gdbarch_register_sim_regno_ftype) (int reg_nr);
Index: gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.138
diff -u -r1.138 gdbarch.sh
--- gdbarch.sh 13 May 2002 17:20:58 -0000 1.138
+++ gdbarch.sh 14 May 2002 22:36:27 -0000
@@ -471,7 +471,7 @@
f:2:PRINT_FLOAT_INFO:void:print_float_info:void::::default_print_float_info::0
# MAP a GDB RAW register number onto a simulator register number. See
# also include/...-sim.h.
-f:2:REGISTER_SIM_REGNO:int:register_sim_regno:int reg_nr:reg_nr:::default_register_sim_regno::0
+f:2:REGISTER_SIM_REGNO:int:register_sim_regno:int reg_nr:reg_nr:::legacy_register_sim_regno::0
F:2:REGISTER_BYTES_OK:int:register_bytes_ok:long nr_bytes:nr_bytes::0:0
f:2:CANNOT_FETCH_REGISTER:int:cannot_fetch_register:int regnum:regnum:::cannot_register_not::0
f:2:CANNOT_STORE_REGISTER:int:cannot_store_register:int regnum:regnum:::cannot_register_not::0
@@ -759,6 +759,7 @@
/* Pull in function declarations refered to, indirectly, via macros. */
#include "value.h" /* For default_coerce_float_to_double which is referenced by a macro. */
#include "inferior.h" /* For unsigned_address_to_pointer(). */
+#include "sim-regno.h" /* For legacy_register_sim_regno(). */
#endif
struct frame_info;
@@ -1220,6 +1221,7 @@
#if GDB_MULTI_ARCH
#include "gdbcmd.h"
#include "inferior.h" /* enum CALL_DUMMY_LOCATION et.al. */
+#include "sim-regno.h" /* For legacy_register_sim_regno(). */
#else
/* Just include everything in sight so that the every old definition
of macro is visible. */
Index: remote-sim.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-sim.c,v
retrieving revision 1.21
diff -u -r1.21 remote-sim.c
--- remote-sim.c 20 Jan 2002 19:26:48 -0000 1.21
+++ remote-sim.c 14 May 2002 22:36:28 -0000
@@ -40,6 +40,8 @@
#include "remote-utils.h"
#include "command.h"
#include "regcache.h"
+#include "gdb_assert.h"
+#include "sim-regno.h"
/* Prototypes */
@@ -276,46 +278,86 @@
}
}
+int
+legacy_register_sim_regno (int regnum)
+{
+ /* Only makes sense to supply raw registers. */
+ gdb_assert (regnum >= 0 && regnum < NUM_REGS);
+ /* NOTE: cagney/2002-05-13: The old code did it this way and it is
+ suspected that some GDB/SIM combinations may rely on this
+ behavour. The default should be one2one_register_sim_regno
+ (below). */
+ if (REGISTER_NAME (regnum) != NULL
+ && REGISTER_NAME (regnum)[0] != '\0')
+ return regnum;
+ else
+ return LEGACY_SIM_REGNO_IGNORE;
+}
+
+int
+one2one_register_sim_regno (int regnum)
+{
+ /* Only makes sense to supply raw registers. */
+ gdb_assert (regnum >= 0 && regnum < NUM_REGS);
+ if (regnum >= 0 && regnum < NUM_REGS)
+ return regnum;
+ else
+ return SIM_REGNO_UNAVAILABLE;
+}
+
static void
gdbsim_fetch_register (int regno)
{
- static int warn_user = 1;
if (regno == -1)
{
for (regno = 0; regno < NUM_REGS; regno++)
gdbsim_fetch_register (regno);
+ return;
}
- else if (REGISTER_NAME (regno) != NULL
- && *REGISTER_NAME (regno) != '\0')
+
+ switch (REGISTER_SIM_REGNO (regno))
{
- char buf[MAX_REGISTER_RAW_SIZE];
- int nr_bytes;
- if (REGISTER_SIM_REGNO (regno) >= 0)
+ case LEGACY_SIM_REGNO_IGNORE:
+ break;
+ case SIM_REGNO_UNAVAILABLE:
+ {
+ char *buf = alloca (MAX_REGISTER_RAW_SIZE);
+ int nr_bytes;
+ memset (buf, 0, MAX_REGISTER_RAW_SIZE);
+ supply_register (regno, buf);
+ set_register_cached (regno, -1);
+ break;
+ }
+ default:
+ {
+ static int warn_user = 1;
+ char *buf = alloca (MAX_REGISTER_RAW_SIZE);
+ int nr_bytes;
+ gdb_assert (regno >= 0 && regno < NUM_REGS);
+ memset (buf, 0, MAX_REGISTER_RAW_SIZE);
nr_bytes = sim_fetch_register (gdbsim_desc,
REGISTER_SIM_REGNO (regno),
buf, REGISTER_RAW_SIZE (regno));
- else
- nr_bytes = 0;
- if (nr_bytes == 0)
- /* register not applicable, supply zero's */
- memset (buf, 0, MAX_REGISTER_RAW_SIZE);
- else if (nr_bytes > 0 && nr_bytes != REGISTER_RAW_SIZE (regno)
- && warn_user)
- {
- fprintf_unfiltered (gdb_stderr,
- "Size of register %s (%d/%d) incorrect (%d instead of %d))",
- REGISTER_NAME (regno),
- regno, REGISTER_SIM_REGNO (regno),
- nr_bytes, REGISTER_RAW_SIZE (regno));
- warn_user = 0;
- }
- supply_register (regno, buf);
- if (sr_get_debug ())
- {
- printf_filtered ("gdbsim_fetch_register: %d", regno);
- /* FIXME: We could print something more intelligible. */
- dump_mem (buf, REGISTER_RAW_SIZE (regno));
- }
+ if (nr_bytes > 0 && nr_bytes != REGISTER_RAW_SIZE (regno) && warn_user)
+ {
+ fprintf_unfiltered (gdb_stderr,
+ "Size of register %s (%d/%d) incorrect (%d instead of %d))",
+ REGISTER_NAME (regno),
+ regno, REGISTER_SIM_REGNO (regno),
+ nr_bytes, REGISTER_RAW_SIZE (regno));
+ warn_user = 0;
+ }
+ /* Else if (nr_bytes < 0): an old simulator, that doesn't
+ think to return the register size. Just assume all is ok. */
+ supply_register (regno, buf);
+ if (sr_get_debug ())
+ {
+ printf_filtered ("gdbsim_fetch_register: %d", regno);
+ /* FIXME: We could print something more intelligible. */
+ dump_mem (buf, REGISTER_RAW_SIZE (regno));
+ }
+ break;
+ }
}
}
@@ -327,10 +369,9 @@
{
for (regno = 0; regno < NUM_REGS; regno++)
gdbsim_store_register (regno);
+ return;
}
- else if (REGISTER_NAME (regno) != NULL
- && *REGISTER_NAME (regno) != '\0'
- && REGISTER_SIM_REGNO (regno) >= 0)
+ else if (REGISTER_SIM_REGNO (regno) >= 0)
{
char tmp[MAX_REGISTER_RAW_SIZE];
int nr_bytes;
Index: sim-regno.h
===================================================================
RCS file: sim-regno.h
diff -N sim-regno.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ sim-regno.h 14 May 2002 22:36:28 -0000
@@ -0,0 +1,50 @@
+/* Generic remote debugging interface for simulators.
+
+ Copyright 2002 Free Software Foundation, Inc.
+
+ Contributed by Red Hat, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef SIM_REGNO_H
+#define SIM_REGNO_H
+
+/* The REGISTER_SIM_REGNO(REGNUM) method, when there is a
+ corresponding simulator register, returns that register number as a
+ cardinal. When there is no corresponding register, it returns a
+ negative value. */
+
+enum {
+ /* Normal sane architecture. The corresponding register cache
+ entry is zero filled and the register is marked as unavailable. */
+ SIM_REGNO_UNAVAILABLE = -1,
+ /* For possible backward compatibility. The register cache doesn't
+ have a corresponding name. Skip the register entirely. */
+ LEGACY_SIM_REGNO_IGNORE = -2
+};
+
+/* For compatibility with older architectures, returns
+ (LEGACY_SIM_REGNO_IGNORE) when a register doesn't have. */
+
+extern int legacy_register_sim_regno (int regnum);
+
+/* Treat all raw registers as valid. */
+
+extern int one2one_register_sim_regno (int regnum);
+
+#endif
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch/rfc] Revise REGISTER_SIM_REGNO()
2002-05-14 15:48 [patch/rfc] Revise REGISTER_SIM_REGNO() Andrew Cagney
@ 2002-05-15 3:46 ` Richard Earnshaw
2002-05-16 16:35 ` Michael Snyder
2002-05-19 21:35 ` Andrew Cagney
1 sibling, 1 reply; 9+ messages in thread
From: Richard Earnshaw @ 2002-05-15 3:46 UTC (permalink / raw)
To: Andrew Cagney; +Cc: gdb-patches, Richard.Earnshaw
> Hello,
>
> The attached, per comments from RichardE, revises the definition and use
> of REGISTER_SIM_REGNO. I think I've managed to preserve existing behavour.
>
> Briefly, REGISTER_SIM_REGNO() [Hmm, do I doco `legacy' behavour?]
> returns a cardinal indicating the simulators register number, or
> SIM_REGNO_UNAVAILABLE/-1 when the register isn't there.
>
> To preserve current behavour on existing targets,
> LEGACY_SIM_REGNO_IGNORE is returned by the default
> legacy_register_sim_regno() function.
I'd like to see a target have a way to report that it is permanently
unable to recover a register -- because there's nothing in the protocol to
allow its recovery.
For example, I've added the privileged mode registers to my ARM target
code; when the target is using a ptrace() interface for debugging a user
program, then these registers are never available and it's pointless
having gdb report them.
Note -- again this is not an ABI issue, the same ABI can be in use when
debugging kernel code; it's clearly a property of the target interface.
Now to the point of why I'm saying this in response to this patch :-)
LEGACY_SIM_REGNO_IGNORE seems to be saying almost exactly the same thing.
So why "legacy"?
R.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch/rfc] Revise REGISTER_SIM_REGNO()
2002-05-15 3:46 ` Richard Earnshaw
@ 2002-05-16 16:35 ` Michael Snyder
2002-05-17 2:07 ` Richard Earnshaw
0 siblings, 1 reply; 9+ messages in thread
From: Michael Snyder @ 2002-05-16 16:35 UTC (permalink / raw)
To: Richard.Earnshaw; +Cc: Andrew Cagney, gdb-patches
Richard Earnshaw wrote:
>
> > Hello,
> >
> > The attached, per comments from RichardE, revises the definition and use
> > of REGISTER_SIM_REGNO. I think I've managed to preserve existing behavour.
> >
> > Briefly, REGISTER_SIM_REGNO() [Hmm, do I doco `legacy' behavour?]
> > returns a cardinal indicating the simulators register number, or
> > SIM_REGNO_UNAVAILABLE/-1 when the register isn't there.
> >
> > To preserve current behavour on existing targets,
> > LEGACY_SIM_REGNO_IGNORE is returned by the default
> > legacy_register_sim_regno() function.
>
> I'd like to see a target have a way to report that it is permanently
> unable to recover a register -- because there's nothing in the protocol to
> allow its recovery.
>
> For example, I've added the privileged mode registers to my ARM target
> code; when the target is using a ptrace() interface for debugging a user
> program, then these registers are never available and it's pointless
> having gdb report them.
How about having target_fetch_register set them to -1 in the cache?
See remote.c:remote_fetch_registers:
set_register_cached (i, -1);
This tells the rest of GDB that the value of the register is
"not available". You could unconditionally mark certain regs
as unavailable whenever target_fetch_registers is called.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch/rfc] Revise REGISTER_SIM_REGNO()
2002-05-16 16:35 ` Michael Snyder
@ 2002-05-17 2:07 ` Richard Earnshaw
2002-05-17 10:49 ` Michael Snyder
0 siblings, 1 reply; 9+ messages in thread
From: Richard Earnshaw @ 2002-05-17 2:07 UTC (permalink / raw)
To: Michael Snyder; +Cc: Richard.Earnshaw, Andrew Cagney, gdb-patches
> > I'd like to see a target have a way to report that it is permanently
> > unable to recover a register -- because there's nothing in the protocol to
> > allow its recovery.
> >
> > For example, I've added the privileged mode registers to my ARM target
> > code; when the target is using a ptrace() interface for debugging a user
> > program, then these registers are never available and it's pointless
> > having gdb report them.
>
> How about having target_fetch_register set them to -1 in the cache?
> See remote.c:remote_fetch_registers:
>
> set_register_cached (i, -1);
>
> This tells the rest of GDB that the value of the register is
> "not available". You could unconditionally mark certain regs
> as unavailable whenever target_fetch_registers is called.
Already tried that idea. It doesn't work.
set_register_cached (-1) means that the register is "temporarily
unavailable" at this time (due to the way we gathered the registers).
Each time registers_changed() is called the value is reset to zero.
I need a way the target vector to let REGISTER_NAME() know that the
register is "unavailable this session", so that it can return an empty
string for the register; so that gdb won't think it exists at all.
R.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch/rfc] Revise REGISTER_SIM_REGNO()
2002-05-17 2:07 ` Richard Earnshaw
@ 2002-05-17 10:49 ` Michael Snyder
2002-05-18 3:55 ` Richard Earnshaw
0 siblings, 1 reply; 9+ messages in thread
From: Michael Snyder @ 2002-05-17 10:49 UTC (permalink / raw)
To: Richard.Earnshaw; +Cc: Andrew Cagney, gdb-patches
Richard Earnshaw wrote:
>
> > > I'd like to see a target have a way to report that it is permanently
> > > unable to recover a register -- because there's nothing in the protocol to
> > > allow its recovery.
> > >
> > > For example, I've added the privileged mode registers to my ARM target
> > > code; when the target is using a ptrace() interface for debugging a user
> > > program, then these registers are never available and it's pointless
> > > having gdb report them.
> >
> > How about having target_fetch_register set them to -1 in the cache?
> > See remote.c:remote_fetch_registers:
> >
> > set_register_cached (i, -1);
> >
> > This tells the rest of GDB that the value of the register is
> > "not available". You could unconditionally mark certain regs
> > as unavailable whenever target_fetch_registers is called.
>
> Already tried that idea. It doesn't work.
>
> set_register_cached (-1) means that the register is "temporarily
> unavailable" at this time (due to the way we gathered the registers).
> Each time registers_changed() is called the value is reset to zero.
>
> I need a way the target vector to let REGISTER_NAME() know that the
> register is "unavailable this session", so that it can return an empty
> string for the register; so that gdb won't think it exists at all.
I see. This is something that depends on both the arch and the target.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch/rfc] Revise REGISTER_SIM_REGNO()
2002-05-17 10:49 ` Michael Snyder
@ 2002-05-18 3:55 ` Richard Earnshaw
2002-05-18 12:39 ` Daniel Jacobowitz
0 siblings, 1 reply; 9+ messages in thread
From: Richard Earnshaw @ 2002-05-18 3:55 UTC (permalink / raw)
To: Michael Snyder; +Cc: Richard.Earnshaw, Andrew Cagney, gdb-patches
> > I need a way the target vector to let REGISTER_NAME() know that the
> > register is "unavailable this session", so that it can return an empty
> > string for the register; so that gdb won't think it exists at all.
>
>
> I see. This is something that depends on both the arch and the target.
Yep, the arch says what registers a processor has, the target says which
of those it can supply.
Of course, you will only get a useful debugging session if the two overlap
sufficiently.
I suspect that it will be quite common for the arch to describe registers
that are only available when the processor is running in a privileged
mode; clearly you don't need those to debug a user-level program, but they
can be very helpful when trying to debug an OS. Certainly this is the way
I'd like to describe the views of ARM processors.
R.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch/rfc] Revise REGISTER_SIM_REGNO()
2002-05-18 3:55 ` Richard Earnshaw
@ 2002-05-18 12:39 ` Daniel Jacobowitz
0 siblings, 0 replies; 9+ messages in thread
From: Daniel Jacobowitz @ 2002-05-18 12:39 UTC (permalink / raw)
To: Richard.Earnshaw; +Cc: Michael Snyder, Andrew Cagney, gdb-patches
On Sat, May 18, 2002 at 11:55:01AM +0100, Richard Earnshaw wrote:
>
> > > I need a way the target vector to let REGISTER_NAME() know that the
> > > register is "unavailable this session", so that it can return an empty
> > > string for the register; so that gdb won't think it exists at all.
> >
> >
> > I see. This is something that depends on both the arch and the target.
>
> Yep, the arch says what registers a processor has, the target says which
> of those it can supply.
>
> Of course, you will only get a useful debugging session if the two overlap
> sufficiently.
>
> I suspect that it will be quite common for the arch to describe registers
> that are only available when the processor is running in a privileged
> mode; clearly you don't need those to debug a user-level program, but they
> can be very helpful when trying to debug an OS. Certainly this is the way
> I'd like to describe the views of ARM processors.
SH is the same. The GNU/Linux native patch that the community is using
(which I keep meaning to fix up and submit...) patches a lot of
register names to "".
--
Daniel Jacobowitz Carnegie Mellon University
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch/rfc] Revise REGISTER_SIM_REGNO()
2002-05-14 15:48 [patch/rfc] Revise REGISTER_SIM_REGNO() Andrew Cagney
2002-05-15 3:46 ` Richard Earnshaw
@ 2002-05-19 21:35 ` Andrew Cagney
2002-05-28 19:19 ` Andrew Cagney
1 sibling, 1 reply; 9+ messages in thread
From: Andrew Cagney @ 2002-05-19 21:35 UTC (permalink / raw)
To: Andrew Cagney; +Cc: gdb-patches
> +enum {
> + /* Normal sane architecture. The corresponding register cache
> + entry is zero filled and the register is marked as unavailable. */
> + SIM_REGNO_UNAVAILABLE = -1,
Does:
SIM_REGNO_DNE = -1,
sound better?
For the moment remote-sim.c would mark the register as unavailable
(fixme comment). At least, though, the name is right.
> + /* For possible backward compatibility. The register cache doesn't
> + have a corresponding name. Skip the register entirely. */
> + LEGACY_SIM_REGNO_IGNORE = -2
> +};
Andrew
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch/rfc] Revise REGISTER_SIM_REGNO()
2002-05-19 21:35 ` Andrew Cagney
@ 2002-05-28 19:19 ` Andrew Cagney
0 siblings, 0 replies; 9+ messages in thread
From: Andrew Cagney @ 2002-05-28 19:19 UTC (permalink / raw)
To: Andrew Cagney; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 637 bytes --]
> +enum {
> + /* Normal sane architecture. The corresponding register cache
> + entry is zero filled and the register is marked as unavailable. */
> + SIM_REGNO_UNAVAILABLE = -1,
>
> Does:
> SIM_REGNO_DNE = -1,
> sound better?
(I spelt it out - SIM_REGNO_DOES_NOT_EXIST)
> For the moment remote-sim.c would mark the register as unavailable (fixme comment). At least, though, the name is right.
>
> + /* For possible backward compatibility. The register cache doesn't
> + have a corresponding name. Skip the register entirely. */
> + LEGACY_SIM_REGNO_IGNORE = -2
> +};
as per the attached. Committed.
Andrew
[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 14691 bytes --]
2002-05-28 Andrew Cagney <ac131313@redhat.com>
* sim-regno.h: New file.
* Makefile.in (sim_regno_h): Define.
(d10v-tdep.o, remote-sim.o): Add dependency on $(sim_regno_h).
* remote-sim.c: Include "sim-regno.h" and "gdb_assert.h".
(legacy_register_sim_regno): New function.
(one2one_register_sim_regno): New function.
(gdbsim_fetch_register): Rewrite.
(gdbsim_store_register): Only store a register when
REGISTER_SIM_REGNO is valid.
* d10v-tdep.c: Include "sim-regno.h".
(d10v_ts2_register_sim_regno): Add legacy_regiter_sim_regno check.
(d10v_ts3_register_sim_regno): Ditto.
* gdbarch.sh: Include "sim-regno.h".
(REGISTER_SIM_REGNO): Set default to legacy_register_sim_regno.
* gdbarch.h, gdbarch.c: Regenerate.
* arch-utils.h (default_register_sim_regno): Delete declaration.
* arch-utils.c (default_register_sim_regno): Delete function.
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.200
diff -u -r1.200 Makefile.in
--- Makefile.in 24 May 2002 00:12:16 -0000 1.200
+++ Makefile.in 29 May 2002 01:22:55 -0000
@@ -652,6 +652,7 @@
ser_unix_h = ser-unix.h
serial_h = serial.h
sh_tdep_h = sh-tdep.h osabi.h
+sim_regno_h = sim-regno.h
solist_h = solist.h
source_h = source.h
stabsread_h = stabsread.h
@@ -1405,7 +1406,8 @@
d10v-tdep.o: d10v-tdep.c $(defs_h) $(frame_h) $(obstack_h) $(symtab_h) \
$(gdbtypes_h) $(gdbcmd_h) $(gdbcore_h) $(gdb_string_h) $(value_h) \
$(inferior_h) $(dis-asm_h) $(symfile_h) $(objfiles_h) $(language_h) \
- $(arch_utils_h) $(regcache_h) $(floatformat_h) $(sim_d10v_h)
+ $(arch_utils_h) $(regcache_h) $(floatformat_h) $(sim_d10v_h) \
+ $(sim_regno_h)
dbxread.o: dbxread.c $(breakpoint_h) $(buildsym_h) $(command_h) \
$(complaints_h) $(defs_h) $(expression_h) $(gdb_stabs_h) $(gdbcore_h) \
@@ -1998,7 +2000,8 @@
remote-sim.o: remote-sim.c $(defs_h) $(inferior_h) $(value_h) $(gdb_string_h) \
$(terminal_h) $(target_h) $(gdbcore_h) $(INCLUDE_DIR)/callback.h \
- $(remote_sim_h) $(remote_utils_h) $(command_h) $(regcache_h)
+ $(remote_sim_h) $(remote_utils_h) $(command_h) $(regcache_h) \
+ $(sim_regno_h)
remote-st.o: remote-st.c $(defs_h) $(gdbcore_h) $(serial_h) \
$(target_h) $(gdb_string_h) $(regcache_h)
Index: arch-utils.c
===================================================================
RCS file: /cvs/src/src/gdb/arch-utils.c,v
retrieving revision 1.57
diff -u -r1.57 arch-utils.c
--- arch-utils.c 12 May 2002 03:09:11 -0000 1.57
+++ arch-utils.c 29 May 2002 01:22:56 -0000
@@ -267,13 +267,6 @@
return 0;
}
-int
-default_register_sim_regno (int num)
-{
- return num;
-}
-
-
CORE_ADDR
core_addr_identity (CORE_ADDR addr)
{
Index: arch-utils.h
===================================================================
RCS file: /cvs/src/src/gdb/arch-utils.h,v
retrieving revision 1.32
diff -u -r1.32 arch-utils.h
--- arch-utils.h 12 May 2002 03:09:11 -0000 1.32
+++ arch-utils.h 29 May 2002 01:22:56 -0000
@@ -94,11 +94,6 @@
extern int (*target_architecture_hook) (const struct bfd_arch_info *);
-
-/* Default raw->sim register re-numbering - does nothing. */
-
-extern int default_register_sim_regno (int reg_nr);
-
/* Identity function on a CORE_ADDR. Just returns its parameter. */
extern CORE_ADDR core_addr_identity (CORE_ADDR addr);
Index: d10v-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/d10v-tdep.c,v
retrieving revision 1.42
diff -u -r1.42 d10v-tdep.c
--- d10v-tdep.c 24 May 2002 00:12:16 -0000 1.42
+++ d10v-tdep.c 29 May 2002 01:22:57 -0000
@@ -41,6 +41,7 @@
#include "floatformat.h"
#include "gdb/sim-d10v.h"
+#include "sim-regno.h"
struct frame_extra_info
{
@@ -296,6 +297,8 @@
static int
d10v_ts2_register_sim_regno (int nr)
{
+ if (legacy_register_sim_regno (nr) < 0)
+ return legacy_register_sim_regno (nr);
if (nr >= TS2_IMAP0_REGNUM
&& nr < TS2_IMAP0_REGNUM + NR_IMAP_REGS)
return nr - TS2_IMAP0_REGNUM + SIM_D10V_IMAP0_REGNUM;
@@ -310,6 +313,8 @@
static int
d10v_ts3_register_sim_regno (int nr)
{
+ if (legacy_register_sim_regno (nr) < 0)
+ return legacy_register_sim_regno (nr);
if (nr >= TS3_IMAP0_REGNUM
&& nr < TS3_IMAP0_REGNUM + NR_IMAP_REGS)
return nr - TS3_IMAP0_REGNUM + SIM_D10V_IMAP0_REGNUM;
Index: gdbarch.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.c,v
retrieving revision 1.127
diff -u -r1.127 gdbarch.c
--- gdbarch.c 13 May 2002 17:20:57 -0000 1.127
+++ gdbarch.c 29 May 2002 01:22:58 -0000
@@ -39,6 +39,7 @@
#if GDB_MULTI_ARCH
#include "gdbcmd.h"
#include "inferior.h" /* enum CALL_DUMMY_LOCATION et.al. */
+#include "sim-regno.h" /* For legacy_register_sim_regno(). */
#else
/* Just include everything in sight so that the every old definition
of macro is visible. */
@@ -488,7 +489,7 @@
current_gdbarch->max_register_virtual_size = -1;
current_gdbarch->do_registers_info = do_registers_info;
current_gdbarch->print_float_info = default_print_float_info;
- current_gdbarch->register_sim_regno = default_register_sim_regno;
+ current_gdbarch->register_sim_regno = legacy_register_sim_regno;
current_gdbarch->cannot_fetch_register = cannot_register_not;
current_gdbarch->cannot_store_register = cannot_register_not;
current_gdbarch->use_generic_dummy_frames = -1;
Index: gdbarch.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.h,v
retrieving revision 1.95
diff -u -r1.95 gdbarch.h
--- gdbarch.h 13 May 2002 17:20:58 -0000 1.95
+++ gdbarch.h 29 May 2002 01:22:59 -0000
@@ -40,6 +40,7 @@
/* Pull in function declarations refered to, indirectly, via macros. */
#include "value.h" /* For default_coerce_float_to_double which is referenced by a macro. */
#include "inferior.h" /* For unsigned_address_to_pointer(). */
+#include "sim-regno.h" /* For legacy_register_sim_regno(). */
#endif
struct frame_info;
@@ -811,7 +812,7 @@
/* Default (function) for non- multi-arch platforms. */
#if (!GDB_MULTI_ARCH) && !defined (REGISTER_SIM_REGNO)
-#define REGISTER_SIM_REGNO(reg_nr) (default_register_sim_regno (reg_nr))
+#define REGISTER_SIM_REGNO(reg_nr) (legacy_register_sim_regno (reg_nr))
#endif
typedef int (gdbarch_register_sim_regno_ftype) (int reg_nr);
Index: gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.138
diff -u -r1.138 gdbarch.sh
--- gdbarch.sh 13 May 2002 17:20:58 -0000 1.138
+++ gdbarch.sh 29 May 2002 01:23:01 -0000
@@ -471,7 +471,7 @@
f:2:PRINT_FLOAT_INFO:void:print_float_info:void::::default_print_float_info::0
# MAP a GDB RAW register number onto a simulator register number. See
# also include/...-sim.h.
-f:2:REGISTER_SIM_REGNO:int:register_sim_regno:int reg_nr:reg_nr:::default_register_sim_regno::0
+f:2:REGISTER_SIM_REGNO:int:register_sim_regno:int reg_nr:reg_nr:::legacy_register_sim_regno::0
F:2:REGISTER_BYTES_OK:int:register_bytes_ok:long nr_bytes:nr_bytes::0:0
f:2:CANNOT_FETCH_REGISTER:int:cannot_fetch_register:int regnum:regnum:::cannot_register_not::0
f:2:CANNOT_STORE_REGISTER:int:cannot_store_register:int regnum:regnum:::cannot_register_not::0
@@ -759,6 +759,7 @@
/* Pull in function declarations refered to, indirectly, via macros. */
#include "value.h" /* For default_coerce_float_to_double which is referenced by a macro. */
#include "inferior.h" /* For unsigned_address_to_pointer(). */
+#include "sim-regno.h" /* For legacy_register_sim_regno(). */
#endif
struct frame_info;
@@ -1220,6 +1221,7 @@
#if GDB_MULTI_ARCH
#include "gdbcmd.h"
#include "inferior.h" /* enum CALL_DUMMY_LOCATION et.al. */
+#include "sim-regno.h" /* For legacy_register_sim_regno(). */
#else
/* Just include everything in sight so that the every old definition
of macro is visible. */
Index: remote-sim.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-sim.c,v
retrieving revision 1.21
diff -u -r1.21 remote-sim.c
--- remote-sim.c 20 Jan 2002 19:26:48 -0000 1.21
+++ remote-sim.c 29 May 2002 01:23:01 -0000
@@ -40,6 +40,8 @@
#include "remote-utils.h"
#include "command.h"
#include "regcache.h"
+#include "gdb_assert.h"
+#include "sim-regno.h"
/* Prototypes */
@@ -276,46 +278,88 @@
}
}
+int
+legacy_register_sim_regno (int regnum)
+{
+ /* Only makes sense to supply raw registers. */
+ gdb_assert (regnum >= 0 && regnum < NUM_REGS);
+ /* NOTE: cagney/2002-05-13: The old code did it this way and it is
+ suspected that some GDB/SIM combinations may rely on this
+ behavour. The default should be one2one_register_sim_regno
+ (below). */
+ if (REGISTER_NAME (regnum) != NULL
+ && REGISTER_NAME (regnum)[0] != '\0')
+ return regnum;
+ else
+ return LEGACY_SIM_REGNO_IGNORE;
+}
+
+int
+one2one_register_sim_regno (int regnum)
+{
+ /* Only makes sense to supply raw registers. */
+ gdb_assert (regnum >= 0 && regnum < NUM_REGS);
+ return regnum;
+}
+
static void
gdbsim_fetch_register (int regno)
{
- static int warn_user = 1;
if (regno == -1)
{
for (regno = 0; regno < NUM_REGS; regno++)
gdbsim_fetch_register (regno);
+ return;
}
- else if (REGISTER_NAME (regno) != NULL
- && *REGISTER_NAME (regno) != '\0')
+
+ switch (REGISTER_SIM_REGNO (regno))
{
- char buf[MAX_REGISTER_RAW_SIZE];
- int nr_bytes;
- if (REGISTER_SIM_REGNO (regno) >= 0)
+ case LEGACY_SIM_REGNO_IGNORE:
+ break;
+ case SIM_REGNO_DOES_NOT_EXIST:
+ {
+ /* For moment treat a `does not exist' register the same way
+ as an ``unavailable'' register. */
+ char *buf = alloca (MAX_REGISTER_RAW_SIZE);
+ int nr_bytes;
+ memset (buf, 0, MAX_REGISTER_RAW_SIZE);
+ supply_register (regno, buf);
+ set_register_cached (regno, -1);
+ break;
+ }
+ default:
+ {
+ static int warn_user = 1;
+ char *buf = alloca (MAX_REGISTER_RAW_SIZE);
+ int nr_bytes;
+ gdb_assert (regno >= 0 && regno < NUM_REGS);
+ memset (buf, 0, MAX_REGISTER_RAW_SIZE);
nr_bytes = sim_fetch_register (gdbsim_desc,
REGISTER_SIM_REGNO (regno),
buf, REGISTER_RAW_SIZE (regno));
- else
- nr_bytes = 0;
- if (nr_bytes == 0)
- /* register not applicable, supply zero's */
- memset (buf, 0, MAX_REGISTER_RAW_SIZE);
- else if (nr_bytes > 0 && nr_bytes != REGISTER_RAW_SIZE (regno)
- && warn_user)
- {
- fprintf_unfiltered (gdb_stderr,
- "Size of register %s (%d/%d) incorrect (%d instead of %d))",
- REGISTER_NAME (regno),
- regno, REGISTER_SIM_REGNO (regno),
- nr_bytes, REGISTER_RAW_SIZE (regno));
- warn_user = 0;
- }
- supply_register (regno, buf);
- if (sr_get_debug ())
- {
- printf_filtered ("gdbsim_fetch_register: %d", regno);
- /* FIXME: We could print something more intelligible. */
- dump_mem (buf, REGISTER_RAW_SIZE (regno));
- }
+ if (nr_bytes > 0 && nr_bytes != REGISTER_RAW_SIZE (regno) && warn_user)
+ {
+ fprintf_unfiltered (gdb_stderr,
+ "Size of register %s (%d/%d) incorrect (%d instead of %d))",
+ REGISTER_NAME (regno),
+ regno, REGISTER_SIM_REGNO (regno),
+ nr_bytes, REGISTER_RAW_SIZE (regno));
+ warn_user = 0;
+ }
+ /* FIXME: cagney/2002-05-27: Should check `nr_bytes == 0'
+ indicatingthat GDB and the SIM have different ideas about
+ which registers are fetchable. */
+ /* Else if (nr_bytes < 0): an old simulator, that doesn't
+ think to return the register size. Just assume all is ok. */
+ supply_register (regno, buf);
+ if (sr_get_debug ())
+ {
+ printf_filtered ("gdbsim_fetch_register: %d", regno);
+ /* FIXME: We could print something more intelligible. */
+ dump_mem (buf, REGISTER_RAW_SIZE (regno));
+ }
+ break;
+ }
}
}
@@ -327,10 +371,9 @@
{
for (regno = 0; regno < NUM_REGS; regno++)
gdbsim_store_register (regno);
+ return;
}
- else if (REGISTER_NAME (regno) != NULL
- && *REGISTER_NAME (regno) != '\0'
- && REGISTER_SIM_REGNO (regno) >= 0)
+ else if (REGISTER_SIM_REGNO (regno) >= 0)
{
char tmp[MAX_REGISTER_RAW_SIZE];
int nr_bytes;
@@ -341,6 +384,9 @@
if (nr_bytes > 0 && nr_bytes != REGISTER_RAW_SIZE (regno))
internal_error (__FILE__, __LINE__,
"Register size different to expected");
+ /* FIXME: cagney/2002-05-27: Should check `nr_bytes == 0'
+ indicatingthat GDB and the SIM have different ideas about
+ which registers are fetchable. */
if (sr_get_debug ())
{
printf_filtered ("gdbsim_store_register: %d", regno);
Index: sim-regno.h
===================================================================
RCS file: sim-regno.h
diff -N sim-regno.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ sim-regno.h 29 May 2002 01:23:01 -0000
@@ -0,0 +1,50 @@
+/* Generic remote debugging interface for simulators.
+
+ Copyright 2002 Free Software Foundation, Inc.
+
+ Contributed by Red Hat, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef SIM_REGNO_H
+#define SIM_REGNO_H
+
+/* The REGISTER_SIM_REGNO(REGNUM) method, when there is a
+ corresponding simulator register, returns that register number as a
+ cardinal. When there is no corresponding register, it returns a
+ negative value. */
+
+enum sim_regno {
+ /* Normal sane architecture. The simulator is known to not model
+ this register. */
+ SIM_REGNO_DOES_NOT_EXIST = -1,
+ /* For possible backward compatibility. The register cache doesn't
+ have a corresponding name. Skip the register entirely. */
+ LEGACY_SIM_REGNO_IGNORE = -2
+};
+
+/* For compatibility with older architectures, returns
+ (LEGACY_SIM_REGNO_IGNORE) when a register doesn't have. */
+
+extern int legacy_register_sim_regno (int regnum);
+
+/* Treat all raw registers as valid. */
+
+extern int one2one_register_sim_regno (int regnum);
+
+#endif
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2002-05-29 1:49 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-14 15:48 [patch/rfc] Revise REGISTER_SIM_REGNO() Andrew Cagney
2002-05-15 3:46 ` Richard Earnshaw
2002-05-16 16:35 ` Michael Snyder
2002-05-17 2:07 ` Richard Earnshaw
2002-05-17 10:49 ` Michael Snyder
2002-05-18 3:55 ` Richard Earnshaw
2002-05-18 12:39 ` Daniel Jacobowitz
2002-05-19 21:35 ` Andrew Cagney
2002-05-28 19:19 ` Andrew Cagney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox