ppudump.pp 67 KB

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