home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 7
/
FreshFishVol7.bin
/
bbs
/
gnu
/
gdb-4.12-src.lha
/
GNU
/
src
/
amiga
/
gdb-4.12
/
gdb
/
values.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-03
|
43KB
|
1,465 lines
/* Low level packing and unpacking of values for GDB, the GNU Debugger.
Copyright 1986, 1987, 1989, 1991 Free Software Foundation, 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "defs.h"
#include <string.h>
#include "symtab.h"
#include "gdbtypes.h"
#include "value.h"
#include "gdbcore.h"
#include "frame.h"
#include "command.h"
#include "gdbcmd.h"
#include "target.h"
#include "demangle.h"
/* Local function prototypes. */
static value
value_headof PARAMS ((value, struct type *, struct type *));
static void
show_values PARAMS ((char *, int));
static void
show_convenience PARAMS ((char *, int));
/* The value-history records all the values printed
by print commands during this session. Each chunk
records 60 consecutive values. The first chunk on
the chain records the most recent values.
The total number of values is in value_history_count. */
#define VALUE_HISTORY_CHUNK 60
struct value_history_chunk
{
struct value_history_chunk *next;
value values[VALUE_HISTORY_CHUNK];
};
/* Chain of chunks now in use. */
static struct value_history_chunk *value_history_chain;
static int value_history_count; /* Abs number of last entry stored */
/* List of all value objects currently allocated
(except for those released by calls to release_value)
This is so they can be freed after each command. */
static value all_values;
/* Allocate a value that has the correct length for type TYPE. */
value
allocate_value (type)
struct type *type;
{
register value val;
check_stub_type (type);
val = (value) xmalloc (sizeof (struct value) + TYPE_LENGTH (type));
VALUE_NEXT (val) = all_values;
all_values = val;
VALUE_TYPE (val) = type;
VALUE_LVAL (val) = not_lval;
VALUE_ADDRESS (val) = 0;
VALUE_FRAME (val) = 0;
VALUE_OFFSET (val) = 0;
VALUE_BITPOS (val) = 0;
VALUE_BITSIZE (val) = 0;
VALUE_REPEATED (val) = 0;
VALUE_REPETITIONS (val) = 0;
VALUE_REGNO (val) = -1;
VALUE_LAZY (val) = 0;
VALUE_OPTIMIZED_OUT (val) = 0;
return val;
}
/* Allocate a value that has the correct length
for COUNT repetitions type TYPE. */
value
allocate_repeat_value (type, count)
struct type *type;
int count;
{
register value val;
val = (value) xmalloc (sizeof (struct value) + TYPE_LENGTH (type) * count);
VALUE_NEXT (val) = all_values;
all_values = val;
VALUE_TYPE (val) = type;
VALUE_LVAL (val) = not_lval;
VALUE_ADDRESS (val) = 0;
VALUE_FRAME (val) = 0;
VALUE_OFFSET (val) = 0;
VALUE_BITPOS (val) = 0;
VALUE_BITSIZE (val) = 0;
VALUE_REPEATED (val) = 1;
VALUE_REPETITIONS (val) = count;
VALUE_REGNO (val) = -1;
VALUE_LAZY (val) = 0;
VALUE_OPTIMIZED_OUT (val) = 0;
return val;
}
/* Return a mark in the value chain. All values allocated after the
mark is obtained (except for those released) are subject to being freed
if a subsequent value_free_to_mark is passed the mark. */
value
value_mark ()
{
return all_values;
}
/* Free all values allocated since MARK was obtained by value_mark
(except for those released). */
void
value_free_to_mark (mark)
value mark;
{
value val, next;
for (val = all_values; val && val != mark; val = next)
{
next = VALUE_NEXT (val);
value_free (val);
}
all_values = val;
}
/* Free all the values that have been allocated (except for those released).
Called after each command, successful or not. */
void
free_all_values ()
{
register value val, next;
for (val = all_values; val; val = next)
{
next = VALUE_NEXT (val);
value_free (val);
}
all_values = 0;
}
/* Remove VAL from the chain all_values
so it will not be freed automatically. */
void
release_value (val)
register value val;
{
register value v;
if (all_values == val)
{
all_values = val->next;
return;
}
for (v = all_values; v; v = v->next)
{
if (v->next == val)
{
v->next = val->next;
break;
}
}
}
/* Return a copy of the value ARG.
It contains the same contents, for same memory address,
but it's a different block of storage. */
value
value_copy (arg)
value arg;
{
register value val;
register struct type *type = VALUE_TYPE (arg);
if (VALUE_REPEATED (arg))
val = allocate_repeat_value (type, VALUE_REPETITIONS (arg));
else
val = allocate_value (type);
VALUE_LVAL (val) = VALUE_LVAL (arg);
VALUE_ADDRESS (val) = VALUE_ADDRESS (arg);
VALUE_OFFSET (val) = VALUE_OFFSET (arg);
VALUE_BITPOS (val) = VALUE_BITPOS (arg);
VALUE_BITSIZE (val) = VALUE_BITSIZE (arg);
VALUE_REGNO (val) = VALUE_REGNO (arg);
VALUE_LAZY (val) = VALUE_LAZY (arg);
if (!VALUE_LAZY (val))
{
memcpy (VALUE_CONTENTS_RAW (val), VALUE_CONTENTS_RAW (arg),
TYPE_LENGTH (VALUE_TYPE (arg))
* (VALUE_REPEATED (arg) ? VALUE_REPETITIONS (arg) : 1));
}
return val;
}
/* Access to the value history. */
/* Record a new value in the value history.
Returns the absolute history index of the entry.
Result of -1 indicates the value was not saved; otherwise it is the
value history index of this new item. */
int
record_latest_value (val)
value val;
{
int i;
/* Check error now if about to store an invalid float. We return -1
to the caller, but allow them to continue, e.g. to print it as "Nan". */
if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FLT)
{
unpack_double (VALUE_TYPE (val), VALUE_CONTENTS (val), &i);
if (i) return -1; /* Indicate value not saved in history */
}
/* Here we treat value_history_count as origin-zero
and applying to the value being stored now. */
i = value_history_count % VALUE_HISTORY_CHUNK;
if (i == 0)
{
register struct value_history_chunk *new
= (struct value_history_chunk *)
xmalloc (sizeof (struct value_history_chunk));
memset (new->values, 0, sizeof new->values);
new->next = value_history_chain;
value_history_chain = new;
}
value_history_chain->values[i] = val;
/* We don't want this value to have anything to do with the inferior anymore.
In particular, "set $1 = 50" should not affect the variable from which
the value was taken, and fast watchpoints should be able to assume that
a value on the value history never changes. */
if (VALUE_LAZY (val))
value_fetch_lazy (val);
VALUE_LVAL (val) = not_lval;
release_value (val);
/* Now we regard value_history_count as origin-one
and applying to the value just stored. */
return ++value_history_count;
}
/* Return a copy of the value in the history with sequence number NUM. */
value
access_value_history (num)
int num;
{
register struct value_history_chunk *chunk;
register int i;
register int absnum = num;
if (absnum <= 0)
absnum += value_history_count;
if (absnum <= 0)
{
if (num == 0)
error ("The history is empty.");
else if (num == 1)
error ("There is only one value in the history.");
else
error ("History does not go back to $$%d.", -num);
}
if (absnum > value_history_count)
error ("History has not yet reached $%d.", absnum);
absnum--;
/* Now absnum is always absolute and origin zero. */
chunk = value_history_chain;
for (i = (value_history_count - 1) / VALUE_HISTORY_CHUNK - absnum / VALUE_HISTORY_CHUNK;
i > 0; i--)
chunk = chunk->next;
return value_copy (chunk->values[absnum % VALUE_HISTORY_CHUNK]);
}
/* Clear the value history entirely.
Must be done when new symbol tables are loaded,
because the type pointers beco