ppudump.pp 72 KB

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