ppudump.pp 66 KB

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