ppudump.pp 72 KB

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