* dwarf2expr.h (dwarf2_read_address): Add gdbarch argument.

* dwarf2expr.c (dwarf2_read_address): Add gdbarch argument.
	Call gdbarch_integer_to_address directly instead of converting
	to value and back.  Update comment.
	(execute_stack_op): Update call site.
	* dwarf2loc.c (find_location_expression): Likewise.
	(locexpr_describe_location): Update

	* dwarf2expr.h (struct dwarf_expr_context): Add gdbarch member.
	* dwarf2-frame.c (execute_stack_op): Initialize ctx->gdbarch.
	* dwarf2loc. (dwarf2_evaluate_loc_desc): Likewise.
	(dwarf2_loc_desc_needs_frame): Likewise.
This commit is contained in:
Ulrich Weigand 2008-09-05 11:40:53 +00:00
parent 714835d5a6
commit f7fd47281b
5 changed files with 44 additions and 26 deletions

View File

@ -1,3 +1,18 @@
2008-09-05 Ulrich Weigand <uweigand@de.ibm.com>
* dwarf2expr.h (dwarf2_read_address): Add gdbarch argument.
* dwarf2expr.c (dwarf2_read_address): Add gdbarch argument.
Call gdbarch_integer_to_address directly instead of converting
to value and back. Update comment.
(execute_stack_op): Update call site.
* dwarf2loc.c (find_location_expression): Likewise.
(locexpr_describe_location): Update
* dwarf2expr.h (struct dwarf_expr_context): Add gdbarch member.
* dwarf2-frame.c (execute_stack_op): Initialize ctx->gdbarch.
* dwarf2loc. (dwarf2_evaluate_loc_desc): Likewise.
(dwarf2_loc_desc_needs_frame): Likewise.
2008-09-05 Ulrich Weigand <uweigand@de.ibm.com>
* breakpoint.h (struct bp_location): Change type of section

View File

