[patch wip] Delete get_saved_register()

Andrew Cagney
2003-03-12T18:56:18Z

[-- Attachment #1: Type: text/plain, Size: 667 bytes --]

Hello,

The attached deletes the function get_saved_register(). It's been
superseeded by frame_register() et.al.

Right now, this patch causes a (major) regression. The sequence:

$ gdb program
(gdb) print $pc

gets an internal error. An examination of a backtrace reveals that the
code was using `deprecated_selected_frame' and that was NULL. Before
committing the attached, I'm going to have to relace a few
`deprecated_selected_frame's with `get_selected_frame()' (the latter
throws an error if there really is no frame).

So at this stage, this patch is largely a heads up. Once I've
eliminated all the regressions, I'll commit the attached.

Andrew

[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 16966 bytes --]

2003-03-12 Andrew Cagney <cagney@redhat.com>

* frame.c (get_saved_register): Delete function.
* xstormy16-tdep.c: Update comment.
* regcache.h: Update comments.
* sparc-tdep.c (sparc_init_extra_frame_info): Instead of
get_saved_register and extract_address, use
frame_read_unsigned_register.
(sparc_frame_saved_pc): Ditto.
(sparc_get_saved_register): Instead of get_saved_register, use
frame_register.
(sparc_pop_frame): Ditto.
* frame.h (get_saved_register): Delete declaration.
* findvar.c: Update comments.
(value_of_register): Call frame_register instead of
get_saved_register.
(value_from_register): Ditto.
* config/sparc/tm-sparc.h: Update comment.
* breakpoint.c: Update comment.

Index: doc/ChangeLog
2003-03-12 Andrew Cagney <cagney@redhat.com>

* gdbint.texinfo (Target Architecture Definition): Delete
references to get_saved_register.

Index: breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.114
diff -u -r1.114 breakpoint.c
--- breakpoint.c 11 Mar 2003 19:07:01 -0000 1.114
+++ breakpoint.c 12 Mar 2003 18:45:52 -0000
@@ -1679,7 +1679,7 @@

/* Return nonzero if FRAME is a dummy frame. We can't use
DEPRECATED_PC_IN_CALL_DUMMY because figuring out the saved SP would
- take too much time, at least using get_saved_register on the 68k.
+ take too much time, at least using frame_register() on the 68k.
This means that for this function to work right a port must use the
bp_call_dummy breakpoint. */

Index: findvar.c
===================================================================
RCS file: /cvs/src/src/gdb/findvar.c,v
retrieving revision 1.50
diff -u -r1.50 findvar.c
--- findvar.c 1 Mar 2003 17:03:19 -0000 1.50
+++ findvar.c 12 Mar 2003 18:45:52 -0000
@@ -299,6 +299,7 @@
CORE_ADDR addr;
int optim;
struct value *reg_val;
+ int realnum;
char *raw_buffer = (char*) alloca (MAX_REGISTER_RAW_SIZE);
enum lval_type lval;

@@ -307,8 +308,7 @@
if (regnum >= NUM_REGS + NUM_PSEUDO_REGS)
return value_of_builtin_reg (regnum, deprecated_selected_frame);

- get_saved_register (raw_buffer, &optim, &addr,
- frame, regnum, &lval);
+ frame_register (frame, regnum, &optim, &lval, &addr, &realnum, raw_buffer);

/* FIXME: cagney/2002-05-15: This test is just bogus.

@@ -780,12 +780,9 @@
(value_bytes_copied += REGISTER_RAW_SIZE (local_regnum),
++local_regnum))
{
- get_saved_register (value_bytes + value_bytes_copied,
- &optim,
- &addr,
- frame,
- local_regnum,
- &lval);
+ int realnum;
+ frame_register (frame, local_regnum, &optim, &lval, &addr,
+ &realnum, value_bytes + value_bytes_copied);

if (register_cached (local_regnum) == -1)
return NULL; /* register value not available */
@@ -851,7 +848,10 @@
register's contents in a real register or in core;
read the data in raw format. */

- get_saved_register (raw_buffer, &optim, &addr, frame, regnum, &lval);
+ {
+ int realnum;
+ frame_register (frame, regnum, &optim, &lval, &addr, &realnum, raw_buffer);
+ }

if (register_cached (regnum) == -1)
return NULL; /* register value not available */
Index: frame.c
===================================================================
RCS file: /cvs/src/src/gdb/frame.c,v
retrieving revision 1.76
diff -u -r1.76 frame.c
--- frame.c 11 Mar 2003 17:47:13 -0000 1.76
+++ frame.c 12 Mar 2003 18:45:52 -0000
@@ -370,23 +370,6 @@
&realnumx, raw_buffer);
}

