ppudump.pp 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by the FPC Development Team
  4. Dumps the contents of a FPC unit file (PPU File)
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************}
  17. {$ifdef TP}
  18. {$N+,E+}
  19. {$endif}
  20. program pppdump;
  21. uses
  22. dos,
  23. ppu;
  24. const
  25. Version = 'Version 1.10';
  26. Title = 'PPU-Analyser';
  27. Copyright = 'Copyright (c) 1998-2002 by the Free Pascal Development Team';
  28. { verbosity }
  29. v_none = $0;
  30. v_header = $1;
  31. v_defs = $2;
  32. v_syms = $4;
  33. v_interface = $8;
  34. v_implementation = $10;
  35. v_browser = $20;
  36. v_all = $ff;
  37. type
  38. { Copied from systems.pas }
  39. ttargetcpu=
  40. (
  41. no_cpu, { 0 }
  42. i386, { 1 }
  43. m68k, { 2 }
  44. alpha, { 3 }
  45. powerpc, { 4 }
  46. sparc, { 5 }
  47. vm { 6 }
  48. );
  49. var
  50. ppufile : tppufile;
  51. space : string;
  52. read_member : boolean;
  53. unitindex : longint;
  54. verbose : longint;
  55. {****************************************************************************
  56. Helper Routines
  57. ****************************************************************************}
  58. const has_errors : boolean = false;
  59. Procedure Error(const S : string);
  60. Begin
  61. Writeln(S);
  62. has_errors:=true;
  63. End;
  64. Function Target2Str(w:longint):string;
  65. type
  66. { taken from systems.pas }
  67. ttarget =
  68. (
  69. target_none, { 0 }
  70. target_i386_GO32V1, { 1 }
  71. target_i386_GO32V2, { 2 }
  72. target_i386_linux, { 3 }
  73. target_i386_OS2, { 4 }
  74. target_i386_Win32, { 5 }
  75. target_i386_freebsd, { 6 }
  76. target_m68k_Amiga, { 7 }
  77. target_m68k_Atari, { 8 }
  78. target_m68k_Mac, { 9 }
  79. target_m68k_linux, { 10 }
  80. target_m68k_PalmOS, { 11 }
  81. target_alpha_linux, { 12 }
  82. target_powerpc_linux, { 13 }
  83. target_powerpc_macos, { 14 }
  84. target_i386_sunos, { 15 }
  85. target_i386_beos, { 16 }
  86. target_i386_netbsd, { 17 }
  87. target_m68k_netbsd, { 18 }
  88. target_i386_Netware, { 19 }
  89. target_i386_qnx, { 20 }
  90. target_i386_wdosx, { 21 }
  91. target_sparc_sunos, { 22 }
  92. target_sparc_linux, { 23 }
  93. target_i386_openbsd, { 24 }
  94. target_m68k_openbsd, { 25 }
  95. system_x86_64_linux, { 26 }
  96. system_powerpc_macosx { 27 }
  97. );
  98. const
  99. Targets : array[ttarget] of string[16]=(
  100. { 0 } 'none',
  101. { 1 } 'GO32V1',
  102. { 2 } 'GO32V2',
  103. { 3 } 'Linux-i386',
  104. { 4 } 'OS/2',
  105. { 5 } 'Win32',
  106. { 6 } 'FreeBSD-i386',
  107. { 7 } 'Amiga',
  108. { 8 } 'Atari',
  109. { 9 } 'MacOS-m68k',
  110. { 10 } 'Linux-m68k',
  111. { 11 } 'PalmOS-m68k',
  112. { 12 } 'Linux-alpha',
  113. { 13 } 'Linux-ppc',
  114. { 14 } 'MacOS-ppc',
  115. { 15 } 'Solaris-i386',
  116. { 16 } 'BeOS-i386',
  117. { 17 } 'NetBSD-i386',
  118. { 18 } 'NetBSD-m68k',
  119. { 19 } 'Netware',
  120. { 20 } 'Qnx-i386',
  121. { 21 } 'WDOSX-i386',
  122. { 22 } 'Solaris-sparc',
  123. { 23 } 'Linux-sparc',
  124. { 24 } 'OpenBSD-i386',
  125. { 25 } 'OpenBSD-m68k',
  126. { 26 } 'Linux-x86-64',
  127. { 27 } 'MacOSX-ppc'
  128. );
  129. begin
  130. if w<=ord(high(ttarget)) then
  131. Target2Str:=Targets[ttarget(w)]
  132. else
  133. Target2Str:='<Unknown>';
  134. end;
  135. Function Cpu2Str(w:longint):string;
  136. const
  137. CpuTxt : array[ttargetcpu] of string[7]=
  138. ('none','i386','m68k','alpha','powerpc','sparc','vis');
  139. begin
  140. if w<=ord(high(ttargetcpu)) then
  141. Cpu2Str:=CpuTxt[ttargetcpu(w)]
  142. else
  143. Cpu2Str:='<Unknown>';
  144. end;
  145. function PPUFlags2Str(flags:longint):string;
  146. type
  147. tflagopt=record
  148. mask : longint;
  149. str : string[30];
  150. end;
  151. const
  152. flagopts=16;
  153. flagopt : array[1..flagopts] of tflagopt=(
  154. (mask: $1 ;str:'init'),
  155. (mask: $2 ;str:'final'),
  156. (mask: $4 ;str:'big_endian'),
  157. (mask: $8 ;str:'dbx'),
  158. (mask: $10 ;str:'browser'),
  159. (mask: $20 ;str:'in_library'),
  160. (mask: $40 ;str:'smart_linked'),
  161. (mask: $80 ;str:'static_linked'),
  162. (mask: $100 ;str:'shared_linked'),
  163. (mask: $200 ;str:'local_browser'),
  164. (mask: $400 ;str:'no_link'),
  165. (mask: $800 ;str:'has_resources'),
  166. (mask: $1000 ;str:'little_endian'),
  167. (mask: $2000 ;str:'release'),
  168. (mask: $4000 ;str:'local_threadvars'),
  169. (mask: $8000 ;str:'fpu emulation on')
  170. );
  171. var
  172. i : longint;
  173. first : boolean;
  174. s : string;
  175. begin
  176. s:='';
  177. if flags<>0 then
  178. begin
  179. first:=true;
  180. for i:=1to flagopts do
  181. if (flags and flagopt[i].mask)<>0 then
  182. begin
  183. if first then
  184. first:=false
  185. else
  186. s:=s+', ';
  187. s:=s+flagopt[i].str;
  188. end;
  189. end
  190. else
  191. s:='none';
  192. PPUFlags2Str:=s;
  193. end;
  194. const
  195. HexTbl : array[0..15] of char='0123456789ABCDEF';
  196. function HexB(b:byte):string;
  197. begin
  198. HexB[0]:=#2;
  199. HexB[1]:=HexTbl[b shr 4];
  200. HexB[2]:=HexTbl[b and $f];
  201. end;
  202. function hexstr(val : cardinal;cnt : byte) : string;
  203. const
  204. HexTbl : array[0..15] of char='0123456789ABCDEF';
  205. var
  206. i : longint;
  207. begin
  208. hexstr[0]:=char(cnt);
  209. for i:=cnt downto 1 do
  210. begin
  211. hexstr[i]:=hextbl[val and $f];
  212. val:=val shr 4;
  213. end;
  214. end;
  215. Function L0(l:longint):string;
  216. {
  217. return the string of value l, if l<10 then insert a zero, so
  218. the string is always at least 2 chars '01','02',etc
  219. }
  220. var
  221. s : string;
  222. begin
  223. Str(l,s);
  224. if l<10 then
  225. s:='0'+s;
  226. L0:=s;
  227. end;
  228. function filetimestring( t : longint) : string;
  229. {
  230. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  231. }
  232. var
  233. DT : DateTime;
  234. begin
  235. if t=-1 then
  236. begin
  237. FileTimeString:='Not Found';
  238. exit;
  239. end;
  240. unpacktime(t,DT);
  241. filetimestring:=L0(dt.Year)+'/'+L0(dt.Month)+'/'+L0(dt.Day)+' '+L0(dt.Hour)+':'+L0(dt.min)+':'+L0(dt.sec);
  242. end;
  243. {****************************************************************************
  244. Read Routines
  245. ****************************************************************************}
  246. function getint64:int64;
  247. var
  248. l1,l2 : longint;
  249. begin
  250. l1:=ppufile.getlongint;
  251. l2:=ppufile.getlongint;
  252. getint64:=(int64(l2) shl 32) or qword(l1);
  253. end;
  254. Procedure ReadLinkContainer(const prefix:string);
  255. {
  256. Read a serie of strings and write to the screen starting every line
  257. with prefix
  258. }
  259. function maskstr(m:longint):string;
  260. const
  261. { link options }
  262. link_none = $0;
  263. link_allways = $1;
  264. link_static = $2;
  265. link_smart = $4;
  266. link_shared = $8;
  267. var
  268. s : string;
  269. begin
  270. s:='';
  271. if (m and link_allways)<>0 then
  272. s:=s+'always ';
  273. if (m and link_static)<>0 then
  274. s:=s+'static ';
  275. if (m and link_smart)<>0 then
  276. s:=s+'smart ';
  277. if (m and link_shared)<>0 then
  278. s:=s+'shared ';
  279. maskstr:=s;
  280. end;
  281. var
  282. s : string;
  283. m : longint;
  284. begin
  285. while not ppufile.endofentry do
  286. begin
  287. s:=ppufile.getstring;
  288. m:=ppufile.getlongint;
  289. WriteLn(prefix,s,' (',maskstr(m),')');
  290. end;
  291. end;
  292. Procedure ReadContainer(const prefix:string);
  293. {
  294. Read a serie of strings and write to the screen starting every line
  295. with prefix
  296. }
  297. begin
  298. while not ppufile.endofentry do
  299. WriteLn(prefix,ppufile.getstring);
  300. end;
  301. Procedure ReadRef;
  302. begin
  303. if (verbose and v_browser)=0 then
  304. exit;
  305. while (not ppufile.endofentry) and (not ppufile.error) do
  306. Writeln(space,' - Refered : ',ppufile.getword,', (',ppufile.getlongint,',',ppufile.getword,')');
  307. end;
  308. Procedure ReadAsmSymbols;
  309. type
  310. { Copied from aasmbase.pas }
  311. TAsmsymbind=(AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL);
  312. TAsmsymtype=(AT_NONE,AT_FUNCTION,AT_DATA,AT_SECTION);
  313. var
  314. s,
  315. bindstr,
  316. typestr : string;
  317. i : longint;
  318. begin
  319. writeln(space,'Number of AsmSymbols: ',ppufile.getlongint);
  320. i:=0;
  321. while (not ppufile.endofentry) and (not ppufile.error) do
  322. begin
  323. s:=ppufile.getstring;
  324. case tasmsymbind(ppufile.getbyte) of
  325. AB_EXTERNAL :
  326. bindstr:='External';
  327. AB_COMMON :
  328. bindstr:='Common';
  329. AB_LOCAL :
  330. bindstr:='Local';
  331. AB_GLOBAL :
  332. bindstr:='Global';
  333. else
  334. bindstr:='<Error !!>'
  335. end;
  336. case tasmsymtype(ppufile.getbyte) of
  337. AT_FUNCTION :
  338. typestr:='Function';
  339. AT_DATA :
  340. typestr:='Data';
  341. AT_SECTION :
  342. typestr:='Section';
  343. else
  344. typestr:='<Error !!>'
  345. end;
  346. Writeln(space,' ',i,' : ',s,' [',bindstr,',',typestr,']');
  347. inc(i);
  348. end;
  349. end;
  350. Procedure ReadPosInfo;
  351. var
  352. info : byte;
  353. fileindex,line,column : longint;
  354. begin
  355. with ppufile do
  356. begin
  357. {
  358. info byte layout in bits:
  359. 0-1 - amount of bytes for fileindex
  360. 2-3 - amount of bytes for line
  361. 4-5 - amount of bytes for column
  362. }
  363. info:=getbyte;
  364. case (info and $03) of
  365. 0 : fileindex:=getbyte;
  366. 1 : fileindex:=getword;
  367. 2 : fileindex:=(getbyte shl 16) or getword;
  368. 3 : fileindex:=getlongint;
  369. end;
  370. case ((info shr 2) and $03) of
  371. 0 : line:=getbyte;
  372. 1 : line:=getword;
  373. 2 : line:=(getbyte shl 16) or getword;
  374. 3 : line:=getlongint;
  375. end;
  376. case ((info shr 4) and $03) of
  377. 0 : column:=getbyte;
  378. 1 : column:=getword;
  379. 2 : column:=(getbyte shl 16) or getword;
  380. 3 : column:=getlongint;
  381. end;
  382. Writeln(fileindex,' (',line,',',column,')');
  383. end;
  384. end;
  385. function readderef(const s:string;skipnil:boolean):boolean;
  386. type
  387. tdereftype = (derefnil,derefaktrecordindex,derefaktstaticindex,
  388. derefunit,derefrecord,derefindex,
  389. dereflocal,derefpara,derefaktlocalindex);
  390. var
  391. b : tdereftype;
  392. begin
  393. readderef:=true;
  394. repeat
  395. b:=tdereftype(ppufile.getbyte);
  396. case b of
  397. derefnil :
  398. begin
  399. if not skipnil then
  400. writeln('nil');
  401. readderef:=false;
  402. break;
  403. end;
  404. derefaktrecordindex :
  405. begin
  406. writeln('AktRecord ',s,' ',ppufile.getword);
  407. break;
  408. end;
  409. derefaktstaticindex :
  410. begin
  411. writeln('AktStatic ',s,' ',ppufile.getword);
  412. break;
  413. end;
  414. derefaktlocalindex :
  415. begin
  416. writeln('AktLocal ',s,' ',ppufile.getword);
  417. break;
  418. end;
  419. derefunit :
  420. begin
  421. writeln('Unit ',ppufile.getword);
  422. break;
  423. end;
  424. derefrecord :
  425. begin
  426. write('RecordDef ',ppufile.getword,', ');
  427. end;
  428. derefpara :
  429. begin
  430. write('Parameter of procdef ',ppufile.getword,', ');
  431. end;
  432. dereflocal :
  433. begin
  434. write('Local of procdef ',ppufile.getword,', ');
  435. end;
  436. derefindex :
  437. begin
  438. write(s,' ',ppufile.getword,', ');
  439. end;
  440. else
  441. begin
  442. writeln('!! unsupported dereftyp: ',ord(b));
  443. break;
  444. end;
  445. end;
  446. until false;
  447. end;
  448. function readdefref:boolean;
  449. begin
  450. readdefref:=readderef('Definition',false);
  451. end;
  452. function readsymref:boolean;
  453. begin
  454. readsymref:=readderef('Symbol',false);
  455. end;
  456. procedure readtype;
  457. var
  458. b1,b2 : boolean;
  459. begin
  460. b1:=readderef('Definition',true);
  461. b2:=readderef('Symbol',true);
  462. if not(b1 or b2) then
  463. Writeln('nil')
  464. else
  465. if (b1 and b2) then
  466. Writeln('!! Type has both definition and symbol stored');
  467. end;
  468. procedure readsymlist(const s:string);
  469. type
  470. tsltype = (sl_none,
  471. sl_load,
  472. sl_call,
  473. sl_subscript,
  474. sl_vec
  475. );
  476. const
  477. slstr : array[tsltype] of string[9] = ('',
  478. 'load',
  479. 'call',
  480. 'subscript',
  481. 'vec'
  482. );
  483. var
  484. sl : tsltype;
  485. begin
  486. readdefref;
  487. repeat
  488. sl:=tsltype(ppufile.getbyte);
  489. if sl=sl_none then
  490. break;
  491. write(s,'(',slstr[sl],') ');
  492. case sl of
  493. sl_call,
  494. sl_load,
  495. sl_subscript :
  496. readsymref;
  497. sl_vec :
  498. writeln(ppufile.getlongint);
  499. end;
  500. until false;
  501. end;
  502. procedure readsymoptions;
  503. type
  504. tsymoption=(sp_none,
  505. sp_public,
  506. sp_private,
  507. sp_published,
  508. sp_protected,
  509. sp_forwarddef,
  510. sp_static,
  511. sp_primary_typesym { this is for typesym, to know who is the primary symbol of a def }
  512. );
  513. tsymoptions=set of tsymoption;
  514. tsymopt=record
  515. mask : tsymoption;
  516. str : string[30];
  517. end;
  518. const
  519. symopts=7;
  520. symopt : array[1..symopts] of tsymopt=(
  521. (mask:sp_public; str:'Public'),
  522. (mask:sp_private; str:'Private'),
  523. (mask:sp_published; str:'Published'),
  524. (mask:sp_protected; str:'Protected'),
  525. (mask:sp_forwarddef; str:'ForwardDef'),
  526. (mask:sp_static; str:'Static'),
  527. (mask:sp_primary_typesym;str:'PrimaryTypeSym')
  528. );
  529. var
  530. symoptions : tsymoptions;
  531. i : longint;
  532. first : boolean;
  533. begin
  534. ppufile.getsmallset(symoptions);
  535. if symoptions<>[] then
  536. begin
  537. first:=true;
  538. for i:=1to symopts do
  539. if (symopt[i].mask in symoptions) then
  540. begin
  541. if first then
  542. first:=false
  543. else
  544. write(', ');
  545. write(symopt[i].str);
  546. end;
  547. end;
  548. writeln;
  549. end;
  550. { Read abstract procdef and return if inline procdef }
  551. type
  552. tproccalloption=(pocall_none,
  553. pocall_cdecl, { procedure uses C styled calling }
  554. pocall_cppdecl, { C++ calling conventions }
  555. pocall_compilerproc, { Procedure is used for internal compiler calls }
  556. pocall_far16, { Far16 for OS/2 }
  557. pocall_fpccall, { FPC default calling }
  558. pocall_inline, { Procedure is an assembler macro }
  559. pocall_internproc, { Procedure has compiler magic}
  560. pocall_palmossyscall, { procedure is a PalmOS system call }
  561. pocall_pascal, { pascal standard left to right }
  562. pocall_register, { procedure uses register (fastcall) calling }
  563. pocall_safecall, { safe call calling conventions }
  564. pocall_stdcall, { procedure uses stdcall call }
  565. pocall_system { system call }
  566. );
  567. tproccalloptions=set of tproccalloption;
  568. tproctypeoption=(potype_none,
  569. potype_proginit, { Program initialization }
  570. potype_unitinit, { unit initialization }
  571. potype_unitfinalize, { unit finalization }
  572. potype_constructor, { Procedure is a constructor }
  573. potype_destructor, { Procedure is a destructor }
  574. potype_operator { Procedure defines an operator }
  575. );
  576. tproctypeoptions=set of tproctypeoption;
  577. tprocoption=(po_none,
  578. po_classmethod, { class method }
  579. po_virtualmethod, { Procedure is a virtual method }
  580. po_abstractmethod, { Procedure is an abstract method }
  581. po_staticmethod, { static method }
  582. po_overridingmethod, { method with override directive }
  583. po_methodpointer, { method pointer, only in procvardef, also used for 'with object do' }
  584. po_containsself, { self is passed explicit to the compiler }
  585. po_interrupt, { Procedure is an interrupt handler }
  586. po_iocheck, { IO checking should be done after a call to the procedure }
  587. po_assembler, { Procedure is written in assembler }
  588. po_msgstr, { method for string message handling }
  589. po_msgint, { method for int message handling }
  590. po_exports, { Procedure has export directive (needed for OS/2) }
  591. po_external, { Procedure is external (in other object or lib)}
  592. po_savestdregs, { save std regs cdecl and stdcall need that ! }
  593. po_saveregisters, { save all registers }
  594. po_overload, { procedure is declared with overload directive }
  595. po_varargs, { printf like arguments }
  596. po_leftright, { push arguments from left to right }
  597. po_clearstack, { caller clears the stack }
  598. po_internconst { procedure has constant evaluator intern }
  599. );
  600. tprocoptions=set of tprocoption;
  601. function read_abstract_proc_def:tproccalloption;
  602. type
  603. tproccallopt=record
  604. mask : tproccalloption;
  605. str : string[30];
  606. end;
  607. tproctypeopt=record
  608. mask : tproctypeoption;
  609. str : string[30];
  610. end;
  611. tprocopt=record
  612. mask : tprocoption;
  613. str : string[30];
  614. end;
  615. const
  616. proccalloptionStr : array[tproccalloption] of string[14]=('',
  617. 'CDecl',
  618. 'CPPDecl',
  619. 'CompilerProc',
  620. 'Far16',
  621. 'FPCCall',
  622. 'Inline',
  623. 'InternProc',
  624. 'PalmOSSysCall',
  625. 'Pascal',
  626. 'Register',
  627. 'SafeCall',
  628. 'StdCall',
  629. 'System'
  630. );
  631. proctypeopts=6;
  632. proctypeopt : array[1..proctypeopts] of tproctypeopt=(
  633. (mask:potype_proginit; str:'ProgInit'),
  634. (mask:potype_unitinit; str:'UnitInit'),
  635. (mask:potype_unitfinalize;str:'UnitFinalize'),
  636. (mask:potype_constructor; str:'Constructor'),
  637. (mask:potype_destructor; str:'Destructor'),
  638. (mask:potype_operator; str:'Operator')
  639. );
  640. procopts=21;
  641. procopt : array[1..procopts] of tprocopt=(
  642. (mask:po_classmethod; str:'ClassMethod'),
  643. (mask:po_virtualmethod; str:'VirtualMethod'),
  644. (mask:po_abstractmethod; str:'AbstractMethod'),
  645. (mask:po_staticmethod; str:'StaticMethod'),
  646. (mask:po_overridingmethod;str:'OverridingMethod'),
  647. (mask:po_methodpointer; str:'MethodPointer'),
  648. (mask:po_containsself; str:'ContainsSelf'),
  649. (mask:po_interrupt; str:'Interrupt'),
  650. (mask:po_iocheck; str:'IOCheck'),
  651. (mask:po_assembler; str:'Assembler'),
  652. (mask:po_msgstr; str:'MsgStr'),
  653. (mask:po_msgint; str:'MsgInt'),
  654. (mask:po_exports; str:'Exports'),
  655. (mask:po_external; str:'External'),
  656. (mask:po_savestdregs; str:'SaveStdRegs'),
  657. (mask:po_saveregisters; str:'SaveRegisters'),
  658. (mask:po_overload; str:'Overload'),
  659. (mask:po_varargs; str:'VarArgs'),
  660. (mask:po_leftright; str:'LeftRight'),
  661. (mask:po_clearstack; str:'ClearStack'),
  662. (mask:po_internconst; str:'InternConst')
  663. );
  664. tvarspez : array[0..3] of string[5]=('Value','Const','Var ','Out ');
  665. var
  666. proctypeoption : tproctypeoption;
  667. proccalloption : tproccalloption;
  668. procoptions : tprocoptions;
  669. i,params : longint;
  670. first : boolean;
  671. paraloc : array[0..15] of byte;
  672. begin
  673. write(space,' Return type : ');
  674. readtype;
  675. writeln(space,' Fpu used : ',ppufile.getbyte);
  676. proctypeoption:=tproctypeoption(ppufile.getbyte);
  677. if proctypeoption<>potype_none then
  678. begin
  679. write(space,' TypeOption : ');
  680. first:=true;
  681. for i:=1to proctypeopts do
  682. if (proctypeopt[i].mask=proctypeoption) then
  683. begin
  684. if first then
  685. first:=false
  686. else
  687. write(', ');
  688. write(proctypeopt[i].str);
  689. end;
  690. writeln;
  691. end;
  692. proccalloption:=tproccalloption(ppufile.getbyte);
  693. read_abstract_proc_def:=proccalloption;
  694. writeln(space,' CallOption : ',proccalloptionStr[proccalloption]);
  695. ppufile.getsmallset(procoptions);
  696. if procoptions<>[] then
  697. begin
  698. write(space,' Options : ');
  699. first:=true;
  700. for i:=1to procopts do
  701. if (procopt[i].mask in procoptions) then
  702. begin
  703. if first then
  704. first:=false
  705. else
  706. write(', ');
  707. write(procopt[i].str);
  708. end;
  709. writeln;
  710. end;
  711. params:=ppufile.getbyte;
  712. writeln(space,' Nr of parameters : ',params);
  713. if params>0 then
  714. begin
  715. repeat
  716. write(space,' - ',tvarspez[ppufile.getbyte],' : ');
  717. readtype;
  718. write(space,' Default : ');
  719. readsymref;
  720. write(space,' Symbol : ');
  721. readsymref;
  722. write(space,' Location : ');
  723. writeln('<not yet implemented>');
  724. ppufile.getdata(paraloc,sizeof(paraloc));
  725. dec(params);
  726. until params=0;
  727. end;
  728. end;
  729. procedure readcommonsym(const s:string);
  730. begin
  731. writeln(space,'** Symbol Nr. ',ppufile.getword,' **');
  732. writeln(space,s,ppufile.getstring);
  733. write(space,' File Pos: ');
  734. readposinfo;
  735. write(space,' SymOptions: ');
  736. readsymoptions;
  737. end;
  738. procedure readcommondef(const s:string);
  739. type
  740. tdefoption=(df_none,
  741. df_has_inittable, { init data has been generated }
  742. df_has_rttitable, { rtti data has been generated }
  743. df_unique
  744. );
  745. tdefoptions=set of tdefoption;
  746. var
  747. defopts : tdefoptions;
  748. begin
  749. writeln(space,'** Definition Nr. ',ppufile.getword,' **');
  750. writeln(space,s);
  751. write (space,' Type symbol : ');
  752. readsymref;
  753. ppufile.getsmallset(defopts);
  754. if df_unique in defopts then
  755. writeln (space,' Unique type symbol');
  756. if df_has_rttitable in defopts then
  757. begin
  758. write (space,' RTTI symbol : ');
  759. readsymref;
  760. end;
  761. if df_has_inittable in defopts then
  762. begin
  763. write (space,' Init symbol : ');
  764. readsymref;
  765. end;
  766. end;
  767. {****************************************************************************
  768. Read Symbols Part
  769. ****************************************************************************}
  770. procedure readsymbols;
  771. type
  772. { options for variables }
  773. tvaroption=(vo_none,
  774. vo_regable,
  775. vo_is_C_var,
  776. vo_is_external,
  777. vo_is_dll_var,
  778. vo_is_thread_var,
  779. vo_fpuregable,
  780. vo_is_local_copy,
  781. vo_is_const, { variable is declared as const (parameter) and can't be written to }
  782. vo_is_exported,
  783. vo_is_high_value
  784. );
  785. tvaroptions=set of tvaroption;
  786. pguid = ^tguid;
  787. tguid = packed record
  788. D1: LongWord;
  789. D2: Word;
  790. D3: Word;
  791. D4: array[0..7] of Byte;
  792. end;
  793. absolutetyp = (tovar,toasm,toaddr);
  794. tconsttyp = (constnone,
  795. constord,conststring,constreal,constbool,
  796. constint,constchar,constset,constpointer,constnil,
  797. constresourcestring,constwstring,constwchar,constguid
  798. );
  799. var
  800. b : byte;
  801. pc : pchar;
  802. totalsyms,
  803. symcnt,
  804. i,j,len : longint;
  805. guid : tguid;
  806. begin
  807. symcnt:=1;
  808. with ppufile do
  809. begin
  810. if space<>'' then
  811. Writeln(space,'-----------------------------');
  812. if readentry=ibstartsyms then
  813. begin
  814. totalsyms:=getlongint;
  815. Writeln(space,'Number of symbols : ',totalsyms);
  816. Writeln(space,'Symtable datasize : ',getlongint);
  817. Writeln(space,'Symtable alignment: ',getlongint);
  818. end
  819. else
  820. begin
  821. totalsyms:=-1;
  822. Writeln('!! ibstartsym not found');
  823. end;
  824. repeat
  825. b:=readentry;
  826. if not (b in [iberror,ibendsyms]) then
  827. inc(symcnt);
  828. case b of
  829. ibunitsym :
  830. readcommonsym('Unit symbol ');
  831. iblabelsym :
  832. readcommonsym('Label symbol ');
  833. ibtypesym :
  834. begin
  835. readcommonsym('Type symbol ');
  836. write(space,' Result Type: ');
  837. readtype;
  838. end;
  839. ibprocsym :
  840. begin
  841. readcommonsym('Procedure symbol ');
  842. repeat
  843. write(space,' Definition: ');
  844. until not readdefref;
  845. end;
  846. ibconstsym :
  847. begin
  848. readcommonsym('Constant symbol ');
  849. b:=getbyte;
  850. case tconsttyp(b) of
  851. constord :
  852. begin
  853. write (space,'OrdinalType: ');
  854. readtype;
  855. writeln (space,' Value: ',getlongint)
  856. end;
  857. constpointer :
  858. begin
  859. write (space,' Pointer Type: ');
  860. readtype;
  861. writeln (space,' Value: ',getlongint)
  862. end;
  863. conststring,
  864. constresourcestring :
  865. begin
  866. len:=getlongint;
  867. getmem(pc,len+1);
  868. getdata(pc^,len);
  869. writeln(space,' Length: ',len);
  870. writeln(space,' Value: "',pc,'"');
  871. freemem(pc,len+1);
  872. if tconsttyp(b)=constresourcestring then
  873. writeln(space,' Index: ',getlongint);
  874. end;
  875. constreal :
  876. writeln(space,' Value: ',getreal);
  877. constbool :
  878. if getlongint<>0 then
  879. writeln (space,' Value : True')
  880. else
  881. writeln (space,' Value: False');
  882. constint :
  883. writeln(space,' Value: ',getint64);
  884. constchar :
  885. writeln(space,' Value: "'+chr(getlongint)+'"');
  886. constset :
  887. begin
  888. write (space,' Set Type: ');
  889. readtype;
  890. for i:=1to 4 do
  891. begin
  892. write (space,' Value: ');
  893. for j:=1to 8 do
  894. begin
  895. if j>1 then
  896. write(',');
  897. write(hexb(getbyte));
  898. end;
  899. writeln;
  900. end;
  901. end;
  902. constwstring:
  903. begin
  904. end;
  905. constwchar:
  906. writeln(space,' Value: #',getlongint);
  907. constguid:
  908. begin
  909. getdata(guid,sizeof(guid));
  910. write (space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-');
  911. for i:=0 to 7 do
  912. begin
  913. write(hexstr(guid.d4[i],2));
  914. if i=1 then write('-');
  915. end;
  916. writeln('}');
  917. end
  918. else
  919. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  920. end;
  921. end;
  922. ibvarsym :
  923. begin
  924. readcommonsym('Variable symbol ');
  925. writeln(space,' Type: ',getbyte);
  926. writeln(space,' Address: ',getlongint);
  927. write (space,' Var Type: ');
  928. readtype;
  929. i:=getlongint;
  930. writeln(space,' Options: ',i);
  931. if (vo_is_C_var in tvaroptions(i)) then
  932. writeln(space,' Mangledname: ',getstring);
  933. end;
  934. ibenumsym :
  935. begin
  936. readcommonsym('Enumeration symbol ');
  937. write (space,' Definition: ');
  938. readdefref;
  939. writeln(space,' Value: ',getlongint);
  940. end;
  941. ibsyssym :
  942. begin
  943. readcommonsym('Internal system symbol ');
  944. writeln(space,' Internal Nr: ',getlongint);
  945. end;
  946. ibrttisym :
  947. begin
  948. readcommonsym('RTTI symbol ');
  949. writeln(space,' RTTI Type: ',getbyte);
  950. end;
  951. ibtypedconstsym :
  952. begin
  953. readcommonsym('Typed constant ');
  954. write (space,' Constant Type: ');
  955. readtype;
  956. writeln(space,' ReallyConst: ',(getbyte<>0));
  957. end;
  958. ibabsolutesym :
  959. begin
  960. readcommonsym('Absolute variable symbol ');
  961. writeln(space,' Type: ',getbyte);
  962. writeln(space,' Address: ',getlongint);
  963. write (space,' Var Type: ');
  964. readtype;
  965. writeln(space,' Options: ',getlongint);
  966. Write (space,' Relocated to ');
  967. b:=getbyte;
  968. case absolutetyp(b) of
  969. tovar :
  970. Writeln('Name : ',getstring);
  971. toasm :
  972. Writeln('Assembler name : ',getstring);
  973. toaddr :
  974. begin
  975. Write('Address : ',getlongint);
  976. WriteLn(' (Far: ',getbyte<>0,')');
  977. end;
  978. else
  979. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  980. end;
  981. end;
  982. ibpropertysym :
  983. begin
  984. readcommonsym('Property ');
  985. i:=getlongint;
  986. writeln(space,' PropOptions: ',i);
  987. if (i and 32)>0 then
  988. begin
  989. write (space,'OverrideProp: ');
  990. readsymref;
  991. end
  992. else
  993. begin
  994. write (space,' Prop Type: ');
  995. readtype;
  996. writeln(space,' Index: ',getlongint);
  997. writeln(space,' Default: ',getlongint);
  998. write (space,' Index Type: ');
  999. readtype;
  1000. write (space,' Readaccess: ');
  1001. readsymlist(space+' Sym: ');
  1002. write (space,' Writeaccess: ');
  1003. readsymlist(space+' Sym: ');
  1004. write (space,'Storedaccess: ');
  1005. readsymlist(space+' Sym: ');
  1006. end;
  1007. end;
  1008. ibfuncretsym :
  1009. begin
  1010. readcommonsym('Func return value ');
  1011. write (space,' Return Type: ');
  1012. readtype;
  1013. writeln(space,' Address: ',getlongint);
  1014. end;
  1015. iberror :
  1016. begin
  1017. Writeln('!! Error in PPU');
  1018. exit;
  1019. end;
  1020. ibendsyms :
  1021. break;
  1022. else
  1023. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  1024. end;
  1025. if not EndOfEntry then
  1026. Writeln('!! Entry has more information stored');
  1027. until false;
  1028. if (totalsyms<>-1) and (symcnt-1<>totalsyms) then
  1029. Writeln('!! Only read ',symcnt-1,' of ',totalsyms,' symbols');
  1030. end;
  1031. end;
  1032. {****************************************************************************
  1033. Read defintions Part
  1034. ****************************************************************************}
  1035. procedure getusedregisters_i386;
  1036. type
  1037. tregister = (R_NO,
  1038. R_EAX,R_ECX,R_EDX,R_EBX,R_ESP,R_EBP,R_ESI,R_EDI,
  1039. R_AX,R_CX,R_DX,R_BX,R_SP,R_BP,R_SI,R_DI,
  1040. R_AL,R_CL,R_DL,R_BL,R_AH,R_CH,R_BH,R_DH,
  1041. R_CS,R_DS,R_ES,R_SS,R_FS,R_GS,
  1042. R_ST,R_ST0,R_ST1,R_ST2,R_ST3,R_ST4,R_ST5,R_ST6,R_ST7,
  1043. R_DR0,R_DR1,R_DR2,R_DR3,R_DR6,R_DR7,
  1044. R_CR0,R_CR2,R_CR3,R_CR4,
  1045. R_TR3,R_TR4,R_TR5,R_TR6,R_TR7,
  1046. R_MM0,R_MM1,R_MM2,R_MM3,R_MM4,R_MM5,R_MM6,R_MM7,
  1047. R_XMM0,R_XMM1,R_XMM2,R_XMM3,R_XMM4,R_XMM5,R_XMM6,R_XMM7
  1048. );
  1049. tregisterset = set of tregister;
  1050. reg2strtable = array[tregister] of string[6];
  1051. const
  1052. std_reg2str : reg2strtable = ('',
  1053. 'eax','ecx','edx','ebx','esp','ebp','esi','edi',
  1054. 'ax','cx','dx','bx','sp','bp','si','di',
  1055. 'al','cl','dl','bl','ah','ch','bh','dh',
  1056. 'cs','ds','es','ss','fs','gs',
  1057. 'st','st(0)','st(1)','st(2)','st(3)','st(4)','st(5)','st(6)','st(7)',
  1058. 'dr0','dr1','dr2','dr3','dr6','dr7',
  1059. 'cr0','cr2','cr3','cr4',
  1060. 'tr3','tr4','tr5','tr6','tr7',
  1061. 'mm0','mm1','mm2','mm3','mm4','mm5','mm6','mm7',
  1062. 'xmm0','xmm1','xmm2','xmm3','xmm4','xmm5','xmm6','xmm7'
  1063. );
  1064. firstsaveintreg = R_EAX;
  1065. lastsaveintreg = R_EBX;
  1066. firstsavefpureg = R_NO;
  1067. lastsavefpureg = R_NO;
  1068. firstsavemmreg = R_MM0;
  1069. lastsavemmreg = R_MM7;
  1070. var
  1071. regs: tregisterset;
  1072. r: tregister;
  1073. first: boolean;
  1074. begin
  1075. first := true;
  1076. ppufile.getnormalset(regs);
  1077. for r := firstsaveintreg to lastsaveintreg do
  1078. if r in regs then
  1079. begin
  1080. if not first then
  1081. write(', ')
  1082. else
  1083. first := false;
  1084. write(std_reg2str[r])
  1085. end;
  1086. if (firstsavefpureg <> R_NO) then
  1087. for r := firstsavefpureg to lastsavefpureg do
  1088. if r in regs then
  1089. begin
  1090. if not first then
  1091. write(', ')
  1092. else
  1093. first := false;
  1094. write(std_reg2str[r])
  1095. end;
  1096. if (firstsavemmreg <> R_NO) then
  1097. for r := firstsavemmreg to lastsavemmreg do
  1098. if r in regs then
  1099. begin
  1100. if not first then
  1101. write(', ')
  1102. else
  1103. first := false;
  1104. write(std_reg2str[r])
  1105. end;
  1106. writeln;
  1107. end;
  1108. procedure readdefinitions(start_read : boolean);
  1109. type
  1110. tsettype = (normset,smallset,varset);
  1111. tbasetype = (
  1112. uvoid,
  1113. u8bit,u16bit,u32bit,u64bit,
  1114. s8bit,s16bit,s32bit,s64bit,
  1115. bool8bit,bool16bit,bool32bit,
  1116. uchar,uwidechar
  1117. );
  1118. tobjectdeftype = (odt_none,
  1119. odt_class,
  1120. odt_object,
  1121. odt_interfacecom,
  1122. odt_interfacecorba,
  1123. odt_cppclass
  1124. );
  1125. var
  1126. b : byte;
  1127. oldread_member : boolean;
  1128. totaldefs,l,j,
  1129. defcnt : longint;
  1130. calloption : tproccalloption;
  1131. regs : set of char;
  1132. begin
  1133. defcnt:=0;
  1134. with ppufile do
  1135. begin
  1136. if space<>'' then
  1137. Writeln(space,'-----------------------------');
  1138. if not start_read then
  1139. if readentry=ibstartdefs then
  1140. begin
  1141. totaldefs:=getlongint;
  1142. Writeln(space,'Number of definitions: ',totaldefs);
  1143. end
  1144. else
  1145. begin
  1146. totaldefs:=-1;
  1147. Writeln('!! ibstartdef not found');
  1148. end;
  1149. repeat
  1150. b:=readentry;
  1151. if not (b in [iberror,ibenddefs]) then
  1152. inc(defcnt);
  1153. case b of
  1154. ibpointerdef :
  1155. begin
  1156. readcommondef('Pointer definition');
  1157. write (space,' Pointed Type : ');
  1158. readtype;
  1159. writeln(space,' Is Far : ',(getbyte<>0));
  1160. end;
  1161. iborddef :
  1162. begin
  1163. readcommondef('Ordinal definition');
  1164. write (space,' Base type : ');
  1165. b:=getbyte;
  1166. case tbasetype(b) of
  1167. uvoid : writeln('uvoid');
  1168. u8bit : writeln('u8bit');
  1169. u16bit : writeln('u16bit');
  1170. u32bit : writeln('s32bit');
  1171. u64bit : writeln('u64bit');
  1172. s8bit : writeln('s8bit');
  1173. s16bit : writeln('s16bit');
  1174. s32bit : writeln('s32bit');
  1175. s64bit : writeln('s64bit');
  1176. bool8bit : writeln('bool8bit');
  1177. bool16bit : writeln('bool16bit');
  1178. bool32bit : writeln('bool32bit');
  1179. uchar : writeln('uchar');
  1180. uwidechar : writeln('uwidechar');
  1181. else writeln('!! Warning: Invalid base type ',b);
  1182. end;
  1183. writeln(space,' Range : ',getint64,' to ',getint64);
  1184. end;
  1185. ibfloatdef :
  1186. begin
  1187. readcommondef('Float definition');
  1188. writeln(space,' Float type : ',getbyte);
  1189. end;
  1190. ibarraydef :
  1191. begin
  1192. readcommondef('Array definition');
  1193. write (space,' Element type : ');
  1194. readtype;
  1195. write (space,' Range Type : ');
  1196. readtype;
  1197. writeln(space,' Range : ',getlongint,' to ',getlongint);
  1198. writeln(space,' Is Constructor : ',(getbyte<>0));
  1199. writeln(space,' Is Dynamic : ',(getbyte<>0));
  1200. end;
  1201. ibprocdef :
  1202. begin
  1203. readcommondef('Procedure definition');
  1204. calloption:=read_abstract_proc_def;
  1205. write (space,' Used IntRegs : ');
  1206. getnormalset(regs);
  1207. writeln('<not yet implemented>');
  1208. write (space,' Used OtherRegs : ');
  1209. getnormalset(regs);
  1210. writeln('<not yet implemented>');
  1211. {$ifdef OLDRA}
  1212. case ttargetcpu(header.cpu) of
  1213. i386 :
  1214. getusedregisters_i386
  1215. else
  1216. begin
  1217. getnormalset(regs);
  1218. writeln('<not yet implemented>');
  1219. end;
  1220. end;
  1221. {$endif OLDRA}
  1222. if (getbyte<>0) then
  1223. writeln(space,' Mangled name : ',getstring);
  1224. writeln(space,' Overload Number : ',getword);
  1225. writeln(space,' Number : ',getword);
  1226. write (space,' Class : ');
  1227. readdefref;
  1228. write (space,' Procsym : ');
  1229. readsymref;
  1230. write (space,' File Pos : ');
  1231. readposinfo;
  1232. write (space,' SymOptions : ');
  1233. readsymoptions;
  1234. if (calloption=pocall_inline) then
  1235. begin
  1236. write (space,' FuncretSym : ');
  1237. readdefref;
  1238. end;
  1239. space:=' '+space;
  1240. { parast }
  1241. readdefinitions(false);
  1242. readsymbols;
  1243. { localst }
  1244. if (calloption=pocall_inline) or
  1245. ((ppufile.header.flags and uf_local_browser) <> 0) then
  1246. begin
  1247. readdefinitions(false);
  1248. readsymbols;
  1249. end;
  1250. delete(space,1,4);
  1251. end;
  1252. ibprocvardef :
  1253. begin
  1254. readcommondef('Procedural type (ProcVar) definition');
  1255. read_abstract_proc_def;
  1256. end;
  1257. ibshortstringdef :
  1258. begin
  1259. readcommondef('ShortString definition');
  1260. writeln(space,' Length : ',getbyte);
  1261. end;
  1262. ibwidestringdef :
  1263. begin
  1264. readcommondef('WideString definition');
  1265. writeln(space,' Length : ',getlongint);
  1266. end;
  1267. ibansistringdef :
  1268. begin
  1269. readcommondef('AnsiString definition');
  1270. writeln(space,' Length : ',getlongint);
  1271. end;
  1272. iblongstringdef :
  1273. begin
  1274. readcommondef('Longstring definition');
  1275. writeln(space,' Length : ',getlongint);
  1276. end;
  1277. ibrecorddef :
  1278. begin
  1279. readcommondef('Record definition');
  1280. writeln(space,' Size : ',getlongint);
  1281. {read the record definitions and symbols}
  1282. space:=' '+space;
  1283. oldread_member:=read_member;
  1284. read_member:=true;
  1285. readdefinitions(false);
  1286. readsymbols;
  1287. read_member:=oldread_member;
  1288. Delete(space,1,4);
  1289. end;
  1290. ibobjectdef :
  1291. begin
  1292. readcommondef('Object/Class definition');
  1293. b:=getbyte;
  1294. write (space,' Type : ');
  1295. case tobjectdeftype(b) of
  1296. odt_class : writeln('class');
  1297. odt_object : writeln('object');
  1298. odt_interfacecom : writeln('interfacecom');
  1299. odt_interfacecorba : writeln('interfacecorba');
  1300. odt_cppclass : writeln('cppclass');
  1301. else writeln('!! Warning: Invalid object type ',b);
  1302. end;
  1303. writeln(space,' Size : ',getlongint);
  1304. writeln(space,' Vmt offset : ',getlongint);
  1305. writeln(space,' Name of Class : ',getstring);
  1306. write(space, ' Ancestor Class : ');
  1307. readdefref;
  1308. writeln(space,' Options : ',getlongint);
  1309. if tobjectdeftype(b) in [odt_interfacecom,odt_interfacecorba] then
  1310. begin
  1311. { IIDGUID }
  1312. for j:=1to 16 do
  1313. getbyte;
  1314. writeln(space,' IID String : ',getstring);
  1315. writeln(space,' Last VTable idx : ',getlongint);
  1316. end;
  1317. if tobjectdeftype(b) in [odt_class,odt_interfacecorba] then
  1318. begin
  1319. l:=getlongint;
  1320. writeln(space,' Impl Intf Count : ',l);
  1321. for j:=1 to l do
  1322. begin
  1323. write (space,' - Definition : ');
  1324. readdefref;
  1325. writeln(space,' IOffset : ',getlongint);
  1326. end;
  1327. end;
  1328. {read the record definitions and symbols}
  1329. space:=' '+space;
  1330. oldread_member:=read_member;
  1331. read_member:=true;
  1332. readdefinitions(false);
  1333. readsymbols;
  1334. read_member:=oldread_member;
  1335. Delete(space,1,4);
  1336. end;
  1337. ibfiledef :
  1338. begin
  1339. ReadCommonDef('File definition');
  1340. write (space,' Type : ');
  1341. case getbyte of
  1342. 0 : writeln('Text');
  1343. 1 : begin
  1344. writeln('Typed');
  1345. write (space,' File of Type : ');
  1346. Readtype;
  1347. end;
  1348. 2 : writeln('Untyped');
  1349. end;
  1350. end;
  1351. ibformaldef :
  1352. readcommondef('Generic Definition (void-typ)');
  1353. ibenumdef :
  1354. begin
  1355. readcommondef('Enumeration type definition');
  1356. write(space,'Base enumeration type : ');
  1357. readdefref;
  1358. writeln(space,' Smallest element : ',getlongint);
  1359. writeln(space,' Largest element : ',getlongint);
  1360. writeln(space,' Size : ',getlongint);
  1361. end;
  1362. ibclassrefdef :
  1363. begin
  1364. readcommondef('Class reference definition');
  1365. write (space,' Pointed Type : ');
  1366. readtype;
  1367. end;
  1368. ibsetdef :
  1369. begin
  1370. readcommondef('Set definition');
  1371. write (space,' Element type : ');
  1372. readtype;
  1373. b:=getbyte;
  1374. case tsettype(b) of
  1375. smallset : writeln(space,' Set with 32 Elements');
  1376. normset : writeln(space,' Set with 256 Elements');
  1377. varset : writeln(space,' Set with ',getlongint,' Elements');
  1378. else writeln('!! Warning: Invalid set type ',b);
  1379. end;
  1380. end;
  1381. ibvariantdef :
  1382. begin
  1383. readcommondef('Variant definition');
  1384. end;
  1385. iberror :
  1386. begin
  1387. Writeln('!! Error in PPU');
  1388. exit;
  1389. end;
  1390. ibenddefs :
  1391. break;
  1392. else
  1393. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  1394. end;
  1395. if not EndOfEntry then
  1396. Writeln('!! Entry has more information stored');
  1397. until false;
  1398. if (totaldefs<>-1) and (defcnt<>totaldefs) then
  1399. Writeln('!! Only read ',defcnt,' of ',totaldefs,' definitions');
  1400. end;
  1401. end;
  1402. {****************************************************************************
  1403. Read General Part
  1404. ****************************************************************************}
  1405. procedure readinterface;
  1406. var
  1407. b : byte;
  1408. sourcenumber,
  1409. unitnumber : word;
  1410. ucrc,uintfcrc : longint;
  1411. begin
  1412. with ppufile do
  1413. begin
  1414. repeat
  1415. b:=readentry;
  1416. case b of
  1417. ibmodulename :
  1418. Writeln('Module Name: ',getstring);
  1419. ibsourcefiles :
  1420. begin
  1421. sourcenumber:=1;
  1422. while not EndOfEntry do
  1423. begin
  1424. Writeln('Source file ',sourcenumber,' : ',getstring,' ',filetimestring(getlongint));
  1425. inc(sourcenumber);
  1426. end;
  1427. end;
  1428. ibusedmacros :
  1429. begin
  1430. while not EndOfEntry do
  1431. begin
  1432. Write('Conditional ',getstring);
  1433. b:=getbyte;
  1434. if boolean(b)=true then
  1435. write(' defined at startup')
  1436. else
  1437. write(' not defined at startup');
  1438. b:=getbyte;
  1439. if boolean(b)=true then
  1440. writeln(' was used')
  1441. else
  1442. writeln;
  1443. end;
  1444. end;
  1445. ibloadunit :
  1446. begin
  1447. unitnumber:=1;
  1448. while not EndOfEntry do
  1449. begin
  1450. write('Uses unit: ',getstring,' (Number: ',unitnumber,')');
  1451. ucrc:=getlongint;
  1452. uintfcrc:=getlongint;
  1453. write(' (Crc: ',hexstr(ucrc,8),', IntfcCrc: ',hexstr(uintfcrc,8),')');
  1454. if getbyte<>0 then
  1455. writeln(' (interface)')
  1456. else
  1457. writeln(' (implementation)');
  1458. inc(unitnumber);
  1459. end;
  1460. end;
  1461. iblinkunitofiles :
  1462. ReadLinkContainer('Link unit object file: ');
  1463. iblinkunitstaticlibs :
  1464. ReadLinkContainer('Link unit static lib: ');
  1465. iblinkunitsharedlibs :
  1466. ReadLinkContainer('Link unit shared lib: ');
  1467. iblinkotherofiles :
  1468. ReadLinkContainer('Link other object file: ');
  1469. iblinkotherstaticlibs :
  1470. ReadLinkContainer('Link other static lib: ');
  1471. iblinkothersharedlibs :
  1472. ReadLinkContainer('Link other shared lib: ');
  1473. iberror :
  1474. begin
  1475. Writeln('Error in PPU');
  1476. exit;
  1477. end;
  1478. ibendinterface :
  1479. break;
  1480. else
  1481. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  1482. end;
  1483. until false;
  1484. end;
  1485. end;
  1486. {****************************************************************************
  1487. Read Implementation Part
  1488. ****************************************************************************}
  1489. procedure readimplementation;
  1490. var
  1491. b : byte;
  1492. begin
  1493. with ppufile do
  1494. begin
  1495. repeat
  1496. b:=readentry;
  1497. case b of
  1498. ibasmsymbols :
  1499. ReadAsmSymbols;
  1500. iberror :
  1501. begin
  1502. Writeln('Error in PPU');
  1503. exit;
  1504. end;
  1505. ibendimplementation :
  1506. break;
  1507. else
  1508. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  1509. end;
  1510. until false;
  1511. end;
  1512. end;
  1513. {****************************************************************************
  1514. Read Browser Part
  1515. ****************************************************************************}
  1516. procedure readbrowser;
  1517. var
  1518. b : byte;
  1519. const indent : string = '';
  1520. begin
  1521. Writeln(indent,'Start of symtable browser');
  1522. indent:=indent+'**';
  1523. with ppufile do
  1524. begin
  1525. repeat
  1526. b:=readentry;
  1527. case b of
  1528. ibbeginsymtablebrowser :
  1529. begin
  1530. { here we must read object and record symtables !! }
  1531. indent:=indent+' ';
  1532. Writeln(indent,'Record/Object symtable');
  1533. readbrowser;
  1534. Indent:=Copy(Indent,1,Length(Indent)-2);
  1535. end;
  1536. ibsymref :
  1537. begin
  1538. readsymref;
  1539. readref;
  1540. end;
  1541. ibdefref :
  1542. begin
  1543. readdefref;
  1544. readref;
  1545. if ((ppufile.header.flags and uf_local_browser)<>0) and
  1546. (UnitIndex=0) then
  1547. begin
  1548. { parast and localst }
  1549. indent:=indent+' ';
  1550. b:=ppufile.readentry;
  1551. if b=ibbeginsymtablebrowser then
  1552. readbrowser;
  1553. b:=ppufile.readentry;
  1554. if b=ibbeginsymtablebrowser then
  1555. readbrowser;
  1556. Indent:=Copy(Indent,1,Length(Indent)-2);
  1557. end;
  1558. end;
  1559. iberror :
  1560. begin
  1561. Writeln('Error in PPU');
  1562. exit;
  1563. end;
  1564. ibendsymtablebrowser :
  1565. break;
  1566. else
  1567. begin
  1568. WriteLn('!! Skipping unsupported PPU Entry in Browser: ',b);
  1569. Halt;
  1570. end;
  1571. end;
  1572. until false;
  1573. end;
  1574. Indent:=Copy(Indent,1,Length(Indent)-2);
  1575. Writeln(Indent,'End of symtable browser');
  1576. end;
  1577. procedure dofile (filename : string);
  1578. var
  1579. b : byte;
  1580. begin
  1581. { reset }
  1582. space:='';
  1583. { fix filename }
  1584. if pos('.',filename)=0 then
  1585. filename:=filename+'.ppu';
  1586. ppufile:=tppufile.create(filename);
  1587. if not ppufile.openfile then
  1588. begin
  1589. writeln ('IO-Error when opening : ',filename,', Skipping');
  1590. exit;
  1591. end;
  1592. { PPU File is open, check for PPU Id }
  1593. if not ppufile.CheckPPUID then
  1594. begin
  1595. writeln(Filename,' : Not a valid PPU file, Skipping');
  1596. exit;
  1597. end;
  1598. { Check PPU Version }
  1599. Writeln('Analyzing ',filename,' (v',ppufile.GetPPUVersion,')');
  1600. if ppufile.GetPPUVersion<16 then
  1601. begin
  1602. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  1603. exit;
  1604. end;
  1605. { Write PPU Header Information }
  1606. if (verbose and v_header)<>0 then
  1607. begin
  1608. Writeln;
  1609. Writeln('Header');
  1610. Writeln('-------');
  1611. with ppufile.header do
  1612. begin
  1613. Writeln('Compiler version : ',ppufile.header.compiler shr 14,'.',
  1614. (ppufile.header.compiler shr 7) and $7f,'.',
  1615. ppufile.header.compiler and $7f);
  1616. WriteLn('Target processor : ',Cpu2Str(cpu));
  1617. WriteLn('Target operating system : ',Target2Str(target));
  1618. Writeln('Unit flags : ',PPUFlags2Str(flags));
  1619. Writeln('FileSize (w/o header) : ',size);
  1620. Writeln('Checksum : ',hexstr(checksum,8));
  1621. Writeln('Interface Checksum : ',hexstr(interface_checksum,8));
  1622. end;
  1623. end;
  1624. {read the general stuff}
  1625. if (verbose and v_interface)<>0 then
  1626. begin
  1627. Writeln;
  1628. Writeln('Interface section');
  1629. Writeln('------------------');
  1630. readinterface;
  1631. end
  1632. else
  1633. ppufile.skipuntilentry(ibendinterface);
  1634. {read the definitions}
  1635. if (verbose and v_defs)<>0 then
  1636. begin
  1637. Writeln;
  1638. Writeln('Interface definitions');
  1639. Writeln('----------------------');
  1640. readdefinitions(false);
  1641. end
  1642. else
  1643. ppufile.skipuntilentry(ibenddefs);
  1644. {read the symbols}
  1645. if (verbose and v_syms)<>0 then
  1646. begin
  1647. Writeln;
  1648. Writeln('Interface Symbols');
  1649. Writeln('------------------');
  1650. readsymbols;
  1651. end
  1652. else
  1653. ppufile.skipuntilentry(ibendsyms);
  1654. {read the implementation stuff}
  1655. if (verbose and v_implementation)<>0 then
  1656. begin
  1657. Writeln;
  1658. Writeln('Implementation section');
  1659. Writeln('-----------------------');
  1660. readimplementation;
  1661. end
  1662. else
  1663. ppufile.skipuntilentry(ibendimplementation);
  1664. {read the static browser units stuff}
  1665. if (ppufile.header.flags and uf_local_browser)<>0 then
  1666. begin
  1667. if (verbose and v_defs)<>0 then
  1668. begin
  1669. Writeln;
  1670. Writeln('Static definitions');
  1671. Writeln('----------------------');
  1672. readdefinitions(false);
  1673. end
  1674. else
  1675. ppufile.skipuntilentry(ibenddefs);
  1676. {read the symbols}
  1677. if (verbose and v_syms)<>0 then
  1678. begin
  1679. Writeln;
  1680. Writeln('Static Symbols');
  1681. Writeln('------------------');
  1682. readsymbols;
  1683. end;
  1684. end;
  1685. {read the browser units stuff}
  1686. if (ppufile.header.flags and uf_has_browser)<>0 then
  1687. begin
  1688. if (verbose and v_browser)<>0 then
  1689. begin
  1690. Writeln;
  1691. Writeln('Browser section');
  1692. Writeln('---------------');
  1693. UnitIndex:=0;
  1694. repeat
  1695. b:=ppufile.readentry;
  1696. if b = ibendbrowser then break;
  1697. if b=ibbeginsymtablebrowser then
  1698. begin
  1699. Writeln('Unit ',UnitIndex);
  1700. readbrowser;
  1701. Inc(UnitIndex);
  1702. end
  1703. else
  1704. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  1705. until false;
  1706. end;
  1707. end;
  1708. {read the static browser units stuff}
  1709. if (ppufile.header.flags and uf_local_browser)<>0 then
  1710. begin
  1711. if (verbose and v_browser)<>0 then
  1712. begin
  1713. Writeln;
  1714. Writeln('Static browser section');
  1715. Writeln('---------------');
  1716. UnitIndex:=0;
  1717. b:=ppufile.readentry;
  1718. if b=ibbeginsymtablebrowser then
  1719. readbrowser
  1720. else
  1721. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  1722. end;
  1723. end;
  1724. {shutdown ppufile}
  1725. ppufile.closefile;
  1726. ppufile.free;
  1727. Writeln;
  1728. end;
  1729. procedure help;
  1730. begin
  1731. writeln('usage: ppudump [options] <filename1> <filename2>...');
  1732. writeln;
  1733. writeln('[options] can be:');
  1734. writeln(' -V<verbose> Set verbosity to <verbose>');
  1735. writeln(' H - Show header info');
  1736. writeln(' I - Show interface');
  1737. writeln(' M - Show implementation');
  1738. writeln(' S - Show interface symbols');
  1739. writeln(' D - Show interface definitions');
  1740. writeln(' B - Show browser info');
  1741. writeln(' A - Show all');
  1742. writeln(' -? This helpscreen');
  1743. halt;
  1744. end;
  1745. var
  1746. startpara,
  1747. nrfile,i : longint;
  1748. para : string;
  1749. begin
  1750. writeln(Title+' '+Version);
  1751. writeln(Copyright);
  1752. writeln;
  1753. if paramcount<1 then
  1754. begin
  1755. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  1756. halt(1);
  1757. end;
  1758. { turn verbose on by default }
  1759. verbose:=v_all;
  1760. { read options }
  1761. startpara:=1;
  1762. while copy(paramstr(startpara),1,1)='-' do
  1763. begin
  1764. para:=paramstr(startpara);
  1765. case upcase(para[2]) of
  1766. 'V' : begin
  1767. verbose:=0;
  1768. for i:=3to length(para) do
  1769. case upcase(para[i]) of
  1770. 'H' : verbose:=verbose or v_header;
  1771. 'I' : verbose:=verbose or v_interface;
  1772. 'M' : verbose:=verbose or v_implementation;
  1773. 'D' : verbose:=verbose or v_defs;
  1774. 'S' : verbose:=verbose or v_syms;
  1775. 'B' : verbose:=verbose or v_browser;
  1776. 'A' : verbose:=verbose or v_all;
  1777. end;
  1778. end;
  1779. '?' : help;
  1780. end;
  1781. inc(startpara);
  1782. end;
  1783. { process files }
  1784. for nrfile:=startpara to paramcount do
  1785. dofile (paramstr(nrfile));
  1786. if has_errors then
  1787. Halt(1);
  1788. end.
  1789. {
  1790. $Log$
  1791. Revision 1.36 2003-03-17 15:54:22 peter
  1792. * store symoptions also for procdef
  1793. * check symoptions (private,public) when calculating possible
  1794. overload candidates
  1795. Revision 1.35 2003/01/03 22:16:29 peter
  1796. * updated for absolutesym and varsym
  1797. Revision 1.34 2002/11/17 16:32:04 carl
  1798. * memory optimization (3-4%) : cleanup of tai fields,
  1799. cleanup of tdef and tsym fields.
  1800. * make it work for m68k
  1801. Revision 1.33 2002/10/20 14:49:31 peter
  1802. * store original source time in ppu so it can be compared instead of
  1803. comparing with the ppu time
  1804. Revision 1.32 2002/10/06 12:25:53 florian
  1805. + dump of tdefoptions.df_unique
  1806. Revision 1.31 2002/09/27 21:22:04 carl
  1807. * update system information
  1808. Revision 1.30 2002/09/26 12:03:54 florian
  1809. + support of constguid and constwchar const symbols added
  1810. Revision 1.29 2002/08/20 16:54:40 peter
  1811. * write address of varsym always
  1812. Revision 1.28 2002/08/19 19:36:44 peter
  1813. * More fixes for cross unit inlining, all tnodes are now implemented
  1814. * Moved pocall_internconst to po_internconst because it is not a
  1815. calling type at all and it conflicted when inlining of these small
  1816. functions was requested
  1817. Revision 1.27 2002/08/15 15:15:56 carl
  1818. * jmpbuf size allocation for exceptions is now cpu specific (as it should)
  1819. * more generic nodes for maths
  1820. * several fixes for better m68k support
  1821. Revision 1.26 2002/08/11 13:24:20 peter
  1822. * saving of asmsymbols in ppu supported
  1823. * asmsymbollist global is removed and moved into a new class
  1824. tasmlibrarydata that will hold the info of a .a file which
  1825. corresponds with a single module. Added librarydata to tmodule
  1826. to keep the library info stored for the module. In the future the
  1827. objectfiles will also be stored to the tasmlibrarydata class
  1828. * all getlabel/newasmsymbol and friends are moved to the new class
  1829. Revision 1.25 2002/05/18 13:34:27 peter
  1830. * readded missing revisions
  1831. Revision 1.24 2002/05/16 19:46:54 carl
  1832. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1833. + try to fix temp allocation (still in ifdef)
  1834. + generic constructor calls
  1835. + start of tassembler / tmodulebase class cleanup
  1836. Revision 1.22 2002/05/12 16:53:18 peter
  1837. * moved entry and exitcode to ncgutil and cgobj
  1838. * foreach gets extra argument for passing local data to the
  1839. iterator function
  1840. * -CR checks also class typecasts at runtime by changing them
  1841. into as
  1842. * fixed compiler to cycle with the -CR option
  1843. * fixed stabs with elf writer, finally the global variables can
  1844. be watched
  1845. * removed a lot of routines from cga unit and replaced them by
  1846. calls to cgobj
  1847. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1848. u32bit then the other is typecasted also to u32bit without giving
  1849. a rangecheck warning/error.
  1850. * fixed pascal calling method with reversing also the high tree in
  1851. the parast, detected by tcalcst3 test
  1852. Revision 1.21 2002/04/23 13:12:58 peter
  1853. * updated for posinfo change
  1854. * updated for mangledname change
  1855. * include i386 registers, removed reference to cpubase unit that would
  1856. make ppudump dependent on the source processor
  1857. Revision 1.20 2002/04/15 19:15:09 carl
  1858. + write std_reg2str instead of gas registers
  1859. Revision 1.19 2002/04/14 17:02:19 carl
  1860. + att_reg2str -> gas_reg2str
  1861. Revision 1.18 2002/04/07 10:23:36 carl
  1862. + added vm / sparc targets
  1863. Revision 1.17 2002/04/04 19:06:14 peter
  1864. * removed unused units
  1865. * use tlocation.size in cg.a_*loc*() routines
  1866. Revision 1.16 2002/04/04 18:50:27 carl
  1867. + added wdosx support (patch from Pavel)
  1868. Revision 1.15 2002/03/31 20:26:42 jonas
  1869. + a_loadfpu_* and a_loadmm_* methods in tcg
  1870. * register allocation is now handled by a class and is mostly processor
  1871. independent (+rgobj.pas and i386/rgcpu.pas)
  1872. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  1873. * some small improvements and fixes to the optimizer
  1874. * some register allocation fixes
  1875. * some fpuvaroffset fixes in the unary minus node
  1876. * push/popusedregisters is now called rg.save/restoreusedregisters and
  1877. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  1878. also better optimizable)
  1879. * fixed and optimized register saving/restoring for new/dispose nodes
  1880. * LOC_FPU locations now also require their "register" field to be set to
  1881. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  1882. - list field removed of the tnode class because it's not used currently
  1883. and can cause hard-to-find bugs
  1884. Revision 1.14 2002/03/28 20:48:52 carl
  1885. - remove go32v1 support
  1886. Revision 1.13 2002/03/28 16:44:59 armin
  1887. + new flag if unit has local threadvars
  1888. Revision 1.12 2002/03/01 14:08:47 peter
  1889. * parasym added
  1890. Revision 1.11 2002/01/06 12:08:16 peter
  1891. * removed uauto from orddef, use new range_to_basetype generating
  1892. the correct ordinal type for a range
  1893. }