Don't error out when variable not available

Andreas Schwab
2005-01-02T22:13:56Z

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