ppudump.pp 65 KB

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