From e2aab0314f833f6b930a5aaae4a93024a41dc1a0 Mon Sep 17 00:00:00 2001 From: Fred Fish Date: Thu, 24 Oct 1991 10:58:41 +0000 Subject: [PATCH] Add three new builtin types (builtin_type_long_double, builtin_type_complex, and builtin_type_double_complex). Also add and use various TARGET__BIT macros to indicate the sizes of various types on the target machine. --- gdb/ChangeLog | 8 ++++++ gdb/c-exp.y | 76 +++++++++++++++++++++++++++++++++++--------------- gdb/defs.h | 64 +++++++++++++++++++++++++++++++++++++----- gdb/symtab.h | 3 ++ gdb/valprint.c | 73 ++++++++++++++++++++++++++++-------------------- 5 files changed, 163 insertions(+), 61 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9849e0e4866..a97914b4c68 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,13 @@ Thu Oct 24 01:32:51 1991 Fred Fish (fnf at cygnus.com) + * c-exp.y, defs.h, symtab.h, valprint.c: Add three new builtin + types to gdb, builtin_type_long_double, builtin_type_complex, and + builtin_type_double_complex. Add and use new TARGET_SHORT_BIT, + TARGET_INT_BIT, TARGET_LONG_BIT, TARGET_FLOAT_BIT, + TARGET_DOUBLE_BIT, TARGET_LONG_DOUBLE_BIT, TARGET_COMPLEX_BIT, and + TARGET_DOUBLE_COMPLEX_BIT, as the sizes in bits of the indicated + types on the target machine (ala the existing TARGET_LONG_LONG_BIT). + * infrun.c: When using SVR4 /proc interface instead of ptrace(), call proc_set_exec_trap() to setup child to stop at first instruction. diff --git a/gdb/c-exp.y b/gdb/c-exp.y index b243e5cb51c..ec2bde99042 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -1455,6 +1455,9 @@ struct type *builtin_type_unsigned_long; struct type *builtin_type_unsigned_long_long; struct type *builtin_type_float; struct type *builtin_type_double; +struct type *builtin_type_long_double; +struct type *builtin_type_complex; +struct type *builtin_type_double_complex; struct type ** const (c_builtin_types[]) = { @@ -1471,6 +1474,9 @@ struct type ** const (c_builtin_types[]) = &builtin_type_unsigned_int, &builtin_type_unsigned_long, &builtin_type_unsigned_long_long, + &builtin_type_long_double, + &builtin_type_complex, + &builtin_type_double_complex, 0 }; @@ -1486,7 +1492,7 @@ const struct language_defn c_language_defn = { c_error, &BUILTIN_TYPE_LONGEST, /* longest signed integral type */ &BUILTIN_TYPE_UNSIGNED_LONGEST,/* longest unsigned integral type */ - &builtin_type_double, /* longest floating point type */ + &builtin_type_double, /* longest floating point type */ /*FIXME*/ "0x%x", "0x%", "x", /* Hex format, prefix, suffix */ "0%o", "0%", "o", /* Octal format, prefix, suffix */ c_op_print_tab, /* expression operators for printing */ @@ -1496,30 +1502,54 @@ const struct language_defn c_language_defn = { void _initialize_c_exp () { - /* FIXME: The code below assumes that the sizes of the basic data - types are the same on the host and target machines!!! */ - - builtin_type_void = init_type (TYPE_CODE_VOID, 1, 0, "void"); - - builtin_type_float = init_type (TYPE_CODE_FLT, sizeof (float), 0, "float"); - builtin_type_double = init_type (TYPE_CODE_FLT, sizeof (double), 0, "double"); - - builtin_type_char = init_type (TYPE_CODE_INT, sizeof (char), 0, "char"); - builtin_type_short = init_type (TYPE_CODE_INT, sizeof (short), 0, "short"); - builtin_type_long = init_type (TYPE_CODE_INT, sizeof (long), 0, "long"); - builtin_type_int = init_type (TYPE_CODE_INT, sizeof (int), 0, "int"); - - builtin_type_unsigned_char = init_type (TYPE_CODE_INT, sizeof (char), 1, "unsigned char"); - builtin_type_unsigned_short = init_type (TYPE_CODE_INT, sizeof (short), 1, "unsigned short"); - builtin_type_unsigned_long = init_type (TYPE_CODE_INT, sizeof (long), 1, "unsigned long"); - builtin_type_unsigned_int = init_type (TYPE_CODE_INT, sizeof (int), 1, "unsigned int"); - + builtin_type_void = + init_type (TYPE_CODE_VOID, 1, 0, + "void"); + builtin_type_char = + init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, 0, + "char"); + builtin_type_unsigned_char = + init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, 1, + "unsigned char"); + builtin_type_short = + init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, 0, + "short"); + builtin_type_unsigned_short = + init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, 1, + "unsigned short"); + builtin_type_int = + init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, 0, + "int"); + builtin_type_unsigned_int = + init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, 1, + "unsigned int"); + builtin_type_long = + init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, 0, + "long"); + builtin_type_unsigned_long = + init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, 1, + "unsigned long"); builtin_type_long_long = - init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, - 0, "long long"); + init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, 0, + "long long"); builtin_type_unsigned_long_long = - init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, - 1, "unsigned long long"); + init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, 1, + "unsigned long long"); + builtin_type_float = + init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT, 0, + "float"); + builtin_type_double = + init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, 0, + "double"); + builtin_type_long_double = + init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, 0, + "long double"); + builtin_type_complex = + init_type (TYPE_CODE_FLT, TARGET_COMPLEX_BIT / TARGET_CHAR_BIT, 0, + "complex"); + builtin_type_double_complex = + init_type (TYPE_CODE_FLT, TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT, 0, + "double complex"); add_language (&c_language_defn); set_language (language_c); /* Make C the default language */ diff --git a/gdb/defs.h b/gdb/defs.h index 5d364a232ea..52d84960202 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -202,15 +202,55 @@ char *baud_rate; #define INT_MIN -0x80000000 #endif -/* Just like CHAR_BIT in but describes the target machine. */ +/* Number of bits in a char or unsigned char for the target machine. + Just like CHAR_BIT in but describes the target machine. */ #if !defined (TARGET_CHAR_BIT) #define TARGET_CHAR_BIT 8 #endif -/* Number of bits in a long long or unsigned long long - for the target machine. */ +/* Number of bits in a short or unsigned short for the target machine. */ +#if !defined (TARGET_SHORT_BIT) +#define TARGET_SHORT_BIT (sizeof (short) * TARGET_CHAR_BIT) +#endif + +/* Number of bits in an int or unsigned int for the target machine. */ +#if !defined (TARGET_INT_BIT) +#define TARGET_INT_BIT (sizeof (int) * TARGET_CHAR_BIT) +#endif + +/* Number of bits in a long or unsigned long for the target machine. */ +#if !defined (TARGET_LONG_BIT) +#define TARGET_LONG_BIT (sizeof (long) * TARGET_CHAR_BIT) +#endif + +/* Number of bits in a long long or unsigned long long for the target machine. */ #if !defined (TARGET_LONG_LONG_BIT) -#define TARGET_LONG_LONG_BIT 64 +#define TARGET_LONG_LONG_BIT (2 * TARGET_LONG_BIT) +#endif + +/* Number of bits in a float for the target machine. */ +#if !defined (TARGET_FLOAT_BIT) +#define TARGET_FLOAT_BIT (sizeof (float) * TARGET_CHAR_BIT) +#endif + +/* Number of bits in a double for the target machine. */ +#if !defined (TARGET_DOUBLE_BIT) +#define TARGET_DOUBLE_BIT (sizeof (double) * TARGET_CHAR_BIT) +#endif + +/* Number of bits in a long double for the target machine. */ +#if !defined (TARGET_LONG_DOUBLE_BIT) +#define TARGET_LONG_DOUBLE_BIT (2 * TARGET_DOUBLE_BIT) +#endif + +/* Number of bits in a "complex" for the target machine. */ +#if !defined (TARGET_COMPLEX_BIT) +#define TARGET_COMPLEX_BIT (2 * TARGET_FLOAT_BIT) +#endif + +/* Number of bits in a "double complex" for the target machine. */ +#if !defined (TARGET_DOUBLE_COMPLEX_BIT) +#define TARGET_DOUBLE_COMPLEX_BIT (2 * TARGET_DOUBLE_BIT) #endif /* Convert a LONGEST to an int. This is used in contexts (e.g. number @@ -227,12 +267,22 @@ char *baud_rate; #endif /* No LONG_LONG. */ #endif /* No longest_to_int. */ +/* Languages represented in the symbol table and elsewhere. */ + +enum language +{ + language_unknown, /* Language not known */ + language_auto, /* Placeholder for automatic setting */ + language_c, /* C */ + language_m2, /* Modula-2 */ +}; + /* Return a format string for printf that will print a number in the local (language-specific) hexadecimal format. Result is static and is overwritten by the next call. local_hex_format_custom takes printf options like "08" or "l" (to produce e.g. %08x or %lx). */ -#define local_hex_format() local_hex_format_custom("") +#define local_hex_format() (current_language->la_hex_format) char *local_hex_format_custom(); /* language.c */ /* Return a string that contains a number formatted in the local @@ -240,7 +290,7 @@ char *local_hex_format_custom(); /* language.c */ overwritten by the next call. local_hex_string_custom takes printf options like "08" or "l". */ -#define local_hex_string(n) local_hex_string_custom((n),"") -char *local_hex_string_custom(); /* language.c */ +char *local_hex_string (); /* language.c */ +char *local_hex_string_custom (); /* language.c */ #endif /* no DEFS_H */ diff --git a/gdb/symtab.h b/gdb/symtab.h index b29f4402e6c..1f8ff418acc 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -826,6 +826,9 @@ extern struct type *builtin_type_unsigned_int; extern struct type *builtin_type_unsigned_long; extern struct type *builtin_type_float; extern struct type *builtin_type_double; +extern struct type *builtin_type_long_double; +extern struct type *builtin_type_complex; +extern struct type *builtin_type_double_complex; /* This type represents a type that was unrecognized in symbol read-in. */ extern struct type *builtin_type_error; diff --git a/gdb/valprint.c b/gdb/valprint.c index 246c66a6142..f893eda4d3e 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -1212,6 +1212,11 @@ val_print (type, valaddr, address, stream, format, fprintf_filtered (stream, "?"); break; + case TYPE_CODE_RANGE: + /* FIXME, we should not ever have to print one of these yet. */ + fprintf_filtered (stream, ""); + break; + default: error ("Invalid type code in symbol table."); } @@ -1599,7 +1604,7 @@ type_print_base (type, stream, show, level) wrap_here (" "); if (type == 0) { - fprintf_filtered (stream, "type unknown"); + fprintf_filtered (stream, ""); return; } @@ -1813,14 +1818,19 @@ type_print_base (type, stream, show, level) fprintf_filtered (stream, "void"); break; - case 0: - fprintf_filtered (stream, "struct unknown"); + case TYPE_CODE_UNDEF: + fprintf_filtered (stream, "struct "); break; case TYPE_CODE_ERROR: fprintf_filtered (stream, ""); break; + case TYPE_CODE_RANGE: + /* This should not occur */ + fprintf_filtered (stream, ""); + break; + default: error ("Invalid type code in symbol table."); } @@ -2017,35 +2027,36 @@ _initialize_valprint () print_max = 200; - /* FIXME! This assumes that these sizes and types are the same on the - host and target machines! */ - unsigned_type_table - = (char **) xmalloc ((1 + sizeof (unsigned LONGEST)) * sizeof (char *)); - bzero (unsigned_type_table, (1 + sizeof (unsigned LONGEST))); - unsigned_type_table[sizeof (unsigned char)] = "unsigned char"; - unsigned_type_table[sizeof (unsigned short)] = "unsigned short"; - unsigned_type_table[sizeof (unsigned long)] = "unsigned long"; - unsigned_type_table[sizeof (unsigned int)] = "unsigned int"; -#ifdef LONG_LONG - unsigned_type_table[TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT] = - "unsigned long long"; -#endif - - signed_type_table - = (char **) xmalloc ((1 + sizeof (LONGEST)) * sizeof (char *)); - bzero (signed_type_table, (1 + sizeof (LONGEST))); - signed_type_table[sizeof (char)] = "char"; - signed_type_table[sizeof (short)] = "short"; - signed_type_table[sizeof (long)] = "long"; - signed_type_table[sizeof (int)] = "int"; -#ifdef LONG_LONG + /* Initialize the names of the various types based on their lengths on + the target, in bits. Note that ordering is important, so that for example, + if ints and longs are the same size, that size will default to "int". */ + + unsigned_type_table = (char **) + xmalloc ((1 + (TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT)) * sizeof (char *)); + bzero (unsigned_type_table, (1 + (TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT))); + unsigned_type_table[TARGET_CHAR_BIT/TARGET_CHAR_BIT] = "unsigned char"; + unsigned_type_table[TARGET_SHORT_BIT/TARGET_CHAR_BIT] = "unsigned short"; + unsigned_type_table[TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT] = "unsigned long long"; + unsigned_type_table[TARGET_LONG_BIT/TARGET_CHAR_BIT] = "unsigned long"; + unsigned_type_table[TARGET_INT_BIT/TARGET_CHAR_BIT] = "unsigned int"; + + signed_type_table = (char **) + xmalloc ((1 + (TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT)) * sizeof (char *)); + bzero (signed_type_table, (1 + (TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT))); + signed_type_table[TARGET_CHAR_BIT/TARGET_CHAR_BIT] = "char"; + signed_type_table[TARGET_SHORT_BIT/TARGET_CHAR_BIT] = "short"; signed_type_table[TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT] = "long long"; -#endif + signed_type_table[TARGET_LONG_BIT/TARGET_CHAR_BIT] = "long"; + signed_type_table[TARGET_INT_BIT/TARGET_CHAR_BIT] = "int"; + + float_type_table = (char **) + xmalloc ((1 + (TARGET_LONG_DOUBLE_BIT/TARGET_CHAR_BIT)) * sizeof (char *)); + bzero (float_type_table, (1 + (TARGET_LONG_DOUBLE_BIT/TARGET_CHAR_BIT))); + float_type_table[TARGET_FLOAT_BIT/TARGET_CHAR_BIT] = "float"; + float_type_table[TARGET_DOUBLE_COMPLEX_BIT/TARGET_CHAR_BIT] = "double complex"; + float_type_table[TARGET_COMPLEX_BIT/TARGET_CHAR_BIT] = "complex"; + float_type_table[TARGET_LONG_DOUBLE_BIT/TARGET_CHAR_BIT] = "long double"; + float_type_table[TARGET_DOUBLE_BIT/TARGET_CHAR_BIT] = "double"; - float_type_table - = (char **) xmalloc ((1 + sizeof (double)) * sizeof (char *)); - bzero (float_type_table, (1 + sizeof (double))); - float_type_table[sizeof (float)] = "float"; - float_type_table[sizeof (double)] = "double"; obstack_begin (&dont_print_obstack, 32 * sizeof (struct type *)); } -- 2.30.2