dbgstabs.pas 66 KB

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