ppudump.pp 74 KB

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