ppudump.pp 65 KB

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