ppudump.pp 73 KB

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