ppudump.pp 67 KB

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