ppudump.pp 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479
  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;
  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('(',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;
  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. );
  710. tsymoptions=set of tsymoption;
  711. tsymopt=record
  712. mask : tsymoption;
  713. str : string[30];
  714. end;
  715. const
  716. symopts=10;
  717. symopt : array[1..symopts] of tsymopt=(
  718. (mask:sp_static; str:'Static'),
  719. (mask:sp_hint_deprecated;str:'Hint Deprecated'),
  720. (mask:sp_hint_platform; str:'Hint Platform'),
  721. (mask:sp_hint_library; str:'Hint Library'),
  722. (mask:sp_hint_unimplemented;str:'Hint Unimplemented'),
  723. (mask:sp_hint_experimental;str:'Hint Experimental'),
  724. (mask:sp_has_overloaded; str:'Has overloaded'),
  725. (mask:sp_internal; str:'Internal'),
  726. (mask:sp_implicitrename; str:'Implicit Rename'),
  727. (mask:sp_generic_para; str:'Generic Parameter')
  728. );
  729. var
  730. symoptions : tsymoptions;
  731. i : longint;
  732. first : boolean;
  733. begin
  734. ppufile.getsmallset(symoptions);
  735. if symoptions<>[] then
  736. begin
  737. first:=true;
  738. for i:=1to symopts do
  739. if (symopt[i].mask in symoptions) then
  740. begin
  741. if first then
  742. first:=false
  743. else
  744. write(', ');
  745. write(symopt[i].str);
  746. end;
  747. end;
  748. writeln;
  749. end;
  750. procedure readcommonsym(const s:string);
  751. begin
  752. writeln(space,'** Symbol Id ',ppufile.getlongint,' **');
  753. writeln(space,s,ppufile.getstring);
  754. write (space,' File Pos : ');
  755. readposinfo;
  756. writeln(space,' Visibility : ',Visibility2Str(ppufile.getbyte));
  757. write (space,' SymOptions : ');
  758. readsymoptions;
  759. end;
  760. type
  761. { flags for a definition }
  762. tdefoption=(df_none,
  763. { type is unique, i.e. declared with type = type <tdef>; }
  764. df_unique,
  765. { type is a generic }
  766. df_generic,
  767. { type is a specialization of a generic type }
  768. df_specialization,
  769. { def has been copied from another def so symtable is not owned }
  770. df_copied_def
  771. );
  772. tdefoptions=set of tdefoption;
  773. var
  774. { needed during tobjectdef parsing... }
  775. current_defoptions : tdefoptions;
  776. procedure readcommondef(const s:string);
  777. type
  778. tdefstate=(ds_none,
  779. ds_vmt_written,
  780. ds_rtti_table_used,
  781. ds_init_table_used,
  782. ds_rtti_table_written,
  783. ds_init_table_written,
  784. ds_dwarf_dbg_info_used,
  785. ds_dwarf_dbg_info_written
  786. );
  787. tdefstates=set of tdefstate;
  788. tdefopt=record
  789. mask : tdefoption;
  790. str : string[30];
  791. end;
  792. tdefstateinfo=record
  793. mask : tdefstate;
  794. str : string[30];
  795. end;
  796. const
  797. defopt : array[1..ord(high(tdefoption))] of tdefopt=(
  798. (mask:df_unique; str:'Unique Type'),
  799. (mask:df_generic; str:'Generic'),
  800. (mask:df_specialization; str:'Specialization'),
  801. (mask:df_copied_def; str:'Copied Typedef')
  802. );
  803. defstate : array[1..ord(high(tdefstate))] of tdefstateinfo=(
  804. (mask:ds_vmt_written; str:'VMT Written'),
  805. (mask:ds_rtti_table_used; str:'RTTITable Used'),
  806. (mask:ds_init_table_used; str:'InitTable Used'),
  807. (mask:ds_rtti_table_written; str:'RTTITable Written'),
  808. (mask:ds_init_table_written; str:'InitTable Written'),
  809. (mask:ds_dwarf_dbg_info_used; str:'Dwarf DbgInfo Used'),
  810. (mask:ds_dwarf_dbg_info_written;str:'Dwarf DbgInfo Written')
  811. );
  812. var
  813. defoptions : tdefoptions;
  814. defstates : tdefstates;
  815. i : longint;
  816. first : boolean;
  817. tokenbufsize : longint;
  818. tokenbuf : pbyte;
  819. begin
  820. writeln(space,'** Definition Id ',ppufile.getlongint,' **');
  821. writeln(space,s);
  822. write (space,' Type symbol : ');
  823. readderef;
  824. write (space,' DefOptions : ');
  825. ppufile.getsmallset(defoptions);
  826. if defoptions<>[] then
  827. begin
  828. first:=true;
  829. for i:=1to high(defopt) do
  830. if (defopt[i].mask in defoptions) then
  831. begin
  832. if first then
  833. first:=false
  834. else
  835. write(', ');
  836. write(defopt[i].str);
  837. end;
  838. end;
  839. writeln;
  840. write (space,' DefStates : ');
  841. ppufile.getsmallset(defstates);
  842. if defstates<>[] then
  843. begin
  844. first:=true;
  845. for i:=1to high(defstate) do
  846. if (defstate[i].mask in defstates) then
  847. begin
  848. if first then
  849. first:=false
  850. else
  851. write(', ');
  852. write(defstate[i].str);
  853. end;
  854. end;
  855. writeln;
  856. if df_generic in defoptions then
  857. begin
  858. tokenbufsize:=ppufile.getlongint;
  859. writeln(space,' Tokenbuffer size : ',tokenbufsize);
  860. tokenbuf:=allocmem(tokenbufsize);
  861. ppufile.getdata(tokenbuf^,tokenbufsize);
  862. i:=0;
  863. write(space,' Tokens: ');
  864. while i<tokenbufsize do
  865. begin
  866. if ttoken(tokenbuf[i])<>_GENERICSPECIALTOKEN then
  867. write(arraytokeninfo[ttoken(tokenbuf[i])].str);
  868. case ttoken(tokenbuf[i]) of
  869. _CWCHAR,
  870. _CWSTRING :
  871. begin
  872. inc(i);
  873. {
  874. replaytokenbuf.read(wlen,sizeof(SizeInt));
  875. setlengthwidestring(patternw,wlen);
  876. replaytokenbuf.read(patternw^.data^,patternw^.len*sizeof(tcompilerwidechar));
  877. pattern:='';
  878. }
  879. end;
  880. _CCHAR,
  881. _CSTRING,
  882. _INTCONST,
  883. _REALNUMBER :
  884. begin
  885. inc(i);
  886. {
  887. replaytokenbuf.read(pattern[0],1);
  888. replaytokenbuf.read(pattern[1],length(pattern));
  889. orgpattern:='';
  890. }
  891. end;
  892. _ID :
  893. begin
  894. inc(i);
  895. inc(i);
  896. write(' ',pshortstring(@tokenbuf[i])^);
  897. inc(i,tokenbuf[i]+1);
  898. {
  899. replaytokenbuf.read(orgpattern[0],1);
  900. replaytokenbuf.read(orgpattern[1],length(orgpattern));
  901. pattern:=upper(orgpattern);
  902. }
  903. end;
  904. _GENERICSPECIALTOKEN:
  905. begin
  906. inc(i);
  907. case tspecialgenerictoken(tokenbuf[i]) of
  908. ST_LOADSETTINGS:
  909. begin
  910. inc(i);
  911. write('Settings');
  912. inc(i,sizeof(tsettings));
  913. end;
  914. ST_LINE:
  915. begin
  916. inc(i);
  917. write('Line: ',pdword(@tokenbuf[i])^);
  918. inc(i,4);
  919. end;
  920. ST_COLUMN:
  921. begin
  922. inc(i);
  923. write('Col: ',pword(@tokenbuf[i])^);
  924. inc(i,2);
  925. end;
  926. ST_FILEINDEX:
  927. begin
  928. inc(i);
  929. write('File: ',pword(@tokenbuf[i])^);
  930. inc(i,2);
  931. end;
  932. end;
  933. {
  934. replaytokenbuf.read(specialtoken,1);
  935. case specialtoken of
  936. ST_LOADSETTINGS:
  937. begin
  938. replaytokenbuf.read(current_settings,sizeof(current_settings));
  939. end
  940. else
  941. internalerror(2006103010);
  942. end;
  943. continue;
  944. }
  945. end;
  946. else
  947. inc(i);
  948. end;
  949. if i<tokenbufsize then
  950. write(',');
  951. end;
  952. writeln;
  953. freemem(tokenbuf);
  954. end;
  955. if df_specialization in defoptions then
  956. begin
  957. write (space,' Orig. GenericDef : ');
  958. readderef;
  959. end;
  960. current_defoptions:=defoptions;
  961. end;
  962. { Read abstract procdef and return if inline procdef }
  963. type
  964. tproccalloption=(pocall_none,
  965. { procedure uses C styled calling }
  966. pocall_cdecl,
  967. { C++ calling conventions }
  968. pocall_cppdecl,
  969. { Far16 for OS/2 }
  970. pocall_far16,
  971. { Old style FPC default calling }
  972. pocall_oldfpccall,
  973. { Procedure has compiler magic}
  974. pocall_internproc,
  975. { procedure is a system call, applies e.g. to MorphOS and PalmOS }
  976. pocall_syscall,
  977. { pascal standard left to right }
  978. pocall_pascal,
  979. { procedure uses register (fastcall) calling }
  980. pocall_register,
  981. { safe call calling conventions }
  982. pocall_safecall,
  983. { procedure uses stdcall call }
  984. pocall_stdcall,
  985. { Special calling convention for cpus without a floating point
  986. unit. Floating point numbers are passed in integer registers
  987. instead of floating point registers. Depending on the other
  988. available calling conventions available for the cpu
  989. this replaces either pocall_fastcall or pocall_stdcall.
  990. }
  991. pocall_softfloat,
  992. { Metrowerks Pascal. Special case on Mac OS (X): passes all }
  993. { constant records by reference. }
  994. pocall_mwpascal
  995. );
  996. tproccalloptions = set of tproccalloption;
  997. tproctypeoption=(potype_none,
  998. potype_proginit, { Program initialization }
  999. potype_unitinit, { unit initialization }
  1000. potype_unitfinalize, { unit finalization }
  1001. potype_constructor, { Procedure is a constructor }
  1002. potype_destructor, { Procedure is a destructor }
  1003. potype_operator, { Procedure defines an operator }
  1004. potype_procedure,
  1005. potype_function
  1006. );
  1007. tproctypeoptions=set of tproctypeoption;
  1008. tprocoption=(po_none,
  1009. po_classmethod, { class method }
  1010. po_virtualmethod, { Procedure is a virtual method }
  1011. po_abstractmethod, { Procedure is an abstract method }
  1012. po_staticmethod, { static method }
  1013. po_overridingmethod, { method with override directive }
  1014. po_methodpointer, { method pointer, only in procvardef, also used for 'with object do' }
  1015. po_interrupt, { Procedure is an interrupt handler }
  1016. po_iocheck, { IO checking should be done after a call to the procedure }
  1017. po_assembler, { Procedure is written in assembler }
  1018. po_msgstr, { method for string message handling }
  1019. po_msgint, { method for int message handling }
  1020. po_exports, { Procedure has export directive (needed for OS/2) }
  1021. po_external, { Procedure is external (in other object or lib)}
  1022. po_overload, { procedure is declared with overload directive }
  1023. po_varargs, { printf like arguments }
  1024. po_internconst, { procedure has constant evaluator intern }
  1025. { flag that only the address of a method is returned and not a full methodpointer }
  1026. po_addressonly,
  1027. { procedure is exported }
  1028. po_public,
  1029. { calling convention is specified explicitly }
  1030. po_hascallingconvention,
  1031. { reintroduce flag }
  1032. po_reintroduce,
  1033. { location of parameters is given explicitly as it is necessary for some syscall
  1034. conventions like that one of MorphOS }
  1035. po_explicitparaloc,
  1036. { no stackframe will be generated, used by lowlevel assembler like get_frame }
  1037. po_nostackframe,
  1038. po_has_mangledname,
  1039. po_has_public_name,
  1040. po_forward,
  1041. po_global,
  1042. po_has_inlininginfo,
  1043. { The different kind of syscalls on MorphOS }
  1044. po_syscall_legacy,
  1045. po_syscall_sysv,
  1046. po_syscall_basesysv,
  1047. po_syscall_sysvbase,
  1048. po_syscall_r12base,
  1049. po_local,
  1050. { Procedure can be inlined }
  1051. po_inline,
  1052. { Procedure is used for internal compiler calls }
  1053. po_compilerproc,
  1054. { importing }
  1055. po_has_importdll,
  1056. po_has_importname,
  1057. po_kylixlocal,
  1058. po_dispid,
  1059. { weakly linked (i.e., may or may not exist at run time) }
  1060. po_weakexternal
  1061. );
  1062. tprocoptions=set of tprocoption;
  1063. procedure read_abstract_proc_def(var proccalloption:tproccalloption;var procoptions:tprocoptions);
  1064. type
  1065. tproccallopt=record
  1066. mask : tproccalloption;
  1067. str : string[30];
  1068. end;
  1069. tproctypeopt=record
  1070. mask : tproctypeoption;
  1071. str : string[30];
  1072. end;
  1073. tprocopt=record
  1074. mask : tprocoption;
  1075. str : string[30];
  1076. end;
  1077. const
  1078. proccalloptionStr : array[tproccalloption] of string[14]=('',
  1079. 'CDecl',
  1080. 'CPPDecl',
  1081. 'Far16',
  1082. 'OldFPCCall',
  1083. 'InternProc',
  1084. 'SysCall',
  1085. 'Pascal',
  1086. 'Register',
  1087. 'SafeCall',
  1088. 'StdCall',
  1089. 'SoftFloat',
  1090. 'MWPascal'
  1091. );
  1092. proctypeopt : array[1..ord(high(tproctypeoption))] of tproctypeopt=(
  1093. (mask:potype_proginit; str:'ProgInit'),
  1094. (mask:potype_unitinit; str:'UnitInit'),
  1095. (mask:potype_unitfinalize;str:'UnitFinalize'),
  1096. (mask:potype_constructor; str:'Constructor'),
  1097. (mask:potype_destructor; str:'Destructor'),
  1098. (mask:potype_operator; str:'Operator'),
  1099. (mask:potype_procedure; str:'Procedure'),
  1100. (mask:potype_function; str:'Function')
  1101. );
  1102. procopt : array[1..ord(high(tprocoption))] of tprocopt=(
  1103. (mask:po_classmethod; str:'ClassMethod'),
  1104. (mask:po_virtualmethod; str:'VirtualMethod'),
  1105. (mask:po_abstractmethod; str:'AbstractMethod'),
  1106. (mask:po_staticmethod; str:'StaticMethod'),
  1107. (mask:po_overridingmethod;str:'OverridingMethod'),
  1108. (mask:po_methodpointer; str:'MethodPointer'),
  1109. (mask:po_interrupt; str:'Interrupt'),
  1110. (mask:po_iocheck; str:'IOCheck'),
  1111. (mask:po_assembler; str:'Assembler'),
  1112. (mask:po_msgstr; str:'MsgStr'),
  1113. (mask:po_msgint; str:'MsgInt'),
  1114. (mask:po_exports; str:'Exports'),
  1115. (mask:po_external; str:'External'),
  1116. (mask:po_overload; str:'Overload'),
  1117. (mask:po_varargs; str:'VarArgs'),
  1118. (mask:po_internconst; str:'InternConst'),
  1119. (mask:po_addressonly; str:'AddressOnly'),
  1120. (mask:po_public; str:'Public'),
  1121. (mask:po_hascallingconvention;str:'HasCallingConvention'),
  1122. (mask:po_reintroduce; str:'ReIntroduce'),
  1123. (mask:po_explicitparaloc; str:'ExplicitParaloc'),
  1124. (mask:po_nostackframe; str:'NoStackFrame'),
  1125. (mask:po_has_mangledname; str:'HasMangledName'),
  1126. (mask:po_has_public_name; str:'HasPublicName'),
  1127. (mask:po_forward; str:'Forward'),
  1128. (mask:po_global; str:'Global'),
  1129. (mask:po_has_inlininginfo;str:'HasInliningInfo'),
  1130. (mask:po_syscall_legacy; str:'SyscallLegacy'),
  1131. (mask:po_syscall_sysv; str:'SyscallSysV'),
  1132. (mask:po_syscall_basesysv;str:'SyscallBaseSysV'),
  1133. (mask:po_syscall_sysvbase;str:'SyscallSysVBase'),
  1134. (mask:po_syscall_r12base; str:'SyscallR12Base'),
  1135. (mask:po_local; str:'Local'),
  1136. (mask:po_inline; str:'Inline'),
  1137. (mask:po_compilerproc; str:'CompilerProc'),
  1138. (mask:po_has_importdll; str:'HasImportDLL'),
  1139. (mask:po_has_importname; str:'HasImportName'),
  1140. (mask:po_kylixlocal; str:'KylixLocal'),
  1141. (mask:po_dispid; str:'DispId'),
  1142. (mask:po_weakexternal; str:'WeakExternal')
  1143. );
  1144. var
  1145. proctypeoption : tproctypeoption;
  1146. i : longint;
  1147. first : boolean;
  1148. tempbuf : array[0..255] of byte;
  1149. begin
  1150. write(space,' Return type : ');
  1151. readderef;
  1152. writeln(space,' Fpu used : ',ppufile.getbyte);
  1153. proctypeoption:=tproctypeoption(ppufile.getbyte);
  1154. write(space,' TypeOption : ');
  1155. first:=true;
  1156. for i:=1 to high(proctypeopt) do
  1157. if (proctypeopt[i].mask=proctypeoption) then
  1158. begin
  1159. if first then
  1160. first:=false
  1161. else
  1162. write(', ');
  1163. write(proctypeopt[i].str);
  1164. end;
  1165. writeln;
  1166. proccalloption:=tproccalloption(ppufile.getbyte);
  1167. writeln(space,' CallOption : ',proccalloptionStr[proccalloption]);
  1168. ppufile.getnormalset(procoptions);
  1169. if procoptions<>[] then
  1170. begin
  1171. write(space,' Options : ');
  1172. first:=true;
  1173. for i:=1 to high(procopt) do
  1174. if (procopt[i].mask in procoptions) then
  1175. begin
  1176. if first then
  1177. first:=false
  1178. else
  1179. write(', ');
  1180. write(procopt[i].str);
  1181. end;
  1182. writeln;
  1183. end;
  1184. if (po_explicitparaloc in procoptions) then
  1185. begin
  1186. i:=ppufile.getbyte;
  1187. ppufile.getdata(tempbuf,i);
  1188. end;
  1189. end;
  1190. type
  1191. tvaroption=(vo_none,
  1192. vo_is_external,
  1193. vo_is_dll_var,
  1194. vo_is_thread_var,
  1195. vo_has_local_copy,
  1196. vo_is_const, { variable is declared as const (parameter) and can't be written to }
  1197. vo_is_public,
  1198. vo_is_high_para,
  1199. vo_is_funcret,
  1200. vo_is_self,
  1201. vo_is_vmt,
  1202. vo_is_result, { special result variable }
  1203. vo_is_parentfp,
  1204. vo_is_loop_counter, { used to detect assignments to loop counter }
  1205. vo_is_hidden_para,
  1206. vo_has_explicit_paraloc,
  1207. vo_is_syscall_lib,
  1208. vo_has_mangledname,
  1209. vo_is_typed_const,
  1210. vo_is_range_check,
  1211. vo_is_overflow_check,
  1212. vo_is_typinfo_para,
  1213. vo_is_weak_external
  1214. );
  1215. tvaroptions=set of tvaroption;
  1216. { register variable }
  1217. tvarregable=(vr_none,
  1218. vr_intreg,
  1219. vr_fpureg,
  1220. vr_mmreg,
  1221. { does not mean "needs address register", but "if it's a parameter which is }
  1222. { passed by reference, then its address can be put in a register }
  1223. vr_addr
  1224. );
  1225. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions);
  1226. type
  1227. tvaropt=record
  1228. mask : tvaroption;
  1229. str : string[30];
  1230. end;
  1231. const
  1232. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  1233. (mask:vo_is_external; str:'External'),
  1234. (mask:vo_is_dll_var; str:'DLLVar'),
  1235. (mask:vo_is_thread_var; str:'ThreadVar'),
  1236. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  1237. (mask:vo_is_const; str:'Constant'),
  1238. (mask:vo_is_public; str:'Public'),
  1239. (mask:vo_is_high_para; str:'HighValue'),
  1240. (mask:vo_is_funcret; str:'Funcret'),
  1241. (mask:vo_is_self; str:'Self'),
  1242. (mask:vo_is_vmt; str:'VMT'),
  1243. (mask:vo_is_result; str:'Result'),
  1244. (mask:vo_is_parentfp; str:'ParentFP'),
  1245. (mask:vo_is_loop_counter; str:'LoopCounter'),
  1246. (mask:vo_is_hidden_para; str:'Hidden'),
  1247. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  1248. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  1249. (mask:vo_has_mangledname; str:'HasMangledName'),
  1250. (mask:vo_is_typed_const; str:'TypedConst'),
  1251. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  1252. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  1253. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  1254. (mask:vo_is_weak_external;str:'WeakExternal')
  1255. );
  1256. var
  1257. i : longint;
  1258. first : boolean;
  1259. begin
  1260. readcommonsym(s);
  1261. writeln(space,' Spez : ',Varspez2Str(ppufile.getbyte));
  1262. writeln(space,' Regable : ',Varregable2Str(ppufile.getbyte));
  1263. writeln(space,' Addr Taken : ',(ppufile.getbyte<>0));
  1264. write (space,' Var Type : ');
  1265. readderef;
  1266. ppufile.getsmallset(varoptions);
  1267. if varoptions<>[] then
  1268. begin
  1269. write(space,' Options : ');
  1270. first:=true;
  1271. for i:=1 to high(varopt) do
  1272. if (varopt[i].mask in varoptions) then
  1273. begin
  1274. if first then
  1275. first:=false
  1276. else
  1277. write(', ');
  1278. write(varopt[i].str);
  1279. end;
  1280. writeln;
  1281. end;
  1282. end;
  1283. procedure readobjectdefoptions;
  1284. type
  1285. tobjectoption=(oo_none,
  1286. oo_is_forward, { the class is only a forward declared yet }
  1287. oo_has_virtual, { the object/class has virtual methods }
  1288. oo_has_private,
  1289. oo_has_protected,
  1290. oo_has_strictprivate,
  1291. oo_has_strictprotected,
  1292. oo_has_constructor, { the object/class has a constructor }
  1293. oo_has_destructor, { the object/class has a destructor }
  1294. oo_has_vmt, { the object/class has a vmt }
  1295. oo_has_msgstr,
  1296. oo_has_msgint,
  1297. oo_can_have_published,{ the class has rtti, i.e. you can publish properties }
  1298. oo_has_default_property,
  1299. oo_has_valid_guid
  1300. );
  1301. tobjectoptions=set of tobjectoption;
  1302. tsymopt=record
  1303. mask : tobjectoption;
  1304. str : string[30];
  1305. end;
  1306. const
  1307. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  1308. (mask:oo_is_forward; str:'IsForward'),
  1309. (mask:oo_has_virtual; str:'HasVirtual'),
  1310. (mask:oo_has_private; str:'HasPrivate'),
  1311. (mask:oo_has_protected; str:'HasProtected'),
  1312. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  1313. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  1314. (mask:oo_has_constructor; str:'HasConstructor'),
  1315. (mask:oo_has_destructor; str:'HasDestructor'),
  1316. (mask:oo_has_vmt; str:'HasVMT'),
  1317. (mask:oo_has_msgstr; str:'HasMsgStr'),
  1318. (mask:oo_has_msgint; str:'HasMsgInt'),
  1319. (mask:oo_can_have_published; str:'CanHavePublished'),
  1320. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  1321. (mask:oo_has_valid_guid; str:'HasValidGUID')
  1322. );
  1323. var
  1324. symoptions : tobjectoptions;
  1325. i : longint;
  1326. first : boolean;
  1327. begin
  1328. ppufile.getsmallset(symoptions);
  1329. if symoptions<>[] then
  1330. begin
  1331. first:=true;
  1332. for i:=1 to high(symopt) do
  1333. if (symopt[i].mask in symoptions) then
  1334. begin
  1335. if first then
  1336. first:=false
  1337. else
  1338. write(', ');
  1339. write(symopt[i].str);
  1340. end;
  1341. end;
  1342. writeln;
  1343. end;
  1344. procedure readarraydefoptions;
  1345. type
  1346. tarraydefoption=(ado_none,
  1347. ado_IsConvertedPointer,
  1348. ado_IsDynamicArray,
  1349. ado_IsVariant,
  1350. ado_IsConstructor,
  1351. ado_IsArrayOfConst,
  1352. ado_IsConstString,
  1353. ado_IsBitPacked
  1354. );
  1355. tarraydefoptions=set of tarraydefoption;
  1356. tsymopt=record
  1357. mask : tarraydefoption;
  1358. str : string[30];
  1359. end;
  1360. const
  1361. symopt : array[1..ord(high(tarraydefoption))] of tsymopt=(
  1362. (mask:ado_IsConvertedPointer;str:'ConvertedPointer'),
  1363. (mask:ado_IsDynamicArray; str:'IsDynamicArray'),
  1364. (mask:ado_IsVariant; str:'IsVariant'),
  1365. (mask:ado_IsConstructor; str:'IsConstructor'),
  1366. (mask:ado_IsArrayOfConst; str:'ArrayOfConst'),
  1367. (mask:ado_IsConstString; str:'ConstString'),
  1368. (mask:ado_IsBitPacked; str:'BitPacked')
  1369. );
  1370. var
  1371. symoptions : tarraydefoptions;
  1372. i : longint;
  1373. first : boolean;
  1374. begin
  1375. ppufile.getsmallset(symoptions);
  1376. if symoptions<>[] then
  1377. begin
  1378. first:=true;
  1379. for i:=1 to high(symopt) do
  1380. if (symopt[i].mask in symoptions) then
  1381. begin
  1382. if first then
  1383. first:=false
  1384. else
  1385. write(', ');
  1386. write(symopt[i].str);
  1387. end;
  1388. end;
  1389. writeln;
  1390. end;
  1391. procedure readnodetree;
  1392. var
  1393. l : longint;
  1394. p : pointer;
  1395. begin
  1396. with ppufile do
  1397. begin
  1398. if space<>'' then
  1399. Writeln(space,'------ nodetree ------');
  1400. if readentry=ibnodetree then
  1401. begin
  1402. l:=entrysize;
  1403. Writeln(space,'Tree size : ',l);
  1404. { Read data to prevent error that entry is not completly read }
  1405. getmem(p,l);
  1406. getdata(p^,l);
  1407. freemem(p);
  1408. end
  1409. else
  1410. begin
  1411. Writeln('!! ibnodetree not found');
  1412. end;
  1413. end;
  1414. end;
  1415. {****************************************************************************
  1416. Read Symbols Part
  1417. ****************************************************************************}
  1418. procedure readsymbols(const s:string);
  1419. type
  1420. pguid = ^tguid;
  1421. tguid = packed record
  1422. D1: LongWord;
  1423. D2: Word;
  1424. D3: Word;
  1425. D4: array[0..7] of Byte;
  1426. end;
  1427. absolutetyp = (tovar,toasm,toaddr);
  1428. tconsttyp = (constnone,
  1429. constord,conststring,constreal,
  1430. constset,constpointer,constnil,
  1431. constresourcestring,constwstring,constguid
  1432. );
  1433. var
  1434. b : byte;
  1435. pc : pchar;
  1436. i,j,len : longint;
  1437. guid : tguid;
  1438. tempbuf : array[0..127] of char;
  1439. varoptions : tvaroptions;
  1440. begin
  1441. with ppufile do
  1442. begin
  1443. if space<>'' then
  1444. Writeln(space,'------ ',s,' ------');
  1445. if readentry=ibstartsyms then
  1446. begin
  1447. Writeln(space,'Symtable datasize : ',getlongint);
  1448. Writeln(space,'Symtable alignment: ',getlongint);
  1449. end
  1450. else
  1451. Writeln('!! ibstartsym not found');
  1452. repeat
  1453. b:=readentry;
  1454. case b of
  1455. ibunitsym :
  1456. readcommonsym('Unit symbol ');
  1457. iblabelsym :
  1458. readcommonsym('Label symbol ');
  1459. ibtypesym :
  1460. begin
  1461. readcommonsym('Type symbol ');
  1462. write(space,' Result Type : ');
  1463. readderef;
  1464. end;
  1465. ibprocsym :
  1466. begin
  1467. readcommonsym('Procedure symbol ');
  1468. len:=ppufile.getword;
  1469. for i:=1 to len do
  1470. begin
  1471. write(space,' Definition : ');
  1472. readderef;
  1473. end;
  1474. end;
  1475. ibconstsym :
  1476. begin
  1477. readcommonsym('Constant symbol ');
  1478. b:=getbyte;
  1479. case tconsttyp(b) of
  1480. constord :
  1481. begin
  1482. write (space,' OrdinalType : ');
  1483. readderef;
  1484. writeln(space,' Value : ',constexp.tostr(getexprint));
  1485. end;
  1486. constpointer :
  1487. begin
  1488. write (space,' PointerType : ');
  1489. readderef;
  1490. writeln(space,' Value : ',getlongint)
  1491. end;
  1492. conststring,
  1493. constresourcestring :
  1494. begin
  1495. len:=getlongint;
  1496. getmem(pc,len+1);
  1497. getdata(pc^,len);
  1498. (pc+len)^:= #0;
  1499. writeln(space,' Length : ',len);
  1500. writeln(space,' Value : "',pc,'"');
  1501. freemem(pc,len+1);
  1502. end;
  1503. constreal :
  1504. writeln(space,' Value : ',getreal);
  1505. constset :
  1506. begin
  1507. write (space,' Set Type : ');
  1508. readderef;
  1509. for i:=1to 4 do
  1510. begin
  1511. write (space,' Value : ');
  1512. for j:=1to 8 do
  1513. begin
  1514. if j>1 then
  1515. write(',');
  1516. write(hexstr(getbyte,2));
  1517. end;
  1518. writeln;
  1519. end;
  1520. end;
  1521. constwstring:
  1522. begin
  1523. end;
  1524. constguid:
  1525. begin
  1526. getdata(guid,sizeof(guid));
  1527. write (space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-');
  1528. for i:=0 to 7 do
  1529. begin
  1530. write(hexstr(guid.d4[i],2));
  1531. if i=1 then write('-');
  1532. end;
  1533. writeln('}');
  1534. end
  1535. else
  1536. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  1537. end;
  1538. end;
  1539. ibabsolutevarsym :
  1540. begin
  1541. readabstractvarsym('Absolute variable symbol ',varoptions);
  1542. Write (space,' Relocated to ');
  1543. b:=getbyte;
  1544. case absolutetyp(b) of
  1545. tovar :
  1546. readpropaccesslist(space+' Sym : ');
  1547. toasm :
  1548. Writeln('Assembler name : ',getstring);
  1549. toaddr :
  1550. begin
  1551. Write('Address : ',getlongint);
  1552. if tsystemcpu(ppufile.header.cpu)=cpu_i386 then
  1553. WriteLn(' (Far: ',getbyte<>0,')');
  1554. end;
  1555. else
  1556. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  1557. end;
  1558. end;
  1559. ibfieldvarsym :
  1560. begin
  1561. readabstractvarsym('Field Variable symbol ',varoptions);
  1562. writeln(space,' Address : ',getaint);
  1563. end;
  1564. ibstaticvarsym :
  1565. begin
  1566. readabstractvarsym('Global Variable symbol ',varoptions);
  1567. write (space,' DefaultConst : ');
  1568. readderef;
  1569. if (vo_has_mangledname in varoptions) then
  1570. writeln(space,' Mangledname : ',getstring);
  1571. end;
  1572. iblocalvarsym :
  1573. begin
  1574. readabstractvarsym('Local Variable symbol ',varoptions);
  1575. write (space,' DefaultConst : ');
  1576. readderef;
  1577. end;
  1578. ibparavarsym :
  1579. begin
  1580. readabstractvarsym('Parameter Variable symbol ',varoptions);
  1581. write (space,' DefaultConst : ');
  1582. readderef;
  1583. writeln(space,' ParaNr : ',getword);
  1584. writeln(space,' VarState : ',getbyte);
  1585. if (vo_has_explicit_paraloc in varoptions) then
  1586. begin
  1587. i:=getbyte;
  1588. getdata(tempbuf,i);
  1589. end;
  1590. end;
  1591. ibenumsym :
  1592. begin
  1593. readcommonsym('Enumeration symbol ');
  1594. write (space,' Definition : ');
  1595. readderef;
  1596. writeln(space,' Value : ',getlongint);
  1597. end;
  1598. ibsyssym :
  1599. begin
  1600. readcommonsym('Internal system symbol ');
  1601. writeln(space,' Internal Nr : ',getlongint);
  1602. end;
  1603. ibmacrosym :
  1604. begin
  1605. readcommonsym('Macro symbol ');
  1606. writeln(space,' Name: ',getstring);
  1607. writeln(space,' Defined: ',getbyte);
  1608. writeln(space,' Compiler var: ',getbyte);
  1609. len:=getlongint;
  1610. writeln(space,' Value length: ',len);
  1611. if len > 0 then
  1612. begin
  1613. getmem(pc,len+1);
  1614. getdata(pc^,len);
  1615. (pc+len)^:= #0;
  1616. writeln(space,' Value: "',pc,'"');
  1617. freemem(pc,len+1);
  1618. end;
  1619. end;
  1620. ibpropertysym :
  1621. begin
  1622. readcommonsym('Property ');
  1623. i:=getlongint;
  1624. writeln(space,' PropOptions : ',i);
  1625. write (space,' OverrideProp : ');
  1626. readderef;
  1627. write (space,' Prop Type : ');
  1628. readderef;
  1629. writeln(space,' Index : ',getlongint);
  1630. writeln(space,' Default : ',getlongint);
  1631. write (space,' Index Type : ');
  1632. readderef;
  1633. write (space,' Readaccess : ');
  1634. readpropaccesslist(space+' Sym: ');
  1635. write (space,' Writeaccess : ');
  1636. readpropaccesslist(space+' Sym: ');
  1637. write (space,' Storedaccess : ');
  1638. readpropaccesslist(space+' Sym: ');
  1639. end;
  1640. iberror :
  1641. begin
  1642. Writeln('!! Error in PPU');
  1643. exit;
  1644. end;
  1645. ibendsyms :
  1646. break;
  1647. else
  1648. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  1649. end;
  1650. if not EndOfEntry then
  1651. Writeln('!! Entry has more information stored');
  1652. until false;
  1653. end;
  1654. end;
  1655. {****************************************************************************
  1656. Read defintions Part
  1657. ****************************************************************************}
  1658. procedure readdefinitions(const s:string);
  1659. type
  1660. tordtype = (
  1661. uvoid,
  1662. u8bit,u16bit,u32bit,u64bit,
  1663. s8bit,s16bit,s32bit,s64bit,
  1664. bool8bit,bool16bit,bool32bit,bool64bit,
  1665. uchar,uwidechar,scurrency
  1666. );
  1667. tobjecttyp = (odt_none,
  1668. odt_class,
  1669. odt_object,
  1670. odt_interfacecom,
  1671. odt_interfacecorba,
  1672. odt_cppclass,
  1673. odt_dispinterface
  1674. );
  1675. tvarianttype = (
  1676. vt_normalvariant,vt_olevariant
  1677. );
  1678. var
  1679. b : byte;
  1680. l,j : longint;
  1681. calloption : tproccalloption;
  1682. procoptions : tprocoptions;
  1683. procinfooptions : tprocinfoflag;
  1684. begin
  1685. with ppufile do
  1686. begin
  1687. if space<>'' then
  1688. Writeln(space,'------ ',s,' ------');
  1689. if readentry<>ibstartdefs then
  1690. Writeln('!! ibstartdefs not found');
  1691. repeat
  1692. b:=readentry;
  1693. case b of
  1694. ibpointerdef :
  1695. begin
  1696. readcommondef('Pointer definition');
  1697. write (space,' Pointed Type : ');
  1698. readderef;
  1699. writeln(space,' Is Far : ',(getbyte<>0));
  1700. end;
  1701. iborddef :
  1702. begin
  1703. readcommondef('Ordinal definition');
  1704. write (space,' Base type : ');
  1705. b:=getbyte;
  1706. case tordtype(b) of
  1707. uvoid : writeln('uvoid');
  1708. u8bit : writeln('u8bit');
  1709. u16bit : writeln('u16bit');
  1710. u32bit : writeln('s32bit');
  1711. u64bit : writeln('u64bit');
  1712. s8bit : writeln('s8bit');
  1713. s16bit : writeln('s16bit');
  1714. s32bit : writeln('s32bit');
  1715. s64bit : writeln('s64bit');
  1716. bool8bit : writeln('bool8bit');
  1717. bool16bit : writeln('bool16bit');
  1718. bool32bit : writeln('bool32bit');
  1719. bool64bit : writeln('bool64bit');
  1720. uchar : writeln('uchar');
  1721. uwidechar : writeln('uwidechar');
  1722. scurrency : writeln('ucurrency');
  1723. else writeln('!! Warning: Invalid base type ',b);
  1724. end;
  1725. writeln(space,' Range : ',constexp.tostr(getexprint),' to ',constexp.tostr(getexprint));
  1726. end;
  1727. ibfloatdef :
  1728. begin
  1729. readcommondef('Float definition');
  1730. writeln(space,' Float type : ',getbyte);
  1731. end;
  1732. ibarraydef :
  1733. begin
  1734. readcommondef('Array definition');
  1735. write (space,' Element type : ');
  1736. readderef;
  1737. write (space,' Range Type : ');
  1738. readderef;
  1739. writeln(space,' Range : ',getaint,' to ',getaint);
  1740. write (space,' Options : ');
  1741. readarraydefoptions;
  1742. end;
  1743. ibprocdef :
  1744. begin
  1745. readcommondef('Procedure definition');
  1746. read_abstract_proc_def(calloption,procoptions);
  1747. if (po_has_mangledname in procoptions) then
  1748. writeln(space,' Mangled name : ',getstring);
  1749. writeln(space,' Number : ',getword);
  1750. writeln(space,' Level : ',getbyte);
  1751. write (space,' Class : ');
  1752. readderef;
  1753. write (space,' Procsym : ');
  1754. readderef;
  1755. write (space,' File Pos : ');
  1756. readposinfo;
  1757. writeln(space,' Visibility : ',Visibility2Str(ppufile.getbyte));
  1758. write (space,' SymOptions : ');
  1759. readsymoptions;
  1760. if tsystemcpu(ppufile.header.cpu)=cpu_powerpc then
  1761. begin
  1762. { library symbol for AmigaOS/MorphOS }
  1763. write (space,' Library symbol : ');
  1764. readderef;
  1765. end;
  1766. if (po_has_importdll in procoptions) then
  1767. writeln(space,' Import DLL : ',getstring);
  1768. if (po_has_importname in procoptions) then
  1769. writeln(space,' Import Name : ',getstring);
  1770. writeln(space,' Import Nr : ',getword);
  1771. if (po_msgint in procoptions) then
  1772. writeln(space,' MsgInt : ',getlongint);
  1773. if (po_msgstr in procoptions) then
  1774. writeln(space,' MsgStr : ',getstring);
  1775. if (po_dispid in procoptions) then
  1776. writeln(space,' DispID: ',ppufile.getlongint);
  1777. if (po_has_inlininginfo in procoptions) then
  1778. begin
  1779. write (space,' FuncretSym : ');
  1780. readderef;
  1781. ppufile.getsmallset(procinfooptions);
  1782. writeln(space,' ProcInfoOptions : ',dword(procinfooptions));
  1783. end;
  1784. b:=ppufile.getbyte;
  1785. if b<>0 then
  1786. begin
  1787. write (space,' Alias names : ');
  1788. for j:=1 to b do
  1789. begin
  1790. write(ppufile.getstring);
  1791. if j<b then
  1792. write(', ');
  1793. end;
  1794. writeln;
  1795. end;
  1796. if not EndOfEntry then
  1797. Writeln('!! Entry has more information stored');
  1798. space:=' '+space;
  1799. { parast }
  1800. readdefinitions('parast');
  1801. readsymbols('parast');
  1802. { localst }
  1803. if (po_has_inlininginfo in procoptions) then
  1804. begin
  1805. readdefinitions('localst');
  1806. readsymbols('localst');
  1807. end;
  1808. if (po_has_inlininginfo in procoptions) then
  1809. readnodetree;
  1810. delete(space,1,4);
  1811. end;
  1812. ibprocvardef :
  1813. begin
  1814. readcommondef('Procedural type (ProcVar) definition');
  1815. read_abstract_proc_def(calloption,procoptions);
  1816. if not EndOfEntry then
  1817. Writeln('!! Entry has more information stored');
  1818. space:=' '+space;
  1819. { parast }
  1820. readdefinitions('parast');
  1821. readsymbols('parast');
  1822. delete(space,1,4);
  1823. end;
  1824. ibshortstringdef :
  1825. begin
  1826. readcommondef('ShortString definition');
  1827. writeln(space,' Length : ',getbyte);
  1828. end;
  1829. ibwidestringdef :
  1830. begin
  1831. readcommondef('WideString definition');
  1832. writeln(space,' Length : ',getlongint);
  1833. end;
  1834. ibansistringdef :
  1835. begin
  1836. readcommondef('AnsiString definition');
  1837. writeln(space,' Length : ',getlongint);
  1838. end;
  1839. iblongstringdef :
  1840. begin
  1841. readcommondef('Longstring definition');
  1842. writeln(space,' Length : ',getlongint);
  1843. end;
  1844. ibrecorddef :
  1845. begin
  1846. readcommondef('Record definition');
  1847. writeln(space,' FieldAlign : ',getbyte);
  1848. writeln(space,' RecordAlign : ',getbyte);
  1849. writeln(space,' PadAlign : ',getbyte);
  1850. writeln(space,'UseFieldAlignment : ',getbyte);
  1851. writeln(space,' DataSize : ',getaint);
  1852. if not EndOfEntry then
  1853. Writeln('!! Entry has more information stored');
  1854. {read the record definitions and symbols}
  1855. space:=' '+space;
  1856. readdefinitions('fields');
  1857. readsymbols('fields');
  1858. Delete(space,1,4);
  1859. end;
  1860. ibobjectdef :
  1861. begin
  1862. readcommondef('Object/Class definition');
  1863. b:=getbyte;
  1864. write (space,' Type : ');
  1865. case tobjecttyp(b) of
  1866. odt_class : writeln('class');
  1867. odt_object : writeln('object');
  1868. odt_interfacecom : writeln('interfacecom');
  1869. odt_interfacecorba : writeln('interfacecorba');
  1870. odt_cppclass : writeln('cppclass');
  1871. else writeln('!! Warning: Invalid object type ',b);
  1872. end;
  1873. writeln(space,' Name of Class : ',getstring);
  1874. writeln(space,' DataSize : ',getaint);
  1875. writeln(space,' FieldAlign : ',getbyte);
  1876. writeln(space,' RecordAlign : ',getbyte);
  1877. writeln(space,' Vmt offset : ',getlongint);
  1878. write (space, ' Ancestor Class : ');
  1879. readderef;
  1880. write (space,' Options : ');
  1881. readobjectdefoptions;
  1882. if tobjecttyp(b) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  1883. begin
  1884. { IIDGUID }
  1885. for j:=1to 16 do
  1886. getbyte;
  1887. writeln(space,' IID String : ',getstring);
  1888. writeln(space,' Last VTable idx : ',getlongint);
  1889. end;
  1890. l:=getlongint;
  1891. writeln(space,' VMT entries: ',l);
  1892. for j:=1 to l do
  1893. begin
  1894. write(space,' ');
  1895. readderef;
  1896. writeln(space,' Visibility: ',Visibility2Str(getbyte));
  1897. end;
  1898. if tobjecttyp(b) in [odt_class,odt_interfacecorba] then
  1899. begin
  1900. l:=getlongint;
  1901. writeln(space,' Impl Intf Count : ',l);
  1902. for j:=1 to l do
  1903. begin
  1904. write (space,' - Definition : ');
  1905. readderef;
  1906. writeln(space,' IOffset : ',getlongint);
  1907. end;
  1908. end;
  1909. if df_copied_def in current_defoptions then
  1910. begin
  1911. writeln(' Copy of def: ');
  1912. readderef;
  1913. end;
  1914. if not EndOfEntry then
  1915. Writeln('!! Entry has more information stored');
  1916. if not(df_copied_def in current_defoptions) then
  1917. begin
  1918. {read the record definitions and symbols}
  1919. space:=' '+space;
  1920. readdefinitions('fields');
  1921. readsymbols('fields');
  1922. Delete(space,1,4);
  1923. end;
  1924. end;
  1925. ibfiledef :
  1926. begin
  1927. ReadCommonDef('File definition');
  1928. write (space,' Type : ');
  1929. case getbyte of
  1930. 0 : writeln('Text');
  1931. 1 : begin
  1932. writeln('Typed');
  1933. write (space,' File of Type : ');
  1934. readderef;
  1935. end;
  1936. 2 : writeln('Untyped');
  1937. end;
  1938. end;
  1939. ibformaldef :
  1940. begin
  1941. readcommondef('Generic definition (void-typ)');
  1942. writeln(space,' Is Typed : ',(getbyte<>0));
  1943. end;
  1944. ibundefineddef :
  1945. readcommondef('Undefined definition (generic parameter)');
  1946. ibenumdef :
  1947. begin
  1948. readcommondef('Enumeration type definition');
  1949. write(space,'Base enumeration type : ');
  1950. readderef;
  1951. writeln(space,' Smallest element : ',getaint);
  1952. writeln(space,' Largest element : ',getaint);
  1953. writeln(space,' Size : ',getaint);
  1954. end;
  1955. ibclassrefdef :
  1956. begin
  1957. readcommondef('Class reference definition');
  1958. write (space,' Pointed Type : ');
  1959. readderef;
  1960. end;
  1961. ibsetdef :
  1962. begin
  1963. readcommondef('Set definition');
  1964. write (space,' Element type : ');
  1965. readderef;
  1966. writeln(space,' Size : ',getaint);
  1967. writeln(space,' Set Base : ',getaint);
  1968. writeln(space,' Set Max : ',getaint);
  1969. end;
  1970. ibvariantdef :
  1971. begin
  1972. readcommondef('Variant definition');
  1973. write (space,' Varianttype : ');
  1974. b:=getbyte;
  1975. case tvarianttype(b) of
  1976. vt_normalvariant :
  1977. writeln('Normal');
  1978. vt_olevariant :
  1979. writeln('OLE');
  1980. else
  1981. writeln('!! Warning: Invalid varianttype ',b);
  1982. end;
  1983. end;
  1984. iberror :
  1985. begin
  1986. Writeln('!! Error in PPU');
  1987. exit;
  1988. end;
  1989. ibenddefs :
  1990. break;
  1991. else
  1992. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  1993. end;
  1994. if not EndOfEntry then
  1995. Writeln('!! Entry has more information stored');
  1996. until false;
  1997. end;
  1998. end;
  1999. {****************************************************************************
  2000. Read General Part
  2001. ****************************************************************************}
  2002. procedure readinterface;
  2003. var
  2004. b : byte;
  2005. sourcenumber : longint;
  2006. begin
  2007. with ppufile do
  2008. begin
  2009. repeat
  2010. b:=readentry;
  2011. case b of
  2012. ibmodulename :
  2013. Writeln('Module Name: ',getstring);
  2014. ibsourcefiles :
  2015. begin
  2016. sourcenumber:=1;
  2017. while not EndOfEntry do
  2018. begin
  2019. Writeln('Source file ',sourcenumber,' : ',getstring,' ',filetimestring(getlongint));
  2020. inc(sourcenumber);
  2021. end;
  2022. end;
  2023. {$IFDEF MACRO_DIFF_HINT}
  2024. ibusedmacros :
  2025. begin
  2026. while not EndOfEntry do
  2027. begin
  2028. Write('Conditional ',getstring);
  2029. b:=getbyte;
  2030. if boolean(b)=true then
  2031. write(' defined at startup')
  2032. else
  2033. write(' not defined at startup');
  2034. b:=getbyte;
  2035. if boolean(b)=true then
  2036. writeln(' was used')
  2037. else
  2038. writeln;
  2039. end;
  2040. end;
  2041. {$ENDIF}
  2042. ibloadunit :
  2043. ReadLoadUnit;
  2044. iblinkunitofiles :
  2045. ReadLinkContainer('Link unit object file: ');
  2046. iblinkunitstaticlibs :
  2047. ReadLinkContainer('Link unit static lib: ');
  2048. iblinkunitsharedlibs :
  2049. ReadLinkContainer('Link unit shared lib: ');
  2050. iblinkotherofiles :
  2051. ReadLinkContainer('Link other object file: ');
  2052. iblinkotherstaticlibs :
  2053. ReadLinkContainer('Link other static lib: ');
  2054. iblinkothersharedlibs :
  2055. ReadLinkContainer('Link other shared lib: ');
  2056. iblinkotherframeworks:
  2057. ReadLinkContainer('Link framework: ');
  2058. ibmainname:
  2059. Writeln('Specified main program symbol name: ',getstring);
  2060. ibImportSymbols :
  2061. ReadImportSymbols;
  2062. ibderefdata :
  2063. ReadDerefData;
  2064. ibderefmap :
  2065. ReadDerefMap;
  2066. ibwpofile :
  2067. ReadWpoFileInfo;
  2068. ibresources :
  2069. ReadLinkContainer('Resource file: ');
  2070. iberror :
  2071. begin
  2072. Writeln('Error in PPU');
  2073. exit;
  2074. end;
  2075. ibendinterface :
  2076. break;
  2077. else
  2078. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  2079. end;
  2080. until false;
  2081. end;
  2082. end;
  2083. {****************************************************************************
  2084. Read Implementation Part
  2085. ****************************************************************************}
  2086. procedure readimplementation;
  2087. var
  2088. b : byte;
  2089. begin
  2090. with ppufile do
  2091. begin
  2092. repeat
  2093. b:=readentry;
  2094. case b of
  2095. ibasmsymbols :
  2096. ReadAsmSymbols;
  2097. ibloadunit :
  2098. ReadLoadUnit;
  2099. iberror :
  2100. begin
  2101. Writeln('Error in PPU');
  2102. exit;
  2103. end;
  2104. ibendimplementation :
  2105. break;
  2106. else
  2107. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  2108. end;
  2109. until false;
  2110. end;
  2111. end;
  2112. procedure dofile (filename : string);
  2113. begin
  2114. { reset }
  2115. space:='';
  2116. { fix filename }
  2117. if pos('.',filename)=0 then
  2118. filename:=filename+'.ppu';
  2119. ppufile:=tppufile.create(filename);
  2120. if not ppufile.openfile then
  2121. begin
  2122. writeln ('IO-Error when opening : ',filename,', Skipping');
  2123. exit;
  2124. end;
  2125. { PPU File is open, check for PPU Id }
  2126. if not ppufile.CheckPPUID then
  2127. begin
  2128. writeln(Filename,' : Not a valid PPU file, Skipping');
  2129. exit;
  2130. end;
  2131. { Check PPU Version }
  2132. Writeln('Analyzing ',filename,' (v',ppufile.GetPPUVersion,')');
  2133. if ppufile.GetPPUVersion<16 then
  2134. begin
  2135. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  2136. exit;
  2137. end;
  2138. { Write PPU Header Information }
  2139. if (verbose and v_header)<>0 then
  2140. begin
  2141. Writeln;
  2142. Writeln('Header');
  2143. Writeln('-------');
  2144. with ppufile.header do
  2145. begin
  2146. Writeln('Compiler version : ',ppufile.header.compiler shr 14,'.',
  2147. (ppufile.header.compiler shr 7) and $7f,'.',
  2148. ppufile.header.compiler and $7f);
  2149. WriteLn('Target processor : ',Cpu2Str(cpu));
  2150. WriteLn('Target operating system : ',Target2Str(target));
  2151. Writeln('Unit flags : ',PPUFlags2Str(flags));
  2152. Writeln('FileSize (w/o header) : ',size);
  2153. Writeln('Checksum : ',hexstr(checksum,8));
  2154. Writeln('Interface Checksum : ',hexstr(interface_checksum,8));
  2155. Writeln('Indirect Checksum : ',hexstr(indirect_checksum,8));
  2156. Writeln('Definitions stored : ',tostr(deflistsize));
  2157. Writeln('Symbols stored : ',tostr(symlistsize));
  2158. end;
  2159. end;
  2160. {read the general stuff}
  2161. if (verbose and v_interface)<>0 then
  2162. begin
  2163. Writeln;
  2164. Writeln('Interface section');
  2165. Writeln('------------------');
  2166. readinterface;
  2167. end
  2168. else
  2169. ppufile.skipuntilentry(ibendinterface);
  2170. {read the definitions}
  2171. if (verbose and v_defs)<>0 then
  2172. begin
  2173. Writeln;
  2174. Writeln('Interface definitions');
  2175. Writeln('----------------------');
  2176. readdefinitions('interface');
  2177. end
  2178. else
  2179. ppufile.skipuntilentry(ibenddefs);
  2180. {read the symbols}
  2181. if (verbose and v_syms)<>0 then
  2182. begin
  2183. Writeln;
  2184. Writeln('Interface Symbols');
  2185. Writeln('------------------');
  2186. readsymbols('interface');
  2187. end
  2188. else
  2189. ppufile.skipuntilentry(ibendsyms);
  2190. {read the macro symbols}
  2191. if (verbose and v_syms)<>0 then
  2192. begin
  2193. Writeln;
  2194. Writeln('Interface Macro Symbols');
  2195. Writeln('-----------------------');
  2196. end;
  2197. if ppufile.readentry<>ibexportedmacros then
  2198. begin
  2199. Writeln('!! Error in PPU');
  2200. exit;
  2201. end;
  2202. if boolean(ppufile.getbyte) then
  2203. begin
  2204. {skip the definition section for macros (since they are never used) }
  2205. ppufile.skipuntilentry(ibenddefs);
  2206. {read the macro symbols}
  2207. if (verbose and v_syms)<>0 then
  2208. readsymbols('interface macro')
  2209. else
  2210. ppufile.skipuntilentry(ibendsyms);
  2211. end
  2212. else
  2213. Writeln('(no exported macros)');
  2214. {read the implementation stuff}
  2215. if (verbose and v_implementation)<>0 then
  2216. begin
  2217. Writeln;
  2218. Writeln('Implementation section');
  2219. Writeln('-----------------------');
  2220. readimplementation;
  2221. end
  2222. else
  2223. ppufile.skipuntilentry(ibendimplementation);
  2224. {read the static symtable}
  2225. if (ppufile.header.flags and uf_local_symtable)<>0 then
  2226. begin
  2227. if (verbose and v_defs)<>0 then
  2228. begin
  2229. Writeln;
  2230. Writeln('Static definitions');
  2231. Writeln('----------------------');
  2232. readdefinitions('implementation');
  2233. end
  2234. else
  2235. ppufile.skipuntilentry(ibenddefs);
  2236. {read the symbols}
  2237. if (verbose and v_syms)<>0 then
  2238. begin
  2239. Writeln;
  2240. Writeln('Static Symbols');
  2241. Writeln('------------------');
  2242. readsymbols('implementation');
  2243. end
  2244. else
  2245. ppufile.skipuntilentry(ibendsyms);
  2246. end;
  2247. {shutdown ppufile}
  2248. ppufile.closefile;
  2249. ppufile.free;
  2250. Writeln;
  2251. end;
  2252. procedure help;
  2253. begin
  2254. writeln('usage: ppudump [options] <filename1> <filename2>...');
  2255. writeln;
  2256. writeln('[options] can be:');
  2257. writeln(' -V<verbose> Set verbosity to <verbose>');
  2258. writeln(' H - Show header info');
  2259. writeln(' I - Show interface');
  2260. writeln(' M - Show implementation');
  2261. writeln(' S - Show interface symbols');
  2262. writeln(' D - Show interface definitions');
  2263. // writeln(' B - Show browser info');
  2264. writeln(' A - Show all');
  2265. writeln(' -h, -? This helpscreen');
  2266. halt;
  2267. end;
  2268. var
  2269. startpara,
  2270. nrfile,i : longint;
  2271. para : string;
  2272. begin
  2273. writeln(Title+' '+Version);
  2274. writeln(Copyright);
  2275. writeln;
  2276. if paramcount<1 then
  2277. begin
  2278. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  2279. halt(1);
  2280. end;
  2281. { turn verbose on by default }
  2282. verbose:=v_all;
  2283. { read options }
  2284. startpara:=1;
  2285. while copy(paramstr(startpara),1,1)='-' do
  2286. begin
  2287. para:=paramstr(startpara);
  2288. case upcase(para[2]) of
  2289. 'V' : begin
  2290. verbose:=0;
  2291. for i:=3 to length(para) do
  2292. case upcase(para[i]) of
  2293. 'H' : verbose:=verbose or v_header;
  2294. 'I' : verbose:=verbose or v_interface;
  2295. 'M' : verbose:=verbose or v_implementation;
  2296. 'D' : verbose:=verbose or v_defs;
  2297. 'S' : verbose:=verbose or v_syms;
  2298. 'A' : verbose:=verbose or v_all;
  2299. end;
  2300. end;
  2301. 'H' : help;
  2302. '?' : help;
  2303. end;
  2304. inc(startpara);
  2305. end;
  2306. { process files }
  2307. for nrfile:=startpara to paramcount do
  2308. dofile (paramstr(nrfile));
  2309. if has_errors then
  2310. Halt(1);
  2311. end.