2001-02-20 22:39:03 +00:00
|
|
|
/* Cache and manage the values of registers for GDB, the GNU debugger.
|
2002-04-09 22:14:39 +00:00
|
|
|
|
|
|
|
Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000,
|
|
|
|
2001, 2002 Free Software Foundation, Inc.
|
2001-02-20 22:39:03 +00:00
|
|
|
|
|
|
|
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. */
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "frame.h"
|
|
|
|
#include "target.h"
|
|
|
|
#include "value.h"
|
2001-05-04 04:15:33 +00:00
|
|
|
#include "inferior.h" /* for inferior_ptid */
|
2001-03-01 01:39:22 +00:00
|
|
|
#include "regcache.h"
|
2001-02-20 22:39:03 +00:00
|
|
|
|
|
|
|
/* FIND_SAVED_REGISTER ()
|
|
|
|
|
|
|
|
Return the address in which frame FRAME's value of register REGNUM
|
|
|
|
has been saved in memory. Or return zero if it has not been saved.
|
|
|
|
If REGNUM specifies the SP, the value we return is actually
|
|
|
|
the SP value, not an address where it was saved. */
|
|
|
|
|
|
|
|
CORE_ADDR
|
|
|
|
find_saved_register (struct frame_info *frame, int regnum)
|
|
|
|
{
|
|
|
|
register struct frame_info *frame1 = NULL;
|
|
|
|
register CORE_ADDR addr = 0;
|
|
|
|
|
|
|
|
if (frame == NULL) /* No regs saved if want current frame */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Note that this next routine assumes that registers used in
|
|
|
|
frame x will be saved only in the frame that x calls and
|
|
|
|
frames interior to it. This is not true on the sparc, but the
|
|
|
|
above macro takes care of it, so we should be all right. */
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
QUIT;
|
2002-04-20 23:54:28 +00:00
|
|
|
frame1 = get_next_frame (frame);
|
|
|
|
if (frame1 == 0)
|
2001-02-20 22:39:03 +00:00
|
|
|
break;
|
2002-04-20 23:54:28 +00:00
|
|
|
frame = frame1;
|
2001-02-20 22:39:03 +00:00
|
|
|
FRAME_INIT_SAVED_REGS (frame1);
|
|
|
|
if (frame1->saved_regs[regnum])
|
|
|
|
addr = frame1->saved_regs[regnum];
|
|
|
|
}
|
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DEFAULT_GET_SAVED_REGISTER ()
|
|
|
|
|
|
|
|
Find register number REGNUM relative to FRAME and put its (raw,
|
|
|
|
target format) contents in *RAW_BUFFER. Set *OPTIMIZED if the
|
|
|
|
variable was optimized out (and thus can't be fetched). Set *LVAL
|
|
|
|
to lval_memory, lval_register, or not_lval, depending on whether
|
|
|
|
the value was fetched from memory, from a register, or in a strange
|
|
|
|
and non-modifiable way (e.g. a frame pointer which was calculated
|
|
|
|
rather than fetched). Set *ADDRP to the address, either in memory
|
|
|
|
on as a REGISTER_BYTE offset into the registers array.
|
|
|
|
|
|
|
|
Note that this implementation never sets *LVAL to not_lval. But
|
|
|
|
it can be replaced by defining GET_SAVED_REGISTER and supplying
|
|
|
|
your own.
|
|
|
|
|
|
|
|
The argument RAW_BUFFER must point to aligned memory. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
default_get_saved_register (char *raw_buffer,
|
|
|
|
int *optimized,
|
|
|
|
CORE_ADDR *addrp,
|
|
|
|
struct frame_info *frame,
|
|
|
|
int regnum,
|
|
|
|
enum lval_type *lval)
|
|
|
|
{
|
|
|
|
CORE_ADDR addr;
|
|
|
|
|
|
|
|
if (!target_has_registers)
|
|
|
|
error ("No registers.");
|
|
|
|
|
|
|
|
/* Normal systems don't optimize out things with register numbers. */
|
|
|
|
if (optimized != NULL)
|
|
|
|
*optimized = 0;
|
|
|
|
addr = find_saved_register (frame, regnum);
|
|
|
|
if (addr != 0)
|
|
|
|
{
|
|
|
|
if (lval != NULL)
|
|
|
|
*lval = lval_memory;
|
|
|
|
if (regnum == SP_REGNUM)
|
|
|
|
{
|
|
|
|
if (raw_buffer != NULL)
|
|
|
|
{
|
|
|
|
/* Put it back in target format. */
|
|
|
|
store_address (raw_buffer, REGISTER_RAW_SIZE (regnum),
|
|
|
|
(LONGEST) addr);
|
|
|
|
}
|
|
|
|
if (addrp != NULL)
|
|
|
|
*addrp = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (raw_buffer != NULL)
|
|
|
|
target_read_memory (addr, raw_buffer, REGISTER_RAW_SIZE (regnum));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (lval != NULL)
|
|
|
|
*lval = lval_register;
|
|
|
|
addr = REGISTER_BYTE (regnum);
|
|
|
|
if (raw_buffer != NULL)
|
|
|
|
read_register_gen (regnum, raw_buffer);
|
|
|
|
}
|
|
|
|
if (addrp != NULL)
|
|
|
|
*addrp = addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined (GET_SAVED_REGISTER)
|
|
|
|
#define GET_SAVED_REGISTER(raw_buffer, optimized, addrp, frame, regnum, lval) \
|
|
|
|
default_get_saved_register(raw_buffer, optimized, addrp, frame, regnum, lval)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
get_saved_register (char *raw_buffer,
|
|
|
|
int *optimized,
|
|
|
|
CORE_ADDR *addrp,
|
|
|
|
struct frame_info *frame,
|
|
|
|
int regnum,
|
|
|
|
enum lval_type *lval)
|
|
|
|
{
|
|
|
|
GET_SAVED_REGISTER (raw_buffer, optimized, addrp, frame, regnum, lval);
|
|
|
|
}
|
|
|
|
|
2002-04-12 18:18:59 +00:00
|
|
|
/* frame_register_read ()
|
2001-02-20 22:39:03 +00:00
|
|
|
|
2002-04-12 18:18:59 +00:00
|
|
|
Find and return the value of REGNUM for the specified stack frame.
|
2001-02-20 22:39:03 +00:00
|
|
|
The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
|
|
|
|
|
2002-04-12 18:18:59 +00:00
|
|
|
Returns 0 if the register value could not be found. */
|
2001-02-20 22:39:03 +00:00
|
|
|
|
2002-04-12 18:18:59 +00:00
|
|
|
int
|
|
|
|
frame_register_read (struct frame_info *frame, int regnum, void *myaddr)
|
2001-02-20 22:39:03 +00:00
|
|
|
{
|
|
|
|
int optim;
|
|
|
|
get_saved_register (myaddr, &optim, (CORE_ADDR *) NULL, frame,
|
|
|
|
regnum, (enum lval_type *) NULL);
|
|
|
|
|
2002-04-12 18:18:59 +00:00
|
|
|
/* FIXME: cagney/2002-04-10: This test is just bogus. It is no
|
|
|
|
indication of the validity of the register. The value could
|
|
|
|
easily be found (on the stack) even though the corresponding
|
|
|
|
register isn't available. */
|
2001-02-20 22:39:03 +00:00
|
|
|
if (register_cached (regnum) < 0)
|
2002-04-12 18:18:59 +00:00
|
|
|
return 0; /* register value not available */
|
2001-02-20 22:39:03 +00:00
|
|
|
|
2002-04-12 18:18:59 +00:00
|
|
|
return !optim;
|
2001-02-20 22:39:03 +00:00
|
|
|
}
|