#include "inferior.h"
#include "target.h"
#include "gdb_string.h"
+#include "gdb_assert.h"
#include "floatformat.h"
#include "symfile.h" /* for overlay functions */
#include "regcache.h"
-
-/* This is used to indicate that we don't know the format of the floating point
- number. Typically, this is useful for native ports, where the actual format
- is irrelevant, since no conversions will be taking place. */
-
-const struct floatformat floatformat_unknown;
+#include "builtin-regs.h"
/* Basic byte-swapping routines. GDB has needed these for a long time...
All extract a target-format integer at ADDR which is LEN bytes long. */
#endif
LONGEST
-extract_signed_integer (void *addr, int len)
+extract_signed_integer (const void *addr, int len)
{
LONGEST retval;
- unsigned char *p;
- unsigned char *startaddr = (unsigned char *) addr;
- unsigned char *endaddr = startaddr + len;
+ const unsigned char *p;
+ const unsigned char *startaddr = addr;
+ const unsigned char *endaddr = startaddr + len;
if (len > (int) sizeof (LONGEST))
error ("\
That operation is not available on integers of more than %d bytes.",
- sizeof (LONGEST));
+ (int) sizeof (LONGEST));
/* Start at the most significant end of the integer, and work towards
the least significant. */
- if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+ if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
{
p = startaddr;
/* Do the sign extension once at the start. */
}
ULONGEST
-extract_unsigned_integer (void *addr, int len)
+extract_unsigned_integer (const void *addr, int len)
{
ULONGEST retval;
- unsigned char *p;
- unsigned char *startaddr = (unsigned char *) addr;
- unsigned char *endaddr = startaddr + len;
+ const unsigned char *p;
+ const unsigned char *startaddr = addr;
+ const unsigned char *endaddr = startaddr + len;
if (len > (int) sizeof (ULONGEST))
error ("\
That operation is not available on integers of more than %d bytes.",
- sizeof (ULONGEST));
+ (int) sizeof (ULONGEST));
/* Start at the most significant end of the integer, and work towards
the least significant. */
retval = 0;
- if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+ if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
{
for (p = startaddr; p < endaddr; ++p)
retval = (retval << 8) | *p;
function returns 1 and sets *PVAL. Otherwise it returns 0. */
int
-extract_long_unsigned_integer (void *addr, int orig_len, LONGEST *pval)
+extract_long_unsigned_integer (const void *addr, int orig_len, LONGEST *pval)
{
char *p, *first_addr;
int len;
len = orig_len;
- if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+ if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
{
for (p = (char *) addr;
len > (int) sizeof (LONGEST) && p < (char *) addr + orig_len;
else based on POINTER_TO_ADDRESS. */
CORE_ADDR
-extract_address (void *addr, int len)
+extract_address (const void *addr, int len)
{
/* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
whether we want this to be true eventually. */
/* Treat the bytes at BUF as a pointer of type TYPE, and return the
address it represents. */
CORE_ADDR
-extract_typed_address (void *buf, struct type *type)
+extract_typed_address (const void *buf, struct type *type)
{
if (TYPE_CODE (type) != TYPE_CODE_PTR
&& TYPE_CODE (type) != TYPE_CODE_REF)
/* Start at the least significant end of the integer, and work towards
the most significant. */
- if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+ if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
{
for (p = endaddr - 1; p >= startaddr; --p)
{
/* Start at the least significant end of the integer, and work towards
the most significant. */
- if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+ if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
{
for (p = endaddr - 1; p >= startaddr; --p)
{
-/* Return a `value' with the contents of register REGNUM
- in its virtual format, with the type specified by
- REGISTER_VIRTUAL_TYPE.
+/* Return a `value' with the contents of (virtual or cooked) register
+ REGNUM as found in the specified FRAME. The register's type is
+ determined by REGISTER_VIRTUAL_TYPE.
- NOTE: returns NULL if register value is not available.
- Caller will check return value or die! */
+ NOTE: returns NULL if register value is not available. Caller will
+ check return value or die! */
-value_ptr
-value_of_register (int regnum)
+struct value *
+value_of_register (int regnum, struct frame_info *frame)
{
CORE_ADDR addr;
int optim;
- register value_ptr reg_val;
+ struct value *reg_val;
char *raw_buffer = (char*) alloca (MAX_REGISTER_RAW_SIZE);
enum lval_type lval;
+ /* Builtin registers lie completly outside of the range of normal
+ registers. Catch them early so that the target never sees them. */
+ if (regnum >= NUM_REGS + NUM_PSEUDO_REGS)
+ return value_of_builtin_reg (regnum, deprecated_selected_frame);
+
get_saved_register (raw_buffer, &optim, &addr,
- selected_frame, regnum, &lval);
+ frame, regnum, &lval);
+
+ /* 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. */
if (register_cached (regnum) < 0)
return NULL; /* register value not available */
/* Given a pointer of type TYPE in target form in BUF, return the
address it represents. */
CORE_ADDR
-unsigned_pointer_to_address (struct type *type, void *buf)
+unsigned_pointer_to_address (struct type *type, const void *buf)
{
return extract_address (buf, TYPE_LENGTH (type));
}
CORE_ADDR
-signed_pointer_to_address (struct type *type, void *buf)
+signed_pointer_to_address (struct type *type, const void *buf)
{
return extract_signed_integer (buf, TYPE_LENGTH (type));
}
case LOC_LOCAL_ARG:
case LOC_BASEREG:
case LOC_BASEREG_ARG:
- case LOC_THREAD_LOCAL_STATIC:
+ case LOC_HP_THREAD_LOCAL_STATIC:
return 1;
case LOC_UNDEF:
and a stack frame id, read the value of the variable
and return a (pointer to a) struct value containing the value.
If the variable cannot be found, return a zero pointer.
- If FRAME is NULL, use the selected_frame. */
+ If FRAME is NULL, use the deprecated_selected_frame. */
-value_ptr
+struct value *
read_var_value (register struct symbol *var, struct frame_info *frame)
{
- register value_ptr v;
+ register struct value *v;
struct type *type = SYMBOL_TYPE (var);
CORE_ADDR addr;
register int len;
len = TYPE_LENGTH (type);
if (frame == NULL)
- frame = selected_frame;
+ frame = deprecated_selected_frame;
switch (SYMBOL_CLASS (var))
{
break;
case LOC_INDIRECT:
- /* The import slot does not have a real address in it from the
- dynamic loader (dld.sl on HP-UX), if the target hasn't begun
- execution yet, so check for that. */
- if (!target_has_execution)
- error ("\
+ {
+ /* The import slot does not have a real address in it from the
+ dynamic loader (dld.sl on HP-UX), if the target hasn't
+ begun execution yet, so check for that. */
+ CORE_ADDR locaddr;
+ struct value *loc;
+ if (!target_has_execution)
+ error ("\
Attempt to access variable defined in different shared object or load module when\n\
addresses have not been bound by the dynamic loader. Try again when executable is running.");
- addr = SYMBOL_VALUE_ADDRESS (var);
- addr = read_memory_unsigned_integer
- (addr, TARGET_PTR_BIT / TARGET_CHAR_BIT);
- break;
+ locaddr = SYMBOL_VALUE_ADDRESS (var);
+ loc = value_at (lookup_pointer_type (type), locaddr, NULL);
+ addr = value_as_address (loc);
+ }
case LOC_ARG:
if (frame == NULL)
break;
case LOC_REF_ARG:
- if (frame == NULL)
- return 0;
- addr = FRAME_ARGS_ADDRESS (frame);
- if (!addr)
- return 0;
- addr += SYMBOL_VALUE (var);
- addr = read_memory_unsigned_integer
- (addr, TARGET_PTR_BIT / TARGET_CHAR_BIT);
- break;
+ {
+ struct value *ref;
+ CORE_ADDR argref;
+ if (frame == NULL)
+ return 0;
+ argref = FRAME_ARGS_ADDRESS (frame);
+ if (!argref)
+ return 0;
+ argref += SYMBOL_VALUE (var);
+ ref = value_at (lookup_pointer_type (type), argref, NULL);
+ addr = value_as_address (ref);
+ break;
+ }
case LOC_LOCAL:
case LOC_LOCAL_ARG:
case LOC_BASEREG:
case LOC_BASEREG_ARG:
- case LOC_THREAD_LOCAL_STATIC:
+ case LOC_HP_THREAD_LOCAL_STATIC:
{
- value_ptr regval;
+ struct value *regval;
regval = value_from_register (lookup_pointer_type (type),
SYMBOL_BASEREG (var), frame);
if (regval == NULL)
error ("Value of base register not available.");
- addr = value_as_pointer (regval);
+ addr = value_as_address (regval);
addr += SYMBOL_VALUE (var);
break;
}
+ case LOC_THREAD_LOCAL_STATIC:
+ {
+ if (target_get_thread_local_address_p ())
+ addr = target_get_thread_local_address (inferior_ptid,
+ SYMBOL_OBJFILE (var),
+ SYMBOL_VALUE_ADDRESS (var));
+ /* It wouldn't be wrong here to try a gdbarch method, too;
+ finding TLS is an ABI-specific thing. But we don't do that
+ yet. */
+ else
+ error ("Cannot find thread-local variables on this target");
+ break;
+ }
+
case LOC_TYPEDEF:
error ("Cannot look up value of a typedef");
break;
{
struct block *b;
int regno = SYMBOL_VALUE (var);
- value_ptr regval;
+ struct value *regval;
if (frame == NULL)
return 0;
- b = get_frame_block (frame);
+ b = get_frame_block (frame, 0);
if (SYMBOL_CLASS (var) == LOC_REGPARM_ADDR)
{
if (regval == NULL)
error ("Value of register variable not available.");
- addr = value_as_pointer (regval);
+ addr = value_as_address (regval);
VALUE_LVAL (v) = lval_memory;
}
else
NOTE: returns NULL if register value is not available.
Caller will check return value or die! */
-value_ptr
+struct value *
value_from_register (struct type *type, int regnum, struct frame_info *frame)
{
char *raw_buffer = (char*) alloca (MAX_REGISTER_RAW_SIZE);
CORE_ADDR addr;
int optim;
- value_ptr v = allocate_value (type);
+ struct value *v = allocate_value (type);
char *value_bytes = 0;
int value_bytes_copied = 0;
int num_storage_locs;
for some good purpose. */
{
VALUE_LVAL (v) = lval_reg_frame_relative;
- VALUE_FRAME (v) = FRAME_FP (frame);
+ VALUE_FRAME (v) = get_frame_base (frame);
VALUE_FRAME_REGNUM (v) = regnum;
}
else if (mem_stor)
VALUE_LVAL (v) = lval;
VALUE_ADDRESS (v) = addr;
- /* Convert raw data to virtual format if necessary. */
+ /* Convert the raw register to the corresponding data value's memory
+ format, if necessary. */
- if (REGISTER_CONVERTIBLE (regnum))
+ if (CONVERT_REGISTER_P (regnum))
{
- REGISTER_CONVERT_TO_VIRTUAL (regnum, type,
- raw_buffer, VALUE_CONTENTS_RAW (v));
+ REGISTER_TO_VALUE (regnum, type, raw_buffer, VALUE_CONTENTS_RAW (v));
}
else
{
/* Raw and virtual formats are the same for this register. */
- if (TARGET_BYTE_ORDER == BIG_ENDIAN && len < REGISTER_RAW_SIZE (regnum))
+ if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG && len < REGISTER_RAW_SIZE (regnum))
{
/* Big-endian, and we want less than full size. */
VALUE_OFFSET (v) = REGISTER_RAW_SIZE (regnum) - len;
return a (pointer to a) struct value containing the properly typed
address. */
-value_ptr
+struct value *
locate_var_value (register struct symbol *var, struct frame_info *frame)
{
CORE_ADDR addr = 0;
struct type *type = SYMBOL_TYPE (var);
- value_ptr lazy_value;
+ struct value *lazy_value;
/* Evaluate it first; if the result is a memory address, we're fine.
Lazy evaluation pays off here. */
if (VALUE_LAZY (lazy_value)
|| TYPE_CODE (type) == TYPE_CODE_FUNC)
{
- value_ptr val;
+ struct value *val;
addr = VALUE_ADDRESS (lazy_value);
val = value_from_pointer (lookup_pointer_type (type), addr);
switch (VALUE_LVAL (lazy_value))
{
case lval_register:
+ gdb_assert (REGISTER_NAME (VALUE_REGNO (lazy_value)) != NULL
+ && *REGISTER_NAME (VALUE_REGNO (lazy_value)) != '\0');
+ error("Address requested for identifier "
+ "\"%s\" which is in register $%s",
+ SYMBOL_SOURCE_NAME (var),
+ REGISTER_NAME (VALUE_REGNO (lazy_value)));
+ break;
+
case lval_reg_frame_relative:
- error ("Address requested for identifier \"%s\" which is in a register.",
- SYMBOL_SOURCE_NAME (var));
+ gdb_assert (REGISTER_NAME (VALUE_FRAME_REGNUM (lazy_value)) != NULL
+ && *REGISTER_NAME (VALUE_FRAME_REGNUM (lazy_value)) != '\0');
+ error("Address requested for identifier "
+ "\"%s\" which is in frame register $%s",
+ SYMBOL_SOURCE_NAME (var),
+ REGISTER_NAME (VALUE_FRAME_REGNUM (lazy_value)));
break;
default: