* gdb.trace/backtrace.exp: Fix a typo.
[deliverable/binutils-gdb.git] / gdb / c-lang.c
CommitLineData
c906108c 1/* C language support routines for GDB, the GNU debugger.
ce27fb25 2
6aba47ca
DJ
3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2002, 2003,
4 2004, 2005, 2007 Free Software Foundation, Inc.
c906108c 5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
c5aa993b 11 (at your option) any later version.
c906108c 12
c5aa993b
JM
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
c906108c 17
c5aa993b 18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
20
21#include "defs.h"
22#include "symtab.h"
23#include "gdbtypes.h"
24#include "expression.h"
25#include "parser-defs.h"
26#include "language.h"
27#include "c-lang.h"
745b8ca0 28#include "valprint.h"
84f0252a
JB
29#include "macroscope.h"
30#include "gdb_assert.h"
234b45d4 31#include "charset.h"
a15ef5f5 32#include "gdb_string.h"
9a3d7dfd 33#include "demangle.h"
b18be20d 34#include "cp-abi.h"
1fcb5155 35#include "cp-support.h"
c906108c 36
a14ed312 37extern void _initialize_c_language (void);
d9fcf2fb 38static void c_emit_char (int c, struct ui_file * stream, int quoter);
c906108c
SS
39
40/* Print the character C on STREAM as part of the contents of a literal
41 string whose delimiter is QUOTER. Note that that format for printing
42 characters and strings is language specific. */
43
44static void
f86f5ca3 45c_emit_char (int c, struct ui_file *stream, int quoter)
c906108c 46{
234b45d4
KB
47 const char *escape;
48 int host_char;
49
c906108c
SS
50 c &= 0xFF; /* Avoid sign bit follies */
51
234b45d4
KB
52 escape = c_target_char_has_backslash_escape (c);
53 if (escape)
c906108c 54 {
234b45d4
KB
55 if (quoter == '"' && strcmp (escape, "0") == 0)
56 /* Print nulls embedded in double quoted strings as \000 to
57 prevent ambiguity. */
58 fprintf_filtered (stream, "\\000");
59 else
60 fprintf_filtered (stream, "\\%s", escape);
c906108c 61 }
234b45d4
KB
62 else if (target_char_to_host (c, &host_char)
63 && host_char_print_literally (host_char))
c906108c 64 {
234b45d4
KB
65 if (host_char == '\\' || host_char == quoter)
66 fputs_filtered ("\\", stream);
67 fprintf_filtered (stream, "%c", host_char);
c906108c 68 }
234b45d4
KB
69 else
70 fprintf_filtered (stream, "\\%.3o", (unsigned int) c);
c906108c
SS
71}
72
73void
fba45db2 74c_printchar (int c, struct ui_file *stream)
c906108c
SS
75{
76 fputc_filtered ('\'', stream);
77 LA_EMIT_CHAR (c, stream, '\'');
78 fputc_filtered ('\'', stream);
79}
80
81/* Print the character string STRING, printing at most LENGTH characters.
82 LENGTH is -1 if the string is nul terminated. Each character is WIDTH bytes
83 long. Printing stops early if the number hits print_max; repeat counts are
84 printed as appropriate. Print ellipses at the end if we had to stop before
85 printing LENGTH characters, or if FORCE_ELLIPSES. */
86
87void
fc1a4b47 88c_printstr (struct ui_file *stream, const gdb_byte *string,
ce27fb25 89 unsigned int length, int width, int force_ellipses)
c906108c 90{
f86f5ca3 91 unsigned int i;
c906108c
SS
92 unsigned int things_printed = 0;
93 int in_quotes = 0;
94 int need_comma = 0;
c906108c
SS
95
96 /* If the string was not truncated due to `set print elements', and
97 the last byte of it is a null, we don't print that, in traditional C
98 style. */
99 if (!force_ellipses
100 && length > 0
78a51202
JB
101 && (extract_unsigned_integer (string + (length - 1) * width, width)
102 == '\0'))
c906108c
SS
103 length--;
104
105 if (length == 0)
106 {
107 fputs_filtered ("\"\"", stream);
108 return;
109 }
110
111 for (i = 0; i < length && things_printed < print_max; ++i)
112 {
113 /* Position of the character we are examining
c5aa993b 114 to see whether it is repeated. */
c906108c
SS
115 unsigned int rep1;
116 /* Number of repetitions we have detected so far. */
117 unsigned int reps;
118 unsigned long current_char;
119
120 QUIT;
121
122 if (need_comma)
123 {
124 fputs_filtered (", ", stream);
125 need_comma = 0;
126 }
127
128 current_char = extract_unsigned_integer (string + i * width, width);
129
130 rep1 = i + 1;
131 reps = 1;
132 while (rep1 < length
133 && extract_unsigned_integer (string + rep1 * width, width)
c5aa993b 134 == current_char)
c906108c
SS
135 {
136 ++rep1;
137 ++reps;
138 }
139
140 if (reps > repeat_count_threshold)
141 {
142 if (in_quotes)
143 {
144 if (inspect_it)
145 fputs_filtered ("\\\", ", stream);
146 else
147 fputs_filtered ("\", ", stream);
148 in_quotes = 0;
149 }
150 LA_PRINT_CHAR (current_char, stream);
3d263c1d 151 fprintf_filtered (stream, _(" <repeats %u times>"), reps);
c906108c
SS
152 i = rep1 - 1;
153 things_printed += repeat_count_threshold;
154 need_comma = 1;
155 }
156 else
157 {
158 if (!in_quotes)
159 {
160 if (inspect_it)
161 fputs_filtered ("\\\"", stream);
162 else
163 fputs_filtered ("\"", stream);
164 in_quotes = 1;
165 }
166 LA_EMIT_CHAR (current_char, stream, '"');
167 ++things_printed;
168 }
169 }
170
171 /* Terminate the quotes if necessary. */
172 if (in_quotes)
173 {
174 if (inspect_it)
175 fputs_filtered ("\\\"", stream);
176 else
177 fputs_filtered ("\"", stream);
178 }
179
180 if (force_ellipses || i < length)
181 fputs_filtered ("...", stream);
182}
183
184/* Create a fundamental C type using default reasonable for the current
185 target machine.
186
187 Some object/debugging file formats (DWARF version 1, COFF, etc) do not
188 define fundamental types such as "int" or "double". Others (stabs or
189 DWARF version 2, etc) do define fundamental types. For the formats which
190 don't provide fundamental types, gdb can create such types using this
191 function.
192
193 FIXME: Some compilers distinguish explicitly signed integral types
194 (signed short, signed int, signed long) from "regular" integral types
195 (short, int, long) in the debugging information. There is some dis-
196 agreement as to how useful this feature is. In particular, gcc does
197 not support this. Also, only some debugging formats allow the
198 distinction to be passed on to a debugger. For now, we always just
199 use "short", "int", or "long" as the type name, for both the implicit
200 and explicitly signed types. This also makes life easier for the
201 gdb test suite since we don't have to account for the differences
202 in output depending upon what the compiler and debugging format
203 support. We will probably have to re-examine the issue when gdb
8470e927 204 starts taking its fundamental type information directly from the
c906108c
SS
205 debugging information supplied by the compiler. fnf@cygnus.com */
206
207struct type *
fba45db2 208c_create_fundamental_type (struct objfile *objfile, int typeid)
c906108c 209{
f86f5ca3 210 struct type *type = NULL;
c906108c
SS
211
212 switch (typeid)
213 {
c5aa993b
JM
214 default:
215 /* FIXME: For now, if we are asked to produce a type not in this
216 language, create the equivalent of a C integer type with the
217 name "<?type?>". When all the dust settles from the type
218 reconstruction work, this should probably become an error. */
219 type = init_type (TYPE_CODE_INT,
9a76efb6 220 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b 221 0, "<?type?>", objfile);
3d263c1d 222 warning (_("internal error: no C/C++ fundamental type %d"), typeid);
c5aa993b
JM
223 break;
224 case FT_VOID:
225 type = init_type (TYPE_CODE_VOID,
226 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
227 0, "void", objfile);
228 break;
229 case FT_BOOLEAN:
230 type = init_type (TYPE_CODE_BOOL,
231 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
232 0, "bool", objfile);
c5aa993b
JM
233 break;
234 case FT_CHAR:
235 type = init_type (TYPE_CODE_INT,
236 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
6edc140f 237 TYPE_FLAG_NOSIGN, "char", objfile);
c5aa993b
JM
238 break;
239 case FT_SIGNED_CHAR:
240 type = init_type (TYPE_CODE_INT,
241 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
242 0, "signed char", objfile);
243 break;
244 case FT_UNSIGNED_CHAR:
245 type = init_type (TYPE_CODE_INT,
246 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
247 TYPE_FLAG_UNSIGNED, "unsigned char", objfile);
248 break;
249 case FT_SHORT:
250 type = init_type (TYPE_CODE_INT,
9a76efb6 251 gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
252 0, "short", objfile);
253 break;
254 case FT_SIGNED_SHORT:
255 type = init_type (TYPE_CODE_INT,
9a76efb6 256 gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
257 0, "short", objfile); /* FIXME-fnf */
258 break;
259 case FT_UNSIGNED_SHORT:
260 type = init_type (TYPE_CODE_INT,
9a76efb6 261 gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
262 TYPE_FLAG_UNSIGNED, "unsigned short", objfile);
263 break;
264 case FT_INTEGER:
265 type = init_type (TYPE_CODE_INT,
9a76efb6 266 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
267 0, "int", objfile);
268 break;
269 case FT_SIGNED_INTEGER:
270 type = init_type (TYPE_CODE_INT,
9a76efb6 271 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
272 0, "int", objfile); /* FIXME -fnf */
273 break;
274 case FT_UNSIGNED_INTEGER:
275 type = init_type (TYPE_CODE_INT,
9a76efb6 276 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
277 TYPE_FLAG_UNSIGNED, "unsigned int", objfile);
278 break;
279 case FT_LONG:
280 type = init_type (TYPE_CODE_INT,
9a76efb6 281 gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
282 0, "long", objfile);
283 break;
284 case FT_SIGNED_LONG:
285 type = init_type (TYPE_CODE_INT,
9a76efb6 286 gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
287 0, "long", objfile); /* FIXME -fnf */
288 break;
289 case FT_UNSIGNED_LONG:
290 type = init_type (TYPE_CODE_INT,
9a76efb6 291 gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
292 TYPE_FLAG_UNSIGNED, "unsigned long", objfile);
293 break;
294 case FT_LONG_LONG:
295 type = init_type (TYPE_CODE_INT,
9a76efb6
UW
296 gdbarch_long_long_bit (current_gdbarch)
297 / TARGET_CHAR_BIT,
c5aa993b
JM
298 0, "long long", objfile);
299 break;
300 case FT_SIGNED_LONG_LONG:
301 type = init_type (TYPE_CODE_INT,
9a76efb6
UW
302 gdbarch_long_long_bit (current_gdbarch)
303 / TARGET_CHAR_BIT,
c5aa993b
JM
304 0, "signed long long", objfile);
305 break;
306 case FT_UNSIGNED_LONG_LONG:
307 type = init_type (TYPE_CODE_INT,
9a76efb6
UW
308 gdbarch_long_long_bit (current_gdbarch)
309 / TARGET_CHAR_BIT,
c5aa993b
JM
310 TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
311 break;
312 case FT_FLOAT:
313 type = init_type (TYPE_CODE_FLT,
ea06eb3d 314 gdbarch_float_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
315 0, "float", objfile);
316 break;
317 case FT_DBL_PREC_FLOAT:
318 type = init_type (TYPE_CODE_FLT,
ea06eb3d 319 gdbarch_double_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
320 0, "double", objfile);
321 break;
322 case FT_EXT_PREC_FLOAT:
323 type = init_type (TYPE_CODE_FLT,
ea06eb3d
UW
324 gdbarch_long_double_bit (current_gdbarch)
325 / TARGET_CHAR_BIT,
c5aa993b 326 0, "long double", objfile);
7678ef8f
TJB
327 break;
328 case FT_DECFLOAT:
329 type = init_type (TYPE_CODE_DECFLOAT,
330 32 / 8,
331 0, "decimal float", objfile);
332 break;
333 case FT_DBL_PREC_DECFLOAT:
334 type = init_type (TYPE_CODE_DECFLOAT,
335 64 / 8,
336 0, "decimal double", objfile);
337 break;
338 case FT_EXT_PREC_DECFLOAT:
339 type = init_type (TYPE_CODE_DECFLOAT,
340 128 / 8,
341 0, "decimal long double", objfile);
c5aa993b 342 break;
f65ca430
DJ
343 case FT_COMPLEX:
344 type = init_type (TYPE_CODE_FLT,
ea06eb3d
UW
345 2 * gdbarch_float_bit (current_gdbarch)
346 / TARGET_CHAR_BIT,
f65ca430
DJ
347 0, "complex float", objfile);
348 TYPE_TARGET_TYPE (type)
ea06eb3d
UW
349 = init_type (TYPE_CODE_FLT,
350 gdbarch_float_bit (current_gdbarch) / TARGET_CHAR_BIT,
f65ca430
DJ
351 0, "float", objfile);
352 break;
353 case FT_DBL_PREC_COMPLEX:
354 type = init_type (TYPE_CODE_FLT,
ea06eb3d
UW
355 2 * gdbarch_double_bit (current_gdbarch)
356 / TARGET_CHAR_BIT,
f65ca430
DJ
357 0, "complex double", objfile);
358 TYPE_TARGET_TYPE (type)
ea06eb3d
UW
359 = init_type (TYPE_CODE_FLT,
360 gdbarch_double_bit (current_gdbarch) / TARGET_CHAR_BIT,
f65ca430
DJ
361 0, "double", objfile);
362 break;
363 case FT_EXT_PREC_COMPLEX:
364 type = init_type (TYPE_CODE_FLT,
ea06eb3d
UW
365 2 * gdbarch_long_double_bit (current_gdbarch)
366 / TARGET_CHAR_BIT,
f65ca430
DJ
367 0, "complex long double", objfile);
368 TYPE_TARGET_TYPE (type)
ea06eb3d
UW
369 = init_type (TYPE_CODE_FLT,
370 gdbarch_long_double_bit (current_gdbarch)
371 / TARGET_CHAR_BIT,
f65ca430
DJ
372 0, "long double", objfile);
373 break;
c5aa993b
JM
374 case FT_TEMPLATE_ARG:
375 type = init_type (TYPE_CODE_TEMPLATE_ARG,
376 0,
377 0, "<template arg>", objfile);
c5aa993b
JM
378 break;
379 }
c906108c
SS
380 return (type);
381}
c906108c 382\f
84f0252a 383/* Preprocessing and parsing C and C++ expressions. */
c5aa993b 384
84f0252a
JB
385
386/* When we find that lexptr (the global var defined in parse.c) is
387 pointing at a macro invocation, we expand the invocation, and call
388 scan_macro_expansion to save the old lexptr here and point lexptr
389 into the expanded text. When we reach the end of that, we call
390 end_macro_expansion to pop back to the value we saved here. The
391 macro expansion code promises to return only fully-expanded text,
392 so we don't need to "push" more than one level.
393
394 This is disgusting, of course. It would be cleaner to do all macro
395 expansion beforehand, and then hand that to lexptr. But we don't
396 really know where the expression ends. Remember, in a command like
397
398 (gdb) break *ADDRESS if CONDITION
399
400 we evaluate ADDRESS in the scope of the current frame, but we
401 evaluate CONDITION in the scope of the breakpoint's location. So
402 it's simply wrong to try to macro-expand the whole thing at once. */
403static char *macro_original_text;
404static char *macro_expanded_text;
405
406
407void
408scan_macro_expansion (char *expansion)
409{
410 /* We'd better not be trying to push the stack twice. */
411 gdb_assert (! macro_original_text);
412 gdb_assert (! macro_expanded_text);
413
414 /* Save the old lexptr value, so we can return to it when we're done
415 parsing the expanded text. */
416 macro_original_text = lexptr;
417 lexptr = expansion;
418
419 /* Save the expanded text, so we can free it when we're finished. */
420 macro_expanded_text = expansion;
421}
422
423
424int
5ae5f592 425scanning_macro_expansion (void)
84f0252a
JB
426{
427 return macro_original_text != 0;
428}
429
430
431void
5ae5f592 432finished_macro_expansion (void)
84f0252a
JB
433{
434 /* There'd better be something to pop back to, and we better have
435 saved a pointer to the start of the expanded text. */
436 gdb_assert (macro_original_text);
437 gdb_assert (macro_expanded_text);
438
439 /* Pop back to the original text. */
440 lexptr = macro_original_text;
441 macro_original_text = 0;
442
443 /* Free the expanded text. */
444 xfree (macro_expanded_text);
445 macro_expanded_text = 0;
446}
447
448
449static void
450scan_macro_cleanup (void *dummy)
451{
452 if (macro_original_text)
453 finished_macro_expansion ();
454}
455
456
457/* We set these global variables before calling c_parse, to tell it
458 how it to find macro definitions for the expression at hand. */
459macro_lookup_ftype *expression_macro_lookup_func;
460void *expression_macro_lookup_baton;
461
462
463static struct macro_definition *
464null_macro_lookup (const char *name, void *baton)
465{
466 return 0;
467}
468
469
470static int
5ae5f592 471c_preprocess_and_parse (void)
84f0252a
JB
472{
473 /* Set up a lookup function for the macro expander. */
474 struct macro_scope *scope = 0;
475 struct cleanup *back_to = make_cleanup (free_current_contents, &scope);
476
477 if (expression_context_block)
478 scope = sal_macro_scope (find_pc_line (expression_context_pc, 0));
479 else
480 scope = default_macro_scope ();
481
482 if (scope)
483 {
484 expression_macro_lookup_func = standard_macro_lookup;
485 expression_macro_lookup_baton = (void *) scope;
486 }
487 else
488 {
489 expression_macro_lookup_func = null_macro_lookup;
490 expression_macro_lookup_baton = 0;
491 }
492
493 gdb_assert (! macro_original_text);
494 make_cleanup (scan_macro_cleanup, 0);
495
496 {
497 int result = c_parse ();
498 do_cleanups (back_to);
499 return result;
500 }
501}
502
503
504\f
c906108c
SS
505/* Table mapping opcodes into strings for printing operators
506 and precedences of the operators. */
507
508const struct op_print c_op_print_tab[] =
c5aa993b
JM
509{
510 {",", BINOP_COMMA, PREC_COMMA, 0},
511 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
512 {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
513 {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
514 {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
515 {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
516 {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
517 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
518 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
519 {"<=", BINOP_LEQ, PREC_ORDER, 0},
520 {">=", BINOP_GEQ, PREC_ORDER, 0},
521 {">", BINOP_GTR, PREC_ORDER, 0},
522 {"<", BINOP_LESS, PREC_ORDER, 0},
523 {">>", BINOP_RSH, PREC_SHIFT, 0},
524 {"<<", BINOP_LSH, PREC_SHIFT, 0},
525 {"+", BINOP_ADD, PREC_ADD, 0},
526 {"-", BINOP_SUB, PREC_ADD, 0},
527 {"*", BINOP_MUL, PREC_MUL, 0},
528 {"/", BINOP_DIV, PREC_MUL, 0},
529 {"%", BINOP_REM, PREC_MUL, 0},
530 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
531 {"-", UNOP_NEG, PREC_PREFIX, 0},
532 {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
533 {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
534 {"*", UNOP_IND, PREC_PREFIX, 0},
535 {"&", UNOP_ADDR, PREC_PREFIX, 0},
536 {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
537 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
538 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
c5aa993b 539 {NULL, 0, 0, 0}
c906108c
SS
540};
541\f
685419e2
AC
542enum c_primitive_types {
543 c_primitive_type_int,
544 c_primitive_type_long,
545 c_primitive_type_short,
546 c_primitive_type_char,
547 c_primitive_type_float,
548 c_primitive_type_double,
549 c_primitive_type_void,
550 c_primitive_type_long_long,
551 c_primitive_type_signed_char,
552 c_primitive_type_unsigned_char,
553 c_primitive_type_unsigned_short,
554 c_primitive_type_unsigned_int,
555 c_primitive_type_unsigned_long,
556 c_primitive_type_unsigned_long_long,
557 c_primitive_type_long_double,
558 c_primitive_type_complex,
559 c_primitive_type_double_complex,
560 nr_c_primitive_types
561};
562
e9667a65 563void
685419e2
AC
564c_language_arch_info (struct gdbarch *gdbarch,
565 struct language_arch_info *lai)
566{
567 const struct builtin_type *builtin = builtin_type (gdbarch);
e9667a65 568 lai->string_char_type = builtin->builtin_char;
685419e2
AC
569 lai->primitive_type_vector
570 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_c_primitive_types + 1,
571 struct type *);
572 lai->primitive_type_vector [c_primitive_type_int] = builtin->builtin_int;
573 lai->primitive_type_vector [c_primitive_type_long] = builtin->builtin_long;
574 lai->primitive_type_vector [c_primitive_type_short] = builtin->builtin_short;
575 lai->primitive_type_vector [c_primitive_type_char] = builtin->builtin_char;
576 lai->primitive_type_vector [c_primitive_type_float] = builtin->builtin_float;
577 lai->primitive_type_vector [c_primitive_type_double] = builtin->builtin_double;
578 lai->primitive_type_vector [c_primitive_type_void] = builtin->builtin_void;
579 lai->primitive_type_vector [c_primitive_type_long_long] = builtin->builtin_long_long;
580 lai->primitive_type_vector [c_primitive_type_signed_char] = builtin->builtin_signed_char;
581 lai->primitive_type_vector [c_primitive_type_unsigned_char] = builtin->builtin_unsigned_char;
582 lai->primitive_type_vector [c_primitive_type_unsigned_short] = builtin->builtin_unsigned_short;
583 lai->primitive_type_vector [c_primitive_type_unsigned_int] = builtin->builtin_unsigned_int;
584 lai->primitive_type_vector [c_primitive_type_unsigned_long] = builtin->builtin_unsigned_long;
585 lai->primitive_type_vector [c_primitive_type_unsigned_long_long] = builtin->builtin_unsigned_long_long;
586 lai->primitive_type_vector [c_primitive_type_long_double] = builtin->builtin_long_double;
587 lai->primitive_type_vector [c_primitive_type_complex] = builtin->builtin_complex;
588 lai->primitive_type_vector [c_primitive_type_double_complex] = builtin->builtin_double_complex;
cad351d1 589}
685419e2 590
c5aa993b
JM
591const struct language_defn c_language_defn =
592{
c906108c
SS
593 "c", /* Language name */
594 language_c,
c906108c
SS
595 range_check_off,
596 type_check_off,
63872f9d 597 case_sensitive_on,
7ca2d3a3 598 array_row_major,
5f9769d1 599 &exp_descriptor_standard,
84f0252a 600 c_preprocess_and_parse,
c906108c 601 c_error,
e85c3284 602 null_post_parser,
c906108c
SS
603 c_printchar, /* Print a character constant */
604 c_printstr, /* Function to print string constant */
605 c_emit_char, /* Print a single char */
606 c_create_fundamental_type, /* Create fundamental type in this language */
607 c_print_type, /* Print a type using appropriate syntax */
608 c_val_print, /* Print a value using appropriate syntax */
609 c_value_print, /* Print a top-level value */
f636b87d 610 NULL, /* Language specific skip_trampoline */
5f9a71c3
DC
611 NULL, /* value_of_this */
612 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 613 basic_lookup_transparent_type,/* lookup_transparent_type */
9a3d7dfd 614 NULL, /* Language specific symbol demangler */
31c27f77 615 NULL, /* Language specific class_name_from_physname */
c906108c
SS
616 c_op_print_tab, /* expression operators for printing */
617 1, /* c-style arrays */
618 0, /* String lower bound */
6084f43a 619 default_word_break_characters,
685419e2 620 c_language_arch_info,
e79af960 621 default_print_array_index,
41f1b697 622 default_pass_by_reference,
c906108c
SS
623 LANG_MAGIC
624};
625
cad351d1
UW
626enum cplus_primitive_types {
627 cplus_primitive_type_int,
628 cplus_primitive_type_long,
629 cplus_primitive_type_short,
630 cplus_primitive_type_char,
631 cplus_primitive_type_float,
632 cplus_primitive_type_double,
633 cplus_primitive_type_void,
634 cplus_primitive_type_long_long,
635 cplus_primitive_type_signed_char,
636 cplus_primitive_type_unsigned_char,
637 cplus_primitive_type_unsigned_short,
638 cplus_primitive_type_unsigned_int,
639 cplus_primitive_type_unsigned_long,
640 cplus_primitive_type_unsigned_long_long,
641 cplus_primitive_type_long_double,
642 cplus_primitive_type_complex,
643 cplus_primitive_type_double_complex,
644 cplus_primitive_type_bool,
645 nr_cplus_primitive_types
c906108c
SS
646};
647
cad351d1
UW
648static void
649cplus_language_arch_info (struct gdbarch *gdbarch,
650 struct language_arch_info *lai)
651{
652 const struct builtin_type *builtin = builtin_type (gdbarch);
653 lai->string_char_type = builtin->builtin_char;
654 lai->primitive_type_vector
655 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_cplus_primitive_types + 1,
656 struct type *);
657 lai->primitive_type_vector [cplus_primitive_type_int]
658 = builtin->builtin_int;
659 lai->primitive_type_vector [cplus_primitive_type_long]
660 = builtin->builtin_long;
661 lai->primitive_type_vector [cplus_primitive_type_short]
662 = builtin->builtin_short;
663 lai->primitive_type_vector [cplus_primitive_type_char]
664 = builtin->builtin_char;
665 lai->primitive_type_vector [cplus_primitive_type_float]
666 = builtin->builtin_float;
667 lai->primitive_type_vector [cplus_primitive_type_double]
668 = builtin->builtin_double;
669 lai->primitive_type_vector [cplus_primitive_type_void]
670 = builtin->builtin_void;
671 lai->primitive_type_vector [cplus_primitive_type_long_long]
672 = builtin->builtin_long_long;
673 lai->primitive_type_vector [cplus_primitive_type_signed_char]
674 = builtin->builtin_signed_char;
675 lai->primitive_type_vector [cplus_primitive_type_unsigned_char]
676 = builtin->builtin_unsigned_char;
677 lai->primitive_type_vector [cplus_primitive_type_unsigned_short]
678 = builtin->builtin_unsigned_short;
679 lai->primitive_type_vector [cplus_primitive_type_unsigned_int]
680 = builtin->builtin_unsigned_int;
681 lai->primitive_type_vector [cplus_primitive_type_unsigned_long]
682 = builtin->builtin_unsigned_long;
683 lai->primitive_type_vector [cplus_primitive_type_unsigned_long_long]
684 = builtin->builtin_unsigned_long_long;
685 lai->primitive_type_vector [cplus_primitive_type_long_double]
686 = builtin->builtin_long_double;
687 lai->primitive_type_vector [cplus_primitive_type_complex]
688 = builtin->builtin_complex;
689 lai->primitive_type_vector [cplus_primitive_type_double_complex]
690 = builtin->builtin_double_complex;
691 lai->primitive_type_vector [cplus_primitive_type_bool]
692 = builtin->builtin_bool;
693}
694
c5aa993b
JM
695const struct language_defn cplus_language_defn =
696{
697 "c++", /* Language name */
c906108c 698 language_cplus,
c906108c
SS
699 range_check_off,
700 type_check_off,
63872f9d 701 case_sensitive_on,
7ca2d3a3 702 array_row_major,
5f9769d1 703 &exp_descriptor_standard,
84f0252a 704 c_preprocess_and_parse,
c906108c 705 c_error,
e85c3284 706 null_post_parser,
c906108c
SS
707 c_printchar, /* Print a character constant */
708 c_printstr, /* Function to print string constant */
709 c_emit_char, /* Print a single char */
710 c_create_fundamental_type, /* Create fundamental type in this language */
711 c_print_type, /* Print a type using appropriate syntax */
712 c_val_print, /* Print a value using appropriate syntax */
713 c_value_print, /* Print a top-level value */
b18be20d 714 cplus_skip_trampoline, /* Language specific skip_trampoline */
5f9a71c3 715 value_of_this, /* value_of_this */
1fcb5155 716 cp_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 717 cp_lookup_transparent_type, /* lookup_transparent_type */
9a3d7dfd 718 cplus_demangle, /* Language specific symbol demangler */
31c27f77 719 cp_class_name_from_physname, /* Language specific class_name_from_physname */
c906108c
SS
720 c_op_print_tab, /* expression operators for printing */
721 1, /* c-style arrays */
722 0, /* String lower bound */
6084f43a 723 default_word_break_characters,
cad351d1 724 cplus_language_arch_info,
e79af960 725 default_print_array_index,
41f1b697 726 cp_pass_by_reference,
c906108c
SS
727 LANG_MAGIC
728};
729
c5aa993b
JM
730const struct language_defn asm_language_defn =
731{
c906108c
SS
732 "asm", /* Language name */
733 language_asm,
c906108c
SS
734 range_check_off,
735 type_check_off,
63872f9d 736 case_sensitive_on,
7ca2d3a3 737 array_row_major,
5f9769d1 738 &exp_descriptor_standard,
84f0252a 739 c_preprocess_and_parse,
c906108c 740 c_error,
e85c3284 741 null_post_parser,
c906108c
SS
742 c_printchar, /* Print a character constant */
743 c_printstr, /* Function to print string constant */
744 c_emit_char, /* Print a single char */
745 c_create_fundamental_type, /* Create fundamental type in this language */
746 c_print_type, /* Print a type using appropriate syntax */
747 c_val_print, /* Print a value using appropriate syntax */
748 c_value_print, /* Print a top-level value */
f636b87d 749 NULL, /* Language specific skip_trampoline */
5f9a71c3
DC
750 NULL, /* value_of_this */
751 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 752 basic_lookup_transparent_type,/* lookup_transparent_type */
9a3d7dfd 753 NULL, /* Language specific symbol demangler */
31c27f77 754 NULL, /* Language specific class_name_from_physname */
c906108c
SS
755 c_op_print_tab, /* expression operators for printing */
756 1, /* c-style arrays */
757 0, /* String lower bound */
6084f43a 758 default_word_break_characters,
e9667a65 759 c_language_arch_info, /* FIXME: la_language_arch_info. */
e79af960 760 default_print_array_index,
41f1b697 761 default_pass_by_reference,
c906108c
SS
762 LANG_MAGIC
763};
764
20a0e81d
JB
765/* The following language_defn does not represent a real language.
766 It just provides a minimal support a-la-C that should allow users
767 to do some simple operations when debugging applications that use
768 a language currently not supported by GDB. */
769
770const struct language_defn minimal_language_defn =
771{
772 "minimal", /* Language name */
773 language_minimal,
20a0e81d
JB
774 range_check_off,
775 type_check_off,
776 case_sensitive_on,
7ca2d3a3 777 array_row_major,
5f9769d1 778 &exp_descriptor_standard,
20a0e81d
JB
779 c_preprocess_and_parse,
780 c_error,
e85c3284 781 null_post_parser,
20a0e81d
JB
782 c_printchar, /* Print a character constant */
783 c_printstr, /* Function to print string constant */
784 c_emit_char, /* Print a single char */
785 c_create_fundamental_type, /* Create fundamental type in this language */
786 c_print_type, /* Print a type using appropriate syntax */
787 c_val_print, /* Print a value using appropriate syntax */
788 c_value_print, /* Print a top-level value */
789 NULL, /* Language specific skip_trampoline */
5f9a71c3
DC
790 NULL, /* value_of_this */
791 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 792 basic_lookup_transparent_type,/* lookup_transparent_type */
20a0e81d 793 NULL, /* Language specific symbol demangler */
31c27f77 794 NULL, /* Language specific class_name_from_physname */
20a0e81d
JB
795 c_op_print_tab, /* expression operators for printing */
796 1, /* c-style arrays */
797 0, /* String lower bound */
6084f43a 798 default_word_break_characters,
e9667a65 799 c_language_arch_info,
e79af960 800 default_print_array_index,
41f1b697 801 default_pass_by_reference,
20a0e81d
JB
802 LANG_MAGIC
803};
804
c906108c 805void
fba45db2 806_initialize_c_language (void)
c906108c
SS
807{
808 add_language (&c_language_defn);
809 add_language (&cplus_language_defn);
810 add_language (&asm_language_defn);
20a0e81d 811 add_language (&minimal_language_defn);
c906108c 812}
This page took 0.669444 seconds and 4 git commands to generate.