dbgstabs.pas 66 KB

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