ppudump.pp 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019
  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. { Read abstract procdef and return if inline procdef }
  503. type
  504. tproccalloption=(pocall_none,
  505. pocall_cdecl, { procedure uses C styled calling }
  506. pocall_cppdecl, { C++ calling conventions }
  507. pocall_compilerproc, { Procedure is used for internal compiler calls }
  508. pocall_far16, { Far16 for OS/2 }
  509. pocall_fpccall, { FPC default calling }
  510. pocall_inline, { Procedure is an assembler macro }
  511. pocall_internproc, { Procedure has compiler magic}
  512. pocall_palmossyscall, { procedure is a PalmOS system call }
  513. pocall_pascal, { pascal standard left to right }
  514. pocall_register, { procedure uses register (fastcall) calling }
  515. pocall_safecall, { safe call calling conventions }
  516. pocall_stdcall, { procedure uses stdcall call }
  517. pocall_system { system call }
  518. );
  519. tproccalloptions=set of tproccalloption;
  520. tproctypeoption=(potype_none,
  521. potype_proginit, { Program initialization }
  522. potype_unitinit, { unit initialization }
  523. potype_unitfinalize, { unit finalization }
  524. potype_constructor, { Procedure is a constructor }
  525. potype_destructor, { Procedure is a destructor }
  526. potype_operator { Procedure defines an operator }
  527. );
  528. tproctypeoptions=set of tproctypeoption;
  529. tprocoption=(po_none,
  530. po_classmethod, { class method }
  531. po_virtualmethod, { Procedure is a virtual method }
  532. po_abstractmethod, { Procedure is an abstract method }
  533. po_staticmethod, { static method }
  534. po_overridingmethod, { method with override directive }
  535. po_methodpointer, { method pointer, only in procvardef, also used for 'with object do' }
  536. po_containsself, { self is passed explicit to the compiler }
  537. po_interrupt, { Procedure is an interrupt handler }
  538. po_iocheck, { IO checking should be done after a call to the procedure }
  539. po_assembler, { Procedure is written in assembler }
  540. po_msgstr, { method for string message handling }
  541. po_msgint, { method for int message handling }
  542. po_exports, { Procedure has export directive (needed for OS/2) }
  543. po_external, { Procedure is external (in other object or lib)}
  544. po_savestdregs, { save std regs cdecl and stdcall need that ! }
  545. po_saveregisters, { save all registers }
  546. po_overload, { procedure is declared with overload directive }
  547. po_varargs, { printf like arguments }
  548. po_leftright, { push arguments from left to right }
  549. po_clearstack, { caller clears the stack }
  550. po_internconst { procedure has constant evaluator intern }
  551. );
  552. tprocoptions=set of tprocoption;
  553. function read_abstract_proc_def:tproccalloption;
  554. type
  555. tproccallopt=record
  556. mask : tproccalloption;
  557. str : string[30];
  558. end;
  559. tproctypeopt=record
  560. mask : tproctypeoption;
  561. str : string[30];
  562. end;
  563. tprocopt=record
  564. mask : tprocoption;
  565. str : string[30];
  566. end;
  567. const
  568. proccalloptionStr : array[tproccalloption] of string[14]=('',
  569. 'CDecl',
  570. 'CPPDecl',
  571. 'CompilerProc',
  572. 'Far16',
  573. 'FPCCall',
  574. 'Inline',
  575. 'InternProc',
  576. 'PalmOSSysCall',
  577. 'Pascal',
  578. 'Register',
  579. 'SafeCall',
  580. 'StdCall',
  581. 'System'
  582. );
  583. proctypeopts=6;
  584. proctypeopt : array[1..proctypeopts] of tproctypeopt=(
  585. (mask:potype_proginit; str:'ProgInit'),
  586. (mask:potype_unitinit; str:'UnitInit'),
  587. (mask:potype_unitfinalize;str:'UnitFinalize'),
  588. (mask:potype_constructor; str:'Constructor'),
  589. (mask:potype_destructor; str:'Destructor'),
  590. (mask:potype_operator; str:'Operator')
  591. );
  592. procopts=21;
  593. procopt : array[1..procopts] of tprocopt=(
  594. (mask:po_classmethod; str:'ClassMethod'),
  595. (mask:po_virtualmethod; str:'VirtualMethod'),
  596. (mask:po_abstractmethod; str:'AbstractMethod'),
  597. (mask:po_staticmethod; str:'StaticMethod'),
  598. (mask:po_overridingmethod;str:'OverridingMethod'),
  599. (mask:po_methodpointer; str:'MethodPointer'),
  600. (mask:po_containsself; str:'ContainsSelf'),
  601. (mask:po_interrupt; str:'Interrupt'),
  602. (mask:po_iocheck; str:'IOCheck'),
  603. (mask:po_assembler; str:'Assembler'),
  604. (mask:po_msgstr; str:'MsgStr'),
  605. (mask:po_msgint; str:'MsgInt'),
  606. (mask:po_exports; str:'Exports'),
  607. (mask:po_external; str:'External'),
  608. (mask:po_savestdregs; str:'SaveStdRegs'),
  609. (mask:po_saveregisters; str:'SaveRegisters'),
  610. (mask:po_overload; str:'Overload'),
  611. (mask:po_varargs; str:'VarArgs'),
  612. (mask:po_leftright; str:'LeftRight'),
  613. (mask:po_clearstack; str:'ClearStack'),
  614. (mask:po_internconst; str:'InternConst')
  615. );
  616. tvarspez : array[0..3] of string[5]=('Value','Const','Var ','Out ');
  617. var
  618. proctypeoption : tproctypeoption;
  619. proccalloption : tproccalloption;
  620. procoptions : tprocoptions;
  621. i,params : longint;
  622. first : boolean;
  623. paraloc : array[0..9] of byte;
  624. begin
  625. write(space,' Return type : ');
  626. readtype;
  627. writeln(space,' Fpu used : ',ppufile.getbyte);
  628. proctypeoption:=tproctypeoption(ppufile.getbyte);
  629. if proctypeoption<>potype_none then
  630. begin
  631. write(space,' TypeOption : ');
  632. first:=true;
  633. for i:=1to proctypeopts do
  634. if (proctypeopt[i].mask=proctypeoption) then
  635. begin
  636. if first then
  637. first:=false
  638. else
  639. write(', ');
  640. write(proctypeopt[i].str);
  641. end;
  642. writeln;
  643. end;
  644. proccalloption:=tproccalloption(ppufile.getbyte);
  645. read_abstract_proc_def:=proccalloption;
  646. writeln(space,' CallOption : ',proccalloptionStr[proccalloption]);
  647. ppufile.getsmallset(procoptions);
  648. if procoptions<>[] then
  649. begin
  650. write(space,' Options : ');
  651. first:=true;
  652. for i:=1to procopts do
  653. if (procopt[i].mask in procoptions) then
  654. begin
  655. if first then
  656. first:=false
  657. else
  658. write(', ');
  659. write(procopt[i].str);
  660. end;
  661. writeln;
  662. end;
  663. params:=ppufile.getbyte;
  664. writeln(space,' Nr of parameters : ',params);
  665. if params>0 then
  666. begin
  667. repeat
  668. write(space,' - ',tvarspez[ppufile.getbyte],' : ');
  669. readtype;
  670. write(space,' Default : ');
  671. readsymref;
  672. write(space,' Symbol : ');
  673. readsymref;
  674. ppufile.getdata(paraloc,sizeof(paraloc));
  675. dec(params);
  676. until params=0;
  677. end;
  678. end;
  679. procedure readcommonsym(const s:string);
  680. type
  681. tsymoption=(sp_none,
  682. sp_public,
  683. sp_private,
  684. sp_published,
  685. sp_protected,
  686. sp_forwarddef,
  687. sp_static,
  688. sp_primary_typesym { this is for typesym, to know who is the primary symbol of a def }
  689. );
  690. tsymoptions=set of tsymoption;
  691. tsymopt=record
  692. mask : tsymoption;
  693. str : string[30];
  694. end;
  695. const
  696. symopts=7;
  697. symopt : array[1..symopts] of tsymopt=(
  698. (mask:sp_public; str:'Public'),
  699. (mask:sp_private; str:'Private'),
  700. (mask:sp_published; str:'Published'),
  701. (mask:sp_protected; str:'Protected'),
  702. (mask:sp_forwarddef; str:'ForwardDef'),
  703. (mask:sp_static; str:'Static'),
  704. (mask:sp_primary_typesym;str:'PrimaryTypeSym')
  705. );
  706. var
  707. symoptions : tsymoptions;
  708. i : longint;
  709. first : boolean;
  710. begin
  711. writeln(space,'** Symbol Nr. ',ppufile.getword,' **');
  712. writeln(space,s,ppufile.getstring);
  713. ppufile.getsmallset(symoptions);
  714. if symoptions<>[] then
  715. begin
  716. write(space,' File Pos: ');
  717. readposinfo;
  718. write(space,' SymOptions: ');
  719. first:=true;
  720. for i:=1to symopts do
  721. if (symopt[i].mask in symoptions) then
  722. begin
  723. if first then
  724. first:=false
  725. else
  726. write(', ');
  727. write(symopt[i].str);
  728. end;
  729. writeln;
  730. end;
  731. end;
  732. procedure readcommondef(const s:string);
  733. type
  734. tdefoption=(df_none,
  735. df_has_inittable, { init data has been generated }
  736. df_has_rttitable, { rtti data has been generated }
  737. df_unique
  738. );
  739. tdefoptions=set of tdefoption;
  740. var
  741. defopts : tdefoptions;
  742. begin
  743. writeln(space,'** Definition Nr. ',ppufile.getword,' **');
  744. writeln(space,s);
  745. write (space,' Type symbol : ');
  746. readsymref;
  747. ppufile.getsmallset(defopts);
  748. if df_unique in defopts then
  749. writeln (space,' Unique type symbol');
  750. if df_has_rttitable in defopts then
  751. begin
  752. write (space,' RTTI symbol : ');
  753. readsymref;
  754. end;
  755. if df_has_inittable in defopts then
  756. begin
  757. write (space,' Init symbol : ');
  758. readsymref;
  759. end;
  760. end;
  761. {****************************************************************************
  762. Read Symbols Part
  763. ****************************************************************************}
  764. procedure readsymbols;
  765. Const
  766. vo_is_C_var = 2;
  767. Type
  768. pguid = ^tguid;
  769. tguid = packed record
  770. D1: LongWord;
  771. D2: Word;
  772. D3: Word;
  773. D4: array[0..7] of Byte;
  774. end;
  775. absolutetyp = (tovar,toasm,toaddr);
  776. tconsttyp = (constnone,
  777. constord,conststring,constreal,constbool,
  778. constint,constchar,constset,constpointer,constnil,
  779. constresourcestring,constwstring,constwchar,constguid
  780. );
  781. var
  782. b : byte;
  783. pc : pchar;
  784. totalsyms,
  785. symcnt,
  786. i,j,len : longint;
  787. guid : tguid;
  788. begin
  789. symcnt:=1;
  790. with ppufile do
  791. begin
  792. if space<>'' then
  793. Writeln(space,'-----------------------------');
  794. if readentry=ibstartsyms then
  795. begin
  796. totalsyms:=getlongint;
  797. Writeln(space,'Number of symbols : ',totalsyms);
  798. Writeln(space,'Symtable datasize : ',getlongint);
  799. Writeln(space,'Symtable alignment: ',getlongint);
  800. end
  801. else
  802. begin
  803. totalsyms:=-1;
  804. Writeln('!! ibstartsym not found');
  805. end;
  806. repeat
  807. b:=readentry;
  808. if not (b in [iberror,ibendsyms]) then
  809. inc(symcnt);
  810. case b of
  811. ibunitsym :
  812. readcommonsym('Unit symbol ');
  813. iblabelsym :
  814. readcommonsym('Label symbol ');
  815. ibtypesym :
  816. begin
  817. readcommonsym('Type symbol ');
  818. write(space,' Result Type: ');
  819. readtype;
  820. end;
  821. ibprocsym :
  822. begin
  823. readcommonsym('Procedure symbol ');
  824. repeat
  825. write(space,' Definition: ');
  826. until not readdefref;
  827. end;
  828. ibconstsym :
  829. begin
  830. readcommonsym('Constant symbol ');
  831. b:=getbyte;
  832. case tconsttyp(b) of
  833. constord :
  834. begin
  835. write (space,'OrdinalType: ');
  836. readtype;
  837. writeln (space,' Value: ',getlongint)
  838. end;
  839. constpointer :
  840. begin
  841. write (space,' Pointer Type: ');
  842. readtype;
  843. writeln (space,' Value: ',getlongint)
  844. end;
  845. conststring,
  846. constresourcestring :
  847. begin
  848. len:=getlongint;
  849. getmem(pc,len+1);
  850. getdata(pc^,len);
  851. writeln(space,' Length: ',len);
  852. writeln(space,' Value: "',pc,'"');
  853. freemem(pc,len+1);
  854. if tconsttyp(b)=constresourcestring then
  855. writeln(space,' Index: ',getlongint);
  856. end;
  857. constreal :
  858. writeln(space,' Value: ',getreal);
  859. constbool :
  860. if getlongint<>0 then
  861. writeln (space,' Value : True')
  862. else
  863. writeln (space,' Value: False');
  864. constint :
  865. writeln(space,' Value: ',getint64);
  866. constchar :
  867. writeln(space,' Value: "'+chr(getlongint)+'"');
  868. constset :
  869. begin
  870. write (space,' Set Type: ');
  871. readtype;
  872. for i:=1to 4 do
  873. begin
  874. write (space,' Value: ');
  875. for j:=1to 8 do
  876. begin
  877. if j>1 then
  878. write(',');
  879. write(hexb(getbyte));
  880. end;
  881. writeln;
  882. end;
  883. end;
  884. constwstring:
  885. begin
  886. end;
  887. constwchar:
  888. writeln(space,' Value: #',getlongint);
  889. constguid:
  890. begin
  891. getdata(guid,sizeof(guid));
  892. write (space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-');
  893. for i:=0 to 7 do
  894. begin
  895. write(hexstr(guid.d4[i],2));
  896. if i=1 then write('-');
  897. end;
  898. writeln('}');
  899. end
  900. else
  901. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  902. end;
  903. end;
  904. ibvarsym :
  905. begin
  906. readcommonsym('Variable symbol ');
  907. writeln(space,' Type: ',getbyte);
  908. writeln(space,' Address: ',getlongint);
  909. write (space,' Var Type: ');
  910. readtype;
  911. i:=getlongint;
  912. writeln(space,' Options: ',i);
  913. if (i and vo_is_C_var)<>0 then
  914. writeln(space,' Mangledname: ',getstring);
  915. end;
  916. ibenumsym :
  917. begin
  918. readcommonsym('Enumeration symbol ');
  919. write (space,' Definition: ');
  920. readdefref;
  921. writeln(space,' Value: ',getlongint);
  922. end;
  923. ibsyssym :
  924. begin
  925. readcommonsym('Internal system symbol ');
  926. writeln(space,' Internal Nr: ',getlongint);
  927. end;
  928. ibrttisym :
  929. begin
  930. readcommonsym('RTTI symbol ');
  931. writeln(space,' RTTI Type: ',getbyte);
  932. end;
  933. ibtypedconstsym :
  934. begin
  935. readcommonsym('Typed constant ');
  936. write (space,' Constant Type: ');
  937. readtype;
  938. writeln(space,' ReallyConst: ',(getbyte<>0));
  939. end;
  940. ibabsolutesym :
  941. begin
  942. readcommonsym('Absolute variable symbol ');
  943. writeln(space,' Type: ',getbyte);
  944. if read_member then
  945. writeln(space,' Address: ',getlongint);
  946. write (space,' Var Type: ');
  947. readtype;
  948. writeln(space,' Options: ',getlongint);
  949. Write (space,' Relocated to ');
  950. b:=getbyte;
  951. case absolutetyp(b) of
  952. tovar :
  953. Writeln('Name : ',getstring);
  954. toasm :
  955. Writeln('Assembler name : ',getstring);
  956. toaddr :
  957. begin
  958. Write('Address : ',getlongint);
  959. WriteLn(' (Far: ',getbyte<>0,')');
  960. end;
  961. else
  962. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  963. end;
  964. end;
  965. ibpropertysym :
  966. begin
  967. readcommonsym('Property ');
  968. i:=getlongint;
  969. writeln(space,' PropOptions: ',i);
  970. if (i and 32)>0 then
  971. begin
  972. write (space,'OverrideProp: ');
  973. readsymref;
  974. end
  975. else
  976. begin
  977. write (space,' Prop Type: ');
  978. readtype;
  979. writeln(space,' Index: ',getlongint);
  980. writeln(space,' Default: ',getlongint);
  981. write (space,' Index Type: ');
  982. readtype;
  983. write (space,' Readaccess: ');
  984. readsymlist(space+' Sym: ');
  985. write (space,' Writeaccess: ');
  986. readsymlist(space+' Sym: ');
  987. write (space,'Storedaccess: ');
  988. readsymlist(space+' Sym: ');
  989. end;
  990. end;
  991. ibfuncretsym :
  992. begin
  993. readcommonsym('Func return value ');
  994. write (space,' Return Type: ');
  995. readtype;
  996. writeln(space,' Address: ',getlongint);
  997. end;
  998. iberror :
  999. begin
  1000. Writeln('!! Error in PPU');
  1001. exit;
  1002. end;
  1003. ibendsyms :
  1004. break;
  1005. else
  1006. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  1007. end;
  1008. if not EndOfEntry then
  1009. Writeln('!! Entry has more information stored');
  1010. until false;
  1011. if (totalsyms<>-1) and (symcnt-1<>totalsyms) then
  1012. Writeln('!! Only read ',symcnt-1,' of ',totalsyms,' symbols');
  1013. end;
  1014. end;
  1015. {****************************************************************************
  1016. Read defintions Part
  1017. ****************************************************************************}
  1018. procedure getusedregisters_i386;
  1019. type
  1020. tregister = (R_NO,
  1021. R_EAX,R_ECX,R_EDX,R_EBX,R_ESP,R_EBP,R_ESI,R_EDI,
  1022. R_AX,R_CX,R_DX,R_BX,R_SP,R_BP,R_SI,R_DI,
  1023. R_AL,R_CL,R_DL,R_BL,R_AH,R_CH,R_BH,R_DH,
  1024. R_CS,R_DS,R_ES,R_SS,R_FS,R_GS,
  1025. R_ST,R_ST0,R_ST1,R_ST2,R_ST3,R_ST4,R_ST5,R_ST6,R_ST7,
  1026. R_DR0,R_DR1,R_DR2,R_DR3,R_DR6,R_DR7,
  1027. R_CR0,R_CR2,R_CR3,R_CR4,
  1028. R_TR3,R_TR4,R_TR5,R_TR6,R_TR7,
  1029. R_MM0,R_MM1,R_MM2,R_MM3,R_MM4,R_MM5,R_MM6,R_MM7,
  1030. R_XMM0,R_XMM1,R_XMM2,R_XMM3,R_XMM4,R_XMM5,R_XMM6,R_XMM7
  1031. );
  1032. tregisterset = set of tregister;
  1033. reg2strtable = array[tregister] of string[6];
  1034. const
  1035. std_reg2str : reg2strtable = ('',
  1036. 'eax','ecx','edx','ebx','esp','ebp','esi','edi',
  1037. 'ax','cx','dx','bx','sp','bp','si','di',
  1038. 'al','cl','dl','bl','ah','ch','bh','dh',
  1039. 'cs','ds','es','ss','fs','gs',
  1040. 'st','st(0)','st(1)','st(2)','st(3)','st(4)','st(5)','st(6)','st(7)',
  1041. 'dr0','dr1','dr2','dr3','dr6','dr7',
  1042. 'cr0','cr2','cr3','cr4',
  1043. 'tr3','tr4','tr5','tr6','tr7',
  1044. 'mm0','mm1','mm2','mm3','mm4','mm5','mm6','mm7',
  1045. 'xmm0','xmm1','xmm2','xmm3','xmm4','xmm5','xmm6','xmm7'
  1046. );
  1047. firstsaveintreg = R_EAX;
  1048. lastsaveintreg = R_EBX;
  1049. firstsavefpureg = R_NO;
  1050. lastsavefpureg = R_NO;
  1051. firstsavemmreg = R_MM0;
  1052. lastsavemmreg = R_MM7;
  1053. var
  1054. regs: tregisterset;
  1055. r: tregister;
  1056. first: boolean;
  1057. begin
  1058. first := true;
  1059. ppufile.getnormalset(regs);
  1060. for r := firstsaveintreg to lastsaveintreg do
  1061. if r in regs then
  1062. begin
  1063. if not first then
  1064. write(', ')
  1065. else
  1066. first := false;
  1067. write(std_reg2str[r])
  1068. end;
  1069. if (firstsavefpureg <> R_NO) then
  1070. for r := firstsavefpureg to lastsavefpureg do
  1071. if r in regs then
  1072. begin
  1073. if not first then
  1074. write(', ')
  1075. else
  1076. first := false;
  1077. write(std_reg2str[r])
  1078. end;
  1079. if (firstsavemmreg <> R_NO) then
  1080. for r := firstsavemmreg to lastsavemmreg do
  1081. if r in regs then
  1082. begin
  1083. if not first then
  1084. write(', ')
  1085. else
  1086. first := false;
  1087. write(std_reg2str[r])
  1088. end;
  1089. writeln;
  1090. end;
  1091. procedure readdefinitions(start_read : boolean);
  1092. type
  1093. tsettype = (normset,smallset,varset);
  1094. tbasetype = (
  1095. uvoid,
  1096. u8bit,u16bit,u32bit,u64bit,
  1097. s8bit,s16bit,s32bit,s64bit,
  1098. bool8bit,bool16bit,bool32bit,
  1099. uchar,uwidechar
  1100. );
  1101. tobjectdeftype = (odt_none,
  1102. odt_class,
  1103. odt_object,
  1104. odt_interfacecom,
  1105. odt_interfacecorba,
  1106. odt_cppclass
  1107. );
  1108. var
  1109. b : byte;
  1110. oldread_member : boolean;
  1111. totaldefs,l,j,
  1112. defcnt : longint;
  1113. calloption : tproccalloption;
  1114. regs : set of char;
  1115. begin
  1116. defcnt:=0;
  1117. with ppufile do
  1118. begin
  1119. if space<>'' then
  1120. Writeln(space,'-----------------------------');
  1121. if not start_read then
  1122. if readentry=ibstartdefs then
  1123. begin
  1124. totaldefs:=getlongint;
  1125. Writeln(space,'Number of definitions: ',totaldefs);
  1126. end
  1127. else
  1128. begin
  1129. totaldefs:=-1;
  1130. Writeln('!! ibstartdef not found');
  1131. end;
  1132. repeat
  1133. b:=readentry;
  1134. if not (b in [iberror,ibenddefs]) then
  1135. inc(defcnt);
  1136. case b of
  1137. ibpointerdef :
  1138. begin
  1139. readcommondef('Pointer definition');
  1140. write (space,' Pointed Type : ');
  1141. readtype;
  1142. writeln(space,' Is Far : ',(getbyte<>0));
  1143. end;
  1144. iborddef :
  1145. begin
  1146. readcommondef('Ordinal definition');
  1147. write (space,' Base type : ');
  1148. b:=getbyte;
  1149. case tbasetype(b) of
  1150. uvoid : writeln('uvoid');
  1151. u8bit : writeln('u8bit');
  1152. u16bit : writeln('u16bit');
  1153. u32bit : writeln('s32bit');
  1154. u64bit : writeln('u64bit');
  1155. s8bit : writeln('s8bit');
  1156. s16bit : writeln('s16bit');
  1157. s32bit : writeln('s32bit');
  1158. s64bit : writeln('s64bit');
  1159. bool8bit : writeln('bool8bit');
  1160. bool16bit : writeln('bool16bit');
  1161. bool32bit : writeln('bool32bit');
  1162. uchar : writeln('uchar');
  1163. uwidechar : writeln('uwidechar');
  1164. else writeln('!! Warning: Invalid base type ',b);
  1165. end;
  1166. writeln(space,' Range : ',getint64,' to ',getint64);
  1167. end;
  1168. ibfloatdef :
  1169. begin
  1170. readcommondef('Float definition');
  1171. writeln(space,' Float type : ',getbyte);
  1172. end;
  1173. ibarraydef :
  1174. begin
  1175. readcommondef('Array definition');
  1176. write (space,' Element type : ');
  1177. readtype;
  1178. write (space,' Range Type : ');
  1179. readtype;
  1180. writeln(space,' Range : ',getlongint,' to ',getlongint);
  1181. writeln(space,' Is Constructor : ',(getbyte<>0));
  1182. writeln(space,' Is Dynamic : ',(getbyte<>0));
  1183. end;
  1184. ibprocdef :
  1185. begin
  1186. readcommondef('Procedure definition');
  1187. calloption:=read_abstract_proc_def;
  1188. write (space,' Used Registers : ');
  1189. case ttargetcpu(header.cpu) of
  1190. i386 :
  1191. getusedregisters_i386
  1192. else
  1193. begin
  1194. getnormalset(regs);
  1195. writeln('<not yet implemented>');
  1196. end;
  1197. end;
  1198. if (getbyte<>0) then
  1199. writeln(space,' Mangled name : ',getstring);
  1200. writeln(space,' Overload Number : ',getword);
  1201. writeln(space,' Number : ',getword);
  1202. write (space,' Class : ');
  1203. readdefref;
  1204. write (space,' Procsym : ');
  1205. readsymref;
  1206. write (space,' File Pos : ');
  1207. readposinfo;
  1208. if (calloption=pocall_inline) then
  1209. begin
  1210. write (space,' FuncretSym : ');
  1211. readdefref;
  1212. end;
  1213. space:=' '+space;
  1214. { parast }
  1215. readdefinitions(false);
  1216. readsymbols;
  1217. { localst }
  1218. if (calloption=pocall_inline) or
  1219. ((ppufile.header.flags and uf_local_browser) <> 0) then
  1220. begin
  1221. readdefinitions(false);
  1222. readsymbols;
  1223. end;
  1224. delete(space,1,4);
  1225. end;
  1226. ibprocvardef :
  1227. begin
  1228. readcommondef('Procedural type (ProcVar) definition');
  1229. read_abstract_proc_def;
  1230. end;
  1231. ibshortstringdef :
  1232. begin
  1233. readcommondef('ShortString definition');
  1234. writeln(space,' Length : ',getbyte);
  1235. end;
  1236. ibwidestringdef :
  1237. begin
  1238. readcommondef('WideString definition');
  1239. writeln(space,' Length : ',getlongint);
  1240. end;
  1241. ibansistringdef :
  1242. begin
  1243. readcommondef('AnsiString definition');
  1244. writeln(space,' Length : ',getlongint);
  1245. end;
  1246. iblongstringdef :
  1247. begin
  1248. readcommondef('Longstring definition');
  1249. writeln(space,' Length : ',getlongint);
  1250. end;
  1251. ibrecorddef :
  1252. begin
  1253. readcommondef('Record definition');
  1254. writeln(space,' Size : ',getlongint);
  1255. {read the record definitions and symbols}
  1256. space:=' '+space;
  1257. oldread_member:=read_member;
  1258. read_member:=true;
  1259. readdefinitions(false);
  1260. readsymbols;
  1261. read_member:=oldread_member;
  1262. Delete(space,1,4);
  1263. end;
  1264. ibobjectdef :
  1265. begin
  1266. readcommondef('Object/Class definition');
  1267. b:=getbyte;
  1268. write (space,' Type : ');
  1269. case tobjectdeftype(b) of
  1270. odt_class : writeln('class');
  1271. odt_object : writeln('object');
  1272. odt_interfacecom : writeln('interfacecom');
  1273. odt_interfacecorba : writeln('interfacecorba');
  1274. odt_cppclass : writeln('cppclass');
  1275. else writeln('!! Warning: Invalid object type ',b);
  1276. end;
  1277. writeln(space,' Size : ',getlongint);
  1278. writeln(space,' Vmt offset : ',getlongint);
  1279. writeln(space,' Name of Class : ',getstring);
  1280. write(space, ' Ancestor Class : ');
  1281. readdefref;
  1282. writeln(space,' Options : ',getlongint);
  1283. if tobjectdeftype(b) in [odt_interfacecom,odt_interfacecorba] then
  1284. begin
  1285. { IIDGUID }
  1286. for j:=1to 16 do
  1287. getbyte;
  1288. writeln(space,' IID String : ',getstring);
  1289. writeln(space,' Last VTable idx : ',getlongint);
  1290. end;
  1291. if tobjectdeftype(b) in [odt_class,odt_interfacecorba] then
  1292. begin
  1293. l:=getlongint;
  1294. writeln(space,' Impl Intf Count : ',l);
  1295. for j:=1 to l do
  1296. begin
  1297. write (space,' - Definition : ');
  1298. readdefref;
  1299. writeln(space,' IOffset : ',getlongint);
  1300. end;
  1301. end;
  1302. {read the record definitions and symbols}
  1303. space:=' '+space;
  1304. oldread_member:=read_member;
  1305. read_member:=true;
  1306. readdefinitions(false);
  1307. readsymbols;
  1308. read_member:=oldread_member;
  1309. Delete(space,1,4);
  1310. end;
  1311. ibfiledef :
  1312. begin
  1313. ReadCommonDef('File definition');
  1314. write (space,' Type : ');
  1315. case getbyte of
  1316. 0 : writeln('Text');
  1317. 1 : begin
  1318. writeln('Typed');
  1319. write (space,' File of Type : ');
  1320. Readtype;
  1321. end;
  1322. 2 : writeln('Untyped');
  1323. end;
  1324. end;
  1325. ibformaldef :
  1326. readcommondef('Generic Definition (void-typ)');
  1327. ibenumdef :
  1328. begin
  1329. readcommondef('Enumeration type definition');
  1330. write(space,'Base enumeration type : ');
  1331. readdefref;
  1332. writeln(space,' Smallest element : ',getlongint);
  1333. writeln(space,' Largest element : ',getlongint);
  1334. writeln(space,' Size : ',getlongint);
  1335. end;
  1336. ibclassrefdef :
  1337. begin
  1338. readcommondef('Class reference definition');
  1339. write (space,' Pointed Type : ');
  1340. readtype;
  1341. end;
  1342. ibsetdef :
  1343. begin
  1344. readcommondef('Set definition');
  1345. write (space,' Element type : ');
  1346. readtype;
  1347. b:=getbyte;
  1348. case tsettype(b) of
  1349. smallset : writeln(space,' Set with 32 Elements');
  1350. normset : writeln(space,' Set with 256 Elements');
  1351. varset : writeln(space,' Set with ',getlongint,' Elements');
  1352. else writeln('!! Warning: Invalid set type ',b);
  1353. end;
  1354. end;
  1355. ibvariantdef :
  1356. begin
  1357. readcommondef('Variant definition');
  1358. end;
  1359. iberror :
  1360. begin
  1361. Writeln('!! Error in PPU');
  1362. exit;
  1363. end;
  1364. ibenddefs :
  1365. break;
  1366. else
  1367. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  1368. end;
  1369. if not EndOfEntry then
  1370. Writeln('!! Entry has more information stored');
  1371. until false;
  1372. if (totaldefs<>-1) and (defcnt<>totaldefs) then
  1373. Writeln('!! Only read ',defcnt,' of ',totaldefs,' definitions');
  1374. end;
  1375. end;
  1376. {****************************************************************************
  1377. Read General Part
  1378. ****************************************************************************}
  1379. procedure readinterface;
  1380. var
  1381. b : byte;
  1382. sourcenumber,
  1383. unitnumber : word;
  1384. ucrc,uintfcrc : longint;
  1385. begin
  1386. with ppufile do
  1387. begin
  1388. repeat
  1389. b:=readentry;
  1390. case b of
  1391. ibmodulename :
  1392. Writeln('Module Name: ',getstring);
  1393. ibsourcefiles :
  1394. begin
  1395. sourcenumber:=1;
  1396. while not EndOfEntry do
  1397. begin
  1398. Writeln('Source file ',sourcenumber,' : ',getstring,' ',filetimestring(getlongint));
  1399. inc(sourcenumber);
  1400. end;
  1401. end;
  1402. ibusedmacros :
  1403. begin
  1404. while not EndOfEntry do
  1405. begin
  1406. Write('Conditional ',getstring);
  1407. b:=getbyte;
  1408. if boolean(b)=true then
  1409. write(' defined at startup')
  1410. else
  1411. write(' not defined at startup');
  1412. b:=getbyte;
  1413. if boolean(b)=true then
  1414. writeln(' was used')
  1415. else
  1416. writeln;
  1417. end;
  1418. end;
  1419. ibloadunit :
  1420. begin
  1421. unitnumber:=1;
  1422. while not EndOfEntry do
  1423. begin
  1424. write('Uses unit: ',getstring,' (Number: ',unitnumber,')');
  1425. ucrc:=getlongint;
  1426. uintfcrc:=getlongint;
  1427. write(' (Crc: ',hexstr(ucrc,8),', IntfcCrc: ',hexstr(uintfcrc,8),')');
  1428. if getbyte<>0 then
  1429. writeln(' (interface)')
  1430. else
  1431. writeln(' (implementation)');
  1432. inc(unitnumber);
  1433. end;
  1434. end;
  1435. iblinkunitofiles :
  1436. ReadLinkContainer('Link unit object file: ');
  1437. iblinkunitstaticlibs :
  1438. ReadLinkContainer('Link unit static lib: ');
  1439. iblinkunitsharedlibs :
  1440. ReadLinkContainer('Link unit shared lib: ');
  1441. iblinkotherofiles :
  1442. ReadLinkContainer('Link other object file: ');
  1443. iblinkotherstaticlibs :
  1444. ReadLinkContainer('Link other static lib: ');
  1445. iblinkothersharedlibs :
  1446. ReadLinkContainer('Link other shared lib: ');
  1447. iberror :
  1448. begin
  1449. Writeln('Error in PPU');
  1450. exit;
  1451. end;
  1452. ibendinterface :
  1453. break;
  1454. else
  1455. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  1456. end;
  1457. until false;
  1458. end;
  1459. end;
  1460. {****************************************************************************
  1461. Read Implementation Part
  1462. ****************************************************************************}
  1463. procedure readimplementation;
  1464. var
  1465. b : byte;
  1466. begin
  1467. with ppufile do
  1468. begin
  1469. repeat
  1470. b:=readentry;
  1471. case b of
  1472. ibasmsymbols :
  1473. ReadAsmSymbols;
  1474. iberror :
  1475. begin
  1476. Writeln('Error in PPU');
  1477. exit;
  1478. end;
  1479. ibendimplementation :
  1480. break;
  1481. else
  1482. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  1483. end;
  1484. until false;
  1485. end;
  1486. end;
  1487. {****************************************************************************
  1488. Read Browser Part
  1489. ****************************************************************************}
  1490. procedure readbrowser;
  1491. var
  1492. b : byte;
  1493. const indent : string = '';
  1494. begin
  1495. Writeln(indent,'Start of symtable browser');
  1496. indent:=indent+'**';
  1497. with ppufile do
  1498. begin
  1499. repeat
  1500. b:=readentry;
  1501. case b of
  1502. ibbeginsymtablebrowser :
  1503. begin
  1504. { here we must read object and record symtables !! }
  1505. indent:=indent+' ';
  1506. Writeln(indent,'Record/Object symtable');
  1507. readbrowser;
  1508. Indent:=Copy(Indent,1,Length(Indent)-2);
  1509. end;
  1510. ibsymref :
  1511. begin
  1512. readsymref;
  1513. readref;
  1514. end;
  1515. ibdefref :
  1516. begin
  1517. readdefref;
  1518. readref;
  1519. if ((ppufile.header.flags and uf_local_browser)<>0) and
  1520. (UnitIndex=0) then
  1521. begin
  1522. { parast and localst }
  1523. indent:=indent+' ';
  1524. b:=ppufile.readentry;
  1525. if b=ibbeginsymtablebrowser then
  1526. readbrowser;
  1527. b:=ppufile.readentry;
  1528. if b=ibbeginsymtablebrowser then
  1529. readbrowser;
  1530. Indent:=Copy(Indent,1,Length(Indent)-2);
  1531. end;
  1532. end;
  1533. iberror :
  1534. begin
  1535. Writeln('Error in PPU');
  1536. exit;
  1537. end;
  1538. ibendsymtablebrowser :
  1539. break;
  1540. else
  1541. begin
  1542. WriteLn('!! Skipping unsupported PPU Entry in Browser: ',b);
  1543. Halt;
  1544. end;
  1545. end;
  1546. until false;
  1547. end;
  1548. Indent:=Copy(Indent,1,Length(Indent)-2);
  1549. Writeln(Indent,'End of symtable browser');
  1550. end;
  1551. procedure dofile (filename : string);
  1552. var
  1553. b : byte;
  1554. begin
  1555. { reset }
  1556. space:='';
  1557. { fix filename }
  1558. if pos('.',filename)=0 then
  1559. filename:=filename+'.ppu';
  1560. ppufile:=tppufile.create(filename);
  1561. if not ppufile.openfile then
  1562. begin
  1563. writeln ('IO-Error when opening : ',filename,', Skipping');
  1564. exit;
  1565. end;
  1566. { PPU File is open, check for PPU Id }
  1567. if not ppufile.CheckPPUID then
  1568. begin
  1569. writeln(Filename,' : Not a valid PPU file, Skipping');
  1570. exit;
  1571. end;
  1572. { Check PPU Version }
  1573. Writeln('Analyzing ',filename,' (v',ppufile.GetPPUVersion,')');
  1574. if ppufile.GetPPUVersion<16 then
  1575. begin
  1576. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  1577. exit;
  1578. end;
  1579. { Write PPU Header Information }
  1580. if (verbose and v_header)<>0 then
  1581. begin
  1582. Writeln;
  1583. Writeln('Header');
  1584. Writeln('-------');
  1585. with ppufile.header do
  1586. begin
  1587. Writeln('Compiler version : ',ppufile.header.compiler shr 14,'.',
  1588. (ppufile.header.compiler shr 7) and $7f,'.',
  1589. ppufile.header.compiler and $7f);
  1590. WriteLn('Target processor : ',Cpu2Str(cpu));
  1591. WriteLn('Target operating system : ',Target2Str(target));
  1592. Writeln('Unit flags : ',PPUFlags2Str(flags));
  1593. Writeln('FileSize (w/o header) : ',size);
  1594. Writeln('Checksum : ',hexstr(checksum,8));
  1595. Writeln('Interface Checksum : ',hexstr(interface_checksum,8));
  1596. end;
  1597. end;
  1598. {read the general stuff}
  1599. if (verbose and v_interface)<>0 then
  1600. begin
  1601. Writeln;
  1602. Writeln('Interface section');
  1603. Writeln('------------------');
  1604. readinterface;
  1605. end
  1606. else
  1607. ppufile.skipuntilentry(ibendinterface);
  1608. {read the definitions}
  1609. if (verbose and v_defs)<>0 then
  1610. begin
  1611. Writeln;
  1612. Writeln('Interface definitions');
  1613. Writeln('----------------------');
  1614. readdefinitions(false);
  1615. end
  1616. else
  1617. ppufile.skipuntilentry(ibenddefs);
  1618. {read the symbols}
  1619. if (verbose and v_syms)<>0 then
  1620. begin
  1621. Writeln;
  1622. Writeln('Interface Symbols');
  1623. Writeln('------------------');
  1624. readsymbols;
  1625. end
  1626. else
  1627. ppufile.skipuntilentry(ibendsyms);
  1628. {read the implementation stuff}
  1629. if (verbose and v_implementation)<>0 then
  1630. begin
  1631. Writeln;
  1632. Writeln('Implementation section');
  1633. Writeln('-----------------------');
  1634. readimplementation;
  1635. end
  1636. else
  1637. ppufile.skipuntilentry(ibendimplementation);
  1638. {read the static browser units stuff}
  1639. if (ppufile.header.flags and uf_local_browser)<>0 then
  1640. begin
  1641. if (verbose and v_defs)<>0 then
  1642. begin
  1643. Writeln;
  1644. Writeln('Static definitions');
  1645. Writeln('----------------------');
  1646. readdefinitions(false);
  1647. end
  1648. else
  1649. ppufile.skipuntilentry(ibenddefs);
  1650. {read the symbols}
  1651. if (verbose and v_syms)<>0 then
  1652. begin
  1653. Writeln;
  1654. Writeln('Static Symbols');
  1655. Writeln('------------------');
  1656. readsymbols;
  1657. end;
  1658. end;
  1659. {read the browser units stuff}
  1660. if (ppufile.header.flags and uf_has_browser)<>0 then
  1661. begin
  1662. if (verbose and v_browser)<>0 then
  1663. begin
  1664. Writeln;
  1665. Writeln('Browser section');
  1666. Writeln('---------------');
  1667. UnitIndex:=0;
  1668. repeat
  1669. b:=ppufile.readentry;
  1670. if b = ibendbrowser then break;
  1671. if b=ibbeginsymtablebrowser then
  1672. begin
  1673. Writeln('Unit ',UnitIndex);
  1674. readbrowser;
  1675. Inc(UnitIndex);
  1676. end
  1677. else
  1678. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  1679. until false;
  1680. end;
  1681. end;
  1682. {read the static browser units stuff}
  1683. if (ppufile.header.flags and uf_local_browser)<>0 then
  1684. begin
  1685. if (verbose and v_browser)<>0 then
  1686. begin
  1687. Writeln;
  1688. Writeln('Static browser section');
  1689. Writeln('---------------');
  1690. UnitIndex:=0;
  1691. b:=ppufile.readentry;
  1692. if b=ibbeginsymtablebrowser then
  1693. readbrowser
  1694. else
  1695. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  1696. end;
  1697. end;
  1698. {shutdown ppufile}
  1699. ppufile.closefile;
  1700. ppufile.free;
  1701. Writeln;
  1702. end;
  1703. procedure help;
  1704. begin
  1705. writeln('usage: ppudump [options] <filename1> <filename2>...');
  1706. writeln;
  1707. writeln('[options] can be:');
  1708. writeln(' -V<verbose> Set verbosity to <verbose>');
  1709. writeln(' H - Show header info');
  1710. writeln(' I - Show interface');
  1711. writeln(' M - Show implementation');
  1712. writeln(' S - Show interface symbols');
  1713. writeln(' D - Show interface definitions');
  1714. writeln(' B - Show browser info');
  1715. writeln(' A - Show all');
  1716. writeln(' -? This helpscreen');
  1717. halt;
  1718. end;
  1719. var
  1720. startpara,
  1721. nrfile,i : longint;
  1722. para : string;
  1723. begin
  1724. writeln(Title+' '+Version);
  1725. writeln(Copyright);
  1726. writeln;
  1727. if paramcount<1 then
  1728. begin
  1729. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  1730. halt(1);
  1731. end;
  1732. { turn verbose on by default }
  1733. verbose:=v_all;
  1734. { read options }
  1735. startpara:=1;
  1736. while copy(paramstr(startpara),1,1)='-' do
  1737. begin
  1738. para:=paramstr(startpara);
  1739. case upcase(para[2]) of
  1740. 'V' : begin
  1741. verbose:=0;
  1742. for i:=3to length(para) do
  1743. case upcase(para[i]) of
  1744. 'H' : verbose:=verbose or v_header;
  1745. 'I' : verbose:=verbose or v_interface;
  1746. 'M' : verbose:=verbose or v_implementation;
  1747. 'D' : verbose:=verbose or v_defs;
  1748. 'S' : verbose:=verbose or v_syms;
  1749. 'B' : verbose:=verbose or v_browser;
  1750. 'A' : verbose:=verbose or v_all;
  1751. end;
  1752. end;
  1753. '?' : help;
  1754. end;
  1755. inc(startpara);
  1756. end;
  1757. { process files }
  1758. for nrfile:=startpara to paramcount do
  1759. dofile (paramstr(nrfile));
  1760. if has_errors then
  1761. Halt(1);
  1762. end.
  1763. {
  1764. $Log$
  1765. Revision 1.34 2002-11-17 16:32:04 carl
  1766. * memory optimization (3-4%) : cleanup of tai fields,
  1767. cleanup of tdef and tsym fields.
  1768. * make it work for m68k
  1769. Revision 1.33 2002/10/20 14:49:31 peter
  1770. * store original source time in ppu so it can be compared instead of
  1771. comparing with the ppu time
  1772. Revision 1.32 2002/10/06 12:25:53 florian
  1773. + dump of tdefoptions.df_unique
  1774. Revision 1.31 2002/09/27 21:22:04 carl
  1775. * update system information
  1776. Revision 1.30 2002/09/26 12:03:54 florian
  1777. + support of constguid and constwchar const symbols added
  1778. Revision 1.29 2002/08/20 16:54:40 peter
  1779. * write address of varsym always
  1780. Revision 1.28 2002/08/19 19:36:44 peter
  1781. * More fixes for cross unit inlining, all tnodes are now implemented
  1782. * Moved pocall_internconst to po_internconst because it is not a
  1783. calling type at all and it conflicted when inlining of these small
  1784. functions was requested
  1785. Revision 1.27 2002/08/15 15:15:56 carl
  1786. * jmpbuf size allocation for exceptions is now cpu specific (as it should)
  1787. * more generic nodes for maths
  1788. * several fixes for better m68k support
  1789. Revision 1.26 2002/08/11 13:24:20 peter
  1790. * saving of asmsymbols in ppu supported
  1791. * asmsymbollist global is removed and moved into a new class
  1792. tasmlibrarydata that will hold the info of a .a file which
  1793. corresponds with a single module. Added librarydata to tmodule
  1794. to keep the library info stored for the module. In the future the
  1795. objectfiles will also be stored to the tasmlibrarydata class
  1796. * all getlabel/newasmsymbol and friends are moved to the new class
  1797. Revision 1.25 2002/05/18 13:34:27 peter
  1798. * readded missing revisions
  1799. Revision 1.24 2002/05/16 19:46:54 carl
  1800. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1801. + try to fix temp allocation (still in ifdef)
  1802. + generic constructor calls
  1803. + start of tassembler / tmodulebase class cleanup
  1804. Revision 1.22 2002/05/12 16:53:18 peter
  1805. * moved entry and exitcode to ncgutil and cgobj
  1806. * foreach gets extra argument for passing local data to the
  1807. iterator function
  1808. * -CR checks also class typecasts at runtime by changing them
  1809. into as
  1810. * fixed compiler to cycle with the -CR option
  1811. * fixed stabs with elf writer, finally the global variables can
  1812. be watched
  1813. * removed a lot of routines from cga unit and replaced them by
  1814. calls to cgobj
  1815. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1816. u32bit then the other is typecasted also to u32bit without giving
  1817. a rangecheck warning/error.
  1818. * fixed pascal calling method with reversing also the high tree in
  1819. the parast, detected by tcalcst3 test
  1820. Revision 1.21 2002/04/23 13:12:58 peter
  1821. * updated for posinfo change
  1822. * updated for mangledname change
  1823. * include i386 registers, removed reference to cpubase unit that would
  1824. make ppudump dependent on the source processor
  1825. Revision 1.20 2002/04/15 19:15:09 carl
  1826. + write std_reg2str instead of gas registers
  1827. Revision 1.19 2002/04/14 17:02:19 carl
  1828. + att_reg2str -> gas_reg2str
  1829. Revision 1.18 2002/04/07 10:23:36 carl
  1830. + added vm / sparc targets
  1831. Revision 1.17 2002/04/04 19:06:14 peter
  1832. * removed unused units
  1833. * use tlocation.size in cg.a_*loc*() routines
  1834. Revision 1.16 2002/04/04 18:50:27 carl
  1835. + added wdosx support (patch from Pavel)
  1836. Revision 1.15 2002/03/31 20:26:42 jonas
  1837. + a_loadfpu_* and a_loadmm_* methods in tcg
  1838. * register allocation is now handled by a class and is mostly processor
  1839. independent (+rgobj.pas and i386/rgcpu.pas)
  1840. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  1841. * some small improvements and fixes to the optimizer
  1842. * some register allocation fixes
  1843. * some fpuvaroffset fixes in the unary minus node
  1844. * push/popusedregisters is now called rg.save/restoreusedregisters and
  1845. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  1846. also better optimizable)
  1847. * fixed and optimized register saving/restoring for new/dispose nodes
  1848. * LOC_FPU locations now also require their "register" field to be set to
  1849. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  1850. - list field removed of the tnode class because it's not used currently
  1851. and can cause hard-to-find bugs
  1852. Revision 1.14 2002/03/28 20:48:52 carl
  1853. - remove go32v1 support
  1854. Revision 1.13 2002/03/28 16:44:59 armin
  1855. + new flag if unit has local threadvars
  1856. Revision 1.12 2002/03/01 14:08:47 peter
  1857. * parasym added
  1858. Revision 1.11 2002/01/06 12:08:16 peter
  1859. * removed uauto from orddef, use new range_to_basetype generating
  1860. the correct ordinal type for a range
  1861. }