ppudump.pp 66 KB

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