ppudump.pp 74 KB

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