-void
-get_saved_register (char *raw_buffer,
- int *optimized,
- CORE_ADDR *addrp,
- struct frame_info *frame,
- int regnum,
- enum lval_type *lval)
-{
- if (GET_SAVED_REGISTER_P ())
- {
- GET_SAVED_REGISTER (raw_buffer, optimized, addrp, frame, regnum, lval);
- return;
- }
- generic_unwind_get_saved_register (raw_buffer, optimized, addrp, frame,
- regnum, lval);
-}
-
/* frame_register_read ()

Find and return the value of REGNUM for the specified stack frame.
@@ -784,9 +767,10 @@
const struct frame_unwind *trad_frame_unwind = &trad_frame_unwinder;

-/* Function: get_saved_register
+/* Function: deprecated_generic_get_saved_register
+
Find register number REGNUM relative to FRAME and put its (raw,
- target format) contents in *RAW_BUFFER.
+ target format) contents in *RAW_BUFFER.

Set *OPTIMIZED if the variable was optimized out (and thus can't be
fetched). Note that this is never set to anything other than zero
@@ -801,10 +785,6 @@
Set *ADDRP to the address, either in memory or as a REGISTER_BYTE
offset into the registers array. If the value is stored in a dummy
frame, set *ADDRP to zero.
-
- To use this implementation, define a function called
- "get_saved_register" in your target code, which simply passes all
- of its arguments to this function.

The argument RAW_BUFFER must point to aligned memory. */

Index: frame.h
===================================================================
RCS file: /cvs/src/src/gdb/frame.h,v
retrieving revision 1.71
diff -u -r1.71 frame.h
--- frame.h 5 Mar 2003 18:51:17 -0000 1.71
+++ frame.h 12 Mar 2003 18:45:53 -0000
@@ -538,7 +538,7 @@
/* NOTE: cagney/2002-06-26: Targets should no longer use this
function. Instead, the contents of a dummy frames registers can be
obtained by applying: frame_register_unwind to the dummy frame; or
- get_saved_register to the next outer frame. */
+ frame_register_unwind() to the next outer frame. */

extern char *deprecated_generic_find_dummy_frame (CORE_ADDR pc, CORE_ADDR fp);

@@ -563,11 +563,6 @@
enum lval_type *);

extern void generic_save_call_dummy_addr (CORE_ADDR lo, CORE_ADDR hi);
-
-extern void get_saved_register (char *raw_buffer, int *optimized,
- CORE_ADDR * addrp,
- struct frame_info *frame,
- int regnum, enum lval_type *lval);

