ppudump.pp 75 KB

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