+/* 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
+dwarf_expr_fetch_in_stack_memory (struct dwarf_expr_context *ctx, int n)
+{
+ if (ctx->stack_len <= n)
+ error (_("Asked for position %d of stack, stack only has %d elements on it."),
+ n, ctx->stack_len);
+ return ctx->stack[ctx->stack_len - (1 + n)].in_stack_memory;
+
+}
+
+/* Return true if the expression stack is empty. */
+
+static int
+dwarf_expr_stack_empty_p (struct dwarf_expr_context *ctx)
+{
+ return ctx->stack_len == 0;
+}
+