/* FIXME: cagney/2003-02-02: Should be deprecated or replaced with a
function called frame_read_register_p(). This slightly weird (and
Index: regcache.h
===================================================================
RCS file: /cvs/src/src/gdb/regcache.h,v
retrieving revision 1.30
diff -u -r1.30 regcache.h
--- regcache.h 10 Mar 2003 19:08:47 -0000 1.30
+++ regcache.h 12 Mar 2003 18:45:53 -0000
@@ -94,7 +94,7 @@

/* The register's ``offset''.

- FIXME: cagney/2002-11-07: The get_saved_register() function, when
+ FIXME: cagney/2002-11-07: The frame_register() function, when
specifying the real location of a register, does so using that
registers offset in the register cache. That offset is then used
by valops.c to determine the location of the register. The code
Index: sparc-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sparc-tdep.c,v
retrieving revision 1.69
diff -u -r1.69 sparc-tdep.c
--- sparc-tdep.c 3 Mar 2003 20:50:20 -0000 1.69
+++ sparc-tdep.c 12 Mar 2003 18:45:53 -0000
@@ -326,9 +326,9 @@
else
{
/* Should we adjust for stack bias here? */
- get_saved_register (buf, 0, 0, fi, FP_REGNUM, 0);
- deprecated_update_frame_base_hack (fi, extract_address (buf, REGISTER_RAW_SIZE (FP_REGNUM)));
-
+ ULONGEST tmp;
+ frame_read_unsigned_register (fi, FP_REGNUM, &tmp);
+ deprecated_update_frame_base_hack (fi, tmp);
if (GDB_TARGET_IS_SPARC64 && (get_frame_base (fi) & 1))
deprecated_update_frame_base_hack (fi, get_frame_base (fi) + 2047);
}
@@ -367,8 +367,11 @@
get_frame_extra_info (fi)->sp_offset = offset;

/* Overwrite the frame's address with the value in %i7. */
- get_saved_register (buf, 0, 0, fi, I7_REGNUM, 0);
- deprecated_update_frame_base_hack (fi, extract_address (buf, REGISTER_RAW_SIZE (I7_REGNUM)));
+ {
+ ULONGEST tmp;
+ frame_read_unsigned_register (fi, I7_REGNUM, &tmp);
+ deprecated_update_frame_base_hack (fi, tmp);
+ }

if (GDB_TARGET_IS_SPARC64 && (get_frame_base (fi) & 1))
deprecated_update_frame_base_hack (fi, get_frame_base (fi) + 2047);
@@ -487,9 +490,11 @@
saved_pc_offset = 12;

/* The sigcontext address is contained in register O2. */
- get_saved_register (buf, (int *) NULL, (CORE_ADDR *) NULL,
- frame, O0_REGNUM + 2, (enum lval_type *) NULL);
- sigcontext_addr = extract_address (buf, REGISTER_RAW_SIZE (O0_REGNUM + 2));
+ {
+ ULONGEST tmp;
+ frame_read_unsigned_register (frame, O0_REGNUM + 2, &tmp);
+ sigcontext_addr = tmp;
+ }

/* Don't cause a memory_error when accessing sigcontext in case the
stack layout has changed or the stack is corrupt. */
@@ -505,9 +510,9 @@
{
/* A frameless function interrupted by a signal did not save
the PC, it is still in %o7. */
- get_saved_register (buf, (int *) NULL, (CORE_ADDR *) NULL,
- frame, O7_REGNUM, (enum lval_type *) NULL);
- return PC_ADJUST (extract_address (buf, SPARC_INTREG_SIZE));
+ ULONGEST tmp;
+ frame_read_unsigned_register (frame, O7_REGNUM, &tmp);
+ return PC_ADJUST (tmp);
}
if (get_frame_extra_info (frame)->flat)
addr = get_frame_extra_info (frame)->pc_addr;
@@ -936,8 +941,9 @@
else if (regnum >= O0_REGNUM && regnum < O0_REGNUM + 8)
{
/* Outs become ins. */
- get_saved_register (raw_buffer, optimized, addrp, frame1,
- (regnum - O0_REGNUM + I0_REGNUM), lval);
+ int realnum;
+ frame_register (frame1, (regnum - O0_REGNUM + I0_REGNUM),
+ optimized, lval, addrp, &realnum, raw_buffer);
return;
}
}
@@ -1090,10 +1096,10 @@
I think few ports of GDB get right--if you are popping a frame
which does not save some register that *is* saved by a more inner
frame (such a frame will never be a dummy frame because dummy
- frames save all registers). Rewriting pop_frame to use
- get_saved_register would solve this problem and also get rid of the
- ugly duplication between sparc_frame_find_saved_regs and
- get_saved_register.
+ frames save all registers).
+
+ NOTE: cagney/2003-03-12: Since pop_frame has been rewritten to use
+ frame_unwind_register() the need for this function is questionable.

