dbgstabs.pas 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698
  1. {
  2. Copyright (c) 2003-2004 by Peter Vreman and Florian Klaempfl
  3. This units contains support for STABS debug info generation
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit dbgstabs;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,
  22. dbgbase,cgbase,
  23. symtype,symdef,symsym,symtable,symbase,
  24. aasmtai,aasmdata;
  25. const
  26. { stab types }
  27. N_GSYM = $20;
  28. N_STSYM = 38; { initialized const }
  29. N_LCSYM = 40; { non initialized variable}
  30. N_Function = $24; { function or const }
  31. N_TextLine = $44;
  32. N_DataLine = $46;
  33. N_BssLine = $48;
  34. N_RSYM = $40; { register variable }
  35. N_LSYM = $80;
  36. N_tsym = 160;
  37. N_SourceFile = $64;
  38. { APPLE LOCAL N_OSO: This is the stab that associated the .o file with the
  39. N_SO stab, in the case where debug info is mostly stored in the .o file. }
  40. N_OSO = $66;
  41. N_IncludeFile = $84;
  42. N_BINCL = $82;
  43. N_EINCL = $A2;
  44. N_LBRAC = $C0;
  45. N_EXCL = $C2;
  46. N_RBRAC = $E0;
  47. type
  48. TDebugInfoStabs=class(TDebugInfo)
  49. private
  50. writing_def_stabs : boolean;
  51. global_stab_number : word;
  52. defnumberlist : TFPObjectList;
  53. vardatadef: trecorddef;
  54. { tsym writing }
  55. function sym_var_value(const s:string;arg:pointer):string;
  56. function sym_stabstr_evaluate(sym:tsym;const s:string;const vars:array of string):ansistring;
  57. procedure write_sym_stabstr(list:TAsmList;sym:tsym;const ss:ansistring);
  58. { tdef writing }
  59. function def_stab_number(def:tdef):string;
  60. function def_stab_classnumber(def:tobjectdef):string;
  61. function def_var_value(const s:string;arg:pointer):string;
  62. function def_stabstr_evaluate(def:tdef;const s:string;const vars:array of string):ansistring;
  63. procedure write_def_stabstr(list:TAsmList;def:tdef;const ss:ansistring);
  64. procedure field_add_stabstr(p:TObject;arg:pointer);
  65. procedure method_add_stabstr(p:TObject;arg:pointer);
  66. procedure field_write_defs(p:TObject;arg:pointer);
  67. function get_enum_defstr(def: tenumdef; lowerbound: longint): ansistring;
  68. function get_appendsym_paravar_reg(sym:tparavarsym;const typ,stabstr:string;reg: tregister): ansistring;
  69. protected
  70. procedure appendsym_staticvar(list:TAsmList;sym:tstaticvarsym);override;
  71. procedure appendsym_paravar(list:TAsmList;sym:tparavarsym);override;
  72. procedure appendsym_localvar(list:TAsmList;sym:tlocalvarsym);override;
  73. procedure appendsym_fieldvar(list:TAsmList;sym:tfieldvarsym);override;
  74. procedure appendsym_const(list:TAsmList;sym:tconstsym);override;
  75. procedure appendsym_type(list:TAsmList;sym:ttypesym);override;
  76. procedure appendsym_label(list:TAsmList;sym:tlabelsym);override;
  77. procedure beforeappenddef(list:TAsmList;def:tdef);override;
  78. procedure appenddef_ord(list:TAsmList;def:torddef);override;
  79. procedure appenddef_float(list:TAsmList;def:tfloatdef);override;
  80. procedure appenddef_file(list:TAsmList;def:tfiledef);override;
  81. procedure appenddef_enum(list:TAsmList;def:tenumdef);override;
  82. procedure appenddef_array(list:TAsmList;def:tarraydef);override;
  83. procedure appenddef_record(list:TAsmList;def:trecorddef);override;
  84. procedure appenddef_object(list:TAsmList;def:tobjectdef);override;
  85. procedure appenddef_pointer(list:TAsmList;def:tpointerdef);override;
  86. procedure appenddef_string(list:TAsmList;def:tstringdef);override;
  87. procedure appenddef_procvar(list:TAsmList;def:tprocvardef);override;
  88. procedure appenddef_variant(list:TAsmList;def:tvariantdef);override;
  89. procedure appenddef_set(list:TAsmList;def:tsetdef);override;
  90. procedure appenddef_formal(list:TAsmList;def:tformaldef);override;
  91. procedure appenddef_undefined(list:TAsmList;def: tundefineddef);override;
  92. procedure appendprocdef(list:TAsmList;def:tprocdef);override;
  93. public
  94. procedure inserttypeinfo;override;
  95. procedure insertmoduleinfo;override;
  96. procedure insertlineinfo(list:TAsmList);override;
  97. procedure referencesections(list:TAsmList);override;
  98. end;
  99. implementation
  100. uses
  101. SysUtils,cutils,cfileutl,
  102. systems,globals,globtype,verbose,constexp,
  103. symconst,defutil,
  104. cpuinfo,cpubase,paramgr,
  105. aasmbase,procinfo,
  106. finput,fmodule,ppu;
  107. function GetSymName(Sym : TSymEntry) : string;
  108. begin
  109. if Not (cs_stabs_preservecase in current_settings.globalswitches) then
  110. result := Sym.Name
  111. else
  112. result := Sym.RealName;
  113. end;
  114. function GetSymTableName(SymTable : TSymTable) : string;
  115. begin
  116. if Not (cs_stabs_preservecase in current_settings.globalswitches) then
  117. result := SymTable.Name^
  118. else
  119. result := SymTable.RealName^;
  120. end;
  121. const
  122. memsizeinc = 512;
  123. tagtypes = [
  124. recorddef,
  125. variantdef,
  126. enumdef,
  127. stringdef,
  128. filedef,
  129. objectdef
  130. ];
  131. type
  132. get_var_value_proc=function(const s:string;arg:pointer):string of object;
  133. function string_evaluate(s:string;get_var_value:get_var_value_proc;get_var_value_arg:pointer;const vars:array of string):ansistring;
  134. (*
  135. S contains a prototype of a result. Stabstr_evaluate will expand
  136. variables and parameters.
  137. Output is s in ASCIIZ format, with the following expanded:
  138. ${varname} - The variable name is expanded.
  139. $n - The parameter n is expanded.
  140. $$ - Is expanded to $
  141. *)
  142. const maxvalue=9;
  143. maxdata=1023;
  144. var i,j:byte;
  145. varname:string[63];
  146. varno,varcounter:byte;
  147. varvalues:array[0..9] of pshortstring;
  148. {1 kb of parameters is the limit. 256 extra bytes are allocated to
  149. ensure buffer integrity.}
  150. varvaluedata:array[0..maxdata+256] of char;
  151. varptr:Pchar;
  152. varidx : byte;
  153. len:longint;
  154. r:Pchar;
  155. begin
  156. {Two pass approach, first, calculate the length and receive variables.}
  157. i:=1;
  158. len:=0;
  159. varcounter:=0;
  160. varptr:=@varvaluedata[0];
  161. while i<=length(s) do
  162. begin
  163. if (s[i]='$') and (i<length(s)) then
  164. begin
  165. if s[i+1]='$' then
  166. begin
  167. inc(len);
  168. inc(i);
  169. end
  170. else if (s[i+1]='{') and (length(s)>2) and (i<length(s)-2) then
  171. begin
  172. varname:='';
  173. inc(i,2);
  174. repeat
  175. inc(varname[0]);
  176. varname[length(varname)]:=s[i];
  177. s[i]:=char(varcounter);
  178. inc(i);
  179. until s[i]='}';
  180. varvalues[varcounter]:=pshortstring(varptr);
  181. if varptr>@varvaluedata[maxdata] then
  182. internalerrorproc(200411152);
  183. pshortstring(varptr)^:=get_var_value(varname,get_var_value_arg);
  184. inc(len,length(pshortstring(varptr)^));
  185. inc(varptr,length(pshortstring(varptr)^)+1);
  186. inc(varcounter);
  187. end
  188. else if s[i+1] in ['1'..'9'] then
  189. begin
  190. varidx:=byte(s[i+1])-byte('1');
  191. if varidx>high(vars) then
  192. internalerror(200509263);
  193. inc(len,length(vars[varidx]));
  194. inc(i);
  195. end;
  196. end
  197. else
  198. inc(len);
  199. inc(i);
  200. end;
  201. {Second pass, writeout result.}
  202. setlength(result,len);
  203. r:=pchar(result);
  204. i:=1;
  205. while i<=length(s) do
  206. begin
  207. if (s[i]='$') and (i<length(s)) then
  208. begin
  209. if s[i+1]='$' then
  210. begin
  211. r^:='$';
  212. inc(r);
  213. inc(i);
  214. end
  215. else if (s[i+1]='{') and (length(s)>2) and (i<length(s)-2) then
  216. begin
  217. varname:='';
  218. inc(i,2);
  219. varno:=byte(s[i]);
  220. repeat
  221. inc(i);
  222. until s[i]='}';
  223. for j:=1 to length(varvalues[varno]^) do
  224. begin
  225. r^:=varvalues[varno]^[j];
  226. inc(r);
  227. end;
  228. end
  229. else if s[i+1] in ['0'..'9'] then
  230. begin
  231. for j:=1 to length(vars[byte(s[i+1])-byte('1')]) do
  232. begin
  233. r^:=vars[byte(s[i+1])-byte('1')][j];
  234. inc(r);
  235. end;
  236. inc(i);
  237. end
  238. end
  239. else
  240. begin
  241. r^:=s[i];
  242. inc(r);
  243. end;
  244. inc(i);
  245. end;
  246. { verify that the length was correct }
  247. if r^<>#0 then
  248. internalerror(200802031);
  249. end;
  250. {****************************************************************************
  251. TDef support
  252. ****************************************************************************}
  253. function TDebugInfoStabs.def_stab_number(def:tdef):string;
  254. begin
  255. { procdefs only need a number, mark them as already written
  256. so they won't be written implicitly }
  257. if (def.typ=procdef) then
  258. def.dbg_state:=dbg_state_written;
  259. { Stab must already be written, or we must be busy writing it }
  260. if writing_def_stabs and
  261. not(def.dbg_state in [dbg_state_writing,dbg_state_written,dbg_state_queued]) then
  262. internalerror(200403091);
  263. { Keep track of used stabs, this info is only usefull for stabs
  264. referenced by the symbols. Definitions will always include all
  265. required stabs }
  266. if def.dbg_state=dbg_state_unused then
  267. def.dbg_state:=dbg_state_used;
  268. { Need a new number? }
  269. if def.stab_number=0 then
  270. begin
  271. inc(global_stab_number);
  272. { classes require 2 numbers }
  273. if is_class(def) then
  274. inc(global_stab_number);
  275. def.stab_number:=global_stab_number;
  276. if global_stab_number>=defnumberlist.count then
  277. defnumberlist.count:=global_stab_number+250;
  278. defnumberlist[global_stab_number]:=def;
  279. end;
  280. result:=tostr(def.stab_number);
  281. end;
  282. function TDebugInfoStabs.def_stab_classnumber(def:tobjectdef):string;
  283. begin
  284. if def.stab_number=0 then
  285. def_stab_number(def);
  286. if (def.objecttype=odt_class) then
  287. result:=tostr(def.stab_number-1)
  288. else
  289. result:=tostr(def.stab_number);
  290. end;
  291. function TDebugInfoStabs.def_var_value(const s:string;arg:pointer):string;
  292. var
  293. def : tdef;
  294. begin
  295. def:=tdef(arg);
  296. result:='';
  297. if s='numberstring' then
  298. result:=def_stab_number(def)
  299. else if s='sym_name' then
  300. begin
  301. if assigned(def.typesym) then
  302. result:=GetSymName(Ttypesym(def.typesym));
  303. end
  304. else if s='N_LSYM' then
  305. result:=tostr(N_LSYM)
  306. else if s='savesize' then
  307. result:=tostr(def.size);
  308. end;
  309. function TDebugInfoStabs.def_stabstr_evaluate(def:tdef;const s:string;const vars:array of string):ansistring;
  310. begin
  311. result:=string_evaluate(s,@def_var_value,def,vars);
  312. end;
  313. procedure TDebugInfoStabs.field_add_stabstr(p:TObject;arg:pointer);
  314. var
  315. spec : string[3];
  316. varsize : aint;
  317. newss : ansistring;
  318. ss : pansistring absolute arg;
  319. begin
  320. if (tsym(p).visibility=vis_hidden) then
  321. exit;
  322. { static variables from objects are like global objects }
  323. if (Tsym(p).typ=fieldvarsym) and
  324. not(sp_static in Tsym(p).symoptions) then
  325. begin
  326. case tsym(p).visibility of
  327. vis_private,
  328. vis_strictprivate :
  329. spec:='/0';
  330. vis_protected,
  331. vis_strictprotected :
  332. spec:='/1';
  333. else
  334. spec:='';
  335. end;
  336. if (tabstractrecordsymtable(tsym(p).owner).usefieldalignment<>bit_alignment) then
  337. begin
  338. varsize:=tfieldvarsym(p).vardef.size;
  339. { open arrays made overflows !! }
  340. { how can a record/object/class contain an open array? (JM) }
  341. if varsize>$fffffff then
  342. varsize:=$fffffff;
  343. newss:=def_stabstr_evaluate(nil,'$1:$2,$3,$4;',[GetSymName(tfieldvarsym(p)),
  344. spec+def_stab_number(tfieldvarsym(p).vardef),
  345. tostr(TConstExprInt(tfieldvarsym(p).fieldoffset)*8),tostr(varsize*8)])
  346. end
  347. else
  348. newss:=def_stabstr_evaluate(nil,'$1:$2,$3,$4;',[GetSymName(tfieldvarsym(p)),
  349. spec+def_stab_number(tfieldvarsym(p).vardef),
  350. tostr(TConstExprInt(tfieldvarsym(p).fieldoffset)),tostr(tfieldvarsym(p).vardef.packedbitsize)]);
  351. ss^:=ss^+newss;
  352. end;
  353. end;
  354. procedure TDebugInfoStabs.method_add_stabstr(p:TObject;arg:pointer);
  355. var
  356. virtualind,argnames : string;
  357. pd : tprocdef;
  358. lindex : longint;
  359. arglength : byte;
  360. sp : char;
  361. i : integer;
  362. parasym : tparavarsym;
  363. newss : ansistring;
  364. ss : pansistring absolute arg;
  365. begin
  366. if tsym(p).typ = procsym then
  367. begin
  368. pd :=tprocdef(tprocsym(p).ProcdefList[0]);
  369. if (po_virtualmethod in pd.procoptions) then
  370. begin
  371. lindex := pd.extnumber;
  372. {doesnt seem to be necessary
  373. lindex := lindex or $80000000;}
  374. virtualind := '*'+tostr(lindex)+';'+def_stab_classnumber(pd._class)+';'
  375. end
  376. else
  377. virtualind := '.';
  378. { used by gdbpas to recognize constructor and destructors }
  379. if (pd.proctypeoption=potype_constructor) then
  380. argnames:='__ct__'
  381. else if (pd.proctypeoption=potype_destructor) then
  382. argnames:='__dt__'
  383. else
  384. argnames := '';
  385. { arguments are not listed here }
  386. {we don't need another definition}
  387. for i:=0 to pd.paras.count-1 do
  388. begin
  389. parasym:=tparavarsym(pd.paras[i]);
  390. if Parasym.vardef.typ = formaldef then
  391. begin
  392. case Parasym.varspez of
  393. vs_var :
  394. argnames := argnames+'3var';
  395. vs_const :
  396. argnames:=argnames+'5const';
  397. vs_out :
  398. argnames:=argnames+'3out';
  399. end;
  400. end
  401. else
  402. begin
  403. { if the arg definition is like (v: ^byte;..
  404. there is no sym attached to data !!! }
  405. if assigned(Parasym.vardef.typesym) then
  406. begin
  407. arglength := length(GetSymName(Parasym.vardef.typesym));
  408. argnames := argnames + tostr(arglength)+GetSymName(Parasym.vardef.typesym);
  409. end
  410. else
  411. argnames:=argnames+'11unnamedtype';
  412. end;
  413. end;
  414. { here 2A must be changed for private and protected }
  415. { 0 is private 1 protected and 2 public }
  416. case tsym(p).visibility of
  417. vis_private,
  418. vis_strictprivate :
  419. sp:='0';
  420. vis_protected,
  421. vis_strictprotected :
  422. sp:='1'
  423. else
  424. sp:='2';
  425. end;
  426. newss:=def_stabstr_evaluate(nil,'$1::$2=##$3;:$4;$5A$6;',[GetSymName(tsym(p)),def_stab_number(pd),
  427. def_stab_number(pd.returndef),argnames,sp,
  428. virtualind]);
  429. ss^:=ss^+newss;
  430. end;
  431. end;
  432. procedure TDebugInfoStabs.field_write_defs(p:TObject;arg:pointer);
  433. begin
  434. if (Tsym(p).typ=fieldvarsym) and
  435. not(sp_static in Tsym(p).symoptions) then
  436. appenddef(TAsmList(arg),tfieldvarsym(p).vardef);
  437. end;
  438. procedure TDebugInfoStabs.write_def_stabstr(list:TAsmList;def:tdef;const ss:ansistring);
  439. var
  440. stabchar : string[2];
  441. symname : string[20];
  442. st : ansistring;
  443. p : pchar;
  444. begin
  445. { type prefix }
  446. if def.typ in tagtypes then
  447. stabchar := 'Tt'
  448. else
  449. stabchar := 't';
  450. { in case of writing the class record structure, we always have to
  451. use the class name (so it refers both to the struct and the
  452. pointer to the struct), otherwise gdb crashes (see tests/webtbs/tw9766.pp) }
  453. if is_class(def) and
  454. tobjectdef(def).writing_class_record_dbginfo then
  455. st:=def_stabstr_evaluate(def,'"${sym_name}:$1$2=',[stabchar,def_stab_classnumber(tobjectdef(def))])
  456. else
  457. begin
  458. { Type names for types defined in the current unit are already written in
  459. the typesym }
  460. if (def.owner.symtabletype=globalsymtable) and
  461. not(def.owner.iscurrentunit) then
  462. symname:='${sym_name}'
  463. else
  464. symname:='';
  465. st:=def_stabstr_evaluate(def,'"'+symname+':$1$2=',[stabchar,def_stab_number(def)]);
  466. end;
  467. st:=st+ss;
  468. { line info is set to 0 for all defs, because the def can be in an other
  469. unit and then the linenumber is invalid in the current sourcefile }
  470. st:=st+def_stabstr_evaluate(def,'",${N_LSYM},0,0,0',[]);
  471. { add to list }
  472. getmem(p,length(st)+1);
  473. move(pchar(st)^,p^,length(st)+1);
  474. list.concat(Tai_stab.create(stab_stabs,p));
  475. end;
  476. procedure TDebugInfoStabs.appenddef_string(list:TAsmList;def:tstringdef);
  477. var
  478. bytest,charst,longst : string;
  479. ss : ansistring;
  480. slen : longint;
  481. begin
  482. ss:='';
  483. case def.stringtype of
  484. st_shortstring:
  485. begin
  486. { fix length of openshortstring }
  487. slen:=def.len;
  488. if slen=0 then
  489. slen:=255;
  490. charst:=def_stab_number(cchartype);
  491. bytest:=def_stab_number(u8inttype);
  492. ss:=def_stabstr_evaluate(def,'s$1length:$2,0,8;st:ar$2;1;$3;$4,8,$5;;',
  493. [tostr(slen+1),bytest,tostr(slen),charst,tostr(slen*8)]);
  494. end;
  495. st_longstring:
  496. begin
  497. charst:=def_stab_number(cchartype);
  498. bytest:=def_stab_number(u8inttype);
  499. longst:=def_stab_number(u32inttype);
  500. ss:=def_stabstr_evaluate(def,'s$1length:$2,0,32;dummy:$6,32,8;st:ar$2;1;$3;$4,40,$5;;',
  501. [tostr(def.len+5),longst,tostr(def.len),charst,tostr(def.len*8),bytest]);
  502. end;
  503. st_ansistring:
  504. begin
  505. { looks like a pchar }
  506. ss:='*'+def_stab_number(cchartype);
  507. end;
  508. st_unicodestring,
  509. st_widestring:
  510. begin
  511. { looks like a pwidechar }
  512. ss:='*'+def_stab_number(cwidechartype);
  513. end;
  514. end;
  515. write_def_stabstr(list,def,ss);
  516. end;
  517. function TDebugInfoStabs.get_enum_defstr(def: tenumdef; lowerbound: longint): ansistring;
  518. var
  519. i: longint;
  520. p: tenumsym;
  521. begin
  522. { we can specify the size with @s<size>; prefix PM }
  523. if def.size <> std_param_align then
  524. result:='@s'+tostr(def.size*8)+';e'
  525. else
  526. result:='e';
  527. p := tenumsym(def.firstenum);
  528. { the if-test is required because pred(def.minval) might overflow;
  529. the longint() typecast should be safe because stabs is not
  530. supported for 64 bit targets }
  531. if (def.minval<>lowerbound) then
  532. for i:=lowerbound to pred(longint(def.minval)) do
  533. result:=result+'<invalid>:'+tostr(i)+',';
  534. while assigned(p) do
  535. begin
  536. result:=result+GetSymName(p)+':'+tostr(p.value)+',';
  537. p:=p.nextenum;
  538. end;
  539. { the final ',' is required to have a valid stabs }
  540. result:=result+';';
  541. end;
  542. procedure TDebugInfoStabs.appenddef_enum(list:TAsmList;def:tenumdef);
  543. begin
  544. write_def_stabstr(list,def,get_enum_defstr(def,def.minval));
  545. end;
  546. procedure TDebugInfoStabs.appenddef_ord(list:TAsmList;def:torddef);
  547. var
  548. ss : ansistring;
  549. begin
  550. ss:='';
  551. if cs_gdb_valgrind in current_settings.globalswitches then
  552. begin
  553. case def.ordtype of
  554. uvoid :
  555. ss:=def_stab_number(def);
  556. pasbool,
  557. bool8bit,
  558. bool16bit,
  559. bool32bit,
  560. bool64bit :
  561. ss:=def_stabstr_evaluate(def,'r${numberstring};0;255;',[]);
  562. u32bit,
  563. s64bit,
  564. u64bit :
  565. ss:=def_stabstr_evaluate(def,'r${numberstring};0;-1;',[]);
  566. else
  567. ss:=def_stabstr_evaluate(def,'r${numberstring};$1;$2;',[tostr(longint(def.low.svalue)),tostr(longint(def.high.svalue))]);
  568. end;
  569. end
  570. else
  571. begin
  572. case def.ordtype of
  573. uvoid :
  574. ss:=def_stab_number(def);
  575. uchar :
  576. ss:='-20;';
  577. uwidechar :
  578. ss:='-30;';
  579. pasbool,
  580. bool8bit :
  581. ss:='-21;';
  582. bool16bit :
  583. ss:='-22;';
  584. bool32bit :
  585. ss:='-23;';
  586. bool64bit :
  587. { no clue if this is correct (FK) }
  588. ss:='-23;';
  589. u64bit :
  590. ss:='-32;';
  591. s64bit :
  592. ss:='-31;';
  593. {u32bit : result:=def_stab_number(s32inttype)+';0;-1;'); }
  594. else
  595. ss:=def_stabstr_evaluate(def,'r${numberstring};$1;$2;',[tostr(longint(def.low.svalue)),tostr(longint(def.high.svalue))]);
  596. end;
  597. end;
  598. write_def_stabstr(list,def,ss);
  599. end;
  600. procedure TDebugInfoStabs.appenddef_float(list:TAsmList;def:tfloatdef);
  601. var
  602. ss : ansistring;
  603. begin
  604. ss:='';
  605. case def.floattype of
  606. s32real,
  607. s64real,
  608. s80real,
  609. sc80real:
  610. ss:=def_stabstr_evaluate(def,'r$1;${savesize};0;',[def_stab_number(s32inttype)]);
  611. s64currency,
  612. s64comp:
  613. ss:=def_stabstr_evaluate(def,'r$1;-${savesize};0;',[def_stab_number(s32inttype)]);
  614. else
  615. internalerror(200509261);
  616. end;
  617. write_def_stabstr(list,def,ss);
  618. end;
  619. procedure TDebugInfoStabs.appenddef_file(list:TAsmList;def:tfiledef);
  620. var
  621. ss : ansistring;
  622. begin
  623. {$ifdef cpu64bitaddr}
  624. ss:=def_stabstr_evaluate(def,'s${savesize}HANDLE:$1,0,32;MODE:$1,32,32;RECSIZE:$2,64,64;'+
  625. '_PRIVATE:ar$1;1;64;$3,128,256;USERDATA:ar$1;1;16;$3,384,128;'+
  626. 'NAME:ar$1;0;255;$4,512,2048;;',[def_stab_number(s32inttype),
  627. def_stab_number(s64inttype),
  628. def_stab_number(u8inttype),
  629. def_stab_number(cchartype)]);
  630. {$else cpu64bitaddr}
  631. ss:=def_stabstr_evaluate(def,'s${savesize}HANDLE:$1,0,32;MODE:$1,32,32;RECSIZE:$1,64,32;'+
  632. '_PRIVATE:ar$1;1;32;$3,96,256;USERDATA:ar$1;1;16;$2,352,128;'+
  633. 'NAME:ar$1;0;255;$3,480,2048;;',[def_stab_number(s32inttype),
  634. def_stab_number(u8inttype),
  635. def_stab_number(cchartype)]);
  636. {$endif cpu64bitaddr}
  637. write_def_stabstr(list,def,ss);
  638. end;
  639. procedure TDebugInfoStabs.appenddef_record(list:TAsmList;def:trecorddef);
  640. var
  641. ss : ansistring;
  642. begin
  643. ss:='s'+tostr(def.size);
  644. def.symtable.SymList.ForEachCall(@field_add_stabstr,@ss);
  645. ss[length(ss)]:=';';
  646. write_def_stabstr(list,def,ss);
  647. end;
  648. procedure TDebugInfoStabs.appenddef_object(list:TAsmList;def:tobjectdef);
  649. procedure do_write_object(list:TAsmList;def:tobjectdef);
  650. var
  651. ss : ansistring;
  652. anc : tobjectdef;
  653. begin
  654. ss:='';
  655. { Write the invisible pointer for the class? }
  656. if (def.objecttype=odt_class) and
  657. (not def.writing_class_record_dbginfo) then
  658. begin
  659. ss:='*'+def_stab_classnumber(def);
  660. write_def_stabstr(list,def,ss);
  661. exit;
  662. end;
  663. ss:='s'+tostr(tobjecTSymtable(def.symtable).datasize);
  664. if assigned(def.childof) then
  665. begin
  666. {only one ancestor not virtual, public, at base offset 0 }
  667. { !1 , 0 2 0 , }
  668. ss:=ss+'!1,020,'+def_stab_classnumber(def.childof)+';';
  669. end;
  670. {virtual table to implement yet}
  671. def.symtable.symList.ForEachCall(@field_add_stabstr,@ss);
  672. if (oo_has_vmt in def.objectoptions) and
  673. (
  674. not assigned(def.childof) or
  675. not(oo_has_vmt in def.childof.objectoptions)
  676. ) then
  677. ss:=ss+'$vf'+def_stab_classnumber(def)+':'+def_stab_number(vmtarraytype)+','+tostr(def.vmt_offset*8)+';';
  678. def.symtable.symList.ForEachCall(@method_add_stabstr,@ss);
  679. if (oo_has_vmt in def.objectoptions) then
  680. begin
  681. anc := def;
  682. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  683. anc := anc.childof;
  684. { just in case anc = self }
  685. ss:=ss+';~%'+def_stab_classnumber(anc)+';';
  686. end
  687. else
  688. ss:=ss+';';
  689. write_def_stabstr(list,def,ss);
  690. end;
  691. var
  692. oldtypesym : tsym;
  693. begin
  694. { classes require special code to write the record and the invisible pointer }
  695. if is_class(def) then
  696. begin
  697. { Write the record class itself }
  698. tobjectdef(def).writing_class_record_dbginfo:=true;
  699. do_write_object(list,def);
  700. tobjectdef(def).writing_class_record_dbginfo:=false;
  701. { Write the invisible pointer class }
  702. oldtypesym:=def.typesym;
  703. def.typesym:=nil;
  704. do_write_object(list,def);
  705. def.typesym:=oldtypesym;
  706. end
  707. else
  708. do_write_object(list,def);
  709. { VMT symbol }
  710. if (oo_has_vmt in tobjectdef(def).objectoptions) and
  711. assigned(def.owner) and
  712. assigned(def.owner.name) then
  713. list.concat(Tai_stab.create(stab_stabs,strpnew('"vmt_'+GetSymTableName(def.owner)+tobjectdef(def).objname^+':S'+
  714. def_stab_number(vmttype)+'",'+tostr(N_STSYM)+',0,0,'+tobjectdef(def).vmt_mangledname)));
  715. end;
  716. procedure TDebugInfoStabs.appenddef_variant(list:TAsmList;def:tvariantdef);
  717. var
  718. ss : ansistring;
  719. begin
  720. ss:='s'+tostr(vardatadef.size);
  721. vardatadef.symtable.SymList.ForEachCall(@field_add_stabstr,@ss);
  722. ss[length(ss)]:=';';
  723. write_def_stabstr(list,def,ss);
  724. end;
  725. procedure TDebugInfoStabs.appenddef_pointer(list:TAsmList;def:tpointerdef);
  726. var
  727. ss : ansistring;
  728. begin
  729. ss:='*'+def_stab_number(tpointerdef(def).pointeddef);
  730. write_def_stabstr(list,def,ss);
  731. end;
  732. procedure TDebugInfoStabs.appenddef_set(list:TAsmList;def:tsetdef);
  733. var
  734. st,
  735. ss : ansistring;
  736. p: pchar;
  737. elementdefstabnr: string;
  738. begin
  739. { ugly hack: create a temporary subrange type if the lower bound of
  740. the set's element type is not a multiple of 8 (because we store them
  741. as if the lower bound is a multiple of 8) }
  742. if (def.setbase<>get_min_value(def.elementdef)) then
  743. begin
  744. { allocate a def number }
  745. inc(global_stab_number);
  746. elementdefstabnr:=tostr(global_stab_number);
  747. { anonymous subrange def }
  748. st:='":t'+elementdefstabnr+'=';
  749. if (def.elementdef.typ = enumdef) then
  750. st:=st+get_enum_defstr(tenumdef(def.elementdef),def.setbase)
  751. else
  752. st:=st+def_stabstr_evaluate(def.elementdef,'r'+elementdefstabnr+';$1;$2;',[tostr(longint(def.setbase)),tostr(longint(get_max_value(def.elementdef).svalue))]);
  753. st:=st+'",'+tostr(N_LSYM)+',0,0,0';
  754. { add to list }
  755. getmem(p,length(st)+1);
  756. move(pchar(st)^,p^,length(st)+1);
  757. list.concat(Tai_stab.create(stab_stabs,p));
  758. end
  759. else
  760. elementdefstabnr:=def_stab_number(def.elementdef);
  761. ss:=def_stabstr_evaluate(def,'@s$1;S$2',[tostr(def.size*8),elementdefstabnr]);
  762. write_def_stabstr(list,def,ss);
  763. end;
  764. procedure TDebugInfoStabs.appenddef_formal(list:TAsmList;def:tformaldef);
  765. var
  766. ss : ansistring;
  767. begin
  768. ss:=def_stabstr_evaluate(def,'${numberstring};',[]);
  769. write_def_stabstr(list,def,ss);
  770. end;
  771. procedure TDebugInfoStabs.appenddef_array(list:TAsmList;def:tarraydef);
  772. var
  773. tempstr: shortstring;
  774. ss : ansistring;
  775. begin
  776. if not is_packed_array(def) then
  777. begin
  778. tempstr:='ar$1;$2;$3;$4';
  779. if is_dynamic_array(def) then
  780. tempstr:='*'+tempstr;
  781. ss:=def_stabstr_evaluate(def,tempstr,[def_stab_number(tarraydef(def).rangedef),
  782. tostr(tarraydef(def).lowrange),tostr(tarraydef(def).highrange),def_stab_number(tarraydef(def).elementdef)])
  783. end
  784. else
  785. begin
  786. // the @P seems to be ignored by gdb
  787. tempstr:=def_stabstr_evaluate(tarraydef(def).rangedef,'r${numberstring};$1;$2;',
  788. [tostr(tarraydef(def).lowrange),tostr(tarraydef(def).highrange)]);
  789. // will only show highrange-lowrange+1 bits in gdb
  790. ss:=def_stabstr_evaluate(def,'@s$1;@S;S$2',
  791. [tostr(TConstExprInt(tarraydef(def).elepackedbitsize) * tarraydef(def).elecount),tempstr]);
  792. end;
  793. write_def_stabstr(list,def,ss);
  794. end;
  795. procedure TDebugInfoStabs.appenddef_procvar(list:TAsmList;def:tprocvardef);
  796. var
  797. ss : ansistring;
  798. begin
  799. ss:='*f'+def_stab_number(tprocvardef(def).returndef);
  800. write_def_stabstr(list,def,ss);
  801. end;
  802. procedure TDebugInfoStabs.appenddef_undefined(list:TAsmList;def:tundefineddef);
  803. var
  804. ss : ansistring;
  805. begin
  806. ss:=def_stabstr_evaluate(def,'${numberstring};',[]);
  807. write_def_stabstr(list,def,ss);
  808. end;
  809. procedure TDebugInfoStabs.beforeappenddef(list:TAsmList;def:tdef);
  810. var
  811. anc : tobjectdef;
  812. i : longint;
  813. begin
  814. { write dependencies first }
  815. case def.typ of
  816. stringdef :
  817. begin
  818. if tstringdef(def).stringtype in [st_widestring,st_unicodestring] then
  819. appenddef(list,cwidechartype)
  820. else
  821. begin
  822. appenddef(list,cchartype);
  823. appenddef(list,u8inttype);
  824. end;
  825. end;
  826. floatdef :
  827. appenddef(list,s32inttype);
  828. filedef :
  829. begin
  830. appenddef(list,s32inttype);
  831. {$ifdef cpu64bitaddr}
  832. appenddef(list,s64inttype);
  833. {$endif cpu64bitaddr}
  834. appenddef(list,u8inttype);
  835. appenddef(list,cchartype);
  836. end;
  837. classrefdef :
  838. appenddef(list,pvmttype);
  839. pointerdef :
  840. appenddef(list,tpointerdef(def).pointeddef);
  841. setdef :
  842. appenddef(list,tsetdef(def).elementdef);
  843. procvardef :
  844. begin
  845. appenddef(list,tprocvardef(def).returndef);
  846. if assigned(tprocvardef(def).parast) then
  847. write_symtable_defs(list,tprocvardef(def).parast);
  848. end;
  849. procdef :
  850. begin
  851. appenddef(list,tprocdef(def).returndef);
  852. if assigned(tprocdef(def).parast) then
  853. write_symtable_defs(list,tprocdef(def).parast);
  854. if assigned(tprocdef(def).localst) and
  855. (tprocdef(def).localst.symtabletype=localsymtable) then
  856. write_symtable_defs(list,tprocdef(def).localst);
  857. end;
  858. arraydef :
  859. begin
  860. appenddef(list,tarraydef(def).rangedef);
  861. appenddef(list,tarraydef(def).elementdef);
  862. end;
  863. recorddef :
  864. trecorddef(def).symtable.symList.ForEachCall(@field_write_defs,list);
  865. enumdef :
  866. if assigned(tenumdef(def).basedef) then
  867. appenddef(list,tenumdef(def).basedef);
  868. objectdef :
  869. begin
  870. { make sure we don't write child classdefs before their parent }
  871. { classdefs, because this crashes gdb }
  872. anc:=tobjectdef(def);
  873. while assigned(anc.childof) do
  874. begin
  875. anc:=anc.childof;
  876. if (anc.dbg_state=dbg_state_writing) then
  877. { happens in case a field of a parent is of the (forward }
  878. { defined) child type }
  879. begin
  880. { We don't explicitly requeue it, but the fact that }
  881. { a child type was used in a parent before the child }
  882. { type was fully defined means that it was forward }
  883. { declared, and will still be encountered later (it }
  884. { cannot have been declared in another unit, because }
  885. { then this and that other unit would depend on }
  886. { eachother's interface) }
  887. { Setting the state to queued however allows us to }
  888. { get the def number already without an IE }
  889. def.dbg_state:=dbg_state_queued;
  890. exit;
  891. end;
  892. end;
  893. appenddef(list,vmtarraytype);
  894. if assigned(tobjectdef(def).ImplementedInterfaces) then
  895. for i:=0 to tobjectdef(def).ImplementedInterfaces.Count-1 do
  896. appenddef(list,TImplementedInterface(tobjectdef(def).ImplementedInterfaces[i]).IntfDef);
  897. { first the parents }
  898. anc:=tobjectdef(def);
  899. while assigned(anc.childof) do
  900. begin
  901. anc:=anc.childof;
  902. appenddef(list,anc);
  903. if assigned(anc.ImplementedInterfaces) then
  904. for i:=0 to anc.ImplementedInterfaces.Count-1 do
  905. appenddef(list,TImplementedInterface(anc.ImplementedInterfaces[i]).IntfDef);
  906. end;
  907. tobjectdef(def).symtable.symList.ForEachCall(@field_write_defs,list);
  908. end;
  909. end;
  910. end;
  911. procedure TDebugInfoStabs.appendprocdef(list:TAsmList;def:tprocdef);
  912. var
  913. templist : TAsmList;
  914. stabsendlabel : tasmlabel;
  915. p : pchar;
  916. RType : Char;
  917. Obj,Info : String;
  918. hs : string;
  919. ss : ansistring;
  920. begin
  921. if not assigned(def.procstarttai) then
  922. exit;
  923. { mark as used so the local type defs also be written }
  924. def.dbg_state:=dbg_state_used;
  925. templist:=TAsmList.create;
  926. { end of procedure }
  927. current_asmdata.getlabel(stabsendlabel,alt_dbgtype);
  928. if assigned(def.funcretsym) and
  929. (tabstractnormalvarsym(def.funcretsym).refs>0) then
  930. begin
  931. if tabstractnormalvarsym(def.funcretsym).localloc.loc=LOC_REFERENCE then
  932. begin
  933. { TODO: Need to add gdb support for ret in param register calling}
  934. if paramanager.ret_in_param(def.returndef,def.proccalloption) then
  935. hs:='X*'
  936. else
  937. hs:='X';
  938. templist.concat(Tai_stab.create(stab_stabs,strpnew(
  939. '"'+GetSymName(def.procsym)+':'+hs+def_stab_number(def.returndef)+'",'+
  940. tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(def.funcretsym).localloc.reference.offset))));
  941. if (m_result in current_settings.modeswitches) then
  942. templist.concat(Tai_stab.create(stab_stabs,strpnew(
  943. '"RESULT:'+hs+def_stab_number(def.returndef)+'",'+
  944. tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(def.funcretsym).localloc.reference.offset))));
  945. end;
  946. end;
  947. // LBRAC
  948. ss:=tostr(N_LBRAC)+',0,0,';
  949. if target_info.cpu=cpu_powerpc64 then
  950. ss:=ss+'.';
  951. ss:=ss+def.mangledname;
  952. if not(af_stabs_use_function_absolute_addresses in target_asm.flags) then
  953. begin
  954. ss:=ss+'-';
  955. if target_info.cpu=cpu_powerpc64 then
  956. ss:=ss+'.';
  957. ss:=ss+def.mangledname;
  958. end;
  959. getmem(p,length(ss)+1);
  960. move(pchar(ss)^,p^,length(ss)+1);
  961. templist.concat(Tai_stab.Create(stab_stabn,p));
  962. // RBRAC
  963. ss:=tostr(N_RBRAC)+',0,0,'+stabsendlabel.name;
  964. if not(af_stabs_use_function_absolute_addresses in target_asm.flags) then
  965. begin
  966. ss:=ss+'-';
  967. if target_info.cpu=cpu_powerpc64 then
  968. ss:=ss+'.';
  969. ss:=ss+def.mangledname;
  970. end;
  971. getmem(p,length(ss)+1);
  972. move(pchar(ss)^,p^,length(ss)+1);
  973. templist.concat(Tai_stab.Create(stab_stabn,p));
  974. { the stabsendlabel must come after all other stabs for this }
  975. { function }
  976. templist.concat(tai_label.create(stabsendlabel));
  977. { Add a "size" stab as described in the last paragraph of 2.5 at }
  978. { http://sourceware.org/gdb/current/onlinedocs/stabs_2.html#SEC12 }
  979. { This works at least on Darwin (and is needed on Darwin to get }
  980. { correct smartlinking of stabs), but I don't know which binutils }
  981. { version is required on other platforms }
  982. { This stab must come after all other stabs for the procedure, }
  983. { including the LBRAC/RBRAC ones }
  984. if (target_info.system in systems_darwin) then
  985. templist.concat(Tai_stab.create(stab_stabs,
  986. strpnew('"",'+tostr(N_FUNCTION)+',0,0,'+stabsendlabel.name+'-'+def.mangledname)));
  987. current_asmdata.asmlists[al_procedures].insertlistafter(def.procendtai,templist);
  988. { "The stab representing a procedure is located immediately
  989. following the code of the procedure. This stab is in turn
  990. directly followed by a group of other stabs describing
  991. elements of the procedure. These other stabs describe the
  992. procedure's parameters, its block local variables, and its
  993. block structure." (stab docs) }
  994. { this is however incorrect in case "include source" statements }
  995. { appear in the block, in that case the procedure stab must }
  996. { appear before this include stabs (and we generate such an }
  997. { stabs for all functions) (JM) }
  998. { FUNC stabs }
  999. obj := GetSymName(def.procsym);
  1000. info := '';
  1001. if (po_global in def.procoptions) then
  1002. RType := 'F'
  1003. else
  1004. RType := 'f';
  1005. if assigned(def.owner) then
  1006. begin
  1007. if (def.owner.symtabletype = objecTSymtable) then
  1008. obj := GetSymTableName(def.owner)+'__'+GetSymName(def.procsym);
  1009. if not(cs_gdb_valgrind in current_settings.globalswitches) and
  1010. (def.owner.symtabletype=localsymtable) and
  1011. assigned(def.owner.defowner) and
  1012. assigned(tprocdef(def.owner.defowner).procsym) then
  1013. info := ','+GetSymName(def.procsym)+','+GetSymName(tprocdef(def.owner.defowner).procsym);
  1014. end;
  1015. ss:='"'+ansistring(obj)+':'+RType+def_stab_number(def.returndef)+info+'",'+tostr(n_function)+',0,'+tostr(def.fileinfo.line)+','+ansistring(def.mangledname);
  1016. getmem(p,length(ss)+1);
  1017. move(pchar(ss)^,p^,length(ss)+1);
  1018. templist.concat(Tai_stab.Create(stab_stabs,p));
  1019. current_asmdata.asmlists[al_procedures].insertlistbefore(def.procstarttai,templist);
  1020. { para types }
  1021. if assigned(def.parast) then
  1022. write_symtable_syms(templist,def.parast);
  1023. { local type defs and vars should not be written
  1024. inside the main proc stab }
  1025. if assigned(def.localst) and
  1026. (def.localst.symtabletype=localsymtable) then
  1027. write_symtable_syms(templist,def.localst);
  1028. current_asmdata.asmlists[al_procedures].insertlistbefore(def.procstarttai,templist);
  1029. templist.free;
  1030. end;
  1031. {****************************************************************************
  1032. TSym support
  1033. ****************************************************************************}
  1034. function TDebugInfoStabs.sym_var_value(const s:string;arg:pointer):string;
  1035. var
  1036. sym : tsym absolute arg;
  1037. begin
  1038. result:='';
  1039. if s='name' then
  1040. result:=GetSymName(sym)
  1041. else if s='mangledname' then
  1042. result:=sym.mangledname
  1043. else if s='ownername' then
  1044. result:=GetSymTableName(sym.owner)
  1045. else if s='line' then
  1046. result:=tostr(sym.fileinfo.line)
  1047. else if s='N_LSYM' then
  1048. result:=tostr(N_LSYM)
  1049. else if s='N_LCSYM' then
  1050. result:=tostr(N_LCSYM)
  1051. else if s='N_RSYM' then
  1052. result:=tostr(N_RSYM)
  1053. else if s='N_TSYM' then
  1054. result:=tostr(N_TSYM)
  1055. else if s='N_STSYM' then
  1056. result:=tostr(N_STSYM)
  1057. else if s='N_FUNCTION' then
  1058. result:=tostr(N_FUNCTION)
  1059. else
  1060. internalerror(200401152);
  1061. end;
  1062. function TDebugInfoStabs.sym_stabstr_evaluate(sym:tsym;const s:string;const vars:array of string):ansistring;
  1063. begin
  1064. result:=string_evaluate(s,@sym_var_value,sym,vars);
  1065. end;
  1066. procedure TDebugInfoStabs.write_sym_stabstr(list:TAsmList;sym:tsym;const ss:ansistring);
  1067. var
  1068. p : pchar;
  1069. begin
  1070. if ss='' then
  1071. exit;
  1072. { add to list }
  1073. getmem(p,length(ss)+1);
  1074. move(pchar(ss)^,p^,length(ss)+1);
  1075. list.concat(Tai_stab.create(stab_stabs,p));
  1076. end;
  1077. procedure TDebugInfoStabs.appendsym_fieldvar(list:TAsmList;sym:tfieldvarsym);
  1078. var
  1079. ss : ansistring;
  1080. begin
  1081. ss:='';
  1082. if (sym.owner.symtabletype=objecTSymtable) and
  1083. (sp_static in sym.symoptions) then
  1084. ss:=sym_stabstr_evaluate(sym,'"${ownername}__${name}:S$1",${N_LCSYM},0,${line},${mangledname}',
  1085. [def_stab_number(sym.vardef)]);
  1086. write_sym_stabstr(list,sym,ss);
  1087. end;
  1088. procedure TDebugInfoStabs.appendsym_staticvar(list:TAsmList;sym:tstaticvarsym);
  1089. var
  1090. ss : ansistring;
  1091. st : string;
  1092. threadvaroffset : string;
  1093. regidx : Tregisterindex;
  1094. nsym : string[7];
  1095. begin
  1096. { external symbols can't be resolved at link time, so we
  1097. can't generate stabs for them }
  1098. if vo_is_external in sym.varoptions then
  1099. exit;
  1100. ss:='';
  1101. st:=def_stab_number(sym.vardef);
  1102. case sym.localloc.loc of
  1103. LOC_REGISTER,
  1104. LOC_CREGISTER,
  1105. LOC_MMREGISTER,
  1106. LOC_CMMREGISTER,
  1107. LOC_FPUREGISTER,
  1108. LOC_CFPUREGISTER :
  1109. begin
  1110. regidx:=findreg_by_number(sym.localloc.register);
  1111. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1112. { this is the register order for GDB}
  1113. if regidx<>0 then
  1114. ss:=sym_stabstr_evaluate(sym,'"${name}:r$1",${N_RSYM},0,${line},$2',[st,tostr(regstabs_table[regidx])]);
  1115. end;
  1116. else
  1117. begin
  1118. if (vo_is_thread_var in sym.varoptions) then
  1119. threadvaroffset:='+'+tostr(sizeof(pint))
  1120. else
  1121. threadvaroffset:='';
  1122. if (vo_is_typed_const in sym.varoptions) then
  1123. nsym:='N_STSYM'
  1124. else
  1125. nsym:='N_LCSYM';
  1126. { Here we used S instead of
  1127. because with G GDB doesn't look at the address field
  1128. but searches the same name or with a leading underscore
  1129. but these names don't exist in pascal !}
  1130. st:='S'+st;
  1131. ss:=sym_stabstr_evaluate(sym,'"${name}:$1",${'+nsym+'},0,${line},${mangledname}$2',[st,threadvaroffset]);
  1132. end;
  1133. end;
  1134. write_sym_stabstr(list,sym,ss);
  1135. end;
  1136. procedure TDebugInfoStabs.appendsym_localvar(list:TAsmList;sym:tlocalvarsym);
  1137. var
  1138. ss : ansistring;
  1139. st : string;
  1140. regidx : Tregisterindex;
  1141. begin
  1142. { There is no space allocated for not referenced locals }
  1143. if (sym.owner.symtabletype=localsymtable) and (sym.refs=0) then
  1144. exit;
  1145. ss:='';
  1146. st:=def_stab_number(sym.vardef);
  1147. case sym.localloc.loc of
  1148. LOC_REGISTER,
  1149. LOC_CREGISTER,
  1150. LOC_MMREGISTER,
  1151. LOC_CMMREGISTER,
  1152. LOC_FPUREGISTER,
  1153. LOC_CFPUREGISTER :
  1154. begin
  1155. regidx:=findreg_by_number(sym.localloc.register);
  1156. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1157. { this is the register order for GDB}
  1158. if regidx<>0 then
  1159. ss:=sym_stabstr_evaluate(sym,'"${name}:r$1",${N_RSYM},0,${line},$2',[st,tostr(regstabs_table[regidx])]);
  1160. end;
  1161. LOC_REFERENCE :
  1162. { offset to ebp => will not work if the framepointer is esp
  1163. so some optimizing will make things harder to debug }
  1164. ss:=sym_stabstr_evaluate(sym,'"${name}:$1",${N_TSYM},0,${line},$2',[st,tostr(sym.localloc.reference.offset)])
  1165. else
  1166. internalerror(2003091814);
  1167. end;
  1168. write_sym_stabstr(list,sym,ss);
  1169. end;
  1170. function TDebugInfoStabs.get_appendsym_paravar_reg(sym:tparavarsym;const typ,stabstr:string;reg: tregister): ansistring;
  1171. var
  1172. ltyp: string[1];
  1173. regidx : Tregisterindex;
  1174. begin
  1175. result:='';
  1176. if typ='p' then
  1177. ltyp:='R'
  1178. else
  1179. ltyp:='a';
  1180. regidx:=findreg_by_number(reg);
  1181. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1182. { this is the register order for GDB}
  1183. if regidx<>0 then
  1184. result:=sym_stabstr_evaluate(sym,'"${name}:$1",${N_RSYM},0,${line},$2',[ltyp+stabstr,tostr(longint(regstabs_table[regidx]))]);
  1185. end;
  1186. procedure TDebugInfoStabs.appendsym_paravar(list:TAsmList;sym:tparavarsym);
  1187. var
  1188. ss : ansistring;
  1189. c : string[1];
  1190. st : string;
  1191. regidx : Tregisterindex;
  1192. begin
  1193. ss:='';
  1194. { set loc to LOC_REFERENCE to get somewhat usable debugging info for -Or }
  1195. { while stabs aren't adapted for regvars yet }
  1196. if (vo_is_self in sym.varoptions) then
  1197. begin
  1198. case sym.localloc.loc of
  1199. LOC_REGISTER,
  1200. LOC_CREGISTER:
  1201. regidx:=findreg_by_number(sym.localloc.register);
  1202. LOC_REFERENCE: ;
  1203. else
  1204. internalerror(2003091815);
  1205. end;
  1206. if (po_classmethod in tabstractprocdef(sym.owner.defowner).procoptions) or
  1207. (po_staticmethod in tabstractprocdef(sym.owner.defowner).procoptions) then
  1208. begin
  1209. if (sym.localloc.loc=LOC_REFERENCE) then
  1210. ss:=sym_stabstr_evaluate(sym,'"pvmt:p$1",${N_TSYM},0,0,$2',
  1211. [def_stab_number(pvmttype),tostr(sym.localloc.reference.offset)])
  1212. else
  1213. begin
  1214. regidx:=findreg_by_number(sym.localloc.register);
  1215. ss:=sym_stabstr_evaluate(sym,'"pvmt:r$1",${N_RSYM},0,0,$2',
  1216. [def_stab_number(pvmttype),tostr(regstabs_table[regidx])]);
  1217. end
  1218. end
  1219. else
  1220. begin
  1221. if not(is_class(tprocdef(sym.owner.defowner)._class)) then
  1222. c:='v'
  1223. else
  1224. c:='p';
  1225. if (sym.localloc.loc=LOC_REFERENCE) then
  1226. ss:=sym_stabstr_evaluate(sym,'"$$t:$1",${N_TSYM},0,0,$2',
  1227. [c+def_stab_number(tprocdef(sym.owner.defowner)._class),tostr(sym.localloc.reference.offset)])
  1228. else
  1229. begin
  1230. regidx:=findreg_by_number(sym.localloc.register);
  1231. ss:=sym_stabstr_evaluate(sym,'"$$t:r$1",${N_RSYM},0,0,$2',
  1232. [c+def_stab_number(tprocdef(sym.owner.defowner)._class),tostr(regstabs_table[regidx])]);
  1233. end
  1234. end;
  1235. end
  1236. else
  1237. begin
  1238. st:=def_stab_number(sym.vardef);
  1239. if paramanager.push_addr_param(sym.varspez,sym.vardef,tprocdef(sym.owner.defowner).proccalloption) and
  1240. not(vo_has_local_copy in sym.varoptions) and
  1241. not is_open_string(sym.vardef) then
  1242. c:='v' { should be 'i' but 'i' doesn't work }
  1243. else
  1244. c:='p';
  1245. case sym.localloc.loc of
  1246. LOC_REGISTER,
  1247. LOC_CREGISTER,
  1248. LOC_MMREGISTER,
  1249. LOC_CMMREGISTER,
  1250. LOC_FPUREGISTER,
  1251. LOC_CFPUREGISTER :
  1252. begin
  1253. ss:=get_appendsym_paravar_reg(sym,c,st,sym.localloc.register);
  1254. end;
  1255. LOC_REFERENCE :
  1256. begin
  1257. { When the *value* of a parameter (so not its address!) is
  1258. copied into a local variable, you have to generate two
  1259. stabs: one for the parmeter, and one for the local copy.
  1260. Not doing this breaks debugging under e.g. SPARC. Doc:
  1261. http://sourceware.org/gdb/current/onlinedocs/stabs_4.html#SEC26
  1262. }
  1263. if (c='p') and
  1264. not is_open_string(sym.vardef) and
  1265. ((sym.paraloc[calleeside].location^.loc<>sym.localloc.loc) or
  1266. ((sym.localloc.loc in [LOC_REFERENCE,LOC_CREFERENCE]) and
  1267. ((sym.paraloc[calleeside].location^.reference.index<>sym.localloc.reference.base) or
  1268. (sym.paraloc[calleeside].location^.reference.offset<>sym.localloc.reference.offset))) or
  1269. ((sym.localloc.loc in [LOC_REGISTER,LOC_CREGISTER,LOC_MMREGISTER,LOC_CMMREGISTER,LOC_FPUREGISTER,LOC_CFPUREGISTER]) and
  1270. (sym.localloc.register<>sym.paraloc[calleeside].location^.register))) then
  1271. begin
  1272. if not(sym.paraloc[calleeside].location^.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  1273. ss:=get_appendsym_paravar_reg(sym,c,st,sym.paraloc[calleeside].location^.register)
  1274. else
  1275. ss:=sym_stabstr_evaluate(sym,'"${name}:$1",${N_TSYM},0,${line},$2',[c+st,tostr(sym.paraloc[calleeside].location^.reference.offset)]);
  1276. write_sym_stabstr(list,sym,ss);
  1277. { second stab has no parameter specifier }
  1278. c:='';
  1279. end;
  1280. { offset to ebp => will not work if the framepointer is esp
  1281. so some optimizing will make things harder to debug }
  1282. ss:=sym_stabstr_evaluate(sym,'"${name}:$1",${N_TSYM},0,${line},$2',[c+st,tostr(sym.localloc.reference.offset)])
  1283. end;
  1284. else
  1285. internalerror(2003091814);
  1286. end;
  1287. end;
  1288. write_sym_stabstr(list,sym,ss);
  1289. end;
  1290. procedure TDebugInfoStabs.appendsym_const(list:TAsmList;sym:tconstsym);
  1291. var
  1292. st : string;
  1293. ss : ansistring;
  1294. begin
  1295. ss:='';
  1296. { Don't write info for default parameter values, the N_Func breaks
  1297. the N_Func for the function itself.
  1298. Valgrind does not support constants }
  1299. if (sym.owner.symtabletype=parasymtable) or
  1300. (cs_gdb_valgrind in current_settings.globalswitches) then
  1301. exit;
  1302. case sym.consttyp of
  1303. conststring:
  1304. begin
  1305. if sym.value.len<200 then
  1306. st:='s'''+backspace_quote(octal_quote(strpas(pchar(sym.value.valueptr)),[#0..#9,#11,#12,#14..#31,'''']),['"','\',#10,#13])+''''
  1307. else
  1308. st:='<constant string too long>';
  1309. end;
  1310. constord:
  1311. st:='i'+tostr(sym.value.valueord);
  1312. constpointer:
  1313. st:='i'+tostr(sym.value.valueordptr);
  1314. constreal:
  1315. begin
  1316. system.str(pbestreal(sym.value.valueptr)^,st);
  1317. st := 'r'+st;
  1318. end;
  1319. else
  1320. begin
  1321. { if we don't know just put zero !! }
  1322. st:='i0';
  1323. end;
  1324. end;
  1325. ss:=sym_stabstr_evaluate(sym,'"${name}:c=$1;",${N_FUNCTION},0,${line},0',[st]);
  1326. write_sym_stabstr(list,sym,ss);
  1327. end;
  1328. procedure TDebugInfoStabs.appendsym_type(list:TAsmList;sym:ttypesym);
  1329. var
  1330. ss : ansistring;
  1331. stabchar : string[2];
  1332. begin
  1333. ss:='';
  1334. if not assigned(sym.typedef) then
  1335. internalerror(200509262);
  1336. if sym.typedef.typ in tagtypes then
  1337. stabchar:='Tt'
  1338. else
  1339. stabchar:='t';
  1340. ss:=sym_stabstr_evaluate(sym,'"${name}:$1$2",${N_LSYM},0,${line},0',[stabchar,def_stab_number(sym.typedef)]);
  1341. write_sym_stabstr(list,sym,ss);
  1342. end;
  1343. procedure TDebugInfoStabs.appendsym_label(list:TAsmList;sym:tlabelsym);
  1344. var
  1345. ss : ansistring;
  1346. begin
  1347. ss:=sym_stabstr_evaluate(sym,'"${name}",${N_LSYM},0,${line},0',[]);
  1348. write_sym_stabstr(list,sym,ss);
  1349. end;
  1350. {****************************************************************************
  1351. Proc/Module support
  1352. ****************************************************************************}
  1353. procedure tdebuginfostabs.inserttypeinfo;
  1354. var
  1355. stabsvarlist,
  1356. stabstypelist : TAsmList;
  1357. storefilepos : tfileposinfo;
  1358. i : longint;
  1359. begin
  1360. storefilepos:=current_filepos;
  1361. current_filepos:=current_module.mainfilepos;
  1362. global_stab_number:=0;
  1363. defnumberlist:=TFPObjectlist.create(false);
  1364. stabsvarlist:=TAsmList.create;
  1365. stabstypelist:=TAsmList.create;
  1366. vardatadef:=trecorddef(search_system_type('TVARDATA').typedef);
  1367. { include symbol that will be referenced from the main to be sure to
  1368. include this debuginfo .o file }
  1369. current_module.flags:=current_module.flags or uf_has_stabs_debuginfo;
  1370. if not(target_info.system in systems_darwin) then
  1371. begin
  1372. new_section(current_asmdata.asmlists[al_stabs],sec_data,GetSymTableName(current_module.localsymtable),0);
  1373. current_asmdata.asmlists[al_stabs].concat(tai_symbol.Createname_global(make_mangledname('DEBUGINFO',current_module.localsymtable,''),AT_DATA,0));
  1374. end
  1375. else
  1376. new_section(current_asmdata.asmlists[al_stabs],sec_code,GetSymTableName(current_module.localsymtable),0);
  1377. { write all global/local variables. This will flag all required tdefs }
  1378. if assigned(current_module.globalsymtable) then
  1379. write_symtable_syms(stabsvarlist,current_module.globalsymtable);
  1380. if assigned(current_module.localsymtable) then
  1381. write_symtable_syms(stabsvarlist,current_module.localsymtable);
  1382. { write all procedures and methods. This will flag all required tdefs }
  1383. if assigned(current_module.globalsymtable) then
  1384. write_symtable_procdefs(stabsvarlist,current_module.globalsymtable);
  1385. if assigned(current_module.localsymtable) then
  1386. write_symtable_procdefs(stabsvarlist,current_module.localsymtable);
  1387. { reset unit type info flag }
  1388. reset_unit_type_info;
  1389. { write used types from the used units }
  1390. write_used_unit_type_info(stabstypelist,current_module);
  1391. { last write the types from this unit }
  1392. if assigned(current_module.globalsymtable) then
  1393. write_symtable_defs(stabstypelist,current_module.globalsymtable);
  1394. if assigned(current_module.localsymtable) then
  1395. write_symtable_defs(stabstypelist,current_module.localsymtable);
  1396. current_asmdata.asmlists[al_stabs].concatlist(stabstypelist);
  1397. current_asmdata.asmlists[al_stabs].concatlist(stabsvarlist);
  1398. { reset stab numbers }
  1399. for i:=0 to defnumberlist.count-1 do
  1400. begin
  1401. if assigned(defnumberlist[i]) then
  1402. begin
  1403. tdef(defnumberlist[i]).stab_number:=0;
  1404. tdef(defnumberlist[i]).dbg_state:=dbg_state_unused;
  1405. end;
  1406. end;
  1407. defnumberlist.free;
  1408. defnumberlist:=nil;
  1409. stabsvarlist.free;
  1410. stabstypelist.free;
  1411. current_filepos:=storefilepos;
  1412. end;
  1413. procedure tdebuginfostabs.insertlineinfo(list:TAsmList);
  1414. var
  1415. currfileinfo,
  1416. lastfileinfo : tfileposinfo;
  1417. currfuncname : pshortstring;
  1418. currsectype : TAsmSectiontype;
  1419. hlabel : tasmlabel;
  1420. hp : tai;
  1421. infile : tinputfile;
  1422. begin
  1423. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  1424. currfuncname:=nil;
  1425. currsectype:=sec_code;
  1426. hp:=Tai(list.first);
  1427. while assigned(hp) do
  1428. begin
  1429. case hp.typ of
  1430. ait_section :
  1431. currsectype:=tai_section(hp).sectype;
  1432. ait_function_name :
  1433. currfuncname:=tai_function_name(hp).funcname;
  1434. ait_force_line :
  1435. lastfileinfo.line:=-1;
  1436. end;
  1437. if (currsectype=sec_code) and
  1438. (hp.typ=ait_instruction) then
  1439. begin
  1440. currfileinfo:=tailineinfo(hp).fileinfo;
  1441. { file changed ? (must be before line info) }
  1442. if (currfileinfo.fileindex<>0) and
  1443. ((lastfileinfo.fileindex<>currfileinfo.fileindex) or
  1444. (lastfileinfo.moduleindex<>currfileinfo.moduleindex)) then
  1445. begin
  1446. infile:=get_module(currfileinfo.moduleindex).sourcefiles.get_file(currfileinfo.fileindex);
  1447. if assigned(infile) then
  1448. begin
  1449. current_asmdata.getlabel(hlabel,alt_dbgfile);
  1450. { emit stabs }
  1451. if not(ds_stabs_abs_include_files in current_settings.debugswitches) or
  1452. path_absolute(infile.path^) then
  1453. list.insertbefore(Tai_stab.Create_str(stab_stabs,'"'+BsToSlash(FixPath(infile.path^,false))+FixFileName(infile.name^)+'",'+tostr(n_includefile)+
  1454. ',0,0,'+hlabel.name),hp)
  1455. else
  1456. list.insertbefore(Tai_stab.Create_str(stab_stabs,'"'+BsToSlash(FixPath(getcurrentdir,false)+FixPath(infile.path^,false))+FixFileName(infile.name^)+'",'+tostr(n_includefile)+
  1457. ',0,0,'+hlabel.name),hp);
  1458. list.insertbefore(tai_label.create(hlabel),hp);
  1459. { force new line info }
  1460. lastfileinfo.line:=-1;
  1461. end;
  1462. end;
  1463. { line changed ? }
  1464. if (currfileinfo.line>lastfileinfo.line) and (currfileinfo.line<>0) then
  1465. begin
  1466. if assigned(currfuncname) and
  1467. not(af_stabs_use_function_absolute_addresses in target_asm.flags) then
  1468. begin
  1469. current_asmdata.getlabel(hlabel,alt_dbgline);
  1470. list.insertbefore(Tai_stab.Create_str(stab_stabn,tostr(n_textline)+',0,'+tostr(currfileinfo.line)+','+
  1471. hlabel.name+' - '+{$IFDEF POWERPC64}'.'+{$ENDIF POWERPC64}currfuncname^),hp);
  1472. list.insertbefore(tai_label.create(hlabel),hp);
  1473. end
  1474. else
  1475. list.insertbefore(Tai_stab.Create_str(stab_stabd,tostr(n_textline)+',0,'+tostr(currfileinfo.line)),hp);
  1476. end;
  1477. lastfileinfo:=currfileinfo;
  1478. end;
  1479. hp:=tai(hp.next);
  1480. end;
  1481. end;
  1482. procedure tdebuginfostabs.insertmoduleinfo;
  1483. var
  1484. hlabel : tasmlabel;
  1485. infile : tinputfile;
  1486. begin
  1487. { emit main source n_sourcefile for start of module }
  1488. current_asmdata.getlabel(hlabel,alt_dbgfile);
  1489. infile:=current_module.sourcefiles.get_file(1);
  1490. new_section(current_asmdata.asmlists[al_start],sec_code,make_mangledname('DEBUGSTART',current_module.localsymtable,''),0,secorder_begin);
  1491. if not(target_info.system in systems_darwin) then
  1492. current_asmdata.asmlists[al_start].concat(tai_symbol.Createname_global(make_mangledname('DEBUGSTART',current_module.localsymtable,''),AT_DATA,0));
  1493. current_asmdata.asmlists[al_start].concat(Tai_stab.Create_str(stab_stabs,'"'+BsToSlash(FixPath(getcurrentdir,false))+'",'+tostr(n_sourcefile)+
  1494. ',0,0,'+hlabel.name));
  1495. current_asmdata.asmlists[al_start].concat(Tai_stab.Create_str(stab_stabs,'"'+BsToSlash(FixPath(infile.path^,false))+FixFileName(infile.name^)+'",'+tostr(n_sourcefile)+
  1496. ',0,0,'+hlabel.name));
  1497. current_asmdata.asmlists[al_start].concat(tai_label.create(hlabel));
  1498. { for darwin, you need a "module marker" too to work around }
  1499. { either some assembler or gdb bug (radar 4386531 according to a }
  1500. { comment in dbxout.c of Apple's gcc) }
  1501. if (target_info.system in systems_darwin) then
  1502. current_asmdata.asmlists[al_end].concat(Tai_stab.Create_str(stab_stabs,'"",'+tostr(N_OSO)+',0,0,0'));
  1503. { emit empty n_sourcefile for end of module }
  1504. current_asmdata.getlabel(hlabel,alt_dbgfile);
  1505. new_section(current_asmdata.asmlists[al_end],sec_code,make_mangledname('DEBUGEND',current_module.localsymtable,''),0,secorder_end);
  1506. if not(target_info.system in systems_darwin) then
  1507. current_asmdata.asmlists[al_end].concat(tai_symbol.Createname_global(make_mangledname('DEBUGEND',current_module.localsymtable,''),AT_DATA,0));
  1508. current_asmdata.asmlists[al_end].concat(Tai_stab.Create_str(stab_stabs,'"",'+tostr(n_sourcefile)+',0,0,'+hlabel.name));
  1509. current_asmdata.asmlists[al_end].concat(tai_label.create(hlabel));
  1510. end;
  1511. procedure tdebuginfostabs.referencesections(list:TAsmList);
  1512. var
  1513. hp : tmodule;
  1514. dbgtable : tai_symbol;
  1515. begin
  1516. { Reference all DEBUGINFO sections from the main .fpc section }
  1517. if (target_info.system in ([system_powerpc_macos]+systems_darwin)) then
  1518. exit;
  1519. list.concat(Tai_section.create(sec_fpc,'links',0));
  1520. { make sure the debuginfo doesn't get stripped out }
  1521. if (target_info.system in systems_darwin) then
  1522. begin
  1523. dbgtable:=tai_symbol.createname('DEBUGINFOTABLE',AT_DATA,0);
  1524. list.concat(tai_directive.create(asd_no_dead_strip,dbgtable.sym.name));
  1525. list.concat(dbgtable);
  1526. end;
  1527. { include reference to all debuginfo sections of used units }
  1528. hp:=tmodule(loaded_units.first);
  1529. while assigned(hp) do
  1530. begin
  1531. If (hp.flags and uf_has_stabs_debuginfo)=uf_has_stabs_debuginfo then
  1532. begin
  1533. list.concat(Tai_const.Createname(make_mangledname('DEBUGINFO',hp.localsymtable,''),0));
  1534. list.concat(Tai_const.Createname(make_mangledname('DEBUGSTART',hp.localsymtable,''),0));
  1535. list.concat(Tai_const.Createname(make_mangledname('DEBUGEND',hp.localsymtable,''),0));
  1536. end;
  1537. hp:=tmodule(hp.next);
  1538. end;
  1539. end;
  1540. const
  1541. dbg_stabs_info : tdbginfo =
  1542. (
  1543. id : dbg_stabs;
  1544. idtxt : 'STABS';
  1545. );
  1546. initialization
  1547. RegisterDebugInfo(dbg_stabs_info,TDebugInfoStabs);
  1548. end.