dbgstabs.pas 66 KB

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