* Don't error out when variable not available
@ 2005-01-02 22:13 Andreas Schwab
2005-01-02 22:57 ` Daniel Jacobowitz
2005-01-04 22:20 ` Andrew Cagney
0 siblings, 2 replies; 8+ messages in thread
From: Andreas Schwab @ 2005-01-02 22:13 UTC (permalink / raw)
To: gdb-patches
With the introduction of DWARF location lists it became impossible to get
the full list of local variables of a function when any of them is not
available. This is especially annoying when the first local or function
parameter is missing. Here is an attempt at correcting this. It is
suboptimal because it still prints the error message including the newline
which badly messes up the output. Any idea how to fix that properly?
Andreas.
2005-01-02 Andreas Schwab <schwab@suse.de>
* findvar.c (read_var_value_no_error, read_var_value_no_error_1)
(struct read_var_value_args): New.
* value.h (read_var_value_no_error): Declare it.
* printcmd.c (print_variable_value): Use read_var_value_no_error.
* stack.c (print_frame_args): Likewise.
--- gdb/findvar.c.~1.82.~ 2004-11-17 00:55:13.000000000 +0100
+++ gdb/findvar.c 2005-01-02 22:48:01.469889953 +0100
@@ -589,6 +589,39 @@ addresses have not been bound by the dyn
return v;
}
+/* Like read_var_value, but catch errors and return NULL if any
+ occured. */
+
+struct read_var_value_args
+{
+ struct symbol *var;
+ struct frame_info *frame;
+ struct value *val;
+};
+
+static int
+read_var_value_no_error_1 (void *data)
+{
+ struct read_var_value_args *args = data;
+ struct value *val;
+
+ val = read_var_value (args->var, args->frame);
+ args->val = val;
+ return 0;
+}
+
+struct value *
+read_var_value_no_error (struct symbol *var, struct frame_info *frame)
+{
+ struct read_var_value_args args;
+
+ args.var = var;
+ args.frame = frame;
+ args.val = NULL;
+ catch_errors (read_var_value_no_error_1, &args, NULL, RETURN_MASK_ERROR);
+ return args.val;
+}
+
/* Return a value of type TYPE, stored in register REGNUM, in frame
FRAME.
--- gdb/printcmd.c.~1.81.~ 2004-11-13 01:24:52.000000000 +0100
+++ gdb/printcmd.c 2005-01-02 22:58:56.751697758 +0100
@@ -1708,9 +1708,10 @@ void
print_variable_value (struct symbol *var, struct frame_info *frame,
struct ui_file *stream)
{
- struct value *val = read_var_value (var, frame);
+ struct value *val = read_var_value_no_error (var, frame);
- value_print (val, stream, 0, Val_pretty_default);
+ if (val != NULL)
+ value_print (val, stream, 0, Val_pretty_default);
}
static void
--- gdb/stack.c.~1.119.~ 2004-11-13 01:24:52.000000000 +0100
+++ gdb/stack.c 2005-01-02 22:37:25.785526361 +0100
@@ -347,7 +347,7 @@ print_frame_args (struct symbol *func, s
we do not know. We pass 2 as "recurse" to val_print because our
standard indentation here is 4 spaces, and val_print indents
2 for each recurse. */
- val = read_var_value (sym, fi);
+ val = read_var_value_no_error (sym, fi);
annotate_arg_value (val == NULL ? NULL : value_type (val));
--- gdb/value.h.~1.61.~ 2004-11-17 00:55:14.000000000 +0100
+++ gdb/value.h 2005-01-02 22:35:28.716424395 +0100
@@ -293,6 +293,9 @@ extern int symbol_read_needs_frame (stru
extern struct value *read_var_value (struct symbol *var,
struct frame_info *frame);
+extern struct value *read_var_value_no_error (struct symbol *var,
+ struct frame_info *frame);
+
extern struct value *locate_var_value (struct symbol *var,
struct frame_info *frame);
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Don't error out when variable not available
2005-01-02 22:13 Don't error out when variable not available Andreas Schwab
@ 2005-01-02 22:57 ` Daniel Jacobowitz
2005-01-02 23:49 ` Andreas Schwab
2005-01-04 22:20 ` Andrew Cagney
1 sibling, 1 reply; 8+ messages in thread
From: Daniel Jacobowitz @ 2005-01-02 22:57 UTC (permalink / raw)
To: Andreas Schwab; +Cc: gdb-patches
On Sun, Jan 02, 2005 at 11:01:45PM +0100, Andreas Schwab wrote:
> With the introduction of DWARF location lists it became impossible to get
> the full list of local variables of a function when any of them is not
> available. This is especially annoying when the first local or function
> parameter is missing. Here is an attempt at correcting this. It is
> suboptimal because it still prints the error message including the newline
> which badly messes up the output. Any idea how to fix that properly?
How about reusing the LOC_OPTIMIZED_OUT handling to describe this case?
I believe that will print "foo = <optimized out>".
--
Daniel Jacobowitz
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Don't error out when variable not available
2005-01-02 22:57 ` Daniel Jacobowitz
@ 2005-01-02 23:49 ` Andreas Schwab
2005-01-03 0:49 ` Daniel Jacobowitz
0 siblings, 1 reply; 8+ messages in thread
From: Andreas Schwab @ 2005-01-02 23:49 UTC (permalink / raw)
To: gdb-patches
Daniel Jacobowitz <drow@false.org> writes:
> How about reusing the LOC_OPTIMIZED_OUT handling to describe this case?
> I believe that will print "foo = <optimized out>".
LOC_OPTIMIZED_OUT is not a value, but a static property of a symbol. I
don't think it fits into the dynamic nature of unavailable values.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, MaxfeldstraÃe 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Don't error out when variable not available
2005-01-02 23:49 ` Andreas Schwab
@ 2005-01-03 0:49 ` Daniel Jacobowitz
2005-01-03 13:41 ` Andreas Schwab
0 siblings, 1 reply; 8+ messages in thread
From: Daniel Jacobowitz @ 2005-01-03 0:49 UTC (permalink / raw)
To: Andreas Schwab; +Cc: gdb-patches
On Mon, Jan 03, 2005 at 12:49:04AM +0100, Andreas Schwab wrote:
> Daniel Jacobowitz <drow@false.org> writes:
>
> > How about reusing the LOC_OPTIMIZED_OUT handling to describe this case?
> > I believe that will print "foo = <optimized out>".
>
> LOC_OPTIMIZED_OUT is not a value, but a static property of a symbol. I
> don't think it fits into the dynamic nature of unavailable values.
However, we always handle it in the same case statements that handle
LOC_COMPUTED, which is how we get into the dwarf2 expression evaluator
anyway.
--
Daniel Jacobowitz
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Don't error out when variable not available
2005-01-03 0:49 ` Daniel Jacobowitz
@ 2005-01-03 13:41 ` Andreas Schwab
0 siblings, 0 replies; 8+ messages in thread
From: Andreas Schwab @ 2005-01-03 13:41 UTC (permalink / raw)
To: gdb-patches
How about this?
Andreas.
2005-01-03 Andreas Schwab <schwab@suse.de>
* stack.c (print_frame_args): Handle VALUE_OPTIMIZED_OUT.
* dwarf2loc.c (loclist_read_variable): Return a value with
VALUE_OPTIMIZED_OUT set instead of erring out when value not
available.
Index: dwarf2loc.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2loc.c,v
retrieving revision 1.18
diff -u -a -p -r1.18 dwarf2loc.c
--- dwarf2loc.c 9 Nov 2004 14:43:25 -0000 1.18
+++ dwarf2loc.c 3 Jan 2005 13:33:23 -0000
@@ -1,5 +1,5 @@
/* DWARF 2 location expression support for GDB.
- Copyright 2003 Free Software Foundation, Inc.
+ Copyright 2003, 2005 Free Software Foundation, Inc.
Contributed by Daniel Jacobowitz, MontaVista Software, Inc.
This file is part of GDB.
@@ -510,9 +510,14 @@ loclist_read_variable (struct symbol *sy
data = find_location_expression (dlbaton, &size,
frame ? get_frame_pc (frame) : 0);
if (data == NULL)
- error ("Variable \"%s\" is not available.", SYMBOL_NATURAL_NAME (symbol));
-
- val = dwarf2_evaluate_loc_desc (symbol, frame, data, size, dlbaton->objfile);
+ {
+ val = allocate_value (SYMBOL_TYPE (symbol));
+ VALUE_LVAL (val) = not_lval;
+ VALUE_OPTIMIZED_OUT (val) = 1;
+ }
+ else
+ val = dwarf2_evaluate_loc_desc (symbol, frame, data, size,
+ dlbaton->objfile);
return val;
}
Index: stack.c
===================================================================
RCS file: /cvs/src/src/gdb/stack.c,v
retrieving revision 1.119
diff -u -a -p -r1.119 stack.c
--- stack.c 12 Nov 2004 21:45:07 -0000 1.119
+++ stack.c 3 Jan 2005 13:33:56 -0000
@@ -1,7 +1,7 @@
/* Print and select stack frames for GDB, the GNU debugger.
Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
- 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free
+ 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free
Software Foundation, Inc.
This file is part of GDB.
@@ -353,10 +353,15 @@ print_frame_args (struct symbol *func, s
if (val)
{
- val_print (value_type (val), VALUE_CONTENTS (val), 0,
- VALUE_ADDRESS (val),
- stb->stream, 0, 0, 2, Val_no_prettyprint);
- ui_out_field_stream (uiout, "value", stb);
+ if (VALUE_OPTIMIZED_OUT (val))
+ ui_out_text (uiout, "<value optimized out>");
+ else
+ {
+ val_print (value_type (val), VALUE_CONTENTS (val), 0,
+ VALUE_ADDRESS (val),
+ stb->stream, 0, 0, 2, Val_no_prettyprint);
+ ui_out_field_stream (uiout, "value", stb);
+ }
}
else
ui_out_text (uiout, "???");
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, MaxfeldstraÃe 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Don't error out when variable not available
2005-01-02 22:13 Don't error out when variable not available Andreas Schwab
2005-01-02 22:57 ` Daniel Jacobowitz
@ 2005-01-04 22:20 ` Andrew Cagney
2005-01-05 19:23 ` Andreas Schwab
1 sibling, 1 reply; 8+ messages in thread
From: Andrew Cagney @ 2005-01-04 22:20 UTC (permalink / raw)
To: Andreas Schwab; +Cc: gdb-patches
Andreas Schwab wrote:
> With the introduction of DWARF location lists it became impossible to get
> the full list of local variables of a function when any of them is not
> available. This is especially annoying when the first local or function
> parameter is missing. Here is an attempt at correcting this. It is
> suboptimal because it still prints the error message including the newline
> which badly messes up the output. Any idea how to fix that properly?
The code to catch these errors and print the message as part of the
output has long been on my (and I suspect others) wish list. It should,
in addition to solving your problem, mean that gdb handles the general
case printing for instance:
(gdb) print struct_s
$1 = { a = <memory error>, b = "hi" }
(gdb)
instead of
$1 = { a = memory error
(gdb)
Have a look at catch_exceptions_with_msg. It was added to handle the
problem of needing to catch the error message (you might need to wiggle
the interface though).
Adding more special case code, as was done with your other patch, isn't
the way to go.
Andrew
> 2005-01-02 Andreas Schwab <schwab@suse.de>
>
> * findvar.c (read_var_value_no_error, read_var_value_no_error_1)
> (struct read_var_value_args): New.
> * value.h (read_var_value_no_error): Declare it.
> * printcmd.c (print_variable_value): Use read_var_value_no_error.
> * stack.c (print_frame_args): Likewise.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Don't error out when variable not available
2005-01-04 22:20 ` Andrew Cagney
@ 2005-01-05 19:23 ` Andreas Schwab
2005-02-28 20:53 ` Daniel Jacobowitz
0 siblings, 1 reply; 8+ messages in thread
From: Andreas Schwab @ 2005-01-05 19:23 UTC (permalink / raw)
To: Andrew Cagney; +Cc: gdb-patches
Andrew Cagney <cagney@gnu.org> writes:
> Adding more special case code, as was done with your other patch, isn't
> the way to go.
There is really no reason to call error in loclist_read_variable when we
can return VALUE_OPTIMIZED_OUT, like we already to in
dwarf2_evaluate_loc_desc. Fixing that problem is orthogonal to the
general problem of not catching errors. That print_frame_args needs to
check for VALUE_OPTIMIZED_OUT is only because it calls val_print directly
without going through value_print. It already has to take care of NULL
value even though value_print would handle that as well. Sooner or later
it would probably have been required to add this case anyway.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, MaxfeldstraÃe 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Don't error out when variable not available
2005-01-05 19:23 ` Andreas Schwab
@ 2005-02-28 20:53 ` Daniel Jacobowitz
0 siblings, 0 replies; 8+ messages in thread
From: Daniel Jacobowitz @ 2005-02-28 20:53 UTC (permalink / raw)
To: Andreas Schwab; +Cc: gdb-patches
On Wed, Jan 05, 2005 at 08:14:19PM +0100, Andreas Schwab wrote:
> There is really no reason to call error in loclist_read_variable when we
> can return VALUE_OPTIMIZED_OUT, like we already to in
> dwarf2_evaluate_loc_desc. Fixing that problem is orthogonal to the
> general problem of not catching errors. That print_frame_args needs to
> check for VALUE_OPTIMIZED_OUT is only because it calls val_print directly
> without going through value_print. It already has to take care of NULL
> value even though value_print would handle that as well. Sooner or later
> it would probably have been required to add this case anyway.
Yes, this is true. However, I'd rather not add it at the call sites of
val_print. Instead, I've created a nicer interface to val_print which
shares sanity-checking code with value_print. Most of the places
currently calling val_print can call this instead; a TODO item is to
make all uses of val_print pass the value around.
I went looking at the original location list support. The error() call
in question was simply a goof on my part; I had forgotten about
the VALUE_OPTIMIZED_OUT bits a couple of functions down.
I've checked in this patch instead. Tested by the GDB testsuite on
i686-pc-linux-gnu (no changes); the GDB testsute on arm-eabi using ARM
RVDS (some improvements); and by hand using GCC 3.4 and optimization
(definite improvement).
--
Daniel Jacobowitz
CodeSourcery, LLC
2005-02-28 Daniel Jacobowitz <dan@codesourcery.com>
* dwarf2loc.c (loclist_read_variable): Set optimized_out
instead of reporting an error.
* valprint.c (value_check_printable): New function.
(common_val_print): New function. Use value_check_printable.
(value_print): Use value_check_printable.
* value.h (common_val_print): Add prototype.
* c-valprint.c (c_val_print): Use common_val_print.
* cp-valprint.c (cp_print_value_fields): Likewise.
(cp_print_hpacc_virtual_table_entries): Likewise.
* f-valprint.c (f_val_print): Likewise.
* jv-valprint.c (java_value_print, java_print_value_fields):
Likewise.
* scm-valprint.c (scm_value_print): Likewise.
* stack.c (print_frame_args): Likewise.
* varobj.c (c_value_of_variable): Likewise.
* p-valprint.c (pascal_val_print, pascal_value_print): Likewise.
(pascal_object_print_value_fields): Likewise. Update call to
pascal_object_print_static_field.
(pascal_object_print_static_field): Remove TYPE argument. Use
common_val_print.
Index: c-valprint.c
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/gdb/c-valprint.c,v
retrieving revision 1.34
diff -u -p -r1.34 c-valprint.c
--- c-valprint.c 14 Feb 2005 14:37:37 -0000 1.34
+++ c-valprint.c 27 Feb 2005 15:51:32 -0000
@@ -233,9 +233,8 @@ c_val_print (struct type *type, const bf
wtype = TYPE_TARGET_TYPE (type);
}
vt_val = value_at (wtype, vt_address);
- val_print (value_type (vt_val), value_contents (vt_val), 0,
- VALUE_ADDRESS (vt_val), stream, format,
- deref_ref, recurse + 1, pretty);
+ common_val_print (vt_val, stream, format,
+ deref_ref, recurse + 1, pretty);
if (pretty)
{
fprintf_filtered (stream, "\n");
@@ -283,15 +282,8 @@ c_val_print (struct type *type, const bf
(TYPE_TARGET_TYPE (type),
unpack_pointer (lookup_pointer_type (builtin_type_void),
valaddr + embedded_offset));
- val_print (value_type (deref_val),
- value_contents (deref_val),
- 0,
- VALUE_ADDRESS (deref_val),
- stream,
- format,
- deref_ref,
- recurse,
- pretty);
+ common_val_print (deref_val, stream, format, deref_ref,
+ recurse, pretty);
}
else
fputs_filtered ("???", stream);
Index: cp-valprint.c
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/gdb/cp-valprint.c,v
retrieving revision 1.40
diff -u -p -r1.40 cp-valprint.c
--- cp-valprint.c 24 Feb 2005 13:51:31 -0000 1.40
+++ cp-valprint.c 27 Feb 2005 15:54:29 -0000
@@ -389,8 +389,7 @@ cp_print_value_fields (struct type *type
(TYPE_FIELD_TYPE (type, i),
unpack_field_as_long (type, valaddr + offset, i));
- val_print (TYPE_FIELD_TYPE (type, i), value_contents (v),
- 0, 0, stream, format, 0, recurse + 1, pretty);
+ common_val_print (v, stream, format, 0, recurse + 1, pretty);
}
}
else
@@ -454,8 +453,7 @@ cp_print_value_fields (struct type *type
v = value_from_pointer (lookup_pointer_type (builtin_type_unsigned_long),
*(unsigned long *) (valaddr + offset));
- val_print (value_type (v), value_contents (v), 0, 0,
- stream, format, 0, recurse + 1, pretty);
+ common_val_print (v, stream, format, 0, recurse + 1, pretty);
fields_seen = 1;
if (vtblprint)
@@ -822,8 +820,7 @@ cp_print_hpacc_virtual_table_entries (st
deprecated_set_value_type (vf, value_type (v));
/* print out the entry */
- val_print (value_type (vf), value_contents (vf), 0, 0,
- stream, format, 0, recurse + 1, pretty);
+ common_val_print (vf, stream, format, 0, recurse + 1, pretty);
field_physname
= TYPE_FN_FIELD_PHYSNAME (TYPE_FN_FIELDLIST1 (type, fn), oi);
/* pai: (temp) FIXME Maybe this should be DMGL_ANSI */
Index: dwarf2loc.c
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/gdb/dwarf2loc.c,v
retrieving revision 1.21
diff -u -p -r1.21 dwarf2loc.c
--- dwarf2loc.c 11 Feb 2005 04:05:46 -0000 1.21
+++ dwarf2loc.c 27 Feb 2005 02:21:47 -0000
@@ -512,9 +512,14 @@ loclist_read_variable (struct symbol *sy
data = find_location_expression (dlbaton, &size,
frame ? get_frame_pc (frame) : 0);
if (data == NULL)
- error (_("Variable \"%s\" is not available."), SYMBOL_NATURAL_NAME (symbol));
-
- val = dwarf2_evaluate_loc_desc (symbol, frame, data, size, dlbaton->objfile);
+ {
+ val = allocate_value (SYMBOL_TYPE (symbol));
+ VALUE_LVAL (val) = not_lval;
+ set_value_optimized_out (val, 1);
+ }
+ else
+ val = dwarf2_evaluate_loc_desc (symbol, frame, data, size,
+ dlbaton->objfile);
return val;
}
Index: f-valprint.c
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/gdb/f-valprint.c,v
retrieving revision 1.28
diff -u -p -r1.28 f-valprint.c
--- f-valprint.c 15 Feb 2005 15:49:09 -0000 1.28
+++ f-valprint.c 27 Feb 2005 15:55:02 -0000
@@ -440,15 +440,8 @@ f_val_print (struct type *type, const bf
(TYPE_TARGET_TYPE (type),
unpack_pointer (lookup_pointer_type (builtin_type_void),
valaddr + embedded_offset));
- val_print (value_type (deref_val),
- value_contents (deref_val),
- 0,
- VALUE_ADDRESS (deref_val),
- stream,
- format,
- deref_ref,
- recurse,
- pretty);
+ common_val_print (deref_val, stream, format, deref_ref, recurse,
+ pretty);
}
else
fputs_filtered ("???", stream);
Index: jv-valprint.c
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/gdb/jv-valprint.c,v
retrieving revision 1.23
diff -u -p -r1.23 jv-valprint.c
--- jv-valprint.c 8 Feb 2005 02:29:17 -0000 1.23
+++ jv-valprint.c 27 Feb 2005 15:58:40 -0000
@@ -182,8 +182,7 @@ java_value_print (struct value *val, str
else
fprintf_filtered (stream, "%d..%d: ", i, i + reps - 1);
- val_print (value_type (v), value_contents (v), 0, 0,
- stream, format, 2, 1, pretty);
+ common_val_print (v, stream, format, 2, 1, pretty);
things_printed++;
i += reps;
@@ -235,8 +234,7 @@ java_value_print (struct value *val, str
return 0;
}
- return (val_print (type, value_contents (val), 0, address,
- stream, format, 1, 0, pretty));
+ return common_val_print (val, stream, format, 1, 0, pretty);
}
/* TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and PRETTY have the
@@ -384,8 +382,7 @@ java_print_value_fields (struct type *ty
v = value_from_longest (TYPE_FIELD_TYPE (type, i),
unpack_field_as_long (type, valaddr, i));
- val_print (TYPE_FIELD_TYPE (type, i), value_contents (v), 0,
- 0, stream, format, 0, recurse + 1, pretty);
+ common_val_print (v, stream, format, 0, recurse + 1, pretty);
}
}
else
@@ -404,9 +401,8 @@ java_print_value_fields (struct type *ty
struct type *t = check_typedef (value_type (v));
if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
v = value_addr (v);
- val_print (value_type (v),
- value_contents (v), 0, VALUE_ADDRESS (v),
- stream, format, 0, recurse + 1, pretty);
+ common_val_print (v, stream, format, 0, recurse + 1,
+ pretty);
}
}
else if (TYPE_FIELD_TYPE (type, i) == NULL)
Index: p-valprint.c
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/gdb/p-valprint.c,v
retrieving revision 1.37
diff -u -p -r1.37 p-valprint.c
--- p-valprint.c 24 Feb 2005 13:51:34 -0000 1.37
+++ p-valprint.c 27 Feb 2005 16:02:06 -0000
@@ -240,9 +240,8 @@ pascal_val_print (struct type *type, con
wtype = TYPE_TARGET_TYPE (type);
}
vt_val = value_at (wtype, vt_address);
- val_print (value_type (vt_val), value_contents (vt_val), 0,
- VALUE_ADDRESS (vt_val), stream, format,
- deref_ref, recurse + 1, pretty);
+ common_val_print (vt_val, stream, format, deref_ref,
+ recurse + 1, pretty);
if (pretty)
{
fprintf_filtered (stream, "\n");
@@ -292,10 +291,8 @@ pascal_val_print (struct type *type, con
(TYPE_TARGET_TYPE (type),
unpack_pointer (lookup_pointer_type (builtin_type_void),
valaddr + embedded_offset));
- val_print (value_type (deref_val),
- value_contents (deref_val), 0,
- VALUE_ADDRESS (deref_val), stream, format,
- deref_ref, recurse + 1, pretty);
+ common_val_print (deref_val, stream, format, deref_ref,
+ recurse + 1, pretty);
}
else
fputs_filtered ("???", stream);
@@ -566,9 +563,7 @@ pascal_value_print (struct value *val, s
fprintf_filtered (stream, ") ");
}
}
- return val_print (type, value_contents (val), value_embedded_offset (val),
- VALUE_ADDRESS (val) + value_offset (val),
- stream, format, 1, 0, pretty);
+ return common_val_print (val, stream, format, 1, 0, pretty);
}
@@ -591,7 +586,7 @@ show_pascal_static_field_print (struct u
static struct obstack dont_print_vb_obstack;
static struct obstack dont_print_statmem_obstack;
-static void pascal_object_print_static_field (struct type *, struct value *,
+static void pascal_object_print_static_field (struct value *,
struct ui_file *, int, int,
enum val_prettyprint);
@@ -854,8 +849,7 @@ pascal_object_print_value_fields (struct
v = value_from_longest (TYPE_FIELD_TYPE (type, i),
unpack_field_as_long (type, valaddr, i));
- val_print (TYPE_FIELD_TYPE (type, i), value_contents (v), 0, 0,
- stream, format, 0, recurse + 1, pretty);
+ common_val_print (v, stream, format, 0, recurse + 1, pretty);
}
}
else
@@ -874,9 +868,8 @@ pascal_object_print_value_fields (struct
if (v == NULL)
fputs_filtered ("<optimized out>", stream);
else
- pascal_object_print_static_field (TYPE_FIELD_TYPE (type, i), v,
- stream, format, recurse + 1,
- pretty);
+ pascal_object_print_static_field (v, stream, format,
+ recurse + 1, pretty);
}
else
{
@@ -1017,14 +1010,16 @@ pascal_object_print_value (struct type *
static member classes in an obstack and refuse to print them more
than once.
- VAL contains the value to print, TYPE, STREAM, RECURSE, and PRETTY
+ VAL contains the value to print, STREAM, RECURSE, and PRETTY
have the same meanings as in c_val_print. */
static void
-pascal_object_print_static_field (struct type *type, struct value *val,
+pascal_object_print_static_field (struct value *val,
struct ui_file *stream, int format,
int recurse, enum val_prettyprint pretty)
{
+ struct type *type = value_type (val);
+
if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
{
CORE_ADDR *first_dont_print;
@@ -1053,8 +1048,7 @@ pascal_object_print_static_field (struct
stream, format, recurse, pretty, NULL, 1);
return;
}
- val_print (type, value_contents (val), 0, VALUE_ADDRESS (val),
- stream, format, 0, recurse, pretty);
+ common_val_print (val, stream, format, 0, recurse, pretty);
}
void
Index: scm-valprint.c
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/gdb/scm-valprint.c,v
retrieving revision 1.9
diff -u -p -r1.9 scm-valprint.c
--- scm-valprint.c 7 Feb 2005 00:09:55 -0000 1.9
+++ scm-valprint.c 27 Feb 2005 15:24:00 -0000
@@ -391,6 +391,5 @@ int
scm_value_print (struct value *val, struct ui_file *stream, int format,
enum val_prettyprint pretty)
{
- return (val_print (value_type (val), value_contents (val), 0,
- VALUE_ADDRESS (val), stream, format, 1, 0, pretty));
+ return (common_val_print (val, stream, format, 1, 0, pretty));
}
Index: stack.c
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/gdb/stack.c,v
retrieving revision 1.129
diff -u -p -r1.129 stack.c
--- stack.c 15 Feb 2005 15:49:20 -0000 1.129
+++ stack.c 27 Feb 2005 02:21:47 -0000
@@ -354,9 +354,7 @@ print_frame_args (struct symbol *func, s
if (val)
{
- val_print (value_type (val), value_contents (val), 0,
- VALUE_ADDRESS (val),
- stb->stream, 0, 0, 2, Val_no_prettyprint);
+ common_val_print (val, stb->stream, 0, 0, 2, Val_no_prettyprint);
ui_out_field_stream (uiout, "value", stb);
}
else
Index: valprint.c
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/gdb/valprint.c,v
retrieving revision 1.51
diff -u -p -r1.51 valprint.c
--- valprint.c 24 Feb 2005 13:51:35 -0000 1.51
+++ valprint.c 27 Feb 2005 02:22:32 -0000
@@ -217,25 +217,66 @@ val_print (struct type *type, const bfd_
stream, format, deref_ref, recurse, pretty));
}
-/* Print the value VAL in C-ish syntax on stream STREAM.
- FORMAT is a format-letter, or 0 for print in natural format of data type.
- If the object printed is a string pointer, returns
- the number of string bytes printed. */
+/* Check whether the value VAL is printable. Return 1 if it is;
+ return 0 and print an appropriate error message to STREAM if it
+ is not. */
-int
-value_print (struct value *val, struct ui_file *stream, int format,
- enum val_prettyprint pretty)
+static int
+value_check_printable (struct value *val, struct ui_file *stream)
{
if (val == 0)
{
- printf_filtered (_("<address of value unknown>"));
+ fprintf_filtered (stream, _("<address of value unknown>"));
return 0;
}
+
if (value_optimized_out (val))
{
- printf_filtered (_("<value optimized out>"));
+ fprintf_filtered (stream, _("<value optimized out>"));
return 0;
}
+
+ return 1;
+}
+
+/* Print the value VAL onto stream STREAM according to FORMAT (a
+ letter, or 0 for natural format using TYPE).
+
+ If DEREF_REF is nonzero, then dereference references, otherwise just print
+ them like pointers.
+
+ The PRETTY parameter controls prettyprinting.
+
+ If the data are a string pointer, returns the number of string characters
+ printed.
+
+ This is a preferable interface to val_print, above, because it uses
+ GDB's value mechanism. */
+
+int
+common_val_print (struct value *val, struct ui_file *stream, int format,
+ int deref_ref, int recurse, enum val_prettyprint pretty)
+{
+ if (!value_check_printable (val, stream))
+ return 0;
+
+ return val_print (value_type (val), value_contents_all (val),
+ value_embedded_offset (val), VALUE_ADDRESS (val),
+ stream, format, deref_ref, recurse, pretty);
+}
+
+/* Print the value VAL in C-ish syntax on stream STREAM.
+ FORMAT is a format-letter, or 0 for print in natural format of data type.
+ If the object printed is a string pointer, returns
+ the number of string bytes printed. */
+
+int
+value_print (struct value *val, struct ui_file *stream, int format,
+ enum val_prettyprint pretty)
+{
+ if (!value_check_printable (val, stream))
+ return 0;
+
return LA_VALUE_PRINT (val, stream, format, pretty);
}
Index: value.h
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/gdb/value.h,v
retrieving revision 1.83
diff -u -p -r1.83 value.h
--- value.h 20 Feb 2005 01:19:24 -0000 1.83
+++ value.h 27 Feb 2005 02:21:47 -0000
@@ -479,6 +479,11 @@ extern int val_print (struct type *type,
int deref_ref, int recurse,
enum val_prettyprint pretty);
+extern int common_val_print (struct value *val,
+ struct ui_file *stream, int format,
+ int deref_ref, int recurse,
+ enum val_prettyprint pretty);
+
extern int val_print_string (CORE_ADDR addr, int len, int width,
struct ui_file *stream);
Index: varobj.c
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/gdb/varobj.c,v
retrieving revision 1.51
diff -u -p -r1.51 varobj.c
--- varobj.c 24 Feb 2005 13:51:35 -0000 1.51
+++ varobj.c 27 Feb 2005 15:49:38 -0000
@@ -2080,10 +2080,8 @@ c_value_of_variable (struct varobj *var)
if (value_lazy (var->value))
gdb_value_fetch_lazy (var->value);
- val_print (value_type (var->value),
- value_contents_raw (var->value), 0,
- VALUE_ADDRESS (var->value), stb,
- format_code[(int) var->format], 1, 0, 0);
+ common_val_print (var->value, stb,
+ format_code[(int) var->format], 1, 0, 0);
thevalue = ui_file_xstrdup (stb, &dummy);
do_cleanups (old_chain);
return thevalue;
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2005-02-28 17:20 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-02 22:13 Don't error out when variable not available Andreas Schwab
2005-01-02 22:57 ` Daniel Jacobowitz
2005-01-02 23:49 ` Andreas Schwab
2005-01-03 0:49 ` Daniel Jacobowitz
2005-01-03 13:41 ` Andreas Schwab
2005-01-04 22:20 ` Andrew Cagney
2005-01-05 19:23 ` Andreas Schwab
2005-02-28 20:53 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox