Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Vladimir Prus <ghost@cs.msu.su>
To: gdb-patches@sources.redhat.com
Subject: Re: MI: type prefixes for values
Date: Thu, 06 Apr 2006 08:42:00 -0000	[thread overview]
Message-ID: <e12k8s$dci$1@sea.gmane.org> (raw)
In-Reply-To: <20060324202056.GA26748@nevyn.them.org>

[-- Attachment #1: Type: text/plain, Size: 1589 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: MI_stack_list_locals_references.diff --]
[-- Type: text/x-diff; name="MI_stack_list_locals_references.diff", Size: 4582 bytes --]

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))

  reply	other threads:[~2006-04-06  8:42 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <dt43qh$sns$1@sea.gmane.org>
2006-03-13  2:44 ` Nick Roberts
2006-03-17 19:32   ` Vladimir Prus
2006-03-17 19:41     ` Daniel Jacobowitz
2006-03-21 14:58       ` Vladimir Prus
2006-03-24  4:30         ` Daniel Jacobowitz
2006-03-24  9:46           ` Vladimir Prus
2006-03-24 21:02             ` Daniel Jacobowitz
2006-04-06  8:42               ` Vladimir Prus [this message]
2006-04-28  6:32                 ` Vladimir Prus
2006-05-05 19:25                   ` Daniel Jacobowitz
2006-05-06  9:59                     ` Nick Roberts
2006-05-15 16:57                       ` Daniel Jacobowitz
2006-05-16  6:10                         ` Nick Roberts
2007-02-03  5:31                         ` MI: type prefixes for values [PATCH] Nick Roberts
2007-02-04 14:16                           ` Daniel Jacobowitz
2007-02-04 21:46                             ` Nick Roberts
2006-03-17 22:25   ` MI: type prefixes for values Daniel Jacobowitz
2006-03-18 18:39     ` Nick Roberts
2006-03-20  6:50       ` Daniel Jacobowitz
2006-03-21 10:22         ` Nick Roberts
2006-03-24  4:25           ` Daniel Jacobowitz
2006-03-24  5:26             ` Nick Roberts

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='e12k8s$dci$1@sea.gmane.org' \
    --to=ghost@cs.msu.su \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox