This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[rfc] DWARF expression evaluation vs. GDB address encoding problems


Hello,

another SPU test case exposes a problem in address handling in the current
dwarf2expr.c code.  The situation is that a local variable has an alignment
requirement larger than the stack pointer alignment, and thus the stack
is realigned on function entry.  The debug info for that variable then
represents the alignment operation by a DWARF expresssion like this:

Symbol "x" is a complex DWARF expression:
     1: DW_OP_fbreg 32
     3: DW_OP_const4s 127
     8: DW_OP_plus
     9: DW_OP_const4s -128
    14: DW_OP_and

(This currently occurs only with XLC, as GCC doesn't support stack
realignment for the SPU target yet.)

This causes dwarf2expr.c to perform those operations on the DWARF value
stack, operating in the width specified by the DWARF address size.  On
the SPU, this now unfortunately truncates off the extended bits used
for encoding the SPU context ID ...

Similarly, it would appear that on targets that require addresses to
always remain sign-extended (to a size beyond the DWARF address size),
operations like that would break that invariant.

Note that the dwarf2_read_address routine attempts to implement such
target-specific rules, but this is done *before* the initial address
value is placed on the DWARF stack and operated upon, not afterwards.

In fact, this seems the real problem to me: operations on the DWARF
stack should really use the target pointer / address representation;
only after the computation is complete should the value be converted
into the GDB internal address representation (CORE_ADDR).

Note that this only applies if the result of the computation is
actually used as an *address* -- if it is a register number or a
(non-address) literal value, that conversion should not apply.

The following patch implements this by:

- creating a new dwarf_expr_fetch_address routine that fetches the top
  value on the DWARF stack and converts it to an address

- updating all callers of dwarf_expr_fetch to use the new routine 
  instead where appropriate (this includes extending the union in
  struct dwarf_expr_piece to distinguish uses as address from uses
  as register number / literal value)

- reading address values (from DW_OP_addr or as DW_OP_deref results)
  as plain unsigned integers; performing stack operations in ULONGEST
  with truncation to and sign-extension from the DWARF address size
  as needed

As a side effect, we no longer need to employ the value machinery
to perform binary operations on the DWARF stack.


I was wondering how to make the equivalent changes to the new
compile_dwarf_to_ax routine, which today uses dwarf2_read_address
as well.  Obviously the stragety of calling gdbarch_integer_to_address
at the end of the computation doesn't work, because that is not 
available on the target side.  On the other hand, on the target side
we do not use the GDB internal address encoding in the first place ...

Thus it seems to me that simply treating addresses as unsigned
integers should work fine.  (One possible exception is that platforms
might require use of sign-extended addresses even on the target.
But this doesn't appear to be supported elsewhere in AX support
either -- e.g. when performing a OP_DW_deref.  Thus I've left
this as-is for now -- if this turns out to be an issue on some
platforms, it would be easy to add sign-extend operations
depending on e.g. the bfd_get_sign_extend_vma flag.)

Tom, does this look reasonable to you?


Tested on powerpc64-linux (Cell/B.E.) and spu-elf.
I'd appreciate any comments or feedback!

Thanks,
Ulrich


ChangeLog:

	* dwarf2expr.h (struct dwarf_value_location): Use ULONGEST as type
	of stack values.
	(struct dwarf_expr_piece): Rename "expr" member to "mem".  Add new
	"value" member.
	(dwarf_expr_push): Change input type to ULONGEST.
	(dwarf_expr_fetch): Change return type to ULONGEST.
	(dwarf_expr_fetch_address): Add prototype.
	(dwarf2_read_address): Remove prototype.
	* dwarf2expr.c (dwarf_expr_push): Use ULONGEST as type of stack values.
	Truncate stack values to ctx->addr_size bytes.
	(dwarf_expr_fetch): Change return value to ULONGEST.
	(dwarf_expr_fetch_address): New function.
	(add_piece): Use dwarf_expr_fetch_address instead of dwarf_expr_fetch
	when appropriate.  Update for struct dwarf_expr_piece changes.
	(dwarf2_read_address): Remove.
	(unsigned_address_type): Remove.
	(signed_address_type): Remove.
	(execute_stack_op): Use dwarf_expr_fetch_address instead of
	dwarf_expr_fetch when appropriate.  Use ULONGEST as type of stack
	values.  Perform operations on ULONGEST instead of on GDB values,
	sign-extending from ctx->addr_size bytes as needed.  Read DW_OP_addr
	values and DW_OP_deref results as unsigned integers.
	* dwarf2loc.c (read_pieced_value): Update for struct dwarf_expr_piece
	changes.
	(write_pieced_value): Likewise.
	(dwarf2_evaluate_loc_desc): Use dwarf_expr_fetch_address instead of
	dwarf_expr_fetch when appropriate.
	(compile_dwarf_to_ax): Read DW_OP_addr values as unsigned integers.
	* dwarf2-frame.c (execute_stack_op): Use dwarf_expr_fetch_address
	instead of dwarf_expr_fetch when appropriate.

