From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29868 invoked by alias); 28 Apr 2006 06:32:50 -0000 Received: (qmail 29860 invoked by uid 22791); 28 Apr 2006 06:32:49 -0000 X-Spam-Check-By: sourceware.org Received: from main.gmane.org (HELO ciao.gmane.org) (80.91.229.2) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 28 Apr 2006 06:32:46 +0000 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1FZMWx-0004Es-6d for gdb-patches@sources.redhat.com; Fri, 28 Apr 2006 08:32:43 +0200 Received: from zigzag.lvk.cs.msu.su ([158.250.17.23]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Apr 2006 08:32:43 +0200 Received: from ghost by zigzag.lvk.cs.msu.su with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Apr 2006 08:32:43 +0200 To: gdb-patches@sources.redhat.com From: Vladimir Prus Subject: Re: MI: type prefixes for values Date: Fri, 28 Apr 2006 06:32:00 -0000 Message-ID: References: <17427.54333.236860.258115@kahikatea.snap.net.nz> <20060317191207.GA19068@nevyn.them.org> <20060324030332.GB2853@nevyn.them.org> <20060324202056.GA26748@nevyn.them.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart1944334.h5NR0VDovh" Content-Transfer-Encoding: 7Bit User-Agent: KNode/0.8.2 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-04/txt/msg00364.txt.bz2 --nextPart1944334.h5NR0VDovh Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 8Bit Content-length: 1278 Any comments on the patch I've send two weeks ago? Note that I'm not longer interested in this patch myself, since I no longer use "--stack-list-frames --all-values" in KDevelop, but I believe the patch affects the MI support in Emacs that Nick is working on. - Volodya >> - 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 > > * 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 --nextPart1944334.h5NR0VDovh Content-Type: text/x-diff; name="MI_stack_list_locals_references.diff" Content-Transfer-Encoding: 8Bit Content-Disposition: attachment; filename="MI_stack_list_locals_references.diff" Content-length: 4582 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)) --nextPart1944334.h5NR0VDovh--