ppudump.pp 65 KB

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