Stores, into an array of CORE_ADDR,
the addresses of the saved registers of frame described by FRAME_INFO.
@@ -1369,12 +1375,9 @@
/* I think this happens only in the innermost frame, if so then
it is a complicated way of saying
"pc = read_register (O7_REGNUM);". */
- char *buf;
-
- buf = alloca (MAX_REGISTER_RAW_SIZE);
- get_saved_register (buf, 0, 0, frame, O7_REGNUM, 0);
- pc = PC_ADJUST (extract_address
- (buf, REGISTER_RAW_SIZE (O7_REGNUM)));
+ ULONGEST tmp;
+ frame_read_unsigned_register (frame, O7_REGNUM, &tmp);
+ pc = PC_ADJUST (tmp);
}

write_register (PC_REGNUM, pc);
Index: xstormy16-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/xstormy16-tdep.c,v
retrieving revision 1.27
diff -u -r1.27 xstormy16-tdep.c
--- xstormy16-tdep.c 3 Mar 2003 20:50:20 -0000 1.27
+++ xstormy16-tdep.c 12 Mar 2003 18:45:53 -0000
@@ -723,11 +723,10 @@
actual value of the previous frame's stack register.

This function may be called in any context where the saved register
- values may be needed (backtrace, frame_info, get_saved_register).
- On many targets, it is called directly by init_extra_frame_info,
- in part because the information may be needed immediately by
- frame_chain.
-*/
+ values may be needed (backtrace, frame_info, frame_register). On
+ many targets, it is called directly by init_extra_frame_info, in
+ part because the information may be needed immediately by
+ frame_chain. */

static void
xstormy16_frame_init_saved_regs (struct frame_info *fi)
@@ -841,12 +840,11 @@
get_frame_base (thisframe) - get_frame_extra_info (thisframe)->framesize == chain);
}

-/* Function: xstormy16_saved_pc_after_call
- Returns the previous PC immediately after a function call.
- This function is meant to bypass the regular get_saved_register
- mechanism, ie. it is meant to work even if the frame isn't complete.
- Called by step_over_function, and sometimes by get_prev_frame.
-*/
+/* Function: xstormy16_saved_pc_after_call Returns the previous PC
+ immediately after a function call. This function is meant to
+ bypass the regular frame_register() mechanism, ie. it is meant to
+ work even if the frame isn't complete. Called by
+ step_over_function, and sometimes by get_prev_frame. */

