diff options
author | Jan Kratochvil <jan.kratochvil@redhat.com> | 2011-10-09 19:30:25 +0000 |
---|---|---|
committer | Jan Kratochvil <jan.kratochvil@redhat.com> | 2011-10-09 19:30:25 +0000 |
commit | 93d86cefdf1902d003f0d54f27777b8ea4f75b13 (patch) | |
tree | 1ecbc64a37b1187f691243e03176a92e98bf574b /gdb/stack.c | |
parent | 2d6c5dc2c7f35f46bdbcee6ea442a97ae880db4b (diff) | |
download | gdb-93d86cefdf1902d003f0d54f27777b8ea4f75b13.zip gdb-93d86cefdf1902d003f0d54f27777b8ea4f75b13.tar.gz gdb-93d86cefdf1902d003f0d54f27777b8ea4f75b13.tar.bz2 |
gdb/
Code reshuffle.
* frame.h (struct frame_arg): New definition.
(read_frame_arg): New declaration.
* mi/mi-cmd-stack.c (list_arg_or_local): New functiom from ...
(list_args_or_locals): ... the code here. New variable arg, call
read_frame_arg and list_arg_or_local with it. Unify the
PRINT_SIMPLE_VALUES and PRINT_ALL_VALUES cases. Call xfree for
arg.error.
* stack.c (print_frame_arg): New functiom from the code of
print_frame_args.
(read_frame_arg): New function.
(print_frame_args): Remove variable val. New variable arg, call
read_frame_arg and print_frame_arg with it. Call xfree for arg.error.
Diffstat (limited to 'gdb/stack.c')
-rw-r--r-- | gdb/stack.c | 176 |
1 files changed, 118 insertions, 58 deletions
diff --git a/gdb/stack.c b/gdb/stack.c index cf15512..bdc3b01 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -162,6 +162,113 @@ print_frame_nameless_args (struct frame_info *frame, long start, int num, } } +/* Print single argument of inferior function. ARG must be already + read in. + + Errors are printed as if they would be the parameter value. Use zeroed ARG + iff it should not be printed accoring to user settings. */ + +static void +print_frame_arg (const struct frame_arg *arg) +{ + struct ui_out *uiout = current_uiout; + volatile struct gdb_exception except; + struct cleanup *old_chain; + struct ui_stream *stb; + + stb = ui_out_stream_new (uiout); + old_chain = make_cleanup_ui_out_stream_delete (stb); + + gdb_assert (!arg->val || !arg->error); + + annotate_arg_begin (); + + make_cleanup_ui_out_tuple_begin_end (uiout, NULL); + fprintf_symbol_filtered (stb->stream, SYMBOL_PRINT_NAME (arg->sym), + SYMBOL_LANGUAGE (arg->sym), DMGL_PARAMS | DMGL_ANSI); + ui_out_field_stream (uiout, "name", stb); + annotate_arg_name_end (); + ui_out_text (uiout, "="); + + if (!arg->val && !arg->error) + ui_out_text (uiout, "..."); + else + { + if (arg->error) + except.message = arg->error; + else + { + /* TRY_CATCH has two statements, wrap it in a block. */ + + TRY_CATCH (except, RETURN_MASK_ERROR) + { + const struct language_defn *language; + struct value_print_options opts; + + /* Avoid value_print because it will deref ref parameters. We + just want to print their addresses. Print ??? for args whose + address 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. */ + + annotate_arg_value (value_type (arg->val)); + + /* Use the appropriate language to display our symbol, unless the + user forced the language to a specific language. */ + if (language_mode == language_mode_auto) + language = language_def (SYMBOL_LANGUAGE (arg->sym)); + else + language = current_language; + + get_raw_print_options (&opts); + opts.deref_ref = 0; + + /* True in "summary" mode, false otherwise. */ + opts.summary = !strcmp (print_frame_arguments, "scalars"); + + common_val_print (arg->val, stb->stream, 2, &opts, language); + } + } + if (except.message) + fprintf_filtered (stb->stream, _("<error reading variable: %s>"), + except.message); + } + + ui_out_field_stream (uiout, "value", stb); + + /* Aleo invoke ui_out_tuple_end. */ + do_cleanups (old_chain); + + annotate_arg_end (); +} + +/* Read in inferior function parameter SYM at FRAME into ARGP. Caller is + responsible for xfree of ARGP->ERROR. This function never throws an + exception. */ + +void +read_frame_arg (struct symbol *sym, struct frame_info *frame, + struct frame_arg *argp) +{ + struct value *val = NULL; + char *val_error = NULL; + volatile struct gdb_exception except; + + TRY_CATCH (except, RETURN_MASK_ERROR) + { + val = read_var_value (sym, frame); + } + if (!val) + { + val_error = alloca (strlen (except.message) + 1); + strcpy (val_error, except.message); + } + + argp->sym = sym; + argp->val = val; + argp->error = val_error ? xstrdup (val_error) : NULL; +} + /* Print the arguments of frame FRAME on STREAM, given the function FUNC running in that frame (as a symbol), where NUM is the number of arguments according to the stack frame (or -1 if the number of @@ -198,10 +305,11 @@ print_frame_args (struct symbol *func, struct frame_info *frame, struct block *b = SYMBOL_BLOCK_VALUE (func); struct dict_iterator iter; struct symbol *sym; - struct value *val; ALL_BLOCK_SYMBOLS (b, iter, sym) { + struct frame_arg arg; + QUIT; /* Keep track of the highest stack argument offset seen, and @@ -314,65 +422,17 @@ print_frame_args (struct symbol *func, struct frame_info *frame, ui_out_text (uiout, ", "); ui_out_wrap_hint (uiout, " "); - annotate_arg_begin (); - - list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); - fprintf_symbol_filtered (stb->stream, SYMBOL_PRINT_NAME (sym), - SYMBOL_LANGUAGE (sym), - DMGL_PARAMS | DMGL_ANSI); - ui_out_field_stream (uiout, "name", stb); - annotate_arg_name_end (); - ui_out_text (uiout, "="); - - if (print_args) - { - volatile struct gdb_exception except; - - TRY_CATCH (except, RETURN_MASK_ERROR) - { - const struct language_defn *language; - struct value_print_options opts; - - /* Avoid value_print because it will deref ref parameters. - We just want to print their addresses. Print ??? for - args whose address 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, frame); - - annotate_arg_value (value_type (val)); - - /* Use the appropriate language to display our symbol, - unless the user forced the language to a specific - language. */ - if (language_mode == language_mode_auto) - language = language_def (SYMBOL_LANGUAGE (sym)); - else - language = current_language; - - get_raw_print_options (&opts); - opts.deref_ref = 0; - opts.summary = summary; - common_val_print (val, stb->stream, 2, &opts, language); - ui_out_field_stream (uiout, "value", stb); - } - if (except.reason < 0) - { - fprintf_filtered (stb->stream, - _("<error reading variable: %s>"), - except.message); - ui_out_field_stream (uiout, "value", stb); - } - } - else - ui_out_text (uiout, "..."); - + if (!print_args) + { + memset (&arg, 0, sizeof (arg)); + arg.sym = sym; + } + else + read_frame_arg (sym, frame, &arg); - /* Invoke ui_out_tuple_end. */ - do_cleanups (list_chain); + print_frame_arg (&arg); - annotate_arg_end (); + xfree (arg.error); first = 0; } |