dbgstabs.pas 65 KB

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