2
0

ppudump.pp 71 KB

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