wrstabs.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286
  1. /* wrstabs.c -- Output stabs 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 writes out stabs debugging
  18. information. */
  19. #include "sysdep.h"
  20. #include <assert.h>
  21. #include "bfd.h"
  22. #include "libiberty.h"
  23. #include "filenames.h"
  24. #include "safe-ctype.h"
  25. #include "bucomm.h"
  26. #include "debug.h"
  27. #include "budbg.h"
  28. #include "aout/aout64.h"
  29. #include "aout/stab_gnu.h"
  30. /* The size of a stabs symbol. This presumes 32 bit values. */
  31. #define STAB_SYMBOL_SIZE (12)
  32. /* An entry in a string hash table. */
  33. struct string_hash_entry
  34. {
  35. struct bfd_hash_entry root;
  36. /* Next string in this table. */
  37. struct string_hash_entry *next;
  38. /* Index in string table. */
  39. long index;
  40. /* Size of type if this is a typedef. */
  41. unsigned int size;
  42. };
  43. /* A string hash table. */
  44. struct string_hash_table
  45. {
  46. struct bfd_hash_table table;
  47. };
  48. /* The type stack. Each element on the stack is a string. */
  49. struct stab_type_stack
  50. {
  51. /* The next element on the stack. */
  52. struct stab_type_stack *next;
  53. /* This element as a string. */
  54. char *string;
  55. /* The type index of this element. */
  56. long index;
  57. /* The size of the type. */
  58. unsigned int size;
  59. /* Whether type string defines a new type. */
  60. bool definition;
  61. /* String defining struct fields. */
  62. char *fields;
  63. /* NULL terminated array of strings defining base classes for a
  64. class. */
  65. char **baseclasses;
  66. /* String defining class methods. */
  67. char *methods;
  68. /* String defining vtable pointer for a class. */
  69. char *vtable;
  70. };
  71. /* This structure is used to keep track of type indices for tagged
  72. types. */
  73. struct stab_tag
  74. {
  75. /* The type index. */
  76. long index;
  77. /* The tag name. */
  78. const char *tag;
  79. /* The kind of type. This is set to DEBUG_KIND_ILLEGAL when the
  80. type is defined. */
  81. enum debug_type_kind kind;
  82. /* The size of the struct. */
  83. unsigned int size;
  84. };
  85. /* We remember various sorts of type indices. They are not related,
  86. but, for convenience, we keep all the information in this
  87. structure. */
  88. struct stab_type_cache
  89. {
  90. /* The void type index. */
  91. long void_type;
  92. /* Signed integer type indices, indexed by size - 1. */
  93. long signed_integer_types[8];
  94. /* Unsigned integer type indices, indexed by size - 1. */
  95. long unsigned_integer_types[8];
  96. /* Floating point types, indexed by size - 1. */
  97. long float_types[16];
  98. /* Pointers to types, indexed by the type index. */
  99. long *pointer_types;
  100. size_t pointer_types_alloc;
  101. /* Functions returning types, indexed by the type index. */
  102. long *function_types;
  103. size_t function_types_alloc;
  104. /* References to types, indexed by the type index. */
  105. long *reference_types;
  106. size_t reference_types_alloc;
  107. /* Struct/union/class type indices, indexed by the struct id. */
  108. struct stab_tag *struct_types;
  109. size_t struct_types_alloc;
  110. };
  111. /* This is the handle passed through debug_write. */
  112. struct stab_write_handle
  113. {
  114. /* The BFD. */
  115. bfd *abfd;
  116. /* This buffer holds the symbols. */
  117. bfd_byte *symbols;
  118. size_t symbols_size;
  119. size_t symbols_alloc;
  120. /* This is a list of hash table entries for the strings. */
  121. struct string_hash_entry *strings;
  122. /* The last string hash table entry. */
  123. struct string_hash_entry *last_string;
  124. /* The size of the strings. */
  125. size_t strings_size;
  126. /* This hash table eliminates duplicate strings. */
  127. struct string_hash_table strhash;
  128. /* The type stack. */
  129. struct stab_type_stack *type_stack;
  130. /* The next type index. */
  131. long type_index;
  132. /* The type cache. */
  133. struct stab_type_cache type_cache;
  134. /* A mapping from typedef names to type indices. */
  135. struct string_hash_table typedef_hash;
  136. /* If this is not -1, it is the offset to the most recent N_SO
  137. symbol, and the value of that symbol needs to be set. */
  138. long so_offset;
  139. /* If this is not -1, it is the offset to the most recent N_FUN
  140. symbol, and the value of that symbol needs to be set. */
  141. long fun_offset;
  142. /* The last text section address seen. */
  143. bfd_vma last_text_address;
  144. /* The block nesting depth. */
  145. unsigned int nesting;
  146. /* The function address. */
  147. bfd_vma fnaddr;
  148. /* A pending LBRAC symbol. */
  149. bfd_vma pending_lbrac;
  150. /* The current line number file name. */
  151. const char *lineno_filename;
  152. };
  153. static struct bfd_hash_entry *string_hash_newfunc
  154. (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
  155. static bool stab_write_symbol
  156. (struct stab_write_handle *, int, int, bfd_vma, const char *);
  157. static bool stab_push_string
  158. (struct stab_write_handle *, const char *, long, bool, unsigned int);
  159. static bool stab_push_defined_type
  160. (struct stab_write_handle *, long, unsigned int);
  161. static char *stab_pop_type (struct stab_write_handle *);
  162. static bool stab_modify_type
  163. (struct stab_write_handle *, int, unsigned int, long **, size_t *);
  164. static long stab_get_struct_index
  165. (struct stab_write_handle *, const char *, unsigned int,
  166. enum debug_type_kind, unsigned int *);
  167. static bool stab_class_method_var
  168. (struct stab_write_handle *, const char *, enum debug_visibility,
  169. bool, bool, bool, bfd_vma, bool);
  170. static bool stab_start_compilation_unit (void *, const char *);
  171. static bool stab_start_source (void *, const char *);
  172. static bool stab_empty_type (void *);
  173. static bool stab_void_type (void *);
  174. static bool stab_int_type (void *, unsigned int, bool);
  175. static bool stab_float_type (void *, unsigned int);
  176. static bool stab_complex_type (void *, unsigned int);
  177. static bool stab_bool_type (void *, unsigned int);
  178. static bool stab_enum_type
  179. (void *, const char *, const char **, bfd_signed_vma *);
  180. static bool stab_pointer_type (void *);
  181. static bool stab_function_type (void *, int, bool);
  182. static bool stab_reference_type (void *);
  183. static bool stab_range_type (void *, bfd_signed_vma, bfd_signed_vma);
  184. static bool stab_array_type
  185. (void *, bfd_signed_vma, bfd_signed_vma, bool);
  186. static bool stab_set_type (void *, bool);
  187. static bool stab_offset_type (void *);
  188. static bool stab_method_type (void *, bool, int, bool);
  189. static bool stab_const_type (void *);
  190. static bool stab_volatile_type (void *);
  191. static bool stab_start_struct_type
  192. (void *, const char *, unsigned int, bool, unsigned int);
  193. static bool stab_struct_field
  194. (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
  195. static bool stab_end_struct_type (void *);
  196. static bool stab_start_class_type
  197. (void *, const char *, unsigned int, bool, unsigned int,
  198. bool, bool);
  199. static bool stab_class_static_member
  200. (void *, const char *, const char *, enum debug_visibility);
  201. static bool stab_class_baseclass
  202. (void *, bfd_vma, bool, enum debug_visibility);
  203. static bool stab_class_start_method (void *, const char *);
  204. static bool stab_class_method_variant
  205. (void *, const char *, enum debug_visibility, bool, bool,
  206. bfd_vma, bool);
  207. static bool stab_class_static_method_variant
  208. (void *, const char *, enum debug_visibility, bool, bool);
  209. static bool stab_class_end_method (void *);
  210. static bool stab_end_class_type (void *);
  211. static bool stab_typedef_type (void *, const char *);
  212. static bool stab_tag_type
  213. (void *, const char *, unsigned int, enum debug_type_kind);
  214. static bool stab_typdef (void *, const char *);
  215. static bool stab_tag (void *, const char *);
  216. static bool stab_int_constant (void *, const char *, bfd_vma);
  217. static bool stab_float_constant (void *, const char *, double);
  218. static bool stab_typed_constant (void *, const char *, bfd_vma);
  219. static bool stab_variable
  220. (void *, const char *, enum debug_var_kind, bfd_vma);
  221. static bool stab_start_function (void *, const char *, bool);
  222. static bool stab_function_parameter
  223. (void *, const char *, enum debug_parm_kind, bfd_vma);
  224. static bool stab_start_block (void *, bfd_vma);
  225. static bool stab_end_block (void *, bfd_vma);
  226. static bool stab_end_function (void *);
  227. static bool stab_lineno (void *, const char *, unsigned long, bfd_vma);
  228. static const struct debug_write_fns stab_fns =
  229. {
  230. stab_start_compilation_unit,
  231. stab_start_source,
  232. stab_empty_type,
  233. stab_void_type,
  234. stab_int_type,
  235. stab_float_type,
  236. stab_complex_type,
  237. stab_bool_type,
  238. stab_enum_type,
  239. stab_pointer_type,
  240. stab_function_type,
  241. stab_reference_type,
  242. stab_range_type,
  243. stab_array_type,
  244. stab_set_type,
  245. stab_offset_type,
  246. stab_method_type,
  247. stab_const_type,
  248. stab_volatile_type,
  249. stab_start_struct_type,
  250. stab_struct_field,
  251. stab_end_struct_type,
  252. stab_start_class_type,
  253. stab_class_static_member,
  254. stab_class_baseclass,
  255. stab_class_start_method,
  256. stab_class_method_variant,
  257. stab_class_static_method_variant,
  258. stab_class_end_method,
  259. stab_end_class_type,
  260. stab_typedef_type,
  261. stab_tag_type,
  262. stab_typdef,
  263. stab_tag,
  264. stab_int_constant,
  265. stab_float_constant,
  266. stab_typed_constant,
  267. stab_variable,
  268. stab_start_function,
  269. stab_function_parameter,
  270. stab_start_block,
  271. stab_end_block,
  272. stab_end_function,
  273. stab_lineno
  274. };
  275. /* Routine to create an entry in a string hash table. */
  276. static struct bfd_hash_entry *
  277. string_hash_newfunc (struct bfd_hash_entry *entry,
  278. struct bfd_hash_table *table, const char *string)
  279. {
  280. struct string_hash_entry *ret = (struct string_hash_entry *) entry;
  281. /* Allocate the structure if it has not already been allocated by a
  282. subclass. */
  283. if (ret == (struct string_hash_entry *) NULL)
  284. ret = ((struct string_hash_entry *)
  285. bfd_hash_allocate (table, sizeof (struct string_hash_entry)));
  286. if (ret == (struct string_hash_entry *) NULL)
  287. return NULL;
  288. /* Call the allocation method of the superclass. */
  289. ret = ((struct string_hash_entry *)
  290. bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
  291. if (ret)
  292. {
  293. /* Initialize the local fields. */
  294. ret->next = NULL;
  295. ret->index = -1;
  296. ret->size = 0;
  297. }
  298. return (struct bfd_hash_entry *) ret;
  299. }
  300. /* Look up an entry in a string hash table. */
  301. #define string_hash_lookup(t, string, create, copy) \
  302. ((struct string_hash_entry *) \
  303. bfd_hash_lookup (&(t)->table, (string), (create), (copy)))
  304. /* Add a symbol to the stabs debugging information we are building. */
  305. static bool
  306. stab_write_symbol (struct stab_write_handle *info, int type, int desc,
  307. bfd_vma value, const char *string)
  308. {
  309. bfd_size_type strx;
  310. bfd_byte sym[STAB_SYMBOL_SIZE];
  311. if (string == NULL)
  312. strx = 0;
  313. else
  314. {
  315. struct string_hash_entry *h;
  316. h = string_hash_lookup (&info->strhash, string, true, true);
  317. if (h == NULL)
  318. {
  319. non_fatal (_("string_hash_lookup failed: %s"),
  320. bfd_errmsg (bfd_get_error ()));
  321. return false;
  322. }
  323. if (h->index != -1)
  324. strx = h->index;
  325. else
  326. {
  327. strx = info->strings_size;
  328. h->index = strx;
  329. if (info->last_string == NULL)
  330. info->strings = h;
  331. else
  332. info->last_string->next = h;
  333. info->last_string = h;
  334. info->strings_size += strlen (string) + 1;
  335. }
  336. }
  337. /* This presumes 32 bit values. */
  338. bfd_put_32 (info->abfd, strx, sym);
  339. bfd_put_8 (info->abfd, type, sym + 4);
  340. bfd_put_8 (info->abfd, 0, sym + 5);
  341. bfd_put_16 (info->abfd, desc, sym + 6);
  342. bfd_put_32 (info->abfd, value, sym + 8);
  343. if (info->symbols_size + STAB_SYMBOL_SIZE > info->symbols_alloc)
  344. {
  345. info->symbols_alloc *= 2;
  346. info->symbols = (bfd_byte *) xrealloc (info->symbols,
  347. info->symbols_alloc);
  348. }
  349. memcpy (info->symbols + info->symbols_size, sym, STAB_SYMBOL_SIZE);
  350. info->symbols_size += STAB_SYMBOL_SIZE;
  351. return true;
  352. }
  353. /* Push a string on to the type stack. */
  354. static bool
  355. stab_push_string (struct stab_write_handle *info, const char *string,
  356. long tindex, bool definition, unsigned int size)
  357. {
  358. struct stab_type_stack *s;
  359. s = (struct stab_type_stack *) xmalloc (sizeof *s);
  360. s->string = xstrdup (string);
  361. s->index = tindex;
  362. s->definition = definition;
  363. s->size = size;
  364. s->fields = NULL;
  365. s->baseclasses = NULL;
  366. s->methods = NULL;
  367. s->vtable = NULL;
  368. s->next = info->type_stack;
  369. info->type_stack = s;
  370. return true;
  371. }
  372. /* Push a type index which has already been defined. */
  373. static bool
  374. stab_push_defined_type (struct stab_write_handle *info, long tindex,
  375. unsigned int size)
  376. {
  377. char buf[20];
  378. sprintf (buf, "%ld", tindex);
  379. return stab_push_string (info, buf, tindex, false, size);
  380. }
  381. /* Pop a type off the type stack. The caller is responsible for
  382. freeing the string. */
  383. static char *
  384. stab_pop_type (struct stab_write_handle *info)
  385. {
  386. struct stab_type_stack *s;
  387. char *ret;
  388. s = info->type_stack;
  389. if (s == NULL)
  390. return NULL;
  391. info->type_stack = s->next;
  392. ret = s->string;
  393. free (s);
  394. return ret;
  395. }
  396. /* The general routine to write out stabs in sections debugging
  397. information. This accumulates the stabs symbols and the strings in
  398. two obstacks. We can't easily write out the information as we go
  399. along, because we need to know the section sizes before we can
  400. write out the section contents. ABFD is the BFD and DHANDLE is the
  401. handle for the debugging information. This sets *PSYMS to point to
  402. the symbols, *PSYMSIZE the size of the symbols, *PSTRINGS to the
  403. strings, and *PSTRINGSIZE to the size of the strings. */
  404. bool
  405. write_stabs_in_sections_debugging_info (bfd *abfd, void *dhandle,
  406. bfd_byte **psyms,
  407. bfd_size_type *psymsize,
  408. bfd_byte **pstrings,
  409. bfd_size_type *pstringsize)
  410. {
  411. struct stab_write_handle info;
  412. struct string_hash_entry *h;
  413. bfd_byte *p;
  414. info.abfd = abfd;
  415. info.symbols_size = 0;
  416. info.symbols_alloc = 500;
  417. info.symbols = (bfd_byte *) xmalloc (info.symbols_alloc);
  418. info.strings = NULL;
  419. info.last_string = NULL;
  420. /* Reserve 1 byte for a null byte. */
  421. info.strings_size = 1;
  422. if (!bfd_hash_table_init (&info.strhash.table, string_hash_newfunc,
  423. sizeof (struct string_hash_entry))
  424. || !bfd_hash_table_init (&info.typedef_hash.table, string_hash_newfunc,
  425. sizeof (struct string_hash_entry)))
  426. {
  427. non_fatal ("bfd_hash_table_init_failed: %s",
  428. bfd_errmsg (bfd_get_error ()));
  429. return false;
  430. }
  431. info.type_stack = NULL;
  432. info.type_index = 1;
  433. memset (&info.type_cache, 0, sizeof info.type_cache);
  434. info.so_offset = -1;
  435. info.fun_offset = -1;
  436. info.last_text_address = 0;
  437. info.nesting = 0;
  438. info.fnaddr = 0;
  439. info.pending_lbrac = (bfd_vma) -1;
  440. /* The initial symbol holds the string size. */
  441. if (! stab_write_symbol (&info, 0, 0, 0, (const char *) NULL))
  442. return false;
  443. /* Output an initial N_SO symbol. */
  444. info.so_offset = info.symbols_size;
  445. if (! stab_write_symbol (&info, N_SO, 0, 0, bfd_get_filename (abfd)))
  446. return false;
  447. if (! debug_write (dhandle, &stab_fns, (void *) &info))
  448. return false;
  449. if (info.pending_lbrac != (bfd_vma) -1)
  450. return false;
  451. /* Output a trailing N_SO. */
  452. if (! stab_write_symbol (&info, N_SO, 0, info.last_text_address,
  453. (const char *) NULL))
  454. return false;
  455. /* Put the string size in the initial symbol. */
  456. bfd_put_32 (abfd, info.strings_size, info.symbols + 8);
  457. *psyms = info.symbols;
  458. *psymsize = info.symbols_size;
  459. *pstringsize = info.strings_size;
  460. *pstrings = (bfd_byte *) xmalloc (info.strings_size);
  461. p = *pstrings;
  462. *p++ = '\0';
  463. for (h = info.strings; h != NULL; h = h->next)
  464. {
  465. strcpy ((char *) p, h->root.string);
  466. p += strlen ((char *) p) + 1;
  467. }
  468. return true;
  469. }
  470. /* Start writing out information for a compilation unit. */
  471. static bool
  472. stab_start_compilation_unit (void *p, const char *filename)
  473. {
  474. struct stab_write_handle *info = (struct stab_write_handle *) p;
  475. /* We would normally output an N_SO symbol here. However, that
  476. would force us to reset all of our type information. I think we
  477. will be better off just outputting an N_SOL symbol, and not
  478. worrying about splitting information between files. */
  479. info->lineno_filename = filename;
  480. return stab_write_symbol (info, N_SOL, 0, 0, filename);
  481. }
  482. /* Start writing out information for a particular source file. */
  483. static bool
  484. stab_start_source (void *p, const char *filename)
  485. {
  486. struct stab_write_handle *info = (struct stab_write_handle *) p;
  487. /* FIXME: The symbol's value is supposed to be the text section
  488. address. However, we would have to fill it in later, and gdb
  489. doesn't care, so we don't bother with it. */
  490. info->lineno_filename = filename;
  491. return stab_write_symbol (info, N_SOL, 0, 0, filename);
  492. }
  493. /* Push an empty type. This shouldn't normally happen. We just use a
  494. void type. */
  495. static bool
  496. stab_empty_type (void *p)
  497. {
  498. struct stab_write_handle *info = (struct stab_write_handle *) p;
  499. /* We don't call stab_void_type if the type is not yet defined,
  500. because that might screw up the typedef. */
  501. if (info->type_cache.void_type != 0)
  502. return stab_push_defined_type (info, info->type_cache.void_type, 0);
  503. else
  504. {
  505. long tindex;
  506. char buf[40];
  507. tindex = info->type_index;
  508. ++info->type_index;
  509. sprintf (buf, "%ld=%ld", tindex, tindex);
  510. return stab_push_string (info, buf, tindex, false, 0);
  511. }
  512. }
  513. /* Push a void type. */
  514. static bool
  515. stab_void_type (void *p)
  516. {
  517. struct stab_write_handle *info = (struct stab_write_handle *) p;
  518. if (info->type_cache.void_type != 0)
  519. return stab_push_defined_type (info, info->type_cache.void_type, 0);
  520. else
  521. {
  522. long tindex;
  523. char buf[40];
  524. tindex = info->type_index;
  525. ++info->type_index;
  526. info->type_cache.void_type = tindex;
  527. sprintf (buf, "%ld=%ld", tindex, tindex);
  528. return stab_push_string (info, buf, tindex, true, 0);
  529. }
  530. }
  531. /* Push an integer type. */
  532. static bool
  533. stab_int_type (void *p, unsigned int size, bool unsignedp)
  534. {
  535. struct stab_write_handle *info = (struct stab_write_handle *) p;
  536. long *cache;
  537. if (size <= 0 || (size > sizeof (long) && size != 8))
  538. {
  539. non_fatal (_("stab_int_type: bad size %u"), size);
  540. return false;
  541. }
  542. if (unsignedp)
  543. cache = info->type_cache.signed_integer_types;
  544. else
  545. cache = info->type_cache.unsigned_integer_types;
  546. if (cache[size - 1] != 0)
  547. return stab_push_defined_type (info, cache[size - 1], size);
  548. else
  549. {
  550. long tindex;
  551. char buf[100];
  552. tindex = info->type_index;
  553. ++info->type_index;
  554. cache[size - 1] = tindex;
  555. sprintf (buf, "%ld=r%ld;", tindex, tindex);
  556. if (unsignedp)
  557. {
  558. strcat (buf, "0;");
  559. if (size < sizeof (long))
  560. sprintf (buf + strlen (buf), "%ld;", ((long) 1 << (size * 8)) - 1);
  561. else if (size == sizeof (long))
  562. strcat (buf, "-1;");
  563. else if (size == 8)
  564. strcat (buf, "01777777777777777777777;");
  565. else
  566. abort ();
  567. }
  568. else
  569. {
  570. if (size <= sizeof (long))
  571. sprintf (buf + strlen (buf), "%ld;%ld;",
  572. (long) - ((unsigned long) 1 << (size * 8 - 1)),
  573. (long) (((unsigned long) 1 << (size * 8 - 1)) - 1));
  574. else if (size == 8)
  575. strcat (buf, "01000000000000000000000;0777777777777777777777;");
  576. else
  577. abort ();
  578. }
  579. return stab_push_string (info, buf, tindex, true, size);
  580. }
  581. }
  582. /* Push a floating point type. */
  583. static bool
  584. stab_float_type (void *p, unsigned int size)
  585. {
  586. struct stab_write_handle *info = (struct stab_write_handle *) p;
  587. if (size > 0
  588. && size - 1 < (sizeof info->type_cache.float_types
  589. / sizeof info->type_cache.float_types[0])
  590. && info->type_cache.float_types[size - 1] != 0)
  591. return stab_push_defined_type (info,
  592. info->type_cache.float_types[size - 1],
  593. size);
  594. else
  595. {
  596. long tindex;
  597. char *int_type;
  598. char buf[50];
  599. /* Floats are defined as a subrange of int. */
  600. if (! stab_int_type (info, 4, false))
  601. return false;
  602. int_type = stab_pop_type (info);
  603. tindex = info->type_index;
  604. ++info->type_index;
  605. if (size > 0
  606. && size - 1 < (sizeof info->type_cache.float_types
  607. / sizeof info->type_cache.float_types[0]))
  608. info->type_cache.float_types[size - 1] = tindex;
  609. sprintf (buf, "%ld=r%s;%u;0;", tindex, int_type, size);
  610. free (int_type);
  611. return stab_push_string (info, buf, tindex, true, size);
  612. }
  613. }
  614. /* Push a complex type. */
  615. static bool
  616. stab_complex_type (void *p, unsigned int size)
  617. {
  618. struct stab_write_handle *info = (struct stab_write_handle *) p;
  619. char buf[50];
  620. long tindex;
  621. tindex = info->type_index;
  622. ++info->type_index;
  623. sprintf (buf, "%ld=r%ld;%u;0;", tindex, tindex, size);
  624. return stab_push_string (info, buf, tindex, true, size * 2);
  625. }
  626. /* Push a bool type. We use an XCOFF predefined type, since gdb
  627. always recognizes them. */
  628. static bool
  629. stab_bool_type (void *p, unsigned int size)
  630. {
  631. struct stab_write_handle *info = (struct stab_write_handle *) p;
  632. long tindex;
  633. switch (size)
  634. {
  635. case 1:
  636. tindex = -21;
  637. break;
  638. case 2:
  639. tindex = -22;
  640. break;
  641. default:
  642. case 4:
  643. tindex = -16;
  644. break;
  645. case 8:
  646. tindex = -33;
  647. break;
  648. }
  649. return stab_push_defined_type (info, tindex, size);
  650. }
  651. /* Push an enum type. */
  652. static bool
  653. stab_enum_type (void *p, const char *tag, const char **names,
  654. bfd_signed_vma *vals)
  655. {
  656. struct stab_write_handle *info = (struct stab_write_handle *) p;
  657. size_t len;
  658. const char **pn;
  659. char *buf;
  660. long tindex = 0;
  661. bfd_signed_vma *pv;
  662. if (names == NULL)
  663. {
  664. if (tag == NULL)
  665. return false;
  666. buf = (char *) xmalloc (10 + strlen (tag));
  667. sprintf (buf, "xe%s:", tag);
  668. /* FIXME: The size is just a guess. */
  669. if (! stab_push_string (info, buf, 0, false, 4))
  670. return false;
  671. free (buf);
  672. return true;
  673. }
  674. len = 10;
  675. if (tag != NULL)
  676. len += strlen (tag);
  677. for (pn = names; *pn != NULL; pn++)
  678. len += strlen (*pn) + 20;
  679. buf = (char *) xmalloc (len);
  680. if (tag == NULL)
  681. strcpy (buf, "e");
  682. else
  683. {
  684. tindex = info->type_index;
  685. ++info->type_index;
  686. sprintf (buf, "%s:T%ld=e", tag, tindex);
  687. }
  688. for (pn = names, pv = vals; *pn != NULL; pn++, pv++)
  689. sprintf (buf + strlen (buf), "%s:%ld,", *pn, (long) *pv);
  690. strcat (buf, ";");
  691. if (tag == NULL)
  692. {
  693. /* FIXME: The size is just a guess. */
  694. if (! stab_push_string (info, buf, 0, false, 4))
  695. return false;
  696. }
  697. else
  698. {
  699. /* FIXME: The size is just a guess. */
  700. if (! stab_write_symbol (info, N_LSYM, 0, 0, buf)
  701. || ! stab_push_defined_type (info, tindex, 4))
  702. return false;
  703. }
  704. free (buf);
  705. return true;
  706. }
  707. /* Push a modification of the top type on the stack. Cache the
  708. results in CACHE and CACHE_ALLOC. */
  709. static bool
  710. stab_modify_type (struct stab_write_handle *info, int mod,
  711. unsigned int size, long **cache, size_t *cache_alloc)
  712. {
  713. long targindex;
  714. long tindex;
  715. char *s, *buf;
  716. if (info->type_stack == NULL)
  717. return false;
  718. targindex = info->type_stack->index;
  719. if (targindex <= 0
  720. || cache == NULL)
  721. {
  722. bool definition;
  723. /* Either the target type has no index, or we aren't caching
  724. this modifier. Either way we have no way of recording the
  725. new type, so we don't bother to define one. */
  726. definition = info->type_stack->definition;
  727. s = stab_pop_type (info);
  728. buf = (char *) xmalloc (strlen (s) + 2);
  729. sprintf (buf, "%c%s", mod, s);
  730. free (s);
  731. if (! stab_push_string (info, buf, 0, definition, size))
  732. return false;
  733. free (buf);
  734. }
  735. else
  736. {
  737. if ((size_t) targindex >= *cache_alloc)
  738. {
  739. size_t alloc;
  740. alloc = *cache_alloc;
  741. if (alloc == 0)
  742. alloc = 10;
  743. while ((size_t) targindex >= alloc)
  744. alloc *= 2;
  745. *cache = (long *) xrealloc (*cache, alloc * sizeof (long));
  746. memset (*cache + *cache_alloc, 0,
  747. (alloc - *cache_alloc) * sizeof (long));
  748. *cache_alloc = alloc;
  749. }
  750. tindex = (*cache)[targindex];
  751. if (tindex != 0 && ! info->type_stack->definition)
  752. {
  753. /* We have already defined a modification of this type, and
  754. the entry on the type stack is not a definition, so we
  755. can safely discard it (we may have a definition on the
  756. stack, even if we already defined a modification, if it
  757. is a struct which we did not define at the time it was
  758. referenced). */
  759. free (stab_pop_type (info));
  760. if (! stab_push_defined_type (info, tindex, size))
  761. return false;
  762. }
  763. else
  764. {
  765. tindex = info->type_index;
  766. ++info->type_index;
  767. s = stab_pop_type (info);
  768. buf = (char *) xmalloc (strlen (s) + 20);
  769. sprintf (buf, "%ld=%c%s", tindex, mod, s);
  770. free (s);
  771. (*cache)[targindex] = tindex;
  772. if (! stab_push_string (info, buf, tindex, true, size))
  773. return false;
  774. free (buf);
  775. }
  776. }
  777. return true;
  778. }
  779. /* Push a pointer type. */
  780. static bool
  781. stab_pointer_type (void *p)
  782. {
  783. struct stab_write_handle *info = (struct stab_write_handle *) p;
  784. /* FIXME: The size should depend upon the architecture. */
  785. return stab_modify_type (info, '*', 4, &info->type_cache.pointer_types,
  786. &info->type_cache.pointer_types_alloc);
  787. }
  788. /* Push a function type. */
  789. static bool
  790. stab_function_type (void *p, int argcount,
  791. bool varargs ATTRIBUTE_UNUSED)
  792. {
  793. struct stab_write_handle *info = (struct stab_write_handle *) p;
  794. int i;
  795. /* We have no way to represent the argument types, so we just
  796. discard them. However, if they define new types, we must output
  797. them. We do this by producing empty typedefs. */
  798. for (i = 0; i < argcount; i++)
  799. {
  800. if (! info->type_stack->definition)
  801. free (stab_pop_type (info));
  802. else
  803. {
  804. char *s, *buf;
  805. s = stab_pop_type (info);
  806. buf = (char *) xmalloc (strlen (s) + 3);
  807. sprintf (buf, ":t%s", s);
  808. free (s);
  809. if (! stab_write_symbol (info, N_LSYM, 0, 0, buf))
  810. return false;
  811. free (buf);
  812. }
  813. }
  814. return stab_modify_type (info, 'f', 0, &info->type_cache.function_types,
  815. &info->type_cache.function_types_alloc);
  816. }
  817. /* Push a reference type. */
  818. static bool
  819. stab_reference_type (void *p)
  820. {
  821. struct stab_write_handle *info = (struct stab_write_handle *) p;
  822. /* FIXME: The size should depend upon the architecture. */
  823. return stab_modify_type (info, '&', 4, &info->type_cache.reference_types,
  824. &info->type_cache.reference_types_alloc);
  825. }
  826. /* Push a range type. */
  827. static bool
  828. stab_range_type (void *p, bfd_signed_vma low, bfd_signed_vma high)
  829. {
  830. struct stab_write_handle *info = (struct stab_write_handle *) p;
  831. bool definition;
  832. unsigned int size;
  833. char *s, *buf;
  834. definition = info->type_stack->definition;
  835. size = info->type_stack->size;
  836. s = stab_pop_type (info);
  837. buf = (char *) xmalloc (strlen (s) + 100);
  838. sprintf (buf, "r%s;%ld;%ld;", s, (long) low, (long) high);
  839. free (s);
  840. if (! stab_push_string (info, buf, 0, definition, size))
  841. return false;
  842. free (buf);
  843. return true;
  844. }
  845. /* Push an array type. */
  846. static bool
  847. stab_array_type (void *p, bfd_signed_vma low, bfd_signed_vma high,
  848. bool stringp)
  849. {
  850. struct stab_write_handle *info = (struct stab_write_handle *) p;
  851. bool definition;
  852. unsigned int element_size;
  853. char *range, *element, *buf;
  854. long tindex;
  855. unsigned int size;
  856. definition = info->type_stack->definition;
  857. range = stab_pop_type (info);
  858. definition = definition || info->type_stack->definition;
  859. element_size = info->type_stack->size;
  860. element = stab_pop_type (info);
  861. buf = (char *) xmalloc (strlen (range) + strlen (element) + 100);
  862. if (! stringp)
  863. {
  864. tindex = 0;
  865. *buf = '\0';
  866. }
  867. else
  868. {
  869. /* We need to define a type in order to include the string
  870. attribute. */
  871. tindex = info->type_index;
  872. ++info->type_index;
  873. definition = true;
  874. sprintf (buf, "%ld=@S;", tindex);
  875. }
  876. sprintf (buf + strlen (buf), "ar%s;%ld;%ld;%s",
  877. range, (long) low, (long) high, element);
  878. free (range);
  879. free (element);
  880. if (high < low)
  881. size = 0;
  882. else
  883. size = element_size * ((high - low) + 1);
  884. if (! stab_push_string (info, buf, tindex, definition, size))
  885. return false;
  886. free (buf);
  887. return true;
  888. }
  889. /* Push a set type. */
  890. static bool
  891. stab_set_type (void *p, bool bitstringp)
  892. {
  893. struct stab_write_handle *info = (struct stab_write_handle *) p;
  894. bool definition;
  895. char *s, *buf;
  896. long tindex;
  897. definition = info->type_stack->definition;
  898. s = stab_pop_type (info);
  899. buf = (char *) xmalloc (strlen (s) + 30);
  900. if (! bitstringp)
  901. {
  902. *buf = '\0';
  903. tindex = 0;
  904. }
  905. else
  906. {
  907. /* We need to define a type in order to include the string
  908. attribute. */
  909. tindex = info->type_index;
  910. ++info->type_index;
  911. definition = true;
  912. sprintf (buf, "%ld=@S;", tindex);
  913. }
  914. sprintf (buf + strlen (buf), "S%s", s);
  915. free (s);
  916. if (! stab_push_string (info, buf, tindex, definition, 0))
  917. return false;
  918. free (buf);
  919. return true;
  920. }
  921. /* Push an offset type. */
  922. static bool
  923. stab_offset_type (void *p)
  924. {
  925. struct stab_write_handle *info = (struct stab_write_handle *) p;
  926. bool definition;
  927. char *target, *base, *buf;
  928. definition = info->type_stack->definition;
  929. target = stab_pop_type (info);
  930. definition = definition || info->type_stack->definition;
  931. base = stab_pop_type (info);
  932. buf = (char *) xmalloc (strlen (target) + strlen (base) + 3);
  933. sprintf (buf, "@%s,%s", base, target);
  934. free (base);
  935. free (target);
  936. if (! stab_push_string (info, buf, 0, definition, 0))
  937. return false;
  938. free (buf);
  939. return true;
  940. }
  941. /* Push a method type. */
  942. static bool
  943. stab_method_type (void *p, bool domainp, int argcount,
  944. bool varargs)
  945. {
  946. struct stab_write_handle *info = (struct stab_write_handle *) p;
  947. bool definition;
  948. char *domain, *return_type, *buf;
  949. char **args;
  950. int i;
  951. size_t len;
  952. /* We don't bother with stub method types, because that would
  953. require a mangler for C++ argument types. This will waste space
  954. in the debugging output. */
  955. /* We need a domain. I'm not sure DOMAINP can ever be false,
  956. anyhow. */
  957. if (! domainp)
  958. {
  959. if (! stab_empty_type (p))
  960. return false;
  961. }
  962. definition = info->type_stack->definition;
  963. domain = stab_pop_type (info);
  964. /* A non-varargs function is indicated by making the last parameter
  965. type be void. */
  966. if (argcount < 0)
  967. {
  968. args = NULL;
  969. argcount = 0;
  970. }
  971. else if (argcount == 0)
  972. {
  973. if (varargs)
  974. args = NULL;
  975. else
  976. {
  977. args = (char **) xmalloc (1 * sizeof (*args));
  978. if (! stab_empty_type (p))
  979. return false;
  980. definition = definition || info->type_stack->definition;
  981. args[0] = stab_pop_type (info);
  982. argcount = 1;
  983. }
  984. }
  985. else
  986. {
  987. args = (char **) xmalloc ((argcount + 1) * sizeof (*args));
  988. for (i = argcount - 1; i >= 0; i--)
  989. {
  990. definition = definition || info->type_stack->definition;
  991. args[i] = stab_pop_type (info);
  992. }
  993. if (! varargs)
  994. {
  995. if (! stab_empty_type (p))
  996. return false;
  997. definition = definition || info->type_stack->definition;
  998. args[argcount] = stab_pop_type (info);
  999. ++argcount;
  1000. }
  1001. }
  1002. definition = definition || info->type_stack->definition;
  1003. return_type = stab_pop_type (info);
  1004. len = strlen (domain) + strlen (return_type) + 10;
  1005. for (i = 0; i < argcount; i++)
  1006. len += strlen (args[i]);
  1007. buf = (char *) xmalloc (len);
  1008. sprintf (buf, "#%s,%s", domain, return_type);
  1009. free (domain);
  1010. free (return_type);
  1011. for (i = 0; i < argcount; i++)
  1012. {
  1013. strcat (buf, ",");
  1014. strcat (buf, args[i]);
  1015. free (args[i]);
  1016. }
  1017. strcat (buf, ";");
  1018. free (args);
  1019. if (! stab_push_string (info, buf, 0, definition, 0))
  1020. return false;
  1021. free (buf);
  1022. return true;
  1023. }
  1024. /* Push a const version of a type. */
  1025. static bool
  1026. stab_const_type (void *p)
  1027. {
  1028. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1029. return stab_modify_type (info, 'k', info->type_stack->size,
  1030. (long **) NULL, (size_t *) NULL);
  1031. }
  1032. /* Push a volatile version of a type. */
  1033. static bool
  1034. stab_volatile_type (void *p)
  1035. {
  1036. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1037. return stab_modify_type (info, 'B', info->type_stack->size,
  1038. (long **) NULL, (size_t *) NULL);
  1039. }
  1040. /* Get the type index to use for a struct/union/class ID. This should
  1041. return -1 if it fails. */
  1042. static long
  1043. stab_get_struct_index (struct stab_write_handle *info, const char *tag,
  1044. unsigned int id, enum debug_type_kind kind,
  1045. unsigned int *psize)
  1046. {
  1047. if (id >= info->type_cache.struct_types_alloc)
  1048. {
  1049. size_t alloc;
  1050. alloc = info->type_cache.struct_types_alloc;
  1051. if (alloc == 0)
  1052. alloc = 10;
  1053. while (id >= alloc)
  1054. alloc *= 2;
  1055. info->type_cache.struct_types =
  1056. (struct stab_tag *) xrealloc (info->type_cache.struct_types,
  1057. alloc * sizeof (struct stab_tag));
  1058. memset ((info->type_cache.struct_types
  1059. + info->type_cache.struct_types_alloc),
  1060. 0,
  1061. ((alloc - info->type_cache.struct_types_alloc)
  1062. * sizeof (struct stab_tag)));
  1063. info->type_cache.struct_types_alloc = alloc;
  1064. }
  1065. if (info->type_cache.struct_types[id].index == 0)
  1066. {
  1067. info->type_cache.struct_types[id].index = info->type_index;
  1068. ++info->type_index;
  1069. info->type_cache.struct_types[id].tag = tag;
  1070. info->type_cache.struct_types[id].kind = kind;
  1071. }
  1072. if (kind == DEBUG_KIND_ILLEGAL)
  1073. {
  1074. /* This is a definition of the struct. */
  1075. info->type_cache.struct_types[id].kind = kind;
  1076. info->type_cache.struct_types[id].size = *psize;
  1077. }
  1078. else
  1079. *psize = info->type_cache.struct_types[id].size;
  1080. return info->type_cache.struct_types[id].index;
  1081. }
  1082. /* Start outputting a struct. We ignore the tag, and handle it in
  1083. stab_tag. */
  1084. static bool
  1085. stab_start_struct_type (void *p, const char *tag, unsigned int id,
  1086. bool structp, unsigned int size)
  1087. {
  1088. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1089. long tindex;
  1090. bool definition;
  1091. char buf[40];
  1092. if (id == 0)
  1093. {
  1094. tindex = 0;
  1095. *buf = '\0';
  1096. definition = false;
  1097. }
  1098. else
  1099. {
  1100. tindex = stab_get_struct_index (info, tag, id, DEBUG_KIND_ILLEGAL,
  1101. &size);
  1102. if (tindex < 0)
  1103. return false;
  1104. sprintf (buf, "%ld=", tindex);
  1105. definition = true;
  1106. }
  1107. sprintf (buf + strlen (buf), "%c%u",
  1108. structp ? 's' : 'u',
  1109. size);
  1110. if (! stab_push_string (info, buf, tindex, definition, size))
  1111. return false;
  1112. info->type_stack->fields = (char *) xmalloc (1);
  1113. info->type_stack->fields[0] = '\0';
  1114. return true;
  1115. }
  1116. /* Add a field to a struct. */
  1117. static bool
  1118. stab_struct_field (void *p, const char *name, bfd_vma bitpos,
  1119. bfd_vma bitsize, enum debug_visibility visibility)
  1120. {
  1121. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1122. bool definition;
  1123. unsigned int size;
  1124. char *s, *n;
  1125. const char *vis;
  1126. definition = info->type_stack->definition;
  1127. size = info->type_stack->size;
  1128. s = stab_pop_type (info);
  1129. /* Add this field to the end of the current struct fields, which is
  1130. currently on the top of the stack. */
  1131. if (info->type_stack->fields == NULL)
  1132. return false;
  1133. n = (char *) xmalloc (strlen (info->type_stack->fields)
  1134. + strlen (name)
  1135. + strlen (s)
  1136. + 50);
  1137. switch (visibility)
  1138. {
  1139. default:
  1140. abort ();
  1141. case DEBUG_VISIBILITY_PUBLIC:
  1142. vis = "";
  1143. break;
  1144. case DEBUG_VISIBILITY_PRIVATE:
  1145. vis = "/0";
  1146. break;
  1147. case DEBUG_VISIBILITY_PROTECTED:
  1148. vis = "/1";
  1149. break;
  1150. }
  1151. if (bitsize == 0)
  1152. {
  1153. bitsize = size * 8;
  1154. if (bitsize == 0)
  1155. non_fatal (_("%s: warning: unknown size for field `%s' in struct"),
  1156. bfd_get_filename (info->abfd), name);
  1157. }
  1158. sprintf (n, "%s%s:%s%s,%ld,%ld;", info->type_stack->fields, name, vis, s,
  1159. (long) bitpos, (long) bitsize);
  1160. free (info->type_stack->fields);
  1161. info->type_stack->fields = n;
  1162. if (definition)
  1163. info->type_stack->definition = true;
  1164. return true;
  1165. }
  1166. /* Finish up a struct. */
  1167. static bool
  1168. stab_end_struct_type (void *p)
  1169. {
  1170. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1171. bool definition;
  1172. long tindex;
  1173. unsigned int size;
  1174. char *fields, *first, *buf;
  1175. if (info->type_stack == NULL || info->type_stack->fields == NULL)
  1176. return false;
  1177. definition = info->type_stack->definition;
  1178. tindex = info->type_stack->index;
  1179. size = info->type_stack->size;
  1180. fields = info->type_stack->fields;
  1181. first = stab_pop_type (info);
  1182. buf = (char *) xmalloc (strlen (first) + strlen (fields) + 2);
  1183. sprintf (buf, "%s%s;", first, fields);
  1184. free (first);
  1185. free (fields);
  1186. if (! stab_push_string (info, buf, tindex, definition, size))
  1187. return false;
  1188. free (buf);
  1189. return true;
  1190. }
  1191. /* Start outputting a class. */
  1192. static bool
  1193. stab_start_class_type (void *p, const char *tag, unsigned int id,
  1194. bool structp, unsigned int size,
  1195. bool vptr, bool ownvptr)
  1196. {
  1197. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1198. bool definition = false;
  1199. char *vstring = NULL;
  1200. if (vptr && !ownvptr)
  1201. {
  1202. definition = info->type_stack->definition;
  1203. vstring = stab_pop_type (info);
  1204. }
  1205. if (! stab_start_struct_type (p, tag, id, structp, size))
  1206. return false;
  1207. if (vptr)
  1208. {
  1209. char *vtable;
  1210. if (ownvptr)
  1211. {
  1212. if (info->type_stack->index < 1)
  1213. return false;
  1214. vtable = (char *) xmalloc (20);
  1215. sprintf (vtable, "~%%%ld", info->type_stack->index);
  1216. }
  1217. else
  1218. {
  1219. if (vstring == NULL)
  1220. return false;
  1221. vtable = (char *) xmalloc (strlen (vstring) + 3);
  1222. sprintf (vtable, "~%%%s", vstring);
  1223. free (vstring);
  1224. if (definition)
  1225. info->type_stack->definition = true;
  1226. }
  1227. info->type_stack->vtable = vtable;
  1228. }
  1229. return true;
  1230. }
  1231. /* Add a static member to the class on the type stack. */
  1232. static bool
  1233. stab_class_static_member (void *p, const char *name, const char *physname,
  1234. enum debug_visibility visibility)
  1235. {
  1236. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1237. bool definition;
  1238. char *s, *n;
  1239. const char *vis;
  1240. definition = info->type_stack->definition;
  1241. s = stab_pop_type (info);
  1242. /* Add this field to the end of the current struct fields, which is
  1243. currently on the top of the stack. */
  1244. if (info->type_stack->fields == NULL)
  1245. return false;
  1246. n = (char *) xmalloc (strlen (info->type_stack->fields)
  1247. + strlen (name)
  1248. + strlen (s)
  1249. + strlen (physname)
  1250. + 10);
  1251. switch (visibility)
  1252. {
  1253. default:
  1254. abort ();
  1255. case DEBUG_VISIBILITY_PUBLIC:
  1256. vis = "";
  1257. break;
  1258. case DEBUG_VISIBILITY_PRIVATE:
  1259. vis = "/0";
  1260. break;
  1261. case DEBUG_VISIBILITY_PROTECTED:
  1262. vis = "/1";
  1263. break;
  1264. }
  1265. sprintf (n, "%s%s:%s%s:%s;", info->type_stack->fields, name, vis, s,
  1266. physname);
  1267. free (info->type_stack->fields);
  1268. info->type_stack->fields = n;
  1269. if (definition)
  1270. info->type_stack->definition = true;
  1271. return true;
  1272. }
  1273. /* Add a base class to the class on the type stack. */
  1274. static bool
  1275. stab_class_baseclass (void *p, bfd_vma bitpos, bool is_virtual,
  1276. enum debug_visibility visibility)
  1277. {
  1278. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1279. bool definition;
  1280. char *s;
  1281. char *buf;
  1282. unsigned int c;
  1283. char **baseclasses;
  1284. definition = info->type_stack->definition;
  1285. s = stab_pop_type (info);
  1286. /* Build the base class specifier. */
  1287. buf = (char *) xmalloc (strlen (s) + 25);
  1288. buf[0] = is_virtual ? '1' : '0';
  1289. switch (visibility)
  1290. {
  1291. default:
  1292. abort ();
  1293. case DEBUG_VISIBILITY_PRIVATE:
  1294. buf[1] = '0';
  1295. break;
  1296. case DEBUG_VISIBILITY_PROTECTED:
  1297. buf[1] = '1';
  1298. break;
  1299. case DEBUG_VISIBILITY_PUBLIC:
  1300. buf[1] = '2';
  1301. break;
  1302. }
  1303. sprintf (buf + 2, "%ld,%s;", (long) bitpos, s);
  1304. free (s);
  1305. /* Add the new baseclass to the existing ones. */
  1306. if (info->type_stack == NULL || info->type_stack->fields == NULL)
  1307. return false;
  1308. if (info->type_stack->baseclasses == NULL)
  1309. c = 0;
  1310. else
  1311. {
  1312. c = 0;
  1313. while (info->type_stack->baseclasses[c] != NULL)
  1314. ++c;
  1315. }
  1316. baseclasses = (char **) xrealloc (info->type_stack->baseclasses,
  1317. (c + 2) * sizeof (*baseclasses));
  1318. baseclasses[c] = buf;
  1319. baseclasses[c + 1] = NULL;
  1320. info->type_stack->baseclasses = baseclasses;
  1321. if (definition)
  1322. info->type_stack->definition = true;
  1323. return true;
  1324. }
  1325. /* Start adding a method to the class on the type stack. */
  1326. static bool
  1327. stab_class_start_method (void *p, const char *name)
  1328. {
  1329. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1330. char *m;
  1331. if (info->type_stack == NULL || info->type_stack->fields == NULL)
  1332. return false;
  1333. if (info->type_stack->methods == NULL)
  1334. {
  1335. m = (char *) xmalloc (strlen (name) + 3);
  1336. *m = '\0';
  1337. }
  1338. else
  1339. {
  1340. m = (char *) xrealloc (info->type_stack->methods,
  1341. (strlen (info->type_stack->methods)
  1342. + strlen (name)
  1343. + 4));
  1344. }
  1345. sprintf (m + strlen (m), "%s::", name);
  1346. info->type_stack->methods = m;
  1347. return true;
  1348. }
  1349. /* Add a variant, either static or not, to the current method. */
  1350. static bool
  1351. stab_class_method_var (struct stab_write_handle *info, const char *physname,
  1352. enum debug_visibility visibility,
  1353. bool staticp, bool constp,
  1354. bool volatilep, bfd_vma voffset,
  1355. bool contextp)
  1356. {
  1357. bool definition;
  1358. char *type;
  1359. char *context = NULL;
  1360. char visc, qualc, typec;
  1361. definition = info->type_stack->definition;
  1362. type = stab_pop_type (info);
  1363. if (contextp)
  1364. {
  1365. definition = definition || info->type_stack->definition;
  1366. context = stab_pop_type (info);
  1367. }
  1368. if (info->type_stack == NULL || info->type_stack->methods == NULL)
  1369. return false;
  1370. switch (visibility)
  1371. {
  1372. default:
  1373. abort ();
  1374. case DEBUG_VISIBILITY_PRIVATE:
  1375. visc = '0';
  1376. break;
  1377. case DEBUG_VISIBILITY_PROTECTED:
  1378. visc = '1';
  1379. break;
  1380. case DEBUG_VISIBILITY_PUBLIC:
  1381. visc = '2';
  1382. break;
  1383. }
  1384. if (constp)
  1385. {
  1386. if (volatilep)
  1387. qualc = 'D';
  1388. else
  1389. qualc = 'B';
  1390. }
  1391. else
  1392. {
  1393. if (volatilep)
  1394. qualc = 'C';
  1395. else
  1396. qualc = 'A';
  1397. }
  1398. if (staticp)
  1399. typec = '?';
  1400. else if (! contextp)
  1401. typec = '.';
  1402. else
  1403. typec = '*';
  1404. info->type_stack->methods =
  1405. (char *) xrealloc (info->type_stack->methods,
  1406. (strlen (info->type_stack->methods)
  1407. + strlen (type)
  1408. + strlen (physname)
  1409. + (contextp ? strlen (context) : 0)
  1410. + 40));
  1411. sprintf (info->type_stack->methods + strlen (info->type_stack->methods),
  1412. "%s:%s;%c%c%c", type, physname, visc, qualc, typec);
  1413. free (type);
  1414. if (contextp)
  1415. {
  1416. sprintf (info->type_stack->methods + strlen (info->type_stack->methods),
  1417. "%ld;%s;", (long) voffset, context);
  1418. free (context);
  1419. }
  1420. if (definition)
  1421. info->type_stack->definition = true;
  1422. return true;
  1423. }
  1424. /* Add a variant to the current method. */
  1425. static bool
  1426. stab_class_method_variant (void *p, const char *physname,
  1427. enum debug_visibility visibility,
  1428. bool constp, bool volatilep,
  1429. bfd_vma voffset, bool contextp)
  1430. {
  1431. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1432. return stab_class_method_var (info, physname, visibility, false, constp,
  1433. volatilep, voffset, contextp);
  1434. }
  1435. /* Add a static variant to the current method. */
  1436. static bool
  1437. stab_class_static_method_variant (void *p, const char *physname,
  1438. enum debug_visibility visibility,
  1439. bool constp, bool volatilep)
  1440. {
  1441. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1442. return stab_class_method_var (info, physname, visibility, true, constp,
  1443. volatilep, 0, false);
  1444. }
  1445. /* Finish up a method. */
  1446. static bool
  1447. stab_class_end_method (void *p)
  1448. {
  1449. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1450. if (info->type_stack == NULL || info->type_stack->methods == NULL)
  1451. return false;
  1452. /* We allocated enough room on info->type_stack->methods to add the
  1453. trailing semicolon. */
  1454. strcat (info->type_stack->methods, ";");
  1455. return true;
  1456. }
  1457. /* Finish up a class. */
  1458. static bool
  1459. stab_end_class_type (void *p)
  1460. {
  1461. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1462. size_t len;
  1463. unsigned int i = 0;
  1464. char *buf;
  1465. if (info->type_stack == NULL
  1466. || info->type_stack->string == NULL
  1467. || info->type_stack->fields == NULL)
  1468. return false;
  1469. /* Work out the size we need to allocate for the class definition. */
  1470. len = (strlen (info->type_stack->string)
  1471. + strlen (info->type_stack->fields)
  1472. + 10);
  1473. if (info->type_stack->baseclasses != NULL)
  1474. {
  1475. len += 20;
  1476. for (i = 0; info->type_stack->baseclasses[i] != NULL; i++)
  1477. len += strlen (info->type_stack->baseclasses[i]);
  1478. }
  1479. if (info->type_stack->methods != NULL)
  1480. len += strlen (info->type_stack->methods);
  1481. if (info->type_stack->vtable != NULL)
  1482. len += strlen (info->type_stack->vtable);
  1483. /* Build the class definition. */
  1484. buf = (char *) xmalloc (len);
  1485. strcpy (buf, info->type_stack->string);
  1486. if (info->type_stack->baseclasses != NULL)
  1487. {
  1488. sprintf (buf + strlen (buf), "!%u,", i);
  1489. for (i = 0; info->type_stack->baseclasses[i] != NULL; i++)
  1490. {
  1491. strcat (buf, info->type_stack->baseclasses[i]);
  1492. free (info->type_stack->baseclasses[i]);
  1493. }
  1494. free (info->type_stack->baseclasses);
  1495. info->type_stack->baseclasses = NULL;
  1496. }
  1497. strcat (buf, info->type_stack->fields);
  1498. free (info->type_stack->fields);
  1499. info->type_stack->fields = NULL;
  1500. if (info->type_stack->methods != NULL)
  1501. {
  1502. strcat (buf, info->type_stack->methods);
  1503. free (info->type_stack->methods);
  1504. info->type_stack->methods = NULL;
  1505. }
  1506. strcat (buf, ";");
  1507. if (info->type_stack->vtable != NULL)
  1508. {
  1509. strcat (buf, info->type_stack->vtable);
  1510. free (info->type_stack->vtable);
  1511. info->type_stack->vtable = NULL;
  1512. }
  1513. /* Replace the string on the top of the stack with the complete
  1514. class definition. */
  1515. free (info->type_stack->string);
  1516. info->type_stack->string = buf;
  1517. return true;
  1518. }
  1519. /* Push a typedef which was previously defined. */
  1520. static bool
  1521. stab_typedef_type (void *p, const char *name)
  1522. {
  1523. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1524. struct string_hash_entry *h;
  1525. h = string_hash_lookup (&info->typedef_hash, name, false, false);
  1526. if (h == NULL || h->index < 1)
  1527. return false;
  1528. return stab_push_defined_type (info, h->index, h->size);
  1529. }
  1530. /* Push a struct, union or class tag. */
  1531. static bool
  1532. stab_tag_type (void *p, const char *name, unsigned int id,
  1533. enum debug_type_kind kind)
  1534. {
  1535. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1536. long tindex;
  1537. unsigned int size = 0;
  1538. tindex = stab_get_struct_index (info, name, id, kind, &size);
  1539. if (tindex < 0)
  1540. return false;
  1541. return stab_push_defined_type (info, tindex, size);
  1542. }
  1543. /* Define a typedef. */
  1544. static bool
  1545. stab_typdef (void *p, const char *name)
  1546. {
  1547. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1548. long tindex;
  1549. unsigned int size;
  1550. char *s, *buf;
  1551. struct string_hash_entry *h;
  1552. tindex = info->type_stack->index;
  1553. size = info->type_stack->size;
  1554. s = stab_pop_type (info);
  1555. buf = (char *) xmalloc (strlen (name) + strlen (s) + 20);
  1556. if (tindex > 0)
  1557. sprintf (buf, "%s:t%s", name, s);
  1558. else
  1559. {
  1560. tindex = info->type_index;
  1561. ++info->type_index;
  1562. sprintf (buf, "%s:t%ld=%s", name, tindex, s);
  1563. }
  1564. free (s);
  1565. if (! stab_write_symbol (info, N_LSYM, 0, 0, buf))
  1566. return false;
  1567. free (buf);
  1568. h = string_hash_lookup (&info->typedef_hash, name, true, false);
  1569. if (h == NULL)
  1570. {
  1571. non_fatal (_("string_hash_lookup failed: %s"),
  1572. bfd_errmsg (bfd_get_error ()));
  1573. return false;
  1574. }
  1575. /* I don't think we care about redefinitions. */
  1576. h->index = tindex;
  1577. h->size = size;
  1578. return true;
  1579. }
  1580. /* Define a tag. */
  1581. static bool
  1582. stab_tag (void *p, const char *tag)
  1583. {
  1584. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1585. char *s, *buf;
  1586. s = stab_pop_type (info);
  1587. buf = (char *) xmalloc (strlen (tag) + strlen (s) + 3);
  1588. sprintf (buf, "%s:T%s", tag, s);
  1589. free (s);
  1590. if (! stab_write_symbol (info, N_LSYM, 0, 0, buf))
  1591. return false;
  1592. free (buf);
  1593. return true;
  1594. }
  1595. /* Define an integer constant. */
  1596. static bool
  1597. stab_int_constant (void *p, const char *name, bfd_vma val)
  1598. {
  1599. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1600. char *buf;
  1601. buf = (char *) xmalloc (strlen (name) + 20);
  1602. sprintf (buf, "%s:c=i%ld", name, (long) val);
  1603. if (! stab_write_symbol (info, N_LSYM, 0, 0, buf))
  1604. return false;
  1605. free (buf);
  1606. return true;
  1607. }
  1608. /* Define a floating point constant. */
  1609. static bool
  1610. stab_float_constant (void *p, const char *name, double val)
  1611. {
  1612. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1613. char *buf;
  1614. buf = (char *) xmalloc (strlen (name) + 20);
  1615. sprintf (buf, "%s:c=f%g", name, val);
  1616. if (! stab_write_symbol (info, N_LSYM, 0, 0, buf))
  1617. return false;
  1618. free (buf);
  1619. return true;
  1620. }
  1621. /* Define a typed constant. */
  1622. static bool
  1623. stab_typed_constant (void *p, const char *name, bfd_vma val)
  1624. {
  1625. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1626. char *s, *buf;
  1627. s = stab_pop_type (info);
  1628. buf = (char *) xmalloc (strlen (name) + strlen (s) + 20);
  1629. sprintf (buf, "%s:c=e%s,%ld", name, s, (long) val);
  1630. free (s);
  1631. if (! stab_write_symbol (info, N_LSYM, 0, 0, buf))
  1632. return false;
  1633. free (buf);
  1634. return true;
  1635. }
  1636. /* Record a variable. */
  1637. static bool
  1638. stab_variable (void *p, const char *name, enum debug_var_kind kind,
  1639. bfd_vma val)
  1640. {
  1641. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1642. char *s, *buf;
  1643. int stab_type;
  1644. const char *kindstr;
  1645. s = stab_pop_type (info);
  1646. switch (kind)
  1647. {
  1648. default:
  1649. abort ();
  1650. case DEBUG_GLOBAL:
  1651. stab_type = N_GSYM;
  1652. kindstr = "G";
  1653. break;
  1654. case DEBUG_STATIC:
  1655. stab_type = N_STSYM;
  1656. kindstr = "S";
  1657. break;
  1658. case DEBUG_LOCAL_STATIC:
  1659. stab_type = N_STSYM;
  1660. kindstr = "V";
  1661. break;
  1662. case DEBUG_LOCAL:
  1663. stab_type = N_LSYM;
  1664. kindstr = "";
  1665. /* Make sure that this is a type reference or definition. */
  1666. if (! ISDIGIT (*s))
  1667. {
  1668. char *n;
  1669. long tindex;
  1670. tindex = info->type_index;
  1671. ++info->type_index;
  1672. n = (char *) xmalloc (strlen (s) + 20);
  1673. sprintf (n, "%ld=%s", tindex, s);
  1674. free (s);
  1675. s = n;
  1676. }
  1677. break;
  1678. case DEBUG_REGISTER:
  1679. stab_type = N_RSYM;
  1680. kindstr = "r";
  1681. break;
  1682. }
  1683. buf = (char *) xmalloc (strlen (name) + strlen (s) + 3);
  1684. sprintf (buf, "%s:%s%s", name, kindstr, s);
  1685. free (s);
  1686. if (! stab_write_symbol (info, stab_type, 0, val, buf))
  1687. return false;
  1688. free (buf);
  1689. return true;
  1690. }
  1691. /* Start outputting a function. */
  1692. static bool
  1693. stab_start_function (void *p, const char *name, bool globalp)
  1694. {
  1695. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1696. char *rettype, *buf;
  1697. if (info->nesting != 0 || info->fun_offset != -1)
  1698. return false;
  1699. rettype = stab_pop_type (info);
  1700. buf = (char *) xmalloc (strlen (name) + strlen (rettype) + 3);
  1701. sprintf (buf, "%s:%c%s", name,
  1702. globalp ? 'F' : 'f',
  1703. rettype);
  1704. /* We don't know the value now, so we set it in start_block. */
  1705. info->fun_offset = info->symbols_size;
  1706. if (! stab_write_symbol (info, N_FUN, 0, 0, buf))
  1707. return false;
  1708. free (buf);
  1709. return true;
  1710. }
  1711. /* Output a function parameter. */
  1712. static bool
  1713. stab_function_parameter (void *p, const char *name, enum debug_parm_kind kind, bfd_vma val)
  1714. {
  1715. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1716. char *s, *buf;
  1717. int stab_type;
  1718. char kindc;
  1719. s = stab_pop_type (info);
  1720. switch (kind)
  1721. {
  1722. default:
  1723. abort ();
  1724. case DEBUG_PARM_STACK:
  1725. stab_type = N_PSYM;
  1726. kindc = 'p';
  1727. break;
  1728. case DEBUG_PARM_REG:
  1729. stab_type = N_RSYM;
  1730. kindc = 'P';
  1731. break;
  1732. case DEBUG_PARM_REFERENCE:
  1733. stab_type = N_PSYM;
  1734. kindc = 'v';
  1735. break;
  1736. case DEBUG_PARM_REF_REG:
  1737. stab_type = N_RSYM;
  1738. kindc = 'a';
  1739. break;
  1740. }
  1741. buf = (char *) xmalloc (strlen (name) + strlen (s) + 3);
  1742. sprintf (buf, "%s:%c%s", name, kindc, s);
  1743. free (s);
  1744. if (! stab_write_symbol (info, stab_type, 0, val, buf))
  1745. return false;
  1746. free (buf);
  1747. return true;
  1748. }
  1749. /* Start a block. */
  1750. static bool
  1751. stab_start_block (void *p, bfd_vma addr)
  1752. {
  1753. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1754. /* Fill in any slots which have been waiting for the first known
  1755. text address. */
  1756. if (info->so_offset != -1)
  1757. {
  1758. bfd_put_32 (info->abfd, addr, info->symbols + info->so_offset + 8);
  1759. info->so_offset = -1;
  1760. }
  1761. if (info->fun_offset != -1)
  1762. {
  1763. bfd_put_32 (info->abfd, addr, info->symbols + info->fun_offset + 8);
  1764. info->fun_offset = -1;
  1765. }
  1766. ++info->nesting;
  1767. /* We will be called with a top level block surrounding the
  1768. function, but stabs information does not output that block, so we
  1769. ignore it. */
  1770. if (info->nesting == 1)
  1771. {
  1772. info->fnaddr = addr;
  1773. return true;
  1774. }
  1775. /* We have to output the LBRAC symbol after any variables which are
  1776. declared inside the block. We postpone the LBRAC until the next
  1777. start_block or end_block. */
  1778. /* If we have postponed an LBRAC, output it now. */
  1779. if (info->pending_lbrac != (bfd_vma) -1)
  1780. {
  1781. if (! stab_write_symbol (info, N_LBRAC, 0, info->pending_lbrac,
  1782. (const char *) NULL))
  1783. return false;
  1784. }
  1785. /* Remember the address and output it later. */
  1786. info->pending_lbrac = addr - info->fnaddr;
  1787. return true;
  1788. }
  1789. /* End a block. */
  1790. static bool
  1791. stab_end_block (void *p, bfd_vma addr)
  1792. {
  1793. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1794. if (addr > info->last_text_address)
  1795. info->last_text_address = addr;
  1796. /* If we have postponed an LBRAC, output it now. */
  1797. if (info->pending_lbrac != (bfd_vma) -1)
  1798. {
  1799. if (! stab_write_symbol (info, N_LBRAC, 0, info->pending_lbrac,
  1800. (const char *) NULL))
  1801. return false;
  1802. info->pending_lbrac = (bfd_vma) -1;
  1803. }
  1804. if (info->nesting < 1)
  1805. return false;
  1806. --info->nesting;
  1807. /* We ignore the outermost block. */
  1808. if (info->nesting == 0)
  1809. return true;
  1810. return stab_write_symbol (info, N_RBRAC, 0, addr - info->fnaddr,
  1811. (const char *) NULL);
  1812. }
  1813. /* End a function. */
  1814. static bool
  1815. stab_end_function (void *p ATTRIBUTE_UNUSED)
  1816. {
  1817. return true;
  1818. }
  1819. /* Output a line number. */
  1820. static bool
  1821. stab_lineno (void *p, const char *file, unsigned long lineno, bfd_vma addr)
  1822. {
  1823. struct stab_write_handle *info = (struct stab_write_handle *) p;
  1824. if (info->lineno_filename == NULL)
  1825. return false;
  1826. if (addr > info->last_text_address)
  1827. info->last_text_address = addr;
  1828. if (filename_cmp (file, info->lineno_filename) != 0)
  1829. {
  1830. if (! stab_write_symbol (info, N_SOL, 0, addr, file))
  1831. return false;
  1832. info->lineno_filename = file;
  1833. }
  1834. return stab_write_symbol (info, N_SLINE, lineno, addr - info->fnaddr,
  1835. (const char *) NULL);
  1836. }