This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[unavailable values part 1, 10/17] unavailable strings
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 7 Feb 2011 14:32:32 +0000
- Subject: [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)))