dbgstabs.pas 66 KB

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