ppudump.pp 67 KB

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