Fix value_print, which used to be ostensibly langauge-indepentdent,

but would print pointers and arrays in C syntax.  Instead, call
	a language-specific function.  See ChangeLog for details.
This commit is contained in:
Per Bothner 1994-06-05 01:43:40 +00:00
parent c4d7d826d7
commit e10cfcaa37
10 changed files with 216 additions and 1 deletions

View File

@ -1,3 +1,32 @@
Sat Jun 4 18:17:03 1994 Per Bothner (bothner@kalessin.cygnus.com)
Fix value_print, which used to be ostensibly langauge-indepentdent,
but would print pointers and arrays in C syntax. Instead, call
a language-specific function.
* language.h (struct language_defn): New functional field
la_value_print. (LA_VALUE_PRINT): New macro.
* language.c (unk_lang_value_print ): New stub/dummy function.
(unknown_language_defn, auto_language_defn, local_language_defn):
Use it.
* c-valprint.c (c_value_print): New function, with code moved from:
* valprint.c (value_print): ... here. Now just invoke
LA_VALUE_PRINT to do language-specific stuff.
* valprint.c (value_print_array_elements): Make non-static.
* c-lang.c (c_language_defn, cplus_language_defn): Add
c_value_print in the la_value_print field,
* m2-lang.c (m2_language_defn): Likewise.
* ch-lang.c (chill_language_defn): But here use chill_value_print.
* ch-valprint.c (chill_val_print): Print null pointer as NULL.
* ch-valprint.c (chill_value_print): New function, based on
c_value_print, but use Chill "look and feel."
* c-lang.h (c_value_print): New prototype.
* ch-lang.h (chill_value_print): New prototype.
* value.h (value_print_array_elements): New prototype.
* ch-valprint.c (chill_val_print, case TYPE_CODE_BITSTRING
and case TYPE_CODE_SET): Check that the element type isn't a stub.
Fri Jun 3 09:15:00 1994 Jim Kingdon (kingdon@lioth.cygnus.com)
* main.c: Move entire file except for #ifndef MAIN_OVERRIDE code

View File

@ -404,6 +404,7 @@ const struct language_defn c_language_defn = {
c_create_fundamental_type, /* Create fundamental type in this language */
c_print_type, /* Print a type using appropriate syntax */
c_val_print, /* Print a value using appropriate syntax */
c_value_print, /* Print a top-level value */
&builtin_type_double, /* longest floating point type */ /*FIXME*/
{"", "", "", ""}, /* Binary format info */
{"0%lo", "0", "o", ""}, /* Octal format info */
@ -426,6 +427,7 @@ const struct language_defn cplus_language_defn = {
c_create_fundamental_type, /* Create fundamental type in this language */
c_print_type, /* Print a type using appropriate syntax */
c_val_print, /* Print a value using appropriate syntax */
c_value_print, /* Print a top-level value */
&builtin_type_double, /* longest floating point type */ /*FIXME*/
{"", "", "", ""}, /* Binary format info */
{"0%lo", "0", "o", ""}, /* Octal format info */

View File

@ -17,6 +17,10 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef __STDC__ /* Forward decls for prototypes */
struct value;
#endif
extern int
c_parse PARAMS ((void)); /* Defined in c-exp.y */
@ -29,3 +33,6 @@ c_print_type PARAMS ((struct type *, char *, GDB_FILE *, int, int));
extern int
c_val_print PARAMS ((struct type *, char *, CORE_ADDR, GDB_FILE *, int, int,
int, enum val_prettyprint));
extern int
c_value_print PARAMS ((struct value *, GDB_FILE *, int, enum val_prettyprint));

View File

@ -434,3 +434,64 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
gdb_flush (stream);
return (0);
}
int
c_value_print (val, stream, format, pretty)
value_ptr val;
GDB_FILE *stream;
int format;
enum val_prettyprint pretty;
{
/* A "repeated" value really contains several values in a row.
They are made by the @ operator.
Print such values as if they were arrays. */
if (VALUE_REPEATED (val))
{
register unsigned int n = VALUE_REPETITIONS (val);
register unsigned int typelen = TYPE_LENGTH (VALUE_TYPE (val));
fprintf_filtered (stream, "{");
/* Print arrays of characters using string syntax. */
if (typelen == 1 && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT
&& format == 0)
LA_PRINT_STRING (stream, VALUE_CONTENTS (val), n, 0);
else
{
value_print_array_elements (val, stream, format, pretty);
}
fprintf_filtered (stream, "}");
return (n * typelen);
}
else
{
struct type *type = VALUE_TYPE (val);
/* If it is a pointer, indicate what it points to.
Print type also if it is a reference.
C++: if it is a member pointer, we will take care
of that when we print it. */
if (TYPE_CODE (type) == TYPE_CODE_PTR ||
TYPE_CODE (type) == TYPE_CODE_REF)
{
/* Hack: remove (char *) for char strings. Their
type is indicated by the quoted string anyway. */
if (TYPE_CODE (type) == TYPE_CODE_PTR &&
TYPE_LENGTH (TYPE_TARGET_TYPE (type)) == sizeof(char) &&
TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_INT &&
!TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)))
{
/* Print nothing */
}
else
{
fprintf_filtered (stream, "(");
type_print (type, "", stream, -1);
fprintf_filtered (stream, ") ");
}
}
return (val_print (type, VALUE_CONTENTS (val),
VALUE_ADDRESS (val), stream, format, 1, 0, pretty));
}
}

