rdcoff.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. /* stabs.c -- Parse COFF debugging information
  2. Copyright (C) 1996-2015 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 *, bfd_boolean, 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 bfd_boolean parse_coff_symbol
  83. (bfd *, struct coff_types *, asymbol *, long, struct internal_syment *,
  84. void *, debug_type, bfd_boolean);
  85. static bfd_boolean 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, bfd_boolean 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. bfd_boolean 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. bfd_boolean 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. return DEBUG_TYPE_NULL;
  339. }
  340. this_coff_symno = symbols->coff_symno;
  341. ++symbols->symno;
  342. symbols->coff_symno += 1 + syment.n_numaux;
  343. if (syment.n_numaux == 0)
  344. psubaux = NULL;
  345. else
  346. {
  347. if (! bfd_coff_get_auxent (abfd, sym, 0, &auxent))
  348. {
  349. non_fatal (_("bfd_coff_get_auxent failed: %s"),
  350. bfd_errmsg (bfd_get_error ()));
  351. return DEBUG_TYPE_NULL;
  352. }
  353. psubaux = &auxent;
  354. }
  355. switch (syment.n_sclass)
  356. {
  357. case C_MOS:
  358. case C_MOU:
  359. bitpos = 8 * bfd_asymbol_value (sym);
  360. bitsize = 0;
  361. break;
  362. case C_FIELD:
  363. bitpos = bfd_asymbol_value (sym);
  364. bitsize = auxent.x_sym.x_misc.x_lnsz.x_size;
  365. break;
  366. case C_EOS:
  367. done = TRUE;
  368. break;
  369. }
  370. if (! done)
  371. {
  372. debug_type ftype;
  373. debug_field f;
  374. ftype = parse_coff_type (abfd, symbols, types, this_coff_symno,
  375. syment.n_type, psubaux, TRUE, dhandle);
  376. f = debug_make_field (dhandle, bfd_asymbol_name (sym), ftype,
  377. bitpos, bitsize, DEBUG_VISIBILITY_PUBLIC);
  378. if (f == DEBUG_FIELD_NULL)
  379. return DEBUG_TYPE_NULL;
  380. if (count + 1 >= alloc)
  381. {
  382. alloc += 10;
  383. fields = ((debug_field *)
  384. xrealloc (fields, alloc * sizeof *fields));
  385. }
  386. fields[count] = f;
  387. ++count;
  388. }
  389. }
  390. fields[count] = DEBUG_FIELD_NULL;
  391. return debug_make_struct_type (dhandle, ntype == T_STRUCT,
  392. pauxent->x_sym.x_misc.x_lnsz.x_size,
  393. fields);
  394. }
  395. /* Parse an enum type. */
  396. static debug_type
  397. parse_coff_enum_type (bfd *abfd, struct coff_symbols *symbols,
  398. struct coff_types *types ATTRIBUTE_UNUSED,
  399. union internal_auxent *pauxent, void *dhandle)
  400. {
  401. long symend;
  402. int alloc;
  403. const char **names;
  404. bfd_signed_vma *vals;
  405. int count;
  406. bfd_boolean done;
  407. symend = pauxent->x_sym.x_fcnary.x_fcn.x_endndx.l;
  408. alloc = 10;
  409. names = (const char **) xmalloc (alloc * sizeof *names);
  410. vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *vals);
  411. count = 0;
  412. done = FALSE;
  413. while (! done
  414. && symbols->coff_symno < symend
  415. && symbols->symno < symbols->symcount)
  416. {
  417. asymbol *sym;
  418. struct internal_syment syment;
  419. sym = symbols->syms[symbols->symno];
  420. if (! bfd_coff_get_syment (abfd, sym, &syment))
  421. {
  422. non_fatal (_("bfd_coff_get_syment failed: %s"),
  423. bfd_errmsg (bfd_get_error ()));
  424. return DEBUG_TYPE_NULL;
  425. }
  426. ++symbols->symno;
  427. symbols->coff_symno += 1 + syment.n_numaux;
  428. switch (syment.n_sclass)
  429. {
  430. case C_MOE:
  431. if (count + 1 >= alloc)
  432. {
  433. alloc += 10;
  434. names = ((const char **)
  435. xrealloc (names, alloc * sizeof *names));
  436. vals = ((bfd_signed_vma *)
  437. xrealloc (vals, alloc * sizeof *vals));
  438. }
  439. names[count] = bfd_asymbol_name (sym);
  440. vals[count] = bfd_asymbol_value (sym);
  441. ++count;
  442. break;
  443. case C_EOS:
  444. done = TRUE;
  445. break;
  446. }
  447. }
  448. names[count] = NULL;
  449. return debug_make_enum_type (dhandle, names, vals);
  450. }
  451. /* Handle a single COFF symbol. */
  452. static bfd_boolean
  453. parse_coff_symbol (bfd *abfd ATTRIBUTE_UNUSED, struct coff_types *types,
  454. asymbol *sym, long coff_symno,
  455. struct internal_syment *psyment, void *dhandle,
  456. debug_type type, bfd_boolean within_function)
  457. {
  458. switch (psyment->n_sclass)
  459. {
  460. case C_NULL:
  461. break;
  462. case C_AUTO:
  463. if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
  464. DEBUG_LOCAL, bfd_asymbol_value (sym)))
  465. return FALSE;
  466. break;
  467. case C_WEAKEXT:
  468. case C_EXT:
  469. if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
  470. DEBUG_GLOBAL, bfd_asymbol_value (sym)))
  471. return FALSE;
  472. break;
  473. case C_STAT:
  474. if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
  475. (within_function
  476. ? DEBUG_LOCAL_STATIC
  477. : DEBUG_STATIC),
  478. bfd_asymbol_value (sym)))
  479. return FALSE;
  480. break;
  481. case C_REG:
  482. /* FIXME: We may need to convert the register number. */
  483. if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
  484. DEBUG_REGISTER, bfd_asymbol_value (sym)))
  485. return FALSE;
  486. break;
  487. case C_LABEL:
  488. break;
  489. case C_ARG:
  490. if (! debug_record_parameter (dhandle, bfd_asymbol_name (sym), type,
  491. DEBUG_PARM_STACK, bfd_asymbol_value (sym)))
  492. return FALSE;
  493. break;
  494. case C_REGPARM:
  495. /* FIXME: We may need to convert the register number. */
  496. if (! debug_record_parameter (dhandle, bfd_asymbol_name (sym), type,
  497. DEBUG_PARM_REG, bfd_asymbol_value (sym)))
  498. return FALSE;
  499. break;
  500. case C_TPDEF:
  501. type = debug_name_type (dhandle, bfd_asymbol_name (sym), type);
  502. if (type == DEBUG_TYPE_NULL)
  503. return FALSE;
  504. break;
  505. case C_STRTAG:
  506. case C_UNTAG:
  507. case C_ENTAG:
  508. {
  509. debug_type *slot;
  510. type = debug_tag_type (dhandle, bfd_asymbol_name (sym), type);
  511. if (type == DEBUG_TYPE_NULL)
  512. return FALSE;
  513. /* Store the named type into the slot, so that references get
  514. the name. */
  515. slot = coff_get_slot (types, coff_symno);
  516. *slot = type;
  517. }
  518. break;
  519. default:
  520. break;
  521. }
  522. return TRUE;
  523. }
  524. /* Determine if a symbol has external visibility. */
  525. static bfd_boolean
  526. external_coff_symbol_p (int sym_class)
  527. {
  528. switch (sym_class)
  529. {
  530. case C_EXT:
  531. case C_WEAKEXT:
  532. return TRUE;
  533. default:
  534. break;
  535. }
  536. return FALSE;
  537. }
  538. /* This is the main routine. It looks through all the symbols and
  539. handles them. */
  540. bfd_boolean
  541. parse_coff (bfd *abfd, asymbol **syms, long symcount, void *dhandle)
  542. {
  543. struct coff_symbols symbols;
  544. struct coff_types types;
  545. int i;
  546. long next_c_file;
  547. const char *fnname;
  548. int fnclass;
  549. int fntype;
  550. bfd_vma fnend;
  551. alent *linenos;
  552. bfd_boolean within_function;
  553. long this_coff_symno;
  554. symbols.syms = syms;
  555. symbols.symcount = symcount;
  556. symbols.symno = 0;
  557. symbols.coff_symno = 0;
  558. types.slots = NULL;
  559. for (i = 0; i <= T_MAX; i++)
  560. types.basic[i] = DEBUG_TYPE_NULL;
  561. next_c_file = -1;
  562. fnname = NULL;
  563. fnclass = 0;
  564. fntype = 0;
  565. fnend = 0;
  566. linenos = NULL;
  567. within_function = FALSE;
  568. while (symbols.symno < symcount)
  569. {
  570. asymbol *sym;
  571. const char *name;
  572. struct internal_syment syment;
  573. union internal_auxent auxent;
  574. union internal_auxent *paux;
  575. debug_type type;
  576. sym = syms[symbols.symno];
  577. if (! bfd_coff_get_syment (abfd, sym, &syment))
  578. {
  579. non_fatal (_("bfd_coff_get_syment failed: %s"),
  580. bfd_errmsg (bfd_get_error ()));
  581. return FALSE;
  582. }
  583. name = bfd_asymbol_name (sym);
  584. this_coff_symno = symbols.coff_symno;
  585. ++symbols.symno;
  586. symbols.coff_symno += 1 + syment.n_numaux;
  587. /* We only worry about the first auxent, because that is the
  588. only one which is relevant for debugging information. */
  589. if (syment.n_numaux == 0)
  590. paux = NULL;
  591. else
  592. {
  593. if (! bfd_coff_get_auxent (abfd, sym, 0, &auxent))
  594. {
  595. non_fatal (_("bfd_coff_get_auxent failed: %s"),
  596. bfd_errmsg (bfd_get_error ()));
  597. return FALSE;
  598. }
  599. paux = &auxent;
  600. }
  601. if (this_coff_symno == next_c_file && syment.n_sclass != C_FILE)
  602. {
  603. /* The last C_FILE symbol points to the first external
  604. symbol. */
  605. if (! debug_set_filename (dhandle, "*globals*"))
  606. return FALSE;
  607. }
  608. switch (syment.n_sclass)
  609. {
  610. case C_EFCN:
  611. case C_EXTDEF:
  612. case C_ULABEL:
  613. case C_USTATIC:
  614. case C_LINE:
  615. case C_ALIAS:
  616. case C_HIDDEN:
  617. /* Just ignore these classes. */
  618. break;
  619. case C_FILE:
  620. next_c_file = syment.n_value;
  621. if (! debug_set_filename (dhandle, name))
  622. return FALSE;
  623. break;
  624. case C_STAT:
  625. /* Ignore static symbols with a type of T_NULL. These
  626. represent section entries. */
  627. if (syment.n_type == T_NULL)
  628. break;
  629. /* Fall through. */
  630. case C_WEAKEXT:
  631. case C_EXT:
  632. if (ISFCN (syment.n_type))
  633. {
  634. fnname = name;
  635. fnclass = syment.n_sclass;
  636. fntype = syment.n_type;
  637. if (syment.n_numaux > 0)
  638. fnend = bfd_asymbol_value (sym) + auxent.x_sym.x_misc.x_fsize;
  639. else
  640. fnend = 0;
  641. linenos = BFD_SEND (abfd, _get_lineno, (abfd, sym));
  642. break;
  643. }
  644. type = parse_coff_type (abfd, &symbols, &types, this_coff_symno,
  645. syment.n_type, paux, TRUE, dhandle);
  646. if (type == DEBUG_TYPE_NULL)
  647. return FALSE;
  648. if (! parse_coff_symbol (abfd, &types, sym, this_coff_symno, &syment,
  649. dhandle, type, within_function))
  650. return FALSE;
  651. break;
  652. case C_FCN:
  653. if (strcmp (name, ".bf") == 0)
  654. {
  655. if (fnname == NULL)
  656. {
  657. non_fatal (_("%ld: .bf without preceding function"),
  658. this_coff_symno);
  659. return FALSE;
  660. }
  661. type = parse_coff_type (abfd, &symbols, &types, this_coff_symno,
  662. DECREF (fntype), paux, FALSE, dhandle);
  663. if (type == DEBUG_TYPE_NULL)
  664. return FALSE;
  665. if (! debug_record_function (dhandle, fnname, type,
  666. external_coff_symbol_p (fnclass),
  667. bfd_asymbol_value (sym)))
  668. return FALSE;
  669. if (linenos != NULL)
  670. {
  671. int base;
  672. bfd_vma addr;
  673. if (syment.n_numaux == 0)
  674. base = 0;
  675. else
  676. base = auxent.x_sym.x_misc.x_lnsz.x_lnno - 1;
  677. addr = bfd_get_section_vma (abfd, bfd_get_section (sym));
  678. ++linenos;
  679. while (linenos->line_number != 0)
  680. {
  681. if (! debug_record_line (dhandle,
  682. linenos->line_number + base,
  683. linenos->u.offset + addr))
  684. return FALSE;
  685. ++linenos;
  686. }
  687. }
  688. fnname = NULL;
  689. linenos = NULL;
  690. fnclass = 0;
  691. fntype = 0;
  692. within_function = TRUE;
  693. }
  694. else if (strcmp (name, ".ef") == 0)
  695. {
  696. if (! within_function)
  697. {
  698. non_fatal (_("%ld: unexpected .ef\n"), this_coff_symno);
  699. return FALSE;
  700. }
  701. if (bfd_asymbol_value (sym) > fnend)
  702. fnend = bfd_asymbol_value (sym);
  703. if (! debug_end_function (dhandle, fnend))
  704. return FALSE;
  705. fnend = 0;
  706. within_function = FALSE;
  707. }
  708. break;
  709. case C_BLOCK:
  710. if (strcmp (name, ".bb") == 0)
  711. {
  712. if (! debug_start_block (dhandle, bfd_asymbol_value (sym)))
  713. return FALSE;
  714. }
  715. else if (strcmp (name, ".eb") == 0)
  716. {
  717. if (! debug_end_block (dhandle, bfd_asymbol_value (sym)))
  718. return FALSE;
  719. }
  720. break;
  721. default:
  722. type = parse_coff_type (abfd, &symbols, &types, this_coff_symno,
  723. syment.n_type, paux, TRUE, dhandle);
  724. if (type == DEBUG_TYPE_NULL)
  725. return FALSE;
  726. if (! parse_coff_symbol (abfd, &types, sym, this_coff_symno, &syment,
  727. dhandle, type, within_function))
  728. return FALSE;
  729. break;
  730. }
  731. }
  732. return TRUE;
  733. }