Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: gdb/m2-valprint.c

Issue 11969036: Merge GDB 7.5.1 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gdb/m2-typeprint.c ('k') | gdb/m32c-tdep.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Support for printing Modula 2 values for GDB, the GNU debugger. 1 /* Support for printing Modula 2 values for GDB, the GNU debugger.
2 2
3 Copyright (C) 1986, 1988-1989, 1991-1992, 1996, 1998, 2000, 2005-2012 3 Copyright (C) 1986, 1988-1989, 1991-1992, 1996, 1998, 2000, 2005-2012
4 Free Software Foundation, Inc. 4 Free Software Foundation, Inc.
5 5
6 This file is part of GDB. 6 This file is part of GDB.
7 7
8 This program is free software; you can redistribute it and/or modify 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 9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or 10 the Free Software Foundation; either version 3 of the License, or
(...skipping 25 matching lines...) Expand all
36 struct ui_file *stream); 36 struct ui_file *stream);
37 static void 37 static void
38 m2_print_array_contents (struct type *type, const gdb_byte *valaddr, 38 m2_print_array_contents (struct type *type, const gdb_byte *valaddr,
39 int embedded_offset, CORE_ADDR address, 39 int embedded_offset, CORE_ADDR address,
40 struct ui_file *stream, int recurse, 40 struct ui_file *stream, int recurse,
41 const struct value *val, 41 const struct value *val,
42 const struct value_print_options *options, 42 const struct value_print_options *options,
43 int len); 43 int len);
44 44
45 45
46 /* Print function pointer with inferior address ADDRESS onto stdio
47 stream STREAM. */
48
49 static void
50 print_function_pointer_address (struct gdbarch *gdbarch, CORE_ADDR address,
51 struct ui_file *stream, int addressprint)
52 {
53 CORE_ADDR func_addr = gdbarch_convert_from_func_ptr_addr (gdbarch, address,
54 &current_target);
55
56 /* If the function pointer is represented by a description, print the
57 address of the description. */
58 if (addressprint && func_addr != address)
59 {
60 fputs_filtered ("@", stream);
61 fputs_filtered (paddress (gdbarch, address), stream);
62 fputs_filtered (": ", stream);
63 }
64 print_address_demangle (gdbarch, func_addr, stream, demangle);
65 }
66
67 /* get_long_set_bounds - assigns the bounds of the long set to low and 46 /* get_long_set_bounds - assigns the bounds of the long set to low and
68 high. */ 47 high. */
69 48
70 int 49 int
71 get_long_set_bounds (struct type *type, LONGEST *low, LONGEST *high) 50 get_long_set_bounds (struct type *type, LONGEST *low, LONGEST *high)
72 { 51 {
73 int len, i; 52 int len, i;
74 53
75 if (TYPE_CODE (type) == TYPE_CODE_STRUCT) 54 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
76 { 55 {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 188 }
210 189
211 static int 190 static int
212 print_unpacked_pointer (struct type *type, 191 print_unpacked_pointer (struct type *type,
213 CORE_ADDR address, CORE_ADDR addr, 192 CORE_ADDR address, CORE_ADDR addr,
214 const struct value_print_options *options, 193 const struct value_print_options *options,
215 struct ui_file *stream) 194 struct ui_file *stream)
216 { 195 {
217 struct gdbarch *gdbarch = get_type_arch (type); 196 struct gdbarch *gdbarch = get_type_arch (type);
218 struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type)); 197 struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type));
198 int want_space = 0;
219 199
220 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) 200 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
221 { 201 {
222 /* Try to print what function it points to. */ 202 /* Try to print what function it points to. */
223 print_function_pointer_address (gdbarch, addr, stream, 203 print_function_pointer_address (options, gdbarch, addr, stream);
224 » » » » options->addressprint);
225 /* Return value is irrelevant except for string pointers. */ 204 /* Return value is irrelevant except for string pointers. */
226 return 0; 205 return 0;
227 } 206 }
228 207
229 if (options->addressprint && options->format != 's') 208 if (options->addressprint && options->format != 's')
230 fputs_filtered (paddress (gdbarch, address), stream); 209 {
210 fputs_filtered (paddress (gdbarch, address), stream);
211 want_space = 1;
212 }
231 213
232 /* For a pointer to char or unsigned char, also print the string 214 /* For a pointer to char or unsigned char, also print the string
233 pointed to, unless pointer is null. */ 215 pointed to, unless pointer is null. */
234 216
235 if (TYPE_LENGTH (elttype) == 1 217 if (TYPE_LENGTH (elttype) == 1
236 && TYPE_CODE (elttype) == TYPE_CODE_INT 218 && TYPE_CODE (elttype) == TYPE_CODE_INT
237 && (options->format == 0 || options->format == 's') 219 && (options->format == 0 || options->format == 's')
238 && addr != 0) 220 && addr != 0)
239 return val_print_string (TYPE_TARGET_TYPE (type), NULL, addr, -1, 221 {
240 » » » stream, options); 222 if (want_space)
223 » fputs_filtered (" ", stream);
224 return val_print_string (TYPE_TARGET_TYPE (type), NULL, addr, -1,
225 » » » stream, options);
226 }
241 227
242 return 0; 228 return 0;
243 } 229 }
244 230
245 static void 231 static void
246 print_variable_at_address (struct type *type, 232 print_variable_at_address (struct type *type,
247 const gdb_byte *valaddr, 233 const gdb_byte *valaddr,
248 struct ui_file *stream, 234 struct ui_file *stream,
249 int recurse, 235 int recurse,
250 const struct value_print_options *options) 236 const struct value_print_options *options)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 { 288 {
303 fprintf_filtered (stream, "{"); 289 fprintf_filtered (stream, "{");
304 val_print_array_elements (type, valaddr, embedded_offset, 290 val_print_array_elements (type, valaddr, embedded_offset,
305 address, stream, recurse, val, 291 address, stream, recurse, val,
306 options, 0); 292 options, 0);
307 fprintf_filtered (stream, "}"); 293 fprintf_filtered (stream, "}");
308 } 294 }
309 } 295 }
310 } 296 }
311 297
298 /* Decorations for Modula 2. */
299
300 static const struct generic_val_print_decorations m2_decorations =
301 {
302 "",
303 " + ",
304 " * I",
305 "TRUE",
306 "FALSE",
307 "void"
308 };
312 309
313 /* See val_print for a description of the various parameters of this 310 /* See val_print for a description of the various parameters of this
314 function; they are identical. The semantics of the return value is 311 function; they are identical. */
315 also identical to val_print. */
316 312
317 int 313 void
318 m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, 314 m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
319 CORE_ADDR address, struct ui_file *stream, int recurse, 315 CORE_ADDR address, struct ui_file *stream, int recurse,
320 const struct value *original_value, 316 const struct value *original_value,
321 const struct value_print_options *options) 317 const struct value_print_options *options)
322 { 318 {
323 struct gdbarch *gdbarch = get_type_arch (type); 319 struct gdbarch *gdbarch = get_type_arch (type);
324 unsigned int i = 0; /* Number of characters printed. */ 320 unsigned int i = 0; /* Number of characters printed. */
325 unsigned len; 321 unsigned len;
326 struct type *elttype; 322 struct type *elttype;
327 unsigned eltlen; 323 unsigned eltlen;
328 LONGEST val;
329 CORE_ADDR addr; 324 CORE_ADDR addr;
330 325
331 CHECK_TYPEDEF (type); 326 CHECK_TYPEDEF (type);
332 switch (TYPE_CODE (type)) 327 switch (TYPE_CODE (type))
333 { 328 {
334 case TYPE_CODE_ARRAY: 329 case TYPE_CODE_ARRAY:
335 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) 330 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
336 { 331 {
337 elttype = check_typedef (TYPE_TARGET_TYPE (type)); 332 elttype = check_typedef (TYPE_TARGET_TYPE (type));
338 eltlen = TYPE_LENGTH (elttype); 333 eltlen = TYPE_LENGTH (elttype);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 else if (options->format && options->format != 's') 382 else if (options->format && options->format != 's')
388 val_print_scalar_formatted (type, valaddr, embedded_offset, 383 val_print_scalar_formatted (type, valaddr, embedded_offset,
389 original_value, options, 0, stream); 384 original_value, options, 0, stream);
390 else 385 else
391 { 386 {
392 addr = unpack_pointer (type, valaddr + embedded_offset); 387 addr = unpack_pointer (type, valaddr + embedded_offset);
393 print_unpacked_pointer (type, addr, address, options, stream); 388 print_unpacked_pointer (type, addr, address, options, stream);
394 } 389 }
395 break; 390 break;
396 391
397 case TYPE_CODE_REF:
398 elttype = check_typedef (TYPE_TARGET_TYPE (type));
399 if (options->addressprint)
400 {
401 CORE_ADDR addr
402 = extract_typed_address (valaddr + embedded_offset, type);
403
404 fprintf_filtered (stream, "@");
405 fputs_filtered (paddress (gdbarch, addr), stream);
406 if (options->deref_ref)
407 fputs_filtered (": ", stream);
408 }
409 /* De-reference the reference. */
410 if (options->deref_ref)
411 {
412 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
413 {
414 struct value *deref_val =
415 value_at
416 (TYPE_TARGET_TYPE (type),
417 unpack_pointer (type, valaddr + embedded_offset));
418
419 common_val_print (deref_val, stream, recurse, options,
420 current_language);
421 }
422 else
423 fputs_filtered ("???", stream);
424 }
425 break;
426
427 case TYPE_CODE_UNION: 392 case TYPE_CODE_UNION:
428 if (recurse && !options->unionprint) 393 if (recurse && !options->unionprint)
429 { 394 {
430 fprintf_filtered (stream, "{...}"); 395 fprintf_filtered (stream, "{...}");
431 break; 396 break;
432 } 397 }
433 /* Fall through. */ 398 /* Fall through. */
434 case TYPE_CODE_STRUCT: 399 case TYPE_CODE_STRUCT:
435 if (m2_is_long_set (type)) 400 if (m2_is_long_set (type))
436 m2_print_long_set (type, valaddr, embedded_offset, address, 401 m2_print_long_set (type, valaddr, embedded_offset, address,
437 stream); 402 stream);
438 else if (m2_is_unbounded_array (type)) 403 else if (m2_is_unbounded_array (type))
439 m2_print_unbounded_array (type, valaddr, embedded_offset, 404 m2_print_unbounded_array (type, valaddr, embedded_offset,
440 address, stream, recurse, options); 405 address, stream, recurse, options);
441 else 406 else
442 cp_print_value_fields (type, type, valaddr, embedded_offset, 407 cp_print_value_fields (type, type, valaddr, embedded_offset,
443 address, stream, recurse, original_value, 408 address, stream, recurse, original_value,
444 options, NULL, 0); 409 options, NULL, 0);
445 break; 410 break;
446 411
447 case TYPE_CODE_ENUM:
448 if (options->format)
449 {
450 val_print_scalar_formatted (type, valaddr, embedded_offset,
451 original_value, options, 0, stream);
452 break;
453 }
454 len = TYPE_NFIELDS (type);
455 val = unpack_long (type, valaddr + embedded_offset);
456 for (i = 0; i < len; i++)
457 {
458 QUIT;
459 if (val == TYPE_FIELD_BITPOS (type, i))
460 {
461 break;
462 }
463 }
464 if (i < len)
465 {
466 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
467 }
468 else
469 {
470 print_longest (stream, 'd', 0, val);
471 }
472 break;
473
474 case TYPE_CODE_FUNC:
475 if (options->format)
476 {
477 val_print_scalar_formatted (type, valaddr, embedded_offset,
478 original_value, options, 0, stream);
479 break;
480 }
481 /* FIXME, we should consider, at least for ANSI C language, eliminating
482 the distinction made between FUNCs and POINTERs to FUNCs. */
483 fprintf_filtered (stream, "{");
484 type_print (type, "", stream, -1);
485 fprintf_filtered (stream, "} ");
486 /* Try to print what function it points to, and its address. */
487 print_address_demangle (gdbarch, address, stream, demangle);
488 break;
489
490 case TYPE_CODE_BOOL:
491 if (options->format || options->output_format)
492 {
493 struct value_print_options opts = *options;
494
495 opts.format = (options->format ? options->format
496 : options->output_format);
497 val_print_scalar_formatted (type, valaddr, embedded_offset,
498 original_value, &opts, 0, stream);
499 }
500 else
501 {
502 val = unpack_long (type, valaddr + embedded_offset);
503 if (val == 0)
504 fputs_filtered ("FALSE", stream);
505 else if (val == 1)
506 fputs_filtered ("TRUE", stream);
507 else
508 fprintf_filtered (stream, "%ld)", (long int) val);
509 }
510 break;
511
512 case TYPE_CODE_RANGE:
513 if (TYPE_LENGTH (type) == TYPE_LENGTH (TYPE_TARGET_TYPE (type)))
514 {
515 m2_val_print (TYPE_TARGET_TYPE (type), valaddr, embedded_offset,
516 address, stream, recurse, original_value, options);
517 break;
518 }
519 /* FIXME: create_range_type does not set the unsigned bit in a
520 range type (I think it probably should copy it from the target
521 type), so we won't print values which are too large to
522 fit in a signed integer correctly. */
523 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
524 print with the target type, though, because the size of our type
525 and the target type might differ). */
526 /* FALLTHROUGH */
527
528 case TYPE_CODE_INT:
529 if (options->format || options->output_format)
530 {
531 struct value_print_options opts = *options;
532
533 opts.format = (options->format ? options->format
534 : options->output_format);
535 val_print_scalar_formatted (type, valaddr, embedded_offset,
536 original_value, &opts, 0, stream);
537 }
538 else
539 val_print_type_code_int (type, valaddr + embedded_offset, stream);
540 break;
541
542 case TYPE_CODE_CHAR:
543 if (options->format || options->output_format)
544 {
545 struct value_print_options opts = *options;
546
547 opts.format = (options->format ? options->format
548 : options->output_format);
549 val_print_scalar_formatted (type, valaddr, embedded_offset,
550 original_value, &opts, 0, stream);
551 }
552 else
553 {
554 val = unpack_long (type, valaddr + embedded_offset);
555 if (TYPE_UNSIGNED (type))
556 fprintf_filtered (stream, "%u", (unsigned int) val);
557 else
558 fprintf_filtered (stream, "%d", (int) val);
559 fputs_filtered (" ", stream);
560 LA_PRINT_CHAR ((unsigned char) val, type, stream);
561 }
562 break;
563
564 case TYPE_CODE_FLT:
565 if (options->format)
566 val_print_scalar_formatted (type, valaddr, embedded_offset,
567 original_value, options, 0, stream);
568 else
569 print_floating (valaddr + embedded_offset, type, stream);
570 break;
571
572 case TYPE_CODE_METHOD:
573 break;
574
575 case TYPE_CODE_BITSTRING: 412 case TYPE_CODE_BITSTRING:
576 case TYPE_CODE_SET: 413 case TYPE_CODE_SET:
577 elttype = TYPE_INDEX_TYPE (type); 414 elttype = TYPE_INDEX_TYPE (type);
578 CHECK_TYPEDEF (elttype); 415 CHECK_TYPEDEF (elttype);
579 if (TYPE_STUB (elttype)) 416 if (TYPE_STUB (elttype))
580 { 417 {
581 fprintf_filtered (stream, _("<incomplete type>")); 418 fprintf_filtered (stream, _("<incomplete type>"));
582 gdb_flush (stream); 419 gdb_flush (stream);
583 break; 420 break;
584 } 421 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 } 476 }
640 } 477 }
641 done: 478 done:
642 if (is_bitstring) 479 if (is_bitstring)
643 fputs_filtered ("'", stream); 480 fputs_filtered ("'", stream);
644 else 481 else
645 fputs_filtered ("}", stream); 482 fputs_filtered ("}", stream);
646 } 483 }
647 break; 484 break;
648 485
486 case TYPE_CODE_RANGE:
487 if (TYPE_LENGTH (type) == TYPE_LENGTH (TYPE_TARGET_TYPE (type)))
488 {
489 m2_val_print (TYPE_TARGET_TYPE (type), valaddr, embedded_offset,
490 address, stream, recurse, original_value, options);
491 break;
492 }
493 /* FIXME: create_range_type does not set the unsigned bit in a
494 range type (I think it probably should copy it from the target
495 type), so we won't print values which are too large to
496 fit in a signed integer correctly. */
497 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
498 print with the target type, though, because the size of our type
499 and the target type might differ). */
500 /* FALLTHROUGH */
501
502 case TYPE_CODE_REF:
503 case TYPE_CODE_ENUM:
504 case TYPE_CODE_FUNC:
505 case TYPE_CODE_INT:
506 case TYPE_CODE_FLT:
507 case TYPE_CODE_METHOD:
649 case TYPE_CODE_VOID: 508 case TYPE_CODE_VOID:
650 fprintf_filtered (stream, "void"); 509 case TYPE_CODE_ERROR:
510 case TYPE_CODE_UNDEF:
511 case TYPE_CODE_BOOL:
512 case TYPE_CODE_CHAR:
513 default:
514 generic_val_print (type, valaddr, embedded_offset, address,
515 » » » stream, recurse, original_value, options,
516 » » » &m2_decorations);
651 break; 517 break;
652
653 case TYPE_CODE_ERROR:
654 fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
655 break;
656
657 case TYPE_CODE_UNDEF:
658 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
659 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
660 and no complete type for struct foo in that file. */
661 fprintf_filtered (stream, _("<incomplete type>"));
662 break;
663
664 default:
665 error (_("Invalid m2 type code %d in symbol table."), TYPE_CODE (type));
666 } 518 }
667 gdb_flush (stream); 519 gdb_flush (stream);
668 return (0);
669 } 520 }
OLDNEW
« no previous file with comments | « gdb/m2-typeprint.c ('k') | gdb/m32c-tdep.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698