View File

@ -315,6 +315,7 @@ const struct language_defn chill_language_defn = {
chill_create_fundamental_type,/* Create fundamental type in this language */
chill_print_type, /* Print a type using appropriate syntax */
chill_val_print, /* Print a value using appropriate syntax */
chill_value_print, /* Print a top-levl value */
&builtin_type_chill_real, /* longest floating point type */
{"", "B'", "", ""}, /* Binary format info */
{"O'%lo", "O'", "o", ""}, /* Octal format info */

View File

@ -17,6 +17,10 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef __STDC__ /* Forward decls for prototypes */
struct value;
#endif
extern int
chill_parse PARAMS ((void)); /* Defined in ch-exp.y */
@ -30,6 +34,10 @@ extern int
chill_val_print PARAMS ((struct type *, char *, CORE_ADDR, GDB_FILE *, int, int,
int, enum val_prettyprint));
extern int
chill_value_print PARAMS ((struct value *, GDB_FILE *,
int, enum val_prettyprint));
extern int
chill_is_varying_struct PARAMS ((struct type *type));

View File

@ -242,6 +242,13 @@ chill_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
}
addr = unpack_pointer (type, valaddr);
elttype = TYPE_TARGET_TYPE (type);
/* We assume a NULL pointer is all zeros ... */
if (addr == 0)
{
fputs_filtered ("NULL", stream);
return 0;
}
if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
{
@ -287,8 +294,16 @@ chill_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
case TYPE_CODE_BITSTRING:
case TYPE_CODE_SET:
elttype = TYPE_FIELD_TYPE (type, 0);
check_stub_type (elttype);
if (TYPE_FLAGS (elttype) & TYPE_FLAG_STUB)
{
fprintf_filtered (stream, "<incomplete type>");
gdb_flush (stream);
break;
}
{
struct type *range = TYPE_FIELD_TYPE (type, 0);
struct type *range = elttype;
int low_bound = TYPE_LOW_BOUND (range);
int high_bound = TYPE_HIGH_BOUND (range);
int i;
@ -494,3 +509,73 @@ chill_print_value_fields (type, valaddr, stream, format, recurse, pretty,
}
fprintf_filtered (stream, "]");
}
int
chill_value_print (val, stream, format, pretty)
value_ptr val;
GDB_FILE *stream;
int format;
enum val_prettyprint pretty;
{
/* A "repeated" value really contains several values in a row.
They are made by the @ operator.
Print such values as if they were arrays. */
if (VALUE_REPEATED (val))
{
register unsigned int n = VALUE_REPETITIONS (val);
register unsigned int typelen = TYPE_LENGTH (VALUE_TYPE (val));
fprintf_filtered (stream, "[");
/* Print arrays of characters using string syntax. */
if (typelen == 1 && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT
&& format == 0)
LA_PRINT_STRING (stream, VALUE_CONTENTS (val), n, 0);
else
{
value_print_array_elements (val, stream, format, pretty);
}
fprintf_filtered (stream, "]");
return (n * typelen);
}
else
{
struct type *type = VALUE_TYPE (val);
/* If it is a pointer, indicate what it points to.
Print type also if it is a reference.
C++: if it is a member pointer, we will take care
of that when we print it. */
if (TYPE_CODE (type) == TYPE_CODE_PTR ||
TYPE_CODE (type) == TYPE_CODE_REF)
{
char *valaddr = VALUE_CONTENTS (val);
CORE_ADDR addr = unpack_pointer (type, valaddr);
if (TYPE_CODE (type) != TYPE_CODE_PTR || addr != 0)
{
int i;
char *name = TYPE_NAME (type);
if (name)
fputs_filtered (name, stream);
else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID)
fputs_filtered ("PTR", stream);
else
{
fprintf_filtered (stream, "(");
type_print (type, "", stream, -1);
fprintf_filtered (stream, ")");
}
fprintf_filtered (stream, "(");
i = val_print (type, valaddr, VALUE_ADDRESS (val),
stream, format, 1, 0, pretty);
fprintf_filtered (stream, ")");
return i;
}
}
return (val_print (type, VALUE_CONTENTS (val),
VALUE_ADDRESS (val), stream, format, 1, 0, pretty));
}
}

