dbgstabs.pas 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697
  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 useful 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 another
  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. ss:=def_stabstr_evaluate(def,'r$1;${savesize};0;',[def_stab_number(s32inttype)]);
  610. s64currency,
  611. s64comp:
  612. ss:=def_stabstr_evaluate(def,'r$1;-${savesize};0;',[def_stab_number(s32inttype)]);
  613. else
  614. internalerror(200509261);
  615. end;
  616. write_def_stabstr(list,def,ss);
  617. end;
  618. procedure TDebugInfoStabs.appenddef_file(list:TAsmList;def:tfiledef);
  619. var
  620. ss : ansistring;
  621. begin
  622. {$ifdef cpu64bitaddr}
  623. ss:=def_stabstr_evaluate(def,'s${savesize}HANDLE:$1,0,32;MODE:$1,32,32;RECSIZE:$2,64,64;'+
  624. '_PRIVATE:ar$1;1;64;$3,128,256;USERDATA:ar$1;1;16;$3,384,128;'+
  625. 'NAME:ar$1;0;255;$4,512,2048;;',[def_stab_number(s32inttype),
  626. def_stab_number(s64inttype),
  627. def_stab_number(u8inttype),
  628. def_stab_number(cchartype)]);
  629. {$else cpu64bitaddr}
  630. ss:=def_stabstr_evaluate(def,'s${savesize}HANDLE:$1,0,32;MODE:$1,32,32;RECSIZE:$1,64,32;'+
  631. '_PRIVATE:ar$1;1;32;$3,96,256;USERDATA:ar$1;1;16;$2,352,128;'+
  632. 'NAME:ar$1;0;255;$3,480,2048;;',[def_stab_number(s32inttype),
  633. def_stab_number(u8inttype),
  634. def_stab_number(cchartype)]);
  635. {$endif cpu64bitaddr}
  636. write_def_stabstr(list,def,ss);
  637. end;
  638. procedure TDebugInfoStabs.appenddef_record(list:TAsmList;def:trecorddef);
  639. var
  640. ss : ansistring;
  641. begin
  642. ss:='s'+tostr(def.size);
  643. def.symtable.SymList.ForEachCall(@field_add_stabstr,@ss);
  644. ss[length(ss)]:=';';
  645. write_def_stabstr(list,def,ss);
  646. end;
  647. procedure TDebugInfoStabs.appenddef_object(list:TAsmList;def:tobjectdef);
  648. procedure do_write_object(list:TAsmList;def:tobjectdef);
  649. var
  650. ss : ansistring;
  651. anc : tobjectdef;
  652. begin
  653. ss:='';
  654. { Write the invisible pointer for the class? }
  655. if (def.objecttype=odt_class) and
  656. (not def.writing_class_record_dbginfo) then
  657. begin
  658. ss:='*'+def_stab_classnumber(def);
  659. write_def_stabstr(list,def,ss);
  660. exit;
  661. end;
  662. ss:='s'+tostr(tobjecTSymtable(def.symtable).datasize);
  663. if assigned(def.childof) then
  664. begin
  665. {only one ancestor not virtual, public, at base offset 0 }
  666. { !1 , 0 2 0 , }
  667. ss:=ss+'!1,020,'+def_stab_classnumber(def.childof)+';';
  668. end;
  669. {virtual table to implement yet}
  670. def.symtable.symList.ForEachCall(@field_add_stabstr,@ss);
  671. if (oo_has_vmt in def.objectoptions) and
  672. (
  673. not assigned(def.childof) or
  674. not(oo_has_vmt in def.childof.objectoptions)
  675. ) then
  676. ss:=ss+'$vf'+def_stab_classnumber(def)+':'+def_stab_number(vmtarraytype)+','+tostr(def.vmt_offset*8)+';';
  677. def.symtable.symList.ForEachCall(@method_add_stabstr,@ss);
  678. if (oo_has_vmt in def.objectoptions) then
  679. begin
  680. anc := def;
  681. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  682. anc := anc.childof;
  683. { just in case anc = self }
  684. ss:=ss+';~%'+def_stab_classnumber(anc)+';';
  685. end
  686. else
  687. ss:=ss+';';
  688. write_def_stabstr(list,def,ss);
  689. end;
  690. var
  691. oldtypesym : tsym;
  692. begin
  693. { classes require special code to write the record and the invisible pointer }
  694. if is_class(def) then
  695. begin
  696. { Write the record class itself }
  697. tobjectdef(def).writing_class_record_dbginfo:=true;
  698. do_write_object(list,def);
  699. tobjectdef(def).writing_class_record_dbginfo:=false;
  700. { Write the invisible pointer class }
  701. oldtypesym:=def.typesym;
  702. def.typesym:=nil;
  703. do_write_object(list,def);
  704. def.typesym:=oldtypesym;
  705. end
  706. else
  707. do_write_object(list,def);
  708. { VMT symbol }
  709. if (oo_has_vmt in tobjectdef(def).objectoptions) and
  710. assigned(def.owner) and
  711. assigned(def.owner.name) then
  712. list.concat(Tai_stab.create(stab_stabs,strpnew('"vmt_'+GetSymTableName(def.owner)+tobjectdef(def).objname^+':S'+
  713. def_stab_number(vmttype)+'",'+tostr(N_STSYM)+',0,0,'+tobjectdef(def).vmt_mangledname)));
  714. end;
  715. procedure TDebugInfoStabs.appenddef_variant(list:TAsmList;def:tvariantdef);
  716. var
  717. ss : ansistring;
  718. begin
  719. ss:='s'+tostr(vardatadef.size);
  720. vardatadef.symtable.SymList.ForEachCall(@field_add_stabstr,@ss);
  721. ss[length(ss)]:=';';
  722. write_def_stabstr(list,def,ss);
  723. end;
  724. procedure TDebugInfoStabs.appenddef_pointer(list:TAsmList;def:tpointerdef);
  725. var
  726. ss : ansistring;
  727. begin
  728. ss:='*'+def_stab_number(tpointerdef(def).pointeddef);
  729. write_def_stabstr(list,def,ss);
  730. end;
  731. procedure TDebugInfoStabs.appenddef_set(list:TAsmList;def:tsetdef);
  732. var
  733. st,
  734. ss : ansistring;
  735. p: pchar;
  736. elementdefstabnr: string;
  737. begin
  738. { ugly hack: create a temporary subrange type if the lower bound of
  739. the set's element type is not a multiple of 8 (because we store them
  740. as if the lower bound is a multiple of 8) }
  741. if (def.setbase<>get_min_value(def.elementdef)) then
  742. begin
  743. { allocate a def number }
  744. inc(global_stab_number);
  745. elementdefstabnr:=tostr(global_stab_number);
  746. { anonymous subrange def }
  747. st:='":t'+elementdefstabnr+'=';
  748. if (def.elementdef.typ = enumdef) then
  749. st:=st+get_enum_defstr(tenumdef(def.elementdef),def.setbase)
  750. else
  751. st:=st+def_stabstr_evaluate(def.elementdef,'r'+elementdefstabnr+';$1;$2;',[tostr(longint(def.setbase)),tostr(longint(get_max_value(def.elementdef).svalue))]);
  752. st:=st+'",'+tostr(N_LSYM)+',0,0,0';
  753. { add to list }
  754. getmem(p,length(st)+1);
  755. move(pchar(st)^,p^,length(st)+1);
  756. list.concat(Tai_stab.create(stab_stabs,p));
  757. end
  758. else
  759. elementdefstabnr:=def_stab_number(def.elementdef);
  760. ss:=def_stabstr_evaluate(def,'@s$1;S$2',[tostr(def.size*8),elementdefstabnr]);
  761. write_def_stabstr(list,def,ss);
  762. end;
  763. procedure TDebugInfoStabs.appenddef_formal(list:TAsmList;def:tformaldef);
  764. var
  765. ss : ansistring;
  766. begin
  767. ss:=def_stabstr_evaluate(def,'${numberstring};',[]);
  768. write_def_stabstr(list,def,ss);
  769. end;
  770. procedure TDebugInfoStabs.appenddef_array(list:TAsmList;def:tarraydef);
  771. var
  772. tempstr: shortstring;
  773. ss : ansistring;
  774. begin
  775. if not is_packed_array(def) then
  776. begin
  777. tempstr:='ar$1;$2;$3;$4';
  778. if is_dynamic_array(def) then
  779. tempstr:='*'+tempstr;
  780. ss:=def_stabstr_evaluate(def,tempstr,[def_stab_number(tarraydef(def).rangedef),
  781. tostr(tarraydef(def).lowrange),tostr(tarraydef(def).highrange),def_stab_number(tarraydef(def).elementdef)])
  782. end
  783. else
  784. begin
  785. // the @P seems to be ignored by gdb
  786. tempstr:=def_stabstr_evaluate(tarraydef(def).rangedef,'r${numberstring};$1;$2;',
  787. [tostr(tarraydef(def).lowrange),tostr(tarraydef(def).highrange)]);
  788. // will only show highrange-lowrange+1 bits in gdb
  789. ss:=def_stabstr_evaluate(def,'@s$1;@S;S$2',
  790. [tostr(TConstExprInt(tarraydef(def).elepackedbitsize) * tarraydef(def).elecount),tempstr]);
  791. end;
  792. write_def_stabstr(list,def,ss);
  793. end;
  794. procedure TDebugInfoStabs.appenddef_procvar(list:TAsmList;def:tprocvardef);
  795. var
  796. ss : ansistring;
  797. begin
  798. ss:='*f'+def_stab_number(tprocvardef(def).returndef);
  799. write_def_stabstr(list,def,ss);
  800. end;
  801. procedure TDebugInfoStabs.appenddef_undefined(list:TAsmList;def:tundefineddef);
  802. var
  803. ss : ansistring;
  804. begin
  805. ss:=def_stabstr_evaluate(def,'${numberstring};',[]);
  806. write_def_stabstr(list,def,ss);
  807. end;
  808. procedure TDebugInfoStabs.beforeappenddef(list:TAsmList;def:tdef);
  809. var
  810. anc : tobjectdef;
  811. i : longint;
  812. begin
  813. { write dependencies first }
  814. case def.typ of
  815. stringdef :
  816. begin
  817. if tstringdef(def).stringtype in [st_widestring,st_unicodestring] then
  818. appenddef(list,cwidechartype)
  819. else
  820. begin
  821. appenddef(list,cchartype);
  822. appenddef(list,u8inttype);
  823. end;
  824. end;
  825. floatdef :
  826. appenddef(list,s32inttype);
  827. filedef :
  828. begin
  829. appenddef(list,s32inttype);
  830. {$ifdef cpu64bitaddr}
  831. appenddef(list,s64inttype);
  832. {$endif cpu64bitaddr}
  833. appenddef(list,u8inttype);
  834. appenddef(list,cchartype);
  835. end;
  836. classrefdef :
  837. appenddef(list,pvmttype);
  838. pointerdef :
  839. appenddef(list,tpointerdef(def).pointeddef);
  840. setdef :
  841. appenddef(list,tsetdef(def).elementdef);
  842. procvardef :
  843. begin
  844. appenddef(list,tprocvardef(def).returndef);
  845. if assigned(tprocvardef(def).parast) then
  846. write_symtable_defs(list,tprocvardef(def).parast);
  847. end;
  848. procdef :
  849. begin
  850. appenddef(list,tprocdef(def).returndef);
  851. if assigned(tprocdef(def).parast) then
  852. write_symtable_defs(list,tprocdef(def).parast);
  853. if assigned(tprocdef(def).localst) and
  854. (tprocdef(def).localst.symtabletype=localsymtable) then
  855. write_symtable_defs(list,tprocdef(def).localst);
  856. end;
  857. arraydef :
  858. begin
  859. appenddef(list,tarraydef(def).rangedef);
  860. appenddef(list,tarraydef(def).elementdef);
  861. end;
  862. recorddef :
  863. trecorddef(def).symtable.symList.ForEachCall(@field_write_defs,list);
  864. enumdef :
  865. if assigned(tenumdef(def).basedef) then
  866. appenddef(list,tenumdef(def).basedef);
  867. objectdef :
  868. begin
  869. { make sure we don't write child classdefs before their parent }
  870. { classdefs, because this crashes gdb }
  871. anc:=tobjectdef(def);
  872. while assigned(anc.childof) do
  873. begin
  874. anc:=anc.childof;
  875. if (anc.dbg_state=dbg_state_writing) then
  876. { happens in case a field of a parent is of the (forward }
  877. { defined) child type }
  878. begin
  879. { We don't explicitly requeue it, but the fact that }
  880. { a child type was used in a parent before the child }
  881. { type was fully defined means that it was forward }
  882. { declared, and will still be encountered later (it }
  883. { cannot have been declared in another unit, because }
  884. { then this and that other unit would depend on }
  885. { eachother's interface) }
  886. { Setting the state to queued however allows us to }
  887. { get the def number already without an IE }
  888. def.dbg_state:=dbg_state_queued;
  889. exit;
  890. end;
  891. end;
  892. appenddef(list,vmtarraytype);
  893. if assigned(tobjectdef(def).ImplementedInterfaces) then
  894. for i:=0 to tobjectdef(def).ImplementedInterfaces.Count-1 do
  895. appenddef(list,TImplementedInterface(tobjectdef(def).ImplementedInterfaces[i]).IntfDef);
  896. { first the parents }
  897. anc:=tobjectdef(def);
  898. while assigned(anc.childof) do
  899. begin
  900. anc:=anc.childof;
  901. appenddef(list,anc);
  902. if assigned(anc.ImplementedInterfaces) then
  903. for i:=0 to anc.ImplementedInterfaces.Count-1 do
  904. appenddef(list,TImplementedInterface(anc.ImplementedInterfaces[i]).IntfDef);
  905. end;
  906. tobjectdef(def).symtable.symList.ForEachCall(@field_write_defs,list);
  907. end;
  908. end;
  909. end;
  910. procedure TDebugInfoStabs.appendprocdef(list:TAsmList;def:tprocdef);
  911. var
  912. templist : TAsmList;
  913. stabsendlabel : tasmlabel;
  914. p : pchar;
  915. RType : Char;
  916. Obj,Info : String;
  917. hs : string;
  918. ss : ansistring;
  919. begin
  920. if not assigned(def.procstarttai) then
  921. exit;
  922. { mark as used so the local type defs also be written }
  923. def.dbg_state:=dbg_state_used;
  924. templist:=TAsmList.create;
  925. { end of procedure }
  926. current_asmdata.getlabel(stabsendlabel,alt_dbgtype);
  927. if assigned(def.funcretsym) and
  928. (tabstractnormalvarsym(def.funcretsym).refs>0) then
  929. begin
  930. if tabstractnormalvarsym(def.funcretsym).localloc.loc=LOC_REFERENCE then
  931. begin
  932. { TODO: Need to add gdb support for ret in param register calling}
  933. if paramanager.ret_in_param(def.returndef,def.proccalloption) then
  934. hs:='X*'
  935. else
  936. hs:='X';
  937. templist.concat(Tai_stab.create(stab_stabs,strpnew(
  938. '"'+GetSymName(def.procsym)+':'+hs+def_stab_number(def.returndef)+'",'+
  939. tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(def.funcretsym).localloc.reference.offset))));
  940. if (m_result in current_settings.modeswitches) then
  941. templist.concat(Tai_stab.create(stab_stabs,strpnew(
  942. '"RESULT:'+hs+def_stab_number(def.returndef)+'",'+
  943. tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(def.funcretsym).localloc.reference.offset))));
  944. end;
  945. end;
  946. // LBRAC
  947. ss:=tostr(N_LBRAC)+',0,0,';
  948. if target_info.cpu=cpu_powerpc64 then
  949. ss:=ss+'.';
  950. ss:=ss+def.mangledname;
  951. if (tf_use_function_relative_addresses in target_info.flags) then
  952. begin
  953. ss:=ss+'-';
  954. if target_info.cpu=cpu_powerpc64 then
  955. ss:=ss+'.';
  956. ss:=ss+def.mangledname;
  957. end;
  958. getmem(p,length(ss)+1);
  959. move(pchar(ss)^,p^,length(ss)+1);
  960. templist.concat(Tai_stab.Create(stab_stabn,p));
  961. // RBRAC
  962. ss:=tostr(N_RBRAC)+',0,0,'+stabsendlabel.name;
  963. if (tf_use_function_relative_addresses in target_info.flags) then
  964. begin
  965. ss:=ss+'-';
  966. if target_info.cpu=cpu_powerpc64 then
  967. ss:=ss+'.';
  968. ss:=ss+def.mangledname;
  969. end;
  970. getmem(p,length(ss)+1);
  971. move(pchar(ss)^,p^,length(ss)+1);
  972. templist.concat(Tai_stab.Create(stab_stabn,p));
  973. { the stabsendlabel must come after all other stabs for this }
  974. { function }
  975. templist.concat(tai_label.create(stabsendlabel));
  976. { Add a "size" stab as described in the last paragraph of 2.5 at }
  977. { http://sourceware.org/gdb/current/onlinedocs/stabs_2.html#SEC12 }
  978. { This works at least on Darwin (and is needed on Darwin to get }
  979. { correct smartlinking of stabs), but I don't know which binutils }
  980. { version is required on other platforms }
  981. { This stab must come after all other stabs for the procedure, }
  982. { including the LBRAC/RBRAC ones }
  983. if (target_info.system in systems_darwin) then
  984. templist.concat(Tai_stab.create(stab_stabs,
  985. strpnew('"",'+tostr(N_FUNCTION)+',0,0,'+stabsendlabel.name+'-'+def.mangledname)));
  986. current_asmdata.asmlists[al_procedures].insertlistafter(def.procendtai,templist);
  987. { "The stab representing a procedure is located immediately
  988. following the code of the procedure. This stab is in turn
  989. directly followed by a group of other stabs describing
  990. elements of the procedure. These other stabs describe the
  991. procedure's parameters, its block local variables, and its
  992. block structure." (stab docs) }
  993. { this is however incorrect in case "include source" statements }
  994. { appear in the block, in that case the procedure stab must }
  995. { appear before this include stabs (and we generate such an }
  996. { stabs for all functions) (JM) }
  997. { FUNC stabs }
  998. obj := GetSymName(def.procsym);
  999. info := '';
  1000. if (po_global in def.procoptions) then
  1001. RType := 'F'
  1002. else
  1003. RType := 'f';
  1004. if assigned(def.owner) then
  1005. begin
  1006. if (def.owner.symtabletype = objecTSymtable) then
  1007. obj := GetSymTableName(def.owner)+'__'+GetSymName(def.procsym);
  1008. if not(cs_gdb_valgrind in current_settings.globalswitches) and
  1009. (def.owner.symtabletype=localsymtable) and
  1010. assigned(def.owner.defowner) and
  1011. assigned(tprocdef(def.owner.defowner).procsym) then
  1012. info := ','+GetSymName(def.procsym)+','+GetSymName(tprocdef(def.owner.defowner).procsym);
  1013. end;
  1014. ss:='"'+ansistring(obj)+':'+RType+def_stab_number(def.returndef)+info+'",'+tostr(n_function)+',0,'+tostr(def.fileinfo.line)+','+ansistring(def.mangledname);
  1015. getmem(p,length(ss)+1);
  1016. move(pchar(ss)^,p^,length(ss)+1);
  1017. templist.concat(Tai_stab.Create(stab_stabs,p));
  1018. current_asmdata.asmlists[al_procedures].insertlistbefore(def.procstarttai,templist);
  1019. { para types }
  1020. if assigned(def.parast) then
  1021. write_symtable_syms(templist,def.parast);
  1022. { local type defs and vars should not be written
  1023. inside the main proc stab }
  1024. if assigned(def.localst) and
  1025. (def.localst.symtabletype=localsymtable) then
  1026. write_symtable_syms(templist,def.localst);
  1027. current_asmdata.asmlists[al_procedures].insertlistbefore(def.procstarttai,templist);
  1028. templist.free;
  1029. end;
  1030. {****************************************************************************
  1031. TSym support
  1032. ****************************************************************************}
  1033. function TDebugInfoStabs.sym_var_value(const s:string;arg:pointer):string;
  1034. var
  1035. sym : tsym absolute arg;
  1036. begin
  1037. result:='';
  1038. if s='name' then
  1039. result:=GetSymName(sym)
  1040. else if s='mangledname' then
  1041. result:=sym.mangledname
  1042. else if s='ownername' then
  1043. result:=GetSymTableName(sym.owner)
  1044. else if s='line' then
  1045. result:=tostr(sym.fileinfo.line)
  1046. else if s='N_LSYM' then
  1047. result:=tostr(N_LSYM)
  1048. else if s='N_LCSYM' then
  1049. result:=tostr(N_LCSYM)
  1050. else if s='N_RSYM' then
  1051. result:=tostr(N_RSYM)
  1052. else if s='N_TSYM' then
  1053. result:=tostr(N_TSYM)
  1054. else if s='N_STSYM' then
  1055. result:=tostr(N_STSYM)
  1056. else if s='N_FUNCTION' then
  1057. result:=tostr(N_FUNCTION)
  1058. else
  1059. internalerror(200401152);
  1060. end;
  1061. function TDebugInfoStabs.sym_stabstr_evaluate(sym:tsym;const s:string;const vars:array of string):ansistring;
  1062. begin
  1063. result:=string_evaluate(s,@sym_var_value,sym,vars);
  1064. end;
  1065. procedure TDebugInfoStabs.write_sym_stabstr(list:TAsmList;sym:tsym;const ss:ansistring);
  1066. var
  1067. p : pchar;
  1068. begin
  1069. if ss='' then
  1070. exit;
  1071. { add to list }
  1072. getmem(p,length(ss)+1);
  1073. move(pchar(ss)^,p^,length(ss)+1);
  1074. list.concat(Tai_stab.create(stab_stabs,p));
  1075. end;
  1076. procedure TDebugInfoStabs.appendsym_fieldvar(list:TAsmList;sym:tfieldvarsym);
  1077. var
  1078. ss : ansistring;
  1079. begin
  1080. ss:='';
  1081. if (sym.owner.symtabletype=objecTSymtable) and
  1082. (sp_static in sym.symoptions) then
  1083. ss:=sym_stabstr_evaluate(sym,'"${ownername}__${name}:S$1",${N_LCSYM},0,${line},${mangledname}',
  1084. [def_stab_number(sym.vardef)]);
  1085. write_sym_stabstr(list,sym,ss);
  1086. end;
  1087. procedure TDebugInfoStabs.appendsym_staticvar(list:TAsmList;sym:tstaticvarsym);
  1088. var
  1089. ss : ansistring;
  1090. st : string;
  1091. threadvaroffset : string;
  1092. regidx : Tregisterindex;
  1093. nsym : string[7];
  1094. begin
  1095. { external symbols can't be resolved at link time, so we
  1096. can't generate stabs for them }
  1097. if vo_is_external in sym.varoptions then
  1098. exit;
  1099. ss:='';
  1100. st:=def_stab_number(sym.vardef);
  1101. case sym.localloc.loc of
  1102. LOC_REGISTER,
  1103. LOC_CREGISTER,
  1104. LOC_MMREGISTER,
  1105. LOC_CMMREGISTER,
  1106. LOC_FPUREGISTER,
  1107. LOC_CFPUREGISTER :
  1108. begin
  1109. regidx:=findreg_by_number(sym.localloc.register);
  1110. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1111. { this is the register order for GDB}
  1112. if regidx<>0 then
  1113. ss:=sym_stabstr_evaluate(sym,'"${name}:r$1",${N_RSYM},0,${line},$2',[st,tostr(regstabs_table[regidx])]);
  1114. end;
  1115. else
  1116. begin
  1117. if (vo_is_thread_var in sym.varoptions) then
  1118. threadvaroffset:='+'+tostr(sizeof(pint))
  1119. else
  1120. threadvaroffset:='';
  1121. if (vo_is_typed_const in sym.varoptions) then
  1122. nsym:='N_STSYM'
  1123. else
  1124. nsym:='N_LCSYM';
  1125. { Here we used S instead of
  1126. because with G GDB doesn't look at the address field
  1127. but searches the same name or with a leading underscore
  1128. but these names don't exist in pascal !}
  1129. st:='S'+st;
  1130. ss:=sym_stabstr_evaluate(sym,'"${name}:$1",${'+nsym+'},0,${line},${mangledname}$2',[st,threadvaroffset]);
  1131. end;
  1132. end;
  1133. write_sym_stabstr(list,sym,ss);
  1134. end;
  1135. procedure TDebugInfoStabs.appendsym_localvar(list:TAsmList;sym:tlocalvarsym);
  1136. var
  1137. ss : ansistring;
  1138. st : string;
  1139. regidx : Tregisterindex;
  1140. begin
  1141. { There is no space allocated for not referenced locals }
  1142. if (sym.owner.symtabletype=localsymtable) and (sym.refs=0) then
  1143. exit;
  1144. ss:='';
  1145. st:=def_stab_number(sym.vardef);
  1146. case sym.localloc.loc of
  1147. LOC_REGISTER,
  1148. LOC_CREGISTER,
  1149. LOC_MMREGISTER,
  1150. LOC_CMMREGISTER,
  1151. LOC_FPUREGISTER,
  1152. LOC_CFPUREGISTER :
  1153. begin
  1154. regidx:=findreg_by_number(sym.localloc.register);
  1155. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1156. { this is the register order for GDB}
  1157. if regidx<>0 then
  1158. ss:=sym_stabstr_evaluate(sym,'"${name}:r$1",${N_RSYM},0,${line},$2',[st,tostr(regstabs_table[regidx])]);
  1159. end;
  1160. LOC_REFERENCE :
  1161. { offset to ebp => will not work if the framepointer is esp
  1162. so some optimizing will make things harder to debug }
  1163. ss:=sym_stabstr_evaluate(sym,'"${name}:$1",${N_TSYM},0,${line},$2',[st,tostr(sym.localloc.reference.offset)])
  1164. else
  1165. internalerror(2003091814);
  1166. end;
  1167. write_sym_stabstr(list,sym,ss);
  1168. end;
  1169. function TDebugInfoStabs.get_appendsym_paravar_reg(sym:tparavarsym;const typ,stabstr:string;reg: tregister): ansistring;
  1170. var
  1171. ltyp: string[1];
  1172. regidx : Tregisterindex;
  1173. begin
  1174. result:='';
  1175. if typ='p' then
  1176. ltyp:='R'
  1177. else
  1178. ltyp:='a';
  1179. regidx:=findreg_by_number(reg);
  1180. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1181. { this is the register order for GDB}
  1182. if regidx<>0 then
  1183. result:=sym_stabstr_evaluate(sym,'"${name}:$1",${N_RSYM},0,${line},$2',[ltyp+stabstr,tostr(longint(regstabs_table[regidx]))]);
  1184. end;
  1185. procedure TDebugInfoStabs.appendsym_paravar(list:TAsmList;sym:tparavarsym);
  1186. var
  1187. ss : ansistring;
  1188. c : string[1];
  1189. st : string;
  1190. regidx : Tregisterindex;
  1191. begin
  1192. ss:='';
  1193. { set loc to LOC_REFERENCE to get somewhat usable debugging info for -Or }
  1194. { while stabs aren't adapted for regvars yet }
  1195. if (vo_is_self in sym.varoptions) then
  1196. begin
  1197. case sym.localloc.loc of
  1198. LOC_REGISTER,
  1199. LOC_CREGISTER:
  1200. regidx:=findreg_by_number(sym.localloc.register);
  1201. LOC_REFERENCE: ;
  1202. else
  1203. internalerror(2003091815);
  1204. end;
  1205. if (po_classmethod in tabstractprocdef(sym.owner.defowner).procoptions) or
  1206. (po_staticmethod in tabstractprocdef(sym.owner.defowner).procoptions) then
  1207. begin
  1208. if (sym.localloc.loc=LOC_REFERENCE) then
  1209. ss:=sym_stabstr_evaluate(sym,'"pvmt:p$1",${N_TSYM},0,0,$2',
  1210. [def_stab_number(pvmttype),tostr(sym.localloc.reference.offset)])
  1211. else
  1212. begin
  1213. regidx:=findreg_by_number(sym.localloc.register);
  1214. ss:=sym_stabstr_evaluate(sym,'"pvmt:r$1",${N_RSYM},0,0,$2',
  1215. [def_stab_number(pvmttype),tostr(regstabs_table[regidx])]);
  1216. end
  1217. end
  1218. else
  1219. begin
  1220. if not(is_class(tprocdef(sym.owner.defowner)._class)) then
  1221. c:='v'
  1222. else
  1223. c:='p';
  1224. if (sym.localloc.loc=LOC_REFERENCE) then
  1225. ss:=sym_stabstr_evaluate(sym,'"$$t:$1",${N_TSYM},0,0,$2',
  1226. [c+def_stab_number(tprocdef(sym.owner.defowner)._class),tostr(sym.localloc.reference.offset)])
  1227. else
  1228. begin
  1229. regidx:=findreg_by_number(sym.localloc.register);
  1230. ss:=sym_stabstr_evaluate(sym,'"$$t:r$1",${N_RSYM},0,0,$2',
  1231. [c+def_stab_number(tprocdef(sym.owner.defowner)._class),tostr(regstabs_table[regidx])]);
  1232. end
  1233. end;
  1234. end
  1235. else
  1236. begin
  1237. st:=def_stab_number(sym.vardef);
  1238. if paramanager.push_addr_param(sym.varspez,sym.vardef,tprocdef(sym.owner.defowner).proccalloption) and
  1239. not(vo_has_local_copy in sym.varoptions) and
  1240. not is_open_string(sym.vardef) then
  1241. c:='v' { should be 'i' but 'i' doesn't work }
  1242. else
  1243. c:='p';
  1244. case sym.localloc.loc of
  1245. LOC_REGISTER,
  1246. LOC_CREGISTER,
  1247. LOC_MMREGISTER,
  1248. LOC_CMMREGISTER,
  1249. LOC_FPUREGISTER,
  1250. LOC_CFPUREGISTER :
  1251. begin
  1252. ss:=get_appendsym_paravar_reg(sym,c,st,sym.localloc.register);
  1253. end;
  1254. LOC_REFERENCE :
  1255. begin
  1256. { When the *value* of a parameter (so not its address!) is
  1257. copied into a local variable, you have to generate two
  1258. stabs: one for the parmeter, and one for the local copy.
  1259. Not doing this breaks debugging under e.g. SPARC. Doc:
  1260. http://sourceware.org/gdb/current/onlinedocs/stabs_4.html#SEC26
  1261. }
  1262. if (c='p') and
  1263. not is_open_string(sym.vardef) and
  1264. ((sym.paraloc[calleeside].location^.loc<>sym.localloc.loc) or
  1265. ((sym.localloc.loc in [LOC_REFERENCE,LOC_CREFERENCE]) and
  1266. ((sym.paraloc[calleeside].location^.reference.index<>sym.localloc.reference.base) or
  1267. (sym.paraloc[calleeside].location^.reference.offset<>sym.localloc.reference.offset))) or
  1268. ((sym.localloc.loc in [LOC_REGISTER,LOC_CREGISTER,LOC_MMREGISTER,LOC_CMMREGISTER,LOC_FPUREGISTER,LOC_CFPUREGISTER]) and
  1269. (sym.localloc.register<>sym.paraloc[calleeside].location^.register))) then
  1270. begin
  1271. if not(sym.paraloc[calleeside].location^.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  1272. ss:=get_appendsym_paravar_reg(sym,c,st,sym.paraloc[calleeside].location^.register)
  1273. else
  1274. ss:=sym_stabstr_evaluate(sym,'"${name}:$1",${N_TSYM},0,${line},$2',[c+st,tostr(sym.paraloc[calleeside].location^.reference.offset)]);
  1275. write_sym_stabstr(list,sym,ss);
  1276. { second stab has no parameter specifier }
  1277. c:='';
  1278. end;
  1279. { offset to ebp => will not work if the framepointer is esp
  1280. so some optimizing will make things harder to debug }
  1281. ss:=sym_stabstr_evaluate(sym,'"${name}:$1",${N_TSYM},0,${line},$2',[c+st,tostr(sym.localloc.reference.offset)])
  1282. end;
  1283. else
  1284. internalerror(2003091814);
  1285. end;
  1286. end;
  1287. write_sym_stabstr(list,sym,ss);
  1288. end;
  1289. procedure TDebugInfoStabs.appendsym_const(list:TAsmList;sym:tconstsym);
  1290. var
  1291. st : string;
  1292. ss : ansistring;
  1293. begin
  1294. ss:='';
  1295. { Don't write info for default parameter values, the N_Func breaks
  1296. the N_Func for the function itself.
  1297. Valgrind does not support constants }
  1298. if (sym.owner.symtabletype=parasymtable) or
  1299. (cs_gdb_valgrind in current_settings.globalswitches) then
  1300. exit;
  1301. case sym.consttyp of
  1302. conststring:
  1303. begin
  1304. if sym.value.len<200 then
  1305. st:='s'''+backspace_quote(octal_quote(strpas(pchar(sym.value.valueptr)),[#0..#9,#11,#12,#14..#31,'''']),['"','\',#10,#13])+''''
  1306. else
  1307. st:='<constant string too long>';
  1308. end;
  1309. constord:
  1310. st:='i'+tostr(sym.value.valueord);
  1311. constpointer:
  1312. st:='i'+tostr(sym.value.valueordptr);
  1313. constreal:
  1314. begin
  1315. system.str(pbestreal(sym.value.valueptr)^,st);
  1316. st := 'r'+st;
  1317. end;
  1318. else
  1319. begin
  1320. { if we don't know just put zero !! }
  1321. st:='i0';
  1322. end;
  1323. end;
  1324. ss:=sym_stabstr_evaluate(sym,'"${name}:c=$1;",${N_FUNCTION},0,${line},0',[st]);
  1325. write_sym_stabstr(list,sym,ss);
  1326. end;
  1327. procedure TDebugInfoStabs.appendsym_type(list:TAsmList;sym:ttypesym);
  1328. var
  1329. ss : ansistring;
  1330. stabchar : string[2];
  1331. begin
  1332. ss:='';
  1333. if not assigned(sym.typedef) then
  1334. internalerror(200509262);
  1335. if sym.typedef.typ in tagtypes then
  1336. stabchar:='Tt'
  1337. else
  1338. stabchar:='t';
  1339. ss:=sym_stabstr_evaluate(sym,'"${name}:$1$2",${N_LSYM},0,${line},0',[stabchar,def_stab_number(sym.typedef)]);
  1340. write_sym_stabstr(list,sym,ss);
  1341. end;
  1342. procedure TDebugInfoStabs.appendsym_label(list:TAsmList;sym:tlabelsym);
  1343. var
  1344. ss : ansistring;
  1345. begin
  1346. ss:=sym_stabstr_evaluate(sym,'"${name}",${N_LSYM},0,${line},0',[]);
  1347. write_sym_stabstr(list,sym,ss);
  1348. end;
  1349. {****************************************************************************
  1350. Proc/Module support
  1351. ****************************************************************************}
  1352. procedure tdebuginfostabs.inserttypeinfo;
  1353. var
  1354. stabsvarlist,
  1355. stabstypelist : TAsmList;
  1356. storefilepos : tfileposinfo;
  1357. i : longint;
  1358. begin
  1359. storefilepos:=current_filepos;
  1360. current_filepos:=current_module.mainfilepos;
  1361. global_stab_number:=0;
  1362. defnumberlist:=TFPObjectlist.create(false);
  1363. stabsvarlist:=TAsmList.create;
  1364. stabstypelist:=TAsmList.create;
  1365. vardatadef:=trecorddef(search_system_type('TVARDATA').typedef);
  1366. { include symbol that will be referenced from the main to be sure to
  1367. include this debuginfo .o file }
  1368. current_module.flags:=current_module.flags or uf_has_stabs_debuginfo;
  1369. if not(target_info.system in systems_darwin) then
  1370. begin
  1371. new_section(current_asmdata.asmlists[al_stabs],sec_data,GetSymTableName(current_module.localsymtable),0);
  1372. current_asmdata.asmlists[al_stabs].concat(tai_symbol.Createname_global(make_mangledname('DEBUGINFO',current_module.localsymtable,''),AT_DATA,0));
  1373. end
  1374. else
  1375. new_section(current_asmdata.asmlists[al_stabs],sec_code,GetSymTableName(current_module.localsymtable),0);
  1376. { write all global/local variables. This will flag all required tdefs }
  1377. if assigned(current_module.globalsymtable) then
  1378. write_symtable_syms(stabsvarlist,current_module.globalsymtable);
  1379. if assigned(current_module.localsymtable) then
  1380. write_symtable_syms(stabsvarlist,current_module.localsymtable);
  1381. { write all procedures and methods. This will flag all required tdefs }
  1382. if assigned(current_module.globalsymtable) then
  1383. write_symtable_procdefs(stabsvarlist,current_module.globalsymtable);
  1384. if assigned(current_module.localsymtable) then
  1385. write_symtable_procdefs(stabsvarlist,current_module.localsymtable);
  1386. { reset unit type info flag }
  1387. reset_unit_type_info;
  1388. { write used types from the used units }
  1389. write_used_unit_type_info(stabstypelist,current_module);
  1390. { last write the types from this unit }
  1391. if assigned(current_module.globalsymtable) then
  1392. write_symtable_defs(stabstypelist,current_module.globalsymtable);
  1393. if assigned(current_module.localsymtable) then
  1394. write_symtable_defs(stabstypelist,current_module.localsymtable);
  1395. current_asmdata.asmlists[al_stabs].concatlist(stabstypelist);
  1396. current_asmdata.asmlists[al_stabs].concatlist(stabsvarlist);
  1397. { reset stab numbers }
  1398. for i:=0 to defnumberlist.count-1 do
  1399. begin
  1400. if assigned(defnumberlist[i]) then
  1401. begin
  1402. tdef(defnumberlist[i]).stab_number:=0;
  1403. tdef(defnumberlist[i]).dbg_state:=dbg_state_unused;
  1404. end;
  1405. end;
  1406. defnumberlist.free;
  1407. defnumberlist:=nil;
  1408. stabsvarlist.free;
  1409. stabstypelist.free;
  1410. current_filepos:=storefilepos;
  1411. end;
  1412. procedure tdebuginfostabs.insertlineinfo(list:TAsmList);
  1413. var
  1414. currfileinfo,
  1415. lastfileinfo : tfileposinfo;
  1416. currfuncname : pshortstring;
  1417. currsectype : TAsmSectiontype;
  1418. hlabel : tasmlabel;
  1419. hp : tai;
  1420. infile : tinputfile;
  1421. begin
  1422. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  1423. currfuncname:=nil;
  1424. currsectype:=sec_code;
  1425. hp:=Tai(list.first);
  1426. while assigned(hp) do
  1427. begin
  1428. case hp.typ of
  1429. ait_section :
  1430. currsectype:=tai_section(hp).sectype;
  1431. ait_function_name :
  1432. currfuncname:=tai_function_name(hp).funcname;
  1433. ait_force_line :
  1434. lastfileinfo.line:=-1;
  1435. end;
  1436. if (currsectype=sec_code) and
  1437. (hp.typ=ait_instruction) then
  1438. begin
  1439. currfileinfo:=tailineinfo(hp).fileinfo;
  1440. { file changed ? (must be before line info) }
  1441. if (currfileinfo.fileindex<>0) and
  1442. ((lastfileinfo.fileindex<>currfileinfo.fileindex) or
  1443. (lastfileinfo.moduleindex<>currfileinfo.moduleindex)) then
  1444. begin
  1445. infile:=get_module(currfileinfo.moduleindex).sourcefiles.get_file(currfileinfo.fileindex);
  1446. if assigned(infile) then
  1447. begin
  1448. current_asmdata.getlabel(hlabel,alt_dbgfile);
  1449. { emit stabs }
  1450. if not(ds_stabs_abs_include_files in current_settings.debugswitches) or
  1451. path_absolute(infile.path^) then
  1452. list.insertbefore(Tai_stab.Create_str(stab_stabs,'"'+BsToSlash(FixPath(infile.path^,false))+FixFileName(infile.name^)+'",'+tostr(n_includefile)+
  1453. ',0,0,'+hlabel.name),hp)
  1454. else
  1455. list.insertbefore(Tai_stab.Create_str(stab_stabs,'"'+BsToSlash(FixPath(getcurrentdir,false)+FixPath(infile.path^,false))+FixFileName(infile.name^)+'",'+tostr(n_includefile)+
  1456. ',0,0,'+hlabel.name),hp);
  1457. list.insertbefore(tai_label.create(hlabel),hp);
  1458. { force new line info }
  1459. lastfileinfo.line:=-1;
  1460. end;
  1461. end;
  1462. { line changed ? }
  1463. if (currfileinfo.line>lastfileinfo.line) and (currfileinfo.line<>0) then
  1464. begin
  1465. if assigned(currfuncname) and
  1466. (tf_use_function_relative_addresses in target_info.flags) then
  1467. begin
  1468. current_asmdata.getlabel(hlabel,alt_dbgline);
  1469. list.insertbefore(Tai_stab.Create_str(stab_stabn,tostr(n_textline)+',0,'+tostr(currfileinfo.line)+','+
  1470. hlabel.name+' - '+{$IFDEF POWERPC64}'.'+{$ENDIF POWERPC64}currfuncname^),hp);
  1471. list.insertbefore(tai_label.create(hlabel),hp);
  1472. end
  1473. else
  1474. list.insertbefore(Tai_stab.Create_str(stab_stabd,tostr(n_textline)+',0,'+tostr(currfileinfo.line)),hp);
  1475. end;
  1476. lastfileinfo:=currfileinfo;
  1477. end;
  1478. hp:=tai(hp.next);
  1479. end;
  1480. end;
  1481. procedure tdebuginfostabs.insertmoduleinfo;
  1482. var
  1483. hlabel : tasmlabel;
  1484. infile : tinputfile;
  1485. begin
  1486. { emit main source n_sourcefile for start of module }
  1487. current_asmdata.getlabel(hlabel,alt_dbgfile);
  1488. infile:=current_module.sourcefiles.get_file(1);
  1489. new_section(current_asmdata.asmlists[al_start],sec_code,make_mangledname('DEBUGSTART',current_module.localsymtable,''),0,secorder_begin);
  1490. if not(target_info.system in systems_darwin) then
  1491. current_asmdata.asmlists[al_start].concat(tai_symbol.Createname_global(make_mangledname('DEBUGSTART',current_module.localsymtable,''),AT_DATA,0));
  1492. current_asmdata.asmlists[al_start].concat(Tai_stab.Create_str(stab_stabs,'"'+BsToSlash(FixPath(getcurrentdir,false))+'",'+tostr(n_sourcefile)+
  1493. ',0,0,'+hlabel.name));
  1494. current_asmdata.asmlists[al_start].concat(Tai_stab.Create_str(stab_stabs,'"'+BsToSlash(FixPath(infile.path^,false))+FixFileName(infile.name^)+'",'+tostr(n_sourcefile)+
  1495. ',0,0,'+hlabel.name));
  1496. current_asmdata.asmlists[al_start].concat(tai_label.create(hlabel));
  1497. { for darwin, you need a "module marker" too to work around }
  1498. { either some assembler or gdb bug (radar 4386531 according to a }
  1499. { comment in dbxout.c of Apple's gcc) }
  1500. if (target_info.system in systems_darwin) then
  1501. current_asmdata.asmlists[al_end].concat(Tai_stab.Create_str(stab_stabs,'"",'+tostr(N_OSO)+',0,0,0'));
  1502. { emit empty n_sourcefile for end of module }
  1503. current_asmdata.getlabel(hlabel,alt_dbgfile);
  1504. new_section(current_asmdata.asmlists[al_end],sec_code,make_mangledname('DEBUGEND',current_module.localsymtable,''),0,secorder_end);
  1505. if not(target_info.system in systems_darwin) then
  1506. current_asmdata.asmlists[al_end].concat(tai_symbol.Createname_global(make_mangledname('DEBUGEND',current_module.localsymtable,''),AT_DATA,0));
  1507. current_asmdata.asmlists[al_end].concat(Tai_stab.Create_str(stab_stabs,'"",'+tostr(n_sourcefile)+',0,0,'+hlabel.name));
  1508. current_asmdata.asmlists[al_end].concat(tai_label.create(hlabel));
  1509. end;
  1510. procedure tdebuginfostabs.referencesections(list:TAsmList);
  1511. var
  1512. hp : tmodule;
  1513. dbgtable : tai_symbol;
  1514. begin
  1515. { Reference all DEBUGINFO sections from the main .fpc section }
  1516. if (target_info.system in ([system_powerpc_macos]+systems_darwin)) then
  1517. exit;
  1518. list.concat(Tai_section.create(sec_fpc,'links',0));
  1519. { make sure the debuginfo doesn't get stripped out }
  1520. if (target_info.system in systems_darwin) then
  1521. begin
  1522. dbgtable:=tai_symbol.createname('DEBUGINFOTABLE',AT_DATA,0);
  1523. list.concat(tai_directive.create(asd_no_dead_strip,dbgtable.sym.name));
  1524. list.concat(dbgtable);
  1525. end;
  1526. { include reference to all debuginfo sections of used units }
  1527. hp:=tmodule(loaded_units.first);
  1528. while assigned(hp) do
  1529. begin
  1530. If (hp.flags and uf_has_stabs_debuginfo)=uf_has_stabs_debuginfo then
  1531. begin
  1532. list.concat(Tai_const.Createname(make_mangledname('DEBUGINFO',hp.localsymtable,''),0));
  1533. list.concat(Tai_const.Createname(make_mangledname('DEBUGSTART',hp.localsymtable,''),0));
  1534. list.concat(Tai_const.Createname(make_mangledname('DEBUGEND',hp.localsymtable,''),0));
  1535. end;
  1536. hp:=tmodule(hp.next);
  1537. end;
  1538. end;
  1539. const
  1540. dbg_stabs_info : tdbginfo =
  1541. (
  1542. id : dbg_stabs;
  1543. idtxt : 'STABS';
  1544. );
  1545. initialization
  1546. RegisterDebugInfo(dbg_stabs_info,TDebugInfoStabs);
  1547. end.