ppudump.pp 72 KB

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