2002-06-01 20:44:21 +00:00
|
|
|
/* Cache and manage frames 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"
|
2002-06-01 20:44:21 +00:00
|
|
|
#include "gdb_assert.h"
|
2002-09-25 20:30:38 +00:00
|
|
|
#include "gdb_string.h"
|
|
|
|
#include "builtin-regs.h"
|
2001-02-20 22:39:03 +00:00
|
|
|
|
2002-06-10 23:25:50 +00:00
|
|
|
/* Return a frame uniq ID that can be used to, later re-find the
|
|
|
|
frame. */
|
|
|
|
|
|
|
|
void
|
|
|
|
get_frame_id (struct frame_info *fi, struct frame_id *id)
|
|
|
|
{
|
|
|
|
if (fi == NULL)
|
|
|
|
{
|
|
|
|
id->base = 0;
|
|
|
|
id->pc = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
id->base = FRAME_FP (fi);
|
|
|
|
id->pc = fi->pc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct frame_info *
|
|
|
|
frame_find_by_id (struct frame_id id)
|
|
|
|
{
|
|
|
|
struct frame_info *frame;
|
|
|
|
|
|
|
|
/* ZERO denotes the null frame, let the caller decide what to do
|
|
|
|
about it. Should it instead return get_current_frame()? */
|
|
|
|
if (id.base == 0 && id.pc == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (frame = get_current_frame ();
|
|
|
|
frame != NULL;
|
|
|
|
frame = get_prev_frame (frame))
|
|
|
|
{
|
|
|
|
if (INNER_THAN (FRAME_FP (frame), id.base))
|
|
|
|
/* ``inner/current < frame < id.base''. Keep looking along
|
|
|
|
the frame chain. */
|
|
|
|
continue;
|
|
|
|
if (INNER_THAN (id.base, FRAME_FP (frame)))
|
|
|
|
/* ``inner/current < id.base < frame''. Oops, gone past it.
|
|
|
|
Just give up. */
|
|
|
|
return NULL;
|
|
|
|
/* FIXME: cagney/2002-04-21: This isn't sufficient. It should
|
|
|
|
use id.pc to check that the two frames belong to the same
|
|
|
|
function. Otherwise we'll do things like match dummy frames
|
|
|
|
or mis-match frameless functions. However, until someone
|
|
|
|
notices, stick with the existing behavour. */
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-06-01 20:44:21 +00:00
|
|
|
void
|
|
|
|
frame_register_unwind (struct frame_info *frame, int regnum,
|
|
|
|
int *optimizedp, enum lval_type *lvalp,
|
|
|
|
CORE_ADDR *addrp, int *realnump, void *bufferp)
|
|
|
|
{
|
|
|
|
struct frame_unwind_cache *cache;
|
|
|
|
|
|
|
|
/* Require all but BUFFERP to be valid. A NULL BUFFERP indicates
|
|
|
|
that the value proper does not need to be fetched. */
|
|
|
|
gdb_assert (optimizedp != NULL);
|
|
|
|
gdb_assert (lvalp != NULL);
|
|
|
|
gdb_assert (addrp != NULL);
|
|
|
|
gdb_assert (realnump != NULL);
|
|
|
|
/* gdb_assert (bufferp != NULL); */
|
|
|
|
|
|
|
|
/* NOTE: cagney/2002-04-14: It would be nice if, instead of a
|
|
|
|
special case, there was always an inner frame dedicated to the
|
|
|
|
hardware registers. Unfortunatly, there is too much unwind code
|
|
|
|
around that looks up/down the frame chain while making the
|
|
|
|
assumption that each frame level is using the same unwind code. */
|
|
|
|
|
|
|
|
if (frame == NULL)
|
|
|
|
{
|
|
|
|
/* We're in the inner-most frame, get the value direct from the
|
|
|
|
register cache. */
|
|
|
|
*optimizedp = 0;
|
|
|
|
*lvalp = lval_register;
|
2002-08-21 03:34:22 +00:00
|
|
|
/* ULGH! Code uses the offset into the raw register byte array
|
|
|
|
as a way of identifying a register. */
|
|
|
|
*addrp = REGISTER_BYTE (regnum);
|
2002-06-01 20:44:21 +00:00
|
|
|
/* Should this code test ``register_cached (regnum) < 0'' and do
|
|
|
|
something like set realnum to -1 when the register isn't
|
|
|
|
available? */
|
|
|
|
*realnump = regnum;
|
|
|
|
if (bufferp)
|
2002-11-02 14:59:10 +00:00
|
|
|
deprecated_read_register_gen (regnum, bufferp);
|
2002-06-01 20:44:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ask this frame to unwind its register. */
|
|
|
|
frame->register_unwind (frame, &frame->register_unwind_cache, regnum,
|
|
|
|
optimizedp, lvalp, addrp, realnump, bufferp);
|
|
|
|
}
|
|
|
|
|
2002-09-17 20:42:01 +00:00
|
|
|
void
|
|
|
|
frame_unwind_signed_register (struct frame_info *frame, int regnum,
|
|
|
|
LONGEST *val)
|
|
|
|
{
|
|
|
|
int optimized;
|
|
|
|
CORE_ADDR addr;
|
|
|
|
int realnum;
|
|
|
|
enum lval_type lval;
|
|
|
|
void *buf = alloca (MAX_REGISTER_RAW_SIZE);
|
|
|
|
frame_register_unwind (frame, regnum, &optimized, &lval, &addr,
|
|
|
|
&realnum, buf);
|
|
|
|
(*val) = extract_signed_integer (buf, REGISTER_VIRTUAL_SIZE (regnum));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
frame_unwind_unsigned_register (struct frame_info *frame, int regnum,
|
|
|
|
ULONGEST *val)
|
|
|
|
{
|
|
|
|
int optimized;
|
|
|
|
CORE_ADDR addr;
|
|
|
|
int realnum;
|
|
|
|
enum lval_type lval;
|
|
|
|
void *buf = alloca (MAX_REGISTER_RAW_SIZE);
|
|
|
|
frame_register_unwind (frame, regnum, &optimized, &lval, &addr,
|
|
|
|
&realnum, buf);
|
|
|
|
(*val) = extract_unsigned_integer (buf, REGISTER_VIRTUAL_SIZE (regnum));
|
|
|
|
}
|
2002-06-01 20:44:21 +00:00
|
|
|
|
2002-10-31 20:14:33 +00:00
|
|
|
void
|
|
|
|
frame_read_unsigned_register (struct frame_info *frame, int regnum,
|
|
|
|
ULONGEST *val)
|
|
|
|
{
|
|
|
|
/* NOTE: cagney/2002-10-31: There is a bit of dogma here - there is
|
|
|
|
always a frame. Both this, and the equivalent
|
|
|
|
frame_read_signed_register() function, can only be called with a
|
|
|
|
valid frame. If, for some reason, this function is called
|
|
|
|
without a frame then the problem isn't here, but rather in the
|
|
|
|
caller. It should of first created a frame and then passed that
|
|
|
|
in. */
|
|
|
|
/* NOTE: cagney/2002-10-31: As a side bar, keep in mind that the
|
|
|
|
``current_frame'' should not be treated as a special case. While
|
|
|
|
``get_next_frame (current_frame) == NULL'' currently holds, it
|
|
|
|
should, as far as possible, not be relied upon. In the future,
|
|
|
|
``get_next_frame (current_frame)'' may instead simply return a
|
|
|
|
normal frame object that simply always gets register values from
|
|
|
|
the register cache. Consequently, frame code should try to avoid
|
|
|
|
tests like ``if get_next_frame() == NULL'' and instead just rely
|
|
|
|
on recursive frame calls (like the below code) when manipulating
|
|
|
|
a frame chain. */
|
|
|
|
gdb_assert (frame != NULL);
|
|
|
|
frame_unwind_unsigned_register (get_next_frame (frame), regnum, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
frame_read_signed_register (struct frame_info *frame, int regnum,
|
|
|
|
LONGEST *val)
|
|
|
|
{
|
|
|
|
/* See note in frame_read_unsigned_register(). */
|
|
|
|
gdb_assert (frame != NULL);
|
|
|
|
frame_unwind_signed_register (get_next_frame (frame), regnum, val);
|
|
|
|
}
|
|
|
|
|
2002-06-01 20:44:21 +00:00
|
|
|
void
|
|
|
|
generic_unwind_get_saved_register (char *raw_buffer,
|
|
|
|
int *optimizedp,
|
|
|
|
CORE_ADDR *addrp,
|
|
|
|
struct frame_info *frame,
|
|
|
|
int regnum,
|
|
|
|
enum lval_type *lvalp)
|
|
|
|
{
|
|
|
|
int optimizedx;
|
|
|
|
CORE_ADDR addrx;
|
|
|
|
int realnumx;
|
|
|
|
enum lval_type lvalx;
|
|
|
|
|
|
|
|
if (!target_has_registers)
|
|
|
|
error ("No registers.");
|
|
|
|
|
|
|
|
/* Keep things simple, ensure that all the pointers (except valuep)
|
|
|
|
are non NULL. */
|
|
|
|
if (optimizedp == NULL)
|
|
|
|
optimizedp = &optimizedx;
|
|
|
|
if (lvalp == NULL)
|
|
|
|
lvalp = &lvalx;
|
|
|
|
if (addrp == NULL)
|
|
|
|
addrp = &addrx;
|
|
|
|
|
|
|
|
/* Reached the the bottom (youngest, inner most) of the frame chain
|
|
|
|
(youngest, inner most) frame, go direct to the hardware register
|
|
|
|
cache (do not pass go, do not try to cache the value, ...). The
|
|
|
|
unwound value would have been cached in frame->next but that
|
|
|
|
doesn't exist. This doesn't matter as the hardware register
|
|
|
|
cache is stopping any unnecessary accesses to the target. */
|
|
|
|
|
|
|
|
/* NOTE: cagney/2002-04-14: It would be nice if, instead of a
|
|
|
|
special case, there was always an inner frame dedicated to the
|
|
|
|
hardware registers. Unfortunatly, there is too much unwind code
|
|
|
|
around that looks up/down the frame chain while making the
|
|
|
|
assumption that each frame level is using the same unwind code. */
|
|
|
|
|
|
|
|
if (frame == NULL)
|
|
|
|
frame_register_unwind (NULL, regnum, optimizedp, lvalp, addrp, &realnumx,
|
|
|
|
raw_buffer);
|
|
|
|
else
|
|
|
|
frame_register_unwind (frame->next, regnum, optimizedp, lvalp, addrp,
|
|
|
|
&realnumx, raw_buffer);
|
|
|
|
}
|
|
|
|
|
2001-02-20 22:39:03 +00:00
|
|
|
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-05-15 01:01:56 +00:00
|
|
|
/* FIXME: cagney/2002-05-15: This test, is just bogus.
|
|
|
|
|
|
|
|
It indicates that the target failed to supply a value for a
|
|
|
|
register because it was "not available" at this time. Problem
|
|
|
|
is, the target still has the register and so get saved_register()
|
|
|
|
may be returning a value saved on the stack. */
|
|
|
|
|
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
|
|
|
}
|
2002-09-25 20:30:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Map between a frame register number and its name. A frame register
|
|
|
|
space is a superset of the cooked register space --- it also
|
|
|
|
includes builtin registers. */
|
|
|
|
|
|
|
|
int
|
|
|
|
frame_map_name_to_regnum (const char *name, int len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Search register name space. */
|
|
|
|
for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++)
|
|
|
|
if (REGISTER_NAME (i) && len == strlen (REGISTER_NAME (i))
|
|
|
|
&& strncmp (name, REGISTER_NAME (i), len) == 0)
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try builtin registers. */
|
|
|
|
i = builtin_reg_map_name_to_regnum (name, len);
|
|
|
|
if (i >= 0)
|
|
|
|
{
|
|
|
|
/* A builtin register doesn't fall into the architecture's
|
|
|
|
register range. */
|
|
|
|
gdb_assert (i >= NUM_REGS + NUM_PSEUDO_REGS);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
frame_map_regnum_to_name (int regnum)
|
|
|
|
{
|
|
|
|
if (regnum < 0)
|
|
|
|
return NULL;
|
|
|
|
if (regnum < NUM_REGS + NUM_PSEUDO_REGS)
|
|
|
|
return REGISTER_NAME (regnum);
|
|
|
|
return builtin_reg_map_regnum_to_name (regnum);
|
|
|
|
}
|