testsuite/ChangeLog:

	* gdb.cell/dwarfaddr.exp: New file.
	* gdb.cell/dwarfaddr.S: New file.


Index: gdb/dwarf2-frame.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2-frame.c,v
retrieving revision 1.112
diff -u -p -r1.112 dwarf2-frame.c
--- gdb/dwarf2-frame.c	7 Jun 2010 19:55:33 -0000	1.112
+++ gdb/dwarf2-frame.c	23 Jun 2010 19:01:01 -0000
@@ -391,11 +391,12 @@ execute_stack_op (const gdb_byte *exp, U
 
   dwarf_expr_push (ctx, initial, initial_in_stack_memory);
   dwarf_expr_eval (ctx, exp, len);
-  result = dwarf_expr_fetch (ctx, 0);
 
-  if (ctx->location == DWARF_VALUE_REGISTER)
-    result = read_reg (this_frame, result);
-  else if (ctx->location != DWARF_VALUE_MEMORY)
+  if (ctx->location == DWARF_VALUE_MEMORY)
+    result = dwarf_expr_fetch_address (ctx, 0);
+  else if (ctx->location == DWARF_VALUE_REGISTER)
+    result = read_reg (this_frame, dwarf_expr_fetch (ctx, 0));
+  else
     {
       /* This is actually invalid DWARF, but if we ever do run across
 	 it somehow, we might as well support it.  So, instead, report
Index: gdb/dwarf2expr.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2expr.c,v
retrieving revision 1.47
diff -u -p -r1.47 dwarf2expr.c
--- gdb/dwarf2expr.c	11 Jun 2010 15:21:11 -0000	1.47
+++ gdb/dwarf2expr.c	23 Jun 2010 19:01:01 -0000
@@ -33,7 +33,6 @@
 
 static void execute_stack_op (struct dwarf_expr_context *,
 			      const gdb_byte *, const gdb_byte *);
-static struct type *unsigned_address_type (struct gdbarch *, int);
 
 /* Create a new context for the expression evaluator.  */
 
@@ -98,11 +97,16 @@ dwarf_expr_grow_stack (struct dwarf_expr
 /* Push VALUE onto CTX's stack.  */
 
 void
-dwarf_expr_push (struct dwarf_expr_context *ctx, CORE_ADDR value,
+dwarf_expr_push (struct dwarf_expr_context *ctx, ULONGEST value,
 		 int in_stack_memory)
 {
   struct dwarf_stack_value *v;
 
+  /* We keep all stack elements within the range defined by the
+     DWARF address size.  */
+  if (ctx->addr_size < sizeof (ULONGEST))
+    value &= ((ULONGEST) 1 << (ctx->addr_size * HOST_CHAR_BIT)) - 1;
+
   dwarf_expr_grow_stack (ctx, 1);
   v = &ctx->stack[ctx->stack_len++];
   v->value = value;
@@ -121,7 +125,7 @@ dwarf_expr_pop (struct dwarf_expr_contex
 
 /* Retrieve the N'th item on CTX's stack.  */
 
-CORE_ADDR
+ULONGEST
 dwarf_expr_fetch (struct dwarf_expr_context *ctx, int n)
 {
   if (ctx->stack_len <= n)
@@ -131,6 +135,48 @@ dwarf_expr_fetch (struct dwarf_expr_cont
 
 }
 
+/* Retrieve the N'th item on CTX's stack, converted to an address.  */
+
+CORE_ADDR
+dwarf_expr_fetch_address (struct dwarf_expr_context *ctx, int n)
+{
+  ULONGEST result = dwarf_expr_fetch (ctx, n);
+
+  /* For most architectures, calling extract_unsigned_integer() alone
+     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.  Make sure we invoke gdbarch_integer_to_address()
+     for those architectures which require it.  */
+  if (gdbarch_integer_to_address_p (ctx->gdbarch))
+    {
+      enum bfd_endian byte_order = gdbarch_byte_order (ctx->gdbarch);
+      gdb_byte *buf = alloca (ctx->addr_size);
+      struct type *int_type;
+
+      switch (ctx->addr_size)
+	{
+	case 2:
+	  int_type = builtin_type (ctx->gdbarch)->builtin_uint16;
+	  break;
+	case 4:
+	  int_type = builtin_type (ctx->gdbarch)->builtin_uint32;
+	  break;
+	case 8:
+	  int_type = builtin_type (ctx->gdbarch)->builtin_uint64;
+	  break;
+	default:
+	  internal_error (__FILE__, __LINE__,
+			  _("Unsupported address size.\n"));
+	}
+
+      store_unsigned_integer (buf, ctx->addr_size, byte_order, result);
+      return gdbarch_integer_to_address (ctx->gdbarch, int_type, buf);
+    }
+
+  return (CORE_ADDR) result;
+}
+
 /* Retrieve the in_stack_memory flag of the N'th item on CTX's stack.  */
 
 int
@@ -182,10 +228,14 @@ add_piece (struct dwarf_expr_context *ct
 	 cases in the evaluator.  */
       ctx->location = DWARF_VALUE_OPTIMIZED_OUT;
     }
+  else if (p->location == DWARF_VALUE_MEMORY)
+    {
+      p->v.mem.addr = dwarf_expr_fetch_address (ctx, 0);
+      p->v.mem.in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
+    }
   else
     {
-      p->v.expr.value = dwarf_expr_fetch (ctx, 0);
-      p->v.expr.in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
+      p->v.value = dwarf_expr_fetch (ctx, 0);
     }
 }
 
@@ -259,76 +309,6 @@ read_sleb128 (const gdb_byte *buf, const
   *r = result;
   return buf;
 }
-
-/* Read an address of size ADDR_SIZE from BUF, and verify that it
-   doesn't extend past BUF_END.  */
-
-CORE_ADDR
-dwarf2_read_address (struct gdbarch *gdbarch, const gdb_byte *buf,
-		     const gdb_byte *buf_end, int addr_size)
-{
-  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-
-  if (buf_end - buf < addr_size)
-    error (_("dwarf2_read_address: Corrupted DWARF expression."));
-
-  /* For most architectures, calling extract_unsigned_integer() alone
-     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.  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.  */
-
-  if (gdbarch_integer_to_address_p (gdbarch))
-    return gdbarch_integer_to_address
-	     (gdbarch, unsigned_address_type (gdbarch, addr_size), buf);
-
-  return extract_unsigned_integer (buf, addr_size, byte_order);
-}
-
-/* Return the type of an address of size ADDR_SIZE,
-   for unsigned arithmetic.  */
-
-static struct type *
-unsigned_address_type (struct gdbarch *gdbarch, int addr_size)
-{
-  switch (addr_size)
-    {
-    case 2:
-      return builtin_type (gdbarch)->builtin_uint16;
-    case 4:
-      return builtin_type (gdbarch)->builtin_uint32;
-    case 8:
-      return builtin_type (gdbarch)->builtin_uint64;
-    default:
-      internal_error (__FILE__, __LINE__,
-		      _("Unsupported address size.\n"));
-    }
-}
-
-/* Return the type of an address of size ADDR_SIZE,
-   for signed arithmetic.  */
-
-static struct type *
-signed_address_type (struct gdbarch *gdbarch, int addr_size)
-{
-  switch (addr_size)
-    {
-    case 2:
-      return builtin_type (gdbarch)->builtin_int16;
-    case 4:
-      return builtin_type (gdbarch)->builtin_int32;
-    case 8:
-      return builtin_type (gdbarch)->builtin_int64;
-    default:
-      internal_error (__FILE__, __LINE__,
-		      _("Unsupported address size.\n"));
-    }
-}
 
 
 /* Check that the current operator is either at the end of an
@@ -355,6 +335,9 @@ static void
 execute_stack_op (struct dwarf_expr_context *ctx,
 		  const gdb_byte *op_ptr, const gdb_byte *op_end)
 {
+  #define sign_ext(x) ((LONGEST) (((x) ^ sign_bit) - sign_bit))
+  ULONGEST sign_bit = (ctx->addr_size >= sizeof (ULONGEST) ? 0
+		       : ((ULONGEST) 1) << (ctx->addr_size * 8 - 1));
   enum bfd_endian byte_order = gdbarch_byte_order (ctx->gdbarch);
 
   ctx->location = DWARF_VALUE_MEMORY;
@@ -368,7 +351,7 @@ execute_stack_op (struct dwarf_expr_cont
   while (op_ptr < op_end)
     {
       enum dwarf_location_atom op = *op_ptr++;
-      CORE_ADDR result;
+      ULONGEST result;
       /* Assume the value is not in stack memory.
 	 Code that knows otherwise sets this to 1.
 	 Some arithmetic on stack addresses can probably be assumed to still
@@ -417,8 +400,8 @@ execute_stack_op (struct dwarf_expr_cont
 	  break;
 
 	case DW_OP_addr:
-	  result = dwarf2_read_address (ctx->gdbarch,
-					op_ptr, op_end, ctx->addr_size);
+	  result = extract_unsigned_integer (op_ptr,
+					     ctx->addr_size, byte_order);
 	  op_ptr += ctx->addr_size;
 	  break;
 
@@ -601,12 +584,12 @@ execute_stack_op (struct dwarf_expr_cont
                specific this_base method.  */
 	    (ctx->get_frame_base) (ctx->baton, &datastart, &datalen);
 	    dwarf_expr_eval (ctx, datastart, datalen);
-	    if (ctx->location == DWARF_VALUE_LITERAL
-		|| ctx->location == DWARF_VALUE_STACK)
+	    if (ctx->location == DWARF_VALUE_MEMORY)
+	      result = dwarf_expr_fetch_address (ctx, 0);
+	    else if (ctx->location == DWARF_VALUE_REGISTER)
+	      result = (ctx->read_reg) (ctx->baton, dwarf_expr_fetch (ctx, 0));
+	    else
 	      error (_("Not implemented: computing frame base using explicit value operator"));
-	    result = dwarf_expr_fetch (ctx, 0);
-	    if (ctx->location == DWARF_VALUE_REGISTER)
-	      result = (ctx->read_reg) (ctx->baton, result);
 	    result = result + offset;
 	    in_stack_memory = 1;
 	    ctx->stack_len = before_stack_len;
@@ -666,6 +649,17 @@ execute_stack_op (struct dwarf_expr_cont
 
 	case DW_OP_deref:
 	case DW_OP_deref_size:
+	  {
+	    int addr_size = (op == DW_OP_deref ? ctx->addr_size : *op_ptr++);
+	    gdb_byte *buf = alloca (addr_size);
+	    CORE_ADDR addr = dwarf_expr_fetch_address (ctx, 0);
+	    dwarf_expr_pop (ctx);
+
+	    (ctx->read_mem) (ctx->baton, buf, addr, addr_size);
+	    result = extract_unsigned_integer (buf, addr_size, byte_order);
+	    break;
+	  }
+
 	case DW_OP_abs:
 	case DW_OP_neg:
 	case DW_OP_not:
@@ -676,31 +670,8 @@ execute_stack_op (struct dwarf_expr_cont
 
 	  switch (op)
 	    {
-	    case DW_OP_deref:
-	      {
-		gdb_byte *buf = alloca (ctx->addr_size);
-
-		(ctx->read_mem) (ctx->baton, buf, result, ctx->addr_size);
-		result = dwarf2_read_address (ctx->gdbarch,
-					      buf, buf + ctx->addr_size,
-					      ctx->addr_size);
-	      }
-	      break;
-
-	    case DW_OP_deref_size:
-	      {
-		int addr_size = *op_ptr++;
-		gdb_byte *buf = alloca (addr_size);
-
-		(ctx->read_mem) (ctx->baton, buf, result, addr_size);
-		result = dwarf2_read_address (ctx->gdbarch,
-					      buf, buf + addr_size,
-					      addr_size);
-	      }
-	      break;
-
 	    case DW_OP_abs:
-	      if ((signed int) result < 0)
+	      if (sign_ext (result) < 0)
 		result = -result;
 	      break;
 	    case DW_OP_neg:
@@ -734,12 +705,8 @@ execute_stack_op (struct dwarf_expr_cont
 	case DW_OP_gt:
 	case DW_OP_ne:
 	  {
-	    /* Binary operations.  Use the value engine to do computations in
-	       the right width.  */
-	    CORE_ADDR first, second;
-	    enum exp_opcode binop;
-	    struct value *val1 = NULL, *val2 = NULL;
-	    struct type *stype, *utype;
+	    /* Binary operations.  */
+	    ULONGEST first, second;
 
 	    second = dwarf_expr_fetch (ctx, 0);
 	    dwarf_expr_pop (ctx);
@@ -747,89 +714,67 @@ execute_stack_op (struct dwarf_expr_cont
 	    first = dwarf_expr_fetch (ctx, 0);
 	    dwarf_expr_pop (ctx);
 
-	    utype = unsigned_address_type (ctx->gdbarch, ctx->addr_size);
-	    stype = signed_address_type (ctx->gdbarch, ctx->addr_size);
-
 	    switch (op)
 	      {
 	      case DW_OP_and:
-		binop = BINOP_BITWISE_AND;
+		result = first & second;
 		break;
 	      case DW_OP_div:
-		binop = BINOP_DIV;
-		val1 = value_from_longest (stype, first);
-		val2 = value_from_longest (stype, second);
+		if (!second)
+		  error (_("Division by zero"));
+		result = sign_ext (first) / sign_ext (second);
                 break;
 	      case DW_OP_minus:
-		binop = BINOP_SUB;
+		result = first - second;
 		break;
 	      case DW_OP_mod:
-		binop = BINOP_MOD;
+		if (!second)
+		  error (_("Division by zero"));
+		result = first % second;
 		break;
 	      case DW_OP_mul:
-		binop = BINOP_MUL;
+		result = first * second;
 		break;
 	      case DW_OP_or:
-		binop = BINOP_BITWISE_IOR;
+		result = first | second;
 		break;
 	      case DW_OP_plus:
-		binop = BINOP_ADD;
+		result = first + second;
 		break;
 	      case DW_OP_shl:
-		binop = BINOP_LSH;
+		result = first << second;
 		break;
 	      case DW_OP_shr:
-		binop = BINOP_RSH;
+		result = first >> second;
                 break;
 	      case DW_OP_shra:
-		binop = BINOP_RSH;
-		val1 = value_from_longest (stype, first);
+		result = sign_ext (first) >> second;
 		break;
 	      case DW_OP_xor:
-		binop = BINOP_BITWISE_XOR;
+		result = first ^ second;
 		break;
 	      case DW_OP_le:
-		binop = BINOP_LEQ;
-		val1 = value_from_longest (stype, first);
-		val2 = value_from_longest (stype, second);
+		result = sign_ext (first) <= sign_ext (second);
 		break;
 	      case DW_OP_ge:
-		binop = BINOP_GEQ;
-		val1 = value_from_longest (stype, first);
-		val2 = value_from_longest (stype, second);
+		result = sign_ext (first) >= sign_ext (second);
 		break;
 	      case DW_OP_eq:
-		binop = BINOP_EQUAL;
-		val1 = value_from_longest (stype, first);
-		val2 = value_from_longest (stype, second);
+		result = sign_ext (first) == sign_ext (second);
 		break;
 	      case DW_OP_lt:
-		binop = BINOP_LESS;
-		val1 = value_from_longest (stype, first);
-		val2 = value_from_longest (stype, second);
+		result = sign_ext (first) < sign_ext (second);
 		break;
 	      case DW_OP_gt:
-		binop = BINOP_GTR;
-		val1 = value_from_longest (stype, first);
-		val2 = value_from_longest (stype, second);
+		result = sign_ext (first) > sign_ext (second);
 		break;
 	      case DW_OP_ne:
-		binop = BINOP_NOTEQUAL;
-		val1 = value_from_longest (stype, first);
-		val2 = value_from_longest (stype, second);
+		result = sign_ext (first) != sign_ext (second);
 		break;
 	      default:
 		internal_error (__FILE__, __LINE__,
 				_("Can't be reached."));
 	      }
-
-	    /* We use unsigned operands by default.  */
-	    if (val1 == NULL)
-	      val1 = value_from_longest (utype, first);
-	    if (val2 == NULL)
-	      val2 = value_from_longest (utype, second);
-
-	    result = value_as_long (value_binop (val1, val2, binop));
 	  }
 	  break;
 
@@ -935,4 +880,5 @@ execute_stack_op (struct dwarf_expr_cont
 
   ctx->recursion_depth--;
   gdb_assert (ctx->recursion_depth >= 0);
+  #undef sign_ext
 }
Index: gdb/dwarf2expr.h
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2expr.h,v
retrieving revision 1.26
diff -u -p -r1.26 dwarf2expr.h
--- gdb/dwarf2expr.h	11 Jun 2010 15:21:11 -0000	1.26
+++ gdb/dwarf2expr.h	23 Jun 2010 19:01:01 -0000
@@ -48,7 +48,7 @@ enum dwarf_value_location
 
 struct dwarf_stack_value
 {
-  CORE_ADDR value;
+  ULONGEST value;
 
   /* Non-zero if the piece is in memory and is known to be
      on the program's stack.  It is always ok to set this to zero.
@@ -163,17 +163,21 @@ struct dwarf_expr_piece
   {
     struct
     {
-      /* This piece's address or register number.  */
-      CORE_ADDR value;
+      /* This piece's address, for DWARF_VALUE_MEMORY pieces.  */
+      CORE_ADDR addr;
       /* Non-zero if the piece is known to be in memory and on
 	 the program's stack.  */
       int in_stack_memory;
-    } expr;
+    } mem;
+
+    /* The piece's register number or literal value, for
+       DWARF_VALUE_REGISTER or DWARF_VALUE_STACK pieces.  */
+    ULONGEST value;
 
     struct
     {
-      /* A pointer to the data making up this piece, for literal
-	 pieces.  */
+      /* A pointer to the data making up this piece,
+	 for DWARF_VALUE_LITERAL pieces.  */
       const gdb_byte *data;
       /* The length of the available data.  */
       ULONGEST length;
@@ -191,12 +195,13 @@ void free_dwarf_expr_context (struct dwa
 struct cleanup *
     make_cleanup_free_dwarf_expr_context (struct dwarf_expr_context *ctx);
 
-void dwarf_expr_push (struct dwarf_expr_context *ctx, CORE_ADDR value,
+void dwarf_expr_push (struct dwarf_expr_context *ctx, ULONGEST value,
 		      int in_stack_memory);
 void dwarf_expr_pop (struct dwarf_expr_context *ctx);
 void dwarf_expr_eval (struct dwarf_expr_context *ctx, const gdb_byte *addr,
 		      size_t len);
-CORE_ADDR dwarf_expr_fetch (struct dwarf_expr_context *ctx, int n);
+ULONGEST dwarf_expr_fetch (struct dwarf_expr_context *ctx, int n);
+CORE_ADDR dwarf_expr_fetch_address (struct dwarf_expr_context *ctx, int n);
 int dwarf_expr_fetch_in_stack_memory (struct dwarf_expr_context *ctx, int n);
 
 
@@ -204,8 +209,6 @@ const gdb_byte *read_uleb128 (const gdb_
 			      ULONGEST * r);
 const gdb_byte *read_sleb128 (const gdb_byte *buf, const gdb_byte *buf_end,
 			      LONGEST * r);
-CORE_ADDR dwarf2_read_address (struct gdbarch *gdbarch, const gdb_byte *buf,
-			       const gdb_byte *buf_end, int addr_size);
 
 const char *dwarf_stack_op_name (unsigned int, int);
 
Index: gdb/dwarf2loc.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2loc.c,v
retrieving revision 1.91
diff -u -p -r1.91 dwarf2loc.c
--- gdb/dwarf2loc.c	21 Jun 2010 16:50:18 -0000	1.91
+++ gdb/dwarf2loc.c	23 Jun 2010 19:01:01 -0000
@@ -548,8 +548,7 @@ read_pieced_value (struct value *v)
 	case DWARF_VALUE_REGISTER:
 	  {
 	    struct gdbarch *arch = get_frame_arch (frame);
-	    int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch,
-							   p->v.expr.value);
+	    int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, p->v.value);
 	    int reg_offset = source_offset;
 
 	    if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
@@ -570,16 +569,16 @@ read_pieced_value (struct value *v)
 	    else
 	      {
 		error (_("Unable to access DWARF register number %s"),
-		       paddress (arch, p->v.expr.value));
+		       paddress (arch, p->v.value));
 	      }
 	  }
 	  break;
 
 	case DWARF_VALUE_MEMORY:
-	  if (p->v.expr.in_stack_memory)
-	    read_stack (p->v.expr.value + source_offset, buffer, this_size);
+	  if (p->v.mem.in_stack_memory)
+	    read_stack (p->v.mem.addr + source_offset, buffer, this_size);
 	  else
-	    read_memory (p->v.expr.value + source_offset, buffer, this_size);
+	    read_memory (p->v.mem.addr + source_offset, buffer, this_size);
 	  break;
 
 	case DWARF_VALUE_STACK:
@@ -598,14 +597,14 @@ read_pieced_value (struct value *v)
 	    else if (source_offset == 0)
 	      store_unsigned_integer (buffer, n,
 				      gdbarch_byte_order (gdbarch),
-				      p->v.expr.value);
+				      p->v.value);
 	    else
 	      {
 		gdb_byte bytes[sizeof (ULONGEST)];
 
 		store_unsigned_integer (bytes, n + source_offset,
 					gdbarch_byte_order (gdbarch),
-					p->v.expr.value);
+					p->v.value);
 		memcpy (buffer, bytes + source_offset, n);
 	      }
 	  }
@@ -730,7 +729,7 @@ write_pieced_value (struct value *to, st
 	case DWARF_VALUE_REGISTER:
 	  {
 	    struct gdbarch *arch = get_frame_arch (frame);
-	    int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, p->v.expr.value);
+	    int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, p->v.value);
 	    int reg_offset = dest_offset;
 
 	    if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
@@ -756,7 +755,7 @@ write_pieced_value (struct value *to, st
 	    else
 	      {
 		error (_("Unable to write to DWARF register number %s"),
-		       paddress (arch, p->v.expr.value));
+		       paddress (arch, p->v.value));
 	      }
 	  }
 	  break;
@@ -765,8 +764,8 @@ write_pieced_value (struct value *to, st
 	    {
 	      /* Only the first and last bytes can possibly have any
 		 bits reused.  */
-	      read_memory (p->v.expr.value + dest_offset, buffer, 1);
-	      read_memory (p->v.expr.value + dest_offset + this_size - 1,
+	      read_memory (p->v.mem.addr + dest_offset, buffer, 1);
+	      read_memory (p->v.mem.addr + dest_offset + this_size - 1,
 			   buffer + this_size - 1, 1);
 	      copy_bitwise (buffer, dest_offset_bits,
 			    contents, source_offset_bits,
@@ -774,7 +773,7 @@ write_pieced_value (struct value *to, st
 			    bits_big_endian);
 	    }
 
-	  write_memory (p->v.expr.value + dest_offset,
+	  write_memory (p->v.mem.addr + dest_offset,
 			source_buffer, this_size);
 	  break;
 	default:
@@ -935,7 +934,7 @@ dwarf2_evaluate_loc_desc (struct type *t
 	case DWARF_VALUE_REGISTER:
 	  {
 	    struct gdbarch *arch = get_frame_arch (frame);
-	    CORE_ADDR dwarf_regnum = dwarf_expr_fetch (ctx, 0);
+	    ULONGEST dwarf_regnum = dwarf_expr_fetch (ctx, 0);
 	    int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, dwarf_regnum);
 
 	    if (gdb_regnum != -1)
@@ -948,7 +947,7 @@ dwarf2_evaluate_loc_desc (struct type *t
 
 	case DWARF_VALUE_MEMORY:
 	  {
-	    CORE_ADDR address = dwarf_expr_fetch (ctx, 0);
+	    CORE_ADDR address = dwarf_expr_fetch_address (ctx, 0);
 	    int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
 
 	    retval = allocate_value (type);
@@ -962,7 +961,7 @@ dwarf2_evaluate_loc_desc (struct type *t
 
 	case DWARF_VALUE_STACK:
 	  {
-	    ULONGEST value = (ULONGEST) dwarf_expr_fetch (ctx, 0);
+	    ULONGEST value = dwarf_expr_fetch (ctx, 0);
 	    bfd_byte *contents;
 	    size_t n = ctx->addr_size;
 
@@ -1233,7 +1232,6 @@ compile_dwarf_to_ax (struct agent_expr *
   while (op_ptr < op_end)
     {
       enum dwarf_location_atom op = *op_ptr;
-      CORE_ADDR result;
       ULONGEST uoffset, reg;
       LONGEST offset;
       int i;
@@ -1295,8 +1293,8 @@ compile_dwarf_to_ax (struct agent_expr *
 	  break;
 
 	case DW_OP_addr:
-	  result = dwarf2_read_address (arch, op_ptr, op_end, addr_size);
-	  ax_const_l (expr, result);
+	  ax_const_l (expr, extract_unsigned_integer (op_ptr,
+						      addr_size, byte_order));
 	  op_ptr += addr_size;
 	  break;
 
--- /dev/null	2010-06-09 19:31:28.423437333 +0200
+++ gdb/testsuite/gdb.cell/dwarfaddr.exp	2010-06-23 20:58:28.000000000 +0200
@@ -0,0 +1,53 @@
+# Copyright 2010 Free Software Foundation, Inc.
+#
+# 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 3 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, see <http://www.gnu.org/licenses/>.
+#
+# This file is part of the gdb testsuite.
+#
+# Contributed by Ulrich Weigand  <uweigand@de.ibm.com>.
+# Tests for SPU addresses resulting from complex DWARF expressions.
+
+load_lib cell.exp
+
+set testfile "dwarfaddr"
+set srcfile ${srcdir}/${subdir}/${testfile}.S
+set binary ${objdir}/${subdir}/${testfile}
+
+if {[skip_cell_tests]} {
+    return 0
+}
+
+# Compile SPU binary.
+if { [gdb_compile_cell_spu $srcfile $binary executable {debug}]  != "" } {
+  unsupported "Compiling spu binary failed."
+  return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binary}
+
+if ![runto_main] then {
+  fail "Can't run to main"
+  return 0
+}
+
+gdb_test "print x" " = \\{0 <repeats 16 times>\\}" "print x"
+gdb_test "print &x" " = \\(int \\(\\*\\)\\\[16\\\]\\) 0x\[0-9a-f\]*" "print &x"
+gdb_test "info address x" "Symbol \"x\" is a complex DWARF expression.*DW_OP_and\[\r\n\]+\." "info address x"
+
+gdb_exit
+
+return 0
--- /dev/null	2010-06-09 19:31:28.423437333 +0200
+++ gdb/testsuite/gdb.cell/dwarfaddr.S	2010-06-23 20:24:40.000000000 +0200
@@ -0,0 +1,190 @@
+/* Copyright 2010 Free Software Foundation, Inc.
+
+   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 3 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, see <http://www.gnu.org/licenses/>.
+
+   This file is part of the gdb testsuite.
+
+   Contributed by Ulrich Weigand <uweigand@de.ibm.com>.
+   Tests for SPU addresses resulting from complex DWARF expressions.  */
+
+	.text
+main:
+.Ltext_s:
+.LFB1:
+	stqd        $1,-240($1)
+	ai          $1,$1,-240
+	ai          $2,$1,32
+	ai          $2,$2,127
+	il          $3,127
+	andc        $3,$2,$3
+	il          $2,1
+	lqd         $4,0($3)
+	cwd         $5,0($3)
+	shufb       $2,$2,$4,$5
+	stqd        $2,0($3)
+	lqd         $1,0($1)
+	bi          $0
+.LFE1:
+	.global main
+	.type	main,@function
+	.size	main,.LFE1-.LFB1
+.Ltext_e:
+
+	.section	.debug_info,"",@progbits
+.Ldebug_info_s:
+	.int	.debug_info_size-4
+	.short	0x2
+	.int	.Ldebug_abbrev_s
+	.byte	0x4
+.Ldie0:
+	.uleb128	0x1
+	.string	"test.c"
+	.int	.Ltext_s
+	.int	.Ltext_e
+	.byte	0x1
+.Ldie1:
+	.uleb128	0x2
+	.string	"int"
+	.byte	0x4
+	.byte	0x5
+.Ldie2:
+	.uleb128	0x3
+	.int	.Ldie4-.Ldebug_info_s
+	.int	.Ldie1-.Ldebug_info_s
+.Ldie3:
+	.uleb128	0x4
+	.byte	0
+	.byte	0xf
+	.uleb128	0
+.Ldie4:
+	.uleb128	0x5
+	.string	"main"
+	.int	.LFB1
+	.int	.LFE1
+	.byte	0x1
+	.byte	0x1
+	.byte	0x3
+	.byte	0x1
+	.byte	0x1
+	.byte	0x51
+.Ldie5:
+	.uleb128	0x6
+	.byte	0xe
+	.byte	0x91
+	.sleb128	0x20
+	.byte	0xd
+	.int	0x7f
+	.byte	0x22
+	.byte	0xd
+	.int	0xffffff80
+	.byte	0x1a
+	.string	"x"
+	.byte	0x1
+	.byte	0
+	.int	.Ldie2-.Ldebug_info_s
+	.uleb128	0
+	.uleb128	0
+.Ldebug_info_e:
+	.set	.debug_info_size,.Ldebug_info_e-.Ldebug_info_s
+
+
+	.section	.debug_abbrev,"",@progbits
+.Ldebug_abbrev_s:
+	.uleb128	0x1
+	.uleb128	0x11
+	.byte	0x1
+	.uleb128	0x3
+	.uleb128	0x8
+	.uleb128	0x11
+	.uleb128	0x1
+	.uleb128	0x12
+	.uleb128	0x1
+	.uleb128	0x13
+	.uleb128	0xb
+	.uleb128	0
+	.uleb128	0
+
+	.uleb128	0x2
+	.uleb128	0x24
+	.byte	0
+	.uleb128	0x3
+	.uleb128	0x8
+	.uleb128	0xb
+	.uleb128	0xb
+	.uleb128	0x3e
+	.uleb128	0xb
+	.uleb128	0
+	.uleb128	0
+
+	.uleb128	0x3
+	.uleb128	0x1
+	.byte	0x1
+	.uleb128	0x1
+	.uleb128	0x13
+	.uleb128	0x49
+	.uleb128	0x13
+	.uleb128	0
+	.uleb128	0
+
+	.uleb128	0x4
+	.uleb128	0x21
+	.byte	0
+	.uleb128	0x22
+	.uleb128	0xb
+	.uleb128	0x2f
+	.uleb128	0xb
+	.uleb128	0
+	.uleb128	0
+
+	.uleb128	0x5
+	.uleb128	0x2e
+	.byte	0x1
+	.uleb128	0x3
+	.uleb128	0x8
+	.uleb128	0x11
+	.uleb128	0x1
+	.uleb128	0x12
+	.uleb128	0x1
+	.uleb128	0x27
+	.uleb128	0xc
+	.uleb128	0x3a
+	.uleb128	0xb
+	.uleb128	0x3b
+	.uleb128	0xb
+	.uleb128	0x3f
+	.uleb128	0xc
+	.uleb128	0x40
+	.uleb128	0xa
+	.uleb128	0
+	.uleb128	0
+
+	.uleb128	0x6
+	.uleb128	0x34
+	.byte	0
+	.uleb128	0x2
+	.uleb128	0xa
+	.uleb128	0x3
+	.uleb128	0x8
+	.uleb128	0x3a
+	.uleb128	0xb
+	.uleb128	0x3b
+	.uleb128	0xb
+	.uleb128	0x49
+	.uleb128	0x13
+	.uleb128	0
+	.uleb128	0
+	.uleb128	0
+.Ldebug_abbrev_e:
+	.set	.debug_abbrev_size,.Ldebug_abbrev_e-.Ldebug_abbrev_s
+
-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]