ppudump.pp 66 KB

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