This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] printcmd.c (ui_printf): make internalvar string can be printf and eval when inferior cannot alloc memory


On Fri, Jul 22, 2011 at 04:38, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> ">" == Hui Zhu <teawater@gmail.com> writes:
>
>>> So I make a patch to handle the error from value_as_address. ?If
>>> value_as_address get error and this is a internalvar, call
>>> value_contents to get the address of the val.
>
> I don't think this is the best approach to solve this problem.
>
> It seems to me that if the value is already an array, the data might
> already exist in gdb, and then you don't have to even try to coerce it
> to memory. ?(However, for a pointer or integer value, using
> value_as_address is still the best thing.)
>
> I would suggest looking to see how valprint handles this situation, then
> do the same thing here.
>
> Tom
>

Hi Tom,

Thanks for your help.
I make a new patch according to your mail.

Best,
Hui

2011-08-14  Hui Zhu  <teawater@gmail.com>

       * printcmd.c (ui_printf): Add a handler for internalvar and
TYPE_CODE_ARRAY.
---
 printcmd.c |   48 +++++++++++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 21 deletions(-)

--- a/printcmd.c
+++ b/printcmd.c
@@ -2343,32 +2343,38 @@ ui_printf (char *arg, struct ui_file *st
 	switch (argclass[i])
 	  {
 	  case string_arg:
-	    {
-	      gdb_byte *str;
-	      CORE_ADDR tem;
-	      int j;
+            if (VALUE_LVAL (val_args[i]) == lval_internalvar
+		&& TYPE_CODE (check_typedef (value_type (val_args[i])))
+		     == TYPE_CODE_ARRAY)
+	      fprintf_filtered (stream, current_substring,
+				(char *) value_contents (val_args[i]));
+	    else
+	      {
+	        gdb_byte *str;
+	        CORE_ADDR tem;
+	        int j;

-	      tem = value_as_address (val_args[i]);
+	        tem = value_as_address (val_args[i]);

-	      /* This is a %s argument.  Find the length of the string.  */
-	      for (j = 0;; j++)
-		{
-		  gdb_byte c;
+	        /* This is a %s argument.  Find the length of the string.  */
+	        for (j = 0;; j++)
+		  {
+		    gdb_byte c;

-		  QUIT;
-		  read_memory (tem + j, &c, 1);
-		  if (c == 0)
-		    break;
-		}
+		    QUIT;
+		    read_memory (tem + j, &c, 1);
+		    if (c == 0)
+		      break;
+		  }

-	      /* Copy the string contents into a string inside GDB.  */
-	      str = (gdb_byte *) alloca (j + 1);
-	      if (j != 0)
-		read_memory (tem, str, j);
-	      str[j] = 0;
+	        /* Copy the string contents into a string inside GDB.  */
+	        str = (gdb_byte *) alloca (j + 1);
+	        if (j != 0)
+		  read_memory (tem, str, j);
+	        str[j] = 0;

-              fprintf_filtered (stream, current_substring, (char *) str);
-	    }
+                fprintf_filtered (stream, current_substring, (char *) str);
+	      }
 	    break;
 	  case wide_string_arg:
 	    {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]