aboutsummaryrefslogtreecommitdiff
path: root/gdb/c-valprint.c
diff options
context:
space:
mode:
authorDaniel Jacobowitz <drow@false.org>2007-09-05 00:51:49 +0000
committerDaniel Jacobowitz <drow@false.org>2007-09-05 00:51:49 +0000
commitea37ba09261f349ac2748da0d4f8f513184776f9 (patch)
treee809a75cbee45334e9521254235524a6394f406c /gdb/c-valprint.c
parentfcd776e5474bde02e7555b33ef57905eae0f7d3e (diff)
downloadgdb-ea37ba09261f349ac2748da0d4f8f513184776f9.zip
gdb-ea37ba09261f349ac2748da0d4f8f513184776f9.tar.gz
gdb-ea37ba09261f349ac2748da0d4f8f513184776f9.tar.bz2
* NEWS: Update description of string changes. Mention print/s.
* c-valprint.c (textual_element_type): New. (c_val_print): Use it. Do not skip address printing for pointers with a string format. (c_value_print): Doc update. * dwarf2read.c (read_array_type): Use make_vector_type. * gdbtypes.c (make_vector_type): New. (init_vector_type): Use it. (gdbtypes_post_init): Initialize builtin_true_unsigned_char. (_initialize_gdbtypes): Mark int8_t and uint8_t as TYPE_FLAG_NOTTEXT. * gdbtypes.h (struct builtin_type): Add builtin_true_unsigned_char. (TYPE_FLAG_NOTTEXT, TYPE_NOTTEXT): New. (make_vector_type): New. * printcmd.c (print_formatted): Only handle 's' and 'i' for examine. Call the language print routine for string format. (print_scalar_formatted): Call val_print for string format. Handle unsigned original types for char format. (validate_format): Do not reject string format. * stabsread.c (read_type): Use make_vector_type. * xml-tdesc.c (tdesc_start_vector): Use init_vector_type. * gdb.texinfo (Output Formats): Update 'c' description. Describe 's'. (Examining Memory): Update mentions of the 's' format. (Automatic Display): Likewise. * gdb.arch/i386-sse.exp: Do not expect character constants. * gdb.base/charsign.c, gdb.base/charsign.exp: Delete. * gdb.base/display.exp: Allow print/s. * gdb.base/printcmds.exp, gdb.base/setvar.exp: Revert signed and unsigned char array changes.
Diffstat (limited to 'gdb/c-valprint.c')
-rw-r--r--gdb/c-valprint.c72
1 files changed, 57 insertions, 15 deletions
diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index f060071..cd4c85a 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -54,6 +54,52 @@ print_function_pointer_address (CORE_ADDR address, struct ui_file *stream)
}
+/* Apply a heuristic to decide whether an array of TYPE or a pointer
+ to TYPE should be printed as a textual string. Return non-zero if
+ it should, or zero if it should be treated as an array of integers
+ or pointer to integers. FORMAT is the current format letter,
+ or 0 if none.
+
+ We guess that "char" is a character. Explicitly signed and
+ unsigned character types are also characters. Integer data from
+ vector types is not. The user can override this by using the /s
+ format letter. */
+
+static int
+textual_element_type (struct type *type, char format)
+{
+ struct type *true_type = check_typedef (type);
+
+ if (format != 0 && format != 's')
+ return 0;
+
+ /* TYPE_CODE_CHAR is always textual. */
+ if (TYPE_CODE (true_type) == TYPE_CODE_CHAR)
+ return 1;
+
+ if (format == 's')
+ {
+ /* Print this as a string if we can manage it. For now, no
+ wide character support. */
+ if (TYPE_CODE (true_type) == TYPE_CODE_INT
+ && TYPE_LENGTH (true_type) == 1)
+ return 1;
+ }
+ else
+ {
+ /* If a one-byte TYPE_CODE_INT is missing the not-a-character
+ flag, then we treat it as text; otherwise, we assume it's
+ being used as data. */
+ if (TYPE_CODE (true_type) == TYPE_CODE_INT
+ && TYPE_LENGTH (true_type) == 1
+ && !TYPE_NOTTEXT (true_type))
+ return 1;
+ }
+
+ return 0;
+}
+
+
/* Print data of type TYPE located at VALADDR (within GDB), which came from
the inferior at address ADDRESS, onto stdio stream STREAM according to
FORMAT (a letter or 0 for natural format). The data at VALADDR is in
@@ -92,12 +138,9 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
{
print_spaces_filtered (2 + 2 * recurse, stream);
}
- /* For an array of chars, print with string syntax. */
- if (eltlen == 1 &&
- ((TYPE_CODE (elttype) == TYPE_CODE_INT && TYPE_NOSIGN (elttype))
- || ((current_language->la_language == language_m2)
- && (TYPE_CODE (elttype) == TYPE_CODE_CHAR)))
- && (format == 0 || format == 's'))
+
+ /* Print arrays of textual chars with a string syntax. */
+ if (textual_element_type (elttype, format))
{
/* If requested, look for the first null char and only print
elements up to it. */
@@ -184,19 +227,16 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
return (0);
}
- if (addressprint && format != 's')
+ if (addressprint)
{
deprecated_print_address_numeric (addr, 1, stream);
}
- /* For a pointer to char or unsigned char, also print the string
+ /* For a pointer to a textual type, also print the string
pointed to, unless pointer is null. */
/* FIXME: need to handle wchar_t here... */
- if (TYPE_LENGTH (elttype) == 1
- && TYPE_CODE (elttype) == TYPE_CODE_INT
- && (format == 0 || format == 's')
- && addr != 0)
+ if (textual_element_type (elttype, format) && addr != 0)
{
i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream);
}
@@ -395,8 +435,8 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
/* C and C++ has no single byte int type, char is used instead.
Since we don't know whether the value is really intended to
be used as an integer or a character, print the character
- equivalent as well. */
- if (TYPE_LENGTH (type) == 1)
+ equivalent as well. */
+ if (textual_element_type (type, format))
{
fputs_filtered (" ", stream);
LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr + embedded_offset),
@@ -498,7 +538,9 @@ c_value_print (struct value *val, struct ui_file *stream, int format,
|| TYPE_CODE (type) == TYPE_CODE_REF)
{
/* Hack: remove (char *) for char strings. Their
- type is indicated by the quoted string anyway. */
+ type is indicated by the quoted string anyway.
+ (Don't use textual_element_type here; quoted strings
+ are always exactly (char *). */
if (TYPE_CODE (type) == TYPE_CODE_PTR
&& TYPE_NAME (type) == NULL
&& TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL