ppudump.pp 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370
  1. {
  2. Copyright (c) 1998-2002 by the FPC Development Team
  3. Dumps the contents of a FPC unit file (PPU File)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************}
  16. {$ifdef TP}
  17. {$N+,E+}
  18. {$endif}
  19. program pppdump;
  20. uses
  21. dos,
  22. ppu;
  23. const
  24. Version = 'Version 2.0.2';
  25. Title = 'PPU-Analyser';
  26. Copyright = 'Copyright (c) 1998-2005 by the Free Pascal Development Team';
  27. { verbosity }
  28. v_none = $0;
  29. v_header = $1;
  30. v_defs = $2;
  31. v_syms = $4;
  32. v_interface = $8;
  33. v_implementation = $10;
  34. v_browser = $20;
  35. v_all = $ff;
  36. type
  37. tprocinfoflag=(
  38. {# procedure uses asm }
  39. pi_uses_asm,
  40. {# procedure does a call }
  41. pi_do_call,
  42. {# procedure has a try statement = no register optimization }
  43. pi_uses_exceptions,
  44. {# procedure is declared as @var(assembler), don't optimize}
  45. pi_is_assembler,
  46. {# procedure contains data which needs to be finalized }
  47. pi_needs_implicit_finally
  48. );
  49. tprocinfoflags=set of tprocinfoflag;
  50. { Copied from systems.pas }
  51. tsystemcpu=
  52. (
  53. cpu_no, { 0 }
  54. cpu_i386, { 1 }
  55. cpu_m68k, { 2 }
  56. cpu_alpha, { 3 }
  57. cpu_powerpc, { 4 }
  58. cpu_sparc, { 5 }
  59. cpu_vm, { 6 }
  60. cpu_iA64, { 7 }
  61. cpu_x86_64, { 8 }
  62. cpu_mips, { 9 }
  63. cpu_arm { 10 }
  64. );
  65. var
  66. ppufile : tppufile;
  67. space : string;
  68. unitindex : longint;
  69. verbose : longint;
  70. derefdata : pbyte;
  71. derefdatalen : longint;
  72. {****************************************************************************
  73. Helper Routines
  74. ****************************************************************************}
  75. const has_errors : boolean = false;
  76. Procedure Error(const S : string);
  77. Begin
  78. Writeln(S);
  79. has_errors:=true;
  80. End;
  81. function ToStr(w:longint):String;
  82. begin
  83. Str(w,ToStr);
  84. end;
  85. Function Target2Str(w:longint):string;
  86. type
  87. { taken from systems.pas }
  88. ttarget =
  89. (
  90. target_none, { 0 }
  91. target_i386_GO32V1, { 1 }
  92. target_i386_GO32V2, { 2 }
  93. target_i386_linux, { 3 }
  94. target_i386_OS2, { 4 }
  95. target_i386_Win32, { 5 }
  96. target_i386_freebsd, { 6 }
  97. target_m68k_Amiga, { 7 }
  98. target_m68k_Atari, { 8 }
  99. target_m68k_Mac, { 9 }
  100. target_m68k_linux, { 10 }
  101. target_m68k_PalmOS, { 11 }
  102. target_alpha_linux, { 12 }
  103. target_powerpc_linux, { 13 }
  104. target_powerpc_macos, { 14 }
  105. target_i386_sunos, { 15 }
  106. target_i386_beos, { 16 }
  107. target_i386_netbsd, { 17 }
  108. target_m68k_netbsd, { 18 }
  109. target_i386_Netware, { 19 }
  110. target_i386_qnx, { 20 }
  111. target_i386_wdosx, { 21 }
  112. target_sparc_sunos, { 22 }
  113. target_sparc_linux, { 23 }
  114. target_i386_openbsd, { 24 }
  115. target_m68k_openbsd, { 25 }
  116. system_x86_64_linux, { 26 }
  117. system_powerpc_macosx, { 27 }
  118. target_i386_emx, { 28 }
  119. target_powerpc_netbsd, { 29 }
  120. target_powerpc_openbsd, { 30 }
  121. target_arm_linux, { 31 }
  122. target_i386_watcom, { 32 }
  123. target_powerpc_MorphOS, { 33 }
  124. target_x86_64_freebsd, { 34 }
  125. target_i386_netwlibc, { 35 }
  126. system_powerpc_Amiga, { 36 }
  127. system_x86_64_win64, { 37 }
  128. system_arm_wince, { 38 }
  129. system_ia64_win64, { 39 }
  130. system_i386_wince, { 40 }
  131. system_x86_6432_linux, { 41 }
  132. system_arm_gba { 42 }
  133. );
  134. const
  135. Targets : array[ttarget] of string[17]=(
  136. { 0 } 'none',
  137. { 1 } 'GO32V1',
  138. { 2 } 'GO32V2',
  139. { 3 } 'Linux-i386',
  140. { 4 } 'OS/2',
  141. { 5 } 'Win32',
  142. { 6 } 'FreeBSD-i386',
  143. { 7 } 'Amiga',
  144. { 8 } 'Atari',
  145. { 9 } 'MacOS-m68k',
  146. { 10 } 'Linux-m68k',
  147. { 11 } 'PalmOS-m68k',
  148. { 12 } 'Linux-alpha',
  149. { 13 } 'Linux-ppc',
  150. { 14 } 'MacOS-ppc',
  151. { 15 } 'Solaris-i386',
  152. { 16 } 'BeOS-i386',
  153. { 17 } 'NetBSD-i386',
  154. { 18 } 'NetBSD-m68k',
  155. { 19 } 'Netware-i386-clib',
  156. { 20 } 'Qnx-i386',
  157. { 21 } 'WDOSX-i386',
  158. { 22 } 'Solaris-sparc',
  159. { 23 } 'Linux-sparc',
  160. { 24 } 'OpenBSD-i386',
  161. { 25 } 'OpenBSD-m68k',
  162. { 26 } 'Linux-x86-64',
  163. { 27 } 'MacOSX-ppc',
  164. { 28 } 'OS/2 via EMX',
  165. { 29 } 'NetBSD-powerpc',
  166. { 30 } 'OpenBSD-powerpc',
  167. { 31 } 'Linux-arm',
  168. { 32 } 'Watcom-i386',
  169. { 33 } 'MorphOS-powerpc',
  170. { 34 } 'FreeBSD-x86-64',
  171. { 35 } 'Netware-i386-libc',
  172. { 36 } 'Amiga-PowerPC',
  173. { 37 } 'Win64-x64',
  174. { 38 } 'WinCE-ARM',
  175. { 39 } 'Win64-iA64',
  176. { 40 } 'WinCE-i386',
  177. { 41 } 'Linux-x64',
  178. { 42 } 'GBA-ARM'
  179. );
  180. begin
  181. if w<=ord(high(ttarget)) then
  182. Target2Str:=Targets[ttarget(w)]
  183. else
  184. Target2Str:='<!! Unknown target value '+tostr(w)+'>';
  185. end;
  186. Function Cpu2Str(w:longint):string;
  187. const
  188. CpuTxt : array[tsystemcpu] of string[8]=
  189. ('none','i386','m68k','alpha','powerpc','sparc','vis','ia64','x86_64','mips','arm');
  190. begin
  191. if w<=ord(high(tsystemcpu)) then
  192. Cpu2Str:=CpuTxt[tsystemcpu(w)]
  193. else
  194. Cpu2Str:='<!! Unknown cpu value '+tostr(w)+'>';
  195. end;
  196. Function Varspez2Str(w:longint):string;
  197. const
  198. varspezstr : array[0..4] of string[6]=('Value','Const','Var','Out','Hidden');
  199. begin
  200. if w<=ord(high(varspezstr)) then
  201. Varspez2Str:=varspezstr[w]
  202. else
  203. Varspez2Str:='<!! Unknown varspez value '+tostr(w)+'>';
  204. end;
  205. Function VarRegable2Str(w:longint):string;
  206. const
  207. varregableStr : array[0..3] of string[6]=('None','IntReg','FPUReg','MMReg');
  208. begin
  209. if w<=ord(high(varregablestr)) then
  210. Varregable2Str:=varregablestr[w]
  211. else
  212. Varregable2Str:='<!! Unknown regable value '+tostr(w)+'>';
  213. end;
  214. function PPUFlags2Str(flags:longint):string;
  215. type
  216. tflagopt=record
  217. mask : longint;
  218. str : string[30];
  219. end;
  220. const
  221. flagopts=19;
  222. flagopt : array[1..flagopts] of tflagopt=(
  223. (mask: $1 ;str:'init'),
  224. (mask: $2 ;str:'final'),
  225. (mask: $4 ;str:'big_endian'),
  226. (mask: $8 ;str:'dbx'),
  227. (mask: $10 ;str:'browser'),
  228. (mask: $20 ;str:'in_library'),
  229. (mask: $40 ;str:'smart_linked'),
  230. (mask: $80 ;str:'static_linked'),
  231. (mask: $100 ;str:'shared_linked'),
  232. (mask: $200 ;str:'local_browser'),
  233. (mask: $400 ;str:'no_link'),
  234. (mask: $800 ;str:'has_resources'),
  235. (mask: $1000 ;str:'little_endian'),
  236. (mask: $2000 ;str:'release'),
  237. (mask: $4000 ;str:'local_threadvars'),
  238. (mask: $8000 ;str:'fpu_emulation_on'),
  239. (mask: $10000 ;str:'has_debug_info'),
  240. (mask: $20000 ;str:'local_symtable'),
  241. (mask: $40000 ;str:'uses_variants')
  242. );
  243. var
  244. i : longint;
  245. first : boolean;
  246. s : string;
  247. begin
  248. s:='';
  249. if flags<>0 then
  250. begin
  251. first:=true;
  252. for i:=1to flagopts do
  253. if (flags and flagopt[i].mask)<>0 then
  254. begin
  255. if first then
  256. first:=false
  257. else
  258. s:=s+', ';
  259. s:=s+flagopt[i].str;
  260. end;
  261. end
  262. else
  263. s:='none';
  264. PPUFlags2Str:=s;
  265. end;
  266. const
  267. HexTbl : array[0..15] of char='0123456789ABCDEF';
  268. function HexB(b:byte):string;
  269. begin
  270. HexB[0]:=#2;
  271. HexB[1]:=HexTbl[b shr 4];
  272. HexB[2]:=HexTbl[b and $f];
  273. end;
  274. function hexstr(val : cardinal;cnt : byte) : string;
  275. const
  276. HexTbl : array[0..15] of char='0123456789ABCDEF';
  277. var
  278. i : longint;
  279. begin
  280. hexstr[0]:=char(cnt);
  281. for i:=cnt downto 1 do
  282. begin
  283. hexstr[i]:=hextbl[val and $f];
  284. val:=val shr 4;
  285. end;
  286. end;
  287. Function L0(l:longint):string;
  288. {
  289. return the string of value l, if l<10 then insert a zero, so
  290. the string is always at least 2 chars '01','02',etc
  291. }
  292. var
  293. s : string;
  294. begin
  295. Str(l,s);
  296. if l<10 then
  297. s:='0'+s;
  298. L0:=s;
  299. end;
  300. function filetimestring( t : longint) : string;
  301. {
  302. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  303. }
  304. var
  305. DT : DateTime;
  306. begin
  307. if t=-1 then
  308. begin
  309. FileTimeString:='Not Found';
  310. exit;
  311. end;
  312. unpacktime(t,DT);
  313. filetimestring:=L0(dt.Year)+'/'+L0(dt.Month)+'/'+L0(dt.Day)+' '+L0(dt.Hour)+':'+L0(dt.min)+':'+L0(dt.sec);
  314. end;
  315. {****************************************************************************
  316. Read Routines
  317. ****************************************************************************}
  318. Procedure ReadLinkContainer(const prefix:string);
  319. {
  320. Read a serie of strings and write to the screen starting every line
  321. with prefix
  322. }
  323. function maskstr(m:longint):string;
  324. const
  325. { link options }
  326. link_none = $0;
  327. link_always = $1;
  328. link_static = $2;
  329. link_smart = $4;
  330. link_shared = $8;
  331. var
  332. s : string;
  333. begin
  334. s:='';
  335. if (m and link_always)<>0 then
  336. s:=s+'always ';
  337. if (m and link_static)<>0 then
  338. s:=s+'static ';
  339. if (m and link_smart)<>0 then
  340. s:=s+'smart ';
  341. if (m and link_shared)<>0 then
  342. s:=s+'shared ';
  343. maskstr:=s;
  344. end;
  345. var
  346. s : string;
  347. m : longint;
  348. begin
  349. while not ppufile.endofentry do
  350. begin
  351. s:=ppufile.getstring;
  352. m:=ppufile.getlongint;
  353. WriteLn(prefix,s,' (',maskstr(m),')');
  354. end;
  355. end;
  356. Procedure ReadContainer(const prefix:string);
  357. {
  358. Read a serie of strings and write to the screen starting every line
  359. with prefix
  360. }
  361. begin
  362. while not ppufile.endofentry do
  363. WriteLn(prefix,ppufile.getstring);
  364. end;
  365. procedure ReadLoadUnit;
  366. var
  367. ucrc,uintfcrc : cardinal;
  368. begin
  369. while not ppufile.EndOfEntry do
  370. begin
  371. write('Uses unit: ',ppufile.getstring);
  372. ucrc:=cardinal(ppufile.getlongint);
  373. uintfcrc:=cardinal(ppufile.getlongint);
  374. writeln(' (Crc: ',hexstr(ucrc,8),', IntfcCrc: ',hexstr(uintfcrc,8),')');
  375. end;
  376. end;
  377. Procedure ReadDerefmap;
  378. var
  379. i,mapsize : longint;
  380. begin
  381. mapsize:=ppufile.getword;
  382. writeln('DerefMapsize: ',mapsize);
  383. for i:=0 to mapsize-1 do
  384. writeln('DerefMap[',i,'] = ',ppufile.getstring);
  385. end;
  386. Procedure ReadDerefdata;
  387. begin
  388. derefdatalen:=ppufile.entrysize;
  389. if derefdatalen=0 then
  390. begin
  391. writeln('!! Error: derefdatalen=0');
  392. exit;
  393. end;
  394. Writeln('Derefdata length: ',derefdatalen);
  395. derefdata:=allocmem(derefdatalen);
  396. ppufile.getdata(derefdata^,derefdatalen);
  397. end;
  398. Procedure ReadRef;
  399. begin
  400. if (verbose and v_browser)=0 then
  401. exit;
  402. while (not ppufile.endofentry) and (not ppufile.error) do
  403. Writeln(space,' - Refered : ',ppufile.getword,', (',ppufile.getlongint,',',ppufile.getword,')');
  404. end;
  405. Procedure ReadAsmSymbols;
  406. type
  407. { Copied from aasmbase.pas }
  408. TAsmsymbind=(AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL);
  409. TAsmsymtype=(AT_NONE,AT_FUNCTION,AT_DATA,AT_SECTION,AT_LABEL);
  410. var
  411. s,
  412. bindstr,
  413. typestr : string;
  414. i : longint;
  415. begin
  416. writeln(space,'Number of AsmSymbols: ',ppufile.getlongint);
  417. i:=0;
  418. while (not ppufile.endofentry) and (not ppufile.error) do
  419. begin
  420. s:=ppufile.getstring;
  421. case tasmsymbind(ppufile.getbyte) of
  422. AB_EXTERNAL :
  423. bindstr:='External';
  424. AB_COMMON :
  425. bindstr:='Common';
  426. AB_LOCAL :
  427. bindstr:='Local';
  428. AB_GLOBAL :
  429. bindstr:='Global';
  430. else
  431. bindstr:='<Error !!>'
  432. end;
  433. case tasmsymtype(ppufile.getbyte) of
  434. AT_FUNCTION :
  435. typestr:='Function';
  436. AT_DATA :
  437. typestr:='Data';
  438. AT_SECTION :
  439. typestr:='Section';
  440. AT_LABEL :
  441. typestr:='Label';
  442. else
  443. typestr:='<Error !!>'
  444. end;
  445. Writeln(space,' ',i,' : ',s,' [',bindstr,',',typestr,']');
  446. inc(i);
  447. end;
  448. end;
  449. Procedure ReadPosInfo;
  450. var
  451. info : byte;
  452. fileindex,line,column : longint;
  453. begin
  454. with ppufile do
  455. begin
  456. {
  457. info byte layout in bits:
  458. 0-1 - amount of bytes for fileindex
  459. 2-3 - amount of bytes for line
  460. 4-5 - amount of bytes for column
  461. }
  462. info:=getbyte;
  463. case (info and $03) of
  464. 0 : fileindex:=getbyte;
  465. 1 : fileindex:=getword;
  466. 2 : fileindex:=(getbyte shl 16) or getword;
  467. 3 : fileindex:=getlongint;
  468. end;
  469. case ((info shr 2) and $03) of
  470. 0 : line:=getbyte;
  471. 1 : line:=getword;
  472. 2 : line:=(getbyte shl 16) or getword;
  473. 3 : line:=getlongint;
  474. end;
  475. case ((info shr 4) and $03) of
  476. 0 : column:=getbyte;
  477. 1 : column:=getword;
  478. 2 : column:=(getbyte shl 16) or getword;
  479. 3 : column:=getlongint;
  480. end;
  481. Writeln(fileindex,' (',line,',',column,')');
  482. end;
  483. end;
  484. procedure readderef;
  485. type
  486. tdereftype = (deref_nil,
  487. deref_sym,
  488. deref_def,
  489. deref_aktrecord,
  490. deref_aktstatic,
  491. deref_aktglobal,
  492. deref_aktlocal,
  493. deref_aktpara,
  494. deref_unit,
  495. deref_record,
  496. deref_local,
  497. deref_para,
  498. deref_parent_object
  499. );
  500. var
  501. b : tdereftype;
  502. first : boolean;
  503. idx : longint;
  504. i,n : byte;
  505. pdata : pbyte;
  506. begin
  507. if not assigned(derefdata) then
  508. exit;
  509. first:=true;
  510. idx:=ppufile.getlongint;
  511. if (idx>derefdatalen) then
  512. begin
  513. writeln('!! Error: Deref idx ',idx,' > ',derefdatalen);
  514. exit;
  515. end;
  516. write('(',idx,') ');
  517. pdata:=@derefdata[idx];
  518. i:=0;
  519. n:=pdata[i];
  520. inc(i);
  521. if n<1 then
  522. begin
  523. writeln('!! Error: Deref len < 1');
  524. exit;
  525. end;
  526. while (i<n) do
  527. begin
  528. if not first then
  529. write(', ')
  530. else
  531. first:=false;
  532. b:=tdereftype(pdata[i]);
  533. inc(i);
  534. case b of
  535. deref_nil :
  536. write('Nil');
  537. deref_def :
  538. begin
  539. idx:=pdata[i] shl 8;
  540. idx:=idx or pdata[i+1];
  541. inc(i,2);
  542. write('Definition ',idx);
  543. end;
  544. deref_sym :
  545. begin
  546. idx:=pdata[i] shl 8;
  547. idx:=idx or pdata[i+1];
  548. inc(i,2);
  549. write('Symbol ',idx);
  550. end;
  551. deref_aktrecord :
  552. write('AktRecord');
  553. deref_aktstatic :
  554. write('AktStatic');
  555. deref_aktglobal :
  556. write('AktGlobal');
  557. deref_aktlocal :
  558. write('AktLocal');
  559. deref_aktpara :
  560. write('AktPara');
  561. deref_unit :
  562. begin
  563. idx:=pdata[i] shl 8;
  564. idx:=idx or pdata[i+1];
  565. inc(i,2);
  566. write('Unit ',idx);
  567. end;
  568. deref_record :
  569. write('RecordDef');
  570. deref_para :
  571. write('Parameter of procdef');
  572. deref_local :
  573. write('Local of procdef');
  574. deref_parent_object :
  575. write('Parent object');
  576. else
  577. begin
  578. writeln('!! unsupported dereftyp: ',ord(b));
  579. break;
  580. end;
  581. end;
  582. end;
  583. writeln;
  584. end;
  585. procedure readtype;
  586. begin
  587. readderef;
  588. end;
  589. procedure readsymlist(const s:string);
  590. type
  591. tsltype = (sl_none,
  592. sl_load,
  593. sl_call,
  594. sl_subscript,
  595. sl_vec
  596. );
  597. const
  598. slstr : array[tsltype] of string[9] = ('',
  599. 'load',
  600. 'call',
  601. 'subscript',
  602. 'vec'
  603. );
  604. var
  605. sl : tsltype;
  606. begin
  607. readderef;
  608. repeat
  609. sl:=tsltype(ppufile.getbyte);
  610. if sl=sl_none then
  611. break;
  612. write(s,'(',slstr[sl],') ');
  613. case sl of
  614. sl_call,
  615. sl_load,
  616. sl_subscript :
  617. readderef;
  618. sl_vec :
  619. writeln(ppufile.getlongint);
  620. end;
  621. until false;
  622. end;
  623. procedure readsymoptions;
  624. type
  625. tsymoption=(sp_none,
  626. sp_public,
  627. sp_private,
  628. sp_published,
  629. sp_protected,
  630. sp_static,
  631. sp_hint_deprecated,
  632. sp_hint_platform,
  633. sp_hint_library,
  634. sp_hint_unimplemented,
  635. sp_has_overloaded,
  636. sp_internal { internal symbol, not reported as unused }
  637. );
  638. tsymoptions=set of tsymoption;
  639. tsymopt=record
  640. mask : tsymoption;
  641. str : string[30];
  642. end;
  643. const
  644. symopts=11;
  645. symopt : array[1..symopts] of tsymopt=(
  646. (mask:sp_public; str:'Public'),
  647. (mask:sp_private; str:'Private'),
  648. (mask:sp_published; str:'Published'),
  649. (mask:sp_protected; str:'Protected'),
  650. (mask:sp_static; str:'Static'),
  651. (mask:sp_hint_deprecated;str:'Hint Deprecated'),
  652. (mask:sp_hint_deprecated;str:'Hint Platform'),
  653. (mask:sp_hint_deprecated;str:'Hint Library'),
  654. (mask:sp_hint_deprecated;str:'Hint Unimplemented'),
  655. (mask:sp_has_overloaded; str:'Has overloaded'),
  656. (mask:sp_internal; str:'Internal')
  657. );
  658. var
  659. symoptions : tsymoptions;
  660. i : longint;
  661. first : boolean;
  662. begin
  663. ppufile.getsmallset(symoptions);
  664. if symoptions<>[] then
  665. begin
  666. first:=true;
  667. for i:=1to symopts do
  668. if (symopt[i].mask in symoptions) then
  669. begin
  670. if first then
  671. first:=false
  672. else
  673. write(', ');
  674. write(symopt[i].str);
  675. end;
  676. end;
  677. writeln;
  678. end;
  679. procedure readcommonsym(const s:string);
  680. begin
  681. writeln(space,'** Symbol Nr. ',ppufile.getword,' **');
  682. writeln(space,s,ppufile.getstring);
  683. write(space,' File Pos : ');
  684. readposinfo;
  685. write(space,' SymOptions : ');
  686. readsymoptions;
  687. end;
  688. procedure readcommondef(const s:string);
  689. type
  690. tdefoption=(df_none,
  691. { init data has been generated }
  692. df_has_inittable,
  693. { rtti data has been generated }
  694. df_has_rttitable,
  695. { type is unique, i.e. declared with type = type <tdef>; }
  696. df_unique,
  697. { type is a generic }
  698. df_generic,
  699. { type is a specialization of a generic type }
  700. df_specialization
  701. );
  702. tdefoptions=set of tdefoption;
  703. tdefopt=record
  704. mask : tdefoption;
  705. str : string[30];
  706. end;
  707. const
  708. defopts=5;
  709. defopt : array[1..defopts] of tdefopt=(
  710. (mask:df_has_inittable; str:'InitTable'),
  711. (mask:df_has_rttitable; str:'RTTITable'),
  712. (mask:df_unique; str:'Unique Type'),
  713. (mask:df_generic; str:'Generic'),
  714. (mask:df_specialization; str:'Specialization')
  715. );
  716. var
  717. defoptions : tdefoptions;
  718. i : longint;
  719. first : boolean;
  720. tokenbufsize : longint;
  721. tokenbuf : pointer;
  722. begin
  723. writeln(space,'** Definition Nr. ',ppufile.getword,' **');
  724. writeln(space,s);
  725. write (space,' Type symbol : ');
  726. readderef;
  727. write (space,' DefOptions : ');
  728. ppufile.getsmallset(defoptions);
  729. if defoptions<>[] then
  730. begin
  731. first:=true;
  732. for i:=1to defopts do
  733. if (defopt[i].mask in defoptions) then
  734. begin
  735. if first then
  736. first:=false
  737. else
  738. write(', ');
  739. write(defopt[i].str);
  740. end;
  741. end;
  742. writeln;
  743. if df_unique in defoptions then
  744. writeln (space,' Unique type symbol');
  745. if df_has_rttitable in defoptions then
  746. begin
  747. write (space,' RTTI symbol : ');
  748. readderef;
  749. end;
  750. if df_has_inittable in defoptions then
  751. begin
  752. write (space,' Init symbol : ');
  753. readderef;
  754. end;
  755. if df_generic in defoptions then
  756. begin
  757. tokenbufsize:=ppufile.getlongint;
  758. writeln(space,' Tokenbuffer size : ',tokenbufsize);
  759. tokenbuf:=allocmem(tokenbufsize);
  760. ppufile.getdata(tokenbuf^,tokenbufsize);
  761. freemem(tokenbuf);
  762. end;
  763. if df_specialization in defoptions then
  764. begin
  765. write (space,' Orig. GenericDef : ');
  766. readderef;
  767. end;
  768. end;
  769. { Read abstract procdef and return if inline procdef }
  770. type
  771. tproccalloption=(pocall_none,
  772. { procedure uses C styled calling }
  773. pocall_cdecl,
  774. { C++ calling conventions }
  775. pocall_cppdecl,
  776. { Far16 for OS/2 }
  777. pocall_far16,
  778. { Old style FPC default calling }
  779. pocall_oldfpccall,
  780. { Procedure has compiler magic}
  781. pocall_internproc,
  782. { procedure is a system call, applies e.g. to MorphOS and PalmOS }
  783. pocall_syscall,
  784. { pascal standard left to right }
  785. pocall_pascal,
  786. { procedure uses register (fastcall) calling }
  787. pocall_register,
  788. { safe call calling conventions }
  789. pocall_safecall,
  790. { procedure uses stdcall call }
  791. pocall_stdcall,
  792. { Special calling convention for cpus without a floating point
  793. unit. Floating point numbers are passed in integer registers
  794. instead of floating point registers. Depending on the other
  795. available calling conventions available for the cpu
  796. this replaces either pocall_fastcall or pocall_stdcall.
  797. }
  798. pocall_softfloat,
  799. { Metrowerks Pascal. Special case on Mac OS (X): passes all }
  800. { constant records by reference. }
  801. pocall_mwpascal
  802. );
  803. tproccalloptions=set of tproccalloption;
  804. tproctypeoption=(potype_none,
  805. potype_proginit, { Program initialization }
  806. potype_unitinit, { unit initialization }
  807. potype_unitfinalize, { unit finalization }
  808. potype_constructor, { Procedure is a constructor }
  809. potype_destructor, { Procedure is a destructor }
  810. potype_operator, { Procedure defines an operator }
  811. potype_procedure,
  812. potype_function
  813. );
  814. tproctypeoptions=set of tproctypeoption;
  815. tprocoption=(po_none,
  816. po_classmethod, { class method }
  817. po_virtualmethod, { Procedure is a virtual method }
  818. po_abstractmethod, { Procedure is an abstract method }
  819. po_staticmethod, { static method }
  820. po_overridingmethod, { method with override directive }
  821. po_methodpointer, { method pointer, only in procvardef, also used for 'with object do' }
  822. po_interrupt, { Procedure is an interrupt handler }
  823. po_iocheck, { IO checking should be done after a call to the procedure }
  824. po_assembler, { Procedure is written in assembler }
  825. po_msgstr, { method for string message handling }
  826. po_msgint, { method for int message handling }
  827. po_exports, { Procedure has export directive (needed for OS/2) }
  828. po_external, { Procedure is external (in other object or lib)}
  829. po_overload, { procedure is declared with overload directive }
  830. po_varargs, { printf like arguments }
  831. po_internconst, { procedure has constant evaluator intern }
  832. { flag that only the address of a method is returned and not a full methodpointer }
  833. po_addressonly,
  834. { procedure is exported }
  835. po_public,
  836. { calling convention is specified explicitly }
  837. po_hascallingconvention,
  838. { reintroduce flag }
  839. po_reintroduce,
  840. { location of parameters is given explicitly as it is necessary for some syscall
  841. conventions like that one of MorphOS }
  842. po_explicitparaloc,
  843. { no stackframe will be generated, used by lowlevel assembler like get_frame }
  844. po_nostackframe,
  845. po_has_mangledname,
  846. po_has_public_name,
  847. po_forward,
  848. po_global,
  849. po_has_inlininginfo,
  850. { The different kind of syscalls on MorphOS }
  851. po_syscall_legacy,
  852. po_syscall_sysv,
  853. po_syscall_basesysv,
  854. po_syscall_sysvbase,
  855. po_syscall_r12base,
  856. po_local,
  857. { Procedure can be inlined }
  858. po_inline,
  859. { Procedure is used for internal compiler calls }
  860. po_compilerproc,
  861. { importing }
  862. po_has_importdll,
  863. po_has_importname
  864. );
  865. tprocoptions=set of tprocoption;
  866. procedure read_abstract_proc_def(var proccalloption:tproccalloption;var procoptions:tprocoptions);
  867. type
  868. tproccallopt=record
  869. mask : tproccalloption;
  870. str : string[30];
  871. end;
  872. tproctypeopt=record
  873. mask : tproctypeoption;
  874. str : string[30];
  875. end;
  876. tprocopt=record
  877. mask : tprocoption;
  878. str : string[30];
  879. end;
  880. const
  881. proccalloptionStr : array[tproccalloption] of string[14]=('',
  882. 'CDecl',
  883. 'CPPDecl',
  884. 'Far16',
  885. 'OldFPCCall',
  886. 'InternProc',
  887. 'SysCall',
  888. 'Pascal',
  889. 'Register',
  890. 'SafeCall',
  891. 'StdCall',
  892. 'SoftFloat',
  893. 'MWPascal'
  894. );
  895. proctypeopts=8;
  896. proctypeopt : array[1..proctypeopts] of tproctypeopt=(
  897. (mask:potype_proginit; str:'ProgInit'),
  898. (mask:potype_unitinit; str:'UnitInit'),
  899. (mask:potype_unitfinalize;str:'UnitFinalize'),
  900. (mask:potype_constructor; str:'Constructor'),
  901. (mask:potype_destructor; str:'Destructor'),
  902. (mask:potype_operator; str:'Operator'),
  903. (mask:potype_function; str:'Function'),
  904. (mask:potype_procedure; str:'Procedure')
  905. );
  906. procopts=37;
  907. procopt : array[1..procopts] of tprocopt=(
  908. (mask:po_classmethod; str:'ClassMethod'),
  909. (mask:po_virtualmethod; str:'VirtualMethod'),
  910. (mask:po_abstractmethod; str:'AbstractMethod'),
  911. (mask:po_staticmethod; str:'StaticMethod'),
  912. (mask:po_overridingmethod;str:'OverridingMethod'),
  913. (mask:po_methodpointer; str:'MethodPointer'),
  914. (mask:po_interrupt; str:'Interrupt'),
  915. (mask:po_iocheck; str:'IOCheck'),
  916. (mask:po_assembler; str:'Assembler'),
  917. (mask:po_msgstr; str:'MsgStr'),
  918. (mask:po_msgint; str:'MsgInt'),
  919. (mask:po_exports; str:'Exports'),
  920. (mask:po_external; str:'External'),
  921. (mask:po_overload; str:'Overload'),
  922. (mask:po_varargs; str:'VarArgs'),
  923. (mask:po_internconst; str:'InternConst'),
  924. (mask:po_addressonly; str:'AddressOnly'),
  925. (mask:po_public; str:'Public'),
  926. (mask:po_hascallingconvention;str:'HasCallingConvention'),
  927. (mask:po_reintroduce; str:'ReIntroduce'),
  928. (mask:po_explicitparaloc; str:'ExplicitParaloc'),
  929. (mask:po_nostackframe; str:'NoStackFrame'),
  930. (mask:po_has_mangledname; str:'HasMangledName'),
  931. (mask:po_has_public_name; str:'HasPublicName'),
  932. (mask:po_forward; str:'Forward'),
  933. (mask:po_global; str:'Global'),
  934. (mask:po_has_inlininginfo;str:'HasInliningInfo'),
  935. (mask:po_syscall_legacy; str:'SyscallLegacy'),
  936. (mask:po_syscall_sysv; str:'SyscallSysV'),
  937. (mask:po_syscall_basesysv;str:'SyscallBaseSysV'),
  938. (mask:po_syscall_sysvbase;str:'SyscallSysVBase'),
  939. (mask:po_syscall_r12base; str:'SyscallR12Base'),
  940. (mask:po_local; str:'Local'),
  941. (mask:po_inline; str:'Inline'),
  942. (mask:po_compilerproc; str:'CompilerProc'),
  943. (mask:po_has_importdll; str:'HasImportDLL'),
  944. (mask:po_has_importname; str:'HasImportName')
  945. );
  946. var
  947. proctypeoption : tproctypeoption;
  948. i : longint;
  949. first : boolean;
  950. tempbuf : array[0..255] of byte;
  951. begin
  952. write(space,' Return type : ');
  953. readtype;
  954. writeln(space,' Fpu used : ',ppufile.getbyte);
  955. proctypeoption:=tproctypeoption(ppufile.getbyte);
  956. write(space,' TypeOption : ');
  957. first:=true;
  958. for i:=1 to proctypeopts do
  959. if (proctypeopt[i].mask=proctypeoption) then
  960. begin
  961. if first then
  962. first:=false
  963. else
  964. write(', ');
  965. write(proctypeopt[i].str);
  966. end;
  967. writeln;
  968. proccalloption:=tproccalloption(ppufile.getbyte);
  969. writeln(space,' CallOption : ',proccalloptionStr[proccalloption]);
  970. ppufile.getnormalset(procoptions);
  971. if procoptions<>[] then
  972. begin
  973. write(space,' Options : ');
  974. first:=true;
  975. for i:=1to procopts do
  976. if (procopt[i].mask in procoptions) then
  977. begin
  978. if first then
  979. first:=false
  980. else
  981. write(', ');
  982. write(procopt[i].str);
  983. end;
  984. writeln;
  985. end;
  986. if (po_explicitparaloc in procoptions) then
  987. begin
  988. i:=ppufile.getbyte;
  989. ppufile.getdata(tempbuf,i);
  990. end;
  991. end;
  992. type
  993. { options for variables }
  994. tvaroption=(vo_none,
  995. vo_is_C_var,
  996. vo_is_external,
  997. vo_is_dll_var,
  998. vo_is_thread_var,
  999. vo_has_local_copy,
  1000. vo_is_const, { variable is declared as const (parameter) and can't be written to }
  1001. vo_is_exported,
  1002. vo_is_high_para,
  1003. vo_is_funcret,
  1004. vo_is_self,
  1005. vo_is_vmt,
  1006. vo_is_result, { special result variable }
  1007. vo_is_parentfp,
  1008. vo_is_loop_counter, { used to detect assignments to loop counter }
  1009. vo_is_hidden_para,
  1010. vo_has_explicit_paraloc,
  1011. vo_is_syscall_lib,
  1012. vo_has_mangledname
  1013. );
  1014. tvaroptions=set of tvaroption;
  1015. { register variable }
  1016. tvarregable=(vr_none,
  1017. vr_intreg,
  1018. vr_fpureg,
  1019. vr_mmreg
  1020. );
  1021. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions);
  1022. type
  1023. tvaropt=record
  1024. mask : tvaroption;
  1025. str : string[30];
  1026. end;
  1027. const
  1028. varopts=18;
  1029. varopt : array[1..varopts] of tvaropt=(
  1030. (mask:vo_is_C_var; str:'CVar'),
  1031. (mask:vo_is_external; str:'External'),
  1032. (mask:vo_is_dll_var; str:'DLLVar'),
  1033. (mask:vo_is_thread_var; str:'ThreadVar'),
  1034. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  1035. (mask:vo_is_const; str:'Constant'),
  1036. (mask:vo_is_exported; str:'Exported'),
  1037. (mask:vo_is_high_para; str:'HighValue'),
  1038. (mask:vo_is_funcret; str:'Funcret'),
  1039. (mask:vo_is_self; str:'Self'),
  1040. (mask:vo_is_vmt; str:'VMT'),
  1041. (mask:vo_is_result; str:'Result'),
  1042. (mask:vo_is_parentfp; str:'ParentFP'),
  1043. (mask:vo_is_loop_counter; str:'LoopCounter'),
  1044. (mask:vo_is_hidden_para; str:'Hidden'),
  1045. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  1046. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  1047. (mask:vo_has_mangledname; str:'HasMangledName')
  1048. );
  1049. var
  1050. i : longint;
  1051. first : boolean;
  1052. begin
  1053. readcommonsym(s);
  1054. writeln(space,' Spez : ',Varspez2Str(ppufile.getbyte));
  1055. writeln(space,' Regable : ',Varregable2Str(ppufile.getbyte));
  1056. write (space,' Var Type : ');
  1057. readtype;
  1058. ppufile.getsmallset(varoptions);
  1059. if varoptions<>[] then
  1060. begin
  1061. write(space,' Options : ');
  1062. first:=true;
  1063. for i:=1to varopts do
  1064. if (varopt[i].mask in varoptions) then
  1065. begin
  1066. if first then
  1067. first:=false
  1068. else
  1069. write(', ');
  1070. write(varopt[i].str);
  1071. end;
  1072. writeln;
  1073. end;
  1074. end;
  1075. procedure readobjectdefoptions;
  1076. type
  1077. tobjectoption=(oo_none,
  1078. oo_is_forward, { the class is only a forward declared yet }
  1079. oo_has_virtual, { the object/class has virtual methods }
  1080. oo_has_private,
  1081. oo_has_protected,
  1082. oo_has_strictprivate,
  1083. oo_has_strictprotected,
  1084. oo_has_constructor, { the object/class has a constructor }
  1085. oo_has_destructor, { the object/class has a destructor }
  1086. oo_has_vmt, { the object/class has a vmt }
  1087. oo_has_msgstr,
  1088. oo_has_msgint,
  1089. oo_can_have_published,{ the class has rtti, i.e. you can publish properties }
  1090. oo_has_default_property
  1091. );
  1092. tobjectoptions=set of tobjectoption;
  1093. tsymopt=record
  1094. mask : tobjectoption;
  1095. str : string[30];
  1096. end;
  1097. const
  1098. symopts=13;
  1099. symopt : array[1..symopts] of tsymopt=(
  1100. (mask:oo_has_virtual; str:'IsForward'),
  1101. (mask:oo_has_virtual; str:'HasVirtual'),
  1102. (mask:oo_has_private; str:'HasPrivate'),
  1103. (mask:oo_has_protected; str:'HasProtected'),
  1104. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  1105. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  1106. (mask:oo_has_constructor; str:'HasConstructor'),
  1107. (mask:oo_has_destructor; str:'HasDestructor'),
  1108. (mask:oo_has_vmt; str:'HasVMT'),
  1109. (mask:oo_has_msgstr; str:'HasMsgStr'),
  1110. (mask:oo_has_msgint; str:'HasMsgInt'),
  1111. (mask:oo_can_have_published; str:'CanHavePublished'),
  1112. (mask:oo_has_default_property;str:'HasDefaultProperty')
  1113. );
  1114. var
  1115. symoptions : tobjectoptions;
  1116. i : longint;
  1117. first : boolean;
  1118. begin
  1119. ppufile.getsmallset(symoptions);
  1120. if symoptions<>[] then
  1121. begin
  1122. first:=true;
  1123. for i:=1to symopts do
  1124. if (symopt[i].mask in symoptions) then
  1125. begin
  1126. if first then
  1127. first:=false
  1128. else
  1129. write(', ');
  1130. write(symopt[i].str);
  1131. end;
  1132. end;
  1133. writeln;
  1134. end;
  1135. procedure readarraydefoptions;
  1136. type
  1137. tarraydefoption=(ado_none,
  1138. ado_IsConvertedPointer,
  1139. ado_IsDynamicArray,
  1140. ado_IsVariant,
  1141. ado_IsConstructor,
  1142. ado_IsArrayOfConst,
  1143. ado_IsConstString
  1144. );
  1145. tarraydefoptions=set of tarraydefoption;
  1146. tsymopt=record
  1147. mask : tarraydefoption;
  1148. str : string[30];
  1149. end;
  1150. const
  1151. symopts=6;
  1152. symopt : array[1..symopts] of tsymopt=(
  1153. (mask:ado_IsConvertedPointer;str:'ConvertedPointer'),
  1154. (mask:ado_IsDynamicArray; str:'IsDynamicArray'),
  1155. (mask:ado_IsVariant; str:'IsVariant'),
  1156. (mask:ado_IsConstructor; str:'IsConstructor'),
  1157. (mask:ado_IsArrayOfConst; str:'ArrayOfConst'),
  1158. (mask:ado_IsConstString; str:'ConstString')
  1159. );
  1160. var
  1161. symoptions : tarraydefoptions;
  1162. i : longint;
  1163. first : boolean;
  1164. begin
  1165. ppufile.getsmallset(symoptions);
  1166. if symoptions<>[] then
  1167. begin
  1168. first:=true;
  1169. for i:=1to symopts do
  1170. if (symopt[i].mask in symoptions) then
  1171. begin
  1172. if first then
  1173. first:=false
  1174. else
  1175. write(', ');
  1176. write(symopt[i].str);
  1177. end;
  1178. end;
  1179. writeln;
  1180. end;
  1181. procedure readnodetree;
  1182. var
  1183. l : longint;
  1184. p : pointer;
  1185. begin
  1186. with ppufile do
  1187. begin
  1188. if space<>'' then
  1189. Writeln(space,'------ nodetree ------');
  1190. if readentry=ibnodetree then
  1191. begin
  1192. l:=entrysize;
  1193. Writeln(space,'Tree size : ',l);
  1194. { Read data to prevent error that entry is not completly read }
  1195. getmem(p,l);
  1196. getdata(p^,l);
  1197. freemem(p);
  1198. end
  1199. else
  1200. begin
  1201. Writeln('!! ibnodetree not found');
  1202. end;
  1203. end;
  1204. end;
  1205. {****************************************************************************
  1206. Read Symbols Part
  1207. ****************************************************************************}
  1208. procedure readsymbols(const s:string);
  1209. type
  1210. pguid = ^tguid;
  1211. tguid = packed record
  1212. D1: LongWord;
  1213. D2: Word;
  1214. D3: Word;
  1215. D4: array[0..7] of Byte;
  1216. end;
  1217. absolutetyp = (tovar,toasm,toaddr);
  1218. tconsttyp = (constnone,
  1219. constord,conststring,constreal,
  1220. constset,constpointer,constnil,
  1221. constresourcestring,constwstring,constguid
  1222. );
  1223. var
  1224. b : byte;
  1225. pc : pchar;
  1226. totalsyms,
  1227. symcnt,
  1228. i,j,len : longint;
  1229. guid : tguid;
  1230. tempbuf : array[0..127] of char;
  1231. varoptions : tvaroptions;
  1232. begin
  1233. symcnt:=1;
  1234. with ppufile do
  1235. begin
  1236. if space<>'' then
  1237. Writeln(space,'------ ',s,' ------');
  1238. if readentry=ibstartsyms then
  1239. begin
  1240. totalsyms:=getlongint;
  1241. Writeln(space,'Number of symbols : ',totalsyms);
  1242. Writeln(space,'Symtable datasize : ',getlongint);
  1243. Writeln(space,'Symtable alignment: ',getlongint);
  1244. end
  1245. else
  1246. begin
  1247. totalsyms:=-1;
  1248. Writeln('!! ibstartsym not found');
  1249. end;
  1250. repeat
  1251. b:=readentry;
  1252. if not (b in [iberror,ibendsyms]) then
  1253. inc(symcnt);
  1254. case b of
  1255. ibunitsym :
  1256. readcommonsym('Unit symbol ');
  1257. iblabelsym :
  1258. readcommonsym('Label symbol ');
  1259. ibtypesym :
  1260. begin
  1261. readcommonsym('Type symbol ');
  1262. write(space,' Result Type : ');
  1263. readtype;
  1264. end;
  1265. ibprocsym :
  1266. begin
  1267. readcommonsym('Procedure symbol ');
  1268. len:=ppufile.getword;
  1269. for i:=1 to len do
  1270. begin
  1271. write(space,' Definition : ');
  1272. readderef;
  1273. end;
  1274. end;
  1275. ibconstsym :
  1276. begin
  1277. readcommonsym('Constant symbol ');
  1278. b:=getbyte;
  1279. case tconsttyp(b) of
  1280. constord :
  1281. begin
  1282. write (space,' OrdinalType : ');
  1283. readtype;
  1284. writeln(space,' Value : ',getint64);
  1285. end;
  1286. constpointer :
  1287. begin
  1288. write (space,' PointerType : ');
  1289. readtype;
  1290. writeln(space,' Value : ',getlongint)
  1291. end;
  1292. conststring,
  1293. constresourcestring :
  1294. begin
  1295. len:=getlongint;
  1296. getmem(pc,len+1);
  1297. getdata(pc^,len);
  1298. (pc+len)^:= #0;
  1299. writeln(space,' Length : ',len);
  1300. writeln(space,' Value : "',pc,'"');
  1301. freemem(pc,len+1);
  1302. if tconsttyp(b)=constresourcestring then
  1303. writeln(space,' Index : ',getlongint);
  1304. end;
  1305. constreal :
  1306. writeln(space,' Value : ',getreal);
  1307. constset :
  1308. begin
  1309. write (space,' Set Type : ');
  1310. readtype;
  1311. for i:=1to 4 do
  1312. begin
  1313. write (space,' Value : ');
  1314. for j:=1to 8 do
  1315. begin
  1316. if j>1 then
  1317. write(',');
  1318. write(hexb(getbyte));
  1319. end;
  1320. writeln;
  1321. end;
  1322. end;
  1323. constwstring:
  1324. begin
  1325. end;
  1326. constguid:
  1327. begin
  1328. getdata(guid,sizeof(guid));
  1329. write (space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-');
  1330. for i:=0 to 7 do
  1331. begin
  1332. write(hexstr(guid.d4[i],2));
  1333. if i=1 then write('-');
  1334. end;
  1335. writeln('}');
  1336. end
  1337. else
  1338. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  1339. end;
  1340. end;
  1341. ibabsolutevarsym :
  1342. begin
  1343. readabstractvarsym('Absolute variable symbol ',varoptions);
  1344. Write (space,' Relocated to ');
  1345. b:=getbyte;
  1346. case absolutetyp(b) of
  1347. tovar :
  1348. readsymlist(space+' Sym : ');
  1349. toasm :
  1350. Writeln('Assembler name : ',getstring);
  1351. toaddr :
  1352. begin
  1353. Write('Address : ',getlongint);
  1354. if tsystemcpu(ppufile.header.cpu)=cpu_i386 then
  1355. WriteLn(' (Far: ',getbyte<>0,')');
  1356. end;
  1357. else
  1358. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  1359. end;
  1360. end;
  1361. ibfieldvarsym :
  1362. begin
  1363. readabstractvarsym('Field Variable symbol ',varoptions);
  1364. writeln(space,' Address : ',getlongint);
  1365. end;
  1366. ibglobalvarsym :
  1367. begin
  1368. readabstractvarsym('Global Variable symbol ',varoptions);
  1369. write (space,' DefaultConst : ');
  1370. readderef;
  1371. if (vo_has_mangledname in varoptions) then
  1372. writeln(space,' Mangledname : ',getstring);
  1373. end;
  1374. iblocalvarsym :
  1375. begin
  1376. readabstractvarsym('Local Variable symbol ',varoptions);
  1377. write (space,' DefaultConst : ');
  1378. readderef;
  1379. end;
  1380. ibparavarsym :
  1381. begin
  1382. readabstractvarsym('Parameter Variable symbol ',varoptions);
  1383. write (space,' DefaultConst : ');
  1384. readderef;
  1385. writeln(space,' ParaNr : ',getword);
  1386. if (vo_has_explicit_paraloc in varoptions) then
  1387. begin
  1388. i:=getbyte;
  1389. getdata(tempbuf,i);
  1390. end;
  1391. end;
  1392. ibenumsym :
  1393. begin
  1394. readcommonsym('Enumeration symbol ');
  1395. write (space,' Definition : ');
  1396. readderef;
  1397. writeln(space,' Value : ',getlongint);
  1398. end;
  1399. ibsyssym :
  1400. begin
  1401. readcommonsym('Internal system symbol ');
  1402. writeln(space,' Internal Nr : ',getlongint);
  1403. end;
  1404. ibrttisym :
  1405. begin
  1406. readcommonsym('RTTI symbol ');
  1407. writeln(space,' RTTI Type : ',getbyte);
  1408. end;
  1409. ibmacrosym :
  1410. begin
  1411. readcommonsym('Macro symbol ');
  1412. writeln(space,' Name: ',getstring);
  1413. writeln(space,' Defined: ',getbyte);
  1414. writeln(space,' Compiler var: ',getbyte);
  1415. len:=getlongint;
  1416. writeln(space,' Value length: ',len);
  1417. if len > 0 then
  1418. begin
  1419. getmem(pc,len+1);
  1420. getdata(pc^,len);
  1421. (pc+len)^:= #0;
  1422. writeln(space,' Value: "',pc,'"');
  1423. freemem(pc,len+1);
  1424. end;
  1425. end;
  1426. ibtypedconstsym :
  1427. begin
  1428. readcommonsym('Typed constant ');
  1429. write (space,' Constant Type : ');
  1430. readtype;
  1431. writeln(space,' ReallyConst : ',(getbyte<>0));
  1432. end;
  1433. ibpropertysym :
  1434. begin
  1435. readcommonsym('Property ');
  1436. i:=getlongint;
  1437. writeln(space,' PropOptions : ',i);
  1438. if (i and 32)>0 then
  1439. begin
  1440. write (space,' OverrideProp : ');
  1441. readderef;
  1442. end
  1443. else
  1444. begin
  1445. write (space,' Prop Type : ');
  1446. readtype;
  1447. writeln(space,' Index : ',getlongint);
  1448. writeln(space,' Default : ',getlongint);
  1449. write (space,' Index Type : ');
  1450. readtype;
  1451. write (space,' Readaccess : ');
  1452. readsymlist(space+' Sym: ');
  1453. write (space,' Writeaccess : ');
  1454. readsymlist(space+' Sym: ');
  1455. write (space,' Storedaccess : ');
  1456. readsymlist(space+' Sym: ');
  1457. end;
  1458. end;
  1459. iberror :
  1460. begin
  1461. Writeln('!! Error in PPU');
  1462. exit;
  1463. end;
  1464. ibendsyms :
  1465. break;
  1466. else
  1467. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  1468. end;
  1469. if not EndOfEntry then
  1470. Writeln('!! Entry has more information stored');
  1471. until false;
  1472. if (totalsyms<>-1) and (symcnt-1<>totalsyms) then
  1473. Writeln('!! Only read ',symcnt-1,' of ',totalsyms,' symbols');
  1474. end;
  1475. end;
  1476. {****************************************************************************
  1477. Read defintions Part
  1478. ****************************************************************************}
  1479. procedure readdefinitions(const s:string;start_read : boolean);
  1480. type
  1481. tsettype = (normset,smallset,varset);
  1482. tbasetype = (
  1483. uvoid,
  1484. u8bit,u16bit,u32bit,u64bit,
  1485. s8bit,s16bit,s32bit,s64bit,
  1486. bool8bit,bool16bit,bool32bit,
  1487. uchar,uwidechar,scurrency
  1488. );
  1489. tobjectdeftype = (odt_none,
  1490. odt_class,
  1491. odt_object,
  1492. odt_interfacecom,
  1493. odt_interfacecorba,
  1494. odt_cppclass
  1495. );
  1496. tvarianttype = (
  1497. vt_normalvariant,vt_olevariant
  1498. );
  1499. var
  1500. b : byte;
  1501. totaldefs,l,j,
  1502. defcnt : longint;
  1503. calloption : tproccalloption;
  1504. procoptions : tprocoptions;
  1505. procinfooptions : tprocinfoflag;
  1506. begin
  1507. defcnt:=0;
  1508. with ppufile do
  1509. begin
  1510. if space<>'' then
  1511. Writeln(space,'------ ',s,' ------');
  1512. if not start_read then
  1513. if readentry=ibstartdefs then
  1514. begin
  1515. totaldefs:=getlongint;
  1516. Writeln(space,'Number of definitions: ',totaldefs);
  1517. end
  1518. else
  1519. begin
  1520. totaldefs:=-1;
  1521. Writeln('!! ibstartdef not found');
  1522. end;
  1523. repeat
  1524. b:=readentry;
  1525. if not (b in [iberror,ibenddefs]) then
  1526. inc(defcnt);
  1527. case b of
  1528. ibpointerdef :
  1529. begin
  1530. readcommondef('Pointer definition');
  1531. write (space,' Pointed Type : ');
  1532. readtype;
  1533. writeln(space,' Is Far : ',(getbyte<>0));
  1534. end;
  1535. iborddef :
  1536. begin
  1537. readcommondef('Ordinal definition');
  1538. write (space,' Base type : ');
  1539. b:=getbyte;
  1540. case tbasetype(b) of
  1541. uvoid : writeln('uvoid');
  1542. u8bit : writeln('u8bit');
  1543. u16bit : writeln('u16bit');
  1544. u32bit : writeln('s32bit');
  1545. u64bit : writeln('u64bit');
  1546. s8bit : writeln('s8bit');
  1547. s16bit : writeln('s16bit');
  1548. s32bit : writeln('s32bit');
  1549. s64bit : writeln('s64bit');
  1550. bool8bit : writeln('bool8bit');
  1551. bool16bit : writeln('bool16bit');
  1552. bool32bit : writeln('bool32bit');
  1553. uchar : writeln('uchar');
  1554. uwidechar : writeln('uwidechar');
  1555. scurrency : writeln('ucurrency');
  1556. else writeln('!! Warning: Invalid base type ',b);
  1557. end;
  1558. writeln(space,' Range : ',getint64,' to ',getint64);
  1559. end;
  1560. ibfloatdef :
  1561. begin
  1562. readcommondef('Float definition');
  1563. writeln(space,' Float type : ',getbyte);
  1564. end;
  1565. ibarraydef :
  1566. begin
  1567. readcommondef('Array definition');
  1568. write (space,' Element type : ');
  1569. readtype;
  1570. write (space,' Range Type : ');
  1571. readtype;
  1572. writeln(space,' Range : ',getlongint,' to ',getlongint);
  1573. write (space,' Options : ');
  1574. readarraydefoptions;
  1575. end;
  1576. ibprocdef :
  1577. begin
  1578. readcommondef('Procedure definition');
  1579. read_abstract_proc_def(calloption,procoptions);
  1580. if (po_has_mangledname in procoptions) then
  1581. writeln(space,' Mangled name : ',getstring);
  1582. writeln(space,' Number : ',getword);
  1583. writeln(space,' Level : ',getbyte);
  1584. write (space,' Class : ');
  1585. readderef;
  1586. write (space,' Procsym : ');
  1587. readderef;
  1588. write (space,' File Pos : ');
  1589. readposinfo;
  1590. write (space,' SymOptions : ');
  1591. readsymoptions;
  1592. if tsystemcpu(ppufile.header.cpu)=cpu_powerpc then
  1593. begin
  1594. { library symbol for AmigaOS/MorphOS }
  1595. write (space,' Library symbol : ');
  1596. readderef;
  1597. end;
  1598. if (po_has_importdll in procoptions) then
  1599. writeln(space,' Import DLL : ',getstring);
  1600. if (po_has_importname in procoptions) then
  1601. writeln(space,' Import Name : ',getstring);
  1602. writeln(space,' Import Nr : ',getword);
  1603. if (po_inline in procoptions) then
  1604. begin
  1605. write (space,' FuncretSym : ');
  1606. readderef;
  1607. ppufile.getsmallset(procinfooptions);
  1608. writeln(space,' ProcInfoOptions : ',dword(procinfooptions));
  1609. b := ppufile.getbyte;
  1610. writeln(space,' Inline node tree : ',b);
  1611. end;
  1612. if not EndOfEntry then
  1613. Writeln('!! Entry has more information stored');
  1614. space:=' '+space;
  1615. { parast }
  1616. readdefinitions('parast',false);
  1617. readsymbols('parast');
  1618. { localst }
  1619. if (po_has_inlininginfo in procoptions) or
  1620. ((ppufile.header.flags and uf_local_browser)<>0) then
  1621. begin
  1622. readdefinitions('localst',false);
  1623. readsymbols('localst');
  1624. end;
  1625. if (po_has_inlininginfo in procoptions) then
  1626. readnodetree;
  1627. delete(space,1,4);
  1628. end;
  1629. ibprocvardef :
  1630. begin
  1631. readcommondef('Procedural type (ProcVar) definition');
  1632. read_abstract_proc_def(calloption,procoptions);
  1633. if not EndOfEntry then
  1634. Writeln('!! Entry has more information stored');
  1635. space:=' '+space;
  1636. { parast }
  1637. readdefinitions('parast',false);
  1638. readsymbols('parast');
  1639. delete(space,1,4);
  1640. end;
  1641. ibshortstringdef :
  1642. begin
  1643. readcommondef('ShortString definition');
  1644. writeln(space,' Length : ',getbyte);
  1645. end;
  1646. ibwidestringdef :
  1647. begin
  1648. readcommondef('WideString definition');
  1649. writeln(space,' Length : ',getlongint);
  1650. end;
  1651. ibansistringdef :
  1652. begin
  1653. readcommondef('AnsiString definition');
  1654. writeln(space,' Length : ',getlongint);
  1655. end;
  1656. iblongstringdef :
  1657. begin
  1658. readcommondef('Longstring definition');
  1659. writeln(space,' Length : ',getlongint);
  1660. end;
  1661. ibrecorddef :
  1662. begin
  1663. readcommondef('Record definition');
  1664. writeln(space,' DataSize : ',getlongint);
  1665. writeln(space,' FieldAlign : ',getbyte);
  1666. writeln(space,' RecordAlign : ',getbyte);
  1667. writeln(space,' PadAlign : ',getbyte);
  1668. if not EndOfEntry then
  1669. Writeln('!! Entry has more information stored');
  1670. {read the record definitions and symbols}
  1671. space:=' '+space;
  1672. readdefinitions('fields',false);
  1673. readsymbols('fields');
  1674. Delete(space,1,4);
  1675. end;
  1676. ibobjectdef :
  1677. begin
  1678. readcommondef('Object/Class definition');
  1679. b:=getbyte;
  1680. write (space,' Type : ');
  1681. case tobjectdeftype(b) of
  1682. odt_class : writeln('class');
  1683. odt_object : writeln('object');
  1684. odt_interfacecom : writeln('interfacecom');
  1685. odt_interfacecorba : writeln('interfacecorba');
  1686. odt_cppclass : writeln('cppclass');
  1687. else writeln('!! Warning: Invalid object type ',b);
  1688. end;
  1689. writeln(space,' Name of Class : ',getstring);
  1690. writeln(space,' DataSize : ',getlongint);
  1691. writeln(space,' FieldAlign : ',getbyte);
  1692. writeln(space,' RecordAlign : ',getbyte);
  1693. writeln(space,' Vmt offset : ',getlongint);
  1694. write (space, ' Ancestor Class : ');
  1695. readderef;
  1696. write (space,' Options : ');
  1697. readobjectdefoptions;
  1698. if tobjectdeftype(b) in [odt_interfacecom,odt_interfacecorba] then
  1699. begin
  1700. { IIDGUID }
  1701. for j:=1to 16 do
  1702. getbyte;
  1703. writeln(space,' IID String : ',getstring);
  1704. writeln(space,' Last VTable idx : ',getlongint);
  1705. end;
  1706. if tobjectdeftype(b) in [odt_class,odt_interfacecorba] then
  1707. begin
  1708. l:=getlongint;
  1709. writeln(space,' Impl Intf Count : ',l);
  1710. for j:=1 to l do
  1711. begin
  1712. write (space,' - Definition : ');
  1713. readderef;
  1714. writeln(space,' IOffset : ',getlongint);
  1715. end;
  1716. end;
  1717. if not EndOfEntry then
  1718. Writeln('!! Entry has more information stored');
  1719. {read the record definitions and symbols}
  1720. space:=' '+space;
  1721. readdefinitions('fields',false);
  1722. readsymbols('fields');
  1723. Delete(space,1,4);
  1724. end;
  1725. ibfiledef :
  1726. begin
  1727. ReadCommonDef('File definition');
  1728. write (space,' Type : ');
  1729. case getbyte of
  1730. 0 : writeln('Text');
  1731. 1 : begin
  1732. writeln('Typed');
  1733. write (space,' File of Type : ');
  1734. Readtype;
  1735. end;
  1736. 2 : writeln('Untyped');
  1737. end;
  1738. end;
  1739. ibformaldef :
  1740. readcommondef('Generic definition (void-typ)');
  1741. ibundefineddef :
  1742. readcommondef('Undefined definition (generic parameter)');
  1743. ibenumdef :
  1744. begin
  1745. readcommondef('Enumeration type definition');
  1746. write(space,'Base enumeration type : ');
  1747. readderef;
  1748. writeln(space,' Smallest element : ',getlongint);
  1749. writeln(space,' Largest element : ',getlongint);
  1750. writeln(space,' Size : ',getlongint);
  1751. end;
  1752. ibclassrefdef :
  1753. begin
  1754. readcommondef('Class reference definition');
  1755. write (space,' Pointed Type : ');
  1756. readtype;
  1757. end;
  1758. ibsetdef :
  1759. begin
  1760. readcommondef('Set definition');
  1761. write (space,' Element type : ');
  1762. readtype;
  1763. b:=getbyte;
  1764. case tsettype(b) of
  1765. smallset : writeln(space,' Set with 32 Elements');
  1766. normset : writeln(space,' Set with 256 Elements');
  1767. varset : writeln(space,' Set with ',getlongint,' Elements');
  1768. else writeln('!! Warning: Invalid set type ',b);
  1769. end;
  1770. end;
  1771. ibvariantdef :
  1772. begin
  1773. readcommondef('Variant definition');
  1774. write (space,' Varianttype : ');
  1775. b:=getbyte;
  1776. case tvarianttype(b) of
  1777. vt_normalvariant :
  1778. writeln('Normal');
  1779. vt_olevariant :
  1780. writeln('OLE');
  1781. else
  1782. writeln('!! Warning: Invalid varianttype ',b);
  1783. end;
  1784. end;
  1785. iberror :
  1786. begin
  1787. Writeln('!! Error in PPU');
  1788. exit;
  1789. end;
  1790. ibenddefs :
  1791. break;
  1792. else
  1793. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  1794. end;
  1795. if not EndOfEntry then
  1796. Writeln('!! Entry has more information stored');
  1797. until false;
  1798. if (totaldefs<>-1) and (defcnt<>totaldefs) then
  1799. Writeln('!! Only read ',defcnt,' of ',totaldefs,' definitions');
  1800. end;
  1801. end;
  1802. {****************************************************************************
  1803. Read General Part
  1804. ****************************************************************************}
  1805. procedure readinterface;
  1806. var
  1807. b : byte;
  1808. sourcenumber : longint;
  1809. begin
  1810. with ppufile do
  1811. begin
  1812. repeat
  1813. b:=readentry;
  1814. case b of
  1815. ibmodulename :
  1816. Writeln('Module Name: ',getstring);
  1817. ibsourcefiles :
  1818. begin
  1819. sourcenumber:=1;
  1820. while not EndOfEntry do
  1821. begin
  1822. Writeln('Source file ',sourcenumber,' : ',getstring,' ',filetimestring(getlongint));
  1823. inc(sourcenumber);
  1824. end;
  1825. end;
  1826. {$IFDEF MACRO_DIFF_HINT}
  1827. ibusedmacros :
  1828. begin
  1829. while not EndOfEntry do
  1830. begin
  1831. Write('Conditional ',getstring);
  1832. b:=getbyte;
  1833. if boolean(b)=true then
  1834. write(' defined at startup')
  1835. else
  1836. write(' not defined at startup');
  1837. b:=getbyte;
  1838. if boolean(b)=true then
  1839. writeln(' was used')
  1840. else
  1841. writeln;
  1842. end;
  1843. end;
  1844. {$ENDIF}
  1845. ibloadunit :
  1846. ReadLoadUnit;
  1847. iblinkunitofiles :
  1848. ReadLinkContainer('Link unit object file: ');
  1849. iblinkunitstaticlibs :
  1850. ReadLinkContainer('Link unit static lib: ');
  1851. iblinkunitsharedlibs :
  1852. ReadLinkContainer('Link unit shared lib: ');
  1853. iblinkotherofiles :
  1854. ReadLinkContainer('Link other object file: ');
  1855. iblinkotherstaticlibs :
  1856. ReadLinkContainer('Link other static lib: ');
  1857. iblinkothersharedlibs :
  1858. ReadLinkContainer('Link other shared lib: ');
  1859. iblinkdlls :
  1860. ReadLinkContainer('Link DLLs: ');
  1861. ibderefdata :
  1862. ReadDerefData;
  1863. ibderefmap :
  1864. ReadDerefMap;
  1865. iberror :
  1866. begin
  1867. Writeln('Error in PPU');
  1868. exit;
  1869. end;
  1870. ibendinterface :
  1871. break;
  1872. else
  1873. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  1874. end;
  1875. until false;
  1876. end;
  1877. end;
  1878. {****************************************************************************
  1879. Read Implementation Part
  1880. ****************************************************************************}
  1881. procedure readimplementation;
  1882. var
  1883. b : byte;
  1884. begin
  1885. with ppufile do
  1886. begin
  1887. repeat
  1888. b:=readentry;
  1889. case b of
  1890. ibasmsymbols :
  1891. ReadAsmSymbols;
  1892. ibloadunit :
  1893. ReadLoadUnit;
  1894. iberror :
  1895. begin
  1896. Writeln('Error in PPU');
  1897. exit;
  1898. end;
  1899. ibendimplementation :
  1900. break;
  1901. else
  1902. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  1903. end;
  1904. until false;
  1905. end;
  1906. end;
  1907. {****************************************************************************
  1908. Read Browser Part
  1909. ****************************************************************************}
  1910. procedure readbrowser;
  1911. var
  1912. b : byte;
  1913. const indent : string = '';
  1914. begin
  1915. Writeln(indent,'Start of symtable browser');
  1916. indent:=indent+'**';
  1917. with ppufile do
  1918. begin
  1919. repeat
  1920. b:=readentry;
  1921. case b of
  1922. ibbeginsymtablebrowser :
  1923. begin
  1924. { here we must read object and record symtables !! }
  1925. indent:=indent+' ';
  1926. Writeln(indent,'Record/Object symtable');
  1927. readbrowser;
  1928. Indent:=Copy(Indent,1,Length(Indent)-2);
  1929. end;
  1930. ibsymref :
  1931. begin
  1932. readderef;
  1933. readref;
  1934. end;
  1935. ibdefref :
  1936. begin
  1937. readderef;
  1938. readref;
  1939. if ((ppufile.header.flags and uf_local_browser)<>0) and
  1940. (UnitIndex=0) then
  1941. begin
  1942. { parast and localst }
  1943. indent:=indent+' ';
  1944. b:=ppufile.readentry;
  1945. if b=ibbeginsymtablebrowser then
  1946. readbrowser;
  1947. b:=ppufile.readentry;
  1948. if b=ibbeginsymtablebrowser then
  1949. readbrowser;
  1950. Indent:=Copy(Indent,1,Length(Indent)-2);
  1951. end;
  1952. end;
  1953. iberror :
  1954. begin
  1955. Writeln('Error in PPU');
  1956. exit;
  1957. end;
  1958. ibendsymtablebrowser :
  1959. break;
  1960. else
  1961. begin
  1962. WriteLn('!! Skipping unsupported PPU Entry in Browser: ',b);
  1963. Halt;
  1964. end;
  1965. end;
  1966. until false;
  1967. end;
  1968. Indent:=Copy(Indent,1,Length(Indent)-2);
  1969. Writeln(Indent,'End of symtable browser');
  1970. end;
  1971. procedure dofile (filename : string);
  1972. var
  1973. b : byte;
  1974. begin
  1975. { reset }
  1976. space:='';
  1977. { fix filename }
  1978. if pos('.',filename)=0 then
  1979. filename:=filename+'.ppu';
  1980. ppufile:=tppufile.create(filename);
  1981. if not ppufile.openfile then
  1982. begin
  1983. writeln ('IO-Error when opening : ',filename,', Skipping');
  1984. exit;
  1985. end;
  1986. { PPU File is open, check for PPU Id }
  1987. if not ppufile.CheckPPUID then
  1988. begin
  1989. writeln(Filename,' : Not a valid PPU file, Skipping');
  1990. exit;
  1991. end;
  1992. { Check PPU Version }
  1993. Writeln('Analyzing ',filename,' (v',ppufile.GetPPUVersion,')');
  1994. if ppufile.GetPPUVersion<16 then
  1995. begin
  1996. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  1997. exit;
  1998. end;
  1999. { Write PPU Header Information }
  2000. if (verbose and v_header)<>0 then
  2001. begin
  2002. Writeln;
  2003. Writeln('Header');
  2004. Writeln('-------');
  2005. with ppufile.header do
  2006. begin
  2007. Writeln('Compiler version : ',ppufile.header.compiler shr 14,'.',
  2008. (ppufile.header.compiler shr 7) and $7f,'.',
  2009. ppufile.header.compiler and $7f);
  2010. WriteLn('Target processor : ',Cpu2Str(cpu));
  2011. WriteLn('Target operating system : ',Target2Str(target));
  2012. Writeln('Unit flags : ',PPUFlags2Str(flags));
  2013. Writeln('FileSize (w/o header) : ',size);
  2014. Writeln('Checksum : ',hexstr(checksum,8));
  2015. Writeln('Interface Checksum : ',hexstr(interface_checksum,8));
  2016. end;
  2017. end;
  2018. {read the general stuff}
  2019. if (verbose and v_interface)<>0 then
  2020. begin
  2021. Writeln;
  2022. Writeln('Interface section');
  2023. Writeln('------------------');
  2024. readinterface;
  2025. end
  2026. else
  2027. ppufile.skipuntilentry(ibendinterface);
  2028. {read the definitions}
  2029. if (verbose and v_defs)<>0 then
  2030. begin
  2031. Writeln;
  2032. Writeln('Interface definitions');
  2033. Writeln('----------------------');
  2034. readdefinitions('interface',false);
  2035. end
  2036. else
  2037. ppufile.skipuntilentry(ibenddefs);
  2038. {read the symbols}
  2039. if (verbose and v_syms)<>0 then
  2040. begin
  2041. Writeln;
  2042. Writeln('Interface Symbols');
  2043. Writeln('------------------');
  2044. readsymbols('interface');
  2045. end
  2046. else
  2047. ppufile.skipuntilentry(ibendsyms);
  2048. {read the macro symbols}
  2049. if (verbose and v_syms)<>0 then
  2050. begin
  2051. Writeln;
  2052. Writeln('Interface Macro Symbols');
  2053. Writeln('-----------------------');
  2054. end;
  2055. if ppufile.readentry<>ibexportedmacros then
  2056. begin
  2057. Writeln('!! Error in PPU');
  2058. exit;
  2059. end;
  2060. if boolean(ppufile.getbyte) then
  2061. begin
  2062. {skip the definition section for macros (since they are never used) }
  2063. ppufile.skipuntilentry(ibenddefs);
  2064. {read the macro symbols}
  2065. if (verbose and v_syms)<>0 then
  2066. readsymbols('interface macro')
  2067. else
  2068. ppufile.skipuntilentry(ibendsyms);
  2069. end
  2070. else
  2071. Writeln('(no exported macros)');
  2072. {read the implementation stuff}
  2073. if (verbose and v_implementation)<>0 then
  2074. begin
  2075. Writeln;
  2076. Writeln('Implementation section');
  2077. Writeln('-----------------------');
  2078. readimplementation;
  2079. end
  2080. else
  2081. ppufile.skipuntilentry(ibendimplementation);
  2082. {read the static browser units stuff}
  2083. if (ppufile.header.flags and uf_local_symtable)<>0 then
  2084. begin
  2085. if (verbose and v_defs)<>0 then
  2086. begin
  2087. Writeln;
  2088. Writeln('Static definitions');
  2089. Writeln('----------------------');
  2090. readdefinitions('implementation',false);
  2091. end
  2092. else
  2093. ppufile.skipuntilentry(ibenddefs);
  2094. {read the symbols}
  2095. if (verbose and v_syms)<>0 then
  2096. begin
  2097. Writeln;
  2098. Writeln('Static Symbols');
  2099. Writeln('------------------');
  2100. readsymbols('implementation');
  2101. end
  2102. else
  2103. ppufile.skipuntilentry(ibendsyms);
  2104. end;
  2105. {read the browser units stuff}
  2106. if (ppufile.header.flags and uf_has_browser)<>0 then
  2107. begin
  2108. if (verbose and v_browser)<>0 then
  2109. begin
  2110. Writeln;
  2111. Writeln('Browser section');
  2112. Writeln('---------------');
  2113. UnitIndex:=0;
  2114. repeat
  2115. b:=ppufile.readentry;
  2116. if b = ibendbrowser then break;
  2117. if b=ibbeginsymtablebrowser then
  2118. begin
  2119. Writeln('Unit ',UnitIndex);
  2120. readbrowser;
  2121. Inc(UnitIndex);
  2122. end
  2123. else
  2124. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  2125. until false;
  2126. end;
  2127. end;
  2128. {read the static browser units stuff}
  2129. if (ppufile.header.flags and uf_local_browser)<>0 then
  2130. begin
  2131. if (verbose and v_browser)<>0 then
  2132. begin
  2133. Writeln;
  2134. Writeln('Static browser section');
  2135. Writeln('---------------');
  2136. UnitIndex:=0;
  2137. b:=ppufile.readentry;
  2138. if b=ibbeginsymtablebrowser then
  2139. readbrowser
  2140. else
  2141. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  2142. end;
  2143. end;
  2144. {shutdown ppufile}
  2145. ppufile.closefile;
  2146. ppufile.free;
  2147. Writeln;
  2148. end;
  2149. procedure help;
  2150. begin
  2151. writeln('usage: ppudump [options] <filename1> <filename2>...');
  2152. writeln;
  2153. writeln('[options] can be:');
  2154. writeln(' -V<verbose> Set verbosity to <verbose>');
  2155. writeln(' H - Show header info');
  2156. writeln(' I - Show interface');
  2157. writeln(' M - Show implementation');
  2158. writeln(' S - Show interface symbols');
  2159. writeln(' D - Show interface definitions');
  2160. writeln(' B - Show browser info');
  2161. writeln(' A - Show all');
  2162. writeln(' -h, -? This helpscreen');
  2163. halt;
  2164. end;
  2165. var
  2166. startpara,
  2167. nrfile,i : longint;
  2168. para : string;
  2169. begin
  2170. writeln(Title+' '+Version);
  2171. writeln(Copyright);
  2172. writeln;
  2173. if paramcount<1 then
  2174. begin
  2175. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  2176. halt(1);
  2177. end;
  2178. { turn verbose on by default }
  2179. verbose:=v_all;
  2180. { read options }
  2181. startpara:=1;
  2182. while copy(paramstr(startpara),1,1)='-' do
  2183. begin
  2184. para:=paramstr(startpara);
  2185. case upcase(para[2]) of
  2186. 'V' : begin
  2187. verbose:=0;
  2188. for i:=3 to length(para) do
  2189. case upcase(para[i]) of
  2190. 'H' : verbose:=verbose or v_header;
  2191. 'I' : verbose:=verbose or v_interface;
  2192. 'M' : verbose:=verbose or v_implementation;
  2193. 'D' : verbose:=verbose or v_defs;
  2194. 'S' : verbose:=verbose or v_syms;
  2195. 'B' : verbose:=verbose or v_browser;
  2196. 'A' : verbose:=verbose or v_all;
  2197. end;
  2198. end;
  2199. 'H' : help;
  2200. '?' : help;
  2201. end;
  2202. inc(startpara);
  2203. end;
  2204. { process files }
  2205. for nrfile:=startpara to paramcount do
  2206. dofile (paramstr(nrfile));
  2207. if has_errors then
  2208. Halt(1);
  2209. end.