You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5082 lines
120 KiB

Added all changes from old 4.0 version: PSTACK, libmysqld and MySQL filesystem UPDATE ... ORDER BY DELETE ... ORDER BY New faster fulltext handling Faster compressed keys Makefile.am: Added support for pstack and libmysqld_dir acconfig.h: MySQL filesystem and PSTACK acinclude.m4: MySQL File system client/mysql.cc: Support for --xml configure.in: Pstack, MySQL FS and libmysqld_dir include/ft_global.h: Faster fulltext include/my_pthread.h: Made c++ safe include/myisam.h: Update for faster fulltext include/mysql_com.h: new my_net_read() include/violite.h: libmysqld libmysql/net.c: New protocol that supports big packets myisam/Makefile.am: Faster fulltext myisam/ft_parser.c: Faster fulltext myisam/ft_search.c: Faster fulltext myisam/ft_update.c: Faster fulltext myisam/ftdefs.h: Faster fulltext myisam/mi_check.c: Faster fulltext myisam/mi_open.c: Faster compressed keys myisam/mi_search.c: Faster compressed keys myisam/mi_update.c: Faster compressed keys myisam/myisamdef.h: Faster compressed keys myisam/sort.c: Faster compressed keys mysql-test/mysql-test-run.sh: --skip-innobase and --skip-bdb sql/ChangeLog: Changelog sql/Makefile.am: PSTACK sql/mysql_priv.h: New ORDER BY options and libmysqld sql/mysqld.cc: PSTACK sql/net_serv.cc: New protocol that supports big packets sql/share/estonian/errmsg.txt: New error messages sql/sql_base.cc: Better list_open_tabels sql/sql_delete.cc: ORDER BY for delete sql/sql_lex.cc: Added language convertation of all strings sql/sql_parse.cc: Changes for libmysqld Use new ORDER BY options sql/sql_show.cc: Character set convertations Use new list_open_tables function. sql/sql_update.cc: UPDATE ... ORDER BY sql/sql_yacc.yy: Clean up symbol definitions DELETE .. ORDER BY UPDATE .. ORDER BY sql/table.h: new OPEN_TABLE_LIST structure BitKeeper/etc/logging_ok: Logging to logging@openlogging.org accepted
25 years ago
  1. /* stabs.c -- Parse stabs debugging information
  2. Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
  3. Written by Ian Lance Taylor <ian@cygnus.com>.
  4. This file is part of GNU Binutils.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  16. 02111-1307, USA. */
  17. /* This file contains code which parses stabs debugging information.
  18. The organization of this code is based on the gdb stabs reading
  19. code. The job it does is somewhat different, because it is not
  20. trying to identify the correct address for anything. */
  21. #include <stdio.h>
  22. #include <ctype.h>
  23. #include <bfd.h>
  24. #include "bucomm.h"
  25. #include <libiberty.h>
  26. #include "demangle.h"
  27. #include "debug.h"
  28. #include "budbg.h"
  29. /* Meaningless definition needs by aout64.h. FIXME. */
  30. #define BYTES_IN_WORD 4
  31. #include "aout/aout64.h"
  32. #include "aout/stab_gnu.h"
  33. /* The number of predefined XCOFF types. */
  34. #define XCOFF_TYPE_COUNT 34
  35. /* This structure is used as a handle so that the stab parsing doesn't
  36. need to use any static variables. */
  37. struct stab_handle
  38. {
  39. /* The BFD. */
  40. bfd *abfd;
  41. /* True if this is stabs in sections. */
  42. boolean sections;
  43. /* The symbol table. */
  44. asymbol **syms;
  45. /* The number of symbols. */
  46. long symcount;
  47. /* The accumulated file name string. */
  48. char *so_string;
  49. /* The value of the last N_SO symbol. */
  50. bfd_vma so_value;
  51. /* The value of the start of the file, so that we can handle file
  52. relative N_LBRAC and N_RBRAC symbols. */
  53. bfd_vma file_start_offset;
  54. /* The offset of the start of the function, so that we can handle
  55. function relative N_LBRAC and N_RBRAC symbols. */
  56. bfd_vma function_start_offset;
  57. /* The version number of gcc which compiled the current compilation
  58. unit, 0 if not compiled by gcc. */
  59. int gcc_compiled;
  60. /* Whether an N_OPT symbol was seen that was not generated by gcc,
  61. so that we can detect the SunPRO compiler. */
  62. boolean n_opt_found;
  63. /* The main file name. */
  64. char *main_filename;
  65. /* A stack of unfinished N_BINCL files. */
  66. struct bincl_file *bincl_stack;
  67. /* A list of finished N_BINCL files. */
  68. struct bincl_file *bincl_list;
  69. /* Whether we are inside a function or not. */
  70. boolean within_function;
  71. /* The address of the end of the function, used if we have seen an
  72. N_FUN symbol while in a function. This is -1 if we have not seen
  73. an N_FUN (the normal case). */
  74. bfd_vma function_end;
  75. /* The depth of block nesting. */
  76. int block_depth;
  77. /* List of pending variable definitions. */
  78. struct stab_pending_var *pending;
  79. /* Number of files for which we have types. */
  80. unsigned int files;
  81. /* Lists of types per file. */
  82. struct stab_types **file_types;
  83. /* Predefined XCOFF types. */
  84. debug_type xcoff_types[XCOFF_TYPE_COUNT];
  85. /* Undefined tags. */
  86. struct stab_tag *tags;
  87. };
  88. /* A list of these structures is used to hold pending variable
  89. definitions seen before the N_LBRAC of a block. */
  90. struct stab_pending_var
  91. {
  92. /* Next pending variable definition. */
  93. struct stab_pending_var *next;
  94. /* Name. */
  95. const char *name;
  96. /* Type. */
  97. debug_type type;
  98. /* Kind. */
  99. enum debug_var_kind kind;
  100. /* Value. */
  101. bfd_vma val;
  102. };
  103. /* A list of these structures is used to hold the types for a single
  104. file. */
  105. struct stab_types
  106. {
  107. /* Next set of slots for this file. */
  108. struct stab_types *next;
  109. /* Types indexed by type number. */
  110. #define STAB_TYPES_SLOTS (16)
  111. debug_type types[STAB_TYPES_SLOTS];
  112. };
  113. /* We keep a list of undefined tags that we encounter, so that we can
  114. fill them in if the tag is later defined. */
  115. struct stab_tag
  116. {
  117. /* Next undefined tag. */
  118. struct stab_tag *next;
  119. /* Tag name. */
  120. const char *name;
  121. /* Type kind. */
  122. enum debug_type_kind kind;
  123. /* Slot to hold real type when we discover it. If we don't, we fill
  124. in an undefined tag type. */
  125. debug_type slot;
  126. /* Indirect type we have created to point at slot. */
  127. debug_type type;
  128. };
  129. static char *savestring PARAMS ((const char *, int));
  130. static bfd_vma parse_number PARAMS ((const char **, boolean *));
  131. static void bad_stab PARAMS ((const char *));
  132. static void warn_stab PARAMS ((const char *, const char *));
  133. static boolean parse_stab_string
  134. PARAMS ((PTR, struct stab_handle *, int, int, bfd_vma, const char *));
  135. static debug_type parse_stab_type
  136. PARAMS ((PTR, struct stab_handle *, const char *, const char **,
  137. debug_type **));
  138. static boolean parse_stab_type_number
  139. PARAMS ((const char **, int *));
  140. static debug_type parse_stab_range_type
  141. PARAMS ((PTR, struct stab_handle *, const char *, const char **,
  142. const int *));
  143. static debug_type parse_stab_sun_builtin_type PARAMS ((PTR, const char **));
  144. static debug_type parse_stab_sun_floating_type
  145. PARAMS ((PTR, const char **));
  146. static debug_type parse_stab_enum_type PARAMS ((PTR, const char **));
  147. static debug_type parse_stab_struct_type
  148. PARAMS ((PTR, struct stab_handle *, const char *, const char **, boolean,
  149. const int *));
  150. static boolean parse_stab_baseclasses
  151. PARAMS ((PTR, struct stab_handle *, const char **, debug_baseclass **));
  152. static boolean parse_stab_struct_fields
  153. PARAMS ((PTR, struct stab_handle *, const char **, debug_field **,
  154. boolean *));
  155. static boolean parse_stab_cpp_abbrev
  156. PARAMS ((PTR, struct stab_handle *, const char **, debug_field *));
  157. static boolean parse_stab_one_struct_field
  158. PARAMS ((PTR, struct stab_handle *, const char **, const char *,
  159. debug_field *, boolean *));
  160. static boolean parse_stab_members
  161. PARAMS ((PTR, struct stab_handle *, const char *, const char **,
  162. const int *, debug_method **));
  163. static debug_type parse_stab_argtypes
  164. PARAMS ((PTR, struct stab_handle *, debug_type, const char *, const char *,
  165. debug_type, const char *, boolean, boolean, const char **));
  166. static boolean parse_stab_tilde_field
  167. PARAMS ((PTR, struct stab_handle *, const char **, const int *,
  168. debug_type *, boolean *));
  169. static debug_type parse_stab_array_type
  170. PARAMS ((PTR, struct stab_handle *, const char **, boolean));
  171. static void push_bincl PARAMS ((struct stab_handle *, const char *, bfd_vma));
  172. static const char *pop_bincl PARAMS ((struct stab_handle *));
  173. static boolean find_excl
  174. PARAMS ((struct stab_handle *, const char *, bfd_vma));
  175. static boolean stab_record_variable
  176. PARAMS ((PTR, struct stab_handle *, const char *, debug_type,
  177. enum debug_var_kind, bfd_vma));
  178. static boolean stab_emit_pending_vars PARAMS ((PTR, struct stab_handle *));
  179. static debug_type *stab_find_slot
  180. PARAMS ((struct stab_handle *, const int *));
  181. static debug_type stab_find_type
  182. PARAMS ((PTR, struct stab_handle *, const int *));
  183. static boolean stab_record_type
  184. PARAMS ((PTR, struct stab_handle *, const int *, debug_type));
  185. static debug_type stab_xcoff_builtin_type
  186. PARAMS ((PTR, struct stab_handle *, int));
  187. static debug_type stab_find_tagged_type
  188. PARAMS ((PTR, struct stab_handle *, const char *, int,
  189. enum debug_type_kind));
  190. static debug_type *stab_demangle_argtypes
  191. PARAMS ((PTR, struct stab_handle *, const char *, boolean *));
  192. /* Save a string in memory. */
  193. static char *
  194. savestring (start, len)
  195. const char *start;
  196. int len;
  197. {
  198. char *ret;
  199. ret = (char *) xmalloc (len + 1);
  200. memcpy (ret, start, len);
  201. ret[len] = '\0';
  202. return ret;
  203. }
  204. /* Read a number from a string. */
  205. static bfd_vma
  206. parse_number (pp, poverflow)
  207. const char **pp;
  208. boolean *poverflow;
  209. {
  210. unsigned long ul;
  211. const char *orig;
  212. if (poverflow != NULL)
  213. *poverflow = false;
  214. orig = *pp;
  215. errno = 0;
  216. ul = strtoul (*pp, (char **) pp, 0);
  217. if (ul + 1 != 0 || errno == 0)
  218. return (bfd_vma) ul;
  219. /* Note that even though strtoul overflowed, it should have set *pp
  220. to the end of the number, which is where we want it. */
  221. if (sizeof (bfd_vma) > sizeof (unsigned long))
  222. {
  223. const char *p;
  224. boolean neg;
  225. int base;
  226. bfd_vma over, lastdig;
  227. boolean overflow;
  228. bfd_vma v;
  229. /* Our own version of strtoul, for a bfd_vma. */
  230. p = orig;
  231. neg = false;
  232. if (*p == '+')
  233. ++p;
  234. else if (*p == '-')
  235. {
  236. neg = true;
  237. ++p;
  238. }
  239. base = 10;
  240. if (*p == '0')
  241. {
  242. if (p[1] == 'x' || p[1] == 'X')
  243. {
  244. base = 16;
  245. p += 2;
  246. }
  247. else
  248. {
  249. base = 8;
  250. ++p;
  251. }
  252. }
  253. over = ((bfd_vma) (bfd_signed_vma) -1) / (bfd_vma) base;
  254. lastdig = ((bfd_vma) (bfd_signed_vma) -1) % (bfd_vma) base;
  255. overflow = false;
  256. v = 0;
  257. while (1)
  258. {
  259. int d;
  260. d = *p++;
  261. if (isdigit ((unsigned char) d))
  262. d -= '0';
  263. else if (isupper ((unsigned char) d))
  264. d -= 'A';
  265. else if (islower ((unsigned char) d))
  266. d -= 'a';
  267. else
  268. break;
  269. if (d >= base)
  270. break;
  271. if (v > over || (v == over && (bfd_vma) d > lastdig))
  272. {
  273. overflow = true;
  274. break;
  275. }
  276. }
  277. if (! overflow)
  278. {
  279. if (neg)
  280. v = - v;
  281. return v;
  282. }
  283. }
  284. /* If we get here, the number is too large to represent in a
  285. bfd_vma. */
  286. if (poverflow != NULL)
  287. *poverflow = true;
  288. else
  289. warn_stab (orig, "numeric overflow");
  290. return 0;
  291. }
  292. /* Give an error for a bad stab string. */
  293. static void
  294. bad_stab (p)
  295. const char *p;
  296. {
  297. fprintf (stderr, "Bad stab: %s\n", p);
  298. }
  299. /* Warn about something in a stab string. */
  300. static void
  301. warn_stab (p, err)
  302. const char *p;
  303. const char *err;
  304. {
  305. fprintf (stderr, "Warning: %s: %s\n", err, p);
  306. }
  307. /* Create a handle to parse stabs symbols with. */
  308. /*ARGSUSED*/
  309. PTR
  310. start_stab (dhandle, abfd, sections, syms, symcount)
  311. PTR dhandle;
  312. bfd *abfd;
  313. boolean sections;
  314. asymbol **syms;
  315. long symcount;
  316. {
  317. struct stab_handle *ret;
  318. ret = (struct stab_handle *) xmalloc (sizeof *ret);
  319. memset (ret, 0, sizeof *ret);
  320. ret->abfd = abfd;
  321. ret->sections = sections;
  322. ret->syms = syms;
  323. ret->symcount = symcount;
  324. ret->files = 1;
  325. ret->file_types = (struct stab_types **) xmalloc (sizeof *ret->file_types);
  326. ret->file_types[0] = NULL;
  327. ret->function_end = (bfd_vma) -1;
  328. return (PTR) ret;
  329. }
  330. /* When we have processed all the stabs information, we need to go
  331. through and fill in all the undefined tags. */
  332. boolean
  333. finish_stab (dhandle, handle)
  334. PTR dhandle;
  335. PTR handle;
  336. {
  337. struct stab_handle *info = (struct stab_handle *) handle;
  338. struct stab_tag *st;
  339. if (info->within_function)
  340. {
  341. if (! stab_emit_pending_vars (dhandle, info)
  342. || ! debug_end_function (dhandle, info->function_end))
  343. return false;
  344. info->within_function = false;
  345. info->function_end = (bfd_vma) -1;
  346. }
  347. for (st = info->tags; st != NULL; st = st->next)
  348. {
  349. enum debug_type_kind kind;
  350. kind = st->kind;
  351. if (kind == DEBUG_KIND_ILLEGAL)
  352. kind = DEBUG_KIND_STRUCT;
  353. st->slot = debug_make_undefined_tagged_type (dhandle, st->name, kind);
  354. if (st->slot == DEBUG_TYPE_NULL)
  355. return false;
  356. }
  357. return true;
  358. }
  359. /* Handle a single stabs symbol. */
  360. boolean
  361. parse_stab (dhandle, handle, type, desc, value, string)
  362. PTR dhandle;
  363. PTR handle;
  364. int type;
  365. int desc;
  366. bfd_vma value;
  367. const char *string;
  368. {
  369. struct stab_handle *info = (struct stab_handle *) handle;
  370. /* gcc will emit two N_SO strings per compilation unit, one for the
  371. directory name and one for the file name. We just collect N_SO
  372. strings as we see them, and start the new compilation unit when
  373. we see a non N_SO symbol. */
  374. if (info->so_string != NULL
  375. && (type != N_SO || *string == '\0' || value != info->so_value))
  376. {
  377. if (! debug_set_filename (dhandle, info->so_string))
  378. return false;
  379. info->main_filename = info->so_string;
  380. info->gcc_compiled = 0;
  381. info->n_opt_found = false;
  382. /* Generally, for stabs in the symbol table, the N_LBRAC and
  383. N_RBRAC symbols are relative to the N_SO symbol value. */
  384. if (! info->sections)
  385. info->file_start_offset = info->so_value;
  386. /* We need to reset the mapping from type numbers to types. We
  387. can't free the old mapping, because of the use of
  388. debug_make_indirect_type. */
  389. info->files = 1;
  390. info->file_types = ((struct stab_types **)
  391. xmalloc (sizeof *info->file_types));
  392. info->file_types[0] = NULL;
  393. info->so_string = NULL;
  394. /* Now process whatever type we just got. */
  395. }
  396. switch (type)
  397. {
  398. case N_FN:
  399. case N_FN_SEQ:
  400. break;
  401. case N_LBRAC:
  402. /* Ignore extra outermost context from SunPRO cc and acc. */
  403. if (info->n_opt_found && desc == 1)
  404. break;
  405. if (! info->within_function)
  406. {
  407. fprintf (stderr, "N_LBRAC not within function\n");
  408. return false;
  409. }
  410. /* Start an inner lexical block. */
  411. if (! debug_start_block (dhandle,
  412. (value
  413. + info->file_start_offset
  414. + info->function_start_offset)))
  415. return false;
  416. /* Emit any pending variable definitions. */
  417. if (! stab_emit_pending_vars (dhandle, info))
  418. return false;
  419. ++info->block_depth;
  420. break;
  421. case N_RBRAC:
  422. /* Ignore extra outermost context from SunPRO cc and acc. */
  423. if (info->n_opt_found && desc == 1)
  424. break;
  425. /* We shouldn't have any pending variable definitions here, but,
  426. if we do, we probably need to emit them before closing the
  427. block. */
  428. if (! stab_emit_pending_vars (dhandle, info))
  429. return false;
  430. /* End an inner lexical block. */
  431. if (! debug_end_block (dhandle,
  432. (value
  433. + info->file_start_offset
  434. + info->function_start_offset)))
  435. return false;
  436. --info->block_depth;
  437. if (info->block_depth < 0)
  438. {
  439. fprintf (stderr, "Too many N_RBRACs\n");
  440. return false;
  441. }
  442. break;
  443. case N_SO:
  444. /* This always ends a function. */
  445. if (info->within_function)
  446. {
  447. bfd_vma endval;
  448. endval = value;
  449. if (*string != '\0'
  450. && info->function_end != (bfd_vma) -1
  451. && info->function_end < endval)
  452. endval = info->function_end;
  453. if (! stab_emit_pending_vars (dhandle, info)
  454. || ! debug_end_function (dhandle, endval))
  455. return false;
  456. info->within_function = false;
  457. info->function_end = (bfd_vma) -1;
  458. }
  459. /* An empty string is emitted by gcc at the end of a compilation
  460. unit. */
  461. if (*string == '\0')
  462. return true;
  463. /* Just accumulate strings until we see a non N_SO symbol. If
  464. the string starts with '/', we discard the previously
  465. accumulated strings. */
  466. if (info->so_string == NULL)
  467. info->so_string = xstrdup (string);
  468. else
  469. {
  470. char *f;
  471. f = info->so_string;
  472. if (*string == '/')
  473. info->so_string = xstrdup (string);
  474. else
  475. info->so_string = concat (info->so_string, string,
  476. (const char *) NULL);
  477. free (f);
  478. }
  479. info->so_value = value;
  480. break;
  481. case N_SOL:
  482. /* Start an include file. */
  483. if (! debug_start_source (dhandle, string))
  484. return false;
  485. break;
  486. case N_BINCL:
  487. /* Start an include file which may be replaced. */
  488. push_bincl (info, string, value);
  489. if (! debug_start_source (dhandle, string))
  490. return false;
  491. break;
  492. case N_EINCL:
  493. /* End an N_BINCL include. */
  494. if (! debug_start_source (dhandle, pop_bincl (info)))
  495. return false;
  496. break;
  497. case N_EXCL:
  498. /* This is a duplicate of a header file named by N_BINCL which
  499. was eliminated by the linker. */
  500. if (! find_excl (info, string, value))
  501. return false;
  502. break;
  503. case N_SLINE:
  504. if (! debug_record_line (dhandle, desc,
  505. value + info->function_start_offset))
  506. return false;
  507. break;
  508. case N_BCOMM:
  509. if (! debug_start_common_block (dhandle, string))
  510. return false;
  511. break;
  512. case N_ECOMM:
  513. if (! debug_end_common_block (dhandle, string))
  514. return false;
  515. break;
  516. case N_FUN:
  517. if (*string == '\0')
  518. {
  519. if (info->within_function)
  520. {
  521. /* This always marks the end of a function; we don't
  522. need to worry about info->function_end. */
  523. if (info->sections)
  524. value += info->function_start_offset;
  525. if (! stab_emit_pending_vars (dhandle, info)
  526. || ! debug_end_function (dhandle, value))
  527. return false;
  528. info->within_function = false;
  529. info->function_end = (bfd_vma) -1;
  530. }
  531. break;
  532. }
  533. /* A const static symbol in the .text section will have an N_FUN
  534. entry. We need to use these to mark the end of the function,
  535. in case we are looking at gcc output before it was changed to
  536. always emit an empty N_FUN. We can't call debug_end_function
  537. here, because it might be a local static symbol. */
  538. if (info->within_function
  539. && (info->function_end == (bfd_vma) -1
  540. || value < info->function_end))
  541. info->function_end = value;
  542. /* Fall through. */
  543. /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
  544. symbols, and if it does not start with :S, gdb relocates the
  545. value to the start of the section. gcc always seems to use
  546. :S, so we don't worry about this. */
  547. /* Fall through. */
  548. default:
  549. {
  550. const char *colon;
  551. colon = strchr (string, ':');
  552. if (colon != NULL
  553. && (colon[1] == 'f' || colon[1] == 'F'))
  554. {
  555. if (info->within_function)
  556. {
  557. bfd_vma endval;
  558. endval = value;
  559. if (info->function_end != (bfd_vma) -1
  560. && info->function_end < endval)
  561. endval = info->function_end;
  562. if (! stab_emit_pending_vars (dhandle, info)
  563. || ! debug_end_function (dhandle, endval))
  564. return false;
  565. info->function_end = (bfd_vma) -1;
  566. }
  567. /* For stabs in sections, line numbers and block addresses
  568. are offsets from the start of the function. */
  569. if (info->sections)
  570. info->function_start_offset = value;
  571. info->within_function = true;
  572. }
  573. if (! parse_stab_string (dhandle, info, type, desc, value, string))
  574. return false;
  575. }
  576. break;
  577. case N_OPT:
  578. if (string != NULL && strcmp (string, "gcc2_compiled.") == 0)
  579. info->gcc_compiled = 2;
  580. else if (string != NULL && strcmp (string, "gcc_compiled.") == 0)
  581. info->gcc_compiled = 1;
  582. else
  583. info->n_opt_found = true;
  584. break;
  585. case N_OBJ:
  586. case N_ENDM:
  587. case N_MAIN:
  588. break;
  589. }
  590. return true;
  591. }
  592. /* Parse the stabs string. */
  593. static boolean
  594. parse_stab_string (dhandle, info, stabtype, desc, value, string)
  595. PTR dhandle;
  596. struct stab_handle *info;
  597. int stabtype;
  598. int desc;
  599. bfd_vma value;
  600. const char *string;
  601. {
  602. const char *p;
  603. char *name;
  604. int type;
  605. debug_type dtype;
  606. boolean synonym;
  607. unsigned int lineno;
  608. debug_type *slot;
  609. p = strchr (string, ':');
  610. if (p == NULL)
  611. return true;
  612. while (p[1] == ':')
  613. {
  614. p += 2;
  615. p = strchr (p, ':');
  616. if (p == NULL)
  617. {
  618. bad_stab (string);
  619. return false;
  620. }
  621. }
  622. /* GCC 2.x puts the line number in desc. SunOS apparently puts in
  623. the number of bytes occupied by a type or object, which we
  624. ignore. */
  625. if (info->gcc_compiled >= 2)
  626. lineno = desc;
  627. else
  628. lineno = 0;
  629. /* FIXME: Sometimes the special C++ names start with '.'. */
  630. name = NULL;
  631. if (string[0] == '$')
  632. {
  633. switch (string[1])
  634. {
  635. case 't':
  636. name = "this";
  637. break;
  638. case 'v':
  639. /* Was: name = "vptr"; */
  640. break;
  641. case 'e':
  642. name = "eh_throw";
  643. break;
  644. case '_':
  645. /* This was an anonymous type that was never fixed up. */
  646. break;
  647. case 'X':
  648. /* SunPRO (3.0 at least) static variable encoding. */
  649. break;
  650. default:
  651. warn_stab (string, "unknown C++ encoded name");
  652. break;
  653. }
  654. }
  655. if (name == NULL)
  656. {
  657. if (p == string || (string[0] == ' ' && p == string + 1))
  658. name = NULL;
  659. else
  660. name = savestring (string, p - string);
  661. }
  662. ++p;
  663. if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-')
  664. type = 'l';
  665. else
  666. type = *p++;
  667. switch (type)
  668. {
  669. case 'c':
  670. /* c is a special case, not followed by a type-number.
  671. SYMBOL:c=iVALUE for an integer constant symbol.
  672. SYMBOL:c=rVALUE for a floating constant symbol.
  673. SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
  674. e.g. "b:c=e6,0" for "const b = blob1"
  675. (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
  676. if (*p != '=')
  677. {
  678. bad_stab (string);
  679. return false;
  680. }
  681. ++p;
  682. switch (*p++)
  683. {
  684. case 'r':
  685. /* Floating point constant. */
  686. if (! debug_record_float_const (dhandle, name, atof (p)))
  687. return false;
  688. break;
  689. case 'i':
  690. /* Integer constant. */
  691. /* Defining integer constants this way is kind of silly,
  692. since 'e' constants allows the compiler to give not only
  693. the value, but the type as well. C has at least int,
  694. long, unsigned int, and long long as constant types;
  695. other languages probably should have at least unsigned as
  696. well as signed constants. */
  697. if (! debug_record_int_const (dhandle, name, atoi (p)))
  698. return false;
  699. break;
  700. case 'e':
  701. /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
  702. can be represented as integral.
  703. e.g. "b:c=e6,0" for "const b = blob1"
  704. (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
  705. dtype = parse_stab_type (dhandle, info, (const char *) NULL,
  706. &p, (debug_type **) NULL);
  707. if (dtype == DEBUG_TYPE_NULL)
  708. return false;
  709. if (*p != ',')
  710. {
  711. bad_stab (string);
  712. return false;
  713. }
  714. if (! debug_record_typed_const (dhandle, name, dtype, atoi (p)))
  715. return false;
  716. break;
  717. default:
  718. bad_stab (string);
  719. return false;
  720. }
  721. break;
  722. case 'C':
  723. /* The name of a caught exception. */
  724. dtype = parse_stab_type (dhandle, info, (const char *) NULL,
  725. &p, (debug_type **) NULL);
  726. if (dtype == DEBUG_TYPE_NULL)
  727. return false;
  728. if (! debug_record_label (dhandle, name, dtype, value))
  729. return false;
  730. break;
  731. case 'f':
  732. case 'F':
  733. /* A function definition. */
  734. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  735. (debug_type **) NULL);
  736. if (dtype == DEBUG_TYPE_NULL)
  737. return false;
  738. if (! debug_record_function (dhandle, name, dtype, type == 'F', value))
  739. return false;
  740. /* Sun acc puts declared types of arguments here. We don't care
  741. about their actual types (FIXME -- we should remember the whole
  742. function prototype), but the list may define some new types
  743. that we have to remember, so we must scan it now. */
  744. while (*p == ';')
  745. {
  746. ++p;
  747. if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
  748. (debug_type **) NULL)
  749. == DEBUG_TYPE_NULL)
  750. return false;
  751. }
  752. break;
  753. case 'G':
  754. {
  755. char leading;
  756. long c;
  757. asymbol **ps;
  758. /* A global symbol. The value must be extracted from the
  759. symbol table. */
  760. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  761. (debug_type **) NULL);
  762. if (dtype == DEBUG_TYPE_NULL)
  763. return false;
  764. leading = bfd_get_symbol_leading_char (info->abfd);
  765. for (c = info->symcount, ps = info->syms; c > 0; --c, ++ps)
  766. {
  767. const char *n;
  768. n = bfd_asymbol_name (*ps);
  769. if (leading != '\0' && *n == leading)
  770. ++n;
  771. if (*n == *name && strcmp (n, name) == 0)
  772. break;
  773. }
  774. if (c > 0)
  775. value = bfd_asymbol_value (*ps);
  776. if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_GLOBAL,
  777. value))
  778. return false;
  779. }
  780. break;
  781. /* This case is faked by a conditional above, when there is no
  782. code letter in the dbx data. Dbx data never actually
  783. contains 'l'. */
  784. case 'l':
  785. case 's':
  786. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  787. (debug_type **) NULL);
  788. if (dtype == DEBUG_TYPE_NULL)
  789. return false;
  790. if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
  791. value))
  792. return false;
  793. break;
  794. case 'p':
  795. /* A function parameter. */
  796. if (*p != 'F')
  797. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  798. (debug_type **) NULL);
  799. else
  800. {
  801. /* pF is a two-letter code that means a function parameter in
  802. Fortran. The type-number specifies the type of the return
  803. value. Translate it into a pointer-to-function type. */
  804. ++p;
  805. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  806. (debug_type **) NULL);
  807. if (dtype != DEBUG_TYPE_NULL)
  808. {
  809. debug_type ftype;
  810. ftype = debug_make_function_type (dhandle, dtype,
  811. (debug_type *) NULL, false);
  812. dtype = debug_make_pointer_type (dhandle, ftype);
  813. }
  814. }
  815. if (dtype == DEBUG_TYPE_NULL)
  816. return false;
  817. if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_STACK,
  818. value))
  819. return false;
  820. /* FIXME: At this point gdb considers rearranging the parameter
  821. address on a big endian machine if it is smaller than an int.
  822. We have no way to do that, since we don't really know much
  823. about the target. */
  824. break;
  825. case 'P':
  826. if (stabtype == N_FUN)
  827. {
  828. /* Prototype of a function referenced by this file. */
  829. while (*p == ';')
  830. {
  831. ++p;
  832. if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
  833. (debug_type **) NULL)
  834. == DEBUG_TYPE_NULL)
  835. return false;
  836. }
  837. break;
  838. }
  839. /* Fall through. */
  840. case 'R':
  841. /* Parameter which is in a register. */
  842. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  843. (debug_type **) NULL);
  844. if (dtype == DEBUG_TYPE_NULL)
  845. return false;
  846. if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REG,
  847. value))
  848. return false;
  849. break;
  850. case 'r':
  851. /* Register variable (either global or local). */
  852. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  853. (debug_type **) NULL);
  854. if (dtype == DEBUG_TYPE_NULL)
  855. return false;
  856. if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_REGISTER,
  857. value))
  858. return false;
  859. /* FIXME: At this point gdb checks to combine pairs of 'p' and
  860. 'r' stabs into a single 'P' stab. */
  861. break;
  862. case 'S':
  863. /* Static symbol at top level of file */
  864. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  865. (debug_type **) NULL);
  866. if (dtype == DEBUG_TYPE_NULL)
  867. return false;
  868. if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_STATIC,
  869. value))
  870. return false;
  871. break;
  872. case 't':
  873. /* A typedef. */
  874. dtype = parse_stab_type (dhandle, info, name, &p, &slot);
  875. if (dtype == DEBUG_TYPE_NULL)
  876. return false;
  877. if (name == NULL)
  878. {
  879. /* A nameless type. Nothing to do. */
  880. return true;
  881. }
  882. dtype = debug_name_type (dhandle, name, dtype);
  883. if (dtype == DEBUG_TYPE_NULL)
  884. return false;
  885. if (slot != NULL)
  886. *slot = dtype;
  887. break;
  888. case 'T':
  889. /* Struct, union, or enum tag. For GNU C++, this can be be followed
  890. by 't' which means we are typedef'ing it as well. */
  891. if (*p != 't')
  892. {
  893. synonym = false;
  894. /* FIXME: gdb sets synonym to true if the current language
  895. is C++. */
  896. }
  897. else
  898. {
  899. synonym = true;
  900. ++p;
  901. }
  902. dtype = parse_stab_type (dhandle, info, name, &p, &slot);
  903. if (dtype == DEBUG_TYPE_NULL)
  904. return false;
  905. if (name == NULL)
  906. return true;
  907. dtype = debug_tag_type (dhandle, name, dtype);
  908. if (dtype == DEBUG_TYPE_NULL)
  909. return false;
  910. if (slot != NULL)
  911. *slot = dtype;
  912. /* See if we have a cross reference to this tag which we can now
  913. fill in. */
  914. {
  915. register struct stab_tag **pst;
  916. for (pst = &info->tags; *pst != NULL; pst = &(*pst)->next)
  917. {
  918. if ((*pst)->name[0] == name[0]
  919. && strcmp ((*pst)->name, name) == 0)
  920. {
  921. (*pst)->slot = dtype;
  922. *pst = (*pst)->next;
  923. break;
  924. }
  925. }
  926. }
  927. if (synonym)
  928. {
  929. dtype = debug_name_type (dhandle, name, dtype);
  930. if (dtype == DEBUG_TYPE_NULL)
  931. return false;
  932. if (slot != NULL)
  933. *slot = dtype;
  934. }
  935. break;
  936. case 'V':
  937. /* Static symbol of local scope */
  938. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  939. (debug_type **) NULL);
  940. if (dtype == DEBUG_TYPE_NULL)
  941. return false;
  942. /* FIXME: gdb checks os9k_stabs here. */
  943. if (! stab_record_variable (dhandle, info, name, dtype,
  944. DEBUG_LOCAL_STATIC, value))
  945. return false;
  946. break;
  947. case 'v':
  948. /* Reference parameter. */
  949. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  950. (debug_type **) NULL);
  951. if (dtype == DEBUG_TYPE_NULL)
  952. return false;
  953. if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REFERENCE,
  954. value))
  955. return false;
  956. break;
  957. case 'a':
  958. /* Reference parameter which is in a register. */
  959. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  960. (debug_type **) NULL);
  961. if (dtype == DEBUG_TYPE_NULL)
  962. return false;
  963. if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REF_REG,
  964. value))
  965. return false;
  966. break;
  967. case 'X':
  968. /* This is used by Sun FORTRAN for "function result value".
  969. Sun claims ("dbx and dbxtool interfaces", 2nd ed)
  970. that Pascal uses it too, but when I tried it Pascal used
  971. "x:3" (local symbol) instead. */
  972. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  973. (debug_type **) NULL);
  974. if (dtype == DEBUG_TYPE_NULL)
  975. return false;
  976. if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
  977. value))
  978. return false;
  979. break;
  980. default:
  981. bad_stab (string);
  982. return false;
  983. }
  984. /* FIXME: gdb converts structure values to structure pointers in a
  985. couple of cases, depending upon the target. */
  986. return true;
  987. }
  988. /* Parse a stabs type. The typename argument is non-NULL if this is a
  989. typedef or a tag definition. The pp argument points to the stab
  990. string, and is updated. The slotp argument points to a place to
  991. store the slot used if the type is being defined. */
  992. static debug_type
  993. parse_stab_type (dhandle, info, typename, pp, slotp)
  994. PTR dhandle;
  995. struct stab_handle *info;
  996. const char *typename;
  997. const char **pp;
  998. debug_type **slotp;
  999. {
  1000. const char *orig;
  1001. int typenums[2];
  1002. int size;
  1003. boolean stringp;
  1004. int descriptor;
  1005. debug_type dtype;
  1006. if (slotp != NULL)
  1007. *slotp = NULL;
  1008. orig = *pp;
  1009. size = -1;
  1010. stringp = false;
  1011. /* Read type number if present. The type number may be omitted.
  1012. for instance in a two-dimensional array declared with type
  1013. "ar1;1;10;ar1;1;10;4". */
  1014. if (! isdigit ((unsigned char) **pp) && **pp != '(' && **pp != '-')
  1015. {
  1016. /* 'typenums=' not present, type is anonymous. Read and return
  1017. the definition, but don't put it in the type vector. */
  1018. typenums[0] = typenums[1] = -1;
  1019. }
  1020. else
  1021. {
  1022. if (! parse_stab_type_number (pp, typenums))
  1023. return DEBUG_TYPE_NULL;
  1024. if (**pp != '=')
  1025. {
  1026. /* Type is not being defined here. Either it already
  1027. exists, or this is a forward reference to it. */
  1028. return stab_find_type (dhandle, info, typenums);
  1029. }
  1030. /* Only set the slot if the type is being defined. This means
  1031. that the mapping from type numbers to types will only record
  1032. the name of the typedef which defines a type. If we don't do
  1033. this, then something like
  1034. typedef int foo;
  1035. int i;
  1036. will record that i is of type foo. Unfortunately, stabs
  1037. information is ambiguous about variable types. For this code,
  1038. typedef int foo;
  1039. int i;
  1040. foo j;
  1041. the stabs information records both i and j as having the same
  1042. type. This could be fixed by patching the compiler. */
  1043. if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0)
  1044. *slotp = stab_find_slot (info, typenums);
  1045. /* Type is being defined here. */
  1046. /* Skip the '='. */
  1047. ++*pp;
  1048. while (**pp == '@')
  1049. {
  1050. const char *p = *pp + 1;
  1051. const char *attr;
  1052. if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-')
  1053. {
  1054. /* Member type. */
  1055. break;
  1056. }
  1057. /* Type attributes. */
  1058. attr = p;
  1059. for (; *p != ';'; ++p)
  1060. {
  1061. if (*p == '\0')
  1062. {
  1063. bad_stab (orig);
  1064. return DEBUG_TYPE_NULL;
  1065. }
  1066. }
  1067. *pp = p + 1;
  1068. switch (*attr)
  1069. {
  1070. case 's':
  1071. size = atoi (attr + 1);
  1072. if (size <= 0)
  1073. size = -1;
  1074. break;
  1075. case 'S':
  1076. stringp = true;
  1077. break;
  1078. default:
  1079. /* Ignore unrecognized type attributes, so future
  1080. compilers can invent new ones. */
  1081. break;
  1082. }
  1083. }
  1084. }
  1085. descriptor = **pp;
  1086. ++*pp;
  1087. switch (descriptor)
  1088. {
  1089. case 'x':
  1090. {
  1091. enum debug_type_kind code;
  1092. const char *q1, *q2, *p;
  1093. /* A cross reference to another type. */
  1094. switch (**pp)
  1095. {
  1096. case 's':
  1097. code = DEBUG_KIND_STRUCT;
  1098. break;
  1099. case 'u':
  1100. code = DEBUG_KIND_UNION;
  1101. break;
  1102. case 'e':
  1103. code = DEBUG_KIND_ENUM;
  1104. break;
  1105. default:
  1106. /* Complain and keep going, so compilers can invent new
  1107. cross-reference types. */
  1108. warn_stab (orig, "unrecognized cross reference type");
  1109. code = DEBUG_KIND_STRUCT;
  1110. break;
  1111. }
  1112. ++*pp;
  1113. q1 = strchr (*pp, '<');
  1114. p = strchr (*pp, ':');
  1115. if (p == NULL)
  1116. {
  1117. bad_stab (orig);
  1118. return DEBUG_TYPE_NULL;
  1119. }
  1120. while (q1 != NULL && p > q1 && p[1] == ':')
  1121. {
  1122. q2 = strchr (q1, '>');
  1123. if (q2 == NULL || q2 < p)
  1124. break;
  1125. p += 2;
  1126. p = strchr (p, ':');
  1127. if (p == NULL)
  1128. {
  1129. bad_stab (orig);
  1130. return DEBUG_TYPE_NULL;
  1131. }
  1132. }
  1133. dtype = stab_find_tagged_type (dhandle, info, *pp, p - *pp, code);
  1134. *pp = p + 1;
  1135. }
  1136. break;
  1137. case '-':
  1138. case '0':
  1139. case '1':
  1140. case '2':
  1141. case '3':
  1142. case '4':
  1143. case '5':
  1144. case '6':
  1145. case '7':
  1146. case '8':
  1147. case '9':
  1148. case '(':
  1149. {
  1150. const char *hold;
  1151. int xtypenums[2];
  1152. /* This type is defined as another type. */
  1153. (*pp)--;
  1154. hold = *pp;
  1155. /* Peek ahead at the number to detect void. */
  1156. if (! parse_stab_type_number (pp, xtypenums))
  1157. return DEBUG_TYPE_NULL;
  1158. if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
  1159. {
  1160. /* This type is being defined as itself, which means that
  1161. it is void. */
  1162. dtype = debug_make_void_type (dhandle);
  1163. }
  1164. else
  1165. {
  1166. *pp = hold;
  1167. /* Go back to the number and have parse_stab_type get it.
  1168. This means that we can deal with something like
  1169. t(1,2)=(3,4)=... which the Lucid compiler uses. */
  1170. dtype = parse_stab_type (dhandle, info, (const char *) NULL,
  1171. pp, (debug_type **) NULL);
  1172. if (dtype == DEBUG_TYPE_NULL)
  1173. return DEBUG_TYPE_NULL;
  1174. }
  1175. if (typenums[0] != -1)
  1176. {
  1177. if (! stab_record_type (dhandle, info, typenums, dtype))
  1178. return DEBUG_TYPE_NULL;
  1179. }
  1180. break;
  1181. }
  1182. case '*':
  1183. dtype = debug_make_pointer_type (dhandle,
  1184. parse_stab_type (dhandle, info,
  1185. (const char *) NULL,
  1186. pp,
  1187. (debug_type **) NULL));
  1188. break;
  1189. case '&':
  1190. /* Reference to another type. */
  1191. dtype = (debug_make_reference_type
  1192. (dhandle,
  1193. parse_stab_type (dhandle, info, (const char *) NULL, pp,
  1194. (debug_type **) NULL)));
  1195. break;
  1196. case 'f':
  1197. /* Function returning another type. */
  1198. /* FIXME: gdb checks os9k_stabs here. */
  1199. dtype = (debug_make_function_type
  1200. (dhandle,
  1201. parse_stab_type (dhandle, info, (const char *) NULL, pp,
  1202. (debug_type **) NULL),
  1203. (debug_type *) NULL, false));
  1204. break;
  1205. case 'k':
  1206. /* Const qualifier on some type (Sun). */
  1207. /* FIXME: gdb accepts 'c' here if os9k_stabs. */
  1208. dtype = debug_make_const_type (dhandle,
  1209. parse_stab_type (dhandle, info,
  1210. (const char *) NULL,
  1211. pp,
  1212. (debug_type **) NULL));
  1213. break;
  1214. case 'B':
  1215. /* Volatile qual on some type (Sun). */
  1216. /* FIXME: gdb accepts 'i' here if os9k_stabs. */
  1217. dtype = (debug_make_volatile_type
  1218. (dhandle,
  1219. parse_stab_type (dhandle, info, (const char *) NULL, pp,
  1220. (debug_type **) NULL)));
  1221. break;
  1222. case '@':
  1223. /* Offset (class & variable) type. This is used for a pointer
  1224. relative to an object. */
  1225. {
  1226. debug_type domain;
  1227. debug_type memtype;
  1228. /* Member type. */
  1229. domain = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  1230. (debug_type **) NULL);
  1231. if (domain == DEBUG_TYPE_NULL)
  1232. return DEBUG_TYPE_NULL;
  1233. if (**pp != ',')
  1234. {
  1235. bad_stab (orig);
  1236. return DEBUG_TYPE_NULL;
  1237. }
  1238. ++*pp;
  1239. memtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  1240. (debug_type **) NULL);
  1241. if (memtype == DEBUG_TYPE_NULL)
  1242. return DEBUG_TYPE_NULL;
  1243. dtype = debug_make_offset_type (dhandle, domain, memtype);
  1244. }
  1245. break;
  1246. case '#':
  1247. /* Method (class & fn) type. */
  1248. if (**pp == '#')
  1249. {
  1250. debug_type return_type;
  1251. ++*pp;
  1252. return_type = parse_stab_type (dhandle, info, (const char *) NULL,
  1253. pp, (debug_type **) NULL);
  1254. if (return_type == DEBUG_TYPE_NULL)
  1255. return DEBUG_TYPE_NULL;
  1256. if (**pp != ';')
  1257. {
  1258. bad_stab (orig);
  1259. return DEBUG_TYPE_NULL;
  1260. }
  1261. ++*pp;
  1262. dtype = debug_make_method_type (dhandle, return_type,
  1263. DEBUG_TYPE_NULL,
  1264. (debug_type *) NULL, false);
  1265. }
  1266. else
  1267. {
  1268. debug_type domain;
  1269. debug_type return_type;
  1270. debug_type *args;
  1271. unsigned int n;
  1272. unsigned int alloc;
  1273. boolean varargs;
  1274. domain = parse_stab_type (dhandle, info, (const char *) NULL,
  1275. pp, (debug_type **) NULL);
  1276. if (domain == DEBUG_TYPE_NULL)
  1277. return DEBUG_TYPE_NULL;
  1278. if (**pp != ',')
  1279. {
  1280. bad_stab (orig);
  1281. return DEBUG_TYPE_NULL;
  1282. }
  1283. ++*pp;
  1284. return_type = parse_stab_type (dhandle, info, (const char *) NULL,
  1285. pp, (debug_type **) NULL);
  1286. if (return_type == DEBUG_TYPE_NULL)
  1287. return DEBUG_TYPE_NULL;
  1288. alloc = 10;
  1289. args = (debug_type *) xmalloc (alloc * sizeof *args);
  1290. n = 0;
  1291. while (**pp != ';')
  1292. {
  1293. if (**pp != ',')
  1294. {
  1295. bad_stab (orig);
  1296. return DEBUG_TYPE_NULL;
  1297. }
  1298. ++*pp;
  1299. if (n + 1 >= alloc)
  1300. {
  1301. alloc += 10;
  1302. args = ((debug_type *)
  1303. xrealloc ((PTR) args, alloc * sizeof *args));
  1304. }
  1305. args[n] = parse_stab_type (dhandle, info, (const char *) NULL,
  1306. pp, (debug_type **) NULL);
  1307. if (args[n] == DEBUG_TYPE_NULL)
  1308. return DEBUG_TYPE_NULL;
  1309. ++n;
  1310. }
  1311. ++*pp;
  1312. /* If the last type is not void, then this function takes a
  1313. variable number of arguments. Otherwise, we must strip
  1314. the void type. */
  1315. if (n == 0
  1316. || debug_get_type_kind (dhandle, args[n - 1]) != DEBUG_KIND_VOID)
  1317. varargs = true;
  1318. else
  1319. {
  1320. --n;
  1321. varargs = false;
  1322. }
  1323. args[n] = DEBUG_TYPE_NULL;
  1324. dtype = debug_make_method_type (dhandle, return_type, domain, args,
  1325. varargs);
  1326. }
  1327. break;
  1328. case 'r':
  1329. /* Range type. */
  1330. dtype = parse_stab_range_type (dhandle, info, typename, pp, typenums);
  1331. break;
  1332. case 'b':
  1333. /* FIXME: gdb checks os9k_stabs here. */
  1334. /* Sun ACC builtin int type. */
  1335. dtype = parse_stab_sun_builtin_type (dhandle, pp);
  1336. break;
  1337. case 'R':
  1338. /* Sun ACC builtin float type. */
  1339. dtype = parse_stab_sun_floating_type (dhandle, pp);
  1340. break;
  1341. case 'e':
  1342. /* Enumeration type. */
  1343. dtype = parse_stab_enum_type (dhandle, pp);
  1344. break;
  1345. case 's':
  1346. case 'u':
  1347. /* Struct or union type. */
  1348. dtype = parse_stab_struct_type (dhandle, info, typename, pp,
  1349. descriptor == 's', typenums);
  1350. break;
  1351. case 'a':
  1352. /* Array type. */
  1353. if (**pp != 'r')
  1354. {
  1355. bad_stab (orig);
  1356. return DEBUG_TYPE_NULL;
  1357. }
  1358. ++*pp;
  1359. dtype = parse_stab_array_type (dhandle, info, pp, stringp);
  1360. break;
  1361. case 'S':
  1362. dtype = debug_make_set_type (dhandle,
  1363. parse_stab_type (dhandle, info,
  1364. (const char *) NULL,
  1365. pp,
  1366. (debug_type **) NULL),
  1367. stringp);
  1368. break;
  1369. default:
  1370. bad_stab (orig);
  1371. return DEBUG_TYPE_NULL;
  1372. }
  1373. if (dtype == DEBUG_TYPE_NULL)
  1374. return DEBUG_TYPE_NULL;
  1375. if (typenums[0] != -1)
  1376. {
  1377. if (! stab_record_type (dhandle, info, typenums, dtype))
  1378. return DEBUG_TYPE_NULL;
  1379. }
  1380. if (size != -1)
  1381. {
  1382. if (! debug_record_type_size (dhandle, dtype, (unsigned int) size))
  1383. return DEBUG_TYPE_NULL;
  1384. }
  1385. return dtype;
  1386. }
  1387. /* Read a number by which a type is referred to in dbx data, or
  1388. perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
  1389. single number N is equivalent to (0,N). Return the two numbers by
  1390. storing them in the vector TYPENUMS. */
  1391. static boolean
  1392. parse_stab_type_number (pp, typenums)
  1393. const char **pp;
  1394. int *typenums;
  1395. {
  1396. const char *orig;
  1397. orig = *pp;
  1398. if (**pp != '(')
  1399. {
  1400. typenums[0] = 0;
  1401. typenums[1] = (int) parse_number (pp, (boolean *) NULL);
  1402. }
  1403. else
  1404. {
  1405. ++*pp;
  1406. typenums[0] = (int) parse_number (pp, (boolean *) NULL);
  1407. if (**pp != ',')
  1408. {
  1409. bad_stab (orig);
  1410. return false;
  1411. }
  1412. ++*pp;
  1413. typenums[1] = (int) parse_number (pp, (boolean *) NULL);
  1414. if (**pp != ')')
  1415. {
  1416. bad_stab (orig);
  1417. return false;
  1418. }
  1419. ++*pp;
  1420. }
  1421. return true;
  1422. }
  1423. /* Parse a range type. */
  1424. static debug_type
  1425. parse_stab_range_type (dhandle, info, typename, pp, typenums)
  1426. PTR dhandle;
  1427. struct stab_handle *info;
  1428. const char *typename;
  1429. const char **pp;
  1430. const int *typenums;
  1431. {
  1432. const char *orig;
  1433. int rangenums[2];
  1434. boolean self_subrange;
  1435. debug_type index_type;
  1436. const char *s2, *s3;
  1437. bfd_signed_vma n2, n3;
  1438. boolean ov2, ov3;
  1439. orig = *pp;
  1440. index_type = DEBUG_TYPE_NULL;
  1441. /* First comes a type we are a subrange of.
  1442. In C it is usually 0, 1 or the type being defined. */
  1443. if (! parse_stab_type_number (pp, rangenums))
  1444. return DEBUG_TYPE_NULL;
  1445. self_subrange = (rangenums[0] == typenums[0]
  1446. && rangenums[1] == typenums[1]);
  1447. if (**pp == '=')
  1448. {
  1449. *pp = orig;
  1450. index_type = parse_stab_type (dhandle, info, (const char *) NULL,
  1451. pp, (debug_type **) NULL);
  1452. if (index_type == DEBUG_TYPE_NULL)
  1453. return DEBUG_TYPE_NULL;
  1454. }
  1455. if (**pp == ';')
  1456. ++*pp;
  1457. /* The remaining two operands are usually lower and upper bounds of
  1458. the range. But in some special cases they mean something else. */
  1459. s2 = *pp;
  1460. n2 = parse_number (pp, &ov2);
  1461. if (**pp != ';')
  1462. {
  1463. bad_stab (orig);
  1464. return DEBUG_TYPE_NULL;
  1465. }
  1466. ++*pp;
  1467. s3 = *pp;
  1468. n3 = parse_number (pp, &ov3);
  1469. if (**pp != ';')
  1470. {
  1471. bad_stab (orig);
  1472. return DEBUG_TYPE_NULL;
  1473. }
  1474. ++*pp;
  1475. if (ov2 || ov3)
  1476. {
  1477. /* gcc will emit range stabs for long long types. Handle this
  1478. as a special case. FIXME: This needs to be more general. */
  1479. #define LLLOW "01000000000000000000000;"
  1480. #define LLHIGH "0777777777777777777777;"
  1481. #define ULLHIGH "01777777777777777777777;"
  1482. if (index_type == DEBUG_TYPE_NULL)
  1483. {
  1484. if (strncmp (s2, LLLOW, sizeof LLLOW - 1) == 0
  1485. && strncmp (s3, LLHIGH, sizeof LLHIGH - 1) == 0)
  1486. return debug_make_int_type (dhandle, 8, false);
  1487. if (! ov2
  1488. && n2 == 0
  1489. && strncmp (s3, ULLHIGH, sizeof ULLHIGH - 1) == 0)
  1490. return debug_make_int_type (dhandle, 8, true);
  1491. }
  1492. warn_stab (orig, "numeric overflow");
  1493. }
  1494. if (index_type == DEBUG_TYPE_NULL)
  1495. {
  1496. /* A type defined as a subrange of itself, with both bounds 0,
  1497. is void. */
  1498. if (self_subrange && n2 == 0 && n3 == 0)
  1499. return debug_make_void_type (dhandle);
  1500. /* A type defined as a subrange of itself, with n2 positive and
  1501. n3 zero, is a complex type, and n2 is the number of bytes. */
  1502. if (self_subrange && n3 == 0 && n2 > 0)
  1503. return debug_make_complex_type (dhandle, n2);
  1504. /* If n3 is zero and n2 is positive, this is a floating point
  1505. type, and n2 is the number of bytes. */
  1506. if (n3 == 0 && n2 > 0)
  1507. return debug_make_float_type (dhandle, n2);
  1508. /* If the upper bound is -1, this is an unsigned int. */
  1509. if (n2 == 0 && n3 == -1)
  1510. {
  1511. /* When gcc is used with -gstabs, but not -gstabs+, it will emit
  1512. long long int:t6=r1;0;-1;
  1513. long long unsigned int:t7=r1;0;-1;
  1514. We hack here to handle this reasonably. */
  1515. if (typename != NULL)
  1516. {
  1517. if (strcmp (typename, "long long int") == 0)
  1518. return debug_make_int_type (dhandle, 8, false);
  1519. else if (strcmp (typename, "long long unsigned int") == 0)
  1520. return debug_make_int_type (dhandle, 8, true);
  1521. }
  1522. /* FIXME: The size here really depends upon the target. */
  1523. return debug_make_int_type (dhandle, 4, true);
  1524. }
  1525. /* A range of 0 to 127 is char. */
  1526. if (self_subrange && n2 == 0 && n3 == 127)
  1527. return debug_make_int_type (dhandle, 1, false);
  1528. /* FIXME: gdb checks for the language CHILL here. */
  1529. if (n2 == 0)
  1530. {
  1531. if (n3 < 0)
  1532. return debug_make_int_type (dhandle, - n3, true);
  1533. else if (n3 == 0xff)
  1534. return debug_make_int_type (dhandle, 1, true);
  1535. else if (n3 == 0xffff)
  1536. return debug_make_int_type (dhandle, 2, true);
  1537. /* -1 is used for the upper bound of (4 byte) "unsigned int"
  1538. and "unsigned long", and we already checked for that, so
  1539. don't need to test for it here. */
  1540. }
  1541. else if (n3 == 0
  1542. && n2 < 0
  1543. && (self_subrange || n2 == -8))
  1544. return debug_make_int_type (dhandle, - n2, true);
  1545. else if (n2 == - n3 - 1)
  1546. {
  1547. if (n3 == 0x7f)
  1548. return debug_make_int_type (dhandle, 1, false);
  1549. else if (n3 == 0x7fff)
  1550. return debug_make_int_type (dhandle, 2, false);
  1551. else if (n3 == 0x7fffffff)
  1552. return debug_make_int_type (dhandle, 4, false);
  1553. }
  1554. }
  1555. /* At this point I don't have the faintest idea how to deal with a
  1556. self_subrange type; I'm going to assume that this is used as an
  1557. idiom, and that all of them are special cases. So . . . */
  1558. if (self_subrange)
  1559. {
  1560. bad_stab (orig);
  1561. return DEBUG_TYPE_NULL;
  1562. }
  1563. index_type = stab_find_type (dhandle, info, rangenums);
  1564. if (index_type == DEBUG_TYPE_NULL)
  1565. {
  1566. /* Does this actually ever happen? Is that why we are worrying
  1567. about dealing with it rather than just calling error_type? */
  1568. warn_stab (orig, "missing index type");
  1569. index_type = debug_make_int_type (dhandle, 4, false);
  1570. }
  1571. return debug_make_range_type (dhandle, index_type, n2, n3);
  1572. }
  1573. /* Sun's ACC uses a somewhat saner method for specifying the builtin
  1574. typedefs in every file (for int, long, etc):
  1575. type = b <signed> <width>; <offset>; <nbits>
  1576. signed = u or s. Possible c in addition to u or s (for char?).
  1577. offset = offset from high order bit to start bit of type.
  1578. width is # bytes in object of this type, nbits is # bits in type.
  1579. The width/offset stuff appears to be for small objects stored in
  1580. larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
  1581. FIXME. */
  1582. static debug_type
  1583. parse_stab_sun_builtin_type (dhandle, pp)
  1584. PTR dhandle;
  1585. const char **pp;
  1586. {
  1587. const char *orig;
  1588. boolean unsignedp;
  1589. bfd_vma bits;
  1590. orig = *pp;
  1591. switch (**pp)
  1592. {
  1593. case 's':
  1594. unsignedp = false;
  1595. break;
  1596. case 'u':
  1597. unsignedp = true;
  1598. break;
  1599. default:
  1600. bad_stab (orig);
  1601. return DEBUG_TYPE_NULL;
  1602. }
  1603. ++*pp;
  1604. /* For some odd reason, all forms of char put a c here. This is strange
  1605. because no other type has this honor. We can safely ignore this because
  1606. we actually determine 'char'acterness by the number of bits specified in
  1607. the descriptor. */
  1608. if (**pp == 'c')
  1609. ++*pp;
  1610. /* The first number appears to be the number of bytes occupied
  1611. by this type, except that unsigned short is 4 instead of 2.
  1612. Since this information is redundant with the third number,
  1613. we will ignore it. */
  1614. (void) parse_number (pp, (boolean *) NULL);
  1615. if (**pp != ';')
  1616. {
  1617. bad_stab (orig);
  1618. return DEBUG_TYPE_NULL;
  1619. }
  1620. ++*pp;
  1621. /* The second number is always 0, so ignore it too. */
  1622. (void) parse_number (pp, (boolean *) NULL);
  1623. if (**pp != ';')
  1624. {
  1625. bad_stab (orig);
  1626. return DEBUG_TYPE_NULL;
  1627. }
  1628. ++*pp;
  1629. /* The third number is the number of bits for this type. */
  1630. bits = parse_number (pp, (boolean *) NULL);
  1631. /* The type *should* end with a semicolon. If it are embedded
  1632. in a larger type the semicolon may be the only way to know where
  1633. the type ends. If this type is at the end of the stabstring we
  1634. can deal with the omitted semicolon (but we don't have to like
  1635. it). Don't bother to complain(), Sun's compiler omits the semicolon
  1636. for "void". */
  1637. if (**pp == ';')
  1638. ++*pp;
  1639. if (bits == 0)
  1640. return debug_make_void_type (dhandle);
  1641. return debug_make_int_type (dhandle, bits / 8, unsignedp);
  1642. }
  1643. /* Parse a builtin floating type generated by the Sun compiler. */
  1644. static debug_type
  1645. parse_stab_sun_floating_type (dhandle, pp)
  1646. PTR dhandle;
  1647. const char **pp;
  1648. {
  1649. const char *orig;
  1650. bfd_vma details;
  1651. bfd_vma bytes;
  1652. orig = *pp;
  1653. /* The first number has more details about the type, for example
  1654. FN_COMPLEX. */
  1655. details = parse_number (pp, (boolean *) NULL);
  1656. if (**pp != ';')
  1657. {
  1658. bad_stab (orig);
  1659. return DEBUG_TYPE_NULL;
  1660. }
  1661. /* The second number is the number of bytes occupied by this type */
  1662. bytes = parse_number (pp, (boolean *) NULL);
  1663. if (**pp != ';')
  1664. {
  1665. bad_stab (orig);
  1666. return DEBUG_TYPE_NULL;
  1667. }
  1668. if (details == NF_COMPLEX
  1669. || details == NF_COMPLEX16
  1670. || details == NF_COMPLEX32)
  1671. return debug_make_complex_type (dhandle, bytes);
  1672. return debug_make_float_type (dhandle, bytes);
  1673. }
  1674. /* Handle an enum type. */
  1675. static debug_type
  1676. parse_stab_enum_type (dhandle, pp)
  1677. PTR dhandle;
  1678. const char **pp;
  1679. {
  1680. const char *orig;
  1681. const char **names;
  1682. bfd_signed_vma *values;
  1683. unsigned int n;
  1684. unsigned int alloc;
  1685. orig = *pp;
  1686. /* FIXME: gdb checks os9k_stabs here. */
  1687. /* The aix4 compiler emits an extra field before the enum members;
  1688. my guess is it's a type of some sort. Just ignore it. */
  1689. if (**pp == '-')
  1690. {
  1691. while (**pp != ':')
  1692. ++*pp;
  1693. ++*pp;
  1694. }
  1695. /* Read the value-names and their values.
  1696. The input syntax is NAME:VALUE,NAME:VALUE, and so on.
  1697. A semicolon or comma instead of a NAME means the end. */
  1698. alloc = 10;
  1699. names = (const char **) xmalloc (alloc * sizeof *names);
  1700. values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values);
  1701. n = 0;
  1702. while (**pp != '\0' && **pp != ';' && **pp != ',')
  1703. {
  1704. const char *p;
  1705. char *name;
  1706. bfd_signed_vma val;
  1707. p = *pp;
  1708. while (*p != ':')
  1709. ++p;
  1710. name = savestring (*pp, p - *pp);
  1711. *pp = p + 1;
  1712. val = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
  1713. if (**pp != ',')
  1714. {
  1715. bad_stab (orig);
  1716. return DEBUG_TYPE_NULL;
  1717. }
  1718. ++*pp;
  1719. if (n + 1 >= alloc)
  1720. {
  1721. alloc += 10;
  1722. names = ((const char **)
  1723. xrealloc ((PTR) names, alloc * sizeof *names));
  1724. values = ((bfd_signed_vma *)
  1725. xrealloc ((PTR) values, alloc * sizeof *values));
  1726. }
  1727. names[n] = name;
  1728. values[n] = val;
  1729. ++n;
  1730. }
  1731. names[n] = NULL;
  1732. values[n] = 0;
  1733. if (**pp == ';')
  1734. ++*pp;
  1735. return debug_make_enum_type (dhandle, names, values);
  1736. }
  1737. /* Read the description of a structure (or union type) and return an object
  1738. describing the type.
  1739. PP points to a character pointer that points to the next unconsumed token
  1740. in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
  1741. *PP will point to "4a:1,0,32;;". */
  1742. static debug_type
  1743. parse_stab_struct_type (dhandle, info, tagname, pp, structp, typenums)
  1744. PTR dhandle;
  1745. struct stab_handle *info;
  1746. const char *tagname;
  1747. const char **pp;
  1748. boolean structp;
  1749. const int *typenums;
  1750. {
  1751. const char *orig;
  1752. bfd_vma size;
  1753. debug_baseclass *baseclasses;
  1754. debug_field *fields;
  1755. boolean statics;
  1756. debug_method *methods;
  1757. debug_type vptrbase;
  1758. boolean ownvptr;
  1759. orig = *pp;
  1760. /* Get the size. */
  1761. size = parse_number (pp, (boolean *) NULL);
  1762. /* Get the other information. */
  1763. if (! parse_stab_baseclasses (dhandle, info, pp, &baseclasses)
  1764. || ! parse_stab_struct_fields (dhandle, info, pp, &fields, &statics)
  1765. || ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods)
  1766. || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase,
  1767. &ownvptr))
  1768. return DEBUG_TYPE_NULL;
  1769. if (! statics
  1770. && baseclasses == NULL
  1771. && methods == NULL
  1772. && vptrbase == DEBUG_TYPE_NULL
  1773. && ! ownvptr)
  1774. return debug_make_struct_type (dhandle, structp, size, fields);
  1775. return debug_make_object_type (dhandle, structp, size, fields, baseclasses,
  1776. methods, vptrbase, ownvptr);
  1777. }
  1778. /* The stabs for C++ derived classes contain baseclass information which
  1779. is marked by a '!' character after the total size. This function is
  1780. called when we encounter the baseclass marker, and slurps up all the
  1781. baseclass information.
  1782. Immediately following the '!' marker is the number of base classes that
  1783. the class is derived from, followed by information for each base class.
  1784. For each base class, there are two visibility specifiers, a bit offset
  1785. to the base class information within the derived class, a reference to
  1786. the type for the base class, and a terminating semicolon.
  1787. A typical example, with two base classes, would be "!2,020,19;0264,21;".
  1788. ^^ ^ ^ ^ ^ ^ ^
  1789. Baseclass information marker __________________|| | | | | | |
  1790. Number of baseclasses __________________________| | | | | | |
  1791. Visibility specifiers (2) ________________________| | | | | |
  1792. Offset in bits from start of class _________________| | | | |
  1793. Type number for base class ___________________________| | | |
  1794. Visibility specifiers (2) _______________________________| | |
  1795. Offset in bits from start of class ________________________| |
  1796. Type number of base class ____________________________________|
  1797. Return true for success, false for failure. */
  1798. static boolean
  1799. parse_stab_baseclasses (dhandle, info, pp, retp)
  1800. PTR dhandle;
  1801. struct stab_handle *info;
  1802. const char **pp;
  1803. debug_baseclass **retp;
  1804. {
  1805. const char *orig;
  1806. unsigned int c, i;
  1807. debug_baseclass *classes;
  1808. *retp = NULL;
  1809. orig = *pp;
  1810. if (**pp != '!')
  1811. {
  1812. /* No base classes. */
  1813. return true;
  1814. }
  1815. ++*pp;
  1816. c = (unsigned int) parse_number (pp, (boolean *) NULL);
  1817. if (**pp != ',')
  1818. {
  1819. bad_stab (orig);
  1820. return false;
  1821. }
  1822. ++*pp;
  1823. classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp));
  1824. for (i = 0; i < c; i++)
  1825. {
  1826. boolean virtual;
  1827. enum debug_visibility visibility;
  1828. bfd_vma bitpos;
  1829. debug_type type;
  1830. switch (**pp)
  1831. {
  1832. case '0':
  1833. virtual = false;
  1834. break;
  1835. case '1':
  1836. virtual = true;
  1837. break;
  1838. default:
  1839. warn_stab (orig, "unknown virtual character for baseclass");
  1840. virtual = false;
  1841. break;
  1842. }
  1843. ++*pp;
  1844. switch (**pp)
  1845. {
  1846. case '0':
  1847. visibility = DEBUG_VISIBILITY_PRIVATE;
  1848. break;
  1849. case '1':
  1850. visibility = DEBUG_VISIBILITY_PROTECTED;
  1851. break;
  1852. case '2':
  1853. visibility = DEBUG_VISIBILITY_PUBLIC;
  1854. break;
  1855. default:
  1856. warn_stab (orig, "unknown visibility character for baseclass");
  1857. visibility = DEBUG_VISIBILITY_PUBLIC;
  1858. break;
  1859. }
  1860. ++*pp;
  1861. /* The remaining value is the bit offset of the portion of the
  1862. object corresponding to this baseclass. Always zero in the
  1863. absence of multiple inheritance. */
  1864. bitpos = parse_number (pp, (boolean *) NULL);
  1865. if (**pp != ',')
  1866. {
  1867. bad_stab (orig);
  1868. return false;
  1869. }
  1870. ++*pp;
  1871. type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  1872. (debug_type **) NULL);
  1873. if (type == DEBUG_TYPE_NULL)
  1874. return false;
  1875. classes[i] = debug_make_baseclass (dhandle, type, bitpos, virtual,
  1876. visibility);
  1877. if (classes[i] == DEBUG_BASECLASS_NULL)
  1878. return false;
  1879. if (**pp != ';')
  1880. return false;
  1881. ++*pp;
  1882. }
  1883. classes[i] = DEBUG_BASECLASS_NULL;
  1884. *retp = classes;
  1885. return true;
  1886. }
  1887. /* Read struct or class data fields. They have the form:
  1888. NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
  1889. At the end, we see a semicolon instead of a field.
  1890. In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
  1891. a static field.
  1892. The optional VISIBILITY is one of:
  1893. '/0' (VISIBILITY_PRIVATE)
  1894. '/1' (VISIBILITY_PROTECTED)
  1895. '/2' (VISIBILITY_PUBLIC)
  1896. '/9' (VISIBILITY_IGNORE)
  1897. or nothing, for C style fields with public visibility.
  1898. Returns 1 for success, 0 for failure. */
  1899. static boolean
  1900. parse_stab_struct_fields (dhandle, info, pp, retp, staticsp)
  1901. PTR dhandle;
  1902. struct stab_handle *info;
  1903. const char **pp;
  1904. debug_field **retp;
  1905. boolean *staticsp;
  1906. {
  1907. const char *orig;
  1908. const char *p;
  1909. debug_field *fields;
  1910. unsigned int c;
  1911. unsigned int alloc;
  1912. *retp = NULL;
  1913. *staticsp = false;
  1914. orig = *pp;
  1915. c = 0;
  1916. alloc = 10;
  1917. fields = (debug_field *) xmalloc (alloc * sizeof *fields);
  1918. while (**pp != ';')
  1919. {
  1920. /* FIXME: gdb checks os9k_stabs here. */
  1921. p = *pp;
  1922. /* Add 1 to c to leave room for NULL pointer at end. */
  1923. if (c + 1 >= alloc)
  1924. {
  1925. alloc += 10;
  1926. fields = ((debug_field *)
  1927. xrealloc ((PTR) fields, alloc * sizeof *fields));
  1928. }
  1929. /* If it starts with CPLUS_MARKER it is a special abbreviation,
  1930. unless the CPLUS_MARKER is followed by an underscore, in
  1931. which case it is just the name of an anonymous type, which we
  1932. should handle like any other type name. We accept either '$'
  1933. or '.', because a field name can never contain one of these
  1934. characters except as a CPLUS_MARKER. */
  1935. if ((*p == '$' || *p == '.') && p[1] != '_')
  1936. {
  1937. ++*pp;
  1938. if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c))
  1939. return false;
  1940. ++c;
  1941. continue;
  1942. }
  1943. /* Look for the ':' that separates the field name from the field
  1944. values. Data members are delimited by a single ':', while member
  1945. functions are delimited by a pair of ':'s. When we hit the member
  1946. functions (if any), terminate scan loop and return. */
  1947. p = strchr (p, ':');
  1948. if (p == NULL)
  1949. {
  1950. bad_stab (orig);
  1951. return false;
  1952. }
  1953. if (p[1] == ':')
  1954. break;
  1955. if (! parse_stab_one_struct_field (dhandle, info, pp, p, fields + c,
  1956. staticsp))
  1957. return false;
  1958. ++c;
  1959. }
  1960. fields[c] = DEBUG_FIELD_NULL;
  1961. *retp = fields;
  1962. return true;
  1963. }
  1964. /* Special GNU C++ name. */
  1965. static boolean
  1966. parse_stab_cpp_abbrev (dhandle, info, pp, retp)
  1967. PTR dhandle;
  1968. struct stab_handle *info;
  1969. const char **pp;
  1970. debug_field *retp;
  1971. {
  1972. const char *orig;
  1973. int cpp_abbrev;
  1974. debug_type context;
  1975. const char *name;
  1976. const char *typename;
  1977. debug_type type;
  1978. bfd_vma bitpos;
  1979. *retp = DEBUG_FIELD_NULL;
  1980. orig = *pp;
  1981. if (**pp != 'v')
  1982. {
  1983. bad_stab (*pp);
  1984. return false;
  1985. }
  1986. ++*pp;
  1987. cpp_abbrev = **pp;
  1988. ++*pp;
  1989. /* At this point, *pp points to something like "22:23=*22...", where
  1990. the type number before the ':' is the "context" and everything
  1991. after is a regular type definition. Lookup the type, find it's
  1992. name, and construct the field name. */
  1993. context = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  1994. (debug_type **) NULL);
  1995. if (context == DEBUG_TYPE_NULL)
  1996. return false;
  1997. switch (cpp_abbrev)
  1998. {
  1999. case 'f':
  2000. /* $vf -- a virtual function table pointer. */
  2001. name = "_vptr$";
  2002. break;
  2003. case 'b':
  2004. /* $vb -- a virtual bsomethingorother */
  2005. typename = debug_get_type_name (dhandle, context);
  2006. if (typename == NULL)
  2007. {
  2008. warn_stab (orig, "unnamed $vb type");
  2009. typename = "FOO";
  2010. }
  2011. name = concat ("_vb$", typename, (const char *) NULL);
  2012. break;
  2013. default:
  2014. warn_stab (orig, "unrecognized C++ abbreviation");
  2015. name = "INVALID_CPLUSPLUS_ABBREV";
  2016. break;
  2017. }
  2018. if (**pp != ':')
  2019. {
  2020. bad_stab (orig);
  2021. return false;
  2022. }
  2023. ++*pp;
  2024. type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  2025. (debug_type **) NULL);
  2026. if (**pp != ',')
  2027. {
  2028. bad_stab (orig);
  2029. return false;
  2030. }
  2031. ++*pp;
  2032. bitpos = parse_number (pp, (boolean *) NULL);
  2033. if (**pp != ';')
  2034. {
  2035. bad_stab (orig);
  2036. return false;
  2037. }
  2038. ++*pp;
  2039. *retp = debug_make_field (dhandle, name, type, bitpos, 0,
  2040. DEBUG_VISIBILITY_PRIVATE);
  2041. if (*retp == DEBUG_FIELD_NULL)
  2042. return false;
  2043. return true;
  2044. }
  2045. /* Parse a single field in a struct or union. */
  2046. static boolean
  2047. parse_stab_one_struct_field (dhandle, info, pp, p, retp, staticsp)
  2048. PTR dhandle;
  2049. struct stab_handle *info;
  2050. const char **pp;
  2051. const char *p;
  2052. debug_field *retp;
  2053. boolean *staticsp;
  2054. {
  2055. const char *orig;
  2056. char *name;
  2057. enum debug_visibility visibility;
  2058. debug_type type;
  2059. bfd_vma bitpos;
  2060. bfd_vma bitsize;
  2061. orig = *pp;
  2062. /* FIXME: gdb checks ARM_DEMANGLING here. */
  2063. name = savestring (*pp, p - *pp);
  2064. *pp = p + 1;
  2065. if (**pp != '/')
  2066. visibility = DEBUG_VISIBILITY_PUBLIC;
  2067. else
  2068. {
  2069. ++*pp;
  2070. switch (**pp)
  2071. {
  2072. case '0':
  2073. visibility = DEBUG_VISIBILITY_PRIVATE;
  2074. break;
  2075. case '1':
  2076. visibility = DEBUG_VISIBILITY_PROTECTED;
  2077. break;
  2078. case '2':
  2079. visibility = DEBUG_VISIBILITY_PUBLIC;
  2080. break;
  2081. default:
  2082. warn_stab (orig, "unknown visibility character for field");
  2083. visibility = DEBUG_VISIBILITY_PUBLIC;
  2084. break;
  2085. }
  2086. ++*pp;
  2087. }
  2088. type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  2089. (debug_type **) NULL);
  2090. if (type == DEBUG_TYPE_NULL)
  2091. return false;
  2092. if (**pp == ':')
  2093. {
  2094. char *varname;
  2095. /* This is a static class member. */
  2096. ++*pp;
  2097. p = strchr (*pp, ';');
  2098. if (p == NULL)
  2099. {
  2100. bad_stab (orig);
  2101. return false;
  2102. }
  2103. varname = savestring (*pp, p - *pp);
  2104. *pp = p + 1;
  2105. *retp = debug_make_static_member (dhandle, name, type, varname,
  2106. visibility);
  2107. *staticsp = true;
  2108. return true;
  2109. }
  2110. if (**pp != ',')
  2111. {
  2112. bad_stab (orig);
  2113. return false;
  2114. }
  2115. ++*pp;
  2116. bitpos = parse_number (pp, (boolean *) NULL);
  2117. if (**pp != ',')
  2118. {
  2119. bad_stab (orig);
  2120. return false;
  2121. }
  2122. ++*pp;
  2123. bitsize = parse_number (pp, (boolean *) NULL);
  2124. if (**pp != ';')
  2125. {
  2126. bad_stab (orig);
  2127. return false;
  2128. }
  2129. ++*pp;
  2130. if (bitpos == 0 && bitsize == 0)
  2131. {
  2132. /* This can happen in two cases: (1) at least for gcc 2.4.5 or
  2133. so, it is a field which has been optimized out. The correct
  2134. stab for this case is to use VISIBILITY_IGNORE, but that is a
  2135. recent invention. (2) It is a 0-size array. For example
  2136. union { int num; char str[0]; } foo. Printing "<no value>"
  2137. for str in "p foo" is OK, since foo.str (and thus foo.str[3])
  2138. will continue to work, and a 0-size array as a whole doesn't
  2139. have any contents to print.
  2140. I suspect this probably could also happen with gcc -gstabs
  2141. (not -gstabs+) for static fields, and perhaps other C++
  2142. extensions. Hopefully few people use -gstabs with gdb, since
  2143. it is intended for dbx compatibility. */
  2144. visibility = DEBUG_VISIBILITY_IGNORE;
  2145. }
  2146. /* FIXME: gdb does some stuff here to mark fields as unpacked. */
  2147. *retp = debug_make_field (dhandle, name, type, bitpos, bitsize, visibility);
  2148. return true;
  2149. }
  2150. /* Read member function stabs info for C++ classes. The form of each member
  2151. function data is:
  2152. NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
  2153. An example with two member functions is:
  2154. afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
  2155. For the case of overloaded operators, the format is op$::*.funcs, where
  2156. $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
  2157. name (such as `+=') and `.' marks the end of the operator name. */
  2158. static boolean
  2159. parse_stab_members (dhandle, info, tagname, pp, typenums, retp)
  2160. PTR dhandle;
  2161. struct stab_handle *info;
  2162. const char *tagname;
  2163. const char **pp;
  2164. const int *typenums;
  2165. debug_method **retp;
  2166. {
  2167. const char *orig;
  2168. debug_method *methods;
  2169. unsigned int c;
  2170. unsigned int alloc;
  2171. *retp = NULL;
  2172. orig = *pp;
  2173. alloc = 0;
  2174. methods = NULL;
  2175. c = 0;
  2176. while (**pp != ';')
  2177. {
  2178. const char *p;
  2179. char *name;
  2180. debug_method_variant *variants;
  2181. unsigned int cvars;
  2182. unsigned int allocvars;
  2183. debug_type look_ahead_type;
  2184. p = strchr (*pp, ':');
  2185. if (p == NULL || p[1] != ':')
  2186. break;
  2187. /* FIXME: Some systems use something other than '$' here. */
  2188. if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$')
  2189. {
  2190. name = savestring (*pp, p - *pp);
  2191. *pp = p + 2;
  2192. }
  2193. else
  2194. {
  2195. /* This is a completely wierd case. In order to stuff in the
  2196. names that might contain colons (the usual name delimiter),
  2197. Mike Tiemann defined a different name format which is
  2198. signalled if the identifier is "op$". In that case, the
  2199. format is "op$::XXXX." where XXXX is the name. This is
  2200. used for names like "+" or "=". YUUUUUUUK! FIXME! */
  2201. *pp = p + 2;
  2202. for (p = *pp; *p != '.' && *p != '\0'; p++)
  2203. ;
  2204. if (*p != '.')
  2205. {
  2206. bad_stab (orig);
  2207. return false;
  2208. }
  2209. name = savestring (*pp, p - *pp);
  2210. *pp = p + 1;
  2211. }
  2212. allocvars = 10;
  2213. variants = ((debug_method_variant *)
  2214. xmalloc (allocvars * sizeof *variants));
  2215. cvars = 0;
  2216. look_ahead_type = DEBUG_TYPE_NULL;
  2217. do
  2218. {
  2219. debug_type type;
  2220. boolean stub;
  2221. char *argtypes;
  2222. enum debug_visibility visibility;
  2223. boolean constp, volatilep, staticp;
  2224. bfd_vma voffset;
  2225. debug_type context;
  2226. const char *physname;
  2227. boolean varargs;
  2228. if (look_ahead_type != DEBUG_TYPE_NULL)
  2229. {
  2230. /* g++ version 1 kludge */
  2231. type = look_ahead_type;
  2232. look_ahead_type = DEBUG_TYPE_NULL;
  2233. }
  2234. else
  2235. {
  2236. type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  2237. (debug_type **) NULL);
  2238. if (type == DEBUG_TYPE_NULL)
  2239. return false;
  2240. if (**pp != ':')
  2241. {
  2242. bad_stab (orig);
  2243. return false;
  2244. }
  2245. }
  2246. ++*pp;
  2247. p = strchr (*pp, ';');
  2248. if (p == NULL)
  2249. {
  2250. bad_stab (orig);
  2251. return false;
  2252. }
  2253. stub = false;
  2254. if (debug_get_type_kind (dhandle, type) == DEBUG_KIND_METHOD
  2255. && debug_get_parameter_types (dhandle, type, &varargs) == NULL)
  2256. stub = true;
  2257. argtypes = savestring (*pp, p - *pp);
  2258. *pp = p + 1;
  2259. switch (**pp)
  2260. {
  2261. case '0':
  2262. visibility = DEBUG_VISIBILITY_PRIVATE;
  2263. break;
  2264. case '1':
  2265. visibility = DEBUG_VISIBILITY_PROTECTED;
  2266. break;
  2267. default:
  2268. visibility = DEBUG_VISIBILITY_PUBLIC;
  2269. break;
  2270. }
  2271. ++*pp;
  2272. constp = false;
  2273. volatilep = false;
  2274. switch (**pp)
  2275. {
  2276. case 'A':
  2277. /* Normal function. */
  2278. ++*pp;
  2279. break;
  2280. case 'B':
  2281. /* const member function. */
  2282. constp = true;
  2283. ++*pp;
  2284. break;
  2285. case 'C':
  2286. /* volatile member function. */
  2287. volatilep = true;
  2288. ++*pp;
  2289. break;
  2290. case 'D':
  2291. /* const volatile member function. */
  2292. constp = true;
  2293. volatilep = true;
  2294. ++*pp;
  2295. break;
  2296. case '*':
  2297. case '?':
  2298. case '.':
  2299. /* File compiled with g++ version 1; no information. */
  2300. break;
  2301. default:
  2302. warn_stab (orig, "const/volatile indicator missing");
  2303. break;
  2304. }
  2305. staticp = false;
  2306. switch (**pp)
  2307. {
  2308. case '*':
  2309. /* virtual member function, followed by index. The sign
  2310. bit is supposedly set to distinguish
  2311. pointers-to-methods from virtual function indicies. */
  2312. ++*pp;
  2313. voffset = parse_number (pp, (boolean *) NULL);
  2314. if (**pp != ';')
  2315. {
  2316. bad_stab (orig);
  2317. return false;
  2318. }
  2319. ++*pp;
  2320. voffset &= 0x7fffffff;
  2321. if (**pp == ';' || *pp == '\0')
  2322. {
  2323. /* Must be g++ version 1. */
  2324. context = DEBUG_TYPE_NULL;
  2325. }
  2326. else
  2327. {
  2328. /* Figure out from whence this virtual function
  2329. came. It may belong to virtual function table of
  2330. one of its baseclasses. */
  2331. look_ahead_type = parse_stab_type (dhandle, info,
  2332. (const char *) NULL,
  2333. pp,
  2334. (debug_type **) NULL);
  2335. if (**pp == ':')
  2336. {
  2337. /* g++ version 1 overloaded methods. */
  2338. context = DEBUG_TYPE_NULL;
  2339. }
  2340. else
  2341. {
  2342. context = look_ahead_type;
  2343. look_ahead_type = DEBUG_TYPE_NULL;
  2344. if (**pp != ';')
  2345. {
  2346. bad_stab (orig);
  2347. return false;
  2348. }
  2349. ++*pp;
  2350. }
  2351. }
  2352. break;
  2353. case '?':
  2354. /* static member function. */
  2355. ++*pp;
  2356. staticp = true;
  2357. voffset = 0;
  2358. context = DEBUG_TYPE_NULL;
  2359. if (strncmp (argtypes, name, strlen (name)) != 0)
  2360. stub = true;
  2361. break;
  2362. default:
  2363. warn_stab (orig, "member function type missing");
  2364. voffset = 0;
  2365. context = DEBUG_TYPE_NULL;
  2366. break;
  2367. case '.':
  2368. ++*pp;
  2369. voffset = 0;
  2370. context = DEBUG_TYPE_NULL;
  2371. break;
  2372. }
  2373. /* If the type is not a stub, then the argtypes string is
  2374. the physical name of the function. Otherwise the
  2375. argtypes string is the mangled form of the argument
  2376. types, and the full type and the physical name must be
  2377. extracted from them. */
  2378. if (! stub)
  2379. physname = argtypes;
  2380. else
  2381. {
  2382. debug_type class_type, return_type;
  2383. class_type = stab_find_type (dhandle, info, typenums);
  2384. if (class_type == DEBUG_TYPE_NULL)
  2385. return false;
  2386. return_type = debug_get_return_type (dhandle, type);
  2387. if (return_type == DEBUG_TYPE_NULL)
  2388. {
  2389. bad_stab (orig);
  2390. return false;
  2391. }
  2392. type = parse_stab_argtypes (dhandle, info, class_type, name,
  2393. tagname, return_type, argtypes,
  2394. constp, volatilep, &physname);
  2395. if (type == DEBUG_TYPE_NULL)
  2396. return false;
  2397. }
  2398. if (cvars + 1 >= allocvars)
  2399. {
  2400. allocvars += 10;
  2401. variants = ((debug_method_variant *)
  2402. xrealloc ((PTR) variants,
  2403. allocvars * sizeof *variants));
  2404. }
  2405. if (! staticp)
  2406. variants[cvars] = debug_make_method_variant (dhandle, physname,
  2407. type, visibility,
  2408. constp, volatilep,
  2409. voffset, context);
  2410. else
  2411. variants[cvars] = debug_make_static_method_variant (dhandle,
  2412. physname,
  2413. type,
  2414. visibility,
  2415. constp,
  2416. volatilep);
  2417. if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL)
  2418. return false;
  2419. ++cvars;
  2420. }
  2421. while (**pp != ';' && **pp != '\0');
  2422. variants[cvars] = DEBUG_METHOD_VARIANT_NULL;
  2423. if (**pp != '\0')
  2424. ++*pp;
  2425. if (c + 1 >= alloc)
  2426. {
  2427. alloc += 10;
  2428. methods = ((debug_method *)
  2429. xrealloc ((PTR) methods, alloc * sizeof *methods));
  2430. }
  2431. methods[c] = debug_make_method (dhandle, name, variants);
  2432. ++c;
  2433. }
  2434. if (methods != NULL)
  2435. methods[c] = DEBUG_METHOD_NULL;
  2436. *retp = methods;
  2437. return true;
  2438. }
  2439. /* Parse a string representing argument types for a method. Stabs
  2440. tries to save space by packing argument types into a mangled
  2441. string. This string should give us enough information to extract
  2442. both argument types and the physical name of the function, given
  2443. the tag name. */
  2444. static debug_type
  2445. parse_stab_argtypes (dhandle, info, class_type, fieldname, tagname,
  2446. return_type, argtypes, constp, volatilep, pphysname)
  2447. PTR dhandle;
  2448. struct stab_handle *info;
  2449. debug_type class_type;
  2450. const char *fieldname;
  2451. const char *tagname;
  2452. debug_type return_type;
  2453. const char *argtypes;
  2454. boolean constp;
  2455. boolean volatilep;
  2456. const char **pphysname;
  2457. {
  2458. boolean is_full_physname_constructor;
  2459. boolean is_constructor;
  2460. boolean is_destructor;
  2461. debug_type *args;
  2462. boolean varargs;
  2463. /* Constructors are sometimes handled specially. */
  2464. is_full_physname_constructor = ((argtypes[0] == '_'
  2465. && argtypes[1] == '_'
  2466. && (isdigit ((unsigned char) argtypes[2])
  2467. || argtypes[2] == 'Q'
  2468. || argtypes[2] == 't'))
  2469. || strncmp (argtypes, "__ct", 4) == 0);
  2470. is_constructor = (is_full_physname_constructor
  2471. || (tagname != NULL
  2472. && strcmp (fieldname, tagname) == 0));
  2473. is_destructor = ((argtypes[0] == '_'
  2474. && (argtypes[1] == '$' || argtypes[1] == '.')
  2475. && argtypes[2] == '_')
  2476. || strncmp (argtypes, "__dt", 4) == 0);
  2477. if (is_destructor || is_full_physname_constructor)
  2478. *pphysname = argtypes;
  2479. else
  2480. {
  2481. unsigned int len;
  2482. const char *const_prefix;
  2483. const char *volatile_prefix;
  2484. char buf[20];
  2485. unsigned int mangled_name_len;
  2486. char *physname;
  2487. len = tagname == NULL ? 0 : strlen (tagname);
  2488. const_prefix = constp ? "C" : "";
  2489. volatile_prefix = volatilep ? "V" : "";
  2490. if (len == 0)
  2491. sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
  2492. else if (tagname != NULL && strchr (tagname, '<') != NULL)
  2493. {
  2494. /* Template methods are fully mangled. */
  2495. sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
  2496. tagname = NULL;
  2497. len = 0;
  2498. }
  2499. else
  2500. sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
  2501. mangled_name_len = ((is_constructor ? 0 : strlen (fieldname))
  2502. + strlen (buf)
  2503. + len
  2504. + strlen (argtypes)
  2505. + 1);
  2506. if (fieldname[0] == 'o'
  2507. && fieldname[1] == 'p'
  2508. && (fieldname[2] == '$' || fieldname[2] == '.'))
  2509. {
  2510. const char *opname;
  2511. opname = cplus_mangle_opname (fieldname + 3, 0);
  2512. if (opname == NULL)
  2513. {
  2514. fprintf (stderr, "No mangling for \"%s\"\n", fieldname);
  2515. return DEBUG_TYPE_NULL;
  2516. }
  2517. mangled_name_len += strlen (opname);
  2518. physname = (char *) xmalloc (mangled_name_len);
  2519. strncpy (physname, fieldname, 3);
  2520. strcpy (physname + 3, opname);
  2521. }
  2522. else
  2523. {
  2524. physname = (char *) xmalloc (mangled_name_len);
  2525. if (is_constructor)
  2526. physname[0] = '\0';
  2527. else
  2528. strcpy (physname, fieldname);
  2529. }
  2530. strcat (physname, buf);
  2531. if (tagname != NULL)
  2532. strcat (physname, tagname);
  2533. strcat (physname, argtypes);
  2534. *pphysname = physname;
  2535. }
  2536. if (*argtypes == '\0' || is_destructor)
  2537. {
  2538. args = (debug_type *) xmalloc (sizeof *args);
  2539. *args = NULL;
  2540. return debug_make_method_type (dhandle, return_type, class_type, args,
  2541. false);
  2542. }
  2543. args = stab_demangle_argtypes (dhandle, info, *pphysname, &varargs);
  2544. if (args == NULL)
  2545. return DEBUG_TYPE_NULL;
  2546. return debug_make_method_type (dhandle, return_type, class_type, args,
  2547. varargs);
  2548. }
  2549. /* The tail end of stabs for C++ classes that contain a virtual function
  2550. pointer contains a tilde, a %, and a type number.
  2551. The type number refers to the base class (possibly this class itself) which
  2552. contains the vtable pointer for the current class.
  2553. This function is called when we have parsed all the method declarations,
  2554. so we can look for the vptr base class info. */
  2555. static boolean
  2556. parse_stab_tilde_field (dhandle, info, pp, typenums, retvptrbase, retownvptr)
  2557. PTR dhandle;
  2558. struct stab_handle *info;
  2559. const char **pp;
  2560. const int *typenums;
  2561. debug_type *retvptrbase;
  2562. boolean *retownvptr;
  2563. {
  2564. const char *orig;
  2565. const char *hold;
  2566. int vtypenums[2];
  2567. *retvptrbase = DEBUG_TYPE_NULL;
  2568. *retownvptr = false;
  2569. orig = *pp;
  2570. /* If we are positioned at a ';', then skip it. */
  2571. if (**pp == ';')
  2572. ++*pp;
  2573. if (**pp != '~')
  2574. return true;
  2575. ++*pp;
  2576. if (**pp == '=' || **pp == '+' || **pp == '-')
  2577. {
  2578. /* Obsolete flags that used to indicate the presence of
  2579. constructors and/or destructors. */
  2580. ++*pp;
  2581. }
  2582. if (**pp != '%')
  2583. return true;
  2584. ++*pp;
  2585. hold = *pp;
  2586. /* The next number is the type number of the base class (possibly
  2587. our own class) which supplies the vtable for this class. */
  2588. if (! parse_stab_type_number (pp, vtypenums))
  2589. return false;
  2590. if (vtypenums[0] == typenums[0]
  2591. && vtypenums[1] == typenums[1])
  2592. *retownvptr = true;
  2593. else
  2594. {
  2595. debug_type vtype;
  2596. const char *p;
  2597. *pp = hold;
  2598. vtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  2599. (debug_type **) NULL);
  2600. for (p = *pp; *p != ';' && *p != '\0'; p++)
  2601. ;
  2602. if (*p != ';')
  2603. {
  2604. bad_stab (orig);
  2605. return false;
  2606. }
  2607. *retvptrbase = vtype;
  2608. *pp = p + 1;
  2609. }
  2610. return true;
  2611. }
  2612. /* Read a definition of an array type. */
  2613. static debug_type
  2614. parse_stab_array_type (dhandle, info, pp, stringp)
  2615. PTR dhandle;
  2616. struct stab_handle *info;
  2617. const char **pp;
  2618. boolean stringp;
  2619. {
  2620. const char *orig;
  2621. const char *p;
  2622. int typenums[2];
  2623. debug_type index_type;
  2624. boolean adjustable;
  2625. bfd_signed_vma lower, upper;
  2626. debug_type element_type;
  2627. /* Format of an array type:
  2628. "ar<index type>;lower;upper;<array_contents_type>".
  2629. OS9000: "arlower,upper;<array_contents_type>".
  2630. Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
  2631. for these, produce a type like float[][]. */
  2632. orig = *pp;
  2633. /* FIXME: gdb checks os9k_stabs here. */
  2634. /* If the index type is type 0, we take it as int. */
  2635. p = *pp;
  2636. if (! parse_stab_type_number (&p, typenums))
  2637. return DEBUG_TYPE_NULL;
  2638. if (typenums[0] == 0 && typenums[1] == 0 && **pp != '=')
  2639. {
  2640. index_type = debug_find_named_type (dhandle, "int");
  2641. if (index_type == DEBUG_TYPE_NULL)
  2642. {
  2643. index_type = debug_make_int_type (dhandle, 4, false);
  2644. if (index_type == DEBUG_TYPE_NULL)
  2645. return DEBUG_TYPE_NULL;
  2646. }
  2647. *pp = p;
  2648. }
  2649. else
  2650. {
  2651. index_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  2652. (debug_type **) NULL);
  2653. }
  2654. if (**pp != ';')
  2655. {
  2656. bad_stab (orig);
  2657. return DEBUG_TYPE_NULL;
  2658. }
  2659. ++*pp;
  2660. adjustable = false;
  2661. if (! isdigit ((unsigned char) **pp) && **pp != '-')
  2662. {
  2663. ++*pp;
  2664. adjustable = true;
  2665. }
  2666. lower = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
  2667. if (**pp != ';')
  2668. {
  2669. bad_stab (orig);
  2670. return DEBUG_TYPE_NULL;
  2671. }
  2672. ++*pp;
  2673. if (! isdigit ((unsigned char) **pp) && **pp != '-')
  2674. {
  2675. ++*pp;
  2676. adjustable = true;
  2677. }
  2678. upper = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
  2679. if (**pp != ';')
  2680. {
  2681. bad_stab (orig);
  2682. return DEBUG_TYPE_NULL;
  2683. }
  2684. ++*pp;
  2685. element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  2686. (debug_type **) NULL);
  2687. if (element_type == DEBUG_TYPE_NULL)
  2688. return DEBUG_TYPE_NULL;
  2689. if (adjustable)
  2690. {
  2691. lower = 0;
  2692. upper = -1;
  2693. }
  2694. return debug_make_array_type (dhandle, element_type, index_type, lower,
  2695. upper, stringp);
  2696. }
  2697. /* This struct holds information about files we have seen using
  2698. N_BINCL. */
  2699. struct bincl_file
  2700. {
  2701. /* The next N_BINCL file. */
  2702. struct bincl_file *next;
  2703. /* The next N_BINCL on the stack. */
  2704. struct bincl_file *next_stack;
  2705. /* The file name. */
  2706. const char *name;
  2707. /* The hash value. */
  2708. bfd_vma hash;
  2709. /* The file index. */
  2710. unsigned int file;
  2711. /* The list of types defined in this file. */
  2712. struct stab_types *file_types;
  2713. };
  2714. /* Start a new N_BINCL file, pushing it onto the stack. */
  2715. static void
  2716. push_bincl (info, name, hash)
  2717. struct stab_handle *info;
  2718. const char *name;
  2719. bfd_vma hash;
  2720. {
  2721. struct bincl_file *n;
  2722. n = (struct bincl_file *) xmalloc (sizeof *n);
  2723. n->next = info->bincl_list;
  2724. n->next_stack = info->bincl_stack;
  2725. n->name = name;
  2726. n->hash = hash;
  2727. n->file = info->files;
  2728. n->file_types = NULL;
  2729. info->bincl_list = n;
  2730. info->bincl_stack = n;
  2731. ++info->files;
  2732. info->file_types = ((struct stab_types **)
  2733. xrealloc ((PTR) info->file_types,
  2734. (info->files
  2735. * sizeof *info->file_types)));
  2736. info->file_types[n->file] = NULL;
  2737. }
  2738. /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
  2739. stack. */
  2740. static const char *
  2741. pop_bincl (info)
  2742. struct stab_handle *info;
  2743. {
  2744. struct bincl_file *o;
  2745. o = info->bincl_stack;
  2746. if (o == NULL)
  2747. return info->main_filename;
  2748. info->bincl_stack = o->next_stack;
  2749. o->file_types = info->file_types[o->file];
  2750. if (info->bincl_stack == NULL)
  2751. return info->main_filename;
  2752. return info->bincl_stack->name;
  2753. }
  2754. /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */
  2755. static boolean
  2756. find_excl (info, name, hash)
  2757. struct stab_handle *info;
  2758. const char *name;
  2759. bfd_vma hash;
  2760. {
  2761. struct bincl_file *l;
  2762. ++info->files;
  2763. info->file_types = ((struct stab_types **)
  2764. xrealloc ((PTR) info->file_types,
  2765. (info->files
  2766. * sizeof *info->file_types)));
  2767. for (l = info->bincl_list; l != NULL; l = l->next)
  2768. if (l->hash == hash && strcmp (l->name, name) == 0)
  2769. break;
  2770. if (l == NULL)
  2771. {
  2772. warn_stab (name, "Undefined N_EXCL");
  2773. info->file_types[info->files - 1] = NULL;
  2774. return true;
  2775. }
  2776. info->file_types[info->files - 1] = l->file_types;
  2777. return true;
  2778. }
  2779. /* Handle a variable definition. gcc emits variable definitions for a
  2780. block before the N_LBRAC, so we must hold onto them until we see
  2781. it. The SunPRO compiler emits variable definitions after the
  2782. N_LBRAC, so we can call debug_record_variable immediately. */
  2783. static boolean
  2784. stab_record_variable (dhandle, info, name, type, kind, val)
  2785. PTR dhandle;
  2786. struct stab_handle *info;
  2787. const char *name;
  2788. debug_type type;
  2789. enum debug_var_kind kind;
  2790. bfd_vma val;
  2791. {
  2792. struct stab_pending_var *v;
  2793. if ((kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
  2794. || ! info->within_function
  2795. || (info->gcc_compiled == 0 && info->n_opt_found))
  2796. return debug_record_variable (dhandle, name, type, kind, val);
  2797. v = (struct stab_pending_var *) xmalloc (sizeof *v);
  2798. memset (v, 0, sizeof *v);
  2799. v->next = info->pending;
  2800. v->name = name;
  2801. v->type = type;
  2802. v->kind = kind;
  2803. v->val = val;
  2804. info->pending = v;
  2805. return true;
  2806. }
  2807. /* Emit pending variable definitions. This is called after we see the
  2808. N_LBRAC that starts the block. */
  2809. static boolean
  2810. stab_emit_pending_vars (dhandle, info)
  2811. PTR dhandle;
  2812. struct stab_handle *info;
  2813. {
  2814. struct stab_pending_var *v;
  2815. v = info->pending;
  2816. while (v != NULL)
  2817. {
  2818. struct stab_pending_var *next;
  2819. if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val))
  2820. return false;
  2821. next = v->next;
  2822. free (v);
  2823. v = next;
  2824. }
  2825. info->pending = NULL;
  2826. return true;
  2827. }
  2828. /* Find the slot for a type in the database. */
  2829. static debug_type *
  2830. stab_find_slot (info, typenums)
  2831. struct stab_handle *info;
  2832. const int *typenums;
  2833. {
  2834. int filenum;
  2835. int index;
  2836. struct stab_types **ps;
  2837. filenum = typenums[0];
  2838. index = typenums[1];
  2839. if (filenum < 0 || (unsigned int) filenum >= info->files)
  2840. {
  2841. fprintf (stderr, "Type file number %d out of range\n", filenum);
  2842. return NULL;
  2843. }
  2844. if (index < 0)
  2845. {
  2846. fprintf (stderr, "Type index number %d out of range\n", index);
  2847. return NULL;
  2848. }
  2849. ps = info->file_types + filenum;
  2850. while (index >= STAB_TYPES_SLOTS)
  2851. {
  2852. if (*ps == NULL)
  2853. {
  2854. *ps = (struct stab_types *) xmalloc (sizeof **ps);
  2855. memset (*ps, 0, sizeof **ps);
  2856. }
  2857. ps = &(*ps)->next;
  2858. index -= STAB_TYPES_SLOTS;
  2859. }
  2860. if (*ps == NULL)
  2861. {
  2862. *ps = (struct stab_types *) xmalloc (sizeof **ps);
  2863. memset (*ps, 0, sizeof **ps);
  2864. }
  2865. return (*ps)->types + index;
  2866. }
  2867. /* Find a type given a type number. If the type has not been
  2868. allocated yet, create an indirect type. */
  2869. static debug_type
  2870. stab_find_type (dhandle, info, typenums)
  2871. PTR dhandle;
  2872. struct stab_handle *info;
  2873. const int *typenums;
  2874. {
  2875. debug_type *slot;
  2876. if (typenums[0] == 0 && typenums[1] < 0)
  2877. {
  2878. /* A negative type number indicates an XCOFF builtin type. */
  2879. return stab_xcoff_builtin_type (dhandle, info, typenums[1]);
  2880. }
  2881. slot = stab_find_slot (info, typenums);
  2882. if (slot == NULL)
  2883. return DEBUG_TYPE_NULL;
  2884. if (*slot == DEBUG_TYPE_NULL)
  2885. return debug_make_indirect_type (dhandle, slot, (const char *) NULL);
  2886. return *slot;
  2887. }
  2888. /* Record that a given type number refers to a given type. */
  2889. static boolean
  2890. stab_record_type (dhandle, info, typenums, type)
  2891. PTR dhandle;
  2892. struct stab_handle *info;
  2893. const int *typenums;
  2894. debug_type type;
  2895. {
  2896. debug_type *slot;
  2897. slot = stab_find_slot (info, typenums);
  2898. if (slot == NULL)
  2899. return false;
  2900. /* gdb appears to ignore type redefinitions, so we do as well. */
  2901. *slot = type;
  2902. return true;
  2903. }
  2904. /* Return an XCOFF builtin type. */
  2905. static debug_type
  2906. stab_xcoff_builtin_type (dhandle, info, typenum)
  2907. PTR dhandle;
  2908. struct stab_handle *info;
  2909. int typenum;
  2910. {
  2911. debug_type rettype;
  2912. const char *name;
  2913. if (typenum >= 0 || typenum < -XCOFF_TYPE_COUNT)
  2914. {
  2915. fprintf (stderr, "Unrecognized XCOFF type %d\n", typenum);
  2916. return DEBUG_TYPE_NULL;
  2917. }
  2918. if (info->xcoff_types[-typenum] != NULL)
  2919. return info->xcoff_types[-typenum];
  2920. switch (-typenum)
  2921. {
  2922. case 1:
  2923. /* The size of this and all the other types are fixed, defined
  2924. by the debugging format. */
  2925. name = "int";
  2926. rettype = debug_make_int_type (dhandle, 4, false);
  2927. break;
  2928. case 2:
  2929. name = "char";
  2930. rettype = debug_make_int_type (dhandle, 1, false);
  2931. break;
  2932. case 3:
  2933. name = "short";
  2934. rettype = debug_make_int_type (dhandle, 2, false);
  2935. break;
  2936. case 4:
  2937. name = "long";
  2938. rettype = debug_make_int_type (dhandle, 4, false);
  2939. break;
  2940. case 5:
  2941. name = "unsigned char";
  2942. rettype = debug_make_int_type (dhandle, 1, true);
  2943. break;
  2944. case 6:
  2945. name = "signed char";
  2946. rettype = debug_make_int_type (dhandle, 1, false);
  2947. break;
  2948. case 7:
  2949. name = "unsigned short";
  2950. rettype = debug_make_int_type (dhandle, 2, true);
  2951. break;
  2952. case 8:
  2953. name = "unsigned int";
  2954. rettype = debug_make_int_type (dhandle, 4, true);
  2955. break;
  2956. case 9:
  2957. name = "unsigned";
  2958. rettype = debug_make_int_type (dhandle, 4, true);
  2959. case 10:
  2960. name = "unsigned long";
  2961. rettype = debug_make_int_type (dhandle, 4, true);
  2962. break;
  2963. case 11:
  2964. name = "void";
  2965. rettype = debug_make_void_type (dhandle);
  2966. break;
  2967. case 12:
  2968. /* IEEE single precision (32 bit). */
  2969. name = "float";
  2970. rettype = debug_make_float_type (dhandle, 4);
  2971. break;
  2972. case 13:
  2973. /* IEEE double precision (64 bit). */
  2974. name = "double";
  2975. rettype = debug_make_float_type (dhandle, 8);
  2976. break;
  2977. case 14:
  2978. /* This is an IEEE double on the RS/6000, and different machines
  2979. with different sizes for "long double" should use different
  2980. negative type numbers. See stabs.texinfo. */
  2981. name = "long double";
  2982. rettype = debug_make_float_type (dhandle, 8);
  2983. break;
  2984. case 15:
  2985. name = "integer";
  2986. rettype = debug_make_int_type (dhandle, 4, false);
  2987. break;
  2988. case 16:
  2989. name = "boolean";
  2990. rettype = debug_make_bool_type (dhandle, 4);
  2991. break;
  2992. case 17:
  2993. name = "short real";
  2994. rettype = debug_make_float_type (dhandle, 4);
  2995. break;
  2996. case 18:
  2997. name = "real";
  2998. rettype = debug_make_float_type (dhandle, 8);
  2999. break;
  3000. case 19:
  3001. /* FIXME */
  3002. name = "stringptr";
  3003. rettype = NULL;
  3004. break;
  3005. case 20:
  3006. /* FIXME */
  3007. name = "character";
  3008. rettype = debug_make_int_type (dhandle, 1, true);
  3009. break;
  3010. case 21:
  3011. name = "logical*1";
  3012. rettype = debug_make_bool_type (dhandle, 1);
  3013. break;
  3014. case 22:
  3015. name = "logical*2";
  3016. rettype = debug_make_bool_type (dhandle, 2);
  3017. break;
  3018. case 23:
  3019. name = "logical*4";
  3020. rettype = debug_make_bool_type (dhandle, 4);
  3021. break;
  3022. case 24:
  3023. name = "logical";
  3024. rettype = debug_make_bool_type (dhandle, 4);
  3025. break;
  3026. case 25:
  3027. /* Complex type consisting of two IEEE single precision values. */
  3028. name = "complex";
  3029. rettype = debug_make_complex_type (dhandle, 8);
  3030. break;
  3031. case 26:
  3032. /* Complex type consisting of two IEEE double precision values. */
  3033. name = "double complex";
  3034. rettype = debug_make_complex_type (dhandle, 16);
  3035. break;
  3036. case 27:
  3037. name = "integer*1";
  3038. rettype = debug_make_int_type (dhandle, 1, false);
  3039. break;
  3040. case 28:
  3041. name = "integer*2";
  3042. rettype = debug_make_int_type (dhandle, 2, false);
  3043. break;
  3044. case 29:
  3045. name = "integer*4";
  3046. rettype = debug_make_int_type (dhandle, 4, false);
  3047. break;
  3048. case 30:
  3049. /* FIXME */
  3050. name = "wchar";
  3051. rettype = debug_make_int_type (dhandle, 2, false);
  3052. break;
  3053. case 31:
  3054. name = "long long";
  3055. rettype = debug_make_int_type (dhandle, 8, false);
  3056. break;
  3057. case 32:
  3058. name = "unsigned long long";
  3059. rettype = debug_make_int_type (dhandle, 8, true);
  3060. break;
  3061. case 33:
  3062. name = "logical*8";
  3063. rettype = debug_make_bool_type (dhandle, 8);
  3064. break;
  3065. case 34:
  3066. name = "integer*8";
  3067. rettype = debug_make_int_type (dhandle, 8, false);
  3068. break;
  3069. default:
  3070. abort ();
  3071. }
  3072. rettype = debug_name_type (dhandle, name, rettype);
  3073. info->xcoff_types[-typenum] = rettype;
  3074. return rettype;
  3075. }
  3076. /* Find or create a tagged type. */
  3077. static debug_type
  3078. stab_find_tagged_type (dhandle, info, p, len, kind)
  3079. PTR dhandle;
  3080. struct stab_handle *info;
  3081. const char *p;
  3082. int len;
  3083. enum debug_type_kind kind;
  3084. {
  3085. char *name;
  3086. debug_type dtype;
  3087. struct stab_tag *st;
  3088. name = savestring (p, len);
  3089. /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
  3090. namespace. This is right for C, and I don't know how to handle
  3091. other languages. FIXME. */
  3092. dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_ILLEGAL);
  3093. if (dtype != DEBUG_TYPE_NULL)
  3094. {
  3095. free (name);
  3096. return dtype;
  3097. }
  3098. /* We need to allocate an entry on the undefined tag list. */
  3099. for (st = info->tags; st != NULL; st = st->next)
  3100. {
  3101. if (st->name[0] == name[0]
  3102. && strcmp (st->name, name) == 0)
  3103. {
  3104. if (st->kind == DEBUG_KIND_ILLEGAL)
  3105. st->kind = kind;
  3106. free (name);
  3107. break;
  3108. }
  3109. }
  3110. if (st == NULL)
  3111. {
  3112. st = (struct stab_tag *) xmalloc (sizeof *st);
  3113. memset (st, 0, sizeof *st);
  3114. st->next = info->tags;
  3115. st->name = name;
  3116. st->kind = kind;
  3117. st->slot = DEBUG_TYPE_NULL;
  3118. st->type = debug_make_indirect_type (dhandle, &st->slot, name);
  3119. info->tags = st;
  3120. }
  3121. return st->type;
  3122. }
  3123. /* In order to get the correct argument types for a stubbed method, we
  3124. need to extract the argument types from a C++ mangled string.
  3125. Since the argument types can refer back to the return type, this
  3126. means that we must demangle the entire physical name. In gdb this
  3127. is done by calling cplus_demangle and running the results back
  3128. through the C++ expression parser. Since we have no expression
  3129. parser, we must duplicate much of the work of cplus_demangle here.
  3130. We assume that GNU style demangling is used, since this is only
  3131. done for method stubs, and only g++ should output that form of
  3132. debugging information. */
  3133. /* This structure is used to hold a pointer to type information which
  3134. demangling a string. */
  3135. struct stab_demangle_typestring
  3136. {
  3137. /* The start of the type. This is not null terminated. */
  3138. const char *typestring;
  3139. /* The length of the type. */
  3140. unsigned int len;
  3141. };
  3142. /* This structure is used to hold information while demangling a
  3143. string. */
  3144. struct stab_demangle_info
  3145. {
  3146. /* The debugging information handle. */
  3147. PTR dhandle;
  3148. /* The stab information handle. */
  3149. struct stab_handle *info;
  3150. /* The array of arguments we are building. */
  3151. debug_type *args;
  3152. /* Whether the method takes a variable number of arguments. */
  3153. boolean varargs;
  3154. /* The array of types we have remembered. */
  3155. struct stab_demangle_typestring *typestrings;
  3156. /* The number of typestrings. */
  3157. unsigned int typestring_count;
  3158. /* The number of typestring slots we have allocated. */
  3159. unsigned int typestring_alloc;
  3160. };
  3161. static void stab_bad_demangle PARAMS ((const char *));
  3162. static unsigned int stab_demangle_count PARAMS ((const char **));
  3163. static boolean stab_demangle_get_count
  3164. PARAMS ((const char **, unsigned int *));
  3165. static boolean stab_demangle_prefix
  3166. PARAMS ((struct stab_demangle_info *, const char **));
  3167. static boolean stab_demangle_function_name
  3168. PARAMS ((struct stab_demangle_info *, const char **, const char *));
  3169. static boolean stab_demangle_signature
  3170. PARAMS ((struct stab_demangle_info *, const char **));
  3171. static boolean stab_demangle_qualified
  3172. PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
  3173. static boolean stab_demangle_template
  3174. PARAMS ((struct stab_demangle_info *, const char **));
  3175. static boolean stab_demangle_class
  3176. PARAMS ((struct stab_demangle_info *, const char **, const char **));
  3177. static boolean stab_demangle_args
  3178. PARAMS ((struct stab_demangle_info *, const char **, debug_type **,
  3179. boolean *));
  3180. static boolean stab_demangle_arg
  3181. PARAMS ((struct stab_demangle_info *, const char **, debug_type **,
  3182. unsigned int *, unsigned int *));
  3183. static boolean stab_demangle_type
  3184. PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
  3185. static boolean stab_demangle_fund_type
  3186. PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
  3187. static boolean stab_demangle_remember_type
  3188. PARAMS ((struct stab_demangle_info *, const char *, int));
  3189. /* Warn about a bad demangling. */
  3190. static void
  3191. stab_bad_demangle (s)
  3192. const char *s;
  3193. {
  3194. fprintf (stderr, "bad mangled name `%s'\n", s);
  3195. }
  3196. /* Get a count from a stab string. */
  3197. static unsigned int
  3198. stab_demangle_count (pp)
  3199. const char **pp;
  3200. {
  3201. unsigned int count;
  3202. count = 0;
  3203. while (isdigit ((unsigned char) **pp))
  3204. {
  3205. count *= 10;
  3206. count += **pp - '0';
  3207. ++*pp;
  3208. }
  3209. return count;
  3210. }
  3211. /* Require a count in a string. The count may be multiple digits, in
  3212. which case it must end in an underscore. */
  3213. static boolean
  3214. stab_demangle_get_count (pp, pi)
  3215. const char **pp;
  3216. unsigned int *pi;
  3217. {
  3218. if (! isdigit ((unsigned char) **pp))
  3219. return false;
  3220. *pi = **pp - '0';
  3221. ++*pp;
  3222. if (isdigit ((unsigned char) **pp))
  3223. {
  3224. unsigned int count;
  3225. const char *p;
  3226. count = *pi;
  3227. p = *pp;
  3228. do
  3229. {
  3230. count *= 10;
  3231. count += *p - '0';
  3232. ++p;
  3233. }
  3234. while (isdigit ((unsigned char) *p));
  3235. if (*p == '_')
  3236. {
  3237. *pp = p + 1;
  3238. *pi = count;
  3239. }
  3240. }
  3241. return true;
  3242. }
  3243. /* This function demangles a physical name, returning a NULL
  3244. terminated array of argument types. */
  3245. static debug_type *
  3246. stab_demangle_argtypes (dhandle, info, physname, pvarargs)
  3247. PTR dhandle;
  3248. struct stab_handle *info;
  3249. const char *physname;
  3250. boolean *pvarargs;
  3251. {
  3252. struct stab_demangle_info minfo;
  3253. minfo.dhandle = dhandle;
  3254. minfo.info = info;
  3255. minfo.args = NULL;
  3256. minfo.varargs = false;
  3257. minfo.typestring_alloc = 10;
  3258. minfo.typestrings = ((struct stab_demangle_typestring *)
  3259. xmalloc (minfo.typestring_alloc
  3260. * sizeof *minfo.typestrings));
  3261. minfo.typestring_count = 0;
  3262. /* cplus_demangle checks for special GNU mangled forms, but we can't
  3263. see any of them in mangled method argument types. */
  3264. if (! stab_demangle_prefix (&minfo, &physname))
  3265. goto error_return;
  3266. if (*physname != '\0')
  3267. {
  3268. if (! stab_demangle_signature (&minfo, &physname))
  3269. goto error_return;
  3270. }
  3271. free (minfo.typestrings);
  3272. minfo.typestrings = NULL;
  3273. if (minfo.args == NULL)
  3274. fprintf (stderr, "no argument types in mangled string\n");
  3275. *pvarargs = minfo.varargs;
  3276. return minfo.args;
  3277. error_return:
  3278. if (minfo.typestrings != NULL)
  3279. free (minfo.typestrings);
  3280. return NULL;
  3281. }
  3282. /* Demangle the prefix of the mangled name. */
  3283. static boolean
  3284. stab_demangle_prefix (minfo, pp)
  3285. struct stab_demangle_info *minfo;
  3286. const char **pp;
  3287. {
  3288. const char *scan;
  3289. unsigned int i;
  3290. /* cplus_demangle checks for global constructors and destructors,
  3291. but we can't see them in mangled argument types. */
  3292. /* Look for `__'. */
  3293. scan = *pp;
  3294. do
  3295. {
  3296. scan = strchr (scan, '_');
  3297. }
  3298. while (scan != NULL && *++scan != '_');
  3299. if (scan == NULL)
  3300. {
  3301. stab_bad_demangle (*pp);
  3302. return false;
  3303. }
  3304. --scan;
  3305. /* We found `__'; move ahead to the last contiguous `__' pair. */
  3306. i = strspn (scan, "_");
  3307. if (i > 2)
  3308. scan += i - 2;
  3309. if (scan == *pp
  3310. && (isdigit ((unsigned char) scan[2])
  3311. || scan[2] == 'Q'
  3312. || scan[2] == 't'))
  3313. {
  3314. /* This is a GNU style constructor name. */
  3315. *pp = scan + 2;
  3316. return true;
  3317. }
  3318. else if (scan == *pp
  3319. && ! isdigit ((unsigned char) scan[2])
  3320. && scan[2] != 't')
  3321. {
  3322. /* Look for the `__' that separates the prefix from the
  3323. signature. */
  3324. while (*scan == '_')
  3325. ++scan;
  3326. scan = strstr (scan, "__");
  3327. if (scan == NULL || scan[2] == '\0')
  3328. {
  3329. stab_bad_demangle (*pp);
  3330. return false;
  3331. }
  3332. return stab_demangle_function_name (minfo, pp, scan);
  3333. }
  3334. else if (scan[2] != '\0')
  3335. {
  3336. /* The name doesn't start with `__', but it does contain `__'. */
  3337. return stab_demangle_function_name (minfo, pp, scan);
  3338. }
  3339. else
  3340. {
  3341. stab_bad_demangle (*pp);
  3342. return false;
  3343. }
  3344. /*NOTREACHED*/
  3345. }
  3346. /* Demangle a function name prefix. The scan argument points to the
  3347. double underscore which separates the function name from the
  3348. signature. */
  3349. static boolean
  3350. stab_demangle_function_name (minfo, pp, scan)
  3351. struct stab_demangle_info *minfo;
  3352. const char **pp;
  3353. const char *scan;
  3354. {
  3355. const char *name;
  3356. /* The string from *pp to scan is the name of the function. We
  3357. don't care about the name, since we just looking for argument
  3358. types. However, for conversion operators, the name may include a
  3359. type which we must remember in order to handle backreferences. */
  3360. name = *pp;
  3361. *pp = scan + 2;
  3362. if (*pp - name >= 5
  3363. && strncmp (name, "type", 4) == 0
  3364. && (name[4] == '$' || name[4] == '.'))
  3365. {
  3366. const char *tem;
  3367. /* This is a type conversion operator. */
  3368. tem = name + 5;
  3369. if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
  3370. return false;
  3371. }
  3372. else if (name[0] == '_'
  3373. && name[1] == '_'
  3374. && name[2] == 'o'
  3375. && name[3] == 'p')
  3376. {
  3377. const char *tem;
  3378. /* This is a type conversion operator. */
  3379. tem = name + 4;
  3380. if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
  3381. return false;
  3382. }
  3383. return true;
  3384. }
  3385. /* Demangle the signature. This is where the argument types are
  3386. found. */
  3387. static boolean
  3388. stab_demangle_signature (minfo, pp)
  3389. struct stab_demangle_info *minfo;
  3390. const char **pp;
  3391. {
  3392. const char *orig;
  3393. boolean expect_func, func_done;
  3394. const char *hold;
  3395. orig = *pp;
  3396. expect_func = false;
  3397. func_done = false;
  3398. hold = NULL;
  3399. while (**pp != '\0')
  3400. {
  3401. switch (**pp)
  3402. {
  3403. case 'Q':
  3404. hold = *pp;
  3405. if (! stab_demangle_qualified (minfo, pp, (debug_type *) NULL)
  3406. || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
  3407. return false;
  3408. expect_func = true;
  3409. hold = NULL;
  3410. break;
  3411. case 'S':
  3412. /* Static member function. FIXME: Can this happen? */
  3413. if (hold == NULL)
  3414. hold = *pp;
  3415. ++*pp;
  3416. break;
  3417. case 'C':
  3418. /* Const member function. */
  3419. if (hold == NULL)
  3420. hold = *pp;
  3421. ++*pp;
  3422. break;
  3423. case '0': case '1': case '2': case '3': case '4':
  3424. case '5': case '6': case '7': case '8': case '9':
  3425. if (hold == NULL)
  3426. hold = *pp;
  3427. if (! stab_demangle_class (minfo, pp, (const char **) NULL)
  3428. || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
  3429. return false;
  3430. expect_func = true;
  3431. hold = NULL;
  3432. break;
  3433. case 'F':
  3434. /* Function. I don't know if this actually happens with g++
  3435. output. */
  3436. hold = NULL;
  3437. func_done = true;
  3438. ++*pp;
  3439. if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
  3440. return false;
  3441. break;
  3442. case 't':
  3443. /* Template. */
  3444. if (hold == NULL)
  3445. hold = *pp;
  3446. if (! stab_demangle_template (minfo, pp)
  3447. || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
  3448. return false;
  3449. hold = NULL;
  3450. expect_func = true;
  3451. break;
  3452. case '_':
  3453. /* At the outermost level, we cannot have a return type
  3454. specified, so if we run into another '_' at this point we
  3455. are dealing with a mangled name that is either bogus, or
  3456. has been mangled by some algorithm we don't know how to
  3457. deal with. So just reject the entire demangling. */
  3458. stab_bad_demangle (orig);
  3459. return false;
  3460. default:
  3461. /* Assume we have stumbled onto the first outermost function
  3462. argument token, and start processing args. */
  3463. func_done = true;
  3464. if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
  3465. return false;
  3466. break;
  3467. }
  3468. if (expect_func)
  3469. {
  3470. func_done = true;
  3471. if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
  3472. return false;
  3473. }
  3474. }
  3475. if (! func_done)
  3476. {
  3477. /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
  3478. bar__3fooi is 'foo::bar(int)'. We get here when we find the
  3479. first case, and need to ensure that the '(void)' gets added
  3480. to the current declp. */
  3481. if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
  3482. return false;
  3483. }
  3484. return true;
  3485. }
  3486. /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
  3487. mangled form of "Outer::Inner". */
  3488. static boolean
  3489. stab_demangle_qualified (minfo, pp, ptype)
  3490. struct stab_demangle_info *minfo;
  3491. const char **pp;
  3492. debug_type *ptype;
  3493. {
  3494. const char *orig;
  3495. const char *p;
  3496. unsigned int qualifiers;
  3497. debug_type context;
  3498. orig = *pp;
  3499. switch ((*pp)[1])
  3500. {
  3501. case '_':
  3502. /* GNU mangled name with more than 9 classes. The count is
  3503. preceded by an underscore (to distinguish it from the <= 9
  3504. case) and followed by an underscore. */
  3505. p = *pp + 2;
  3506. if (! isdigit ((unsigned char) *p) || *p == '0')
  3507. {
  3508. stab_bad_demangle (orig);
  3509. return false;
  3510. }
  3511. qualifiers = atoi (p);
  3512. while (isdigit ((unsigned char) *p))
  3513. ++p;
  3514. if (*p != '_')
  3515. {
  3516. stab_bad_demangle (orig);
  3517. return false;
  3518. }
  3519. *pp = p + 1;
  3520. break;
  3521. case '1': case '2': case '3': case '4': case '5':
  3522. case '6': case '7': case '8': case '9':
  3523. qualifiers = (*pp)[1] - '0';
  3524. /* Skip an optional underscore after the count. */
  3525. if ((*pp)[2] == '_')
  3526. ++*pp;
  3527. *pp += 2;
  3528. break;
  3529. case '0':
  3530. default:
  3531. stab_bad_demangle (orig);
  3532. return false;
  3533. }
  3534. context = DEBUG_TYPE_NULL;
  3535. /* Pick off the names. */
  3536. while (qualifiers-- > 0)
  3537. {
  3538. if (**pp == '_')
  3539. ++*pp;
  3540. if (**pp == 't')
  3541. {
  3542. /* FIXME: I don't know how to handle the ptype != NULL case
  3543. here. */
  3544. if (! stab_demangle_template (minfo, pp))
  3545. return false;
  3546. }
  3547. else
  3548. {
  3549. unsigned int len;
  3550. len = stab_demangle_count (pp);
  3551. if (strlen (*pp) < len)
  3552. {
  3553. stab_bad_demangle (orig);
  3554. return false;
  3555. }
  3556. if (ptype != NULL)
  3557. {
  3558. const debug_field *fields;
  3559. fields = NULL;
  3560. if (context != DEBUG_TYPE_NULL)
  3561. fields = debug_get_fields (minfo->dhandle, context);
  3562. context = DEBUG_TYPE_NULL;
  3563. if (fields != NULL)
  3564. {
  3565. char *name;
  3566. /* Try to find the type by looking through the
  3567. fields of context until we find a field with the
  3568. same type. This ought to work for a class
  3569. defined within a class, but it won't work for,
  3570. e.g., an enum defined within a class. stabs does
  3571. not give us enough information to figure out the
  3572. latter case. */
  3573. name = savestring (*pp, len);
  3574. for (; *fields != DEBUG_FIELD_NULL; fields++)
  3575. {
  3576. debug_type ft;
  3577. const char *dn;
  3578. ft = debug_get_field_type (minfo->dhandle, *fields);
  3579. if (ft == NULL)
  3580. return false;
  3581. dn = debug_get_type_name (minfo->dhandle, ft);
  3582. if (dn != NULL && strcmp (dn, name) == 0)
  3583. {
  3584. context = ft;
  3585. break;
  3586. }
  3587. }
  3588. free (name);
  3589. }
  3590. if (context == DEBUG_TYPE_NULL)
  3591. {
  3592. /* We have to fall back on finding the type by name.
  3593. If there are more types to come, then this must
  3594. be a class. Otherwise, it could be anything. */
  3595. if (qualifiers == 0)
  3596. {
  3597. char *name;
  3598. name = savestring (*pp, len);
  3599. context = debug_find_named_type (minfo->dhandle,
  3600. name);
  3601. free (name);
  3602. }
  3603. if (context == DEBUG_TYPE_NULL)
  3604. {
  3605. context = stab_find_tagged_type (minfo->dhandle,
  3606. minfo->info,
  3607. *pp, len,
  3608. (qualifiers == 0
  3609. ? DEBUG_KIND_ILLEGAL
  3610. : DEBUG_KIND_CLASS));
  3611. if (context == DEBUG_TYPE_NULL)
  3612. return false;
  3613. }
  3614. }
  3615. }
  3616. *pp += len;
  3617. }
  3618. }
  3619. if (ptype != NULL)
  3620. *ptype = context;
  3621. return true;
  3622. }
  3623. /* Demangle a template. */
  3624. static boolean
  3625. stab_demangle_template (minfo, pp)
  3626. struct stab_demangle_info *minfo;
  3627. const char **pp;
  3628. {
  3629. const char *orig;
  3630. unsigned int r, i;
  3631. orig = *pp;
  3632. ++*pp;
  3633. /* Skip the template name. */
  3634. r = stab_demangle_count (pp);
  3635. if (r == 0 || strlen (*pp) < r)
  3636. {
  3637. stab_bad_demangle (orig);
  3638. return false;
  3639. }
  3640. *pp += r;
  3641. /* Get the size of the parameter list. */
  3642. if (stab_demangle_get_count (pp, &r) == 0)
  3643. {
  3644. stab_bad_demangle (orig);
  3645. return false;
  3646. }
  3647. for (i = 0; i < r; i++)
  3648. {
  3649. if (**pp == 'Z')
  3650. {
  3651. /* This is a type parameter. */
  3652. ++*pp;
  3653. if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
  3654. return false;
  3655. }
  3656. else
  3657. {
  3658. const char *old_p;
  3659. boolean pointerp, realp, integralp, charp, boolp;
  3660. boolean done;
  3661. old_p = *pp;
  3662. pointerp = false;
  3663. realp = false;
  3664. integralp = false;
  3665. charp = false;
  3666. boolp = false;
  3667. done = false;
  3668. /* This is a value parameter. */
  3669. if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
  3670. return false;
  3671. while (*old_p != '\0' && ! done)
  3672. {
  3673. switch (*old_p)
  3674. {
  3675. case 'P':
  3676. case 'p':
  3677. case 'R':
  3678. pointerp = true;
  3679. done = true;
  3680. break;
  3681. case 'C': /* Const. */
  3682. case 'S': /* Signed. */
  3683. case 'U': /* Unsigned. */
  3684. case 'V': /* Volatile. */
  3685. case 'F': /* Function. */
  3686. case 'M': /* Member function. */
  3687. case 'O': /* ??? */
  3688. ++old_p;
  3689. break;
  3690. case 'Q': /* Qualified name. */
  3691. integralp = true;
  3692. done = true;
  3693. break;
  3694. case 'T': /* Remembered type. */
  3695. abort ();
  3696. case 'v': /* Void. */
  3697. abort ();
  3698. case 'x': /* Long long. */
  3699. case 'l': /* Long. */
  3700. case 'i': /* Int. */
  3701. case 's': /* Short. */
  3702. case 'w': /* Wchar_t. */
  3703. integralp = true;
  3704. done = true;
  3705. break;
  3706. case 'b': /* Bool. */
  3707. boolp = true;
  3708. done = true;
  3709. break;
  3710. case 'c': /* Char. */
  3711. charp = true;
  3712. done = true;
  3713. break;
  3714. case 'r': /* Long double. */
  3715. case 'd': /* Double. */
  3716. case 'f': /* Float. */
  3717. realp = true;
  3718. done = true;
  3719. break;
  3720. default:
  3721. /* Assume it's a user defined integral type. */
  3722. integralp = true;
  3723. done = true;
  3724. break;
  3725. }
  3726. }
  3727. if (integralp)
  3728. {
  3729. if (**pp == 'm')
  3730. ++*pp;
  3731. while (isdigit ((unsigned char) **pp))
  3732. ++*pp;
  3733. }
  3734. else if (charp)
  3735. {
  3736. unsigned int val;
  3737. if (**pp == 'm')
  3738. ++*pp;
  3739. val = stab_demangle_count (pp);
  3740. if (val == 0)
  3741. {
  3742. stab_bad_demangle (orig);
  3743. return false;
  3744. }
  3745. }
  3746. else if (boolp)
  3747. {
  3748. unsigned int val;
  3749. val = stab_demangle_count (pp);
  3750. if (val != 0 && val != 1)
  3751. {
  3752. stab_bad_demangle (orig);
  3753. return false;
  3754. }
  3755. }
  3756. else if (realp)
  3757. {
  3758. if (**pp == 'm')
  3759. ++*pp;
  3760. while (isdigit ((unsigned char) **pp))
  3761. ++*pp;
  3762. if (**pp == '.')
  3763. {
  3764. ++*pp;
  3765. while (isdigit ((unsigned char) **pp))
  3766. ++*pp;
  3767. }
  3768. if (**pp == 'e')
  3769. {
  3770. ++*pp;
  3771. while (isdigit ((unsigned char) **pp))
  3772. ++*pp;
  3773. }
  3774. }
  3775. else if (pointerp)
  3776. {
  3777. unsigned int len;
  3778. if (! stab_demangle_get_count (pp, &len))
  3779. {
  3780. stab_bad_demangle (orig);
  3781. return false;
  3782. }
  3783. *pp += len;
  3784. }
  3785. }
  3786. }
  3787. return true;
  3788. }
  3789. /* Demangle a class name. */
  3790. static boolean
  3791. stab_demangle_class (minfo, pp, pstart)
  3792. struct stab_demangle_info *minfo;
  3793. const char **pp;
  3794. const char **pstart;
  3795. {
  3796. const char *orig;
  3797. unsigned int n;
  3798. orig = *pp;
  3799. n = stab_demangle_count (pp);
  3800. if (strlen (*pp) < n)
  3801. {
  3802. stab_bad_demangle (orig);
  3803. return false;
  3804. }
  3805. if (pstart != NULL)
  3806. *pstart = *pp;
  3807. *pp += n;
  3808. return true;
  3809. }
  3810. /* Demangle function arguments. If the pargs argument is not NULL, it
  3811. is set to a NULL terminated array holding the arguments. */
  3812. static boolean
  3813. stab_demangle_args (minfo, pp, pargs, pvarargs)
  3814. struct stab_demangle_info *minfo;
  3815. const char **pp;
  3816. debug_type **pargs;
  3817. boolean *pvarargs;
  3818. {
  3819. const char *orig;
  3820. unsigned int alloc, count;
  3821. orig = *pp;
  3822. alloc = 10;
  3823. if (pargs != NULL)
  3824. {
  3825. *pargs = (debug_type *) xmalloc (alloc * sizeof **pargs);
  3826. *pvarargs = false;
  3827. }
  3828. count = 0;
  3829. while (**pp != '_' && **pp != '\0' && **pp != 'e')
  3830. {
  3831. if (**pp == 'N' || **pp == 'T')
  3832. {
  3833. char temptype;
  3834. unsigned int r, t;
  3835. temptype = **pp;
  3836. ++*pp;
  3837. if (temptype == 'T')
  3838. r = 1;
  3839. else
  3840. {
  3841. if (! stab_demangle_get_count (pp, &r))
  3842. {
  3843. stab_bad_demangle (orig);
  3844. return false;
  3845. }
  3846. }
  3847. if (! stab_demangle_get_count (pp, &t))
  3848. {
  3849. stab_bad_demangle (orig);
  3850. return false;
  3851. }
  3852. if (t >= minfo->typestring_count)
  3853. {
  3854. stab_bad_demangle (orig);
  3855. return false;
  3856. }
  3857. while (r-- > 0)
  3858. {
  3859. const char *tem;
  3860. tem = minfo->typestrings[t].typestring;
  3861. if (! stab_demangle_arg (minfo, &tem, pargs, &count, &alloc))
  3862. return false;
  3863. }
  3864. }
  3865. else
  3866. {
  3867. if (! stab_demangle_arg (minfo, pp, pargs, &count, &alloc))
  3868. return false;
  3869. }
  3870. }
  3871. if (pargs != NULL)
  3872. (*pargs)[count] = DEBUG_TYPE_NULL;
  3873. if (**pp == 'e')
  3874. {
  3875. if (pargs != NULL)
  3876. *pvarargs = true;
  3877. ++*pp;
  3878. }
  3879. return true;
  3880. }
  3881. /* Demangle a single argument. */
  3882. static boolean
  3883. stab_demangle_arg (minfo, pp, pargs, pcount, palloc)
  3884. struct stab_demangle_info *minfo;
  3885. const char **pp;
  3886. debug_type **pargs;
  3887. unsigned int *pcount;
  3888. unsigned int *palloc;
  3889. {
  3890. const char *start;
  3891. debug_type type;
  3892. start = *pp;
  3893. if (! stab_demangle_type (minfo, pp,
  3894. pargs == NULL ? (debug_type *) NULL : &type)
  3895. || ! stab_demangle_remember_type (minfo, start, *pp - start))
  3896. return false;
  3897. if (pargs != NULL)
  3898. {
  3899. if (type == DEBUG_TYPE_NULL)
  3900. return false;
  3901. if (*pcount + 1 >= *palloc)
  3902. {
  3903. *palloc += 10;
  3904. *pargs = ((debug_type *)
  3905. xrealloc (*pargs, *palloc * sizeof **pargs));
  3906. }
  3907. (*pargs)[*pcount] = type;
  3908. ++*pcount;
  3909. }
  3910. return true;
  3911. }
  3912. /* Demangle a type. If the ptype argument is not NULL, *ptype is set
  3913. to the newly allocated type. */
  3914. static boolean
  3915. stab_demangle_type (minfo, pp, ptype)
  3916. struct stab_demangle_info *minfo;
  3917. const char **pp;
  3918. debug_type *ptype;
  3919. {
  3920. const char *orig;
  3921. orig = *pp;
  3922. switch (**pp)
  3923. {
  3924. case 'P':
  3925. case 'p':
  3926. /* A pointer type. */
  3927. ++*pp;
  3928. if (! stab_demangle_type (minfo, pp, ptype))
  3929. return false;
  3930. if (ptype != NULL)
  3931. *ptype = debug_make_pointer_type (minfo->dhandle, *ptype);
  3932. break;
  3933. case 'R':
  3934. /* A reference type. */
  3935. ++*pp;
  3936. if (! stab_demangle_type (minfo, pp, ptype))
  3937. return false;
  3938. if (ptype != NULL)
  3939. *ptype = debug_make_reference_type (minfo->dhandle, *ptype);
  3940. break;
  3941. case 'A':
  3942. /* An array. */
  3943. {
  3944. unsigned long high;
  3945. ++*pp;
  3946. high = 0;
  3947. while (**pp != '\0' && **pp != '_')
  3948. {
  3949. if (! isdigit ((unsigned char) **pp))
  3950. {
  3951. stab_bad_demangle (orig);
  3952. return false;
  3953. }
  3954. high *= 10;
  3955. high += **pp - '0';
  3956. ++*pp;
  3957. }
  3958. if (**pp != '_')
  3959. {
  3960. stab_bad_demangle (orig);
  3961. return false;
  3962. }
  3963. ++*pp;
  3964. if (! stab_demangle_type (minfo, pp, ptype))
  3965. return false;
  3966. if (ptype != NULL)
  3967. {
  3968. debug_type int_type;
  3969. int_type = debug_find_named_type (minfo->dhandle, "int");
  3970. if (int_type == NULL)
  3971. int_type = debug_make_int_type (minfo->dhandle, 4, false);
  3972. *ptype = debug_make_array_type (minfo->dhandle, *ptype, int_type,
  3973. 0, high, false);
  3974. }
  3975. }
  3976. break;
  3977. case 'T':
  3978. /* A back reference to a remembered type. */
  3979. {
  3980. unsigned int i;
  3981. const char *p;
  3982. ++*pp;
  3983. if (! stab_demangle_get_count (pp, &i))
  3984. {
  3985. stab_bad_demangle (orig);
  3986. return false;
  3987. }
  3988. if (i >= minfo->typestring_count)
  3989. {
  3990. stab_bad_demangle (orig);
  3991. return false;
  3992. }
  3993. p = minfo->typestrings[i].typestring;
  3994. if (! stab_demangle_type (minfo, &p, ptype))
  3995. return false;
  3996. }
  3997. break;
  3998. case 'F':
  3999. /* A function. */
  4000. {
  4001. debug_type *args;
  4002. boolean varargs;
  4003. ++*pp;
  4004. if (! stab_demangle_args (minfo, pp,
  4005. (ptype == NULL
  4006. ? (debug_type **) NULL
  4007. : &args),
  4008. (ptype == NULL
  4009. ? (boolean *) NULL
  4010. : &varargs)))
  4011. return false;
  4012. if (**pp != '_')
  4013. {
  4014. /* cplus_demangle will accept a function without a return
  4015. type, but I don't know when that will happen, or what
  4016. to do if it does. */
  4017. stab_bad_demangle (orig);
  4018. return false;
  4019. }
  4020. ++*pp;
  4021. if (! stab_demangle_type (minfo, pp, ptype))
  4022. return false;
  4023. if (ptype != NULL)
  4024. *ptype = debug_make_function_type (minfo->dhandle, *ptype, args,
  4025. varargs);
  4026. }
  4027. break;
  4028. case 'M':
  4029. case 'O':
  4030. {
  4031. boolean memberp, constp, volatilep;
  4032. debug_type *args;
  4033. boolean varargs;
  4034. unsigned int n;
  4035. const char *name;
  4036. memberp = **pp == 'M';
  4037. constp = false;
  4038. volatilep = false;
  4039. args = NULL;
  4040. varargs = false;
  4041. ++*pp;
  4042. if (! isdigit ((unsigned char) **pp))
  4043. {
  4044. stab_bad_demangle (orig);
  4045. return false;
  4046. }
  4047. n = stab_demangle_count (pp);
  4048. if (strlen (*pp) < n)
  4049. {
  4050. stab_bad_demangle (orig);
  4051. return false;
  4052. }
  4053. name = *pp;
  4054. *pp += n;
  4055. if (memberp)
  4056. {
  4057. if (**pp == 'C')
  4058. {
  4059. constp = true;
  4060. ++*pp;
  4061. }
  4062. else if (**pp == 'V')
  4063. {
  4064. volatilep = true;
  4065. ++*pp;
  4066. }
  4067. if (**pp != 'F')
  4068. {
  4069. stab_bad_demangle (orig);
  4070. return false;
  4071. }
  4072. ++*pp;
  4073. if (! stab_demangle_args (minfo, pp,
  4074. (ptype == NULL
  4075. ? (debug_type **) NULL
  4076. : &args),
  4077. (ptype == NULL
  4078. ? (boolean *) NULL
  4079. : &varargs)))
  4080. return false;
  4081. }
  4082. if (**pp != '_')
  4083. {
  4084. stab_bad_demangle (orig);
  4085. return false;
  4086. }
  4087. ++*pp;
  4088. if (! stab_demangle_type (minfo, pp, ptype))
  4089. return false;
  4090. if (ptype != NULL)
  4091. {
  4092. debug_type class_type;
  4093. class_type = stab_find_tagged_type (minfo->dhandle, minfo->info,
  4094. name, (int) n,
  4095. DEBUG_KIND_CLASS);
  4096. if (class_type == DEBUG_TYPE_NULL)
  4097. return false;
  4098. if (! memberp)
  4099. *ptype = debug_make_offset_type (minfo->dhandle, class_type,
  4100. *ptype);
  4101. else
  4102. {
  4103. /* FIXME: We have no way to record constp or
  4104. volatilep. */
  4105. *ptype = debug_make_method_type (minfo->dhandle, *ptype,
  4106. class_type, args, varargs);
  4107. }
  4108. }
  4109. }
  4110. break;
  4111. case 'G':
  4112. ++*pp;
  4113. if (! stab_demangle_type (minfo, pp, ptype))
  4114. return false;
  4115. break;
  4116. case 'C':
  4117. ++*pp;
  4118. if (! stab_demangle_type (minfo, pp, ptype))
  4119. return false;
  4120. if (ptype != NULL)
  4121. *ptype = debug_make_const_type (minfo->dhandle, *ptype);
  4122. break;
  4123. case 'Q':
  4124. {
  4125. const char *hold;
  4126. hold = *pp;
  4127. if (! stab_demangle_qualified (minfo, pp, ptype))
  4128. return false;
  4129. }
  4130. break;
  4131. default:
  4132. if (! stab_demangle_fund_type (minfo, pp, ptype))
  4133. return false;
  4134. break;
  4135. }
  4136. return true;
  4137. }
  4138. /* Demangle a fundamental type. If the ptype argument is not NULL,
  4139. *ptype is set to the newly allocated type. */
  4140. static boolean
  4141. stab_demangle_fund_type (minfo, pp, ptype)
  4142. struct stab_demangle_info *minfo;
  4143. const char **pp;
  4144. debug_type *ptype;
  4145. {
  4146. const char *orig;
  4147. boolean constp, volatilep, unsignedp, signedp;
  4148. boolean done;
  4149. orig = *pp;
  4150. constp = false;
  4151. volatilep = false;
  4152. unsignedp = false;
  4153. signedp = false;
  4154. done = false;
  4155. while (! done)
  4156. {
  4157. switch (**pp)
  4158. {
  4159. case 'C':
  4160. constp = true;
  4161. ++*pp;
  4162. break;
  4163. case 'U':
  4164. unsignedp = true;
  4165. ++*pp;
  4166. break;
  4167. case 'S':
  4168. signedp = true;
  4169. ++*pp;
  4170. break;
  4171. case 'V':
  4172. volatilep = true;
  4173. ++*pp;
  4174. break;
  4175. default:
  4176. done = true;
  4177. break;
  4178. }
  4179. }
  4180. switch (**pp)
  4181. {
  4182. case '\0':
  4183. case '_':
  4184. /* cplus_demangle permits this, but I don't know what it means. */
  4185. stab_bad_demangle (orig);
  4186. break;
  4187. case 'v': /* void */
  4188. if (ptype != NULL)
  4189. {
  4190. *ptype = debug_find_named_type (minfo->dhandle, "void");
  4191. if (*ptype == DEBUG_TYPE_NULL)
  4192. *ptype = debug_make_void_type (minfo->dhandle);
  4193. }
  4194. ++*pp;
  4195. break;
  4196. case 'x': /* long long */
  4197. if (ptype != NULL)
  4198. {
  4199. *ptype = debug_find_named_type (minfo->dhandle,
  4200. (unsignedp
  4201. ? "long long unsigned int"
  4202. : "long long int"));
  4203. if (*ptype == DEBUG_TYPE_NULL)
  4204. *ptype = debug_make_int_type (minfo->dhandle, 8, unsignedp);
  4205. }
  4206. ++*pp;
  4207. break;
  4208. case 'l': /* long */
  4209. if (ptype != NULL)
  4210. {
  4211. *ptype = debug_find_named_type (minfo->dhandle,
  4212. (unsignedp
  4213. ? "long unsigned int"
  4214. : "long int"));
  4215. if (*ptype == DEBUG_TYPE_NULL)
  4216. *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
  4217. }
  4218. ++*pp;
  4219. break;
  4220. case 'i': /* int */
  4221. if (ptype != NULL)
  4222. {
  4223. *ptype = debug_find_named_type (minfo->dhandle,
  4224. (unsignedp
  4225. ? "unsigned int"
  4226. : "int"));
  4227. if (*ptype == DEBUG_TYPE_NULL)
  4228. *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
  4229. }
  4230. ++*pp;
  4231. break;
  4232. case 's': /* short */
  4233. if (ptype != NULL)
  4234. {
  4235. *ptype = debug_find_named_type (minfo->dhandle,
  4236. (unsignedp
  4237. ? "short unsigned int"
  4238. : "short int"));
  4239. if (*ptype == DEBUG_TYPE_NULL)
  4240. *ptype = debug_make_int_type (minfo->dhandle, 2, unsignedp);
  4241. }
  4242. ++*pp;
  4243. break;
  4244. case 'b': /* bool */
  4245. if (ptype != NULL)
  4246. {
  4247. *ptype = debug_find_named_type (minfo->dhandle, "bool");
  4248. if (*ptype == DEBUG_TYPE_NULL)
  4249. *ptype = debug_make_bool_type (minfo->dhandle, 4);
  4250. }
  4251. ++*pp;
  4252. break;
  4253. case 'c': /* char */
  4254. if (ptype != NULL)
  4255. {
  4256. *ptype = debug_find_named_type (minfo->dhandle,
  4257. (unsignedp
  4258. ? "unsigned char"
  4259. : (signedp
  4260. ? "signed char"
  4261. : "char")));
  4262. if (*ptype == DEBUG_TYPE_NULL)
  4263. *ptype = debug_make_int_type (minfo->dhandle, 1, unsignedp);
  4264. }
  4265. ++*pp;
  4266. break;
  4267. case 'w': /* wchar_t */
  4268. if (ptype != NULL)
  4269. {
  4270. *ptype = debug_find_named_type (minfo->dhandle, "__wchar_t");
  4271. if (*ptype == DEBUG_TYPE_NULL)
  4272. *ptype = debug_make_int_type (minfo->dhandle, 2, true);
  4273. }
  4274. ++*pp;
  4275. break;
  4276. case 'r': /* long double */
  4277. if (ptype != NULL)
  4278. {
  4279. *ptype = debug_find_named_type (minfo->dhandle, "long double");
  4280. if (*ptype == DEBUG_TYPE_NULL)
  4281. *ptype = debug_make_float_type (minfo->dhandle, 8);
  4282. }
  4283. ++*pp;
  4284. break;
  4285. case 'd': /* double */
  4286. if (ptype != NULL)
  4287. {
  4288. *ptype = debug_find_named_type (minfo->dhandle, "double");
  4289. if (*ptype == DEBUG_TYPE_NULL)
  4290. *ptype = debug_make_float_type (minfo->dhandle, 8);
  4291. }
  4292. ++*pp;
  4293. break;
  4294. case 'f': /* float */
  4295. if (ptype != NULL)
  4296. {
  4297. *ptype = debug_find_named_type (minfo->dhandle, "float");
  4298. if (*ptype == DEBUG_TYPE_NULL)
  4299. *ptype = debug_make_float_type (minfo->dhandle, 4);
  4300. }
  4301. ++*pp;
  4302. break;
  4303. case 'G':
  4304. ++*pp;
  4305. if (! isdigit ((unsigned char) **pp))
  4306. {
  4307. stab_bad_demangle (orig);
  4308. return false;
  4309. }
  4310. /* Fall through. */
  4311. case '0': case '1': case '2': case '3': case '4':
  4312. case '5': case '6': case '7': case '8': case '9':
  4313. {
  4314. const char *hold;
  4315. if (! stab_demangle_class (minfo, pp, &hold))
  4316. return false;
  4317. if (ptype != NULL)
  4318. {
  4319. char *name;
  4320. name = savestring (hold, *pp - hold);
  4321. *ptype = debug_find_named_type (minfo->dhandle, name);
  4322. if (*ptype == DEBUG_TYPE_NULL)
  4323. {
  4324. /* FIXME: It is probably incorrect to assume that
  4325. undefined types are tagged types. */
  4326. *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
  4327. hold, *pp - hold,
  4328. DEBUG_KIND_ILLEGAL);
  4329. }
  4330. free (name);
  4331. }
  4332. }
  4333. break;
  4334. case 't':
  4335. if (! stab_demangle_template (minfo, pp))
  4336. return false;
  4337. if (ptype != NULL)
  4338. {
  4339. debug_type t;
  4340. /* FIXME: I really don't know how a template should be
  4341. represented in the current type system. Perhaps the
  4342. template should be demangled into a string, and the type
  4343. should be represented as a named type. However, I don't
  4344. know what the base type of the named type should be. */
  4345. t = debug_make_void_type (minfo->dhandle);
  4346. t = debug_make_pointer_type (minfo->dhandle, t);
  4347. t = debug_name_type (minfo->dhandle, "TEMPLATE", t);
  4348. *ptype = t;
  4349. }
  4350. break;
  4351. default:
  4352. stab_bad_demangle (orig);
  4353. return false;
  4354. }
  4355. if (ptype != NULL)
  4356. {
  4357. if (constp)
  4358. *ptype = debug_make_const_type (minfo->dhandle, *ptype);
  4359. if (volatilep)
  4360. *ptype = debug_make_volatile_type (minfo->dhandle, *ptype);
  4361. }
  4362. return true;
  4363. }
  4364. /* Remember a type string in a demangled string. */
  4365. static boolean
  4366. stab_demangle_remember_type (minfo, p, len)
  4367. struct stab_demangle_info *minfo;
  4368. const char *p;
  4369. int len;
  4370. {
  4371. if (minfo->typestring_count >= minfo->typestring_alloc)
  4372. {
  4373. minfo->typestring_alloc += 10;
  4374. minfo->typestrings = ((struct stab_demangle_typestring *)
  4375. xrealloc (minfo->typestrings,
  4376. (minfo->typestring_alloc
  4377. * sizeof *minfo->typestrings)));
  4378. }
  4379. minfo->typestrings[minfo->typestring_count].typestring = p;
  4380. minfo->typestrings[minfo->typestring_count].len = (unsigned int) len;
  4381. ++minfo->typestring_count;
  4382. return true;
  4383. }