p-typeprint.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. /* Support for printing Pascal types for GDB, the GNU debugger.
  2. Copyright (C) 2000-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. /* This file is derived from p-typeprint.c */
  15. #include "defs.h"
  16. #include "gdbsupport/gdb_obstack.h"
  17. #include "bfd.h" /* Binary File Description */
  18. #include "symtab.h"
  19. #include "gdbtypes.h"
  20. #include "expression.h"
  21. #include "value.h"
  22. #include "gdbcore.h"
  23. #include "target.h"
  24. #include "language.h"
  25. #include "p-lang.h"
  26. #include "typeprint.h"
  27. #include "gdb-demangle.h"
  28. #include <ctype.h>
  29. #include "cli/cli-style.h"
  30. /* See language.h. */
  31. void
  32. pascal_language::print_type (struct type *type, const char *varstring,
  33. struct ui_file *stream, int show, int level,
  34. const struct type_print_options *flags) const
  35. {
  36. enum type_code code;
  37. int demangled_args;
  38. code = type->code ();
  39. if (show > 0)
  40. type = check_typedef (type);
  41. if ((code == TYPE_CODE_FUNC
  42. || code == TYPE_CODE_METHOD))
  43. {
  44. type_print_varspec_prefix (type, stream, show, 0, flags);
  45. }
  46. /* first the name */
  47. gdb_puts (varstring, stream);
  48. if ((varstring != NULL && *varstring != '\0')
  49. && !(code == TYPE_CODE_FUNC
  50. || code == TYPE_CODE_METHOD))
  51. {
  52. gdb_puts (" : ", stream);
  53. }
  54. if (!(code == TYPE_CODE_FUNC
  55. || code == TYPE_CODE_METHOD))
  56. {
  57. type_print_varspec_prefix (type, stream, show, 0, flags);
  58. }
  59. type_print_base (type, stream, show, level, flags);
  60. /* For demangled function names, we have the arglist as part of the name,
  61. so don't print an additional pair of ()'s. */
  62. demangled_args = varstring ? strchr (varstring, '(') != NULL : 0;
  63. type_print_varspec_suffix (type, stream, show, 0, demangled_args,
  64. flags);
  65. }
  66. /* See language.h. */
  67. void
  68. pascal_language::print_typedef (struct type *type, struct symbol *new_symbol,
  69. struct ui_file *stream) const
  70. {
  71. type = check_typedef (type);
  72. gdb_printf (stream, "type ");
  73. gdb_printf (stream, "%s = ", new_symbol->print_name ());
  74. type_print (type, "", stream, 0);
  75. gdb_printf (stream, ";");
  76. }
  77. /* See p-lang.h. */
  78. void
  79. pascal_language::type_print_derivation_info (struct ui_file *stream,
  80. struct type *type) const
  81. {
  82. const char *name;
  83. int i;
  84. for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
  85. {
  86. gdb_puts (i == 0 ? ": " : ", ", stream);
  87. gdb_printf (stream, "%s%s ",
  88. BASETYPE_VIA_PUBLIC (type, i) ? "public" : "private",
  89. BASETYPE_VIA_VIRTUAL (type, i) ? " virtual" : "");
  90. name = TYPE_BASECLASS (type, i)->name ();
  91. gdb_printf (stream, "%s", name ? name : "(null)");
  92. }
  93. if (i > 0)
  94. {
  95. gdb_puts (" ", stream);
  96. }
  97. }
  98. /* See p-lang.h. */
  99. void
  100. pascal_language::type_print_method_args (const char *physname,
  101. const char *methodname,
  102. struct ui_file *stream) const
  103. {
  104. int is_constructor = (startswith (physname, "__ct__"));
  105. int is_destructor = (startswith (physname, "__dt__"));
  106. if (is_constructor || is_destructor)
  107. {
  108. physname += 6;
  109. }
  110. gdb_puts (methodname, stream);
  111. if (physname && (*physname != 0))
  112. {
  113. gdb_puts (" (", stream);
  114. /* We must demangle this. */
  115. while (isdigit (physname[0]))
  116. {
  117. int len = 0;
  118. int i, j;
  119. char *argname;
  120. while (isdigit (physname[len]))
  121. {
  122. len++;
  123. }
  124. i = strtol (physname, &argname, 0);
  125. physname += len;
  126. for (j = 0; j < i; ++j)
  127. gdb_putc (physname[j], stream);
  128. physname += i;
  129. if (physname[0] != 0)
  130. {
  131. gdb_puts (", ", stream);
  132. }
  133. }
  134. gdb_puts (")", stream);
  135. }
  136. }
  137. /* See p-lang.h. */
  138. void
  139. pascal_language::type_print_varspec_prefix (struct type *type,
  140. struct ui_file *stream,
  141. int show, int passed_a_ptr,
  142. const struct type_print_options *flags) const
  143. {
  144. if (type == 0)
  145. return;
  146. if (type->name () && show <= 0)
  147. return;
  148. QUIT;
  149. switch (type->code ())
  150. {
  151. case TYPE_CODE_PTR:
  152. gdb_printf (stream, "^");
  153. type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1,
  154. flags);
  155. break; /* Pointer should be handled normally
  156. in pascal. */
  157. case TYPE_CODE_METHOD:
  158. if (passed_a_ptr)
  159. gdb_printf (stream, "(");
  160. if (TYPE_TARGET_TYPE (type) != NULL
  161. && TYPE_TARGET_TYPE (type)->code () != TYPE_CODE_VOID)
  162. {
  163. gdb_printf (stream, "function ");
  164. }
  165. else
  166. {
  167. gdb_printf (stream, "procedure ");
  168. }
  169. if (passed_a_ptr)
  170. {
  171. gdb_printf (stream, " ");
  172. type_print_base (TYPE_SELF_TYPE (type),
  173. stream, 0, passed_a_ptr, flags);
  174. gdb_printf (stream, "::");
  175. }
  176. break;
  177. case TYPE_CODE_REF:
  178. type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1,
  179. flags);
  180. gdb_printf (stream, "&");
  181. break;
  182. case TYPE_CODE_FUNC:
  183. if (passed_a_ptr)
  184. gdb_printf (stream, "(");
  185. if (TYPE_TARGET_TYPE (type) != NULL
  186. && TYPE_TARGET_TYPE (type)->code () != TYPE_CODE_VOID)
  187. {
  188. gdb_printf (stream, "function ");
  189. }
  190. else
  191. {
  192. gdb_printf (stream, "procedure ");
  193. }
  194. break;
  195. case TYPE_CODE_ARRAY:
  196. if (passed_a_ptr)
  197. gdb_printf (stream, "(");
  198. gdb_printf (stream, "array ");
  199. if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
  200. && type->bounds ()->high.kind () != PROP_UNDEFINED)
  201. gdb_printf (stream, "[%s..%s] ",
  202. plongest (type->bounds ()->low.const_val ()),
  203. plongest (type->bounds ()->high.const_val ()));
  204. gdb_printf (stream, "of ");
  205. break;
  206. case TYPE_CODE_UNDEF:
  207. case TYPE_CODE_STRUCT:
  208. case TYPE_CODE_UNION:
  209. case TYPE_CODE_ENUM:
  210. case TYPE_CODE_INT:
  211. case TYPE_CODE_FLT:
  212. case TYPE_CODE_VOID:
  213. case TYPE_CODE_ERROR:
  214. case TYPE_CODE_CHAR:
  215. case TYPE_CODE_BOOL:
  216. case TYPE_CODE_SET:
  217. case TYPE_CODE_RANGE:
  218. case TYPE_CODE_STRING:
  219. case TYPE_CODE_COMPLEX:
  220. case TYPE_CODE_TYPEDEF:
  221. case TYPE_CODE_FIXED_POINT:
  222. /* These types need no prefix. They are listed here so that
  223. gcc -Wall will reveal any types that haven't been handled. */
  224. break;
  225. default:
  226. gdb_assert_not_reached ("unexpected type");
  227. break;
  228. }
  229. }
  230. /* See p-lang.h. */
  231. void
  232. pascal_language::print_func_args (struct type *type, struct ui_file *stream,
  233. const struct type_print_options *flags) const
  234. {
  235. int i, len = type->num_fields ();
  236. if (len)
  237. {
  238. gdb_printf (stream, "(");
  239. }
  240. for (i = 0; i < len; i++)
  241. {
  242. if (i > 0)
  243. {
  244. gdb_puts (", ", stream);
  245. stream->wrap_here (4);
  246. }
  247. /* Can we find if it is a var parameter ??
  248. if ( TYPE_FIELD(type, i) == )
  249. {
  250. gdb_printf (stream, "var ");
  251. } */
  252. print_type (type->field (i).type (), "" /* TYPE_FIELD_NAME
  253. seems invalid! */
  254. ,stream, -1, 0, flags);
  255. }
  256. if (len)
  257. {
  258. gdb_printf (stream, ")");
  259. }
  260. }
  261. /* See p-lang.h. */
  262. void
  263. pascal_language::type_print_func_varspec_suffix (struct type *type,
  264. struct ui_file *stream,
  265. int show, int passed_a_ptr,
  266. int demangled_args,
  267. const struct type_print_options *flags) const
  268. {
  269. if (TYPE_TARGET_TYPE (type) == NULL
  270. || TYPE_TARGET_TYPE (type)->code () != TYPE_CODE_VOID)
  271. {
  272. gdb_printf (stream, " : ");
  273. type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
  274. stream, 0, 0, flags);
  275. if (TYPE_TARGET_TYPE (type) == NULL)
  276. type_print_unknown_return_type (stream);
  277. else
  278. type_print_base (TYPE_TARGET_TYPE (type), stream, show, 0,
  279. flags);
  280. type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
  281. passed_a_ptr, 0, flags);
  282. }
  283. }
  284. /* See p-lang.h. */
  285. void
  286. pascal_language::type_print_varspec_suffix (struct type *type,
  287. struct ui_file *stream,
  288. int show, int passed_a_ptr,
  289. int demangled_args,
  290. const struct type_print_options *flags) const
  291. {
  292. if (type == 0)
  293. return;
  294. if (type->name () && show <= 0)
  295. return;
  296. QUIT;
  297. switch (type->code ())
  298. {
  299. case TYPE_CODE_ARRAY:
  300. if (passed_a_ptr)
  301. gdb_printf (stream, ")");
  302. break;
  303. case TYPE_CODE_METHOD:
  304. if (passed_a_ptr)
  305. gdb_printf (stream, ")");
  306. type_print_method_args ("", "", stream);
  307. type_print_func_varspec_suffix (type, stream, show,
  308. passed_a_ptr, 0, flags);
  309. break;
  310. case TYPE_CODE_PTR:
  311. case TYPE_CODE_REF:
  312. type_print_varspec_suffix (TYPE_TARGET_TYPE (type),
  313. stream, 0, 1, 0, flags);
  314. break;
  315. case TYPE_CODE_FUNC:
  316. if (passed_a_ptr)
  317. gdb_printf (stream, ")");
  318. if (!demangled_args)
  319. print_func_args (type, stream, flags);
  320. type_print_func_varspec_suffix (type, stream, show,
  321. passed_a_ptr, 0, flags);
  322. break;
  323. case TYPE_CODE_UNDEF:
  324. case TYPE_CODE_STRUCT:
  325. case TYPE_CODE_UNION:
  326. case TYPE_CODE_ENUM:
  327. case TYPE_CODE_INT:
  328. case TYPE_CODE_FLT:
  329. case TYPE_CODE_VOID:
  330. case TYPE_CODE_ERROR:
  331. case TYPE_CODE_CHAR:
  332. case TYPE_CODE_BOOL:
  333. case TYPE_CODE_SET:
  334. case TYPE_CODE_RANGE:
  335. case TYPE_CODE_STRING:
  336. case TYPE_CODE_COMPLEX:
  337. case TYPE_CODE_TYPEDEF:
  338. case TYPE_CODE_FIXED_POINT:
  339. /* These types do not need a suffix. They are listed so that
  340. gcc -Wall will report types that may not have been considered. */
  341. break;
  342. default:
  343. gdb_assert_not_reached ("unexpected type");
  344. break;
  345. }
  346. }
  347. /* See p-lang.h. */
  348. void
  349. pascal_language::type_print_base (struct type *type, struct ui_file *stream, int show,
  350. int level, const struct type_print_options *flags) const
  351. {
  352. int i;
  353. int len;
  354. LONGEST lastval;
  355. enum
  356. {
  357. s_none, s_public, s_private, s_protected
  358. }
  359. section_type;
  360. QUIT;
  361. stream->wrap_here (4);
  362. if (type == NULL)
  363. {
  364. fputs_styled ("<type unknown>", metadata_style.style (), stream);
  365. return;
  366. }
  367. /* void pointer */
  368. if ((type->code () == TYPE_CODE_PTR)
  369. && (TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_VOID))
  370. {
  371. gdb_puts (type->name () ? type->name () : "pointer",
  372. stream);
  373. return;
  374. }
  375. /* When SHOW is zero or less, and there is a valid type name, then always
  376. just print the type name directly from the type. */
  377. if (show <= 0
  378. && type->name () != NULL)
  379. {
  380. gdb_puts (type->name (), stream);
  381. return;
  382. }
  383. type = check_typedef (type);
  384. switch (type->code ())
  385. {
  386. case TYPE_CODE_TYPEDEF:
  387. case TYPE_CODE_PTR:
  388. case TYPE_CODE_REF:
  389. type_print_base (TYPE_TARGET_TYPE (type), stream, show, level,
  390. flags);
  391. break;
  392. case TYPE_CODE_ARRAY:
  393. print_type (TYPE_TARGET_TYPE (type), NULL, stream, 0, 0, flags);
  394. break;
  395. case TYPE_CODE_FUNC:
  396. case TYPE_CODE_METHOD:
  397. break;
  398. case TYPE_CODE_STRUCT:
  399. if (type->name () != NULL)
  400. {
  401. gdb_puts (type->name (), stream);
  402. gdb_puts (" = ", stream);
  403. }
  404. if (HAVE_CPLUS_STRUCT (type))
  405. {
  406. gdb_printf (stream, "class ");
  407. }
  408. else
  409. {
  410. gdb_printf (stream, "record ");
  411. }
  412. goto struct_union;
  413. case TYPE_CODE_UNION:
  414. if (type->name () != NULL)
  415. {
  416. gdb_puts (type->name (), stream);
  417. gdb_puts (" = ", stream);
  418. }
  419. gdb_printf (stream, "case <?> of ");
  420. struct_union:
  421. stream->wrap_here (4);
  422. if (show < 0)
  423. {
  424. /* If we just printed a tag name, no need to print anything else. */
  425. if (type->name () == NULL)
  426. gdb_printf (stream, "{...}");
  427. }
  428. else if (show > 0 || type->name () == NULL)
  429. {
  430. type_print_derivation_info (stream, type);
  431. gdb_printf (stream, "\n");
  432. if ((type->num_fields () == 0) && (TYPE_NFN_FIELDS (type) == 0))
  433. {
  434. if (type->is_stub ())
  435. gdb_printf (stream, "%*s<incomplete type>\n",
  436. level + 4, "");
  437. else
  438. gdb_printf (stream, "%*s<no data fields>\n",
  439. level + 4, "");
  440. }
  441. /* Start off with no specific section type, so we can print
  442. one for the first field we find, and use that section type
  443. thereafter until we find another type. */
  444. section_type = s_none;
  445. /* If there is a base class for this type,
  446. do not print the field that it occupies. */
  447. len = type->num_fields ();
  448. for (i = TYPE_N_BASECLASSES (type); i < len; i++)
  449. {
  450. QUIT;
  451. /* Don't print out virtual function table. */
  452. if ((startswith (type->field (i).name (), "_vptr"))
  453. && is_cplus_marker ((type->field (i).name ())[5]))
  454. continue;
  455. /* If this is a pascal object or class we can print the
  456. various section labels. */
  457. if (HAVE_CPLUS_STRUCT (type))
  458. {
  459. if (TYPE_FIELD_PROTECTED (type, i))
  460. {
  461. if (section_type != s_protected)
  462. {
  463. section_type = s_protected;
  464. gdb_printf (stream, "%*sprotected\n",
  465. level + 2, "");
  466. }
  467. }
  468. else if (TYPE_FIELD_PRIVATE (type, i))
  469. {
  470. if (section_type != s_private)
  471. {
  472. section_type = s_private;
  473. gdb_printf (stream, "%*sprivate\n",
  474. level + 2, "");
  475. }
  476. }
  477. else
  478. {
  479. if (section_type != s_public)
  480. {
  481. section_type = s_public;
  482. gdb_printf (stream, "%*spublic\n",
  483. level + 2, "");
  484. }
  485. }
  486. }
  487. print_spaces (level + 4, stream);
  488. if (field_is_static (&type->field (i)))
  489. gdb_printf (stream, "static ");
  490. print_type (type->field (i).type (),
  491. type->field (i).name (),
  492. stream, show - 1, level + 4, flags);
  493. if (!field_is_static (&type->field (i))
  494. && TYPE_FIELD_PACKED (type, i))
  495. {
  496. /* It is a bitfield. This code does not attempt
  497. to look at the bitpos and reconstruct filler,
  498. unnamed fields. This would lead to misleading
  499. results if the compiler does not put out fields
  500. for such things (I don't know what it does). */
  501. gdb_printf (stream, " : %d",
  502. TYPE_FIELD_BITSIZE (type, i));
  503. }
  504. gdb_printf (stream, ";\n");
  505. }
  506. /* If there are both fields and methods, put a space between. */
  507. len = TYPE_NFN_FIELDS (type);
  508. if (len && section_type != s_none)
  509. gdb_printf (stream, "\n");
  510. /* Object pascal: print out the methods. */
  511. for (i = 0; i < len; i++)
  512. {
  513. struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
  514. int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
  515. const char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
  516. /* this is GNU C++ specific
  517. how can we know constructor/destructor?
  518. It might work for GNU pascal. */
  519. for (j = 0; j < len2; j++)
  520. {
  521. const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
  522. int is_constructor = (startswith (physname, "__ct__"));
  523. int is_destructor = (startswith (physname, "__dt__"));
  524. QUIT;
  525. if (TYPE_FN_FIELD_PROTECTED (f, j))
  526. {
  527. if (section_type != s_protected)
  528. {
  529. section_type = s_protected;
  530. gdb_printf (stream, "%*sprotected\n",
  531. level + 2, "");
  532. }
  533. }
  534. else if (TYPE_FN_FIELD_PRIVATE (f, j))
  535. {
  536. if (section_type != s_private)
  537. {
  538. section_type = s_private;
  539. gdb_printf (stream, "%*sprivate\n",
  540. level + 2, "");
  541. }
  542. }
  543. else
  544. {
  545. if (section_type != s_public)
  546. {
  547. section_type = s_public;
  548. gdb_printf (stream, "%*spublic\n",
  549. level + 2, "");
  550. }
  551. }
  552. print_spaces (level + 4, stream);
  553. if (TYPE_FN_FIELD_STATIC_P (f, j))
  554. gdb_printf (stream, "static ");
  555. if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
  556. {
  557. /* Keep GDB from crashing here. */
  558. gdb_printf (stream, "<undefined type> %s;\n",
  559. TYPE_FN_FIELD_PHYSNAME (f, j));
  560. break;
  561. }
  562. if (is_constructor)
  563. {
  564. gdb_printf (stream, "constructor ");
  565. }
  566. else if (is_destructor)
  567. {
  568. gdb_printf (stream, "destructor ");
  569. }
  570. else if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) != 0
  571. && TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE(f, j))->code () != TYPE_CODE_VOID)
  572. {
  573. gdb_printf (stream, "function ");
  574. }
  575. else
  576. {
  577. gdb_printf (stream, "procedure ");
  578. }
  579. /* This does not work, no idea why !! */
  580. type_print_method_args (physname, method_name, stream);
  581. if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) != 0
  582. && TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE(f, j))->code () != TYPE_CODE_VOID)
  583. {
  584. gdb_puts (" : ", stream);
  585. type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
  586. "", stream, -1);
  587. }
  588. if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
  589. gdb_printf (stream, "; virtual");
  590. gdb_printf (stream, ";\n");
  591. }
  592. }
  593. gdb_printf (stream, "%*send", level, "");
  594. }
  595. break;
  596. case TYPE_CODE_ENUM:
  597. if (type->name () != NULL)
  598. {
  599. gdb_puts (type->name (), stream);
  600. if (show > 0)
  601. gdb_puts (" ", stream);
  602. }
  603. /* enum is just defined by
  604. type enume_name = (enum_member1,enum_member2,...) */
  605. gdb_printf (stream, " = ");
  606. stream->wrap_here (4);
  607. if (show < 0)
  608. {
  609. /* If we just printed a tag name, no need to print anything else. */
  610. if (type->name () == NULL)
  611. gdb_printf (stream, "(...)");
  612. }
  613. else if (show > 0 || type->name () == NULL)
  614. {
  615. gdb_printf (stream, "(");
  616. len = type->num_fields ();
  617. lastval = 0;
  618. for (i = 0; i < len; i++)
  619. {
  620. QUIT;
  621. if (i)
  622. gdb_printf (stream, ", ");
  623. stream->wrap_here (4);
  624. gdb_puts (type->field (i).name (), stream);
  625. if (lastval != type->field (i).loc_enumval ())
  626. {
  627. gdb_printf (stream,
  628. " := %s",
  629. plongest (type->field (i).loc_enumval ()));
  630. lastval = type->field (i).loc_enumval ();
  631. }
  632. lastval++;
  633. }
  634. gdb_printf (stream, ")");
  635. }
  636. break;
  637. case TYPE_CODE_VOID:
  638. gdb_printf (stream, "void");
  639. break;
  640. case TYPE_CODE_UNDEF:
  641. gdb_printf (stream, "record <unknown>");
  642. break;
  643. case TYPE_CODE_ERROR:
  644. gdb_printf (stream, "%s", TYPE_ERROR_NAME (type));
  645. break;
  646. /* this probably does not work for enums. */
  647. case TYPE_CODE_RANGE:
  648. {
  649. struct type *target = TYPE_TARGET_TYPE (type);
  650. print_type_scalar (target, type->bounds ()->low.const_val (), stream);
  651. gdb_puts ("..", stream);
  652. print_type_scalar (target, type->bounds ()->high.const_val (), stream);
  653. }
  654. break;
  655. case TYPE_CODE_SET:
  656. gdb_puts ("set of ", stream);
  657. print_type (type->index_type (), "", stream,
  658. show - 1, level, flags);
  659. break;
  660. case TYPE_CODE_STRING:
  661. gdb_puts ("String", stream);
  662. break;
  663. default:
  664. /* Handle types not explicitly handled by the other cases,
  665. such as fundamental types. For these, just print whatever
  666. the type name is, as recorded in the type itself. If there
  667. is no type name, then complain. */
  668. if (type->name () != NULL)
  669. {
  670. gdb_puts (type->name (), stream);
  671. }
  672. else
  673. {
  674. /* At least for dump_symtab, it is important that this not be
  675. an error (). */
  676. fprintf_styled (stream, metadata_style.style (),
  677. "<invalid unnamed pascal type code %d>",
  678. type->code ());
  679. }
  680. break;
  681. }
  682. }