Use common_val_print in c-valprint.c
This changes c_value_print to call common_val_print. This is more complicated than the usual sort of common_val_print change, due to the handling of RTTI. gdb/ChangeLog 2020-03-13 Tom Tromey <tom@tromey.com> * c-valprint.c (c_value_print): Use common_val_print. gdb/testsuite/ChangeLog 2020-03-13 Tom Tromey <tom@tromey.com> * gdb.base/printcmds.exp (test_print_strings): Add regression test. * gdb.base/printcmds.c (charptr): New typedef. (teststring2): New global.
This commit is contained in:
parent
410cf31501
commit
a1f6a07c3d
5 changed files with 37 additions and 37 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
2020-03-13 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* c-valprint.c (c_value_print): Use common_val_print.
|
||||||
|
|
||||||
2020-03-13 Tom Tromey <tom@tromey.com>
|
2020-03-13 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* cp-valprint.c (cp_print_static_field): Use common_val_print.
|
* cp-valprint.c (cp_print_static_field): Use common_val_print.
|
||||||
|
|
|
@ -567,7 +567,7 @@ void
|
||||||
c_value_print (struct value *val, struct ui_file *stream,
|
c_value_print (struct value *val, struct ui_file *stream,
|
||||||
const struct value_print_options *options)
|
const struct value_print_options *options)
|
||||||
{
|
{
|
||||||
struct type *type, *real_type, *val_type;
|
struct type *type, *real_type;
|
||||||
int full, using_enc;
|
int full, using_enc;
|
||||||
LONGEST top;
|
LONGEST top;
|
||||||
struct value_print_options opts = *options;
|
struct value_print_options opts = *options;
|
||||||
|
@ -581,24 +581,22 @@ c_value_print (struct value *val, struct ui_file *stream,
|
||||||
C++: if it is a member pointer, we will take care
|
C++: if it is a member pointer, we will take care
|
||||||
of that when we print it. */
|
of that when we print it. */
|
||||||
|
|
||||||
/* Preserve the original type before stripping typedefs. We prefer
|
type = check_typedef (value_type (val));
|
||||||
to pass down the original type when possible, but for local
|
|
||||||
checks it is better to look past the typedefs. */
|
|
||||||
val_type = value_type (val);
|
|
||||||
type = check_typedef (val_type);
|
|
||||||
|
|
||||||
if (TYPE_CODE (type) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (type))
|
if (TYPE_CODE (type) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (type))
|
||||||
{
|
{
|
||||||
|
struct type *original_type = value_type (val);
|
||||||
|
|
||||||
/* Hack: remove (char *) for char strings. Their
|
/* 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 c_textual_element_type here; quoted strings
|
(Don't use c_textual_element_type here; quoted strings
|
||||||
are always exactly (char *), (wchar_t *), or the like. */
|
are always exactly (char *), (wchar_t *), or the like. */
|
||||||
if (TYPE_CODE (val_type) == TYPE_CODE_PTR
|
if (TYPE_CODE (original_type) == TYPE_CODE_PTR
|
||||||
&& TYPE_NAME (val_type) == NULL
|
&& TYPE_NAME (original_type) == NULL
|
||||||
&& TYPE_NAME (TYPE_TARGET_TYPE (val_type)) != NULL
|
&& TYPE_NAME (TYPE_TARGET_TYPE (original_type)) != NULL
|
||||||
&& (strcmp (TYPE_NAME (TYPE_TARGET_TYPE (val_type)),
|
&& (strcmp (TYPE_NAME (TYPE_TARGET_TYPE (original_type)),
|
||||||
"char") == 0
|
"char") == 0
|
||||||
|| textual_name (TYPE_NAME (TYPE_TARGET_TYPE (val_type)))))
|
|| textual_name (TYPE_NAME (TYPE_TARGET_TYPE (original_type)))))
|
||||||
{
|
{
|
||||||
/* Print nothing. */
|
/* Print nothing. */
|
||||||
}
|
}
|
||||||
|
@ -624,7 +622,6 @@ c_value_print (struct value *val, struct ui_file *stream,
|
||||||
if (real_type)
|
if (real_type)
|
||||||
{
|
{
|
||||||
/* RTTI entry found. */
|
/* RTTI entry found. */
|
||||||
type = real_type;
|
|
||||||
|
|
||||||
/* Need to adjust pointer value. */
|
/* Need to adjust pointer value. */
|
||||||
val = value_from_pointer (real_type,
|
val = value_from_pointer (real_type,
|
||||||
|
@ -637,14 +634,11 @@ c_value_print (struct value *val, struct ui_file *stream,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_ref)
|
if (is_ref)
|
||||||
{
|
|
||||||
val = value_ref (value_ind (val), refcode);
|
val = value_ref (value_ind (val), refcode);
|
||||||
type = value_type (val);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
type = value_type (val);
|
||||||
type_print (type, "", stream, -1);
|
type_print (type, "", stream, -1);
|
||||||
fprintf_filtered (stream, ") ");
|
fprintf_filtered (stream, ") ");
|
||||||
val_type = type;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -667,36 +661,25 @@ c_value_print (struct value *val, struct ui_file *stream,
|
||||||
/* We have RTTI information, so use it. */
|
/* We have RTTI information, so use it. */
|
||||||
val = value_full_object (val, real_type,
|
val = value_full_object (val, real_type,
|
||||||
full, top, using_enc);
|
full, top, using_enc);
|
||||||
|
/* In a destructor we might see a real type that is a
|
||||||
|
superclass of the object's type. In this case it is
|
||||||
|
better to leave the object as-is. */
|
||||||
|
if (!(full
|
||||||
|
&& (TYPE_LENGTH (real_type)
|
||||||
|
< TYPE_LENGTH (value_enclosing_type (val)))))
|
||||||
|
val = value_cast (real_type, val);
|
||||||
fprintf_filtered (stream, "(%s%s) ",
|
fprintf_filtered (stream, "(%s%s) ",
|
||||||
TYPE_NAME (real_type),
|
TYPE_NAME (real_type),
|
||||||
full ? "" : _(" [incomplete object]"));
|
full ? "" : _(" [incomplete object]"));
|
||||||
/* Print out object: enclosing type is same as real_type if
|
|
||||||
full. */
|
|
||||||
val_print (value_enclosing_type (val),
|
|
||||||
0,
|
|
||||||
value_address (val), stream, 0,
|
|
||||||
val, &opts, current_language);
|
|
||||||
return;
|
|
||||||
/* Note: When we look up RTTI entries, we don't get any
|
|
||||||
information on const or volatile attributes. */
|
|
||||||
}
|
}
|
||||||
else if (type != check_typedef (value_enclosing_type (val)))
|
else if (type != check_typedef (value_enclosing_type (val)))
|
||||||
{
|
{
|
||||||
/* No RTTI information, so let's do our best. */
|
/* No RTTI information, so let's do our best. */
|
||||||
fprintf_filtered (stream, "(%s ?) ",
|
fprintf_filtered (stream, "(%s ?) ",
|
||||||
TYPE_NAME (value_enclosing_type (val)));
|
TYPE_NAME (value_enclosing_type (val)));
|
||||||
val_print (value_enclosing_type (val),
|
val = value_cast (value_enclosing_type (val), val);
|
||||||
0,
|
|
||||||
value_address (val), stream, 0,
|
|
||||||
val, &opts, current_language);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
/* Otherwise, we end up at the return outside this "if". */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val_print (val_type,
|
common_val_print (val, stream, 0, &opts, current_language);
|
||||||
value_embedded_offset (val),
|
|
||||||
value_address (val),
|
|
||||||
stream, 0,
|
|
||||||
val, &opts, current_language);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
2020-03-13 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* gdb.base/printcmds.exp (test_print_strings): Add regression
|
||||||
|
test.
|
||||||
|
* gdb.base/printcmds.c (charptr): New typedef.
|
||||||
|
(teststring2): New global.
|
||||||
|
|
||||||
2020-03-13 Andrew Burgess <andrew.burgess@embecosm.com>
|
2020-03-13 Andrew Burgess <andrew.burgess@embecosm.com>
|
||||||
|
|
||||||
* gdb.base/break-interp.exp: Use the tail of the filename, not the
|
* gdb.base/break-interp.exp: Use the tail of the filename, not the
|
||||||
|
|
|
@ -72,6 +72,9 @@ int int4dim[1][2][3][2] = {{{{0,1},{2,3},{4,5}},{{6,7},{8,9},{10,11}}}};
|
||||||
|
|
||||||
char *teststring = (char*)"teststring contents";
|
char *teststring = (char*)"teststring contents";
|
||||||
|
|
||||||
|
typedef char *charptr;
|
||||||
|
charptr teststring2 = "more contents";
|
||||||
|
|
||||||
/* Test printing of a struct containing character arrays. */
|
/* Test printing of a struct containing character arrays. */
|
||||||
|
|
||||||
struct some_arrays {
|
struct some_arrays {
|
||||||
|
|
|
@ -519,6 +519,9 @@ proc test_print_strings {} {
|
||||||
gdb_test "p teststring" \
|
gdb_test "p teststring" \
|
||||||
" = (.unsigned char .. )?\"teststring contents\"" "p teststring with elements set to 20"
|
" = (.unsigned char .. )?\"teststring contents\"" "p teststring with elements set to 20"
|
||||||
|
|
||||||
|
gdb_test "print teststring2" \
|
||||||
|
" = (charptr) \"more contents\""
|
||||||
|
|
||||||
gdb_test_no_output "set print elements 8"
|
gdb_test_no_output "set print elements 8"
|
||||||
|
|
||||||
# Set the target-charset to ASCII, because the output varies from
|
# Set the target-charset to ASCII, because the output varies from
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue