dbgstabs.pas 66 KB

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