This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: MI: type prefixes for values
- From: Vladimir Prus <ghost at cs dot msu dot su>
- To: gdb-patches at sources dot redhat dot com
- Date: Thu, 06 Apr 2006 12:42:03 +0400
- Subject: Re: MI: type prefixes for values
- References: <dt43qh$sns$1@sea.gmane.org> <17427.54333.236860.258115@kahikatea.snap.net.nz> <dvemrm$al0$1@sea.gmane.org> <20060317191207.GA19068@nevyn.them.org> <dvliph$urc$1@sea.gmane.org> <20060324030332.GB2853@nevyn.them.org> <e00anu$f6m$1@sea.gmane.org> <20060324202056.GA26748@nevyn.them.org>
Daniel Jacobowitz wrote:
>> > } else {
>> >
>> > It wants to show the value in its variables window, not the reference.
>> > So this patch would break it.
>> >
>> > So, should we change common_val_print, do you think?
>>
>> Short-term, this might be a solution. But note again that depending on
>> textual "value" field is bad idea in any case.
>
> That's not actually what I meant - I'm not thinking of MI here.
> common_val_print gets called from a number of places:
>
> - varobj c_value_of_variable, used by Insight and MI
> (-var-list-children, -var-evaluate-expression, -var-assign,
> -var-update).
>
> - print_frame_args, where it is used to deliberately print
> only the address of a reference. I'm not entirely sure why.
>
> - Languages, to implement value_print - not relevant right now.
It appears that 'common_val_print' has 'deref_ref' parameter which can be
used to get back the old behaviour. However, then we'll again get no output
if there's any undereferencable reference.
I attach a patch that addresses this issue -- now, undereferencable
references don't throw. For dereferencable references the value is printed
after ":" as it is now.
Changelog:
2006-04-04 Vladimir Prus <ghost@cs.msu.su>
* c-valprint.c (c_val_print): Explicitly check if a reference
is dereferencable.
* valops.c (value_at_maybe): New function
* value.h (value_at_maybe): Export.
* mi/mi-cmd-stack.c (list_args_or_locals): Use 'common_val_print',
instead of 'print_value_value'. Remove code duplication.
Patch is attached.
- Volodya
Index: c-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/c-valprint.c,v
retrieving revision 1.39
diff -u -p -r1.39 c-valprint.c
--- c-valprint.c 18 Jan 2006 21:24:19 -0000 1.39
+++ c-valprint.c 6 Apr 2006 08:28:55 -0000
@@ -277,13 +277,16 @@ c_val_print (struct type *type, const gd
{
if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
{
- struct value *deref_val =
- value_at
- (TYPE_TARGET_TYPE (type),
- unpack_pointer (lookup_pointer_type (builtin_type_void),
- valaddr + embedded_offset));
- common_val_print (deref_val, stream, format, deref_ref,
- recurse, pretty);
+ CORE_ADDR addr = unpack_pointer (
+ lookup_pointer_type (builtin_type_void),
+ valaddr + embedded_offset);
+ struct value *deref_val = value_at_maybe(TYPE_TARGET_TYPE(type),
+ addr);
+ if (deref_val)
+ common_val_print (deref_val, stream, format, deref_ref,
+ recurse, pretty);
+ else
+ fputs_filtered("memory not accessible", stream);
}
else
fputs_filtered ("???", stream);
Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.163
diff -u -p -r1.163 valops.c
--- valops.c 17 Dec 2005 22:34:03 -0000 1.163
+++ valops.c 6 Apr 2006 08:28:55 -0000
@@ -472,6 +472,36 @@ value_at (struct type *type, CORE_ADDR a
return val;
}
+
+/* Same as 'value_at', but returns NULL when memory can't be read
+ instead of throwing.
+*/
+struct value*
+value_at_maybe (struct type *type, CORE_ADDR addr)
+{
+ struct value *val;
+ int status;
+
+ if (TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
+ error (_("Attempt to dereference a generic pointer."));
+
+
+ val = allocate_value (type);
+ status = target_read_memory (addr, value_contents_all_raw(val),
+ TYPE_LENGTH (type));
+ if (status == 0)
+ {
+ VALUE_LVAL (val) = lval_memory;
+ VALUE_ADDRESS (val) = addr;
+ return val;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+
/* Return a lazy value with type TYPE located at ADDR (cf. value_at). */
struct value *
Index: value.h
===================================================================
RCS file: /cvs/src/src/gdb/value.h,v
retrieving revision 1.90
diff -u -p -r1.90 value.h
--- value.h 1 Feb 2006 23:14:10 -0000 1.90
+++ value.h 6 Apr 2006 08:28:56 -0000
@@ -277,6 +277,8 @@ extern struct value *value_from_string (
extern struct value *value_at (struct type *type, CORE_ADDR addr);
extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
+extern struct value *value_at_maybe (struct type *type, CORE_ADDR addr);
+
extern struct value *value_from_register (struct type *type, int regnum,
struct frame_info *frame);
Index: mi/mi-cmd-stack.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmd-stack.c,v
retrieving revision 1.29
diff -u -p -r1.29 mi-cmd-stack.c
--- mi/mi-cmd-stack.c 23 Dec 2005 18:57:46 -0000 1.29
+++ mi/mi-cmd-stack.c 6 Apr 2006 08:28:56 -0000
@@ -278,6 +278,8 @@ list_args_or_locals (int locals, int val
{
struct cleanup *cleanup_tuple = NULL;
struct symbol *sym2;
+ struct value *val;
+ int print_it = 0;
if (values != PRINT_NO_VALUES)
cleanup_tuple =
make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
@@ -300,17 +302,24 @@ list_args_or_locals (int locals, int val
&& TYPE_CODE (type) != TYPE_CODE_STRUCT
&& TYPE_CODE (type) != TYPE_CODE_UNION)
{
- print_variable_value (sym2, fi, stb->stream);
- ui_out_field_stream (uiout, "value", stb);
+ print_it = 1;
}
do_cleanups (cleanup_tuple);
break;
case PRINT_ALL_VALUES:
- print_variable_value (sym2, fi, stb->stream);
- ui_out_field_stream (uiout, "value", stb);
- do_cleanups (cleanup_tuple);
+ print_it = 1;
break;
}
+
+ if (print_it)
+ {
+ val = read_var_value (sym2, fi);
+ common_val_print
+ (val, stb->stream, 0, 1 /*deref refs*/, 2, Val_no_prettyprint);
+ ui_out_field_stream (uiout, "value", stb);
+ do_cleanups (cleanup_tuple);
+ }
+
}
}
if (BLOCK_FUNCTION (block))