ppudump.pp 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575
  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. );
  1230. tvaroptions=set of tvaroption;
  1231. { register variable }
  1232. tvarregable=(vr_none,
  1233. vr_intreg,
  1234. vr_fpureg,
  1235. vr_mmreg,
  1236. { does not mean "needs address register", but "if it's a parameter which is }
  1237. { passed by reference, then its address can be put in a register }
  1238. vr_addr
  1239. );
  1240. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions);
  1241. type
  1242. tvaropt=record
  1243. mask : tvaroption;
  1244. str : string[30];
  1245. end;
  1246. const
  1247. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  1248. (mask:vo_is_external; str:'External'),
  1249. (mask:vo_is_dll_var; str:'DLLVar'),
  1250. (mask:vo_is_thread_var; str:'ThreadVar'),
  1251. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  1252. (mask:vo_is_const; str:'Constant'),
  1253. (mask:vo_is_public; str:'Public'),
  1254. (mask:vo_is_high_para; str:'HighValue'),
  1255. (mask:vo_is_funcret; str:'Funcret'),
  1256. (mask:vo_is_self; str:'Self'),
  1257. (mask:vo_is_vmt; str:'VMT'),
  1258. (mask:vo_is_result; str:'Result'),
  1259. (mask:vo_is_parentfp; str:'ParentFP'),
  1260. (mask:vo_is_loop_counter; str:'LoopCounter'),
  1261. (mask:vo_is_hidden_para; str:'Hidden'),
  1262. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  1263. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  1264. (mask:vo_has_mangledname; str:'HasMangledName'),
  1265. (mask:vo_is_typed_const; str:'TypedConst'),
  1266. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  1267. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  1268. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  1269. (mask:vo_is_weak_external;str:'WeakExternal')
  1270. );
  1271. var
  1272. i : longint;
  1273. first : boolean;
  1274. begin
  1275. readcommonsym(s);
  1276. writeln(space,' Spez : ',Varspez2Str(ppufile.getbyte));
  1277. writeln(space,' Regable : ',Varregable2Str(ppufile.getbyte));
  1278. writeln(space,' Addr Taken : ',(ppufile.getbyte<>0));
  1279. write (space,' Var Type : ');
  1280. readderef('');
  1281. ppufile.getsmallset(varoptions);
  1282. if varoptions<>[] then
  1283. begin
  1284. write(space,' Options : ');
  1285. first:=true;
  1286. for i:=1 to high(varopt) do
  1287. if (varopt[i].mask in varoptions) then
  1288. begin
  1289. if first then
  1290. first:=false
  1291. else
  1292. write(', ');
  1293. write(varopt[i].str);
  1294. end;
  1295. writeln;
  1296. end;
  1297. end;
  1298. procedure readobjectdefoptions;
  1299. type
  1300. tobjectoption=(oo_none,
  1301. oo_is_forward, { the class is only a forward declared yet }
  1302. oo_is_abstract, { the class is abstract - only descendants can be used }
  1303. oo_is_sealed, { the class is sealed - can't have descendants }
  1304. oo_has_virtual, { the object/class has virtual methods }
  1305. oo_has_private,
  1306. oo_has_protected,
  1307. oo_has_strictprivate,
  1308. oo_has_strictprotected,
  1309. oo_has_constructor, { the object/class has a constructor }
  1310. oo_has_destructor, { the object/class has a destructor }
  1311. oo_has_vmt, { the object/class has a vmt }
  1312. oo_has_msgstr,
  1313. oo_has_msgint,
  1314. oo_can_have_published,{ the class has rtti, i.e. you can publish properties }
  1315. oo_has_default_property,
  1316. oo_has_valid_guid,
  1317. oo_has_enumerator_movenext,
  1318. oo_has_enumerator_current,
  1319. oo_is_external, { the class is externally implemented (objcclass, cppclass) }
  1320. oo_is_anonymous, { the class is only formally defined in this module (objcclass x = class; external;) }
  1321. oo_is_classhelper { objcclasses that represent categories, and Delpi-style class helpers, are marked like this }
  1322. );
  1323. tobjectoptions=set of tobjectoption;
  1324. tsymopt=record
  1325. mask : tobjectoption;
  1326. str : string[30];
  1327. end;
  1328. const
  1329. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  1330. (mask:oo_is_forward; str:'IsForward'),
  1331. (mask:oo_is_abstract; str:'IsAbstract'),
  1332. (mask:oo_is_sealed; str:'IsSealed'),
  1333. (mask:oo_has_virtual; str:'HasVirtual'),
  1334. (mask:oo_has_private; str:'HasPrivate'),
  1335. (mask:oo_has_protected; str:'HasProtected'),
  1336. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  1337. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  1338. (mask:oo_has_constructor; str:'HasConstructor'),
  1339. (mask:oo_has_destructor; str:'HasDestructor'),
  1340. (mask:oo_has_vmt; str:'HasVMT'),
  1341. (mask:oo_has_msgstr; str:'HasMsgStr'),
  1342. (mask:oo_has_msgint; str:'HasMsgInt'),
  1343. (mask:oo_can_have_published; str:'CanHavePublished'),
  1344. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  1345. (mask:oo_has_valid_guid; str:'HasValidGUID'),
  1346. (mask:oo_has_enumerator_movenext; str:'HasEnumeratorMoveNext'),
  1347. (mask:oo_has_enumerator_current; str:'HasEnumeratorCurrent'),
  1348. (mask:oo_is_external; str:'External'),
  1349. (mask:oo_is_anonymous; str:'Anonymous'),
  1350. (mask:oo_is_classhelper; str:'Class Helper/Category'));
  1351. var
  1352. symoptions : tobjectoptions;
  1353. i : longint;
  1354. first : boolean;
  1355. begin
  1356. ppufile.getsmallset(symoptions);
  1357. if symoptions<>[] then
  1358. begin
  1359. first:=true;
  1360. for i:=1 to high(symopt) do
  1361. if (symopt[i].mask in symoptions) then
  1362. begin
  1363. if first then
  1364. first:=false
  1365. else
  1366. write(', ');
  1367. write(symopt[i].str);
  1368. end;
  1369. end;
  1370. writeln;
  1371. end;
  1372. procedure readarraydefoptions;
  1373. type
  1374. tarraydefoption=(ado_none,
  1375. ado_IsConvertedPointer,
  1376. ado_IsDynamicArray,
  1377. ado_IsVariant,
  1378. ado_IsConstructor,
  1379. ado_IsArrayOfConst,
  1380. ado_IsConstString,
  1381. ado_IsBitPacked
  1382. );
  1383. tarraydefoptions=set of tarraydefoption;
  1384. tsymopt=record
  1385. mask : tarraydefoption;
  1386. str : string[30];
  1387. end;
  1388. const
  1389. symopt : array[1..ord(high(tarraydefoption))] of tsymopt=(
  1390. (mask:ado_IsConvertedPointer;str:'ConvertedPointer'),
  1391. (mask:ado_IsDynamicArray; str:'IsDynamicArray'),
  1392. (mask:ado_IsVariant; str:'IsVariant'),
  1393. (mask:ado_IsConstructor; str:'IsConstructor'),
  1394. (mask:ado_IsArrayOfConst; str:'ArrayOfConst'),
  1395. (mask:ado_IsConstString; str:'ConstString'),
  1396. (mask:ado_IsBitPacked; str:'BitPacked')
  1397. );
  1398. var
  1399. symoptions : tarraydefoptions;
  1400. i : longint;
  1401. first : boolean;
  1402. begin
  1403. ppufile.getsmallset(symoptions);
  1404. if symoptions<>[] then
  1405. begin
  1406. first:=true;
  1407. for i:=1 to high(symopt) do
  1408. if (symopt[i].mask in symoptions) then
  1409. begin
  1410. if first then
  1411. first:=false
  1412. else
  1413. write(', ');
  1414. write(symopt[i].str);
  1415. end;
  1416. end;
  1417. writeln;
  1418. end;
  1419. procedure readnodetree;
  1420. var
  1421. l : longint;
  1422. p : pointer;
  1423. begin
  1424. with ppufile do
  1425. begin
  1426. if space<>'' then
  1427. Writeln(space,'------ nodetree ------');
  1428. if readentry=ibnodetree then
  1429. begin
  1430. l:=entrysize;
  1431. Writeln(space,'Tree size : ',l);
  1432. { Read data to prevent error that entry is not completly read }
  1433. getmem(p,l);
  1434. getdata(p^,l);
  1435. freemem(p);
  1436. end
  1437. else
  1438. begin
  1439. Writeln('!! ibnodetree not found');
  1440. end;
  1441. end;
  1442. end;
  1443. procedure ReadCreatedObjTypes;
  1444. var
  1445. i,j,
  1446. len,
  1447. bssize: longint;
  1448. bs: pbyte;
  1449. begin
  1450. if ppufile.readentry<>ibcreatedobjtypes then
  1451. begin
  1452. writeln('!! ibcreatedobjtypes entry not found');
  1453. ppufile.skipdata(ppufile.entrysize);
  1454. exit
  1455. end;
  1456. writeln;
  1457. writeln(space,'WPO info');
  1458. writeln(space,'--------');
  1459. len:=ppufile.getlongint;
  1460. writeln(space,'** Instantiated Object/Class types: ',len,' **');
  1461. space:=space+' ';
  1462. for i:=0 to len-1 do
  1463. readderef(space);
  1464. setlength(space,length(space)-2);
  1465. len:=ppufile.getlongint;
  1466. writeln(space,'** Instantiated ClassRef 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,'** Possibly 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,'** Class types with called virtual methods info : ',len,' **');
  1479. space:=space+' ';
  1480. for i:=0 to len-1 do
  1481. begin
  1482. write(space,'Class def : ');
  1483. readderef('');
  1484. write(space+' ','Called vmtentries : ');
  1485. bssize:=ppufile.getlongint;
  1486. getmem(bs,bssize);
  1487. ppufile.readdata(bs^,bssize);
  1488. for j:=0 to bssize*8-1 do
  1489. if (((bs+j shr 3)^ shr (j and 7)) and 1) <> 0 then
  1490. write(j,', ');
  1491. writeln;
  1492. freemem(bs);
  1493. end;
  1494. setlength(space,length(space)-2);
  1495. end;
  1496. {****************************************************************************
  1497. Read Symbols Part
  1498. ****************************************************************************}
  1499. procedure readsymbols(const s:string);
  1500. type
  1501. pguid = ^tguid;
  1502. tguid = packed record
  1503. D1: LongWord;
  1504. D2: Word;
  1505. D3: Word;
  1506. D4: array[0..7] of Byte;
  1507. end;
  1508. absolutetyp = (tovar,toasm,toaddr);
  1509. tconsttyp = (constnone,
  1510. constord,conststring,constreal,
  1511. constset,constpointer,constnil,
  1512. constresourcestring,constwstring,constguid
  1513. );
  1514. var
  1515. b : byte;
  1516. pc : pchar;
  1517. i,j,len : longint;
  1518. guid : tguid;
  1519. tempbuf : array[0..127] of char;
  1520. varoptions : tvaroptions;
  1521. begin
  1522. with ppufile do
  1523. begin
  1524. if space<>'' then
  1525. Writeln(space,'------ ',s,' ------');
  1526. if readentry=ibstartsyms then
  1527. begin
  1528. Writeln(space,'Symtable datasize : ',getlongint);
  1529. Writeln(space,'Symtable alignment: ',getlongint);
  1530. end
  1531. else
  1532. Writeln('!! ibstartsym not found');
  1533. repeat
  1534. b:=readentry;
  1535. case b of
  1536. ibunitsym :
  1537. readcommonsym('Unit symbol ');
  1538. iblabelsym :
  1539. readcommonsym('Label symbol ');
  1540. ibtypesym :
  1541. begin
  1542. readcommonsym('Type symbol ');
  1543. write(space,' Result Type : ');
  1544. readderef('');
  1545. end;
  1546. ibprocsym :
  1547. begin
  1548. readcommonsym('Procedure symbol ');
  1549. len:=ppufile.getword;
  1550. for i:=1 to len do
  1551. begin
  1552. write(space,' Definition : ');
  1553. readderef('');
  1554. end;
  1555. end;
  1556. ibconstsym :
  1557. begin
  1558. readcommonsym('Constant symbol ');
  1559. b:=getbyte;
  1560. case tconsttyp(b) of
  1561. constord :
  1562. begin
  1563. write (space,' OrdinalType : ');
  1564. readderef('');
  1565. writeln(space,' Value : ',constexp.tostr(getexprint));
  1566. end;
  1567. constpointer :
  1568. begin
  1569. write (space,' PointerType : ');
  1570. readderef('');
  1571. writeln(space,' Value : ',getlongint)
  1572. end;
  1573. conststring,
  1574. constresourcestring :
  1575. begin
  1576. len:=getlongint;
  1577. getmem(pc,len+1);
  1578. getdata(pc^,len);
  1579. (pc+len)^:= #0;
  1580. writeln(space,' Length : ',len);
  1581. writeln(space,' Value : "',pc,'"');
  1582. freemem(pc,len+1);
  1583. end;
  1584. constreal :
  1585. writeln(space,' Value : ',getreal);
  1586. constset :
  1587. begin
  1588. write (space,' Set Type : ');
  1589. readderef('');
  1590. for i:=1to 4 do
  1591. begin
  1592. write (space,' Value : ');
  1593. for j:=1to 8 do
  1594. begin
  1595. if j>1 then
  1596. write(',');
  1597. write(hexstr(getbyte,2));
  1598. end;
  1599. writeln;
  1600. end;
  1601. end;
  1602. constwstring:
  1603. begin
  1604. end;
  1605. constguid:
  1606. begin
  1607. getdata(guid,sizeof(guid));
  1608. write (space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-');
  1609. for i:=0 to 7 do
  1610. begin
  1611. write(hexstr(guid.d4[i],2));
  1612. if i=1 then write('-');
  1613. end;
  1614. writeln('}');
  1615. end
  1616. else
  1617. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  1618. end;
  1619. end;
  1620. ibabsolutevarsym :
  1621. begin
  1622. readabstractvarsym('Absolute variable symbol ',varoptions);
  1623. Write (space,' Relocated to ');
  1624. b:=getbyte;
  1625. case absolutetyp(b) of
  1626. tovar :
  1627. readpropaccesslist(space+' Sym : ');
  1628. toasm :
  1629. Writeln('Assembler name : ',getstring);
  1630. toaddr :
  1631. begin
  1632. Write('Address : ',getlongint);
  1633. if tsystemcpu(ppufile.header.cpu)=cpu_i386 then
  1634. WriteLn(' (Far: ',getbyte<>0,')');
  1635. end;
  1636. else
  1637. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  1638. end;
  1639. end;
  1640. ibfieldvarsym :
  1641. begin
  1642. readabstractvarsym('Field Variable symbol ',varoptions);
  1643. writeln(space,' Address : ',getaint);
  1644. end;
  1645. ibstaticvarsym :
  1646. begin
  1647. readabstractvarsym('Global Variable symbol ',varoptions);
  1648. write (space,' DefaultConst : ');
  1649. readderef('');
  1650. if (vo_has_mangledname in varoptions) then
  1651. writeln(space,' Mangledname : ',getstring);
  1652. end;
  1653. iblocalvarsym :
  1654. begin
  1655. readabstractvarsym('Local Variable symbol ',varoptions);
  1656. write (space,' DefaultConst : ');
  1657. readderef('');
  1658. end;
  1659. ibparavarsym :
  1660. begin
  1661. readabstractvarsym('Parameter Variable symbol ',varoptions);
  1662. write (space,' DefaultConst : ');
  1663. readderef('');
  1664. writeln(space,' ParaNr : ',getword);
  1665. writeln(space,' VarState : ',getbyte);
  1666. if (vo_has_explicit_paraloc in varoptions) then
  1667. begin
  1668. i:=getbyte;
  1669. getdata(tempbuf,i);
  1670. end;
  1671. end;
  1672. ibenumsym :
  1673. begin
  1674. readcommonsym('Enumeration symbol ');
  1675. write (space,' Definition : ');
  1676. readderef('');
  1677. writeln(space,' Value : ',getlongint);
  1678. end;
  1679. ibsyssym :
  1680. begin
  1681. readcommonsym('Internal system symbol ');
  1682. writeln(space,' Internal Nr : ',getlongint);
  1683. end;
  1684. ibmacrosym :
  1685. begin
  1686. readcommonsym('Macro symbol ');
  1687. writeln(space,' Name: ',getstring);
  1688. writeln(space,' Defined: ',getbyte);
  1689. writeln(space,' Compiler var: ',getbyte);
  1690. len:=getlongint;
  1691. writeln(space,' Value length: ',len);
  1692. if len > 0 then
  1693. begin
  1694. getmem(pc,len+1);
  1695. getdata(pc^,len);
  1696. (pc+len)^:= #0;
  1697. writeln(space,' Value: "',pc,'"');
  1698. freemem(pc,len+1);
  1699. end;
  1700. end;
  1701. ibpropertysym :
  1702. begin
  1703. readcommonsym('Property ');
  1704. i:=getlongint;
  1705. writeln(space,' PropOptions : ',i);
  1706. write (space,' OverrideProp : ');
  1707. readderef('');
  1708. write (space,' Prop Type : ');
  1709. readderef('');
  1710. writeln(space,' Index : ',getlongint);
  1711. writeln(space,' Default : ',getlongint);
  1712. write (space,' Index Type : ');
  1713. readderef('');
  1714. write (space,' Readaccess : ');
  1715. readpropaccesslist(space+' Sym: ');
  1716. write (space,' Writeaccess : ');
  1717. readpropaccesslist(space+' Sym: ');
  1718. write (space,' Storedaccess : ');
  1719. readpropaccesslist(space+' Sym: ');
  1720. end;
  1721. iberror :
  1722. begin
  1723. Writeln('!! Error in PPU');
  1724. exit;
  1725. end;
  1726. ibendsyms :
  1727. break;
  1728. else
  1729. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  1730. end;
  1731. if not EndOfEntry then
  1732. Writeln('!! Entry has more information stored');
  1733. until false;
  1734. end;
  1735. end;
  1736. {****************************************************************************
  1737. Read defintions Part
  1738. ****************************************************************************}
  1739. procedure readdefinitions(const s:string);
  1740. type
  1741. tordtype = (
  1742. uvoid,
  1743. u8bit,u16bit,u32bit,u64bit,
  1744. s8bit,s16bit,s32bit,s64bit,
  1745. bool8bit,bool16bit,bool32bit,bool64bit,
  1746. uchar,uwidechar,scurrency
  1747. );
  1748. tobjecttyp = (odt_none,
  1749. odt_class,
  1750. odt_object,
  1751. odt_interfacecom,
  1752. odt_interfacecom_property,
  1753. odt_interfacecom_function,
  1754. odt_interfacecorba,
  1755. odt_cppclass,
  1756. odt_dispinterface,
  1757. odt_objcclass,
  1758. odt_objcprotocol
  1759. );
  1760. tvarianttype = (
  1761. vt_normalvariant,vt_olevariant
  1762. );
  1763. var
  1764. b : byte;
  1765. l,j : longint;
  1766. calloption : tproccalloption;
  1767. procoptions : tprocoptions;
  1768. procinfooptions : tprocinfoflag;
  1769. begin
  1770. with ppufile do
  1771. begin
  1772. if space<>'' then
  1773. Writeln(space,'------ ',s,' ------');
  1774. if readentry<>ibstartdefs then
  1775. Writeln('!! ibstartdefs not found');
  1776. repeat
  1777. b:=readentry;
  1778. case b of
  1779. ibpointerdef :
  1780. begin
  1781. readcommondef('Pointer definition');
  1782. write (space,' Pointed Type : ');
  1783. readderef('');
  1784. writeln(space,' Is Far : ',(getbyte<>0));
  1785. end;
  1786. iborddef :
  1787. begin
  1788. readcommondef('Ordinal definition');
  1789. write (space,' Base type : ');
  1790. b:=getbyte;
  1791. case tordtype(b) of
  1792. uvoid : writeln('uvoid');
  1793. u8bit : writeln('u8bit');
  1794. u16bit : writeln('u16bit');
  1795. u32bit : writeln('s32bit');
  1796. u64bit : writeln('u64bit');
  1797. s8bit : writeln('s8bit');
  1798. s16bit : writeln('s16bit');
  1799. s32bit : writeln('s32bit');
  1800. s64bit : writeln('s64bit');
  1801. bool8bit : writeln('bool8bit');
  1802. bool16bit : writeln('bool16bit');
  1803. bool32bit : writeln('bool32bit');
  1804. bool64bit : writeln('bool64bit');
  1805. uchar : writeln('uchar');
  1806. uwidechar : writeln('uwidechar');
  1807. scurrency : writeln('ucurrency');
  1808. else writeln('!! Warning: Invalid base type ',b);
  1809. end;
  1810. writeln(space,' Range : ',constexp.tostr(getexprint),' to ',constexp.tostr(getexprint));
  1811. end;
  1812. ibfloatdef :
  1813. begin
  1814. readcommondef('Float definition');
  1815. writeln(space,' Float type : ',getbyte);
  1816. end;
  1817. ibarraydef :
  1818. begin
  1819. readcommondef('Array definition');
  1820. write (space,' Element type : ');
  1821. readderef('');
  1822. write (space,' Range Type : ');
  1823. readderef('');
  1824. writeln(space,' Range : ',getaint,' to ',getaint);
  1825. write (space,' Options : ');
  1826. readarraydefoptions;
  1827. end;
  1828. ibprocdef :
  1829. begin
  1830. readcommondef('Procedure definition');
  1831. read_abstract_proc_def(calloption,procoptions);
  1832. if (po_has_mangledname in procoptions) then
  1833. writeln(space,' Mangled name : ',getstring);
  1834. writeln(space,' Number : ',getword);
  1835. writeln(space,' Level : ',getbyte);
  1836. write (space,' Class : ');
  1837. readderef('');
  1838. write (space,' Procsym : ');
  1839. readderef('');
  1840. write (space,' File Pos : ');
  1841. readposinfo;
  1842. writeln(space,' Visibility : ',Visibility2Str(ppufile.getbyte));
  1843. write (space,' SymOptions : ');
  1844. readsymoptions(space+' ');
  1845. if tsystemcpu(ppufile.header.cpu)=cpu_powerpc then
  1846. begin
  1847. { library symbol for AmigaOS/MorphOS }
  1848. write (space,' Library symbol : ');
  1849. readderef('');
  1850. end;
  1851. if (po_has_importdll in procoptions) then
  1852. writeln(space,' Import DLL : ',getstring);
  1853. if (po_has_importname in procoptions) then
  1854. writeln(space,' Import Name : ',getstring);
  1855. writeln(space,' Import Nr : ',getword);
  1856. if (po_msgint in procoptions) then
  1857. writeln(space,' MsgInt : ',getlongint);
  1858. if (po_msgstr in procoptions) then
  1859. writeln(space,' MsgStr : ',getstring);
  1860. if (po_dispid in procoptions) then
  1861. writeln(space,' DispID: ',ppufile.getlongint);
  1862. if (po_has_inlininginfo in procoptions) then
  1863. begin
  1864. write (space,' FuncretSym : ');
  1865. readderef('');
  1866. ppufile.getsmallset(procinfooptions);
  1867. writeln(space,' ProcInfoOptions : ',dword(procinfooptions));
  1868. end;
  1869. b:=ppufile.getbyte;
  1870. if b<>0 then
  1871. begin
  1872. write (space,' Alias names : ');
  1873. for j:=1 to b do
  1874. begin
  1875. write(ppufile.getstring);
  1876. if j<b then
  1877. write(', ');
  1878. end;
  1879. writeln;
  1880. end;
  1881. if not EndOfEntry then
  1882. Writeln('!! Entry has more information stored');
  1883. space:=' '+space;
  1884. { parast }
  1885. readdefinitions('parast');
  1886. readsymbols('parast');
  1887. { localst }
  1888. if (po_has_inlininginfo in procoptions) then
  1889. begin
  1890. readdefinitions('localst');
  1891. readsymbols('localst');
  1892. end;
  1893. if (po_has_inlininginfo in procoptions) then
  1894. readnodetree;
  1895. delete(space,1,4);
  1896. end;
  1897. ibprocvardef :
  1898. begin
  1899. readcommondef('Procedural type (ProcVar) definition');
  1900. read_abstract_proc_def(calloption,procoptions);
  1901. if not EndOfEntry then
  1902. Writeln('!! Entry has more information stored');
  1903. space:=' '+space;
  1904. { parast }
  1905. readdefinitions('parast');
  1906. readsymbols('parast');
  1907. delete(space,1,4);
  1908. end;
  1909. ibshortstringdef :
  1910. begin
  1911. readcommondef('ShortString definition');
  1912. writeln(space,' Length : ',getbyte);
  1913. end;
  1914. ibwidestringdef :
  1915. begin
  1916. readcommondef('WideString definition');
  1917. writeln(space,' Length : ',getlongint);
  1918. end;
  1919. ibansistringdef :
  1920. begin
  1921. readcommondef('AnsiString definition');
  1922. writeln(space,' Length : ',getlongint);
  1923. end;
  1924. iblongstringdef :
  1925. begin
  1926. readcommondef('Longstring definition');
  1927. writeln(space,' Length : ',getlongint);
  1928. end;
  1929. ibrecorddef :
  1930. begin
  1931. readcommondef('Record definition');
  1932. writeln(space,' FieldAlign : ',getbyte);
  1933. writeln(space,' RecordAlign : ',getbyte);
  1934. writeln(space,' PadAlign : ',getbyte);
  1935. writeln(space,'UseFieldAlignment : ',getbyte);
  1936. writeln(space,' DataSize : ',getaint);
  1937. if not EndOfEntry then
  1938. Writeln('!! Entry has more information stored');
  1939. {read the record definitions and symbols}
  1940. space:=' '+space;
  1941. readdefinitions('fields');
  1942. readsymbols('fields');
  1943. Delete(space,1,4);
  1944. end;
  1945. ibobjectdef :
  1946. begin
  1947. readcommondef('Object/Class definition');
  1948. b:=getbyte;
  1949. write (space,' Type : ');
  1950. case tobjecttyp(b) of
  1951. odt_class : writeln('class');
  1952. odt_object : writeln('object');
  1953. odt_interfacecom : writeln('interfacecom');
  1954. odt_interfacecorba : writeln('interfacecorba');
  1955. odt_cppclass : writeln('cppclass');
  1956. odt_dispinterface : writeln('dispinterface');
  1957. odt_objcclass : writeln('objcclass');
  1958. odt_objcprotocol : writeln('objcprotocol');
  1959. else writeln('!! Warning: Invalid object type ',b);
  1960. end;
  1961. writeln(space,' Name of Class : ',getstring);
  1962. writeln(space,' External name : ',getstring);
  1963. writeln(space,' Import lib : ',getstring);
  1964. writeln(space,' DataSize : ',getaint);
  1965. writeln(space,' FieldAlign : ',getbyte);
  1966. writeln(space,' RecordAlign : ',getbyte);
  1967. writeln(space,' Vmt offset : ',getlongint);
  1968. write (space, ' Ancestor Class : ');
  1969. readderef('');
  1970. write (space,' Options : ');
  1971. readobjectdefoptions;
  1972. if tobjecttyp(b) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  1973. begin
  1974. { IIDGUID }
  1975. for j:=1to 16 do
  1976. getbyte;
  1977. writeln(space,' IID String : ',getstring);
  1978. writeln(space,' Last VTable idx : ',getlongint);
  1979. end;
  1980. l:=getlongint;
  1981. writeln(space,' VMT entries: ',l);
  1982. for j:=1 to l do
  1983. begin
  1984. write(space,' ');
  1985. readderef('');
  1986. writeln(space,' Visibility: ',Visibility2Str(getbyte));
  1987. end;
  1988. if tobjecttyp(b) in [odt_class,odt_interfacecorba,odt_objcclass,odt_objcprotocol] then
  1989. begin
  1990. l:=getlongint;
  1991. writeln(space,' Impl Intf Count : ',l);
  1992. for j:=1 to l do
  1993. begin
  1994. write (space,' - Definition : ');
  1995. readderef('');
  1996. writeln(space,' IOffset : ',getlongint);
  1997. end;
  1998. end;
  1999. if df_copied_def in current_defoptions then
  2000. begin
  2001. writeln(' Copy of def: ');
  2002. readderef('');
  2003. end;
  2004. if not EndOfEntry then
  2005. Writeln('!! Entry has more information stored');
  2006. if not(df_copied_def in current_defoptions) then
  2007. begin
  2008. {read the record definitions and symbols}
  2009. space:=' '+space;
  2010. readdefinitions('fields');
  2011. readsymbols('fields');
  2012. Delete(space,1,4);
  2013. end;
  2014. end;
  2015. ibfiledef :
  2016. begin
  2017. ReadCommonDef('File definition');
  2018. write (space,' Type : ');
  2019. case getbyte of
  2020. 0 : writeln('Text');
  2021. 1 : begin
  2022. writeln('Typed');
  2023. write (space,' File of Type : ');
  2024. readderef('');
  2025. end;
  2026. 2 : writeln('Untyped');
  2027. end;
  2028. end;
  2029. ibformaldef :
  2030. begin
  2031. readcommondef('Generic definition (void-typ)');
  2032. writeln(space,' Is Typed : ',(getbyte<>0));
  2033. end;
  2034. ibundefineddef :
  2035. readcommondef('Undefined definition (generic parameter)');
  2036. ibenumdef :
  2037. begin
  2038. readcommondef('Enumeration type definition');
  2039. write(space,'Base enumeration type : ');
  2040. readderef('');
  2041. writeln(space,' Smallest element : ',getaint);
  2042. writeln(space,' Largest element : ',getaint);
  2043. writeln(space,' Size : ',getaint);
  2044. end;
  2045. ibclassrefdef :
  2046. begin
  2047. readcommondef('Class reference definition');
  2048. write (space,' Pointed Type : ');
  2049. readderef('');
  2050. end;
  2051. ibsetdef :
  2052. begin
  2053. readcommondef('Set definition');
  2054. write (space,' Element type : ');
  2055. readderef('');
  2056. writeln(space,' Size : ',getaint);
  2057. writeln(space,' Set Base : ',getaint);
  2058. writeln(space,' Set Max : ',getaint);
  2059. end;
  2060. ibvariantdef :
  2061. begin
  2062. readcommondef('Variant definition');
  2063. write (space,' Varianttype : ');
  2064. b:=getbyte;
  2065. case tvarianttype(b) of
  2066. vt_normalvariant :
  2067. writeln('Normal');
  2068. vt_olevariant :
  2069. writeln('OLE');
  2070. else
  2071. writeln('!! Warning: Invalid varianttype ',b);
  2072. end;
  2073. end;
  2074. iberror :
  2075. begin
  2076. Writeln('!! Error in PPU');
  2077. exit;
  2078. end;
  2079. ibenddefs :
  2080. break;
  2081. else
  2082. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  2083. end;
  2084. if not EndOfEntry then
  2085. Writeln('!! Entry has more information stored');
  2086. until false;
  2087. end;
  2088. end;
  2089. {****************************************************************************
  2090. Read General Part
  2091. ****************************************************************************}
  2092. procedure readinterface;
  2093. var
  2094. b : byte;
  2095. sourcenumber : longint;
  2096. begin
  2097. with ppufile do
  2098. begin
  2099. repeat
  2100. b:=readentry;
  2101. case b of
  2102. ibmodulename :
  2103. Writeln('Module Name: ',getstring);
  2104. ibsourcefiles :
  2105. begin
  2106. sourcenumber:=1;
  2107. while not EndOfEntry do
  2108. begin
  2109. Writeln('Source file ',sourcenumber,' : ',getstring,' ',filetimestring(getlongint));
  2110. inc(sourcenumber);
  2111. end;
  2112. end;
  2113. {$IFDEF MACRO_DIFF_HINT}
  2114. ibusedmacros :
  2115. begin
  2116. while not EndOfEntry do
  2117. begin
  2118. Write('Conditional ',getstring);
  2119. b:=getbyte;
  2120. if boolean(b)=true then
  2121. write(' defined at startup')
  2122. else
  2123. write(' not defined at startup');
  2124. b:=getbyte;
  2125. if boolean(b)=true then
  2126. writeln(' was used')
  2127. else
  2128. writeln;
  2129. end;
  2130. end;
  2131. {$ENDIF}
  2132. ibloadunit :
  2133. ReadLoadUnit;
  2134. iblinkunitofiles :
  2135. ReadLinkContainer('Link unit object file: ');
  2136. iblinkunitstaticlibs :
  2137. ReadLinkContainer('Link unit static lib: ');
  2138. iblinkunitsharedlibs :
  2139. ReadLinkContainer('Link unit shared lib: ');
  2140. iblinkotherofiles :
  2141. ReadLinkContainer('Link other object file: ');
  2142. iblinkotherstaticlibs :
  2143. ReadLinkContainer('Link other static lib: ');
  2144. iblinkothersharedlibs :
  2145. ReadLinkContainer('Link other shared lib: ');
  2146. iblinkotherframeworks:
  2147. ReadLinkContainer('Link framework: ');
  2148. ibmainname:
  2149. Writeln('Specified main program symbol name: ',getstring);
  2150. ibImportSymbols :
  2151. ReadImportSymbols;
  2152. ibderefdata :
  2153. ReadDerefData;
  2154. ibderefmap :
  2155. ReadDerefMap;
  2156. ibwpofile :
  2157. ReadWpoFileInfo;
  2158. ibresources :
  2159. ReadLinkContainer('Resource file: ');
  2160. iberror :
  2161. begin
  2162. Writeln('Error in PPU');
  2163. exit;
  2164. end;
  2165. ibendinterface :
  2166. break;
  2167. else
  2168. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  2169. end;
  2170. until false;
  2171. end;
  2172. end;
  2173. {****************************************************************************
  2174. Read Implementation Part
  2175. ****************************************************************************}
  2176. procedure readimplementation;
  2177. var
  2178. b : byte;
  2179. begin
  2180. with ppufile do
  2181. begin
  2182. repeat
  2183. b:=readentry;
  2184. case b of
  2185. ibasmsymbols :
  2186. ReadAsmSymbols;
  2187. ibloadunit :
  2188. ReadLoadUnit;
  2189. iberror :
  2190. begin
  2191. Writeln('Error in PPU');
  2192. exit;
  2193. end;
  2194. ibendimplementation :
  2195. break;
  2196. else
  2197. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  2198. end;
  2199. until false;
  2200. end;
  2201. end;
  2202. procedure dofile (filename : string);
  2203. begin
  2204. { reset }
  2205. space:='';
  2206. { fix filename }
  2207. if pos('.',filename)=0 then
  2208. filename:=filename+'.ppu';
  2209. ppufile:=tppufile.create(filename);
  2210. if not ppufile.openfile then
  2211. begin
  2212. writeln ('IO-Error when opening : ',filename,', Skipping');
  2213. exit;
  2214. end;
  2215. { PPU File is open, check for PPU Id }
  2216. if not ppufile.CheckPPUID then
  2217. begin
  2218. writeln(Filename,' : Not a valid PPU file, Skipping');
  2219. exit;
  2220. end;
  2221. { Check PPU Version }
  2222. Writeln('Analyzing ',filename,' (v',ppufile.GetPPUVersion,')');
  2223. if ppufile.GetPPUVersion<16 then
  2224. begin
  2225. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  2226. exit;
  2227. end;
  2228. { Write PPU Header Information }
  2229. if (verbose and v_header)<>0 then
  2230. begin
  2231. Writeln;
  2232. Writeln('Header');
  2233. Writeln('-------');
  2234. with ppufile.header do
  2235. begin
  2236. Writeln('Compiler version : ',ppufile.header.compiler shr 14,'.',
  2237. (ppufile.header.compiler shr 7) and $7f,'.',
  2238. ppufile.header.compiler and $7f);
  2239. WriteLn('Target processor : ',Cpu2Str(cpu));
  2240. WriteLn('Target operating system : ',Target2Str(target));
  2241. Writeln('Unit flags : ',PPUFlags2Str(flags));
  2242. Writeln('FileSize (w/o header) : ',size);
  2243. Writeln('Checksum : ',hexstr(checksum,8));
  2244. Writeln('Interface Checksum : ',hexstr(interface_checksum,8));
  2245. Writeln('Indirect Checksum : ',hexstr(indirect_checksum,8));
  2246. Writeln('Definitions stored : ',tostr(deflistsize));
  2247. Writeln('Symbols stored : ',tostr(symlistsize));
  2248. end;
  2249. end;
  2250. {read the general stuff}
  2251. if (verbose and v_interface)<>0 then
  2252. begin
  2253. Writeln;
  2254. Writeln('Interface section');
  2255. Writeln('------------------');
  2256. readinterface;
  2257. end
  2258. else
  2259. ppufile.skipuntilentry(ibendinterface);
  2260. {read the definitions}
  2261. if (verbose and v_defs)<>0 then
  2262. begin
  2263. Writeln;
  2264. Writeln('Interface definitions');
  2265. Writeln('----------------------');
  2266. readdefinitions('interface');
  2267. end
  2268. else
  2269. ppufile.skipuntilentry(ibenddefs);
  2270. {read the symbols}
  2271. if (verbose and v_syms)<>0 then
  2272. begin
  2273. Writeln;
  2274. Writeln('Interface Symbols');
  2275. Writeln('------------------');
  2276. readsymbols('interface');
  2277. end
  2278. else
  2279. ppufile.skipuntilentry(ibendsyms);
  2280. {read the macro symbols}
  2281. if (verbose and v_syms)<>0 then
  2282. begin
  2283. Writeln;
  2284. Writeln('Interface Macro Symbols');
  2285. Writeln('-----------------------');
  2286. end;
  2287. if ppufile.readentry<>ibexportedmacros then
  2288. begin
  2289. Writeln('!! Error in PPU');
  2290. exit;
  2291. end;
  2292. if boolean(ppufile.getbyte) then
  2293. begin
  2294. {skip the definition section for macros (since they are never used) }
  2295. ppufile.skipuntilentry(ibenddefs);
  2296. {read the macro symbols}
  2297. if (verbose and v_syms)<>0 then
  2298. readsymbols('interface macro')
  2299. else
  2300. ppufile.skipuntilentry(ibendsyms);
  2301. end
  2302. else
  2303. Writeln('(no exported macros)');
  2304. {read the implementation stuff}
  2305. if (verbose and v_implementation)<>0 then
  2306. begin
  2307. Writeln;
  2308. Writeln('Implementation section');
  2309. Writeln('-----------------------');
  2310. readimplementation;
  2311. end
  2312. else
  2313. ppufile.skipuntilentry(ibendimplementation);
  2314. {read the static symtable}
  2315. if (ppufile.header.flags and uf_local_symtable)<>0 then
  2316. begin
  2317. if (verbose and v_defs)<>0 then
  2318. begin
  2319. Writeln;
  2320. Writeln('Static definitions');
  2321. Writeln('----------------------');
  2322. readdefinitions('implementation');
  2323. end
  2324. else
  2325. ppufile.skipuntilentry(ibenddefs);
  2326. {read the symbols}
  2327. if (verbose and v_syms)<>0 then
  2328. begin
  2329. Writeln;
  2330. Writeln('Static Symbols');
  2331. Writeln('------------------');
  2332. readsymbols('implementation');
  2333. end
  2334. else
  2335. ppufile.skipuntilentry(ibendsyms);
  2336. end;
  2337. ReadCreatedObjTypes;
  2338. {shutdown ppufile}
  2339. ppufile.closefile;
  2340. ppufile.free;
  2341. Writeln;
  2342. end;
  2343. procedure help;
  2344. begin
  2345. writeln('usage: ppudump [options] <filename1> <filename2>...');
  2346. writeln;
  2347. writeln('[options] can be:');
  2348. writeln(' -V<verbose> Set verbosity to <verbose>');
  2349. writeln(' H - Show header info');
  2350. writeln(' I - Show interface');
  2351. writeln(' M - Show implementation');
  2352. writeln(' S - Show interface symbols');
  2353. writeln(' D - Show interface definitions');
  2354. // writeln(' B - Show browser info');
  2355. writeln(' A - Show all');
  2356. writeln(' -h, -? This helpscreen');
  2357. halt;
  2358. end;
  2359. var
  2360. startpara,
  2361. nrfile,i : longint;
  2362. para : string;
  2363. begin
  2364. writeln(Title+' '+Version);
  2365. writeln(Copyright);
  2366. writeln;
  2367. if paramcount<1 then
  2368. begin
  2369. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  2370. halt(1);
  2371. end;
  2372. { turn verbose on by default }
  2373. verbose:=v_all;
  2374. { read options }
  2375. startpara:=1;
  2376. while copy(paramstr(startpara),1,1)='-' do
  2377. begin
  2378. para:=paramstr(startpara);
  2379. case upcase(para[2]) of
  2380. 'V' : begin
  2381. verbose:=0;
  2382. for i:=3 to length(para) do
  2383. case upcase(para[i]) of
  2384. 'H' : verbose:=verbose or v_header;
  2385. 'I' : verbose:=verbose or v_interface;
  2386. 'M' : verbose:=verbose or v_implementation;
  2387. 'D' : verbose:=verbose or v_defs;
  2388. 'S' : verbose:=verbose or v_syms;
  2389. 'A' : verbose:=verbose or v_all;
  2390. end;
  2391. end;
  2392. 'H' : help;
  2393. '?' : help;
  2394. end;
  2395. inc(startpara);
  2396. end;
  2397. { process files }
  2398. for nrfile:=startpara to paramcount do
  2399. dofile (paramstr(nrfile));
  2400. if has_errors then
  2401. Halt(1);
  2402. end.