+2011-03-18 Pedro Alves <pedro@codesourcery.com>
+
+ * findvar.c (value_of_register): Mark the value as unavailable, if
+ the register is unavailable.
+ * frame.h (frame_register_unwind): New `unavailablep' parameter.
+ (frame_register): New `unavailablep' parameter.
+ (frame_register_read): Update comment.
+ * frame.c (frame_register_unwind): New `unavailablep' parameter.
+ Set it if the register is unavailable. If the register is
+ unavailable, clear the output buffer.
+ (frame_register): New `unavailablep' parameter. Pass it down.
+ (frame_unwind_register): Adjust.
+ (put_frame_register): Adjust.
+ (frame_register_read): Adjust. Also return false if the register
+ is not available.
+ (frame_register_unwind_location): Adjust.
+ * sentinel-frame.c (sentinel_frame_prev_register): If the register
+ is unavailable, mark the value accordingly.
+ * stack.c (frame_info): Handle unavailable registers.
+
2011-03-18 Pedro Alves <pedro@codesourcery.com>
* mi/mi-main.c (register_changed_p): Handle REG_UNAVAILABLE, and
struct gdbarch *gdbarch = get_frame_arch (frame);
CORE_ADDR addr;
int optim;
+ int unavail;
struct value *reg_val;
int realnum;
gdb_byte raw_buffer[MAX_REGISTER_SIZE];
+ gdbarch_num_pseudo_regs (gdbarch))
return value_of_user_reg (regnum, frame);
- frame_register (frame, regnum, &optim, &lval, &addr, &realnum, raw_buffer);
+ frame_register (frame, regnum, &optim, &unavail,
+ &lval, &addr, &realnum, raw_buffer);
reg_val = allocate_value (register_type (gdbarch, regnum));
- memcpy (value_contents_raw (reg_val), raw_buffer,
- register_size (gdbarch, regnum));
+ if (!optim && !unavail)
+ memcpy (value_contents_raw (reg_val), raw_buffer,
+ register_size (gdbarch, regnum));
+ else
+ memset (value_contents_raw (reg_val), 0,
+ register_size (gdbarch, regnum));
+
VALUE_LVAL (reg_val) = lval;
set_value_address (reg_val, addr);
VALUE_REGNUM (reg_val) = regnum;
set_value_optimized_out (reg_val, optim);
+ if (unavail)
+ mark_value_bytes_unavailable (reg_val, 0, register_size (gdbarch, regnum));
VALUE_FRAME_ID (reg_val) = get_frame_id (frame);
return reg_val;
}
void
frame_register_unwind (struct frame_info *frame, int regnum,
- int *optimizedp, enum lval_type *lvalp,
- CORE_ADDR *addrp, int *realnump, gdb_byte *bufferp)
+ int *optimizedp, int *unavailablep,
+ enum lval_type *lvalp, CORE_ADDR *addrp,
+ int *realnump, gdb_byte *bufferp)
{
struct value *value;
gdb_assert (value != NULL);
*optimizedp = value_optimized_out (value);
+ *unavailablep = !value_entirely_available (value);
*lvalp = VALUE_LVAL (value);
*addrp = value_address (value);
*realnump = VALUE_REGNUM (value);
- if (bufferp && !*optimizedp)
- memcpy (bufferp, value_contents_all (value),
- TYPE_LENGTH (value_type (value)));
+ if (bufferp)
+ {
+ if (!*optimizedp && !*unavailablep)
+ memcpy (bufferp, value_contents_all (value),
+ TYPE_LENGTH (value_type (value)));
+ else
+ memset (bufferp, 0, TYPE_LENGTH (value_type (value)));
+ }
/* Dispose of the new value. This prevents watchpoints from
trying to watch the saved frame pointer. */
void
frame_register (struct frame_info *frame, int regnum,
- int *optimizedp, enum lval_type *lvalp,
+ int *optimizedp, int *unavailablep, enum lval_type *lvalp,
CORE_ADDR *addrp, int *realnump, gdb_byte *bufferp)
{
/* Require all but BUFFERP to be valid. A NULL BUFFERP indicates
/* Obtain the register value by unwinding the register from the next
(more inner frame). */
gdb_assert (frame != NULL && frame->next != NULL);
- frame_register_unwind (frame->next, regnum, optimizedp, lvalp, addrp,
- realnump, bufferp);
+ frame_register_unwind (frame->next, regnum, optimizedp, unavailablep,
+ lvalp, addrp, realnump, bufferp);
}
void
frame_unwind_register (struct frame_info *frame, int regnum, gdb_byte *buf)
{
int optimized;
+ int unavailable;
CORE_ADDR addr;
int realnum;
enum lval_type lval;
- frame_register_unwind (frame, regnum, &optimized, &lval, &addr,
- &realnum, buf);
+ frame_register_unwind (frame, regnum, &optimized, &unavailable,
+ &lval, &addr, &realnum, buf);
}
void
struct gdbarch *gdbarch = get_frame_arch (frame);
int realnum;
int optim;
+ int unavail;
enum lval_type lval;
CORE_ADDR addr;
- frame_register (frame, regnum, &optim, &lval, &addr, &realnum, NULL);
+ frame_register (frame, regnum, &optim, &unavail,
+ &lval, &addr, &realnum, NULL);
if (optim)
error (_("Attempt to assign to a value that was optimized out."));
switch (lval)
gdb_byte *myaddr)
{
int optimized;
+ int unavailable;
enum lval_type lval;
CORE_ADDR addr;
int realnum;
- frame_register (frame, regnum, &optimized, &lval, &addr, &realnum, myaddr);
+ frame_register (frame, regnum, &optimized, &unavailable,
+ &lval, &addr, &realnum, myaddr);
- return !optimized;
+ return !optimized && !unavailable;
}
int
while (this_frame != NULL)
{
- frame_register_unwind (this_frame, regnum, optimizedp, lvalp,
- addrp, realnump, NULL);
+ int unavailable;
+
+ frame_register_unwind (this_frame, regnum, optimizedp, &unavailable,
+ lvalp, addrp, realnump, NULL);
if (*optimizedp)
break;
fetch/compute the value. Instead just return the location of the
value. */
extern void frame_register_unwind (struct frame_info *frame, int regnum,
- int *optimizedp, enum lval_type *lvalp,
+ int *optimizedp, int *unavailablep,
+ enum lval_type *lvalp,
CORE_ADDR *addrp, int *realnump,
gdb_byte *valuep);
VALUEP is NULL, the registers value is not fetched/computed. */
extern void frame_register (struct frame_info *frame, int regnum,
- int *optimizedp, enum lval_type *lvalp,
+ int *optimizedp, int *unavailablep,
+ enum lval_type *lvalp,
CORE_ADDR *addrp, int *realnump,
gdb_byte *valuep);
/* FIXME: cagney/2003-02-02: Should be deprecated or replaced with a
function called get_frame_register_p(). This slightly weird (and
older) variant of get_frame_register() returns zero (indicating the
- register is unavailable) if either: the register isn't cached; or
- the register has been optimized out. Problem is, neither check is
- exactly correct. A register can't be optimized out (it may not
- have been saved as part of a function call); The fact that a
- register isn't in the register cache doesn't mean that the register
- isn't available (it could have been fetched from memory). */
+ register value is unavailable/invalid) if either: the register
+ isn't cached; or the register has been optimized out; or the
+ register contents are unavailable (because they haven't been
+ collected in a traceframe). Problem is, neither check is exactly
+ correct. A register can't be optimized out (it may not have been
+ saved as part of a function call); The fact that a register isn't
+ in the register cache doesn't mean that the register isn't
+ available (it could have been fetched from memory). */
extern int frame_register_read (struct frame_info *frame, int regnum,
gdb_byte *buf);
/* Use the regcache_cooked_read() method so that it, on the fly,
constructs either a raw or pseudo register from the raw
register cache. */
- regcache_cooked_read (cache->regcache, regnum, value_contents_raw (value));
+ if (regcache_cooked_read (cache->regcache,
+ regnum,
+ value_contents_raw (value)) == REG_UNAVAILABLE)
+ mark_value_bytes_unavailable (value, 0, register_size (gdbarch, regnum));
return value;
}
{
enum lval_type lval;
int optimized;
+ int unavailable;
CORE_ADDR addr;
int realnum;
int count;
/* Find out the location of the saved stack pointer with out
actually evaluating it. */
frame_register_unwind (fi, gdbarch_sp_regnum (gdbarch),
- &optimized, &lval, &addr,
+ &optimized, &unavailable, &lval, &addr,
&realnum, NULL);
- if (!optimized && lval == not_lval)
+ if (!optimized && !unavailable && lval == not_lval)
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
int sp_size = register_size (gdbarch, gdbarch_sp_regnum (gdbarch));
CORE_ADDR sp;
frame_register_unwind (fi, gdbarch_sp_regnum (gdbarch),
- &optimized, &lval, &addr,
+ &optimized, &unavailable, &lval, &addr,
&realnum, value);
/* NOTE: cagney/2003-05-22: This is assuming that the
stack pointer was packed as an unsigned integer. That
printf_filtered ("\n");
need_nl = 0;
}
- else if (!optimized && lval == lval_memory)
+ else if (!optimized && !unavailable && lval == lval_memory)
{
printf_filtered (" Previous frame's sp at ");
fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
printf_filtered ("\n");
need_nl = 0;
}
- else if (!optimized && lval == lval_register)
+ else if (!optimized && !unavailable && lval == lval_register)
{
printf_filtered (" Previous frame's sp in %s\n",
gdbarch_register_name (gdbarch, realnum));
{
/* Find out the location of the saved register without
fetching the corresponding value. */
- frame_register_unwind (fi, i, &optimized, &lval, &addr, &realnum,
- NULL);
+ frame_register_unwind (fi, i, &optimized, &unavailable,
+ &lval, &addr, &realnum, NULL);
/* For moment, only display registers that were saved on the
stack. */
- if (!optimized && lval == lval_memory)
+ if (!optimized && !unavailable && lval == lval_memory)
{
if (count == 0)
puts_filtered (" Saved registers:\n ");
+2011-03-18 Pedro Alves <pedro@codesourcery.com>
+
+ * gdb.trace/unavailable.exp (fpreg, spreg, pcreg): Define.
+ (test_register, test_register_unavailable): New procedures.
+ (gdb_unavailable_registers_test): New procedure.
+ (gdb_trace_collection_test): Call it.
+
2011-03-18 Phil Muldoon <pmuldoon@redhat.com>
PR python/12149
set ws "\[\r\n\t \]+"
set cr "\[\r\n\]+"
+if [istarget "x86_64-*"] then {
+ set fpreg "rbp"
+ set spreg "rsp"
+ set pcreg "rip"
+} elseif [istarget "i?86-*"] then {
+ set fpreg "ebp"
+ set spreg "esp"
+ set pcreg "eip"
+} else {
+ set fpreg "fp"
+ set spreg "sp"
+ set pcreg "pc"
+}
+
#
# Utility procs
#
+proc test_register { reg } {
+ global gdb_prompt
+ global hex
+ global cr
+
+ gdb_test_multiple "print /x $reg" "collected $reg" {
+ -re "\\$\[0-9\]+ = \[x0\]+$cr$gdb_prompt $" {
+ fail "collected $reg (zero)"
+ }
+ -re "\\$\[0-9\]+ = $hex$cr$gdb_prompt $" {
+ pass "collected $reg"
+ }
+ -re "\[Ee\]rror.*$gdb_prompt $" {
+ fail "collected $reg (error)"
+ }
+ }
+}
+
+proc test_register_unavailable { reg } {
+ gdb_test "print /x $reg" \
+ "<unavailable>" \
+ "correctly report $reg as unavailable"
+}
+
proc prepare_for_trace_test {} {
global executable
# Test procs
#
+proc gdb_unavailable_registers_test { } {
+ global gdb_prompt
+ global spreg
+ global pcreg
+ global pf_prefix
+
+ set old_pf_prefix $pf_prefix
+ set pf_prefix "$pf_prefix unavailable registers:"
+
+ prepare_for_trace_test
+
+ # We'll simply re-use the globals_test_function for this test
+ gdb_test "trace globals_test_func" \
+ "Tracepoint \[0-9\]+ at .*" \
+ "set tracepoint"
+
+ # Collect nothing.
+
+ # Begin the test.
+ run_trace_experiment globals_test_func
+
+ # On some archs, the $sp/$pc are a real raw registers. On others,
+ # like x86, they're user registers. Test both variants.
+ test_register_unavailable "\$$spreg"
+ test_register_unavailable "\$sp"
+
+ # Test reading uncollected pseudo-registers. The set of which
+ # depends on target.
+ if [istarget "x86_64-*"] then {
+ # Check the raw register first.
+ test_register_unavailable "\$rax"
+ test_register_unavailable "\$eax"
+ test_register_unavailable "\$ax"
+ } elseif [istarget "i?86-*"] then {
+ # Check the raw register first.
+ test_register_unavailable "\$eax"
+ test_register_unavailable "\$ax"
+ }
+
+ # GDBserver always provides the PC value of regular tracepoint
+ # hits, since it's the same as the tracepoint's address.
+ test_register "\$$pcreg"
+ test_register "\$pc"
+
+ gdb_test "info registers" \
+ "\\*value not available\\*.*\\*value not available\\*" \
+ "info registers, multiple registers not available"
+
+ gdb_test "info registers \$$spreg" \
+ "\\*value not available\\*" \
+ "info registers \$$spreg reports not available"
+
+ gdb_test "tfind none" "#0 end .*" "cease trace debugging"
+
+ set pf_prefix $old_pf_prefix
+}
+
proc gdb_collect_globals_test { } {
global ws
global cr
proc gdb_trace_collection_test {} {
gdb_collect_globals_test
+ gdb_unavailable_registers_test
}
clean_restart $executable