ppudump.pp 67 KB

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