dbgstabs.pas 66 KB

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