dbxout.c 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840
  1. /* Output dbx-format symbol table information from GNU compiler.
  2. Copyright (C) 1987-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. /* Output dbx-format symbol table data.
  16. This consists of many symbol table entries, each of them
  17. a .stabs assembler pseudo-op with four operands:
  18. a "name" which is really a description of one symbol and its type,
  19. a "code", which is a symbol defined in stab.h whose name starts with N_,
  20. an unused operand always 0,
  21. and a "value" which is an address or an offset.
  22. The name is enclosed in doublequote characters.
  23. Each function, variable, typedef, and structure tag
  24. has a symbol table entry to define it.
  25. The beginning and end of each level of name scoping within
  26. a function are also marked by special symbol table entries.
  27. The "name" consists of the symbol name, a colon, a kind-of-symbol letter,
  28. and a data type number. The data type number may be followed by
  29. "=" and a type definition; normally this will happen the first time
  30. the type number is mentioned. The type definition may refer to
  31. other types by number, and those type numbers may be followed
  32. by "=" and nested definitions.
  33. This can make the "name" quite long.
  34. When a name is more than 80 characters, we split the .stabs pseudo-op
  35. into two .stabs pseudo-ops, both sharing the same "code" and "value".
  36. The first one is marked as continued with a double-backslash at the
  37. end of its "name".
  38. The kind-of-symbol letter distinguished function names from global
  39. variables from file-scope variables from parameters from auto
  40. variables in memory from typedef names from register variables.
  41. See `dbxout_symbol'.
  42. The "code" is mostly redundant with the kind-of-symbol letter
  43. that goes in the "name", but not entirely: for symbols located
  44. in static storage, the "code" says which segment the address is in,
  45. which controls how it is relocated.
  46. The "value" for a symbol in static storage
  47. is the core address of the symbol (actually, the assembler
  48. label for the symbol). For a symbol located in a stack slot
  49. it is the stack offset; for one in a register, the register number.
  50. For a typedef symbol, it is zero.
  51. If DEBUG_SYMS_TEXT is defined, all debugging symbols must be
  52. output while in the text section.
  53. For more on data type definitions, see `dbxout_type'. */
  54. #include "config.h"
  55. #include "system.h"
  56. #include "coretypes.h"
  57. #include "tm.h"
  58. #include "hash-set.h"
  59. #include "machmode.h"
  60. #include "vec.h"
  61. #include "double-int.h"
  62. #include "input.h"
  63. #include "alias.h"
  64. #include "symtab.h"
  65. #include "wide-int.h"
  66. #include "inchash.h"
  67. #include "tree.h"
  68. #include "fold-const.h"
  69. #include "varasm.h"
  70. #include "stor-layout.h"
  71. #include "rtl.h"
  72. #include "flags.h"
  73. #include "regs.h"
  74. #include "insn-config.h"
  75. #include "reload.h"
  76. #include "output.h"
  77. #include "dbxout.h"
  78. #include "diagnostic-core.h"
  79. #include "toplev.h"
  80. #include "tm_p.h"
  81. #include "ggc.h"
  82. #include "debug.h"
  83. #include "hashtab.h"
  84. #include "hard-reg-set.h"
  85. #include "function.h"
  86. #include "target.h"
  87. #include "common/common-target.h"
  88. #include "langhooks.h"
  89. #include "obstack.h"
  90. #include "statistics.h"
  91. #include "real.h"
  92. #include "fixed-value.h"
  93. #include "expmed.h"
  94. #include "dojump.h"
  95. #include "explow.h"
  96. #include "calls.h"
  97. #include "emit-rtl.h"
  98. #include "stmt.h"
  99. #include "expr.h"
  100. #include "hash-map.h"
  101. #include "is-a.h"
  102. #include "plugin-api.h"
  103. #include "ipa-ref.h"
  104. #include "cgraph.h"
  105. #include "stringpool.h"
  106. #ifdef XCOFF_DEBUGGING_INFO
  107. #include "xcoffout.h"
  108. #endif
  109. #ifndef ASM_STABS_OP
  110. # ifdef XCOFF_DEBUGGING_INFO
  111. # define ASM_STABS_OP "\t.stabx\t"
  112. # else
  113. # define ASM_STABS_OP "\t.stabs\t"
  114. # endif
  115. #endif
  116. #ifndef ASM_STABN_OP
  117. #define ASM_STABN_OP "\t.stabn\t"
  118. #endif
  119. #ifndef ASM_STABD_OP
  120. #define ASM_STABD_OP "\t.stabd\t"
  121. #endif
  122. #ifndef DBX_TYPE_DECL_STABS_CODE
  123. #define DBX_TYPE_DECL_STABS_CODE N_LSYM
  124. #endif
  125. #ifndef DBX_STATIC_CONST_VAR_CODE
  126. #define DBX_STATIC_CONST_VAR_CODE N_FUN
  127. #endif
  128. #ifndef DBX_REGPARM_STABS_CODE
  129. #define DBX_REGPARM_STABS_CODE N_RSYM
  130. #endif
  131. #ifndef DBX_REGPARM_STABS_LETTER
  132. #define DBX_REGPARM_STABS_LETTER 'P'
  133. #endif
  134. #ifndef NO_DBX_FUNCTION_END
  135. #define NO_DBX_FUNCTION_END 0
  136. #endif
  137. #ifndef NO_DBX_BNSYM_ENSYM
  138. #define NO_DBX_BNSYM_ENSYM 0
  139. #endif
  140. #ifndef NO_DBX_MAIN_SOURCE_DIRECTORY
  141. #define NO_DBX_MAIN_SOURCE_DIRECTORY 0
  142. #endif
  143. #ifndef DBX_BLOCKS_FUNCTION_RELATIVE
  144. #define DBX_BLOCKS_FUNCTION_RELATIVE 0
  145. #endif
  146. #ifndef DBX_LINES_FUNCTION_RELATIVE
  147. #define DBX_LINES_FUNCTION_RELATIVE 0
  148. #endif
  149. #ifndef DBX_CONTIN_LENGTH
  150. #define DBX_CONTIN_LENGTH 80
  151. #endif
  152. #ifndef DBX_CONTIN_CHAR
  153. #define DBX_CONTIN_CHAR '\\'
  154. #endif
  155. enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
  156. /* Structure recording information about a C data type.
  157. The status element says whether we have yet output
  158. the definition of the type. TYPE_XREF says we have
  159. output it as a cross-reference only.
  160. The file_number and type_number elements are used if DBX_USE_BINCL
  161. is defined. */
  162. struct GTY(()) typeinfo {
  163. enum typestatus status;
  164. int file_number;
  165. int type_number;
  166. };
  167. /* Vector recording information about C data types.
  168. When we first notice a data type (a tree node),
  169. we assign it a number using next_type_number.
  170. That is its index in this vector. */
  171. static GTY ((length ("typevec_len"))) struct typeinfo *typevec;
  172. /* Number of elements of space allocated in `typevec'. */
  173. static GTY(()) int typevec_len;
  174. /* In dbx output, each type gets a unique number.
  175. This is the number for the next type output.
  176. The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
  177. static GTY(()) int next_type_number;
  178. /* The C front end may call dbxout_symbol before dbxout_init runs.
  179. We save all such decls in this list and output them when we get
  180. to dbxout_init. */
  181. static GTY(()) tree preinit_symbols;
  182. enum binclstatus {BINCL_NOT_REQUIRED, BINCL_PENDING, BINCL_PROCESSED};
  183. /* When using N_BINCL in dbx output, each type number is actually a
  184. pair of the file number and the type number within the file.
  185. This is a stack of input files. */
  186. struct dbx_file
  187. {
  188. struct dbx_file *next;
  189. int file_number;
  190. int next_type_number;
  191. enum binclstatus bincl_status; /* Keep track of lazy bincl. */
  192. const char *pending_bincl_name; /* Name of bincl. */
  193. struct dbx_file *prev; /* Chain to traverse all pending bincls. */
  194. };
  195. /* This is the top of the stack.
  196. This is not saved for PCH, because restoring a PCH should not change it.
  197. next_file_number does have to be saved, because the PCH may use some
  198. file numbers; however, just before restoring a PCH, next_file_number
  199. should always be 0 because we should not have needed any file numbers
  200. yet. */
  201. #if (defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)) \
  202. && defined (DBX_USE_BINCL)
  203. static struct dbx_file *current_file;
  204. #endif
  205. /* This is the next file number to use. */
  206. static GTY(()) int next_file_number;
  207. /* A counter for dbxout_function_end. */
  208. static GTY(()) int scope_labelno;
  209. /* A counter for dbxout_source_line. */
  210. static GTY(()) int dbxout_source_line_counter;
  211. /* Number for the next N_SOL filename stabs label. The number 0 is reserved
  212. for the N_SO filename stabs label. */
  213. static GTY(()) int source_label_number = 1;
  214. /* Last source file name mentioned in a NOTE insn. */
  215. static GTY(()) const char *lastfile;
  216. /* Used by PCH machinery to detect if 'lastfile' should be reset to
  217. base_input_file. */
  218. static GTY(()) int lastfile_is_base;
  219. /* Typical USG systems don't have stab.h, and they also have
  220. no use for DBX-format debugging info. */
  221. #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
  222. #ifdef DBX_USE_BINCL
  223. /* If zero then there is no pending BINCL. */
  224. static int pending_bincls = 0;
  225. #endif
  226. /* The original input file name. */
  227. static const char *base_input_file;
  228. #ifdef DEBUG_SYMS_TEXT
  229. #define FORCE_TEXT switch_to_section (current_function_section ())
  230. #else
  231. #define FORCE_TEXT
  232. #endif
  233. #include "gstab.h"
  234. /* 1 if PARM is passed to this function in memory. */
  235. #define PARM_PASSED_IN_MEMORY(PARM) \
  236. (MEM_P (DECL_INCOMING_RTL (PARM)))
  237. /* A C expression for the integer offset value of an automatic variable
  238. (N_LSYM) having address X (an RTX). */
  239. #ifndef DEBUGGER_AUTO_OFFSET
  240. #define DEBUGGER_AUTO_OFFSET(X) \
  241. (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
  242. #endif
  243. /* A C expression for the integer offset value of an argument (N_PSYM)
  244. having address X (an RTX). The nominal offset is OFFSET.
  245. Note that we use OFFSET + 0 here to avoid the self-assign warning
  246. when the macro is called in a context like
  247. number = DEBUGGER_ARG_OFFSET(number, X) */
  248. #ifndef DEBUGGER_ARG_OFFSET
  249. #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET + 0)
  250. #endif
  251. /* This obstack holds the stab string currently being constructed. We
  252. build it up here, then write it out, so we can split long lines up
  253. properly (see dbxout_finish_complex_stabs). */
  254. static struct obstack stabstr_ob;
  255. static size_t stabstr_last_contin_point;
  256. #ifdef DBX_USE_BINCL
  257. static void emit_bincl_stab (const char *c);
  258. static void emit_pending_bincls (void);
  259. #endif
  260. static inline void emit_pending_bincls_if_required (void);
  261. static void dbxout_init (const char *);
  262. static void dbxout_finish (const char *);
  263. static void dbxout_start_source_file (unsigned, const char *);
  264. static void dbxout_end_source_file (unsigned);
  265. static void dbxout_typedefs (tree);
  266. static void dbxout_type_index (tree);
  267. static void dbxout_args (tree);
  268. static void dbxout_type_fields (tree);
  269. static void dbxout_type_method_1 (tree);
  270. static void dbxout_type_methods (tree);
  271. static void dbxout_range_type (tree, tree, tree);
  272. static void dbxout_type (tree, int);
  273. static bool print_int_cst_bounds_in_octal_p (tree, tree, tree);
  274. static bool is_fortran (void);
  275. static void dbxout_type_name (tree);
  276. static void dbxout_class_name_qualifiers (tree);
  277. static int dbxout_symbol_location (tree, tree, const char *, rtx);
  278. static void dbxout_symbol_name (tree, const char *, int);
  279. static void dbxout_common_name (tree, const char *, stab_code_type);
  280. static const char *dbxout_common_check (tree, int *);
  281. static void dbxout_global_decl (tree);
  282. static void dbxout_type_decl (tree, int);
  283. static void dbxout_handle_pch (unsigned);
  284. static void debug_free_queue (void);
  285. /* The debug hooks structure. */
  286. #if defined (DBX_DEBUGGING_INFO)
  287. static void dbxout_source_line (unsigned int, const char *, int, bool);
  288. static void dbxout_begin_prologue (unsigned int, const char *);
  289. static void dbxout_source_file (const char *);
  290. static void dbxout_function_end (tree);
  291. static void dbxout_begin_function (tree);
  292. static void dbxout_begin_block (unsigned, unsigned);
  293. static void dbxout_end_block (unsigned, unsigned);
  294. static void dbxout_function_decl (tree);
  295. const struct gcc_debug_hooks dbx_debug_hooks =
  296. {
  297. dbxout_init,
  298. dbxout_finish,
  299. debug_nothing_void,
  300. debug_nothing_int_charstar,
  301. debug_nothing_int_charstar,
  302. dbxout_start_source_file,
  303. dbxout_end_source_file,
  304. dbxout_begin_block,
  305. dbxout_end_block,
  306. debug_true_const_tree, /* ignore_block */
  307. dbxout_source_line, /* source_line */
  308. dbxout_begin_prologue, /* begin_prologue */
  309. debug_nothing_int_charstar, /* end_prologue */
  310. debug_nothing_int_charstar, /* begin_epilogue */
  311. debug_nothing_int_charstar, /* end_epilogue */
  312. #ifdef DBX_FUNCTION_FIRST
  313. dbxout_begin_function,
  314. #else
  315. debug_nothing_tree, /* begin_function */
  316. #endif
  317. debug_nothing_int, /* end_function */
  318. debug_nothing_tree, /* register_main_translation_unit */
  319. dbxout_function_decl,
  320. dbxout_global_decl, /* global_decl */
  321. dbxout_type_decl, /* type_decl */
  322. debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
  323. debug_nothing_tree, /* deferred_inline_function */
  324. debug_nothing_tree, /* outlining_inline_function */
  325. debug_nothing_rtx_code_label, /* label */
  326. dbxout_handle_pch, /* handle_pch */
  327. debug_nothing_rtx_insn, /* var_location */
  328. debug_nothing_void, /* switch_text_section */
  329. debug_nothing_tree_tree, /* set_name */
  330. 0, /* start_end_main_source_file */
  331. TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
  332. };
  333. #endif /* DBX_DEBUGGING_INFO */
  334. #if defined (XCOFF_DEBUGGING_INFO)
  335. const struct gcc_debug_hooks xcoff_debug_hooks =
  336. {
  337. dbxout_init,
  338. dbxout_finish,
  339. debug_nothing_void,
  340. debug_nothing_int_charstar,
  341. debug_nothing_int_charstar,
  342. dbxout_start_source_file,
  343. dbxout_end_source_file,
  344. xcoffout_begin_block,
  345. xcoffout_end_block,
  346. debug_true_const_tree, /* ignore_block */
  347. xcoffout_source_line,
  348. xcoffout_begin_prologue, /* begin_prologue */
  349. debug_nothing_int_charstar, /* end_prologue */
  350. debug_nothing_int_charstar, /* begin_epilogue */
  351. xcoffout_end_epilogue,
  352. debug_nothing_tree, /* begin_function */
  353. xcoffout_end_function,
  354. debug_nothing_tree, /* register_main_translation_unit */
  355. debug_nothing_tree, /* function_decl */
  356. dbxout_global_decl, /* global_decl */
  357. dbxout_type_decl, /* type_decl */
  358. debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
  359. debug_nothing_tree, /* deferred_inline_function */
  360. debug_nothing_tree, /* outlining_inline_function */
  361. debug_nothing_rtx_code_label, /* label */
  362. dbxout_handle_pch, /* handle_pch */
  363. debug_nothing_rtx_insn, /* var_location */
  364. debug_nothing_void, /* switch_text_section */
  365. debug_nothing_tree_tree, /* set_name */
  366. 0, /* start_end_main_source_file */
  367. TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
  368. };
  369. #endif /* XCOFF_DEBUGGING_INFO */
  370. /* Numeric formatting helper macro. Note that this does not handle
  371. hexadecimal. */
  372. #define NUMBER_FMT_LOOP(P, NUM, BASE) \
  373. do \
  374. { \
  375. int digit = NUM % BASE; \
  376. NUM /= BASE; \
  377. *--P = digit + '0'; \
  378. } \
  379. while (NUM > 0)
  380. /* Utility: write a decimal integer NUM to asm_out_file. */
  381. void
  382. dbxout_int (int num)
  383. {
  384. char buf[64];
  385. char *p = buf + sizeof buf;
  386. unsigned int unum;
  387. if (num == 0)
  388. {
  389. putc ('0', asm_out_file);
  390. return;
  391. }
  392. if (num < 0)
  393. {
  394. putc ('-', asm_out_file);
  395. unum = -num;
  396. }
  397. else
  398. unum = num;
  399. NUMBER_FMT_LOOP (p, unum, 10);
  400. while (p < buf + sizeof buf)
  401. {
  402. putc (*p, asm_out_file);
  403. p++;
  404. }
  405. }
  406. /* Primitives for emitting simple stabs directives. All other stabs
  407. routines should use these functions instead of directly emitting
  408. stabs. They are exported because machine-dependent code may need
  409. to invoke them, e.g. in a DBX_OUTPUT_* macro whose definition
  410. forwards to code in CPU.c. */
  411. /* The following functions should all be called immediately after one
  412. of the dbxout_begin_stab* functions (below). They write out
  413. various things as the value of a stab. */
  414. /* Write out a literal zero as the value of a stab. */
  415. void
  416. dbxout_stab_value_zero (void)
  417. {
  418. fputs ("0\n", asm_out_file);
  419. }
  420. /* Write out the label LABEL as the value of a stab. */
  421. void
  422. dbxout_stab_value_label (const char *label)
  423. {
  424. assemble_name (asm_out_file, label);
  425. putc ('\n', asm_out_file);
  426. }
  427. /* Write out the difference of two labels, LABEL - BASE, as the value
  428. of a stab. */
  429. void
  430. dbxout_stab_value_label_diff (const char *label, const char *base)
  431. {
  432. assemble_name (asm_out_file, label);
  433. putc ('-', asm_out_file);
  434. assemble_name (asm_out_file, base);
  435. putc ('\n', asm_out_file);
  436. }
  437. /* Write out an internal label as the value of a stab, and immediately
  438. emit that internal label. This should be used only when
  439. dbxout_stabd will not work. STEM is the name stem of the label,
  440. COUNTERP is a pointer to a counter variable which will be used to
  441. guarantee label uniqueness. */
  442. void
  443. dbxout_stab_value_internal_label (const char *stem, int *counterp)
  444. {
  445. char label[100];
  446. int counter = counterp ? (*counterp)++ : 0;
  447. ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
  448. dbxout_stab_value_label (label);
  449. targetm.asm_out.internal_label (asm_out_file, stem, counter);
  450. }
  451. /* Write out the difference between BASE and an internal label as the
  452. value of a stab, and immediately emit that internal label. STEM and
  453. COUNTERP are as for dbxout_stab_value_internal_label. */
  454. void
  455. dbxout_stab_value_internal_label_diff (const char *stem, int *counterp,
  456. const char *base)
  457. {
  458. char label[100];
  459. int counter = counterp ? (*counterp)++ : 0;
  460. ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
  461. dbxout_stab_value_label_diff (label, base);
  462. targetm.asm_out.internal_label (asm_out_file, stem, counter);
  463. }
  464. /* The following functions produce specific kinds of stab directives. */
  465. /* Write a .stabd directive with type STYPE and desc SDESC to asm_out_file. */
  466. void
  467. dbxout_stabd (int stype, int sdesc)
  468. {
  469. fputs (ASM_STABD_OP, asm_out_file);
  470. dbxout_int (stype);
  471. fputs (",0,", asm_out_file);
  472. dbxout_int (sdesc);
  473. putc ('\n', asm_out_file);
  474. }
  475. /* Write a .stabn directive with type STYPE. This function stops
  476. short of emitting the value field, which is the responsibility of
  477. the caller (normally it will be either a symbol or the difference
  478. of two symbols). */
  479. void
  480. dbxout_begin_stabn (int stype)
  481. {
  482. fputs (ASM_STABN_OP, asm_out_file);
  483. dbxout_int (stype);
  484. fputs (",0,0,", asm_out_file);
  485. }
  486. /* Write a .stabn directive with type N_SLINE and desc LINE. As above,
  487. the value field is the responsibility of the caller. */
  488. void
  489. dbxout_begin_stabn_sline (int lineno)
  490. {
  491. fputs (ASM_STABN_OP, asm_out_file);
  492. dbxout_int (N_SLINE);
  493. fputs (",0,", asm_out_file);
  494. dbxout_int (lineno);
  495. putc (',', asm_out_file);
  496. }
  497. /* Begin a .stabs directive with string "", type STYPE, and desc and
  498. other fields 0. The value field is the responsibility of the
  499. caller. This function cannot be used for .stabx directives. */
  500. void
  501. dbxout_begin_empty_stabs (int stype)
  502. {
  503. fputs (ASM_STABS_OP, asm_out_file);
  504. fputs ("\"\",", asm_out_file);
  505. dbxout_int (stype);
  506. fputs (",0,0,", asm_out_file);
  507. }
  508. /* Begin a .stabs directive with string STR, type STYPE, and desc 0.
  509. The value field is the responsibility of the caller. */
  510. void
  511. dbxout_begin_simple_stabs (const char *str, int stype)
  512. {
  513. fputs (ASM_STABS_OP, asm_out_file);
  514. output_quoted_string (asm_out_file, str);
  515. putc (',', asm_out_file);
  516. dbxout_int (stype);
  517. fputs (",0,0,", asm_out_file);
  518. }
  519. /* As above but use SDESC for the desc field. */
  520. void
  521. dbxout_begin_simple_stabs_desc (const char *str, int stype, int sdesc)
  522. {
  523. fputs (ASM_STABS_OP, asm_out_file);
  524. output_quoted_string (asm_out_file, str);
  525. putc (',', asm_out_file);
  526. dbxout_int (stype);
  527. fputs (",0,", asm_out_file);
  528. dbxout_int (sdesc);
  529. putc (',', asm_out_file);
  530. }
  531. /* The next set of functions are entirely concerned with production of
  532. "complex" .stabs directives: that is, .stabs directives whose
  533. strings have to be constructed piecemeal. dbxout_type,
  534. dbxout_symbol, etc. use these routines heavily. The string is queued
  535. up in an obstack, then written out by dbxout_finish_complex_stabs, which
  536. is also responsible for splitting it up if it exceeds DBX_CONTIN_LENGTH.
  537. (You might think it would be more efficient to go straight to stdio
  538. when DBX_CONTIN_LENGTH is 0 (i.e. no length limit) but that turns
  539. out not to be the case, and anyway this needs fewer #ifdefs.) */
  540. /* Begin a complex .stabs directive. If we can, write the initial
  541. ASM_STABS_OP to the asm_out_file. */
  542. static void
  543. dbxout_begin_complex_stabs (void)
  544. {
  545. emit_pending_bincls_if_required ();
  546. FORCE_TEXT;
  547. fputs (ASM_STABS_OP, asm_out_file);
  548. putc ('"', asm_out_file);
  549. gcc_assert (stabstr_last_contin_point == 0);
  550. }
  551. /* As above, but do not force text or emit pending bincls. This is
  552. used by dbxout_symbol_location, which needs to do something else. */
  553. static void
  554. dbxout_begin_complex_stabs_noforcetext (void)
  555. {
  556. fputs (ASM_STABS_OP, asm_out_file);
  557. putc ('"', asm_out_file);
  558. gcc_assert (stabstr_last_contin_point == 0);
  559. }
  560. /* Add CHR, a single character, to the string being built. */
  561. #define stabstr_C(chr) obstack_1grow (&stabstr_ob, chr)
  562. /* Add STR, a normal C string, to the string being built. */
  563. #define stabstr_S(str) obstack_grow (&stabstr_ob, str, strlen (str))
  564. /* Add the text of ID, an IDENTIFIER_NODE, to the string being built. */
  565. #define stabstr_I(id) obstack_grow (&stabstr_ob, \
  566. IDENTIFIER_POINTER (id), \
  567. IDENTIFIER_LENGTH (id))
  568. /* Add NUM, a signed decimal number, to the string being built. */
  569. static void
  570. stabstr_D (HOST_WIDE_INT num)
  571. {
  572. char buf[64];
  573. char *p = buf + sizeof buf;
  574. unsigned int unum;
  575. if (num == 0)
  576. {
  577. stabstr_C ('0');
  578. return;
  579. }
  580. if (num < 0)
  581. {
  582. stabstr_C ('-');
  583. unum = -num;
  584. }
  585. else
  586. unum = num;
  587. NUMBER_FMT_LOOP (p, unum, 10);
  588. obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
  589. }
  590. /* Add NUM, an unsigned decimal number, to the string being built. */
  591. static void
  592. stabstr_U (unsigned HOST_WIDE_INT num)
  593. {
  594. char buf[64];
  595. char *p = buf + sizeof buf;
  596. if (num == 0)
  597. {
  598. stabstr_C ('0');
  599. return;
  600. }
  601. NUMBER_FMT_LOOP (p, num, 10);
  602. obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
  603. }
  604. /* Add CST, an INTEGER_CST tree, to the string being built as an
  605. unsigned octal number. This routine handles values which are
  606. larger than a single HOST_WIDE_INT. */
  607. static void
  608. stabstr_O (tree cst)
  609. {
  610. int prec = TYPE_PRECISION (TREE_TYPE (cst));
  611. int res_pres = prec % 3;
  612. int i;
  613. unsigned int digit;
  614. /* Leading zero for base indicator. */
  615. stabstr_C ('0');
  616. /* If the value is zero, the base indicator will serve as the value
  617. all by itself. */
  618. if (wi::eq_p (cst, 0))
  619. return;
  620. /* GDB wants constants with no extra leading "1" bits, so
  621. we need to remove any sign-extension that might be
  622. present. */
  623. if (res_pres == 1)
  624. {
  625. digit = wi::extract_uhwi (cst, prec - 1, 1);
  626. stabstr_C ('0' + digit);
  627. }
  628. else if (res_pres == 2)
  629. {
  630. digit = wi::extract_uhwi (cst, prec - 2, 2);
  631. stabstr_C ('0' + digit);
  632. }
  633. prec -= res_pres;
  634. for (i = prec - 3; i >= 0; i = i - 3)
  635. {
  636. digit = wi::extract_uhwi (cst, i, 3);
  637. stabstr_C ('0' + digit);
  638. }
  639. }
  640. /* Called whenever it is safe to break a stabs string into multiple
  641. .stabs directives. If the current string has exceeded the limit
  642. set by DBX_CONTIN_LENGTH, mark the current position in the buffer
  643. as a continuation point by inserting DBX_CONTIN_CHAR (doubled if
  644. it is a backslash) and a null character. */
  645. static inline void
  646. stabstr_continue (void)
  647. {
  648. if (DBX_CONTIN_LENGTH > 0
  649. && obstack_object_size (&stabstr_ob) - stabstr_last_contin_point
  650. > DBX_CONTIN_LENGTH)
  651. {
  652. if (DBX_CONTIN_CHAR == '\\')
  653. obstack_1grow (&stabstr_ob, '\\');
  654. obstack_1grow (&stabstr_ob, DBX_CONTIN_CHAR);
  655. obstack_1grow (&stabstr_ob, '\0');
  656. stabstr_last_contin_point = obstack_object_size (&stabstr_ob);
  657. }
  658. }
  659. #define CONTIN stabstr_continue ()
  660. /* Macro subroutine of dbxout_finish_complex_stabs, which emits
  661. all of the arguments to the .stabs directive after the string.
  662. Overridden by xcoffout.h. CODE is the stabs code for this symbol;
  663. LINE is the source line to write into the desc field (in extended
  664. mode); SYM is the symbol itself.
  665. ADDR, LABEL, and NUMBER are three different ways to represent the
  666. stabs value field. At most one of these should be nonzero.
  667. ADDR is used most of the time; it represents the value as an
  668. RTL address constant.
  669. LABEL is used (currently) only for N_CATCH stabs; it represents
  670. the value as a string suitable for assemble_name.
  671. NUMBER is used when the value is an offset from an implicit base
  672. pointer (e.g. for a stack variable), or an index (e.g. for a
  673. register variable). It represents the value as a decimal integer. */
  674. #ifndef DBX_FINISH_STABS
  675. #define DBX_FINISH_STABS(SYM, CODE, LINE, ADDR, LABEL, NUMBER) \
  676. do { \
  677. int line_ = use_gnu_debug_info_extensions ? LINE : 0; \
  678. \
  679. dbxout_int (CODE); \
  680. fputs (",0,", asm_out_file); \
  681. dbxout_int (line_); \
  682. putc (',', asm_out_file); \
  683. if (ADDR) \
  684. output_addr_const (asm_out_file, ADDR); \
  685. else if (LABEL) \
  686. assemble_name (asm_out_file, LABEL); \
  687. else \
  688. dbxout_int (NUMBER); \
  689. putc ('\n', asm_out_file); \
  690. } while (0)
  691. #endif
  692. /* Finish the emission of a complex .stabs directive. When DBX_CONTIN_LENGTH
  693. is zero, this has only to emit the close quote and the remainder of
  694. the arguments. When it is nonzero, the string has been marshalled in
  695. stabstr_ob, and this routine is responsible for breaking it up into
  696. DBX_CONTIN_LENGTH-sized chunks.
  697. SYM is the DECL of the symbol under consideration; it is used only
  698. for its DECL_SOURCE_LINE. The other arguments are all passed directly
  699. to DBX_FINISH_STABS; see above for details. */
  700. static void
  701. dbxout_finish_complex_stabs (tree sym, stab_code_type code,
  702. rtx addr, const char *label, int number)
  703. {
  704. int line ATTRIBUTE_UNUSED;
  705. char *str;
  706. size_t len;
  707. line = sym ? DECL_SOURCE_LINE (sym) : 0;
  708. if (DBX_CONTIN_LENGTH > 0)
  709. {
  710. char *chunk;
  711. size_t chunklen;
  712. /* Nul-terminate the growing string, then get its size and
  713. address. */
  714. obstack_1grow (&stabstr_ob, '\0');
  715. len = obstack_object_size (&stabstr_ob);
  716. chunk = str = XOBFINISH (&stabstr_ob, char *);
  717. /* Within the buffer are a sequence of NUL-separated strings,
  718. each of which is to be written out as a separate stab
  719. directive. */
  720. for (;;)
  721. {
  722. chunklen = strlen (chunk);
  723. fwrite (chunk, 1, chunklen, asm_out_file);
  724. fputs ("\",", asm_out_file);
  725. /* Must add an extra byte to account for the NUL separator. */
  726. chunk += chunklen + 1;
  727. len -= chunklen + 1;
  728. /* Only put a line number on the last stab in the sequence. */
  729. DBX_FINISH_STABS (sym, code, len == 0 ? line : 0,
  730. addr, label, number);
  731. if (len == 0)
  732. break;
  733. fputs (ASM_STABS_OP, asm_out_file);
  734. putc ('"', asm_out_file);
  735. }
  736. stabstr_last_contin_point = 0;
  737. }
  738. else
  739. {
  740. /* No continuations - we can put the whole string out at once.
  741. It is faster to augment the string with the close quote and
  742. comma than to do a two-character fputs. */
  743. obstack_grow (&stabstr_ob, "\",", 2);
  744. len = obstack_object_size (&stabstr_ob);
  745. str = XOBFINISH (&stabstr_ob, char *);
  746. fwrite (str, 1, len, asm_out_file);
  747. DBX_FINISH_STABS (sym, code, line, addr, label, number);
  748. }
  749. obstack_free (&stabstr_ob, str);
  750. }
  751. #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
  752. /* When -gused is used, emit debug info for only used symbols. But in
  753. addition to the standard intercepted debug_hooks there are some
  754. direct calls into this file, i.e., dbxout_symbol, dbxout_parms, and
  755. dbxout_reg_params. Those routines may also be called from a higher
  756. level intercepted routine. So to prevent recording data for an inner
  757. call to one of these for an intercept, we maintain an intercept
  758. nesting counter (debug_nesting). We only save the intercepted
  759. arguments if the nesting is 1. */
  760. static int debug_nesting = 0;
  761. static tree *symbol_queue;
  762. static int symbol_queue_index = 0;
  763. static int symbol_queue_size = 0;
  764. #define DBXOUT_DECR_NESTING \
  765. if (--debug_nesting == 0 && symbol_queue_index > 0) \
  766. { emit_pending_bincls_if_required (); debug_flush_symbol_queue (); }
  767. #define DBXOUT_DECR_NESTING_AND_RETURN(x) \
  768. do {--debug_nesting; return (x);} while (0)
  769. #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
  770. #if defined (DBX_DEBUGGING_INFO)
  771. static void
  772. dbxout_function_end (tree decl ATTRIBUTE_UNUSED)
  773. {
  774. char lscope_label_name[100];
  775. /* The Lscope label must be emitted even if we aren't doing anything
  776. else; dbxout_block needs it. */
  777. switch_to_section (function_section (current_function_decl));
  778. /* Convert Lscope into the appropriate format for local labels in case
  779. the system doesn't insert underscores in front of user generated
  780. labels. */
  781. ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
  782. targetm.asm_out.internal_label (asm_out_file, "Lscope", scope_labelno);
  783. /* The N_FUN tag at the end of the function is a GNU extension,
  784. which may be undesirable, and is unnecessary if we do not have
  785. named sections. */
  786. if (!use_gnu_debug_info_extensions
  787. || NO_DBX_FUNCTION_END
  788. || !targetm_common.have_named_sections)
  789. return;
  790. /* By convention, GCC will mark the end of a function with an N_FUN
  791. symbol and an empty string. */
  792. if (flag_reorder_blocks_and_partition)
  793. {
  794. dbxout_begin_empty_stabs (N_FUN);
  795. dbxout_stab_value_label_diff (crtl->subsections.hot_section_end_label,
  796. crtl->subsections.hot_section_label);
  797. dbxout_begin_empty_stabs (N_FUN);
  798. dbxout_stab_value_label_diff (crtl->subsections.cold_section_end_label,
  799. crtl->subsections.cold_section_label);
  800. }
  801. else
  802. {
  803. char begin_label[20];
  804. /* Reference current function start using LFBB. */
  805. ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
  806. dbxout_begin_empty_stabs (N_FUN);
  807. dbxout_stab_value_label_diff (lscope_label_name, begin_label);
  808. }
  809. if (!NO_DBX_BNSYM_ENSYM && !flag_debug_only_used_symbols)
  810. dbxout_stabd (N_ENSYM, 0);
  811. }
  812. #endif /* DBX_DEBUGGING_INFO */
  813. /* Get lang description for N_SO stab. */
  814. static unsigned int ATTRIBUTE_UNUSED
  815. get_lang_number (void)
  816. {
  817. const char *language_string = lang_hooks.name;
  818. if (lang_GNU_C ())
  819. return N_SO_C;
  820. else if (lang_GNU_CXX ())
  821. return N_SO_CC;
  822. else if (strcmp (language_string, "GNU F77") == 0)
  823. return N_SO_FORTRAN;
  824. else if (lang_GNU_Fortran ())
  825. return N_SO_FORTRAN90; /* CHECKME */
  826. else if (strcmp (language_string, "GNU Pascal") == 0)
  827. return N_SO_PASCAL;
  828. else if (strcmp (language_string, "GNU Objective-C") == 0)
  829. return N_SO_OBJC;
  830. else if (strcmp (language_string, "GNU Objective-C++") == 0)
  831. return N_SO_OBJCPLUS;
  832. else
  833. return 0;
  834. }
  835. static bool
  836. is_fortran (void)
  837. {
  838. unsigned int lang = get_lang_number ();
  839. return (lang == N_SO_FORTRAN) || (lang == N_SO_FORTRAN90);
  840. }
  841. /* At the beginning of compilation, start writing the symbol table.
  842. Initialize `typevec' and output the standard data types of C. */
  843. static void
  844. dbxout_init (const char *input_file_name)
  845. {
  846. char ltext_label_name[100];
  847. bool used_ltext_label_name = false;
  848. tree syms = lang_hooks.decls.getdecls ();
  849. const char *mapped_name;
  850. typevec_len = 100;
  851. typevec = ggc_cleared_vec_alloc<typeinfo> (typevec_len);
  852. /* stabstr_ob contains one string, which will be just fine with
  853. 1-byte alignment. */
  854. obstack_specify_allocation (&stabstr_ob, 0, 1, xmalloc, free);
  855. /* Convert Ltext into the appropriate format for local labels in case
  856. the system doesn't insert underscores in front of user generated
  857. labels. */
  858. ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
  859. /* Put the current working directory in an N_SO symbol. */
  860. if (use_gnu_debug_info_extensions && !NO_DBX_MAIN_SOURCE_DIRECTORY)
  861. {
  862. static const char *cwd;
  863. if (!cwd)
  864. {
  865. cwd = get_src_pwd ();
  866. if (cwd[0] == '\0')
  867. cwd = "/";
  868. else if (!IS_DIR_SEPARATOR (cwd[strlen (cwd) - 1]))
  869. cwd = concat (cwd, "/", NULL);
  870. cwd = remap_debug_filename (cwd);
  871. }
  872. #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
  873. DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asm_out_file, cwd);
  874. #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
  875. dbxout_begin_simple_stabs_desc (cwd, N_SO, get_lang_number ());
  876. dbxout_stab_value_label (ltext_label_name);
  877. used_ltext_label_name = true;
  878. #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
  879. }
  880. mapped_name = remap_debug_filename (input_file_name);
  881. #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
  882. DBX_OUTPUT_MAIN_SOURCE_FILENAME (asm_out_file, mapped_name);
  883. #else
  884. dbxout_begin_simple_stabs_desc (mapped_name, N_SO, get_lang_number ());
  885. dbxout_stab_value_label (ltext_label_name);
  886. used_ltext_label_name = true;
  887. #endif
  888. if (used_ltext_label_name)
  889. {
  890. switch_to_section (text_section);
  891. targetm.asm_out.internal_label (asm_out_file, "Ltext", 0);
  892. }
  893. /* Emit an N_OPT stab to indicate that this file was compiled by GCC.
  894. The string used is historical. */
  895. #ifndef NO_DBX_GCC_MARKER
  896. dbxout_begin_simple_stabs ("gcc2_compiled.", N_OPT);
  897. dbxout_stab_value_zero ();
  898. #endif
  899. base_input_file = lastfile = input_file_name;
  900. next_type_number = 1;
  901. #ifdef DBX_USE_BINCL
  902. current_file = XNEW (struct dbx_file);
  903. current_file->next = NULL;
  904. current_file->file_number = 0;
  905. current_file->next_type_number = 1;
  906. next_file_number = 1;
  907. current_file->prev = NULL;
  908. current_file->bincl_status = BINCL_NOT_REQUIRED;
  909. current_file->pending_bincl_name = NULL;
  910. #endif
  911. /* Get all permanent types that have typedef names, and output them
  912. all, except for those already output. Some language front ends
  913. put these declarations in the top-level scope; some do not;
  914. the latter are responsible for calling debug_hooks->type_decl from
  915. their record_builtin_type function. */
  916. dbxout_typedefs (syms);
  917. if (preinit_symbols)
  918. {
  919. tree t;
  920. for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
  921. dbxout_symbol (TREE_VALUE (t), 0);
  922. preinit_symbols = 0;
  923. }
  924. }
  925. /* Output any typedef names for types described by TYPE_DECLs in SYMS. */
  926. static void
  927. dbxout_typedefs (tree syms)
  928. {
  929. for (; syms != NULL_TREE; syms = DECL_CHAIN (syms))
  930. {
  931. if (TREE_CODE (syms) == TYPE_DECL)
  932. {
  933. tree type = TREE_TYPE (syms);
  934. if (TYPE_NAME (type)
  935. && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  936. && COMPLETE_OR_VOID_TYPE_P (type)
  937. && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
  938. dbxout_symbol (TYPE_NAME (type), 0);
  939. }
  940. }
  941. }
  942. #ifdef DBX_USE_BINCL
  943. /* Emit BINCL stab using given name. */
  944. static void
  945. emit_bincl_stab (const char *name)
  946. {
  947. dbxout_begin_simple_stabs (name, N_BINCL);
  948. dbxout_stab_value_zero ();
  949. }
  950. /* If there are pending bincls then it is time to emit all of them. */
  951. static inline void
  952. emit_pending_bincls_if_required (void)
  953. {
  954. if (pending_bincls)
  955. emit_pending_bincls ();
  956. }
  957. /* Emit all pending bincls. */
  958. static void
  959. emit_pending_bincls (void)
  960. {
  961. struct dbx_file *f = current_file;
  962. /* Find first pending bincl. */
  963. while (f->bincl_status == BINCL_PENDING)
  964. f = f->next;
  965. /* Now emit all bincls. */
  966. f = f->prev;
  967. while (f)
  968. {
  969. if (f->bincl_status == BINCL_PENDING)
  970. {
  971. emit_bincl_stab (f->pending_bincl_name);
  972. /* Update file number and status. */
  973. f->file_number = next_file_number++;
  974. f->bincl_status = BINCL_PROCESSED;
  975. }
  976. if (f == current_file)
  977. break;
  978. f = f->prev;
  979. }
  980. /* All pending bincls have been emitted. */
  981. pending_bincls = 0;
  982. }
  983. #else
  984. static inline void
  985. emit_pending_bincls_if_required (void) {}
  986. #endif
  987. /* Change to reading from a new source file. Generate a N_BINCL stab. */
  988. static void
  989. dbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
  990. const char *filename ATTRIBUTE_UNUSED)
  991. {
  992. #ifdef DBX_USE_BINCL
  993. struct dbx_file *n = XNEW (struct dbx_file);
  994. n->next = current_file;
  995. n->next_type_number = 1;
  996. /* Do not assign file number now.
  997. Delay it until we actually emit BINCL. */
  998. n->file_number = 0;
  999. n->prev = NULL;
  1000. current_file->prev = n;
  1001. n->bincl_status = BINCL_PENDING;
  1002. n->pending_bincl_name = remap_debug_filename (filename);
  1003. pending_bincls = 1;
  1004. current_file = n;
  1005. #endif
  1006. }
  1007. /* Revert to reading a previous source file. Generate a N_EINCL stab. */
  1008. static void
  1009. dbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
  1010. {
  1011. #ifdef DBX_USE_BINCL
  1012. /* Emit EINCL stab only if BINCL is not pending. */
  1013. if (current_file->bincl_status == BINCL_PROCESSED)
  1014. {
  1015. dbxout_begin_stabn (N_EINCL);
  1016. dbxout_stab_value_zero ();
  1017. }
  1018. current_file->bincl_status = BINCL_NOT_REQUIRED;
  1019. current_file = current_file->next;
  1020. #endif
  1021. }
  1022. /* Handle a few odd cases that occur when trying to make PCH files work. */
  1023. static void
  1024. dbxout_handle_pch (unsigned at_end)
  1025. {
  1026. if (! at_end)
  1027. {
  1028. /* When using the PCH, this file will be included, so we need to output
  1029. a BINCL. */
  1030. dbxout_start_source_file (0, lastfile);
  1031. /* The base file when using the PCH won't be the same as
  1032. the base file when it's being generated. */
  1033. lastfile = NULL;
  1034. }
  1035. else
  1036. {
  1037. /* ... and an EINCL. */
  1038. dbxout_end_source_file (0);
  1039. /* Deal with cases where 'lastfile' was never actually changed. */
  1040. lastfile_is_base = lastfile == NULL;
  1041. }
  1042. }
  1043. #if defined (DBX_DEBUGGING_INFO)
  1044. static void dbxout_block (tree, int, tree);
  1045. /* Output debugging info to FILE to switch to sourcefile FILENAME. */
  1046. static void
  1047. dbxout_source_file (const char *filename)
  1048. {
  1049. if (lastfile == 0 && lastfile_is_base)
  1050. {
  1051. lastfile = base_input_file;
  1052. lastfile_is_base = 0;
  1053. }
  1054. if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
  1055. {
  1056. /* Don't change section amid function. */
  1057. if (current_function_decl == NULL_TREE)
  1058. switch_to_section (text_section);
  1059. dbxout_begin_simple_stabs (remap_debug_filename (filename), N_SOL);
  1060. dbxout_stab_value_internal_label ("Ltext", &source_label_number);
  1061. lastfile = filename;
  1062. }
  1063. }
  1064. /* Output N_BNSYM, line number symbol entry, and local symbol at
  1065. function scope */
  1066. static void
  1067. dbxout_begin_prologue (unsigned int lineno, const char *filename)
  1068. {
  1069. if (use_gnu_debug_info_extensions
  1070. && !NO_DBX_FUNCTION_END
  1071. && !NO_DBX_BNSYM_ENSYM
  1072. && !flag_debug_only_used_symbols)
  1073. dbxout_stabd (N_BNSYM, 0);
  1074. /* pre-increment the scope counter */
  1075. scope_labelno++;
  1076. dbxout_source_line (lineno, filename, 0, true);
  1077. /* Output function begin block at function scope, referenced
  1078. by dbxout_block, dbxout_source_line and dbxout_function_end. */
  1079. emit_pending_bincls_if_required ();
  1080. targetm.asm_out.internal_label (asm_out_file, "LFBB", scope_labelno);
  1081. }
  1082. /* Output a line number symbol entry for source file FILENAME and line
  1083. number LINENO. */
  1084. static void
  1085. dbxout_source_line (unsigned int lineno, const char *filename,
  1086. int discriminator ATTRIBUTE_UNUSED,
  1087. bool is_stmt ATTRIBUTE_UNUSED)
  1088. {
  1089. dbxout_source_file (filename);
  1090. #ifdef DBX_OUTPUT_SOURCE_LINE
  1091. DBX_OUTPUT_SOURCE_LINE (asm_out_file, lineno, dbxout_source_line_counter);
  1092. #else
  1093. if (DBX_LINES_FUNCTION_RELATIVE)
  1094. {
  1095. char begin_label[20];
  1096. dbxout_begin_stabn_sline (lineno);
  1097. /* Reference current function start using LFBB. */
  1098. ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
  1099. dbxout_stab_value_internal_label_diff ("LM", &dbxout_source_line_counter,
  1100. begin_label);
  1101. }
  1102. else
  1103. dbxout_stabd (N_SLINE, lineno);
  1104. #endif
  1105. }
  1106. /* Describe the beginning of an internal block within a function. */
  1107. static void
  1108. dbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
  1109. {
  1110. emit_pending_bincls_if_required ();
  1111. targetm.asm_out.internal_label (asm_out_file, "LBB", n);
  1112. }
  1113. /* Describe the end line-number of an internal block within a function. */
  1114. static void
  1115. dbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
  1116. {
  1117. emit_pending_bincls_if_required ();
  1118. targetm.asm_out.internal_label (asm_out_file, "LBE", n);
  1119. }
  1120. /* Output dbx data for a function definition.
  1121. This includes a definition of the function name itself (a symbol),
  1122. definitions of the parameters (locating them in the parameter list)
  1123. and then output the block that makes up the function's body
  1124. (including all the auto variables of the function). */
  1125. static void
  1126. dbxout_function_decl (tree decl)
  1127. {
  1128. emit_pending_bincls_if_required ();
  1129. #ifndef DBX_FUNCTION_FIRST
  1130. dbxout_begin_function (decl);
  1131. #endif
  1132. dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
  1133. dbxout_function_end (decl);
  1134. }
  1135. #endif /* DBX_DEBUGGING_INFO */
  1136. /* Debug information for a global DECL. Called from toplev.c after
  1137. compilation proper has finished. */
  1138. static void
  1139. dbxout_global_decl (tree decl)
  1140. {
  1141. if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
  1142. {
  1143. int saved_tree_used = TREE_USED (decl);
  1144. TREE_USED (decl) = 1;
  1145. dbxout_symbol (decl, 0);
  1146. TREE_USED (decl) = saved_tree_used;
  1147. }
  1148. }
  1149. /* This is just a function-type adapter; dbxout_symbol does exactly
  1150. what we want but returns an int. */
  1151. static void
  1152. dbxout_type_decl (tree decl, int local)
  1153. {
  1154. dbxout_symbol (decl, local);
  1155. }
  1156. /* At the end of compilation, finish writing the symbol table.
  1157. The default is to call debug_free_queue but do nothing else. */
  1158. static void
  1159. dbxout_finish (const char *filename ATTRIBUTE_UNUSED)
  1160. {
  1161. #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
  1162. DBX_OUTPUT_MAIN_SOURCE_FILE_END (asm_out_file, filename);
  1163. #elif defined DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END
  1164. {
  1165. switch_to_section (text_section);
  1166. dbxout_begin_empty_stabs (N_SO);
  1167. dbxout_stab_value_internal_label ("Letext", 0);
  1168. }
  1169. #endif
  1170. debug_free_queue ();
  1171. }
  1172. /* Output the index of a type. */
  1173. static void
  1174. dbxout_type_index (tree type)
  1175. {
  1176. #ifndef DBX_USE_BINCL
  1177. stabstr_D (TYPE_SYMTAB_ADDRESS (type));
  1178. #else
  1179. struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
  1180. stabstr_C ('(');
  1181. stabstr_D (t->file_number);
  1182. stabstr_C (',');
  1183. stabstr_D (t->type_number);
  1184. stabstr_C (')');
  1185. #endif
  1186. }
  1187. /* Generate the symbols for any queued up type symbols we encountered
  1188. while generating the type info for some originally used symbol.
  1189. This might generate additional entries in the queue. Only when
  1190. the nesting depth goes to 0 is this routine called. */
  1191. static void
  1192. debug_flush_symbol_queue (void)
  1193. {
  1194. int i;
  1195. /* Make sure that additionally queued items are not flushed
  1196. prematurely. */
  1197. ++debug_nesting;
  1198. for (i = 0; i < symbol_queue_index; ++i)
  1199. {
  1200. /* If we pushed queued symbols then such symbols must be
  1201. output no matter what anyone else says. Specifically,
  1202. we need to make sure dbxout_symbol() thinks the symbol was
  1203. used and also we need to override TYPE_DECL_SUPPRESS_DEBUG
  1204. which may be set for outside reasons. */
  1205. int saved_tree_used = TREE_USED (symbol_queue[i]);
  1206. int saved_suppress_debug = TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]);
  1207. TREE_USED (symbol_queue[i]) = 1;
  1208. TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]) = 0;
  1209. #ifdef DBX_DEBUGGING_INFO
  1210. dbxout_symbol (symbol_queue[i], 0);
  1211. #endif
  1212. TREE_USED (symbol_queue[i]) = saved_tree_used;
  1213. TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]) = saved_suppress_debug;
  1214. }
  1215. symbol_queue_index = 0;
  1216. --debug_nesting;
  1217. }
  1218. /* Queue a type symbol needed as part of the definition of a decl
  1219. symbol. These symbols are generated when debug_flush_symbol_queue()
  1220. is called. */
  1221. static void
  1222. debug_queue_symbol (tree decl)
  1223. {
  1224. if (symbol_queue_index >= symbol_queue_size)
  1225. {
  1226. symbol_queue_size += 10;
  1227. symbol_queue = XRESIZEVEC (tree, symbol_queue, symbol_queue_size);
  1228. }
  1229. symbol_queue[symbol_queue_index++] = decl;
  1230. }
  1231. /* Free symbol queue. */
  1232. static void
  1233. debug_free_queue (void)
  1234. {
  1235. if (symbol_queue)
  1236. {
  1237. free (symbol_queue);
  1238. symbol_queue = NULL;
  1239. symbol_queue_size = 0;
  1240. }
  1241. }
  1242. /* Used in several places: evaluates to '0' for a private decl,
  1243. '1' for a protected decl, '2' for a public decl. */
  1244. #define DECL_ACCESSIBILITY_CHAR(DECL) \
  1245. (TREE_PRIVATE (DECL) ? '0' : TREE_PROTECTED (DECL) ? '1' : '2')
  1246. /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
  1247. This must be a separate function because anonymous unions require
  1248. recursive calls. */
  1249. static void
  1250. dbxout_type_fields (tree type)
  1251. {
  1252. tree tem;
  1253. /* Output the name, type, position (in bits), size (in bits) of each
  1254. field that we can support. */
  1255. for (tem = TYPE_FIELDS (type); tem; tem = DECL_CHAIN (tem))
  1256. {
  1257. /* If one of the nodes is an error_mark or its type is then
  1258. return early. */
  1259. if (error_operand_p (tem))
  1260. return;
  1261. /* Omit here local type decls until we know how to support them. */
  1262. if (TREE_CODE (tem) == TYPE_DECL
  1263. /* Omit here the nameless fields that are used to skip bits. */
  1264. || DECL_IGNORED_P (tem)
  1265. /* Omit fields whose position or size are variable or too large to
  1266. represent. */
  1267. || (TREE_CODE (tem) == FIELD_DECL
  1268. && (! tree_fits_shwi_p (bit_position (tem))
  1269. || ! DECL_SIZE (tem)
  1270. || ! tree_fits_uhwi_p (DECL_SIZE (tem)))))
  1271. continue;
  1272. else if (TREE_CODE (tem) != CONST_DECL)
  1273. {
  1274. /* Continue the line if necessary,
  1275. but not before the first field. */
  1276. if (tem != TYPE_FIELDS (type))
  1277. CONTIN;
  1278. if (DECL_NAME (tem))
  1279. stabstr_I (DECL_NAME (tem));
  1280. stabstr_C (':');
  1281. if (use_gnu_debug_info_extensions
  1282. && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
  1283. || TREE_CODE (tem) != FIELD_DECL))
  1284. {
  1285. stabstr_C ('/');
  1286. stabstr_C (DECL_ACCESSIBILITY_CHAR (tem));
  1287. }
  1288. dbxout_type ((TREE_CODE (tem) == FIELD_DECL
  1289. && DECL_BIT_FIELD_TYPE (tem))
  1290. ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
  1291. if (TREE_CODE (tem) == VAR_DECL)
  1292. {
  1293. if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
  1294. {
  1295. tree name = DECL_ASSEMBLER_NAME (tem);
  1296. stabstr_C (':');
  1297. stabstr_I (name);
  1298. stabstr_C (';');
  1299. }
  1300. else
  1301. /* If TEM is non-static, GDB won't understand it. */
  1302. stabstr_S (",0,0;");
  1303. }
  1304. else
  1305. {
  1306. stabstr_C (',');
  1307. stabstr_D (int_bit_position (tem));
  1308. stabstr_C (',');
  1309. stabstr_D (tree_to_uhwi (DECL_SIZE (tem)));
  1310. stabstr_C (';');
  1311. }
  1312. }
  1313. }
  1314. }
  1315. /* Subroutine of `dbxout_type_methods'. Output debug info about the
  1316. method described DECL. */
  1317. static void
  1318. dbxout_type_method_1 (tree decl)
  1319. {
  1320. char c1 = 'A', c2;
  1321. if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
  1322. c2 = '?';
  1323. else /* it's a METHOD_TYPE. */
  1324. {
  1325. tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
  1326. /* A for normal functions.
  1327. B for `const' member functions.
  1328. C for `volatile' member functions.
  1329. D for `const volatile' member functions. */
  1330. if (TYPE_READONLY (TREE_TYPE (firstarg)))
  1331. c1 += 1;
  1332. if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
  1333. c1 += 2;
  1334. if (DECL_VINDEX (decl))
  1335. c2 = '*';
  1336. else
  1337. c2 = '.';
  1338. }
  1339. /* ??? Output the mangled name, which contains an encoding of the
  1340. method's type signature. May not be necessary anymore. */
  1341. stabstr_C (':');
  1342. stabstr_I (DECL_ASSEMBLER_NAME (decl));
  1343. stabstr_C (';');
  1344. stabstr_C (DECL_ACCESSIBILITY_CHAR (decl));
  1345. stabstr_C (c1);
  1346. stabstr_C (c2);
  1347. if (DECL_VINDEX (decl) && tree_fits_shwi_p (DECL_VINDEX (decl)))
  1348. {
  1349. stabstr_D (tree_to_shwi (DECL_VINDEX (decl)));
  1350. stabstr_C (';');
  1351. dbxout_type (DECL_CONTEXT (decl), 0);
  1352. stabstr_C (';');
  1353. }
  1354. }
  1355. /* Subroutine of `dbxout_type'. Output debug info about the methods defined
  1356. in TYPE. */
  1357. static void
  1358. dbxout_type_methods (tree type)
  1359. {
  1360. /* C++: put out the method names and their parameter lists */
  1361. tree methods = TYPE_METHODS (type);
  1362. tree fndecl;
  1363. tree last;
  1364. if (methods == NULL_TREE)
  1365. return;
  1366. if (TREE_CODE (methods) != TREE_VEC)
  1367. fndecl = methods;
  1368. else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
  1369. fndecl = TREE_VEC_ELT (methods, 0);
  1370. else
  1371. fndecl = TREE_VEC_ELT (methods, 1);
  1372. while (fndecl)
  1373. {
  1374. int need_prefix = 1;
  1375. /* Group together all the methods for the same operation.
  1376. These differ in the types of the arguments. */
  1377. for (last = NULL_TREE;
  1378. fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
  1379. fndecl = DECL_CHAIN (fndecl))
  1380. /* Output the name of the field (after overloading), as
  1381. well as the name of the field before overloading, along
  1382. with its parameter list */
  1383. {
  1384. /* Skip methods that aren't FUNCTION_DECLs. (In C++, these
  1385. include TEMPLATE_DECLs.) The debugger doesn't know what
  1386. to do with such entities anyhow. */
  1387. if (TREE_CODE (fndecl) != FUNCTION_DECL)
  1388. continue;
  1389. CONTIN;
  1390. last = fndecl;
  1391. /* Also ignore abstract methods; those are only interesting to
  1392. the DWARF backends. */
  1393. if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT_P (fndecl))
  1394. continue;
  1395. /* Redundantly output the plain name, since that's what gdb
  1396. expects. */
  1397. if (need_prefix)
  1398. {
  1399. stabstr_I (DECL_NAME (fndecl));
  1400. stabstr_S ("::");
  1401. need_prefix = 0;
  1402. }
  1403. dbxout_type (TREE_TYPE (fndecl), 0);
  1404. dbxout_type_method_1 (fndecl);
  1405. }
  1406. if (!need_prefix)
  1407. stabstr_C (';');
  1408. }
  1409. }
  1410. /* Emit a "range" type specification, which has the form:
  1411. "r<index type>;<lower bound>;<upper bound>;".
  1412. TYPE is an INTEGER_TYPE, LOW and HIGH are the bounds. */
  1413. static void
  1414. dbxout_range_type (tree type, tree low, tree high)
  1415. {
  1416. stabstr_C ('r');
  1417. if (TREE_TYPE (type))
  1418. dbxout_type (TREE_TYPE (type), 0);
  1419. else if (TREE_CODE (type) != INTEGER_TYPE)
  1420. dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
  1421. else
  1422. {
  1423. /* Traditionally, we made sure 'int' was type 1, and builtin types
  1424. were defined to be sub-ranges of int. Unfortunately, this
  1425. does not allow us to distinguish true sub-ranges from integer
  1426. types. So, instead we define integer (non-sub-range) types as
  1427. sub-ranges of themselves. This matters for Chill. If this isn't
  1428. a subrange type, then we want to define it in terms of itself.
  1429. However, in C, this may be an anonymous integer type, and we don't
  1430. want to emit debug info referring to it. Just calling
  1431. dbxout_type_index won't work anyways, because the type hasn't been
  1432. defined yet. We make this work for both cases by checked to see
  1433. whether this is a defined type, referring to it if it is, and using
  1434. 'int' otherwise. */
  1435. if (TYPE_SYMTAB_ADDRESS (type) != 0)
  1436. dbxout_type_index (type);
  1437. else
  1438. dbxout_type_index (integer_type_node);
  1439. }
  1440. stabstr_C (';');
  1441. if (low && tree_fits_shwi_p (low))
  1442. {
  1443. if (print_int_cst_bounds_in_octal_p (type, low, high))
  1444. stabstr_O (low);
  1445. else
  1446. stabstr_D (tree_to_shwi (low));
  1447. }
  1448. else
  1449. stabstr_C ('0');
  1450. stabstr_C (';');
  1451. if (high && tree_fits_shwi_p (high))
  1452. {
  1453. if (print_int_cst_bounds_in_octal_p (type, low, high))
  1454. stabstr_O (high);
  1455. else
  1456. stabstr_D (tree_to_shwi (high));
  1457. stabstr_C (';');
  1458. }
  1459. else
  1460. stabstr_S ("-1;");
  1461. }
  1462. /* Output a reference to a type. If the type has not yet been
  1463. described in the dbx output, output its definition now.
  1464. For a type already defined, just refer to its definition
  1465. using the type number.
  1466. If FULL is nonzero, and the type has been described only with
  1467. a forward-reference, output the definition now.
  1468. If FULL is zero in this case, just refer to the forward-reference
  1469. using the number previously allocated. */
  1470. static void
  1471. dbxout_type (tree type, int full)
  1472. {
  1473. static int anonymous_type_number = 0;
  1474. tree tem, main_variant, low, high;
  1475. if (TREE_CODE (type) == INTEGER_TYPE)
  1476. {
  1477. if (TREE_TYPE (type) == 0)
  1478. {
  1479. low = TYPE_MIN_VALUE (type);
  1480. high = TYPE_MAX_VALUE (type);
  1481. }
  1482. else if (subrange_type_for_debug_p (type, &low, &high))
  1483. ;
  1484. /* If this is a subtype that should not be emitted as a subrange type,
  1485. use the base type. */
  1486. else
  1487. {
  1488. type = TREE_TYPE (type);
  1489. low = TYPE_MIN_VALUE (type);
  1490. high = TYPE_MAX_VALUE (type);
  1491. }
  1492. }
  1493. /* If there was an input error and we don't really have a type,
  1494. avoid crashing and write something that is at least valid
  1495. by assuming `int'. */
  1496. if (type == error_mark_node)
  1497. type = integer_type_node;
  1498. else
  1499. {
  1500. if (TYPE_NAME (type)
  1501. && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  1502. && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
  1503. full = 0;
  1504. }
  1505. /* Try to find the "main variant" with the same name. */
  1506. if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  1507. && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
  1508. main_variant = TREE_TYPE (TYPE_NAME (type));
  1509. else
  1510. main_variant = TYPE_MAIN_VARIANT (type);
  1511. /* If we are not using extensions, stabs does not distinguish const and
  1512. volatile, so there is no need to make them separate types. */
  1513. if (!use_gnu_debug_info_extensions)
  1514. type = main_variant;
  1515. if (TYPE_SYMTAB_ADDRESS (type) == 0)
  1516. {
  1517. /* Type has no dbx number assigned. Assign next available number. */
  1518. TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
  1519. /* Make sure type vector is long enough to record about this type. */
  1520. if (next_type_number == typevec_len)
  1521. {
  1522. typevec = GGC_RESIZEVEC (struct typeinfo, typevec, typevec_len * 2);
  1523. memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]);
  1524. typevec_len *= 2;
  1525. }
  1526. #ifdef DBX_USE_BINCL
  1527. emit_pending_bincls_if_required ();
  1528. typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
  1529. = current_file->file_number;
  1530. typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
  1531. = current_file->next_type_number++;
  1532. #endif
  1533. }
  1534. if (flag_debug_only_used_symbols)
  1535. {
  1536. if ((TREE_CODE (type) == RECORD_TYPE
  1537. || TREE_CODE (type) == UNION_TYPE
  1538. || TREE_CODE (type) == QUAL_UNION_TYPE
  1539. || TREE_CODE (type) == ENUMERAL_TYPE)
  1540. && TYPE_STUB_DECL (type)
  1541. && DECL_P (TYPE_STUB_DECL (type))
  1542. && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
  1543. debug_queue_symbol (TYPE_STUB_DECL (type));
  1544. else if (TYPE_NAME (type)
  1545. && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
  1546. debug_queue_symbol (TYPE_NAME (type));
  1547. }
  1548. /* Output the number of this type, to refer to it. */
  1549. dbxout_type_index (type);
  1550. #ifdef DBX_TYPE_DEFINED
  1551. if (DBX_TYPE_DEFINED (type))
  1552. return;
  1553. #endif
  1554. /* If this type's definition has been output or is now being output,
  1555. that is all. */
  1556. switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
  1557. {
  1558. case TYPE_UNSEEN:
  1559. break;
  1560. case TYPE_XREF:
  1561. /* If we have already had a cross reference,
  1562. and either that's all we want or that's the best we could do,
  1563. don't repeat the cross reference.
  1564. Sun dbx crashes if we do. */
  1565. if (! full || !COMPLETE_TYPE_P (type)
  1566. /* No way in DBX fmt to describe a variable size. */
  1567. || ! tree_fits_uhwi_p (TYPE_SIZE (type)))
  1568. return;
  1569. break;
  1570. case TYPE_DEFINED:
  1571. return;
  1572. }
  1573. #ifdef DBX_NO_XREFS
  1574. /* For systems where dbx output does not allow the `=xsNAME:' syntax,
  1575. leave the type-number completely undefined rather than output
  1576. a cross-reference. If we have already used GNU debug info extensions,
  1577. then it is OK to output a cross reference. This is necessary to get
  1578. proper C++ debug output. */
  1579. if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
  1580. || TREE_CODE (type) == QUAL_UNION_TYPE
  1581. || TREE_CODE (type) == ENUMERAL_TYPE)
  1582. && ! use_gnu_debug_info_extensions)
  1583. /* We must use the same test here as we use twice below when deciding
  1584. whether to emit a cross-reference. */
  1585. if ((TYPE_NAME (type) != 0
  1586. && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  1587. && DECL_IGNORED_P (TYPE_NAME (type)))
  1588. && !full)
  1589. || !COMPLETE_TYPE_P (type)
  1590. /* No way in DBX fmt to describe a variable size. */
  1591. || ! tree_fits_uhwi_p (TYPE_SIZE (type)))
  1592. {
  1593. typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
  1594. return;
  1595. }
  1596. #endif
  1597. /* Output a definition now. */
  1598. stabstr_C ('=');
  1599. /* Mark it as defined, so that if it is self-referent
  1600. we will not get into an infinite recursion of definitions. */
  1601. typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
  1602. /* If this type is a variant of some other, hand off. Types with
  1603. different names are usefully distinguished. We only distinguish
  1604. cv-qualified types if we're using extensions. */
  1605. if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
  1606. {
  1607. stabstr_C ('k');
  1608. dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
  1609. return;
  1610. }
  1611. else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
  1612. {
  1613. stabstr_C ('B');
  1614. dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
  1615. return;
  1616. }
  1617. else if (main_variant != TYPE_MAIN_VARIANT (type))
  1618. {
  1619. if (flag_debug_only_used_symbols)
  1620. {
  1621. tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
  1622. if ((TREE_CODE (orig_type) == RECORD_TYPE
  1623. || TREE_CODE (orig_type) == UNION_TYPE
  1624. || TREE_CODE (orig_type) == QUAL_UNION_TYPE
  1625. || TREE_CODE (orig_type) == ENUMERAL_TYPE)
  1626. && TYPE_STUB_DECL (orig_type)
  1627. && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type)))
  1628. debug_queue_symbol (TYPE_STUB_DECL (orig_type));
  1629. }
  1630. /* 'type' is a typedef; output the type it refers to. */
  1631. dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
  1632. return;
  1633. }
  1634. /* else continue. */
  1635. switch (TREE_CODE (type))
  1636. {
  1637. case VOID_TYPE:
  1638. case NULLPTR_TYPE:
  1639. case LANG_TYPE:
  1640. /* For a void type, just define it as itself; i.e., "5=5".
  1641. This makes us consider it defined
  1642. without saying what it is. The debugger will make it
  1643. a void type when the reference is seen, and nothing will
  1644. ever override that default. */
  1645. dbxout_type_index (type);
  1646. break;
  1647. case INTEGER_TYPE:
  1648. if (type == char_type_node && ! TYPE_UNSIGNED (type))
  1649. {
  1650. /* Output the type `char' as a subrange of itself!
  1651. I don't understand this definition, just copied it
  1652. from the output of pcc.
  1653. This used to use `r2' explicitly and we used to
  1654. take care to make sure that `char' was type number 2. */
  1655. stabstr_C ('r');
  1656. dbxout_type_index (type);
  1657. stabstr_S (";0;127;");
  1658. }
  1659. /* If this is a subtype of another integer type, always prefer to
  1660. write it as a subtype. */
  1661. else if (TREE_TYPE (type) != 0
  1662. && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
  1663. {
  1664. /* If the size is non-standard, say what it is if we can use
  1665. GDB extensions. */
  1666. if (use_gnu_debug_info_extensions
  1667. && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
  1668. {
  1669. stabstr_S ("@s");
  1670. stabstr_D (TYPE_PRECISION (type));
  1671. stabstr_C (';');
  1672. }
  1673. dbxout_range_type (type, low, high);
  1674. }
  1675. else
  1676. {
  1677. /* If the size is non-standard, say what it is if we can use
  1678. GDB extensions. */
  1679. if (use_gnu_debug_info_extensions
  1680. && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
  1681. {
  1682. stabstr_S ("@s");
  1683. stabstr_D (TYPE_PRECISION (type));
  1684. stabstr_C (';');
  1685. }
  1686. if (print_int_cst_bounds_in_octal_p (type, low, high))
  1687. {
  1688. stabstr_C ('r');
  1689. /* If this type derives from another type, output type index of
  1690. parent type. This is particularly important when parent type
  1691. is an enumerated type, because not generating the parent type
  1692. index would transform the definition of this enumerated type
  1693. into a plain unsigned type. */
  1694. if (TREE_TYPE (type) != 0)
  1695. dbxout_type_index (TREE_TYPE (type));
  1696. else
  1697. dbxout_type_index (type);
  1698. stabstr_C (';');
  1699. stabstr_O (low);
  1700. stabstr_C (';');
  1701. stabstr_O (high);
  1702. stabstr_C (';');
  1703. }
  1704. else
  1705. /* Output other integer types as subranges of `int'. */
  1706. dbxout_range_type (type, low, high);
  1707. }
  1708. break;
  1709. case REAL_TYPE:
  1710. case FIXED_POINT_TYPE:
  1711. /* This used to say `r1' and we used to take care
  1712. to make sure that `int' was type number 1. */
  1713. stabstr_C ('r');
  1714. dbxout_type_index (integer_type_node);
  1715. stabstr_C (';');
  1716. stabstr_D (int_size_in_bytes (type));
  1717. stabstr_S (";0;");
  1718. break;
  1719. case BOOLEAN_TYPE:
  1720. if (use_gnu_debug_info_extensions)
  1721. {
  1722. stabstr_S ("@s");
  1723. stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
  1724. stabstr_S (";-16;");
  1725. }
  1726. else /* Define as enumeral type (False, True) */
  1727. stabstr_S ("eFalse:0,True:1,;");
  1728. break;
  1729. case COMPLEX_TYPE:
  1730. /* Differs from the REAL_TYPE by its new data type number.
  1731. R3 is NF_COMPLEX. We don't try to use any of the other NF_*
  1732. codes since gdb doesn't care anyway. */
  1733. if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
  1734. {
  1735. stabstr_S ("R3;");
  1736. stabstr_D (2 * int_size_in_bytes (TREE_TYPE (type)));
  1737. stabstr_S (";0;");
  1738. }
  1739. else
  1740. {
  1741. /* Output a complex integer type as a structure,
  1742. pending some other way to do it. */
  1743. stabstr_C ('s');
  1744. stabstr_D (int_size_in_bytes (type));
  1745. stabstr_S ("real:");
  1746. dbxout_type (TREE_TYPE (type), 0);
  1747. stabstr_S (",0,");
  1748. stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
  1749. stabstr_S (";imag:");
  1750. dbxout_type (TREE_TYPE (type), 0);
  1751. stabstr_C (',');
  1752. stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
  1753. stabstr_C (',');
  1754. stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
  1755. stabstr_S (";;");
  1756. }
  1757. break;
  1758. case ARRAY_TYPE:
  1759. /* Make arrays of packed bits look like bitstrings for chill. */
  1760. if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
  1761. {
  1762. stabstr_S ("@s");
  1763. stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
  1764. stabstr_S (";@S;S");
  1765. dbxout_type (TYPE_DOMAIN (type), 0);
  1766. break;
  1767. }
  1768. /* Output "a" followed by a range type definition
  1769. for the index type of the array
  1770. followed by a reference to the target-type.
  1771. ar1;0;N;M for a C array of type M and size N+1. */
  1772. /* Check if a character string type, which in Chill is
  1773. different from an array of characters. */
  1774. if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
  1775. {
  1776. stabstr_S ("@S;");
  1777. }
  1778. tem = TYPE_DOMAIN (type);
  1779. if (tem == NULL)
  1780. {
  1781. stabstr_S ("ar");
  1782. dbxout_type_index (integer_type_node);
  1783. stabstr_S (";0;-1;");
  1784. }
  1785. else
  1786. {
  1787. stabstr_C ('a');
  1788. dbxout_range_type (tem, TYPE_MIN_VALUE (tem), TYPE_MAX_VALUE (tem));
  1789. }
  1790. dbxout_type (TREE_TYPE (type), 0);
  1791. break;
  1792. case VECTOR_TYPE:
  1793. /* Make vectors look like an array. */
  1794. if (use_gnu_debug_info_extensions)
  1795. stabstr_S ("@V;");
  1796. /* Output "a" followed by a range type definition
  1797. for the index type of the array
  1798. followed by a reference to the target-type.
  1799. ar1;0;N;M for a C array of type M and size N+1. */
  1800. stabstr_C ('a');
  1801. dbxout_range_type (integer_type_node, size_zero_node,
  1802. size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
  1803. dbxout_type (TREE_TYPE (type), 0);
  1804. break;
  1805. case RECORD_TYPE:
  1806. case UNION_TYPE:
  1807. case QUAL_UNION_TYPE:
  1808. {
  1809. tree binfo = TYPE_BINFO (type);
  1810. /* Output a structure type. We must use the same test here as we
  1811. use in the DBX_NO_XREFS case above. */
  1812. if ((TYPE_NAME (type) != 0
  1813. && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  1814. && DECL_IGNORED_P (TYPE_NAME (type)))
  1815. && !full)
  1816. || !COMPLETE_TYPE_P (type)
  1817. /* No way in DBX fmt to describe a variable size. */
  1818. || ! tree_fits_uhwi_p (TYPE_SIZE (type)))
  1819. {
  1820. /* If the type is just a cross reference, output one
  1821. and mark the type as partially described.
  1822. If it later becomes defined, we will output
  1823. its real definition.
  1824. If the type has a name, don't nest its definition within
  1825. another type's definition; instead, output an xref
  1826. and let the definition come when the name is defined. */
  1827. stabstr_S ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
  1828. if (TYPE_IDENTIFIER (type))
  1829. {
  1830. /* Note that the C frontend creates for anonymous variable
  1831. length records/unions TYPE_NAME with DECL_NAME NULL. */
  1832. dbxout_type_name (type);
  1833. }
  1834. else
  1835. {
  1836. stabstr_S ("$$");
  1837. stabstr_D (anonymous_type_number++);
  1838. }
  1839. stabstr_C (':');
  1840. typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
  1841. break;
  1842. }
  1843. /* Identify record or union, and print its size. */
  1844. stabstr_C ((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u');
  1845. stabstr_D (int_size_in_bytes (type));
  1846. if (binfo)
  1847. {
  1848. int i;
  1849. tree child;
  1850. vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
  1851. if (use_gnu_debug_info_extensions)
  1852. {
  1853. if (BINFO_N_BASE_BINFOS (binfo))
  1854. {
  1855. stabstr_C ('!');
  1856. stabstr_U (BINFO_N_BASE_BINFOS (binfo));
  1857. stabstr_C (',');
  1858. }
  1859. }
  1860. for (i = 0; BINFO_BASE_ITERATE (binfo, i, child); i++)
  1861. {
  1862. tree access = (accesses ? (*accesses)[i] : access_public_node);
  1863. if (use_gnu_debug_info_extensions)
  1864. {
  1865. stabstr_C (BINFO_VIRTUAL_P (child) ? '1' : '0');
  1866. stabstr_C (access == access_public_node ? '2' :
  1867. access == access_protected_node
  1868. ? '1' :'0');
  1869. if (BINFO_VIRTUAL_P (child)
  1870. && (lang_GNU_CXX ()
  1871. || strcmp (lang_hooks.name, "GNU Objective-C++") == 0))
  1872. /* For a virtual base, print the (negative)
  1873. offset within the vtable where we must look
  1874. to find the necessary adjustment. */
  1875. stabstr_D
  1876. (tree_to_shwi (BINFO_VPTR_FIELD (child))
  1877. * BITS_PER_UNIT);
  1878. else
  1879. stabstr_D (tree_to_shwi (BINFO_OFFSET (child))
  1880. * BITS_PER_UNIT);
  1881. stabstr_C (',');
  1882. dbxout_type (BINFO_TYPE (child), 0);
  1883. stabstr_C (';');
  1884. }
  1885. else
  1886. {
  1887. /* Print out the base class information with
  1888. fields which have the same names at the types
  1889. they hold. */
  1890. dbxout_type_name (BINFO_TYPE (child));
  1891. stabstr_C (':');
  1892. dbxout_type (BINFO_TYPE (child), full);
  1893. stabstr_C (',');
  1894. stabstr_D (tree_to_shwi (BINFO_OFFSET (child))
  1895. * BITS_PER_UNIT);
  1896. stabstr_C (',');
  1897. stabstr_D
  1898. (tree_to_shwi (TYPE_SIZE (BINFO_TYPE (child)))
  1899. * BITS_PER_UNIT);
  1900. stabstr_C (';');
  1901. }
  1902. }
  1903. }
  1904. }
  1905. /* Write out the field declarations. */
  1906. dbxout_type_fields (type);
  1907. if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
  1908. {
  1909. dbxout_type_methods (type);
  1910. }
  1911. stabstr_C (';');
  1912. if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
  1913. /* Avoid the ~ if we don't really need it--it confuses dbx. */
  1914. && TYPE_VFIELD (type))
  1915. {
  1916. /* We need to write out info about what field this class
  1917. uses as its "main" vtable pointer field, because if this
  1918. field is inherited from a base class, GDB cannot necessarily
  1919. figure out which field it's using in time. */
  1920. stabstr_S ("~%");
  1921. dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
  1922. stabstr_C (';');
  1923. }
  1924. break;
  1925. case ENUMERAL_TYPE:
  1926. /* We must use the same test here as we use in the DBX_NO_XREFS case
  1927. above. We simplify it a bit since an enum will never have a variable
  1928. size. */
  1929. if ((TYPE_NAME (type) != 0
  1930. && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  1931. && DECL_IGNORED_P (TYPE_NAME (type)))
  1932. && !full)
  1933. || !COMPLETE_TYPE_P (type))
  1934. {
  1935. stabstr_S ("xe");
  1936. dbxout_type_name (type);
  1937. typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
  1938. stabstr_C (':');
  1939. return;
  1940. }
  1941. if (use_gnu_debug_info_extensions
  1942. && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
  1943. {
  1944. stabstr_S ("@s");
  1945. stabstr_D (TYPE_PRECISION (type));
  1946. stabstr_C (';');
  1947. }
  1948. stabstr_C ('e');
  1949. for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
  1950. {
  1951. tree value = TREE_VALUE (tem);
  1952. stabstr_I (TREE_PURPOSE (tem));
  1953. stabstr_C (':');
  1954. if (TREE_CODE (value) == CONST_DECL)
  1955. value = DECL_INITIAL (value);
  1956. if (cst_and_fits_in_hwi (value))
  1957. stabstr_D (TREE_INT_CST_LOW (value));
  1958. else
  1959. stabstr_O (value);
  1960. stabstr_C (',');
  1961. if (TREE_CHAIN (tem) != 0)
  1962. CONTIN;
  1963. }
  1964. stabstr_C (';');
  1965. break;
  1966. case POINTER_TYPE:
  1967. stabstr_C ('*');
  1968. dbxout_type (TREE_TYPE (type), 0);
  1969. break;
  1970. case METHOD_TYPE:
  1971. if (use_gnu_debug_info_extensions)
  1972. {
  1973. stabstr_C ('#');
  1974. /* Write the argument types out longhand. */
  1975. dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
  1976. stabstr_C (',');
  1977. dbxout_type (TREE_TYPE (type), 0);
  1978. dbxout_args (TYPE_ARG_TYPES (type));
  1979. stabstr_C (';');
  1980. }
  1981. else
  1982. /* Treat it as a function type. */
  1983. dbxout_type (TREE_TYPE (type), 0);
  1984. break;
  1985. case OFFSET_TYPE:
  1986. if (use_gnu_debug_info_extensions)
  1987. {
  1988. stabstr_C ('@');
  1989. dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
  1990. stabstr_C (',');
  1991. dbxout_type (TREE_TYPE (type), 0);
  1992. }
  1993. else
  1994. /* Should print as an int, because it is really just an offset. */
  1995. dbxout_type (integer_type_node, 0);
  1996. break;
  1997. case REFERENCE_TYPE:
  1998. if (use_gnu_debug_info_extensions)
  1999. {
  2000. stabstr_C ('&');
  2001. }
  2002. else
  2003. stabstr_C ('*');
  2004. dbxout_type (TREE_TYPE (type), 0);
  2005. break;
  2006. case FUNCTION_TYPE:
  2007. stabstr_C ('f');
  2008. dbxout_type (TREE_TYPE (type), 0);
  2009. break;
  2010. case POINTER_BOUNDS_TYPE:
  2011. /* No debug info for pointer bounds type supported yet. */
  2012. break;
  2013. default:
  2014. /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
  2015. named 'auto' in its type.
  2016. No debug info for TEMPLATE_TYPE_PARM type supported yet. */
  2017. if (lang_GNU_CXX ())
  2018. {
  2019. tree name = TYPE_IDENTIFIER (type);
  2020. if (name == get_identifier ("auto")
  2021. || name == get_identifier ("decltype(auto)"))
  2022. break;
  2023. }
  2024. gcc_unreachable ();
  2025. }
  2026. }
  2027. /* Return nonzero if the given type represents an integer whose bounds
  2028. should be printed in octal format. */
  2029. static bool
  2030. print_int_cst_bounds_in_octal_p (tree type, tree low, tree high)
  2031. {
  2032. /* If we can use GDB extensions and the size is wider than a long
  2033. (the size used by GDB to read them) or we may have trouble writing
  2034. the bounds the usual way, write them in octal. Note the test is for
  2035. the *target's* size of "long", not that of the host. The host test
  2036. is just to make sure we can write it out in case the host wide int
  2037. is narrower than the target "long".
  2038. For unsigned types, we use octal if they are the same size or larger.
  2039. This is because we print the bounds as signed decimal, and hence they
  2040. can't span same size unsigned types. */
  2041. if (use_gnu_debug_info_extensions
  2042. && low && TREE_CODE (low) == INTEGER_CST
  2043. && high && TREE_CODE (high) == INTEGER_CST
  2044. && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
  2045. || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
  2046. && TYPE_UNSIGNED (type))
  2047. || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
  2048. || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
  2049. && TYPE_UNSIGNED (type))))
  2050. return TRUE;
  2051. else
  2052. return FALSE;
  2053. }
  2054. /* Output the name of type TYPE, with no punctuation.
  2055. Such names can be set up either by typedef declarations
  2056. or by struct, enum and union tags. */
  2057. static void
  2058. dbxout_type_name (tree type)
  2059. {
  2060. tree t = TYPE_NAME (type);
  2061. gcc_assert (t);
  2062. switch (TREE_CODE (t))
  2063. {
  2064. case IDENTIFIER_NODE:
  2065. break;
  2066. case TYPE_DECL:
  2067. t = DECL_NAME (t);
  2068. break;
  2069. default:
  2070. gcc_unreachable ();
  2071. }
  2072. stabstr_I (t);
  2073. }
  2074. /* Output leading leading struct or class names needed for qualifying
  2075. type whose scope is limited to a struct or class. */
  2076. static void
  2077. dbxout_class_name_qualifiers (tree decl)
  2078. {
  2079. tree context = decl_type_context (decl);
  2080. if (context != NULL_TREE
  2081. && TREE_CODE (context) == RECORD_TYPE
  2082. && TYPE_NAME (context) != 0
  2083. && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
  2084. || (DECL_NAME (TYPE_NAME (context)) != 0)))
  2085. {
  2086. tree name = TYPE_NAME (context);
  2087. if (TREE_CODE (name) == TYPE_DECL)
  2088. {
  2089. dbxout_class_name_qualifiers (name);
  2090. name = DECL_NAME (name);
  2091. }
  2092. stabstr_I (name);
  2093. stabstr_S ("::");
  2094. }
  2095. }
  2096. /* This is a specialized subset of expand_expr for use by dbxout_symbol in
  2097. evaluating DECL_VALUE_EXPR. In particular, we stop if we find decls that
  2098. haven't been expanded, or if the expression is getting so complex we won't
  2099. be able to represent it in stabs anyway. Returns NULL on failure. */
  2100. static rtx
  2101. dbxout_expand_expr (tree expr)
  2102. {
  2103. switch (TREE_CODE (expr))
  2104. {
  2105. case VAR_DECL:
  2106. /* We can't handle emulated tls variables, because the address is an
  2107. offset to the return value of __emutls_get_address, and there is no
  2108. way to express that in stabs. Also, there are name mangling issues
  2109. here. We end up with references to undefined symbols if we don't
  2110. disable debug info for these variables. */
  2111. if (!targetm.have_tls && DECL_THREAD_LOCAL_P (expr))
  2112. return NULL;
  2113. if (TREE_STATIC (expr)
  2114. && !TREE_ASM_WRITTEN (expr)
  2115. && !DECL_HAS_VALUE_EXPR_P (expr)
  2116. && !TREE_PUBLIC (expr)
  2117. && DECL_RTL_SET_P (expr)
  2118. && MEM_P (DECL_RTL (expr)))
  2119. {
  2120. /* If this is a var that might not be actually output,
  2121. return NULL, otherwise stabs might reference an undefined
  2122. symbol. */
  2123. varpool_node *node = varpool_node::get (expr);
  2124. if (!node || !node->definition)
  2125. return NULL;
  2126. }
  2127. /* FALLTHRU */
  2128. case PARM_DECL:
  2129. case RESULT_DECL:
  2130. if (DECL_HAS_VALUE_EXPR_P (expr))
  2131. return dbxout_expand_expr (DECL_VALUE_EXPR (expr));
  2132. /* FALLTHRU */
  2133. case CONST_DECL:
  2134. return DECL_RTL_IF_SET (expr);
  2135. case INTEGER_CST:
  2136. return expand_expr (expr, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
  2137. case COMPONENT_REF:
  2138. case ARRAY_REF:
  2139. case ARRAY_RANGE_REF:
  2140. case BIT_FIELD_REF:
  2141. {
  2142. machine_mode mode;
  2143. HOST_WIDE_INT bitsize, bitpos;
  2144. tree offset, tem;
  2145. int volatilep = 0, unsignedp = 0;
  2146. rtx x;
  2147. tem = get_inner_reference (expr, &bitsize, &bitpos, &offset,
  2148. &mode, &unsignedp, &volatilep, true);
  2149. x = dbxout_expand_expr (tem);
  2150. if (x == NULL || !MEM_P (x))
  2151. return NULL;
  2152. if (offset != NULL)
  2153. {
  2154. if (!tree_fits_shwi_p (offset))
  2155. return NULL;
  2156. x = adjust_address_nv (x, mode, tree_to_shwi (offset));
  2157. }
  2158. if (bitpos != 0)
  2159. x = adjust_address_nv (x, mode, bitpos / BITS_PER_UNIT);
  2160. return x;
  2161. }
  2162. default:
  2163. return NULL;
  2164. }
  2165. }
  2166. /* Helper function for output_used_types. Queue one entry from the
  2167. used types hash to be output. */
  2168. bool
  2169. output_used_types_helper (tree const &type, vec<tree> *types_p)
  2170. {
  2171. if ((TREE_CODE (type) == RECORD_TYPE
  2172. || TREE_CODE (type) == UNION_TYPE
  2173. || TREE_CODE (type) == QUAL_UNION_TYPE
  2174. || TREE_CODE (type) == ENUMERAL_TYPE)
  2175. && TYPE_STUB_DECL (type)
  2176. && DECL_P (TYPE_STUB_DECL (type))
  2177. && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
  2178. types_p->quick_push (TYPE_STUB_DECL (type));
  2179. else if (TYPE_NAME (type)
  2180. && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
  2181. types_p->quick_push (TYPE_NAME (type));
  2182. return true;
  2183. }
  2184. /* This is a qsort callback which sorts types and declarations into a
  2185. predictable order (types, then declarations, sorted by UID
  2186. within). */
  2187. static int
  2188. output_types_sort (const void *pa, const void *pb)
  2189. {
  2190. const tree lhs = *((const tree *)pa);
  2191. const tree rhs = *((const tree *)pb);
  2192. if (TYPE_P (lhs))
  2193. {
  2194. if (TYPE_P (rhs))
  2195. return TYPE_UID (lhs) - TYPE_UID (rhs);
  2196. else
  2197. return 1;
  2198. }
  2199. else
  2200. {
  2201. if (TYPE_P (rhs))
  2202. return -1;
  2203. else
  2204. return DECL_UID (lhs) - DECL_UID (rhs);
  2205. }
  2206. }
  2207. /* Force all types used by this function to be output in debug
  2208. information. */
  2209. static void
  2210. output_used_types (void)
  2211. {
  2212. if (cfun && cfun->used_types_hash)
  2213. {
  2214. vec<tree> types;
  2215. int i;
  2216. tree type;
  2217. types.create (cfun->used_types_hash->elements ());
  2218. cfun->used_types_hash->traverse<vec<tree> *, output_used_types_helper>
  2219. (&types);
  2220. /* Sort by UID to prevent dependence on hash table ordering. */
  2221. types.qsort (output_types_sort);
  2222. FOR_EACH_VEC_ELT (types, i, type)
  2223. debug_queue_symbol (type);
  2224. types.release ();
  2225. }
  2226. }
  2227. /* Output a .stabs for the symbol defined by DECL,
  2228. which must be a ..._DECL node in the normal namespace.
  2229. It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
  2230. LOCAL is nonzero if the scope is less than the entire file.
  2231. Return 1 if a stabs might have been emitted. */
  2232. int
  2233. dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
  2234. {
  2235. tree type = TREE_TYPE (decl);
  2236. tree context = NULL_TREE;
  2237. int result = 0;
  2238. rtx decl_rtl;
  2239. /* "Intercept" dbxout_symbol() calls like we do all debug_hooks. */
  2240. ++debug_nesting;
  2241. /* Ignore nameless syms, but don't ignore type tags. */
  2242. if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
  2243. || DECL_IGNORED_P (decl))
  2244. DBXOUT_DECR_NESTING_AND_RETURN (0);
  2245. /* If we are to generate only the symbols actually used then such
  2246. symbol nodes are flagged with TREE_USED. Ignore any that
  2247. aren't flagged as TREE_USED. */
  2248. if (flag_debug_only_used_symbols
  2249. && (!TREE_USED (decl)
  2250. && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl))))
  2251. DBXOUT_DECR_NESTING_AND_RETURN (0);
  2252. /* If dbxout_init has not yet run, queue this symbol for later. */
  2253. if (!typevec)
  2254. {
  2255. preinit_symbols = tree_cons (0, decl, preinit_symbols);
  2256. DBXOUT_DECR_NESTING_AND_RETURN (0);
  2257. }
  2258. if (flag_debug_only_used_symbols)
  2259. {
  2260. tree t;
  2261. /* We now have a used symbol. We need to generate the info for
  2262. the symbol's type in addition to the symbol itself. These
  2263. type symbols are queued to be generated after were done with
  2264. the symbol itself (otherwise they would fight over the
  2265. stabstr obstack).
  2266. Note, because the TREE_TYPE(type) might be something like a
  2267. pointer to a named type we need to look for the first name
  2268. we see following the TREE_TYPE chain. */
  2269. t = type;
  2270. while (POINTER_TYPE_P (t))
  2271. t = TREE_TYPE (t);
  2272. /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
  2273. need special treatment. The TYPE_STUB_DECL field in these
  2274. types generally represents the tag name type we want to
  2275. output. In addition there could be a typedef type with
  2276. a different name. In that case we also want to output
  2277. that. */
  2278. if (TREE_CODE (t) == RECORD_TYPE
  2279. || TREE_CODE (t) == UNION_TYPE
  2280. || TREE_CODE (t) == QUAL_UNION_TYPE
  2281. || TREE_CODE (t) == ENUMERAL_TYPE)
  2282. {
  2283. if (TYPE_STUB_DECL (t)
  2284. && TYPE_STUB_DECL (t) != decl
  2285. && DECL_P (TYPE_STUB_DECL (t))
  2286. && ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
  2287. {
  2288. debug_queue_symbol (TYPE_STUB_DECL (t));
  2289. if (TYPE_NAME (t)
  2290. && TYPE_NAME (t) != TYPE_STUB_DECL (t)
  2291. && TYPE_NAME (t) != decl
  2292. && DECL_P (TYPE_NAME (t)))
  2293. debug_queue_symbol (TYPE_NAME (t));
  2294. }
  2295. }
  2296. else if (TYPE_NAME (t)
  2297. && TYPE_NAME (t) != decl
  2298. && DECL_P (TYPE_NAME (t)))
  2299. debug_queue_symbol (TYPE_NAME (t));
  2300. }
  2301. emit_pending_bincls_if_required ();
  2302. switch (TREE_CODE (decl))
  2303. {
  2304. case CONST_DECL:
  2305. /* Enum values are defined by defining the enum type. */
  2306. break;
  2307. case FUNCTION_DECL:
  2308. decl_rtl = DECL_RTL_IF_SET (decl);
  2309. if (!decl_rtl)
  2310. DBXOUT_DECR_NESTING_AND_RETURN (0);
  2311. if (DECL_EXTERNAL (decl))
  2312. break;
  2313. /* Don't mention a nested function under its parent. */
  2314. context = decl_function_context (decl);
  2315. if (context == current_function_decl)
  2316. break;
  2317. /* Don't mention an inline instance of a nested function. */
  2318. if (context && DECL_FROM_INLINE (decl))
  2319. break;
  2320. if (!MEM_P (decl_rtl)
  2321. || GET_CODE (XEXP (decl_rtl, 0)) != SYMBOL_REF)
  2322. break;
  2323. if (flag_debug_only_used_symbols)
  2324. output_used_types ();
  2325. dbxout_begin_complex_stabs ();
  2326. stabstr_I (DECL_ASSEMBLER_NAME (decl));
  2327. stabstr_S (TREE_PUBLIC (decl) ? ":F" : ":f");
  2328. result = 1;
  2329. if (TREE_TYPE (type))
  2330. dbxout_type (TREE_TYPE (type), 0);
  2331. else
  2332. dbxout_type (void_type_node, 0);
  2333. /* For a nested function, when that function is compiled,
  2334. mention the containing function name
  2335. as well as (since dbx wants it) our own assembler-name. */
  2336. if (context != 0)
  2337. {
  2338. stabstr_C (',');
  2339. stabstr_I (DECL_ASSEMBLER_NAME (decl));
  2340. stabstr_C (',');
  2341. stabstr_I (DECL_NAME (context));
  2342. }
  2343. dbxout_finish_complex_stabs (decl, N_FUN, XEXP (decl_rtl, 0), 0, 0);
  2344. break;
  2345. case TYPE_DECL:
  2346. /* Don't output the same typedef twice.
  2347. And don't output what language-specific stuff doesn't want output. */
  2348. if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
  2349. DBXOUT_DECR_NESTING_AND_RETURN (0);
  2350. /* Don't output typedefs for types with magic type numbers (XCOFF). */
  2351. #ifdef DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER
  2352. {
  2353. int fundamental_type_number =
  2354. DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER (decl);
  2355. if (fundamental_type_number != 0)
  2356. {
  2357. TREE_ASM_WRITTEN (decl) = 1;
  2358. TYPE_SYMTAB_ADDRESS (TREE_TYPE (decl)) = fundamental_type_number;
  2359. DBXOUT_DECR_NESTING_AND_RETURN (0);
  2360. }
  2361. }
  2362. #endif
  2363. FORCE_TEXT;
  2364. result = 1;
  2365. {
  2366. int tag_needed = 1;
  2367. int did_output = 0;
  2368. if (DECL_NAME (decl))
  2369. {
  2370. /* Nonzero means we must output a tag as well as a typedef. */
  2371. tag_needed = 0;
  2372. /* Handle the case of a C++ structure or union
  2373. where the TYPE_NAME is a TYPE_DECL
  2374. which gives both a typedef name and a tag. */
  2375. /* dbx requires the tag first and the typedef second. */
  2376. if ((TREE_CODE (type) == RECORD_TYPE
  2377. || TREE_CODE (type) == UNION_TYPE
  2378. || TREE_CODE (type) == QUAL_UNION_TYPE)
  2379. && TYPE_NAME (type) == decl
  2380. && !use_gnu_debug_info_extensions
  2381. && !TREE_ASM_WRITTEN (TYPE_NAME (type))
  2382. /* Distinguish the implicit typedefs of C++
  2383. from explicit ones that might be found in C. */
  2384. && DECL_ARTIFICIAL (decl)
  2385. /* Do not generate a tag for incomplete records. */
  2386. && COMPLETE_TYPE_P (type)
  2387. /* Do not generate a tag for records of variable size,
  2388. since this type can not be properly described in the
  2389. DBX format, and it confuses some tools such as objdump. */
  2390. && tree_fits_uhwi_p (TYPE_SIZE (type)))
  2391. {
  2392. tree name = TYPE_IDENTIFIER (type);
  2393. dbxout_begin_complex_stabs ();
  2394. stabstr_I (name);
  2395. stabstr_S (":T");
  2396. dbxout_type (type, 1);
  2397. dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE,
  2398. 0, 0, 0);
  2399. }
  2400. dbxout_begin_complex_stabs ();
  2401. /* Output leading class/struct qualifiers. */
  2402. if (use_gnu_debug_info_extensions)
  2403. dbxout_class_name_qualifiers (decl);
  2404. /* Output typedef name. */
  2405. stabstr_I (DECL_NAME (decl));
  2406. stabstr_C (':');
  2407. /* Short cut way to output a tag also. */
  2408. if ((TREE_CODE (type) == RECORD_TYPE
  2409. || TREE_CODE (type) == UNION_TYPE
  2410. || TREE_CODE (type) == QUAL_UNION_TYPE)
  2411. && TYPE_NAME (type) == decl
  2412. /* Distinguish the implicit typedefs of C++
  2413. from explicit ones that might be found in C. */
  2414. && DECL_ARTIFICIAL (decl))
  2415. {
  2416. if (use_gnu_debug_info_extensions)
  2417. {
  2418. stabstr_C ('T');
  2419. TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
  2420. }
  2421. }
  2422. stabstr_C ('t');
  2423. dbxout_type (type, 1);
  2424. dbxout_finish_complex_stabs (decl, DBX_TYPE_DECL_STABS_CODE,
  2425. 0, 0, 0);
  2426. did_output = 1;
  2427. }
  2428. /* Don't output a tag if this is an incomplete type. This prevents
  2429. the sun4 Sun OS 4.x dbx from crashing. */
  2430. if (tag_needed && TYPE_NAME (type) != 0
  2431. && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
  2432. || (DECL_NAME (TYPE_NAME (type)) != 0))
  2433. && COMPLETE_TYPE_P (type)
  2434. && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
  2435. {
  2436. /* For a TYPE_DECL with no name, but the type has a name,
  2437. output a tag.
  2438. This is what represents `struct foo' with no typedef. */
  2439. /* In C++, the name of a type is the corresponding typedef.
  2440. In C, it is an IDENTIFIER_NODE. */
  2441. tree name = TYPE_IDENTIFIER (type);
  2442. dbxout_begin_complex_stabs ();
  2443. stabstr_I (name);
  2444. stabstr_S (":T");
  2445. dbxout_type (type, 1);
  2446. dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
  2447. did_output = 1;
  2448. }
  2449. /* If an enum type has no name, it cannot be referred to, but
  2450. we must output it anyway, to record the enumeration
  2451. constants. */
  2452. if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
  2453. {
  2454. dbxout_begin_complex_stabs ();
  2455. /* Some debuggers fail when given NULL names, so give this a
  2456. harmless name of " " (Why not "(anon)"?). */
  2457. stabstr_S (" :T");
  2458. dbxout_type (type, 1);
  2459. dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
  2460. }
  2461. /* Prevent duplicate output of a typedef. */
  2462. TREE_ASM_WRITTEN (decl) = 1;
  2463. break;
  2464. }
  2465. case PARM_DECL:
  2466. if (DECL_HAS_VALUE_EXPR_P (decl))
  2467. decl = DECL_VALUE_EXPR (decl);
  2468. /* PARM_DECLs go in their own separate chain and are output by
  2469. dbxout_reg_parms and dbxout_parms, except for those that are
  2470. disguised VAR_DECLs like Out parameters in Ada. */
  2471. gcc_assert (TREE_CODE (decl) == VAR_DECL);
  2472. /* ... fall through ... */
  2473. case RESULT_DECL:
  2474. case VAR_DECL:
  2475. /* Don't mention a variable that is external.
  2476. Let the file that defines it describe it. */
  2477. if (DECL_EXTERNAL (decl))
  2478. break;
  2479. /* If the variable is really a constant
  2480. and not written in memory, inform the debugger.
  2481. ??? Why do we skip emitting the type and location in this case? */
  2482. if (TREE_STATIC (decl) && TREE_READONLY (decl)
  2483. && DECL_INITIAL (decl) != 0
  2484. && tree_fits_shwi_p (DECL_INITIAL (decl))
  2485. && ! TREE_ASM_WRITTEN (decl)
  2486. && (DECL_FILE_SCOPE_P (decl)
  2487. || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK
  2488. || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
  2489. && TREE_PUBLIC (decl) == 0)
  2490. {
  2491. /* The sun4 assembler does not grok this. */
  2492. if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
  2493. || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
  2494. {
  2495. HOST_WIDE_INT ival = tree_to_shwi (DECL_INITIAL (decl));
  2496. dbxout_begin_complex_stabs ();
  2497. dbxout_symbol_name (decl, NULL, 'c');
  2498. stabstr_S ("=i");
  2499. stabstr_D (ival);
  2500. dbxout_finish_complex_stabs (0, N_LSYM, 0, 0, 0);
  2501. DBXOUT_DECR_NESTING;
  2502. return 1;
  2503. }
  2504. else
  2505. break;
  2506. }
  2507. /* else it is something we handle like a normal variable. */
  2508. decl_rtl = dbxout_expand_expr (decl);
  2509. if (!decl_rtl)
  2510. DBXOUT_DECR_NESTING_AND_RETURN (0);
  2511. if (!is_global_var (decl))
  2512. decl_rtl = eliminate_regs (decl_rtl, VOIDmode, NULL_RTX);
  2513. #ifdef LEAF_REG_REMAP
  2514. if (crtl->uses_only_leaf_regs)
  2515. leaf_renumber_regs_insn (decl_rtl);
  2516. #endif
  2517. result = dbxout_symbol_location (decl, type, 0, decl_rtl);
  2518. break;
  2519. default:
  2520. break;
  2521. }
  2522. DBXOUT_DECR_NESTING;
  2523. return result;
  2524. }
  2525. /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
  2526. Add SUFFIX to its name, if SUFFIX is not 0.
  2527. Describe the variable as residing in HOME
  2528. (usually HOME is DECL_RTL (DECL), but not always).
  2529. Returns 1 if the stab was really emitted. */
  2530. static int
  2531. dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
  2532. {
  2533. int letter = 0;
  2534. stab_code_type code;
  2535. rtx addr = 0;
  2536. int number = 0;
  2537. int regno = -1;
  2538. /* Don't mention a variable at all
  2539. if it was completely optimized into nothingness.
  2540. If the decl was from an inline function, then its rtl
  2541. is not identically the rtl that was used in this
  2542. particular compilation. */
  2543. if (GET_CODE (home) == SUBREG)
  2544. {
  2545. rtx value = home;
  2546. while (GET_CODE (value) == SUBREG)
  2547. value = SUBREG_REG (value);
  2548. if (REG_P (value))
  2549. {
  2550. if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
  2551. return 0;
  2552. }
  2553. home = alter_subreg (&home, true);
  2554. }
  2555. if (REG_P (home))
  2556. {
  2557. regno = REGNO (home);
  2558. if (regno >= FIRST_PSEUDO_REGISTER)
  2559. return 0;
  2560. }
  2561. /* The kind-of-variable letter depends on where
  2562. the variable is and on the scope of its name:
  2563. G and N_GSYM for static storage and global scope,
  2564. S for static storage and file scope,
  2565. V for static storage and local scope,
  2566. for those two, use N_LCSYM if data is in bss segment,
  2567. N_STSYM if in data segment, N_FUN otherwise.
  2568. (We used N_FUN originally, then changed to N_STSYM
  2569. to please GDB. However, it seems that confused ld.
  2570. Now GDB has been fixed to like N_FUN, says Kingdon.)
  2571. no letter at all, and N_LSYM, for auto variable,
  2572. r and N_RSYM for register variable. */
  2573. if (MEM_P (home) && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
  2574. {
  2575. if (TREE_PUBLIC (decl))
  2576. {
  2577. int offs;
  2578. letter = 'G';
  2579. code = N_GSYM;
  2580. if (NULL != dbxout_common_check (decl, &offs))
  2581. {
  2582. letter = 'V';
  2583. addr = 0;
  2584. number = offs;
  2585. }
  2586. }
  2587. else
  2588. {
  2589. addr = XEXP (home, 0);
  2590. letter = decl_function_context (decl) ? 'V' : 'S';
  2591. /* Some ports can transform a symbol ref into a label ref,
  2592. because the symbol ref is too far away and has to be
  2593. dumped into a constant pool. Alternatively, the symbol
  2594. in the constant pool might be referenced by a different
  2595. symbol. */
  2596. if (GET_CODE (addr) == SYMBOL_REF
  2597. && CONSTANT_POOL_ADDRESS_P (addr))
  2598. {
  2599. bool marked;
  2600. rtx tmp = get_pool_constant_mark (addr, &marked);
  2601. if (GET_CODE (tmp) == SYMBOL_REF)
  2602. {
  2603. addr = tmp;
  2604. if (CONSTANT_POOL_ADDRESS_P (addr))
  2605. get_pool_constant_mark (addr, &marked);
  2606. else
  2607. marked = true;
  2608. }
  2609. else if (GET_CODE (tmp) == LABEL_REF)
  2610. {
  2611. addr = tmp;
  2612. marked = true;
  2613. }
  2614. /* If all references to the constant pool were optimized
  2615. out, we just ignore the symbol. */
  2616. if (!marked)
  2617. return 0;
  2618. }
  2619. /* This should be the same condition as in assemble_variable, but
  2620. we don't have access to dont_output_data here. So, instead,
  2621. we rely on the fact that error_mark_node initializers always
  2622. end up in bss for C++ and never end up in bss for C. */
  2623. if (DECL_INITIAL (decl) == 0
  2624. || (lang_GNU_CXX ()
  2625. && DECL_INITIAL (decl) == error_mark_node))
  2626. {
  2627. int offs;
  2628. code = N_LCSYM;
  2629. if (NULL != dbxout_common_check (decl, &offs))
  2630. {
  2631. addr = 0;
  2632. number = offs;
  2633. letter = 'V';
  2634. code = N_GSYM;
  2635. }
  2636. }
  2637. else if (DECL_IN_TEXT_SECTION (decl))
  2638. /* This is not quite right, but it's the closest
  2639. of all the codes that Unix defines. */
  2640. code = DBX_STATIC_CONST_VAR_CODE;
  2641. else
  2642. {
  2643. /* Ultrix `as' seems to need this. */
  2644. #ifdef DBX_STATIC_STAB_DATA_SECTION
  2645. switch_to_section (data_section);
  2646. #endif
  2647. code = N_STSYM;
  2648. }
  2649. }
  2650. }
  2651. else if (regno >= 0)
  2652. {
  2653. letter = 'r';
  2654. code = N_RSYM;
  2655. number = DBX_REGISTER_NUMBER (regno);
  2656. }
  2657. else if (MEM_P (home)
  2658. && (MEM_P (XEXP (home, 0))
  2659. || (REG_P (XEXP (home, 0))
  2660. && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
  2661. && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
  2662. #if !HARD_FRAME_POINTER_IS_ARG_POINTER
  2663. && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
  2664. #endif
  2665. )))
  2666. /* If the value is indirect by memory or by a register
  2667. that isn't the frame pointer
  2668. then it means the object is variable-sized and address through
  2669. that register or stack slot. DBX has no way to represent this
  2670. so all we can do is output the variable as a pointer.
  2671. If it's not a parameter, ignore it. */
  2672. {
  2673. if (REG_P (XEXP (home, 0)))
  2674. {
  2675. letter = 'r';
  2676. code = N_RSYM;
  2677. if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
  2678. return 0;
  2679. number = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
  2680. }
  2681. else
  2682. {
  2683. code = N_LSYM;
  2684. /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
  2685. We want the value of that CONST_INT. */
  2686. number = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
  2687. }
  2688. /* Effectively do build_pointer_type, but don't cache this type,
  2689. since it might be temporary whereas the type it points to
  2690. might have been saved for inlining. */
  2691. /* Don't use REFERENCE_TYPE because dbx can't handle that. */
  2692. type = make_node (POINTER_TYPE);
  2693. TREE_TYPE (type) = TREE_TYPE (decl);
  2694. }
  2695. else if (MEM_P (home)
  2696. && REG_P (XEXP (home, 0)))
  2697. {
  2698. code = N_LSYM;
  2699. number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
  2700. }
  2701. else if (MEM_P (home)
  2702. && GET_CODE (XEXP (home, 0)) == PLUS
  2703. && CONST_INT_P (XEXP (XEXP (home, 0), 1)))
  2704. {
  2705. code = N_LSYM;
  2706. /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
  2707. We want the value of that CONST_INT. */
  2708. number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
  2709. }
  2710. else if (MEM_P (home)
  2711. && GET_CODE (XEXP (home, 0)) == CONST)
  2712. {
  2713. /* Handle an obscure case which can arise when optimizing and
  2714. when there are few available registers. (This is *always*
  2715. the case for i386/i486 targets). The RTL looks like
  2716. (MEM (CONST ...)) even though this variable is a local `auto'
  2717. or a local `register' variable. In effect, what has happened
  2718. is that the reload pass has seen that all assignments and
  2719. references for one such a local variable can be replaced by
  2720. equivalent assignments and references to some static storage
  2721. variable, thereby avoiding the need for a register. In such
  2722. cases we're forced to lie to debuggers and tell them that
  2723. this variable was itself `static'. */
  2724. int offs;
  2725. code = N_LCSYM;
  2726. letter = 'V';
  2727. if (NULL == dbxout_common_check (decl, &offs))
  2728. addr = XEXP (XEXP (home, 0), 0);
  2729. else
  2730. {
  2731. addr = 0;
  2732. number = offs;
  2733. code = N_GSYM;
  2734. }
  2735. }
  2736. else if (GET_CODE (home) == CONCAT)
  2737. {
  2738. tree subtype;
  2739. /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
  2740. for example), then there is no easy way to figure out
  2741. what SUBTYPE should be. So, we give up. */
  2742. if (TREE_CODE (type) != COMPLEX_TYPE)
  2743. return 0;
  2744. subtype = TREE_TYPE (type);
  2745. /* If the variable's storage is in two parts,
  2746. output each as a separate stab with a modified name. */
  2747. if (WORDS_BIG_ENDIAN)
  2748. dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
  2749. else
  2750. dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
  2751. if (WORDS_BIG_ENDIAN)
  2752. dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
  2753. else
  2754. dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
  2755. return 1;
  2756. }
  2757. else
  2758. /* Address might be a MEM, when DECL is a variable-sized object.
  2759. Or it might be const0_rtx, meaning previous passes
  2760. want us to ignore this variable. */
  2761. return 0;
  2762. /* Ok, start a symtab entry and output the variable name. */
  2763. emit_pending_bincls_if_required ();
  2764. FORCE_TEXT;
  2765. #ifdef DBX_STATIC_BLOCK_START
  2766. DBX_STATIC_BLOCK_START (asm_out_file, code);
  2767. #endif
  2768. dbxout_begin_complex_stabs_noforcetext ();
  2769. dbxout_symbol_name (decl, suffix, letter);
  2770. dbxout_type (type, 0);
  2771. dbxout_finish_complex_stabs (decl, code, addr, 0, number);
  2772. #ifdef DBX_STATIC_BLOCK_END
  2773. DBX_STATIC_BLOCK_END (asm_out_file, code);
  2774. #endif
  2775. return 1;
  2776. }
  2777. /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
  2778. Then output LETTER to indicate the kind of location the symbol has. */
  2779. static void
  2780. dbxout_symbol_name (tree decl, const char *suffix, int letter)
  2781. {
  2782. tree name;
  2783. if (DECL_CONTEXT (decl)
  2784. && (TYPE_P (DECL_CONTEXT (decl))
  2785. || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL))
  2786. /* One slight hitch: if this is a VAR_DECL which is a class member
  2787. or a namespace member, we must put out the mangled name instead of the
  2788. DECL_NAME. Note also that static member (variable) names DO NOT begin
  2789. with underscores in .stabs directives. */
  2790. name = DECL_ASSEMBLER_NAME (decl);
  2791. else
  2792. /* ...but if we're function-local, we don't want to include the junk
  2793. added by ASM_FORMAT_PRIVATE_NAME. */
  2794. name = DECL_NAME (decl);
  2795. if (name)
  2796. stabstr_I (name);
  2797. else
  2798. stabstr_S ("(anon)");
  2799. if (suffix)
  2800. stabstr_S (suffix);
  2801. stabstr_C (':');
  2802. if (letter)
  2803. stabstr_C (letter);
  2804. }
  2805. /* Output the common block name for DECL in a stabs.
  2806. Symbols in global common (.comm) get wrapped with an N_BCOMM/N_ECOMM pair
  2807. around each group of symbols in the same .comm area. The N_GSYM stabs
  2808. that are emitted only contain the offset in the common area. This routine
  2809. emits the N_BCOMM and N_ECOMM stabs. */
  2810. static void
  2811. dbxout_common_name (tree decl, const char *name, stab_code_type op)
  2812. {
  2813. dbxout_begin_complex_stabs ();
  2814. stabstr_S (name);
  2815. dbxout_finish_complex_stabs (decl, op, NULL_RTX, NULL, 0);
  2816. }
  2817. /* Check decl to determine whether it is a VAR_DECL destined for storage in a
  2818. common area. If it is, the return value will be a non-null string giving
  2819. the name of the common storage block it will go into. If non-null, the
  2820. value is the offset into the common block for that symbol's storage. */
  2821. static const char *
  2822. dbxout_common_check (tree decl, int *value)
  2823. {
  2824. rtx home;
  2825. rtx sym_addr;
  2826. const char *name = NULL;
  2827. /* If the decl isn't a VAR_DECL, or if it isn't static, or if
  2828. it does not have a value (the offset into the common area), or if it
  2829. is thread local (as opposed to global) then it isn't common, and shouldn't
  2830. be handled as such.
  2831. ??? DECL_THREAD_LOCAL_P check prevents problems with improper .stabs
  2832. for thread-local symbols. Can be handled via same mechanism as used
  2833. in dwarf2out.c. */
  2834. if (TREE_CODE (decl) != VAR_DECL
  2835. || !TREE_STATIC (decl)
  2836. || !DECL_HAS_VALUE_EXPR_P (decl)
  2837. || DECL_THREAD_LOCAL_P (decl)
  2838. || !is_fortran ())
  2839. return NULL;
  2840. home = DECL_RTL (decl);
  2841. if (home == NULL_RTX || GET_CODE (home) != MEM)
  2842. return NULL;
  2843. sym_addr = dbxout_expand_expr (DECL_VALUE_EXPR (decl));
  2844. if (sym_addr == NULL_RTX || GET_CODE (sym_addr) != MEM)
  2845. return NULL;
  2846. sym_addr = XEXP (sym_addr, 0);
  2847. if (GET_CODE (sym_addr) == CONST)
  2848. sym_addr = XEXP (sym_addr, 0);
  2849. if ((GET_CODE (sym_addr) == SYMBOL_REF || GET_CODE (sym_addr) == PLUS)
  2850. && DECL_INITIAL (decl) == 0)
  2851. {
  2852. /* We have a sym that will go into a common area, meaning that it
  2853. will get storage reserved with a .comm/.lcomm assembler pseudo-op.
  2854. Determine name of common area this symbol will be an offset into,
  2855. and offset into that area. Also retrieve the decl for the area
  2856. that the symbol is offset into. */
  2857. tree cdecl = NULL;
  2858. switch (GET_CODE (sym_addr))
  2859. {
  2860. case PLUS:
  2861. if (CONST_INT_P (XEXP (sym_addr, 0)))
  2862. {
  2863. name =
  2864. targetm.strip_name_encoding (XSTR (XEXP (sym_addr, 1), 0));
  2865. *value = INTVAL (XEXP (sym_addr, 0));
  2866. cdecl = SYMBOL_REF_DECL (XEXP (sym_addr, 1));
  2867. }
  2868. else
  2869. {
  2870. name =
  2871. targetm.strip_name_encoding (XSTR (XEXP (sym_addr, 0), 0));
  2872. *value = INTVAL (XEXP (sym_addr, 1));
  2873. cdecl = SYMBOL_REF_DECL (XEXP (sym_addr, 0));
  2874. }
  2875. break;
  2876. case SYMBOL_REF:
  2877. name = targetm.strip_name_encoding (XSTR (sym_addr, 0));
  2878. *value = 0;
  2879. cdecl = SYMBOL_REF_DECL (sym_addr);
  2880. break;
  2881. default:
  2882. error ("common symbol debug info is not structured as "
  2883. "symbol+offset");
  2884. }
  2885. /* Check area common symbol is offset into. If this is not public, then
  2886. it is not a symbol in a common block. It must be a .lcomm symbol, not
  2887. a .comm symbol. */
  2888. if (cdecl == NULL || !TREE_PUBLIC (cdecl))
  2889. name = NULL;
  2890. }
  2891. else
  2892. name = NULL;
  2893. return name;
  2894. }
  2895. /* Output definitions of all the decls in a chain. Return nonzero if
  2896. anything was output */
  2897. int
  2898. dbxout_syms (tree syms)
  2899. {
  2900. int result = 0;
  2901. const char *comm_prev = NULL;
  2902. tree syms_prev = NULL;
  2903. while (syms)
  2904. {
  2905. int temp, copen, cclos;
  2906. const char *comm_new;
  2907. /* Check for common symbol, and then progression into a new/different
  2908. block of common symbols. Emit closing/opening common bracket if
  2909. necessary. */
  2910. comm_new = dbxout_common_check (syms, &temp);
  2911. copen = comm_new != NULL
  2912. && (comm_prev == NULL || strcmp (comm_new, comm_prev));
  2913. cclos = comm_prev != NULL
  2914. && (comm_new == NULL || strcmp (comm_new, comm_prev));
  2915. if (cclos)
  2916. dbxout_common_name (syms_prev, comm_prev, N_ECOMM);
  2917. if (copen)
  2918. {
  2919. dbxout_common_name (syms, comm_new, N_BCOMM);
  2920. syms_prev = syms;
  2921. }
  2922. comm_prev = comm_new;
  2923. result += dbxout_symbol (syms, 1);
  2924. syms = DECL_CHAIN (syms);
  2925. }
  2926. if (comm_prev != NULL)
  2927. dbxout_common_name (syms_prev, comm_prev, N_ECOMM);
  2928. return result;
  2929. }
  2930. /* The following two functions output definitions of function parameters.
  2931. Each parameter gets a definition locating it in the parameter list.
  2932. Each parameter that is a register variable gets a second definition
  2933. locating it in the register.
  2934. Printing or argument lists in gdb uses the definitions that
  2935. locate in the parameter list. But reference to the variable in
  2936. expressions uses preferentially the definition as a register. */
  2937. /* Output definitions, referring to storage in the parmlist,
  2938. of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
  2939. void
  2940. dbxout_parms (tree parms)
  2941. {
  2942. ++debug_nesting;
  2943. emit_pending_bincls_if_required ();
  2944. for (; parms; parms = DECL_CHAIN (parms))
  2945. if (DECL_NAME (parms)
  2946. && TREE_TYPE (parms) != error_mark_node
  2947. && DECL_RTL_SET_P (parms)
  2948. && DECL_INCOMING_RTL (parms))
  2949. {
  2950. tree eff_type;
  2951. char letter;
  2952. stab_code_type code;
  2953. int number;
  2954. /* Perform any necessary register eliminations on the parameter's rtl,
  2955. so that the debugging output will be accurate. */
  2956. DECL_INCOMING_RTL (parms)
  2957. = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX);
  2958. SET_DECL_RTL (parms,
  2959. eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX));
  2960. #ifdef LEAF_REG_REMAP
  2961. if (crtl->uses_only_leaf_regs)
  2962. {
  2963. leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
  2964. leaf_renumber_regs_insn (DECL_RTL (parms));
  2965. }
  2966. #endif
  2967. if (PARM_PASSED_IN_MEMORY (parms))
  2968. {
  2969. rtx inrtl = XEXP (DECL_INCOMING_RTL (parms), 0);
  2970. /* ??? Here we assume that the parm address is indexed
  2971. off the frame pointer or arg pointer.
  2972. If that is not true, we produce meaningless results,
  2973. but do not crash. */
  2974. if (GET_CODE (inrtl) == PLUS
  2975. && CONST_INT_P (XEXP (inrtl, 1)))
  2976. number = INTVAL (XEXP (inrtl, 1));
  2977. else
  2978. number = 0;
  2979. code = N_PSYM;
  2980. number = DEBUGGER_ARG_OFFSET (number, inrtl);
  2981. letter = 'p';
  2982. /* It is quite tempting to use TREE_TYPE (parms) instead
  2983. of DECL_ARG_TYPE (parms) for the eff_type, so that gcc
  2984. reports the actual type of the parameter, rather than
  2985. the promoted type. This certainly makes GDB's life
  2986. easier, at least for some ports. The change is a bad
  2987. idea however, since GDB expects to be able access the
  2988. type without performing any conversions. So for
  2989. example, if we were passing a float to an unprototyped
  2990. function, gcc will store a double on the stack, but if
  2991. we emit a stab saying the type is a float, then gdb
  2992. will only read in a single value, and this will produce
  2993. an erroneous value. */
  2994. eff_type = DECL_ARG_TYPE (parms);
  2995. }
  2996. else if (REG_P (DECL_RTL (parms)))
  2997. {
  2998. rtx best_rtl;
  2999. /* Parm passed in registers and lives in registers or nowhere. */
  3000. code = DBX_REGPARM_STABS_CODE;
  3001. letter = DBX_REGPARM_STABS_LETTER;
  3002. /* For parms passed in registers, it is better to use the
  3003. declared type of the variable, not the type it arrived in. */
  3004. eff_type = TREE_TYPE (parms);
  3005. /* If parm lives in a register, use that register; pretend
  3006. the parm was passed there. It would be more consistent
  3007. to describe the register where the parm was passed, but
  3008. in practice that register usually holds something else.
  3009. If the parm lives nowhere, use the register where it
  3010. was passed. */
  3011. if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
  3012. best_rtl = DECL_RTL (parms);
  3013. else if (GET_CODE (DECL_INCOMING_RTL (parms)) == PARALLEL)
  3014. best_rtl = XEXP (XVECEXP (DECL_INCOMING_RTL (parms), 0, 0), 0);
  3015. else
  3016. best_rtl = DECL_INCOMING_RTL (parms);
  3017. number = DBX_REGISTER_NUMBER (REGNO (best_rtl));
  3018. }
  3019. else if (MEM_P (DECL_RTL (parms))
  3020. && REG_P (XEXP (DECL_RTL (parms), 0))
  3021. && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
  3022. && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
  3023. #if !HARD_FRAME_POINTER_IS_ARG_POINTER
  3024. && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
  3025. #endif
  3026. )
  3027. {
  3028. /* Parm was passed via invisible reference.
  3029. That is, its address was passed in a register.
  3030. Output it as if it lived in that register.
  3031. The debugger will know from the type
  3032. that it was actually passed by invisible reference. */
  3033. code = DBX_REGPARM_STABS_CODE;
  3034. /* GDB likes this marked with a special letter. */
  3035. letter = (use_gnu_debug_info_extensions
  3036. ? 'a' : DBX_REGPARM_STABS_LETTER);
  3037. eff_type = TREE_TYPE (parms);
  3038. /* DECL_RTL looks like (MEM (REG...). Get the register number.
  3039. If it is an unallocated pseudo-reg, then use the register where
  3040. it was passed instead.
  3041. ??? Why is DBX_REGISTER_NUMBER not used here? */
  3042. if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
  3043. number = REGNO (XEXP (DECL_RTL (parms), 0));
  3044. else
  3045. number = REGNO (DECL_INCOMING_RTL (parms));
  3046. }
  3047. else if (MEM_P (DECL_RTL (parms))
  3048. && MEM_P (XEXP (DECL_RTL (parms), 0)))
  3049. {
  3050. /* Parm was passed via invisible reference, with the reference
  3051. living on the stack. DECL_RTL looks like
  3052. (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
  3053. could look like (MEM (MEM (REG))). */
  3054. code = N_PSYM;
  3055. letter = 'v';
  3056. eff_type = TREE_TYPE (parms);
  3057. if (!REG_P (XEXP (XEXP (DECL_RTL (parms), 0), 0)))
  3058. number = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
  3059. else
  3060. number = 0;
  3061. number = DEBUGGER_ARG_OFFSET (number,
  3062. XEXP (XEXP (DECL_RTL (parms), 0), 0));
  3063. }
  3064. else if (MEM_P (DECL_RTL (parms))
  3065. && XEXP (DECL_RTL (parms), 0) != const0_rtx
  3066. /* ??? A constant address for a parm can happen
  3067. when the reg it lives in is equiv to a constant in memory.
  3068. Should make this not happen, after 2.4. */
  3069. && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
  3070. {
  3071. /* Parm was passed in registers but lives on the stack. */
  3072. code = N_PSYM;
  3073. letter = 'p';
  3074. eff_type = TREE_TYPE (parms);
  3075. /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
  3076. in which case we want the value of that CONST_INT,
  3077. or (MEM (REG ...)),
  3078. in which case we use a value of zero. */
  3079. if (!REG_P (XEXP (DECL_RTL (parms), 0)))
  3080. number = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
  3081. else
  3082. number = 0;
  3083. /* Make a big endian correction if the mode of the type of the
  3084. parameter is not the same as the mode of the rtl. */
  3085. if (BYTES_BIG_ENDIAN
  3086. && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
  3087. && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
  3088. number += (GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
  3089. - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))));
  3090. }
  3091. else
  3092. /* ??? We don't know how to represent this argument. */
  3093. continue;
  3094. dbxout_begin_complex_stabs ();
  3095. if (DECL_NAME (parms))
  3096. {
  3097. stabstr_I (DECL_NAME (parms));
  3098. stabstr_C (':');
  3099. }
  3100. else
  3101. stabstr_S ("(anon):");
  3102. stabstr_C (letter);
  3103. dbxout_type (eff_type, 0);
  3104. dbxout_finish_complex_stabs (parms, code, 0, 0, number);
  3105. }
  3106. DBXOUT_DECR_NESTING;
  3107. }
  3108. /* Output definitions for the places where parms live during the function,
  3109. when different from where they were passed, when the parms were passed
  3110. in memory.
  3111. It is not useful to do this for parms passed in registers
  3112. that live during the function in different registers, because it is
  3113. impossible to look in the passed register for the passed value,
  3114. so we use the within-the-function register to begin with.
  3115. PARMS is a chain of PARM_DECL nodes. */
  3116. void
  3117. dbxout_reg_parms (tree parms)
  3118. {
  3119. ++debug_nesting;
  3120. for (; parms; parms = DECL_CHAIN (parms))
  3121. if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
  3122. {
  3123. /* Report parms that live in registers during the function
  3124. but were passed in memory. */
  3125. if (REG_P (DECL_RTL (parms))
  3126. && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
  3127. dbxout_symbol_location (parms, TREE_TYPE (parms),
  3128. 0, DECL_RTL (parms));
  3129. else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
  3130. dbxout_symbol_location (parms, TREE_TYPE (parms),
  3131. 0, DECL_RTL (parms));
  3132. /* Report parms that live in memory but not where they were passed. */
  3133. else if (MEM_P (DECL_RTL (parms))
  3134. && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
  3135. dbxout_symbol_location (parms, TREE_TYPE (parms),
  3136. 0, DECL_RTL (parms));
  3137. }
  3138. DBXOUT_DECR_NESTING;
  3139. }
  3140. /* Given a chain of ..._TYPE nodes (as come in a parameter list),
  3141. output definitions of those names, in raw form */
  3142. static void
  3143. dbxout_args (tree args)
  3144. {
  3145. while (args)
  3146. {
  3147. stabstr_C (',');
  3148. dbxout_type (TREE_VALUE (args), 0);
  3149. args = TREE_CHAIN (args);
  3150. }
  3151. }
  3152. #if defined (DBX_DEBUGGING_INFO)
  3153. /* Subroutine of dbxout_block. Emit an N_LBRAC stab referencing LABEL.
  3154. BEGIN_LABEL is the name of the beginning of the function, which may
  3155. be required. */
  3156. static void
  3157. dbx_output_lbrac (const char *label,
  3158. const char *begin_label ATTRIBUTE_UNUSED)
  3159. {
  3160. dbxout_begin_stabn (N_LBRAC);
  3161. if (DBX_BLOCKS_FUNCTION_RELATIVE)
  3162. dbxout_stab_value_label_diff (label, begin_label);
  3163. else
  3164. dbxout_stab_value_label (label);
  3165. }
  3166. /* Subroutine of dbxout_block. Emit an N_RBRAC stab referencing LABEL.
  3167. BEGIN_LABEL is the name of the beginning of the function, which may
  3168. be required. */
  3169. static void
  3170. dbx_output_rbrac (const char *label,
  3171. const char *begin_label ATTRIBUTE_UNUSED)
  3172. {
  3173. dbxout_begin_stabn (N_RBRAC);
  3174. if (DBX_BLOCKS_FUNCTION_RELATIVE)
  3175. dbxout_stab_value_label_diff (label, begin_label);
  3176. else
  3177. dbxout_stab_value_label (label);
  3178. }
  3179. /* Output everything about a symbol block (a BLOCK node
  3180. that represents a scope level),
  3181. including recursive output of contained blocks.
  3182. BLOCK is the BLOCK node.
  3183. DEPTH is its depth within containing symbol blocks.
  3184. ARGS is usually zero; but for the outermost block of the
  3185. body of a function, it is a chain of PARM_DECLs for the function parameters.
  3186. We output definitions of all the register parms
  3187. as if they were local variables of that block.
  3188. If -g1 was used, we count blocks just the same, but output nothing
  3189. except for the outermost block.
  3190. Actually, BLOCK may be several blocks chained together.
  3191. We handle them all in sequence. */
  3192. static void
  3193. dbxout_block (tree block, int depth, tree args)
  3194. {
  3195. char begin_label[20];
  3196. /* Reference current function start using LFBB. */
  3197. ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
  3198. while (block)
  3199. {
  3200. /* Ignore blocks never expanded or otherwise marked as real. */
  3201. if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
  3202. {
  3203. int did_output;
  3204. int blocknum = BLOCK_NUMBER (block);
  3205. /* In dbx format, the syms of a block come before the N_LBRAC.
  3206. If nothing is output, we don't need the N_LBRAC, either. */
  3207. did_output = 0;
  3208. if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
  3209. did_output = dbxout_syms (BLOCK_VARS (block));
  3210. if (args)
  3211. dbxout_reg_parms (args);
  3212. /* Now output an N_LBRAC symbol to represent the beginning of
  3213. the block. Use the block's tree-walk order to generate
  3214. the assembler symbols LBBn and LBEn
  3215. that final will define around the code in this block. */
  3216. if (did_output)
  3217. {
  3218. char buf[20];
  3219. const char *scope_start;
  3220. if (depth == 0)
  3221. /* The outermost block doesn't get LBB labels; use
  3222. the LFBB local symbol emitted by dbxout_begin_prologue. */
  3223. scope_start = begin_label;
  3224. else
  3225. {
  3226. ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
  3227. scope_start = buf;
  3228. }
  3229. dbx_output_lbrac (scope_start, begin_label);
  3230. }
  3231. /* Output the subblocks. */
  3232. dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
  3233. /* Refer to the marker for the end of the block. */
  3234. if (did_output)
  3235. {
  3236. char buf[100];
  3237. if (depth == 0)
  3238. /* The outermost block doesn't get LBE labels;
  3239. use the "scope" label which will be emitted
  3240. by dbxout_function_end. */
  3241. ASM_GENERATE_INTERNAL_LABEL (buf, "Lscope", scope_labelno);
  3242. else
  3243. ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
  3244. dbx_output_rbrac (buf, begin_label);
  3245. }
  3246. }
  3247. block = BLOCK_CHAIN (block);
  3248. }
  3249. }
  3250. /* Output the information about a function and its arguments and result.
  3251. Usually this follows the function's code,
  3252. but on some systems, it comes before. */
  3253. static void
  3254. dbxout_begin_function (tree decl)
  3255. {
  3256. int saved_tree_used1;
  3257. saved_tree_used1 = TREE_USED (decl);
  3258. TREE_USED (decl) = 1;
  3259. if (DECL_NAME (DECL_RESULT (decl)) != 0)
  3260. {
  3261. int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
  3262. TREE_USED (DECL_RESULT (decl)) = 1;
  3263. dbxout_symbol (decl, 0);
  3264. TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
  3265. }
  3266. else
  3267. dbxout_symbol (decl, 0);
  3268. TREE_USED (decl) = saved_tree_used1;
  3269. dbxout_parms (DECL_ARGUMENTS (decl));
  3270. if (DECL_NAME (DECL_RESULT (decl)) != 0)
  3271. dbxout_symbol (DECL_RESULT (decl), 1);
  3272. }
  3273. #endif /* DBX_DEBUGGING_INFO */
  3274. #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
  3275. /* Record an element in the table of global destructors. SYMBOL is
  3276. a SYMBOL_REF of the function to be called; PRIORITY is a number
  3277. between 0 and MAX_INIT_PRIORITY. */
  3278. void
  3279. default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
  3280. int priority ATTRIBUTE_UNUSED)
  3281. {
  3282. #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
  3283. /* Tell GNU LD that this is part of the static destructor set.
  3284. This will work for any system that uses stabs, most usefully
  3285. aout systems. */
  3286. dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
  3287. dbxout_stab_value_label (XSTR (symbol, 0));
  3288. #else
  3289. sorry ("global destructors not supported on this target");
  3290. #endif
  3291. }
  3292. /* Likewise for global constructors. */
  3293. void
  3294. default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
  3295. int priority ATTRIBUTE_UNUSED)
  3296. {
  3297. #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
  3298. /* Tell GNU LD that this is part of the static destructor set.
  3299. This will work for any system that uses stabs, most usefully
  3300. aout systems. */
  3301. dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
  3302. dbxout_stab_value_label (XSTR (symbol, 0));
  3303. #else
  3304. sorry ("global constructors not supported on this target");
  3305. #endif
  3306. }
  3307. #include "gt-dbxout.h"