This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[unavailable values part 1, 11/17] unavailable (C++) references
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 7 Feb 2011 14:32:58 +0000
- Subject: [unavailable values part 1, 11/17] unavailable (C++) references
With:
int anint;
int &ref = anint;
where neither of the variables is collected:
Before:
(gdb) p anint
$3 = <unavailable>
(gdb) p ref
$4 = (int &) @0x601094: <error reading variable>
After:
(gdb) p anint
$3 = <unavailable>
(gdb) p ref
$4 = (int &) @0x601094: <unavailable>
The error is thrown from within read_memory. The fix
it to use value_fetch_lazy instead, which handles all
the unvailable-ness gracefully.
With a "foo3" being a pointer into a struct like so:
struct foo3_s
{
foo3_s (unsigned int val) : ref(this->d) {}
unsigned int d;
unsigned int &ref;
};
If you collect "foo3->ref":
(gdb) p foo3
$8 = (foo3_s *) 0x615a00
(gdb) p *foo3
$9 = {d = <unavailable>, ref = @0x615a00}
(GDB auto-collects "foo3")
(gdb) p foo3->ref
$5 = (unsigned int &) @0x615a00: <unavailable>
(gdb) p &foo3->ref
$2 = (unsigned int *) 0x615a00
(gdb) p *&foo3->ref
$6 = <unavailable>
(gdb) p foo3->ref + 1
value is not available
If you only collect "foo3":
$2 = {d = <unavailable>, ref = <unavailable>}
(gdb) p foo3->ref
$3 = (unsigned int &) <unavailable>
(gdb) p foo3->ref + 1
value is not available
(gdb) p &foo3->ref
$2 = (unsigned int *) <unavailable>
(gdb) p *&foo3->ref
value is not available
(Note that currently collecting a reference does
_not_ also automatically collect what the
reference points to...)
--
Pedro Alves
2011-02-07 Pedro Alves <pedro@codesourcery.com>
<unavailable> references.
gdb/
* valops.c (get_value_at): Use value_from_contents_and_address,
avoiding read_memory.
---
gdb/valops.c | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
Index: src/gdb/valops.c
===================================================================
--- src.orig/gdb/valops.c 2011-01-31 19:58:14.594644999 +0000
+++ src/gdb/valops.c 2011-01-31 20:00:39.374645003 +0000
@@ -917,18 +917,10 @@ get_value_at (struct type *type, CORE_AD
if (TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
error (_("Attempt to dereference a generic pointer."));
- if (lazy)
- {
- val = allocate_value_lazy (type);
- }
- else
- {
- val = allocate_value (type);
- read_memory (addr, value_contents_all_raw (val), TYPE_LENGTH (type));
- }
+ val = value_from_contents_and_address (type, NULL, addr);
- VALUE_LVAL (val) = lval_memory;
- set_value_address (val, addr);
+ if (!lazy)
+ value_fetch_lazy (val);
return val;
}