View File

@ -1165,6 +1165,16 @@ unk_lang_val_print (type, valaddr, address, stream, format, deref_ref,
error ("internal error - unimplemented function unk_lang_val_print called.");
}
int
unk_lang_value_print (val, stream, format, pretty)
value_ptr val;
GDB_FILE *stream;
int format;
enum val_prettyprint pretty;
{
error ("internal error - unimplemented function unk_lang_value_print called.");
}
static struct type ** const (unknown_builtin_types[]) = { 0 };
static const struct op_print unk_op_print_tab[] = {
{NULL, OP_NULL, PREC_NULL, 0}
@ -1183,6 +1193,7 @@ const struct language_defn unknown_language_defn = {
unk_lang_create_fundamental_type,
unk_lang_print_type, /* Print a type using appropriate syntax */
unk_lang_val_print, /* Print a value using appropriate syntax */
unk_lang_value_print, /* Print a top-level value */
&builtin_type_error, /* longest floating point type */
{"", "", "", ""}, /* Binary format info */
{"0%lo", "0", "o", ""}, /* Octal format info */
@ -1206,6 +1217,7 @@ const struct language_defn auto_language_defn = {
unk_lang_create_fundamental_type,
unk_lang_print_type, /* Print a type using appropriate syntax */
unk_lang_val_print, /* Print a value using appropriate syntax */
unk_lang_value_print, /* Print a top-level value */
&builtin_type_error, /* longest floating point type */
{"", "", "", ""}, /* Binary format info */
{"0%lo", "0", "o", ""}, /* Octal format info */
@ -1228,6 +1240,7 @@ const struct language_defn local_language_defn = {
unk_lang_create_fundamental_type,
unk_lang_print_type, /* Print a type using appropriate syntax */
unk_lang_val_print, /* Print a value using appropriate syntax */
unk_lang_value_print, /* Print a top-level value */
&builtin_type_error, /* longest floating point type */
{"", "", "", ""}, /* Binary format info */
{"0%lo", "0", "o", ""}, /* Octal format info */

View File

@ -144,6 +144,11 @@ struct language_defn
int (*la_val_print) PARAMS ((struct type *, char *, CORE_ADDR, GDB_FILE *,
int, int, int, enum val_prettyprint));
/* Print a top-level value using syntax appropriate for this language. */
int (*la_value_print) PARAMS ((struct value *, GDB_FILE *,
int, enum val_prettyprint));
/* Longest floating point type */
struct type **la_longest_float;
@ -247,6 +252,8 @@ set_language PARAMS ((enum language));
#define LA_VAL_PRINT(type,valaddr,addr,stream,fmt,deref,recurse,pretty) \
(current_language->la_val_print(type,valaddr,addr,stream,fmt,deref, \
recurse,pretty))
#define LA_VALUE_PRINT(val,stream,fmt,pretty) \
(current_language->la_value_print(val,stream,fmt,pretty))
/* Return a format string for printf that will print a number in one of
the local (language-specific) formats. Result is static and is

View File

@ -24,6 +24,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "parser-defs.h"
#include "language.h"
#include "m2-lang.h"
#include "c-lang.h"
/* Print the character C on STREAM as part of the contents of a literal
string whose delimiter is QUOTER. Note that that format for printing
@ -405,6 +406,7 @@ const struct language_defn m2_language_defn = {
m2_create_fundamental_type, /* Create fundamental type in this language */
m2_print_type, /* Print a type using appropriate syntax */
m2_val_print, /* Print a value using appropriate syntax */
c_value_print, /* Print a top-level value */
&builtin_type_m2_real, /* longest floating point type */
{"", "", "", ""}, /* Binary format info */
{"%loB", "", "o", "B"}, /* Octal format info */