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]

[unavailable values part 1, 10/17] unavailable strings


With:

 const char string[] = "hello world";
 char string2[sizeof (string)];

 main ()
 {
   memcpy (string2, string, sizeof (string));
 ...
 }

 trace ...
 actions
 	collect string2[1]
 	collect string2[2]
            end

The bad:

 (gdb) p string2
 $1 = "\000el\000\000\000\000\000\000\000\000"

The simplest and most consistent with current behavior is to handle
it the same as optimized out strings are handled.  Print such
incomplete strings as an array:

The good:

 (gdb) p string2
 $1 = {<unavailable>, 101 'e', 108 'l', <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, 
   <unavailable>, <unavailable>, <unavailable>, <unavailable>}

That's what this patch does.

BTW, a test for this (forthcoming) needs to use a non-constant
string, as otherwise, GDB falls back to read the string from
live memory, and manages to print the whole "hello world".

-- 
Pedro Alves

2011-02-07  Pedro Alves  <pedro@codesourcery.com>

	gdb/
	* c-valprint.c (c_val_print): Print a string with unavailable
	contents as an array.

---
 gdb/c-valprint.c |    2 ++
 1 file changed, 2 insertions(+)

Index: src/gdb/c-valprint.c
===================================================================
--- src.orig/gdb/c-valprint.c	2011-02-07 10:54:23.076706000 +0000
+++ src/gdb/c-valprint.c	2011-02-07 11:15:33.786706001 +0000
@@ -187,6 +187,8 @@ c_val_print (struct type *type, const gd
 	     long as the entire array is valid.  */
           if (c_textual_element_type (unresolved_elttype,
 				      options->format)
+	      && value_bytes_available (original_value, embedded_offset,
+					TYPE_LENGTH (type))
 	      && value_bits_valid (original_value,
 				   TARGET_CHAR_BIT * embedded_offset,
 				   TARGET_CHAR_BIT * TYPE_LENGTH (type)))


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