ppudump.pp 72 KB

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