#include "frame.h"
#include "command.h"
#include "gdbcmd.h"
+#include "target.h"
/* Local function prototypes. */
show_values PARAMS ((char *, int));
static void
-show_convenience PARAMS ((void));
+show_convenience PARAMS ((char *, int));
/* The value-history records all the values printed
by print commands during this session. Each chunk
{
for (i = 0; i < VALUE_HISTORY_CHUNK; i++)
if (val = value_history_chain->values[i])
- free (val);
+ free ((PTR)val);
next = value_history_chain->next;
- free (value_history_chain);
+ free ((PTR)value_history_chain);
value_history_chain = next;
}
value_history_count = 0;
SET_TRAPPED_INTERNALVAR (var, val, 0, 0, 0);
#endif
- free (var->value);
+ free ((PTR)var->value);
var->value = value_copy (val);
+ /* Force the value to be fetched from the target now, to avoid problems
+ later when this internalvar is referenced and the target is gone or
+ has changed. */
+ if (VALUE_LAZY (var->value))
+ value_fetch_lazy (var->value);
release_value (var->value);
}
{
var = internalvars;
internalvars = var->next;
- free (var->name);
- free (var->value);
- free (var);
+ free ((PTR)var->name);
+ free ((PTR)var->value);
+ free ((PTR)var);
}
}
static void
-show_convenience ()
+show_convenience (ignore, from_tty)
+ char *ignore;
+ int from_tty;
{
register struct internalvar *var;
int varseen = 0;
#endif
if (!varseen)
{
-#if 0
- /* Useless noise. */
- printf ("Debugger convenience variables:\n\n");
-#endif
varseen = 1;
}
printf_filtered ("$%s = ", var->name);
{
/* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
whether we want this to be true eventually. */
- return value_as_long (val);
+ return ADDR_BITS_REMOVE(value_as_long (val));
}
\f
/* Unpack raw data (copied from debugee, target byte order) at VALADDR
{
if (len == sizeof (char))
{
- char retval;
+ SIGNED char retval; /* plain chars might be unsigned on host */
bcopy (valaddr, &retval, sizeof (retval));
SWAP_TARGET_AND_HOST (&retval, sizeof (retval));
return retval;
{
if (len == sizeof(long))
{
- long retval;
+ unsigned long retval;
bcopy (valaddr, &retval, sizeof(retval));
SWAP_TARGET_AND_HOST (&retval, sizeof(retval));
return retval;
}
else if (len == sizeof(short))
{
- short retval;
+ unsigned short retval;
bcopy (valaddr, &retval, len);
SWAP_TARGET_AND_HOST (&retval, len);
return retval;
{
pc_for_sym = value_as_pointer (value_field (best_entry, 2));
sym = find_pc_function (pc_for_sym);
- demangled_name = cplus_demangle (SYMBOL_NAME (sym), -1);
+ demangled_name = cplus_demangle (SYMBOL_NAME (sym), 0);
*(strchr (demangled_name, ':')) = '\0';
}
sym = lookup_symbol (demangled_name, 0, VAR_NAMESPACE, 0, 0);
return value_headof (arg, 0, type);
}
-/* The value of a static class member does not depend
- on its instance, only on its type. If FIELDNO >= 0,
- then fieldno is a valid field number and is used directly.
- Otherwise, FIELDNAME is the name of the field we are
- searching for. If it is not a static field name, an
- error is signaled. TYPE is the type in which we look for the
- static field member.
-
- Return zero if we couldn't find anything; the caller may signal
- an error in that case. */
-
-value
-value_static_field (type, fieldname, fieldno)
- register struct type *type;
- char *fieldname;
- register int fieldno;
-{
- register value v;
- struct symbol *sym;
- char *phys_name;
-
- if (fieldno < 0)
- {
- /* Look for static field. */
- int i;
- for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
- if (! strcmp (TYPE_FIELD_NAME (type, i), fieldname))
- {
- if (TYPE_FIELD_STATIC (type, i))
- {
- fieldno = i;
- goto found;
- }
- else
- error ("field `%s' is not static", fieldname);
- }
- for (; i > 0; i--)
- {
- v = value_static_field (TYPE_BASECLASS (type, i), fieldname, -1);
- if (v != 0)
- return v;
- }
-
- if (destructor_name_p (fieldname, type))
- error ("Cannot get value of destructor");
-
- for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; i--)
- {
- if (! strcmp (TYPE_FN_FIELDLIST_NAME (type, i), fieldname))
- error ("Cannot get value of method \"%s\"", fieldname);
- }
- error("there is no field named %s", fieldname);
- }
-
- found:
- phys_name = TYPE_FIELD_STATIC_PHYSNAME (type, fieldno);
- sym = lookup_symbol (phys_name, 0, VAR_NAMESPACE, 0, NULL);
- if (! sym) error ("Internal error: could not find physical static variable named %s", phys_name);
-
- type = TYPE_FIELD_TYPE (type, fieldno);
- v = value_at (type, (CORE_ADDR)SYMBOL_BLOCK_VALUE (sym));
- return v;
-}
-
/* Compute the address of the baseclass which is
the INDEXth baseclass of class TYPE. The TYPE base
of the object is at VALADDR.
return valaddr + TYPE_BASECLASS_BITPOS (type, index) / 8;
}
\f
-long
+/* Unpack a field FIELDNO of the specified TYPE, from the anonymous object at
+ VALADDR.
+
+ Extracting bits depends on endianness of the machine. Compute the
+ number of least significant bits to discard. For big endian machines,
+ we compute the total number of bits in the anonymous object, subtract
+ off the bit count from the MSB of the object to the MSB of the
+ bitfield, then the size of the bitfield, which leaves the LSB discard
+ count. For little endian machines, the discard count is simply the
+ number of bits from the LSB of the anonymous object to the LSB of the
+ bitfield.
+
+ If the field is signed, we also do sign extension. */
+
+LONGEST
unpack_field_as_long (type, valaddr, fieldno)
struct type *type;
char *valaddr;
int fieldno;
{
- unsigned long val;
+ unsigned LONGEST val;
+ unsigned LONGEST valmask;
int bitpos = TYPE_FIELD_BITPOS (type, fieldno);
int bitsize = TYPE_FIELD_BITSIZE (type, fieldno);
+ int lsbcount;
- bcopy (valaddr + bitpos / 8, &val, sizeof val);
- SWAP_TARGET_AND_HOST (&val, sizeof val);
+ bcopy (valaddr + bitpos / 8, &val, sizeof (val));
+ SWAP_TARGET_AND_HOST (&val, sizeof (val));
+
+ /* Extract bits. See comment above. */
- /* Extracting bits depends on endianness of the machine. */
#if BITS_BIG_ENDIAN
- val = val >> (sizeof val * 8 - bitpos % 8 - bitsize);
+ lsbcount = (sizeof val * 8 - bitpos % 8 - bitsize);
#else
- val = val >> (bitpos % 8);
+ lsbcount = (bitpos % 8);
#endif
+ val >>= lsbcount;
- if (bitsize < 8 * sizeof (val))
- val &= (((unsigned long)1) << bitsize) - 1;
- return val;
+ /* If the field does not entirely fill a LONGEST, then zero the sign bits.
+ If the field is signed, and is negative, then sign extend. */
+
+ if ((bitsize > 0) && (bitsize < 8 * sizeof (val)))
+ {
+ valmask = (((unsigned LONGEST) 1) << bitsize) - 1;
+ val &= valmask;
+ if (!TYPE_UNSIGNED (TYPE_FIELD_TYPE (type, fieldno)))
+ {
+ if (val & (valmask ^ (valmask >> 1)))
+ {
+ val |= ~valmask;
+ }
+ }
+ }
+ return (val);
}
/* Modify the value of a bitfield. ADDR points to a block of memory in
/* FIXME, we assume that pointers have the same form and byte order as
integers, and that all pointers have the same form. */
if (code == TYPE_CODE_INT || code == TYPE_CODE_ENUM ||
- code == TYPE_CODE_CHAR || code == TYPE_CODE_PTR)
+ code == TYPE_CODE_CHAR || code == TYPE_CODE_PTR ||
+ code == TYPE_CODE_REF)
{
if (len == sizeof (char))
* (char *) VALUE_CONTENTS_RAW (val) = num;