@ -348,6 +348,7 @@ execute_stack_op (gdb_byte *exp, ULONGEST len, int addr_size,
CORE_ADDR result;
ctx = new_dwarf_expr_context ();
ctx->gdbarch = get_frame_arch (this_frame);
ctx->addr_size = addr_size;
ctx->baton = this_frame;
ctx->read_reg = read_reg;

View File

@ -204,7 +204,8 @@ read_sleb128 (gdb_byte *buf, gdb_byte *buf_end, LONGEST * r)
doesn't extend past BUF_END. */
CORE_ADDR
dwarf2_read_address (gdb_byte *buf, gdb_byte *buf_end, int addr_size)
dwarf2_read_address (struct gdbarch *gdbarch, gdb_byte *buf,
gdb_byte *buf_end, int addr_size)
{
CORE_ADDR result;
@ -215,28 +216,18 @@ dwarf2_read_address (gdb_byte *buf, gdb_byte *buf_end, int addr_size)
is sufficient for extracting an address. However, some
architectures (e.g. MIPS) use signed addresses and using
extract_unsigned_integer() will not produce a correct
result. Turning the unsigned integer into a value and then
decomposing that value as an address will cause
gdbarch_integer_to_address() to be invoked for those
architectures which require it. Thus, using value_as_address()
will produce the correct result for both types of architectures.
One concern regarding the use of values for this purpose is
efficiency. Obviously, these extra calls will take more time to
execute and creating a value takes more space, space which will
have to be garbage collected at a later time. If constructing
and then decomposing a value for this purpose proves to be too
inefficient, then gdbarch_integer_to_address() can be called
directly.
result. Make sure we invoke gdbarch_integer_to_address()
for those architectures which require it.
The use of `unsigned_address_type' in the code below refers to
the type of buf and has no bearing on the signedness of the
address being returned. */
result = value_as_address (value_from_longest
(unsigned_address_type (addr_size),
extract_unsigned_integer (buf, addr_size)));
return result;
if (gdbarch_integer_to_address_p (gdbarch))
return gdbarch_integer_to_address
(gdbarch, unsigned_address_type (addr_size), buf);
return extract_unsigned_integer (buf, addr_size);
}
/* Return the type of an address of size ADDR_SIZE,
@ -339,7 +330,8 @@ execute_stack_op (struct dwarf_expr_context *ctx,
break;
case DW_OP_addr:
result = dwarf2_read_address (op_ptr, op_end, ctx->addr_size);
result = dwarf2_read_address (ctx->gdbarch,
op_ptr, op_end, ctx->addr_size);
op_ptr += ctx->addr_size;
break;
@ -559,7 +551,8 @@ execute_stack_op (struct dwarf_expr_context *ctx,
{
gdb_byte *buf = alloca (ctx->addr_size);
(ctx->read_mem) (ctx->baton, buf, result, ctx->addr_size);
result = dwarf2_read_address (buf, buf + ctx->addr_size,
result = dwarf2_read_address (ctx->gdbarch,
buf, buf + ctx->addr_size,
ctx->addr_size);
}
break;
@ -569,7 +562,8 @@ execute_stack_op (struct dwarf_expr_context *ctx,
int addr_size = *op_ptr++;
gdb_byte *buf = alloca (addr_size);
(ctx->read_mem) (ctx->baton, buf, result, addr_size);
result = dwarf2_read_address (buf, buf + addr_size,
result = dwarf2_read_address (ctx->gdbarch,
buf, buf + addr_size,
addr_size);
}
break;

View File

@ -34,6 +34,9 @@ struct dwarf_expr_context
number of elements allocated to the stack. */
int stack_len, stack_allocated;
/* Target architecture to use for address operations. */
struct gdbarch *gdbarch;
/* Target address size in bytes. */
int addr_size;
@ -138,7 +141,7 @@ CORE_ADDR dwarf_expr_fetch (struct dwarf_expr_context *ctx, int n);
gdb_byte *read_uleb128 (gdb_byte *buf, gdb_byte *buf_end, ULONGEST * r);
gdb_byte *read_sleb128 (gdb_byte *buf, gdb_byte *buf_end, LONGEST * r);
CORE_ADDR dwarf2_read_address (gdb_byte *buf, gdb_byte *buf_end,
int addr_size);
CORE_ADDR dwarf2_read_address (struct gdbarch *gdbarch, gdb_byte *buf,
gdb_byte *buf_end, int addr_size);
#endif /* dwarf2expr.h */

View File

@ -55,6 +55,7 @@ find_location_expression (struct dwarf2_loclist_baton *baton,
gdb_byte *loc_ptr, *buf_end;
int length;
struct objfile *objfile = dwarf2_per_cu_objfile (baton->per_cu);
struct gdbarch *gdbarch = get_objfile_arch (objfile);
unsigned int addr_size = dwarf2_per_cu_addr_size (baton->per_cu);
CORE_ADDR base_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
/* Adjust base_address for relocatable objects. */
@ -67,9 +68,9 @@ find_location_expression (struct dwarf2_loclist_baton *baton,
while (1)
{
low = dwarf2_read_address (loc_ptr, buf_end, addr_size);
low = dwarf2_read_address (gdbarch, loc_ptr, buf_end, addr_size);
loc_ptr += addr_size;
high = dwarf2_read_address (loc_ptr, buf_end, addr_size);
high = dwarf2_read_address (gdbarch, loc_ptr, buf_end, addr_size);
loc_ptr += addr_size;
/* An end-of-list entry. */
@ -215,6 +216,7 @@ dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
baton.objfile = dwarf2_per_cu_objfile (per_cu);
ctx = new_dwarf_expr_context ();
ctx->gdbarch = get_objfile_arch (baton.objfile);
ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
ctx->baton = &baton;
ctx->read_reg = dwarf_expr_read_reg;
@ -336,6 +338,7 @@ dwarf2_loc_desc_needs_frame (gdb_byte *data, unsigned short size,
baton.needs_frame = 0;
ctx = new_dwarf_expr_context ();
ctx->gdbarch = get_objfile_arch (dwarf2_per_cu_objfile (per_cu));
ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
ctx->baton = &baton;
ctx->read_reg = needs_frame_read_reg;
@ -492,7 +495,9 @@ locexpr_describe_location (struct symbol *symbol, struct ui_file *stream)
if (dlbaton->data[0] == DW_OP_addr)
{
struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
CORE_ADDR offset = dwarf2_read_address (&dlbaton->data[1],
struct gdbarch *gdbarch = get_objfile_arch (objfile);
CORE_ADDR offset = dwarf2_read_address (gdbarch,
&dlbaton->data[1],
&dlbaton->data[dlbaton->size - 1],
addr_size);
fprintf_filtered (stream,