1 /* C language support routines for GDB, the GNU debugger.
2 Copyright 1992, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 #include "expression.h"
24 #include "parser-defs.h"
28 /* Print the character C on STREAM as part of the contents of a literal
29 string whose delimiter is QUOTER. Note that that format for printing
30 characters and strings is language specific. */
33 emit_char (c, stream, quoter)
39 c &= 0xFF; /* Avoid sign bit follies */
41 if (PRINT_LITERAL_FORM (c))
43 if (c == '\\' || c == quoter)
45 fputs_filtered ("\\", stream);
47 fprintf_filtered (stream, "%c", c);
54 fputs_filtered ("\\n", stream);
57 fputs_filtered ("\\b", stream);
60 fputs_filtered ("\\t", stream);
63 fputs_filtered ("\\f", stream);
66 fputs_filtered ("\\r", stream);
69 fputs_filtered ("\\e", stream);
72 fputs_filtered ("\\a", stream);
75 fprintf_filtered (stream, "\\%.3o", (unsigned int) c);
82 c_printchar (c, stream)
86 fputs_filtered ("'", stream);
87 emit_char (c, stream, '\'');
88 fputs_filtered ("'", stream);
91 /* Print the character string STRING, printing at most LENGTH characters.
92 Printing stops early if the number hits print_max; repeat counts
93 are printed as appropriate. Print ellipses at the end if we
94 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */
97 c_printstr (stream, string, length, force_ellipses)
103 register unsigned int i;
104 unsigned int things_printed = 0;
107 extern int inspect_it;
108 extern int repeat_count_threshold;
109 extern int print_max;
111 /* If the string was not truncated due to `set print elements', and
112 the last byte of it is a null, we don't print that, in traditional C
114 if ((!force_ellipses) && length > 0 && string[length-1] == '\0')
119 fputs_filtered ("\"\"", stream);
123 for (i = 0; i < length && things_printed < print_max; ++i)
125 /* Position of the character we are examining
126 to see whether it is repeated. */
128 /* Number of repetitions we have detected so far. */
135 fputs_filtered (", ", stream);
141 while (rep1 < length && string[rep1] == string[i])
147 if (reps > repeat_count_threshold)
152 fputs_filtered ("\\\", ", stream);
154 fputs_filtered ("\", ", stream);
157 c_printchar (string[i], stream);
158 fprintf_filtered (stream, " <repeats %u times>", reps);
160 things_printed += repeat_count_threshold;
168 fputs_filtered ("\\\"", stream);
170 fputs_filtered ("\"", stream);
173 emit_char (string[i], stream, '"');
178 /* Terminate the quotes if necessary. */
182 fputs_filtered ("\\\"", stream);
184 fputs_filtered ("\"", stream);
187 if (force_ellipses || i < length)
188 fputs_filtered ("...", stream);
191 /* Create a fundamental C type using default reasonable for the current
194 Some object/debugging file formats (DWARF version 1, COFF, etc) do not
195 define fundamental types such as "int" or "double". Others (stabs or
196 DWARF version 2, etc) do define fundamental types. For the formats which
197 don't provide fundamental types, gdb can create such types using this
200 FIXME: Some compilers distinguish explicitly signed integral types
201 (signed short, signed int, signed long) from "regular" integral types
202 (short, int, long) in the debugging information. There is some dis-
203 agreement as to how useful this feature is. In particular, gcc does
204 not support this. Also, only some debugging formats allow the
205 distinction to be passed on to a debugger. For now, we always just
206 use "short", "int", or "long" as the type name, for both the implicit
207 and explicitly signed types. This also makes life easier for the
208 gdb test suite since we don't have to account for the differences
209 in output depending upon what the compiler and debugging format
210 support. We will probably have to re-examine the issue when gdb
211 starts taking it's fundamental type information directly from the
212 debugging information supplied by the compiler. fnf@cygnus.com */
215 c_create_fundamental_type (objfile, typeid)
216 struct objfile *objfile;
219 register struct type *type = NULL;
224 /* FIXME: For now, if we are asked to produce a type not in this
225 language, create the equivalent of a C integer type with the
226 name "<?type?>". When all the dust settles from the type
227 reconstruction work, this should probably become an error. */
228 type = init_type (TYPE_CODE_INT,
229 TARGET_INT_BIT / TARGET_CHAR_BIT,
230 0, "<?type?>", objfile);
231 warning ("internal error: no C/C++ fundamental type %d", typeid);
234 type = init_type (TYPE_CODE_VOID,
235 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
239 type = init_type (TYPE_CODE_INT,
240 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
244 type = init_type (TYPE_CODE_INT,
245 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
246 0, "signed char", objfile);
248 case FT_UNSIGNED_CHAR:
249 type = init_type (TYPE_CODE_INT,
250 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
251 TYPE_FLAG_UNSIGNED, "unsigned char", objfile);
254 type = init_type (TYPE_CODE_INT,
255 TARGET_SHORT_BIT / TARGET_CHAR_BIT,
256 0, "short", objfile);
258 case FT_SIGNED_SHORT:
259 type = init_type (TYPE_CODE_INT,
260 TARGET_SHORT_BIT / TARGET_CHAR_BIT,
261 0, "short", objfile); /* FIXME-fnf */
263 case FT_UNSIGNED_SHORT:
264 type = init_type (TYPE_CODE_INT,
265 TARGET_SHORT_BIT / TARGET_CHAR_BIT,
266 TYPE_FLAG_UNSIGNED, "unsigned short", objfile);
269 type = init_type (TYPE_CODE_INT,
270 TARGET_INT_BIT / TARGET_CHAR_BIT,
273 case FT_SIGNED_INTEGER:
274 type = init_type (TYPE_CODE_INT,
275 TARGET_INT_BIT / TARGET_CHAR_BIT,
276 0, "int", objfile); /* FIXME -fnf */
278 case FT_UNSIGNED_INTEGER:
279 type = init_type (TYPE_CODE_INT,
280 TARGET_INT_BIT / TARGET_CHAR_BIT,
281 TYPE_FLAG_UNSIGNED, "unsigned int", objfile);
284 type = init_type (TYPE_CODE_INT,
285 TARGET_LONG_BIT / TARGET_CHAR_BIT,
289 type = init_type (TYPE_CODE_INT,
290 TARGET_LONG_BIT / TARGET_CHAR_BIT,
291 0, "long", objfile); /* FIXME -fnf */
293 case FT_UNSIGNED_LONG:
294 type = init_type (TYPE_CODE_INT,
295 TARGET_LONG_BIT / TARGET_CHAR_BIT,
296 TYPE_FLAG_UNSIGNED, "unsigned long", objfile);
299 type = init_type (TYPE_CODE_INT,
300 TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
301 0, "long long", objfile);
303 case FT_SIGNED_LONG_LONG:
304 type = init_type (TYPE_CODE_INT,
305 TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
306 0, "signed long long", objfile);
308 case FT_UNSIGNED_LONG_LONG:
309 type = init_type (TYPE_CODE_INT,
310 TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
311 TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
314 type = init_type (TYPE_CODE_FLT,
315 TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
316 0, "float", objfile);
318 case FT_DBL_PREC_FLOAT:
319 type = init_type (TYPE_CODE_FLT,
320 TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
321 0, "double", objfile);
323 case FT_EXT_PREC_FLOAT:
324 type = init_type (TYPE_CODE_FLT,
325 TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
326 0, "long double", objfile);
333 /* Table mapping opcodes into strings for printing operators
334 and precedences of the operators. */
336 static const struct op_print c_op_print_tab[] =
338 {",", BINOP_COMMA, PREC_COMMA, 0},
339 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
340 {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
341 {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
342 {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
343 {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
344 {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
345 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
346 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
347 {"<=", BINOP_LEQ, PREC_ORDER, 0},
348 {">=", BINOP_GEQ, PREC_ORDER, 0},
349 {">", BINOP_GTR, PREC_ORDER, 0},
350 {"<", BINOP_LESS, PREC_ORDER, 0},
351 {">>", BINOP_RSH, PREC_SHIFT, 0},
352 {"<<", BINOP_LSH, PREC_SHIFT, 0},
353 {"+", BINOP_ADD, PREC_ADD, 0},
354 {"-", BINOP_SUB, PREC_ADD, 0},
355 {"*", BINOP_MUL, PREC_MUL, 0},
356 {"/", BINOP_DIV, PREC_MUL, 0},
357 {"%", BINOP_REM, PREC_MUL, 0},
358 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
359 {"-", UNOP_NEG, PREC_PREFIX, 0},
360 {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
361 {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
362 {"*", UNOP_IND, PREC_PREFIX, 0},
363 {"&", UNOP_ADDR, PREC_PREFIX, 0},
364 {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
365 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
366 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
368 {"::", BINOP_SCOPE, PREC_PREFIX, 0},
372 struct type ** const (c_builtin_types[]) =
379 &builtin_type_double,
381 &builtin_type_long_long,
382 &builtin_type_signed_char,
383 &builtin_type_unsigned_char,
384 &builtin_type_unsigned_short,
385 &builtin_type_unsigned_int,
386 &builtin_type_unsigned_long,
387 &builtin_type_unsigned_long_long,
388 &builtin_type_long_double,
389 &builtin_type_complex,
390 &builtin_type_double_complex,
394 const struct language_defn c_language_defn = {
395 "c", /* Language name */
402 c_printchar, /* Print a character constant */
403 c_printstr, /* Function to print string constant */
404 c_create_fundamental_type, /* Create fundamental type in this language */
405 c_print_type, /* Print a type using appropriate syntax */
406 c_val_print, /* Print a value using appropriate syntax */
407 c_value_print, /* Print a top-level value */
408 &builtin_type_double, /* longest floating point type */ /*FIXME*/
409 {"", "", "", ""}, /* Binary format info */
410 {"0%lo", "0", "o", ""}, /* Octal format info */
411 {"%ld", "", "d", ""}, /* Decimal format info */
412 {"0x%lx", "0x", "x", ""}, /* Hex format info */
413 c_op_print_tab, /* expression operators for printing */
417 const struct language_defn cplus_language_defn = {
418 "c++", /* Language name */
425 c_printchar, /* Print a character constant */
426 c_printstr, /* Function to print string constant */
427 c_create_fundamental_type, /* Create fundamental type in this language */
428 c_print_type, /* Print a type using appropriate syntax */
429 c_val_print, /* Print a value using appropriate syntax */
430 c_value_print, /* Print a top-level value */
431 &builtin_type_double, /* longest floating point type */ /*FIXME*/
432 {"", "", "", ""}, /* Binary format info */
433 {"0%lo", "0", "o", ""}, /* Octal format info */
434 {"%ld", "", "d", ""}, /* Decimal format info */
435 {"0x%lx", "0x", "x", ""}, /* Hex format info */
436 c_op_print_tab, /* expression operators for printing */
440 const struct language_defn asm_language_defn = {
441 "asm", /* Language name */
448 c_printchar, /* Print a character constant */
449 c_printstr, /* Function to print string constant */
450 c_create_fundamental_type, /* Create fundamental type in this language */
451 c_print_type, /* Print a type using appropriate syntax */
452 c_val_print, /* Print a value using appropriate syntax */
453 c_value_print, /* Print a top-level value */
454 &builtin_type_double, /* longest floating point type */ /*FIXME*/
455 {"", "", "", ""}, /* Binary format info */
456 {"0%lo", "0", "o", ""}, /* Octal format info */
457 {"%ld", "", "d", ""}, /* Decimal format info */
458 {"0x%lx", "0x", "x", ""}, /* Hex format info */
459 c_op_print_tab, /* expression operators for printing */
464 _initialize_c_language ()
466 add_language (&c_language_defn);
467 add_language (&cplus_language_defn);
468 add_language (&asm_language_defn);