static CORE_ADDR
xstormy16_saved_pc_after_call (struct frame_info *ignore)
Index: config/sparc/tm-sparc.h
===================================================================
RCS file: /cvs/src/src/gdb/config/sparc/tm-sparc.h,v
retrieving revision 1.35
diff -u -r1.35 tm-sparc.h
--- config/sparc/tm-sparc.h 3 Mar 2003 20:50:20 -0000 1.35
+++ config/sparc/tm-sparc.h 12 Mar 2003 18:45:53 -0000
@@ -199,10 +199,10 @@
stack rather than with the other registers, and this causes hair
and confusion in places like pop_frame. It might be better to
remove the ins and locals from `registers', make sure that
- get_saved_register can get them from the stack (even in the
- innermost frame), and make this the way to access them. For the
- frame pointer we would do that via TARGET_READ_FP. On the other
- hand, that is likely to be confusing or worse for flat frames. */
+ frame_register() can get them from the stack (even in the innermost
+ frame), and make this the way to access them. For the frame
+ pointer we would do that via TARGET_READ_FP. On the other hand,
+ that is likely to be confusing or worse for flat frames. */

#define REGISTER_BYTES (32*4+32*4+8*4)

Index: doc/gdbint.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdbint.texinfo,v
retrieving revision 1.128
diff -u -r1.128 gdbint.texinfo
--- doc/gdbint.texinfo 10 Mar 2003 15:28:41 -0000 1.128
+++ doc/gdbint.texinfo 12 Mar 2003 18:45:54 -0000
@@ -3354,9 +3354,8 @@

@item GET_SAVED_REGISTER
@findex GET_SAVED_REGISTER
-@findex get_saved_register
Define this if you need to supply your own definition for the function
-@code{get_saved_register}.
+@code{GET_SAVED_REGISTER}.

@item IBM6000_TARGET
@findex IBM6000_TARGET
Index: mi/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/mi/ChangeLog,v
retrieving revision 1.97
diff -u -r1.97 ChangeLog
--- mi/ChangeLog 8 Mar 2003 20:04:27 -0000 1.97
+++ mi/ChangeLog 12 Mar 2003 18:45:54 -0000
@@ -1,3 +1,8 @@
+2003-03-12 Andrew Cagney <cagney@redhat.com>
+
+ * mi-main.c (get_register): Use frame_register instead of
+ get_saved_register.
+
2003-03-08 Andrew Cagney <cagney@redhat.com>

* mi-out.c: Update copyright.
Index: mi/mi-main.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
retrieving revision 1.41
diff -u -r1.41 mi-main.c
--- mi/mi-main.c 1 Mar 2003 17:03:19 -0000 1.41
+++ mi/mi-main.c 12 Mar 2003 18:45:54 -0000
@@ -514,6 +514,9 @@
char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
char *virtual_buffer = alloca (MAX_REGISTER_VIRTUAL_SIZE);
int optim;
+ int realnum;
+ CORE_ADDR addr;
+ enum lval_type lval;
static struct ui_stream *stb = NULL;

stb = ui_out_stream_new (uiout);
@@ -521,9 +524,9 @@
if (format == 'N')
format = 0;

- get_saved_register (raw_buffer, &optim, (CORE_ADDR *) NULL,
- deprecated_selected_frame,
- regnum, (enum lval_type *) NULL);
+ frame_register (deprecated_selected_frame, regnum, &optim, &lval, &addr,
+ &realnum, raw_buffer);
+
if (optim)
{
xasprintf (&mi_error_message, "Optimized out");
Index: tui/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/tui/ChangeLog,v
retrieving revision 1.109
diff -u -r1.109 ChangeLog
--- tui/ChangeLog 8 Mar 2003 20:04:27 -0000 1.109
+++ tui/ChangeLog 12 Mar 2003 18:45:54 -0000
@@ -1,3 +1,8 @@
+2003-03-12 Andrew Cagney <cagney@redhat.com>
+
+ * tuiRegs.c (_tuiGetRegisterRawValue): Use frame_read_register,
+ instead of get_saved_register.
+
2003-03-08 Andrew Cagney <cagney@redhat.com>

* tui-out.c: Update copyright.
Index: tui/tuiRegs.c
===================================================================
RCS file: /cvs/src/src/gdb/tui/tuiRegs.c,v
retrieving revision 1.15
diff -u -r1.15 tuiRegs.c
--- tui/tuiRegs.c 29 Nov 2002 19:15:16 -0000 1.15
+++ tui/tuiRegs.c 12 Mar 2003 18:45:55 -0000
@@ -799,10 +799,7 @@

if (target_has_registers)
{
- int opt;
-
- get_saved_register (regValue, &opt, (CORE_ADDR*) NULL, frame,
- regNum, (enum lval_type*) NULL);
+ frame_read_register (frame, regNum, regValue);
if (register_cached (regNum) >= 0)
ret = TUI_SUCCESS;
}