dbgstabs.pas 65 KB

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