ppudump.pp 66 KB

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