rdcoff.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. /* stabs.c -- Parse COFF debugging information
  2. Copyright (C) 1996-2022 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 3 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., 51 Franklin Street - Fifth Floor, Boston, MA
  16. 02110-1301, USA. */
  17. /* This file contains code which parses COFF debugging information. */
  18. #include "sysdep.h"
  19. #include "bfd.h"
  20. #include "coff/internal.h"
  21. #include "libiberty.h"
  22. #include "bucomm.h"
  23. #include "debug.h"
  24. #include "budbg.h"
  25. /* FIXME: We should not need this BFD internal file. We need it for
  26. the N_BTMASK, etc., values. */
  27. #include "libcoff.h"
  28. /* These macros extract the right mask and shifts for this BFD. They
  29. assume that there is a local variable named ABFD. This is so that
  30. macros like ISFCN and DECREF, from coff/internal.h, will work
  31. without modification. */
  32. #define N_BTMASK (coff_data (abfd)->local_n_btmask)
  33. #define N_BTSHFT (coff_data (abfd)->local_n_btshft)
  34. #define N_TMASK (coff_data (abfd)->local_n_tmask)
  35. #define N_TSHIFT (coff_data (abfd)->local_n_tshift)
  36. /* This structure is used to hold the symbols, as well as the current
  37. location within the symbols. */
  38. struct coff_symbols
  39. {
  40. /* The symbols. */
  41. asymbol **syms;
  42. /* The number of symbols. */
  43. long symcount;
  44. /* The index of the current symbol. */
  45. long symno;
  46. /* The index of the current symbol in the COFF symbol table (where
  47. each auxent counts as a symbol). */
  48. long coff_symno;
  49. };
  50. /* The largest basic type we are prepared to handle. */
  51. #define T_MAX (T_LNGDBL)
  52. /* This structure is used to hold slots. */
  53. struct coff_slots
  54. {
  55. /* Next set of slots. */
  56. struct coff_slots *next;
  57. /* Slots. */
  58. #define COFF_SLOTS (16)
  59. debug_type slots[COFF_SLOTS];
  60. };
  61. /* This structure is used to map symbol indices to types. */
  62. struct coff_types
  63. {
  64. /* Slots. */
  65. struct coff_slots *slots;
  66. /* Basic types. */
  67. debug_type basic[T_MAX + 1];
  68. };
  69. static debug_type *coff_get_slot (struct coff_types *, long);
  70. static debug_type parse_coff_type
  71. (bfd *, struct coff_symbols *, struct coff_types *, long, int,
  72. union internal_auxent *, bool, void *);
  73. static debug_type parse_coff_base_type
  74. (bfd *, struct coff_symbols *, struct coff_types *, long, int,
  75. union internal_auxent *, void *);
  76. static debug_type parse_coff_struct_type
  77. (bfd *, struct coff_symbols *, struct coff_types *, int,
  78. union internal_auxent *, void *);
  79. static debug_type parse_coff_enum_type
  80. (bfd *, struct coff_symbols *, struct coff_types *,
  81. union internal_auxent *, void *);
  82. static bool parse_coff_symbol
  83. (bfd *, struct coff_types *, asymbol *, long, struct internal_syment *,
  84. void *, debug_type, bool);
  85. static bool external_coff_symbol_p (int sym_class);
  86. /* Return the slot for a type. */
  87. static debug_type *
  88. coff_get_slot (struct coff_types *types, long indx)
  89. {
  90. struct coff_slots **pps;
  91. pps = &types->slots;
  92. /* PR 17512: file: 078-18333-0.001:0.1.
  93. FIXME: The value of 1000 is a guess. Maybe a better heuristic is needed. */
  94. if (indx / COFF_SLOTS > 1000)
  95. fatal (_("Excessively large slot index: %lx"), indx);
  96. while (indx >= COFF_SLOTS)
  97. {
  98. if (*pps == NULL)
  99. {
  100. *pps = (struct coff_slots *) xmalloc (sizeof **pps);
  101. memset (*pps, 0, sizeof **pps);
  102. }
  103. pps = &(*pps)->next;
  104. indx -= COFF_SLOTS;
  105. }
  106. if (*pps == NULL)
  107. {
  108. *pps = (struct coff_slots *) xmalloc (sizeof **pps);
  109. memset (*pps, 0, sizeof **pps);
  110. }
  111. return (*pps)->slots + indx;
  112. }
  113. /* Parse a COFF type code in NTYPE. */
  114. static debug_type
  115. parse_coff_type (bfd *abfd, struct coff_symbols *symbols,
  116. struct coff_types *types, long coff_symno, int ntype,
  117. union internal_auxent *pauxent, bool useaux,
  118. void *dhandle)
  119. {
  120. debug_type type;
  121. if ((ntype & ~N_BTMASK) != 0)
  122. {
  123. int newtype;
  124. newtype = DECREF (ntype);
  125. if (ISPTR (ntype))
  126. {
  127. type = parse_coff_type (abfd, symbols, types, coff_symno, newtype,
  128. pauxent, useaux, dhandle);
  129. type = debug_make_pointer_type (dhandle, type);
  130. }
  131. else if (ISFCN (ntype))
  132. {
  133. type = parse_coff_type (abfd, symbols, types, coff_symno, newtype,
  134. pauxent, useaux, dhandle);
  135. type = debug_make_function_type (dhandle, type, (debug_type *) NULL,
  136. false);
  137. }
  138. else if (ISARY (ntype))
  139. {
  140. int n;
  141. if (pauxent == NULL)
  142. n = 0;
  143. else
  144. {
  145. unsigned short *dim;
  146. int i;
  147. /* FIXME: If pauxent->x_sym.x_tagndx.l == 0, gdb sets
  148. the c_naux field of the syment to 0. */
  149. /* Move the dimensions down, so that the next array
  150. picks up the next one. */
  151. dim = pauxent->x_sym.x_fcnary.x_ary.x_dimen;
  152. n = dim[0];
  153. for (i = 0; *dim != 0 && i < DIMNUM - 1; i++, dim++)
  154. *dim = *(dim + 1);
  155. *dim = 0;
  156. }
  157. type = parse_coff_type (abfd, symbols, types, coff_symno, newtype,
  158. pauxent, false, dhandle);
  159. type = debug_make_array_type (dhandle, type,
  160. parse_coff_base_type (abfd, symbols,
  161. types,
  162. coff_symno,
  163. T_INT,
  164. NULL, dhandle),
  165. 0, n - 1, false);
  166. }
  167. else
  168. {
  169. non_fatal (_("parse_coff_type: Bad type code 0x%x"), ntype);
  170. return DEBUG_TYPE_NULL;
  171. }
  172. return type;
  173. }
  174. if (pauxent != NULL && pauxent->x_sym.x_tagndx.l > 0)
  175. {
  176. debug_type *slot;
  177. /* This is a reference to an existing type. FIXME: gdb checks
  178. that the class is not C_STRTAG, nor C_UNTAG, nor C_ENTAG. */
  179. slot = coff_get_slot (types, pauxent->x_sym.x_tagndx.l);
  180. if (*slot != DEBUG_TYPE_NULL)
  181. return *slot;
  182. else
  183. return debug_make_indirect_type (dhandle, slot, (const char *) NULL);
  184. }
  185. /* If the aux entry has already been used for something, useaux will
  186. have been set to false, indicating that parse_coff_base_type
  187. should not use it. We need to do it this way, rather than simply
  188. passing pauxent as NULL, because we need to be able handle
  189. multiple array dimensions while still discarding pauxent after
  190. having handled all of them. */
  191. if (! useaux)
  192. pauxent = NULL;
  193. return parse_coff_base_type (abfd, symbols, types, coff_symno, ntype,
  194. pauxent, dhandle);
  195. }
  196. /* Parse a basic COFF type in NTYPE. */
  197. static debug_type
  198. parse_coff_base_type (bfd *abfd, struct coff_symbols *symbols,
  199. struct coff_types *types, long coff_symno, int ntype,
  200. union internal_auxent *pauxent, void *dhandle)
  201. {
  202. debug_type ret;
  203. bool set_basic;
  204. const char *name;
  205. debug_type *slot;
  206. if (ntype >= 0
  207. && ntype <= T_MAX
  208. && types->basic[ntype] != DEBUG_TYPE_NULL)
  209. return types->basic[ntype];
  210. set_basic = true;
  211. name = NULL;
  212. switch (ntype)
  213. {
  214. default:
  215. ret = debug_make_void_type (dhandle);
  216. break;
  217. case T_NULL:
  218. case T_VOID:
  219. ret = debug_make_void_type (dhandle);
  220. name = "void";
  221. break;
  222. case T_CHAR:
  223. ret = debug_make_int_type (dhandle, 1, false);
  224. name = "char";
  225. break;
  226. case T_SHORT:
  227. ret = debug_make_int_type (dhandle, 2, false);
  228. name = "short";
  229. break;
  230. case T_INT:
  231. /* FIXME: Perhaps the size should depend upon the architecture. */
  232. ret = debug_make_int_type (dhandle, 4, false);
  233. name = "int";
  234. break;
  235. case T_LONG:
  236. ret = debug_make_int_type (dhandle, 4, false);
  237. name = "long";
  238. break;
  239. case T_FLOAT:
  240. ret = debug_make_float_type (dhandle, 4);
  241. name = "float";
  242. break;
  243. case T_DOUBLE:
  244. ret = debug_make_float_type (dhandle, 8);
  245. name = "double";
  246. break;
  247. case T_LNGDBL:
  248. ret = debug_make_float_type (dhandle, 12);
  249. name = "long double";
  250. break;
  251. case T_UCHAR:
  252. ret = debug_make_int_type (dhandle, 1, true);
  253. name = "unsigned char";
  254. break;
  255. case T_USHORT:
  256. ret = debug_make_int_type (dhandle, 2, true);
  257. name = "unsigned short";
  258. break;
  259. case T_UINT:
  260. ret = debug_make_int_type (dhandle, 4, true);
  261. name = "unsigned int";
  262. break;
  263. case T_ULONG:
  264. ret = debug_make_int_type (dhandle, 4, true);
  265. name = "unsigned long";
  266. break;
  267. case T_STRUCT:
  268. if (pauxent == NULL)
  269. ret = debug_make_struct_type (dhandle, true, 0,
  270. (debug_field *) NULL);
  271. else
  272. ret = parse_coff_struct_type (abfd, symbols, types, ntype, pauxent,
  273. dhandle);
  274. slot = coff_get_slot (types, coff_symno);
  275. *slot = ret;
  276. set_basic = false;
  277. break;
  278. case T_UNION:
  279. if (pauxent == NULL)
  280. ret = debug_make_struct_type (dhandle, false, 0, (debug_field *) NULL);
  281. else
  282. ret = parse_coff_struct_type (abfd, symbols, types, ntype, pauxent,
  283. dhandle);
  284. slot = coff_get_slot (types, coff_symno);
  285. *slot = ret;
  286. set_basic = false;
  287. break;
  288. case T_ENUM:
  289. if (pauxent == NULL)
  290. ret = debug_make_enum_type (dhandle, (const char **) NULL,
  291. (bfd_signed_vma *) NULL);
  292. else
  293. ret = parse_coff_enum_type (abfd, symbols, types, pauxent, dhandle);
  294. slot = coff_get_slot (types, coff_symno);
  295. *slot = ret;
  296. set_basic = false;
  297. break;
  298. }
  299. if (name != NULL)
  300. ret = debug_name_type (dhandle, name, ret);
  301. if (set_basic
  302. && ntype >= 0
  303. && ntype <= T_MAX)
  304. types->basic[ntype] = ret;
  305. return ret;
  306. }
  307. /* Parse a struct type. */
  308. static debug_type
  309. parse_coff_struct_type (bfd *abfd, struct coff_symbols *symbols,
  310. struct coff_types *types, int ntype,
  311. union internal_auxent *pauxent, void *dhandle)
  312. {
  313. long symend;
  314. int alloc;
  315. debug_field *fields;
  316. int count;
  317. bool done;
  318. symend = pauxent->x_sym.x_fcnary.x_fcn.x_endndx.l;
  319. alloc = 10;
  320. fields = (debug_field *) xmalloc (alloc * sizeof *fields);
  321. count = 0;
  322. done = false;
  323. while (! done
  324. && symbols->coff_symno < symend
  325. && symbols->symno < symbols->symcount)
  326. {
  327. asymbol *sym;
  328. long this_coff_symno;
  329. struct internal_syment syment;
  330. union internal_auxent auxent;
  331. union internal_auxent *psubaux;
  332. bfd_vma bitpos = 0, bitsize = 0;
  333. sym = symbols->syms[symbols->symno];
  334. if (! bfd_coff_get_syment (abfd, sym, &syment))
  335. {
  336. non_fatal (_("bfd_coff_get_syment failed: %s"),
  337. bfd_errmsg (bfd_get_error ()));
  338. free (fields);
  339. return DEBUG_TYPE_NULL;
  340. }
  341. this_coff_symno = symbols->coff_symno;
  342. ++symbols->symno;
  343. symbols->coff_symno += 1 + syment.n_numaux;
  344. if (syment.n_numaux == 0)
  345. psubaux = NULL;
  346. else
  347. {
  348. if (! bfd_coff_get_auxent (abfd, sym, 0, &auxent))
  349. {
  350. non_fatal (_("bfd_coff_get_auxent failed: %s"),
  351. bfd_errmsg (bfd_get_error ()));
  352. free (fields);
  353. return DEBUG_TYPE_NULL;
  354. }
  355. psubaux = &auxent;
  356. }
  357. switch (syment.n_sclass)
  358. {
  359. case C_MOS:
  360. case C_MOU:
  361. bitpos = 8 * bfd_asymbol_value (sym);
  362. bitsize = 0;
  363. break;
  364. case C_FIELD:
  365. bitpos = bfd_asymbol_value (sym);
  366. bitsize = auxent.x_sym.x_misc.x_lnsz.x_size;
  367. break;
  368. case C_EOS:
  369. done = true;
  370. break;
  371. }
  372. if (! done)
  373. {
  374. debug_type ftype;
  375. debug_field f;
  376. ftype = parse_coff_type (abfd, symbols, types, this_coff_symno,
  377. syment.n_type, psubaux, true, dhandle);
  378. f = debug_make_field (dhandle, bfd_asymbol_name (sym), ftype,
  379. bitpos, bitsize, DEBUG_VISIBILITY_PUBLIC);
  380. if (f == DEBUG_FIELD_NULL)
  381. return DEBUG_TYPE_NULL;
  382. if (count + 1 >= alloc)
  383. {
  384. alloc += 10;
  385. fields = ((debug_field *)
  386. xrealloc (fields, alloc * sizeof *fields));
  387. }
  388. fields[count] = f;
  389. ++count;
  390. }
  391. }
  392. fields[count] = DEBUG_FIELD_NULL;
  393. return debug_make_struct_type (dhandle, ntype == T_STRUCT,
  394. pauxent->x_sym.x_misc.x_lnsz.x_size,
  395. fields);
  396. }
  397. /* Parse an enum type. */
  398. static debug_type
  399. parse_coff_enum_type (bfd *abfd, struct coff_symbols *symbols,
  400. struct coff_types *types ATTRIBUTE_UNUSED,
  401. union internal_auxent *pauxent, void *dhandle)
  402. {
  403. long symend;
  404. int alloc;
  405. const char **names;
  406. bfd_signed_vma *vals;
  407. int count;
  408. bool done;
  409. symend = pauxent->x_sym.x_fcnary.x_fcn.x_endndx.l;
  410. alloc = 10;
  411. names = (const char **) xmalloc (alloc * sizeof *names);
  412. vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *vals);
  413. count = 0;
  414. done = false;
  415. while (! done
  416. && symbols->coff_symno < symend
  417. && symbols->symno < symbols->symcount)
  418. {
  419. asymbol *sym;
  420. struct internal_syment syment;
  421. sym = symbols->syms[symbols->symno];
  422. if (! bfd_coff_get_syment (abfd, sym, &syment))
  423. {
  424. non_fatal (_("bfd_coff_get_syment failed: %s"),
  425. bfd_errmsg (bfd_get_error ()));
  426. free (names);
  427. free (vals);
  428. return DEBUG_TYPE_NULL;
  429. }
  430. ++symbols->symno;
  431. symbols->coff_symno += 1 + syment.n_numaux;
  432. switch (syment.n_sclass)
  433. {
  434. case C_MOE:
  435. if (count + 1 >= alloc)
  436. {
  437. alloc += 10;
  438. names = ((const char **)
  439. xrealloc (names, alloc * sizeof *names));
  440. vals = ((bfd_signed_vma *)
  441. xrealloc (vals, alloc * sizeof *vals));
  442. }
  443. names[count] = bfd_asymbol_name (sym);
  444. vals[count] = bfd_asymbol_value (sym);
  445. ++count;
  446. break;
  447. case C_EOS:
  448. done = true;
  449. break;
  450. }
  451. }
  452. names[count] = NULL;
  453. return debug_make_enum_type (dhandle, names, vals);
  454. }
  455. /* Handle a single COFF symbol. */
  456. static bool
  457. parse_coff_symbol (bfd *abfd ATTRIBUTE_UNUSED, struct coff_types *types,
  458. asymbol *sym, long coff_symno,
  459. struct internal_syment *psyment, void *dhandle,
  460. debug_type type, bool within_function)
  461. {
  462. switch (psyment->n_sclass)
  463. {
  464. case C_NULL:
  465. break;
  466. case C_AUTO:
  467. if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
  468. DEBUG_LOCAL, bfd_asymbol_value (sym)))
  469. return false;
  470. break;
  471. case C_WEAKEXT:
  472. case C_EXT:
  473. if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
  474. DEBUG_GLOBAL, bfd_asymbol_value (sym)))
  475. return false;
  476. break;
  477. case C_STAT:
  478. if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
  479. (within_function
  480. ? DEBUG_LOCAL_STATIC
  481. : DEBUG_STATIC),
  482. bfd_asymbol_value (sym)))
  483. return false;
  484. break;
  485. case C_REG:
  486. /* FIXME: We may need to convert the register number. */
  487. if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
  488. DEBUG_REGISTER, bfd_asymbol_value (sym)))
  489. return false;
  490. break;
  491. case C_LABEL:
  492. break;
  493. case C_ARG:
  494. if (! debug_record_parameter (dhandle, bfd_asymbol_name (sym), type,
  495. DEBUG_PARM_STACK, bfd_asymbol_value (sym)))
  496. return false;
  497. break;
  498. case C_REGPARM:
  499. /* FIXME: We may need to convert the register number. */
  500. if (! debug_record_parameter (dhandle, bfd_asymbol_name (sym), type,
  501. DEBUG_PARM_REG, bfd_asymbol_value (sym)))
  502. return false;
  503. break;
  504. case C_TPDEF:
  505. type = debug_name_type (dhandle, bfd_asymbol_name (sym), type);
  506. if (type == DEBUG_TYPE_NULL)
  507. return false;
  508. break;
  509. case C_STRTAG:
  510. case C_UNTAG:
  511. case C_ENTAG:
  512. {
  513. debug_type *slot;
  514. type = debug_tag_type (dhandle, bfd_asymbol_name (sym), type);
  515. if (type == DEBUG_TYPE_NULL)
  516. return false;
  517. /* Store the named type into the slot, so that references get
  518. the name. */
  519. slot = coff_get_slot (types, coff_symno);
  520. *slot = type;
  521. }
  522. break;
  523. default:
  524. break;
  525. }
  526. return true;
  527. }
  528. /* Determine if a symbol has external visibility. */
  529. static bool
  530. external_coff_symbol_p (int sym_class)
  531. {
  532. switch (sym_class)
  533. {
  534. case C_EXT:
  535. case C_WEAKEXT:
  536. return true;
  537. default:
  538. break;
  539. }
  540. return false;
  541. }
  542. /* This is the main routine. It looks through all the symbols and
  543. handles them. */
  544. bool
  545. parse_coff (bfd *abfd, asymbol **syms, long symcount, void *dhandle)
  546. {
  547. struct coff_symbols symbols;
  548. struct coff_types types;
  549. int i;
  550. long next_c_file;
  551. const char *fnname;
  552. int fnclass;
  553. int fntype;
  554. bfd_vma fnend;
  555. alent *linenos;
  556. bool within_function;
  557. long this_coff_symno;
  558. symbols.syms = syms;
  559. symbols.symcount = symcount;
  560. symbols.symno = 0;
  561. symbols.coff_symno = 0;
  562. types.slots = NULL;
  563. for (i = 0; i <= T_MAX; i++)
  564. types.basic[i] = DEBUG_TYPE_NULL;
  565. next_c_file = -1;
  566. fnname = NULL;
  567. fnclass = 0;
  568. fntype = 0;
  569. fnend = 0;
  570. linenos = NULL;
  571. within_function = false;
  572. while (symbols.symno < symcount)
  573. {
  574. asymbol *sym;
  575. const char *name;
  576. struct internal_syment syment;
  577. union internal_auxent auxent;
  578. union internal_auxent *paux;
  579. debug_type type;
  580. sym = syms[symbols.symno];
  581. if (! bfd_coff_get_syment (abfd, sym, &syment))
  582. {
  583. non_fatal (_("bfd_coff_get_syment failed: %s"),
  584. bfd_errmsg (bfd_get_error ()));
  585. return false;
  586. }
  587. name = bfd_asymbol_name (sym);
  588. this_coff_symno = symbols.coff_symno;
  589. ++symbols.symno;
  590. symbols.coff_symno += 1 + syment.n_numaux;
  591. /* We only worry about the first auxent, because that is the
  592. only one which is relevant for debugging information. */
  593. if (syment.n_numaux == 0)
  594. paux = NULL;
  595. else
  596. {
  597. if (! bfd_coff_get_auxent (abfd, sym, 0, &auxent))
  598. {
  599. non_fatal (_("bfd_coff_get_auxent failed: %s"),
  600. bfd_errmsg (bfd_get_error ()));
  601. return false;
  602. }
  603. paux = &auxent;
  604. }
  605. if (this_coff_symno == next_c_file && syment.n_sclass != C_FILE)
  606. {
  607. /* The last C_FILE symbol points to the first external
  608. symbol. */
  609. if (! debug_set_filename (dhandle, "*globals*"))
  610. return false;
  611. }
  612. switch (syment.n_sclass)
  613. {
  614. case C_EFCN:
  615. case C_EXTDEF:
  616. case C_ULABEL:
  617. case C_USTATIC:
  618. case C_LINE:
  619. case C_ALIAS:
  620. case C_HIDDEN:
  621. /* Just ignore these classes. */
  622. break;
  623. case C_FILE:
  624. next_c_file = syment.n_value;
  625. if (! debug_set_filename (dhandle, name))
  626. return false;
  627. break;
  628. case C_STAT:
  629. /* Ignore static symbols with a type of T_NULL. These
  630. represent section entries. */
  631. if (syment.n_type == T_NULL)
  632. break;
  633. /* Fall through. */
  634. case C_WEAKEXT:
  635. case C_EXT:
  636. if (ISFCN (syment.n_type))
  637. {
  638. fnname = name;
  639. fnclass = syment.n_sclass;
  640. fntype = syment.n_type;
  641. if (syment.n_numaux > 0)
  642. fnend = bfd_asymbol_value (sym) + auxent.x_sym.x_misc.x_fsize;
  643. else
  644. fnend = 0;
  645. linenos = BFD_SEND (abfd, _get_lineno, (abfd, sym));
  646. break;
  647. }
  648. type = parse_coff_type (abfd, &symbols, &types, this_coff_symno,
  649. syment.n_type, paux, true, dhandle);
  650. if (type == DEBUG_TYPE_NULL)
  651. return false;
  652. if (! parse_coff_symbol (abfd, &types, sym, this_coff_symno, &syment,
  653. dhandle, type, within_function))
  654. return false;
  655. break;
  656. case C_FCN:
  657. if (strcmp (name, ".bf") == 0)
  658. {
  659. if (fnname == NULL)
  660. {
  661. non_fatal (_("%ld: .bf without preceding function"),
  662. this_coff_symno);
  663. return false;
  664. }
  665. type = parse_coff_type (abfd, &symbols, &types, this_coff_symno,
  666. DECREF (fntype), paux, false, dhandle);
  667. if (type == DEBUG_TYPE_NULL)
  668. return false;
  669. if (! debug_record_function (dhandle, fnname, type,
  670. external_coff_symbol_p (fnclass),
  671. bfd_asymbol_value (sym)))
  672. return false;
  673. if (linenos != NULL)
  674. {
  675. int base;
  676. bfd_vma addr;
  677. if (syment.n_numaux == 0)
  678. base = 0;
  679. else
  680. base = auxent.x_sym.x_misc.x_lnsz.x_lnno - 1;
  681. addr = bfd_section_vma (bfd_asymbol_section (sym));
  682. ++linenos;
  683. while (linenos->line_number != 0)
  684. {
  685. if (! debug_record_line (dhandle,
  686. linenos->line_number + base,
  687. linenos->u.offset + addr))
  688. return false;
  689. ++linenos;
  690. }
  691. }
  692. fnname = NULL;
  693. linenos = NULL;
  694. fnclass = 0;
  695. fntype = 0;
  696. within_function = true;
  697. }
  698. else if (strcmp (name, ".ef") == 0)
  699. {
  700. if (! within_function)
  701. {
  702. non_fatal (_("%ld: unexpected .ef\n"), this_coff_symno);
  703. return false;
  704. }
  705. if (bfd_asymbol_value (sym) > fnend)
  706. fnend = bfd_asymbol_value (sym);
  707. if (! debug_end_function (dhandle, fnend))
  708. return false;
  709. fnend = 0;
  710. within_function = false;
  711. }
  712. break;
  713. case C_BLOCK:
  714. if (strcmp (name, ".bb") == 0)
  715. {
  716. if (! debug_start_block (dhandle, bfd_asymbol_value (sym)))
  717. return false;
  718. }
  719. else if (strcmp (name, ".eb") == 0)
  720. {
  721. if (! debug_end_block (dhandle, bfd_asymbol_value (sym)))
  722. return false;
  723. }
  724. break;
  725. default:
  726. type = parse_coff_type (abfd, &symbols, &types, this_coff_symno,
  727. syment.n_type, paux, true, dhandle);
  728. if (type == DEBUG_TYPE_NULL)
  729. return false;
  730. if (! parse_coff_symbol (abfd, &types, sym, this_coff_symno, &syment,
  731. dhandle, type, within_function))
  732. return false;
  733. break;
  734. }
  735. }
  736. return true;
  737. }