ppudump.pp 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638
  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. {$i fpcdefs.inc}
  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. { 14 } 'jvm'
  64. );
  65. { List of all supported system-cpu couples }
  66. const
  67. Targets : array[tsystem] of string[18]=(
  68. { 0 } 'none',
  69. { 1 } 'GO32V1 (obsolete)',
  70. { 2 } 'GO32V2',
  71. { 3 } 'Linux-i386',
  72. { 4 } 'OS/2',
  73. { 5 } 'Win32',
  74. { 6 } 'FreeBSD-i386',
  75. { 7 } 'Amiga',
  76. { 8 } 'Atari',
  77. { 9 } 'MacOS-m68k',
  78. { 10 } 'Linux-m68k',
  79. { 11 } 'PalmOS-m68k',
  80. { 12 } 'Linux-alpha',
  81. { 13 } 'Linux-ppc',
  82. { 14 } 'MacOS-ppc',
  83. { 15 } 'Solaris-i386',
  84. { 16 } 'BeOS-i386',
  85. { 17 } 'NetBSD-i386',
  86. { 18 } 'NetBSD-m68k',
  87. { 19 } 'Netware-i386-clib',
  88. { 20 } 'Qnx-i386',
  89. { 21 } 'WDOSX-i386',
  90. { 22 } 'Solaris-sparc',
  91. { 23 } 'Linux-sparc',
  92. { 24 } 'OpenBSD-i386',
  93. { 25 } 'OpenBSD-m68k',
  94. { 26 } 'Linux-x86-64',
  95. { 27 } 'MacOSX-ppc',
  96. { 28 } 'OS/2 via EMX',
  97. { 29 } 'NetBSD-powerpc',
  98. { 30 } 'OpenBSD-powerpc',
  99. { 31 } 'Linux-arm',
  100. { 32 } 'Watcom-i386',
  101. { 33 } 'MorphOS-powerpc',
  102. { 34 } 'FreeBSD-x86-64',
  103. { 35 } 'Netware-i386-libc',
  104. { 36 } 'Amiga-PowerPC',
  105. { 37 } 'Win64-x64',
  106. { 38 } 'WinCE-ARM',
  107. { 39 } 'Win64-iA64',
  108. { 40 } 'WinCE-i386',
  109. { 41 } 'Linux-x64',
  110. { 42 } 'GBA-arm',
  111. { 43 } 'Linux-powerpc64',
  112. { 44 } 'Darwin-i386',
  113. { 45 } 'PalmOS-arm',
  114. { 46 } 'MacOSX-powerpc64',
  115. { 47 } 'NDS-arm',
  116. { 48 } 'Embedded-i386',
  117. { 49 } 'Embedded-m68k',
  118. { 50 } 'Embedded-alpha',
  119. { 51 } 'Embedded-powerpc',
  120. { 52 } 'Embedded-sparc',
  121. { 53 } 'Embedded-vm',
  122. { 54 } 'Embedded-iA64',
  123. { 55 } 'Embedded-x64',
  124. { 56 } 'Embedded-mips',
  125. { 57 } 'Embedded-arm',
  126. { 58 } 'Embedded-powerpc64',
  127. { 59 } 'Symbian-i386',
  128. { 60 } 'Symbian-arm',
  129. { 61 } 'MacOSX-x64',
  130. { 62 } 'Embedded-avr',
  131. { 63 } 'Haiku-i386',
  132. { 64 } 'Darwin-ARM',
  133. { 65 } 'Solaris-x86-64',
  134. { 66 } 'Linux-MIPS',
  135. { 67 } 'Linux-MIPSel',
  136. { 68 } 'NativeNT-i386',
  137. { 69 } 'iPhoneSim-i386',
  138. { 70 } 'Wii-powerpc',
  139. { 71 } 'Java-JVM'
  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[8]=('Value','Const','Var','Out','ConstRef','Final');
  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','<none>'
  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[31];
  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. (mask:po_java_nonvirtual; str: 'Java non-virtual method'),
  1069. (mask:po_ignore_for_overload_resolution;str: 'Ignored for overload resolution')
  1070. );
  1071. var
  1072. proctypeoption : tproctypeoption;
  1073. i : longint;
  1074. first : boolean;
  1075. tempbuf : array[0..255] of byte;
  1076. begin
  1077. write(space,' Return type : ');
  1078. readderef('');
  1079. writeln(space,' Fpu used : ',ppufile.getbyte);
  1080. proctypeoption:=tproctypeoption(ppufile.getbyte);
  1081. write(space,' TypeOption : ');
  1082. first:=true;
  1083. for i:=1 to high(proctypeopt) do
  1084. if (proctypeopt[i].mask=proctypeoption) then
  1085. begin
  1086. if first then
  1087. first:=false
  1088. else
  1089. write(', ');
  1090. write(proctypeopt[i].str);
  1091. end;
  1092. writeln;
  1093. proccalloption:=tproccalloption(ppufile.getbyte);
  1094. writeln(space,' CallOption : ',proccalloptionStr[proccalloption]);
  1095. ppufile.getnormalset(procoptions);
  1096. if procoptions<>[] then
  1097. begin
  1098. write(space,' Options : ');
  1099. first:=true;
  1100. for i:=1 to high(procopt) do
  1101. if (procopt[i].mask in procoptions) then
  1102. begin
  1103. if first then
  1104. first:=false
  1105. else
  1106. write(', ');
  1107. write(procopt[i].str);
  1108. end;
  1109. writeln;
  1110. end;
  1111. if (po_explicitparaloc in procoptions) then
  1112. begin
  1113. i:=ppufile.getbyte;
  1114. ppufile.getdata(tempbuf,i);
  1115. end;
  1116. end;
  1117. { type tvaroption is in unit symconst }
  1118. { register variable }
  1119. { type tvarregable is in unit symconst }
  1120. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions);
  1121. type
  1122. tvaropt=record
  1123. mask : tvaroption;
  1124. str : string[30];
  1125. end;
  1126. const
  1127. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  1128. (mask:vo_is_external; str:'External'),
  1129. (mask:vo_is_dll_var; str:'DLLVar'),
  1130. (mask:vo_is_thread_var; str:'ThreadVar'),
  1131. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  1132. (mask:vo_is_const; str:'Constant'),
  1133. (mask:vo_is_public; str:'Public'),
  1134. (mask:vo_is_high_para; str:'HighValue'),
  1135. (mask:vo_is_funcret; str:'Funcret'),
  1136. (mask:vo_is_self; str:'Self'),
  1137. (mask:vo_is_vmt; str:'VMT'),
  1138. (mask:vo_is_result; str:'Result'),
  1139. (mask:vo_is_parentfp; str:'ParentFP'),
  1140. (mask:vo_is_loop_counter; str:'LoopCounter'),
  1141. (mask:vo_is_hidden_para; str:'Hidden'),
  1142. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  1143. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  1144. (mask:vo_has_mangledname; str:'HasMangledName'),
  1145. (mask:vo_is_typed_const; str:'TypedConst'),
  1146. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  1147. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  1148. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  1149. (mask:vo_is_msgsel;str:'MsgSel'),
  1150. (mask:vo_is_weak_external;str:'WeakExternal'),
  1151. (mask:vo_is_first_field;str:'IsFirstField'),
  1152. (mask:vo_volatile;str:'Volatile'),
  1153. (mask:vo_has_section;str:'HasSection'),
  1154. (mask:vo_force_finalize;str:'ForceFinalize')
  1155. );
  1156. var
  1157. i : longint;
  1158. first : boolean;
  1159. begin
  1160. readcommonsym(s);
  1161. writeln(space,' Spez : ',Varspez2Str(ppufile.getbyte));
  1162. writeln(space,' Regable : ',Varregable2Str(ppufile.getbyte));
  1163. writeln(space,' Addr Taken : ',(ppufile.getbyte<>0));
  1164. write (space,' Var Type : ');
  1165. readderef('');
  1166. ppufile.getsmallset(varoptions);
  1167. if varoptions<>[] then
  1168. begin
  1169. write(space,' Options : ');
  1170. first:=true;
  1171. for i:=1 to high(varopt) do
  1172. if (varopt[i].mask in varoptions) then
  1173. begin
  1174. if first then
  1175. first:=false
  1176. else
  1177. write(', ');
  1178. write(varopt[i].str);
  1179. if varopt[i].mask = vo_has_section then
  1180. writeln('Section name:',ppufile.getansistring);
  1181. end;
  1182. writeln;
  1183. end;
  1184. end;
  1185. procedure readobjectdefoptions;
  1186. type
  1187. tsymopt=record
  1188. mask : tobjectoption;
  1189. str : string[30];
  1190. end;
  1191. const
  1192. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  1193. (mask:oo_is_forward; str:'IsForward'),
  1194. (mask:oo_is_abstract; str:'IsAbstract'),
  1195. (mask:oo_is_sealed; str:'IsSealed'),
  1196. (mask:oo_has_virtual; str:'HasVirtual'),
  1197. (mask:oo_has_private; str:'HasPrivate'),
  1198. (mask:oo_has_protected; str:'HasProtected'),
  1199. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  1200. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  1201. (mask:oo_has_constructor; str:'HasConstructor'),
  1202. (mask:oo_has_destructor; str:'HasDestructor'),
  1203. (mask:oo_has_vmt; str:'HasVMT'),
  1204. (mask:oo_has_msgstr; str:'HasMsgStr'),
  1205. (mask:oo_has_msgint; str:'HasMsgInt'),
  1206. (mask:oo_can_have_published; str:'CanHavePublished'),
  1207. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  1208. (mask:oo_has_valid_guid; str:'HasValidGUID'),
  1209. (mask:oo_has_enumerator_movenext; str:'HasEnumeratorMoveNext'),
  1210. (mask:oo_has_enumerator_current; str:'HasEnumeratorCurrent'),
  1211. (mask:oo_is_external; str:'External'),
  1212. (mask:oo_is_formal; str:'Formal'),
  1213. (mask:oo_is_classhelper; str:'Class Helper/Category'),
  1214. (mask:oo_has_class_constructor; str:'HasClassConstructor'),
  1215. (mask:oo_has_class_destructor; str:'HasClassDestructor'),
  1216. (mask:oo_is_enum_class; str:'JvmEnumClass'),
  1217. (mask:oo_has_new_destructor; str:'HasNewDestructor')
  1218. );
  1219. var
  1220. i : longint;
  1221. first : boolean;
  1222. begin
  1223. ppufile.getsmallset(current_objectoptions);
  1224. if current_objectoptions<>[] then
  1225. begin
  1226. first:=true;
  1227. for i:=1 to high(symopt) do
  1228. if (symopt[i].mask in current_objectoptions) then
  1229. begin
  1230. if first then
  1231. first:=false
  1232. else
  1233. write(', ');
  1234. write(symopt[i].str);
  1235. end;
  1236. end;
  1237. writeln;
  1238. end;
  1239. procedure readarraydefoptions;
  1240. { type tarraydefoption is in unit symconst }
  1241. type
  1242. tsymopt=record
  1243. mask : tarraydefoption;
  1244. str : string[30];
  1245. end;
  1246. const
  1247. symopt : array[1..ord(high(tarraydefoption))] of tsymopt=(
  1248. (mask:ado_IsConvertedPointer;str:'ConvertedPointer'),
  1249. (mask:ado_IsDynamicArray; str:'IsDynamicArray'),
  1250. (mask:ado_IsVariant; str:'IsVariant'),
  1251. (mask:ado_IsConstructor; str:'IsConstructor'),
  1252. (mask:ado_IsArrayOfConst; str:'ArrayOfConst'),
  1253. (mask:ado_IsConstString; str:'ConstString'),
  1254. (mask:ado_IsBitPacked; str:'BitPacked')
  1255. );
  1256. var
  1257. symoptions : tarraydefoptions;
  1258. i : longint;
  1259. first : boolean;
  1260. begin
  1261. ppufile.getsmallset(symoptions);
  1262. if symoptions<>[] then
  1263. begin
  1264. first:=true;
  1265. for i:=1 to high(symopt) do
  1266. if (symopt[i].mask in symoptions) then
  1267. begin
  1268. if first then
  1269. first:=false
  1270. else
  1271. write(', ');
  1272. write(symopt[i].str);
  1273. end;
  1274. end;
  1275. writeln;
  1276. end;
  1277. procedure readnodetree;
  1278. var
  1279. l : longint;
  1280. p : pointer;
  1281. begin
  1282. with ppufile do
  1283. begin
  1284. if space<>'' then
  1285. Writeln(space,'------ nodetree ------');
  1286. if readentry=ibnodetree then
  1287. begin
  1288. l:=entrysize;
  1289. Writeln(space,'Tree size : ',l);
  1290. { Read data to prevent error that entry is not completly read }
  1291. getmem(p,l);
  1292. getdata(p^,l);
  1293. freemem(p);
  1294. end
  1295. else
  1296. begin
  1297. WriteError('!! ibnodetree not found');
  1298. end;
  1299. end;
  1300. end;
  1301. procedure ReadCreatedObjTypes;
  1302. var
  1303. i,j,
  1304. len,
  1305. bssize: longint;
  1306. bs: pbyte;
  1307. begin
  1308. if ppufile.readentry<>ibcreatedobjtypes then
  1309. begin
  1310. writeln('!! ibcreatedobjtypes entry not found');
  1311. ppufile.skipdata(ppufile.entrysize);
  1312. has_errors:=true;
  1313. exit
  1314. end;
  1315. writeln;
  1316. writeln(space,'WPO info');
  1317. writeln(space,'--------');
  1318. len:=ppufile.getlongint;
  1319. writeln(space,'** Instantiated Object/Class types: ',len,' **');
  1320. space:=space+' ';
  1321. for i:=0 to len-1 do
  1322. readderef(space);
  1323. setlength(space,length(space)-2);
  1324. len:=ppufile.getlongint;
  1325. writeln(space,'** Instantiated ClassRef types: ',len,' **');
  1326. space:=space+' ';
  1327. for i:=0 to len-1 do
  1328. readderef(space);
  1329. setlength(space,length(space)-2);
  1330. len:=ppufile.getlongint;
  1331. writeln(space,'** Possibly instantiated ClassRef types : ',len,' **');
  1332. space:=space+' ';
  1333. for i:=0 to len-1 do
  1334. readderef(space);
  1335. setlength(space,length(space)-2);
  1336. len:=ppufile.getlongint;
  1337. writeln(space,'** Class types with called virtual methods info : ',len,' **');
  1338. space:=space+' ';
  1339. for i:=0 to len-1 do
  1340. begin
  1341. write(space,'Class def : ');
  1342. readderef('');
  1343. write(space+' ','Called vmtentries : ');
  1344. bssize:=ppufile.getlongint;
  1345. getmem(bs,bssize);
  1346. ppufile.readdata(bs^,bssize);
  1347. for j:=0 to bssize*8-1 do
  1348. if (((bs+j shr 3)^ shr (j and 7)) and 1) <> 0 then
  1349. write(j,', ');
  1350. writeln;
  1351. freemem(bs);
  1352. end;
  1353. setlength(space,length(space)-2);
  1354. end;
  1355. {****************************************************************************
  1356. Read Symbols Part
  1357. ****************************************************************************}
  1358. procedure readsymbols(const s:string);
  1359. type
  1360. pguid = ^tguid;
  1361. tguid = packed record
  1362. D1: LongWord;
  1363. D2: Word;
  1364. D3: Word;
  1365. D4: array[0..7] of Byte;
  1366. end;
  1367. var
  1368. b : byte;
  1369. pc : pchar;
  1370. ch : dword;
  1371. startnewline : boolean;
  1372. i,j,len : longint;
  1373. guid : tguid;
  1374. realvalue : extended;
  1375. tempbuf : array[0..127] of char;
  1376. pw : pcompilerwidestring;
  1377. varoptions : tvaroptions;
  1378. begin
  1379. with ppufile do
  1380. begin
  1381. if space<>'' then
  1382. Writeln(space,'------ ',s,' ------');
  1383. if readentry=ibstartsyms then
  1384. begin
  1385. Writeln(space,'Symtable datasize : ',getlongint);
  1386. Writeln(space,'Symtable alignment: ',getlongint);
  1387. end
  1388. else
  1389. Writeln('!! ibstartsym not found');
  1390. repeat
  1391. b:=readentry;
  1392. case b of
  1393. ibunitsym :
  1394. readcommonsym('Unit symbol ');
  1395. iblabelsym :
  1396. readcommonsym('Label symbol ');
  1397. ibtypesym :
  1398. begin
  1399. readcommonsym('Type symbol ');
  1400. write(space,' Result Type : ');
  1401. readderef('');
  1402. end;
  1403. ibprocsym :
  1404. begin
  1405. readcommonsym('Procedure symbol ');
  1406. len:=ppufile.getword;
  1407. for i:=1 to len do
  1408. begin
  1409. write(space,' Definition : ');
  1410. readderef('');
  1411. end;
  1412. end;
  1413. ibconstsym :
  1414. begin
  1415. readcommonsym('Constant symbol ');
  1416. b:=getbyte;
  1417. case tconsttyp(b) of
  1418. constord :
  1419. begin
  1420. write (space,' OrdinalType : ');
  1421. readderef('');
  1422. writeln(space,' Value : ',constexp.tostr(getexprint));
  1423. end;
  1424. constpointer :
  1425. begin
  1426. write (space,' PointerType : ');
  1427. readderef('');
  1428. writeln(space,' Value : ',getaint)
  1429. end;
  1430. conststring,
  1431. constresourcestring :
  1432. begin
  1433. len:=getlongint;
  1434. getmem(pc,len+1);
  1435. getdata(pc^,len);
  1436. (pc+len)^:= #0;
  1437. writeln(space,' Length : ',len);
  1438. writeln(space,' Value : "',pc,'"');
  1439. freemem(pc,len+1);
  1440. end;
  1441. constreal :
  1442. begin
  1443. if entryleft=sizeof(extended) then
  1444. realvalue:=getrealsize(sizeof(extended))
  1445. else if entryleft=sizeof(double) then
  1446. realvalue:=getrealsize(sizeof(double))
  1447. else
  1448. begin
  1449. realvalue:=0.0;
  1450. has_errors:=true;
  1451. end;
  1452. writeln(space,' Value : ',realvalue);
  1453. end;
  1454. constset :
  1455. begin
  1456. write (space,' Set Type : ');
  1457. readderef('');
  1458. for i:=1to 4 do
  1459. begin
  1460. write (space,' Value : ');
  1461. for j:=1to 8 do
  1462. begin
  1463. if j>1 then
  1464. write(',');
  1465. write(hexstr(getbyte,2));
  1466. end;
  1467. writeln;
  1468. end;
  1469. end;
  1470. constnil:
  1471. writeln(space,' NIL pointer.');
  1472. constwstring :
  1473. begin
  1474. initwidestring(pw);
  1475. setlengthwidestring(pw,getlongint);
  1476. if widecharsize=2 then
  1477. { don't use getdata, because the compilerwidechars may have to
  1478. be byteswapped
  1479. }
  1480. begin
  1481. for i:=0 to pw^.len-1 do
  1482. pw^.data[i]:=ppufile.getword;
  1483. end
  1484. else if widecharsize=4 then
  1485. begin
  1486. for i:=0 to pw^.len-1 do
  1487. pw^.data[i]:=cardinal(ppufile.getlongint);
  1488. end
  1489. else
  1490. begin
  1491. WriteError('Unsupported tcompilerwidechar size');
  1492. end;
  1493. Writeln(space,'Wide string type');
  1494. startnewline:=true;
  1495. for i:=0 to pw^.len-1 do
  1496. begin
  1497. if startnewline then
  1498. begin
  1499. write(space);
  1500. startnewline:=false;
  1501. end;
  1502. ch:=pw^.data[i];
  1503. if widecharsize=2 then
  1504. write(hexstr(ch,4))
  1505. else
  1506. write(hexstr(ch,8));
  1507. if (i mod 8)= 0 then
  1508. startnewline:=true
  1509. else
  1510. write(', ');
  1511. end;
  1512. donewidestring(pw);
  1513. end;
  1514. constguid:
  1515. begin
  1516. getdata(guid,sizeof(guid));
  1517. write (space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-');
  1518. for i:=0 to 7 do
  1519. begin
  1520. write(hexstr(guid.d4[i],2));
  1521. if i=1 then write('-');
  1522. end;
  1523. writeln('}');
  1524. end
  1525. else
  1526. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  1527. end;
  1528. end;
  1529. ibabsolutevarsym :
  1530. begin
  1531. readabstractvarsym('Absolute variable symbol ',varoptions);
  1532. Write (space,' Relocated to ');
  1533. b:=getbyte;
  1534. case absolutetyp(b) of
  1535. tovar :
  1536. readpropaccesslist(space+' Sym : ');
  1537. toasm :
  1538. Writeln('Assembler name : ',getstring);
  1539. toaddr :
  1540. begin
  1541. Write('Address : ',getlongint);
  1542. if tsystemcpu(ppufile.header.cpu)=cpu_i386 then
  1543. WriteLn(' (Far: ',getbyte<>0,')');
  1544. end;
  1545. else
  1546. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  1547. end;
  1548. end;
  1549. ibfieldvarsym :
  1550. begin
  1551. readabstractvarsym('Field Variable symbol ',varoptions);
  1552. writeln(space,' Address : ',getaint);
  1553. end;
  1554. ibstaticvarsym :
  1555. begin
  1556. readabstractvarsym('Global Variable symbol ',varoptions);
  1557. write (space,' DefaultConst : ');
  1558. readderef('');
  1559. if (vo_has_mangledname in varoptions) then
  1560. {$ifdef symansistr}
  1561. writeln(space,' Mangledname : ',getansistring);
  1562. {$else symansistr}
  1563. writeln(space,' Mangledname : ',getstring);
  1564. {$endif symansistr}
  1565. end;
  1566. iblocalvarsym :
  1567. begin
  1568. readabstractvarsym('Local Variable symbol ',varoptions);
  1569. write (space,' DefaultConst : ');
  1570. readderef('');
  1571. end;
  1572. ibparavarsym :
  1573. begin
  1574. readabstractvarsym('Parameter Variable symbol ',varoptions);
  1575. write (space,' DefaultConst : ');
  1576. readderef('');
  1577. writeln(space,' ParaNr : ',getword);
  1578. writeln(space,' Univ : ',boolean(getbyte));
  1579. writeln(space,' VarState : ',getbyte);
  1580. if (vo_has_explicit_paraloc in varoptions) then
  1581. begin
  1582. i:=getbyte;
  1583. getdata(tempbuf,i);
  1584. end;
  1585. end;
  1586. ibenumsym :
  1587. begin
  1588. readcommonsym('Enumeration symbol ');
  1589. write (space,' Definition : ');
  1590. readderef('');
  1591. writeln(space,' Value : ',getlongint);
  1592. end;
  1593. ibsyssym :
  1594. begin
  1595. readcommonsym('Internal system symbol ');
  1596. writeln(space,' Internal Nr : ',getlongint);
  1597. end;
  1598. ibmacrosym :
  1599. begin
  1600. readcommonsym('Macro symbol ');
  1601. writeln(space,' Name: ',getstring);
  1602. writeln(space,' Defined: ',getbyte);
  1603. writeln(space,' Compiler var: ',getbyte);
  1604. len:=getlongint;
  1605. writeln(space,' Value length: ',len);
  1606. if len > 0 then
  1607. begin
  1608. getmem(pc,len+1);
  1609. getdata(pc^,len);
  1610. (pc+len)^:= #0;
  1611. writeln(space,' Value: "',pc,'"');
  1612. freemem(pc,len+1);
  1613. end;
  1614. end;
  1615. ibpropertysym :
  1616. begin
  1617. readcommonsym('Property ');
  1618. i:=getlongint;
  1619. writeln(space,' PropOptions : ',i);
  1620. write (space,' OverrideProp : ');
  1621. readderef('');
  1622. write (space,' Prop Type : ');
  1623. readderef('');
  1624. writeln(space,' Index : ',getlongint);
  1625. writeln(space,' Default : ',getlongint);
  1626. write (space,' Index Type : ');
  1627. readderef('');
  1628. { palt_none }
  1629. readpropaccesslist('');
  1630. write (space,' Readaccess : ');
  1631. readpropaccesslist(space+' Sym: ');
  1632. write (space,' Writeaccess : ');
  1633. readpropaccesslist(space+' Sym: ');
  1634. write (space,' Storedaccess : ');
  1635. readpropaccesslist(space+' Sym: ');
  1636. end;
  1637. iberror :
  1638. begin
  1639. WriteError('!! Error in PPU');
  1640. exit;
  1641. end;
  1642. ibendsyms :
  1643. break;
  1644. else
  1645. begin
  1646. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  1647. has_errors:=true;
  1648. end;
  1649. end;
  1650. if not EndOfEntry then
  1651. HasMoreInfos;
  1652. until false;
  1653. end;
  1654. end;
  1655. {****************************************************************************
  1656. Read defintions Part
  1657. ****************************************************************************}
  1658. procedure readdefinitions(const s:string);
  1659. { type tordtype is in symconst unit }
  1660. {
  1661. uvoid,
  1662. u8bit,u16bit,u32bit,u64bit,
  1663. s8bit,s16bit,s32bit,s64bit,
  1664. bool8bit,bool16bit,bool32bit,bool64bit,
  1665. uchar,uwidechar,scurrency
  1666. ); }
  1667. { type tobjecttyp is in symconst unit }
  1668. { type tvarianttype is in symconst unit }
  1669. var
  1670. b : byte;
  1671. l,j : longint;
  1672. calloption : tproccalloption;
  1673. procoptions : tprocoptions;
  1674. procinfooptions : tprocinfoflag;
  1675. defoptions: tdefoptions;
  1676. begin
  1677. with ppufile do
  1678. begin
  1679. if space<>'' then
  1680. Writeln(space,'------ ',s,' ------');
  1681. if readentry<>ibstartdefs then
  1682. Writeln('!! ibstartdefs not found');
  1683. repeat
  1684. b:=readentry;
  1685. case b of
  1686. ibpointerdef :
  1687. begin
  1688. readcommondef('Pointer definition',defoptions);
  1689. write (space,' Pointed Type : ');
  1690. readderef('');
  1691. writeln(space,' Is Far : ',(getbyte<>0));
  1692. writeln(space,' Has Pointer Math : ',(getbyte<>0));
  1693. end;
  1694. iborddef :
  1695. begin
  1696. readcommondef('Ordinal definition',defoptions);
  1697. write (space,' Base type : ');
  1698. b:=getbyte;
  1699. case tordtype(b) of
  1700. uvoid : writeln('uvoid');
  1701. u8bit : writeln('u8bit');
  1702. u16bit : writeln('u16bit');
  1703. u32bit : writeln('s32bit');
  1704. u64bit : writeln('u64bit');
  1705. s8bit : writeln('s8bit');
  1706. s16bit : writeln('s16bit');
  1707. s32bit : writeln('s32bit');
  1708. s64bit : writeln('s64bit');
  1709. bool8bit : writeln('bool8bit');
  1710. bool16bit : writeln('bool16bit');
  1711. bool32bit : writeln('bool32bit');
  1712. bool64bit : writeln('bool64bit');
  1713. uchar : writeln('uchar');
  1714. uwidechar : writeln('uwidechar');
  1715. scurrency : writeln('ucurrency');
  1716. else writeln('!! Warning: Invalid base type ',b);
  1717. end;
  1718. writeln(space,' Range : ',constexp.tostr(getexprint),' to ',constexp.tostr(getexprint));
  1719. end;
  1720. ibfloatdef :
  1721. begin
  1722. readcommondef('Float definition',defoptions);
  1723. writeln(space,' Float type : ',getbyte);
  1724. end;
  1725. ibarraydef :
  1726. begin
  1727. readcommondef('Array definition',defoptions);
  1728. write (space,' Element type : ');
  1729. readderef('');
  1730. write (space,' Range Type : ');
  1731. readderef('');
  1732. writeln(space,' Range : ',getaint,' to ',getaint);
  1733. write (space,' Options : ');
  1734. readarraydefoptions;
  1735. readsymtableoptions('symbols');
  1736. readdefinitions('symbols');
  1737. readsymbols('symbols');
  1738. end;
  1739. ibprocdef :
  1740. begin
  1741. readcommondef('Procedure definition',defoptions);
  1742. read_abstract_proc_def(calloption,procoptions);
  1743. if (po_has_mangledname in procoptions) then
  1744. {$ifdef symansistr}
  1745. writeln(space,' Mangled name : ',getansistring);
  1746. {$else symansistr}
  1747. writeln(space,' Mangled name : ',getstring);
  1748. {$endif symansistr}
  1749. writeln(space,' Number : ',getword);
  1750. writeln(space,' Level : ',getbyte);
  1751. write (space,' Class : ');
  1752. readderef('');
  1753. write (space,' Procsym : ');
  1754. readderef('');
  1755. write (space,' File Pos : ');
  1756. readposinfo;
  1757. writeln(space,' Visibility : ',Visibility2Str(ppufile.getbyte));
  1758. write (space,' SymOptions : ');
  1759. readsymoptions(space+' ');
  1760. if tsystemcpu(ppufile.header.cpu)=cpu_powerpc then
  1761. begin
  1762. { library symbol for AmigaOS/MorphOS }
  1763. write (space,' Library symbol : ');
  1764. readderef('');
  1765. end;
  1766. if (po_has_importdll in procoptions) then
  1767. writeln(space,' Import DLL : ',getstring);
  1768. if (po_has_importname in procoptions) then
  1769. writeln(space,' Import Name : ',getstring);
  1770. writeln(space,' Import Nr : ',getword);
  1771. if (po_msgint in procoptions) then
  1772. writeln(space,' MsgInt : ',getlongint);
  1773. if (po_msgstr in procoptions) then
  1774. writeln(space,' MsgStr : ',getstring);
  1775. if (po_dispid in procoptions) then
  1776. writeln(space,' DispID: ',ppufile.getlongint);
  1777. if (po_has_inlininginfo in procoptions) then
  1778. begin
  1779. write (space,' FuncretSym : ');
  1780. readderef('');
  1781. ppufile.getsmallset(procinfooptions);
  1782. writeln(space,' ProcInfoOptions : ',dword(procinfooptions));
  1783. end;
  1784. b:=ppufile.getbyte;
  1785. if b<>0 then
  1786. begin
  1787. write (space,' Alias names : ');
  1788. for j:=1 to b do
  1789. begin
  1790. write(ppufile.getstring);
  1791. if j<b then
  1792. write(', ');
  1793. end;
  1794. writeln;
  1795. end;
  1796. if not EndOfEntry then
  1797. HasMoreInfos;
  1798. space:=' '+space;
  1799. { parast }
  1800. readsymtableoptions('parast');
  1801. readdefinitions('parast');
  1802. readsymbols('parast');
  1803. { localst }
  1804. if (po_has_inlininginfo in procoptions) then
  1805. begin
  1806. readsymtableoptions('localst');
  1807. readdefinitions('localst');
  1808. readsymbols('localst');
  1809. end;
  1810. if (po_has_inlininginfo in procoptions) then
  1811. readnodetree;
  1812. delete(space,1,4);
  1813. end;
  1814. ibprocvardef :
  1815. begin
  1816. readcommondef('Procedural type (ProcVar) definition',defoptions);
  1817. read_abstract_proc_def(calloption,procoptions);
  1818. writeln(space,' Symtable level :',ppufile.getbyte);
  1819. if not EndOfEntry then
  1820. HasMoreInfos;
  1821. space:=' '+space;
  1822. { parast }
  1823. readsymtableoptions('parast');
  1824. readdefinitions('parast');
  1825. readsymbols('parast');
  1826. delete(space,1,4);
  1827. end;
  1828. ibshortstringdef :
  1829. begin
  1830. readcommondef('ShortString definition',defoptions);
  1831. writeln(space,' Length : ',getbyte);
  1832. end;
  1833. ibwidestringdef :
  1834. begin
  1835. readcommondef('WideString definition',defoptions);
  1836. writeln(space,' Length : ',getaint);
  1837. end;
  1838. ibunicodestringdef :
  1839. begin
  1840. readcommondef('UnicodeString definition',defoptions);
  1841. writeln(space,' Length : ',getaint);
  1842. end;
  1843. ibansistringdef :
  1844. begin
  1845. readcommondef('AnsiString definition',defoptions);
  1846. writeln(space,' Length : ',getaint);
  1847. end;
  1848. iblongstringdef :
  1849. begin
  1850. readcommondef('Longstring definition',defoptions);
  1851. writeln(space,' Length : ',getaint);
  1852. end;
  1853. ibrecorddef :
  1854. begin
  1855. readcommondef('Record definition',defoptions);
  1856. writeln(space,' Name of Record : ',getstring);
  1857. writeln(space,' Import lib/pkg : ',getstring);
  1858. write (space,' Options : ');
  1859. readobjectdefoptions;
  1860. if (df_copied_def in defoptions) then
  1861. begin
  1862. write(space,' Copied from : ');
  1863. readderef('');
  1864. end
  1865. else
  1866. begin
  1867. writeln(space,' FieldAlign : ',shortint(getbyte));
  1868. writeln(space,' RecordAlign : ',shortint(getbyte));
  1869. writeln(space,' PadAlign : ',shortint(getbyte));
  1870. writeln(space,'UseFieldAlignment : ',shortint(getbyte));
  1871. writeln(space,' DataSize : ',getasizeint);
  1872. writeln(space,' PaddingSize : ',getword);
  1873. end;
  1874. if not EndOfEntry then
  1875. HasMoreInfos;
  1876. {read the record definitions and symbols}
  1877. space:=' '+space;
  1878. readrecsymtableoptions;
  1879. readsymtableoptions('fields');
  1880. readdefinitions('fields');
  1881. readsymbols('fields');
  1882. Delete(space,1,4);
  1883. end;
  1884. ibobjectdef :
  1885. begin
  1886. readcommondef('Object/Class definition',defoptions);
  1887. writeln(space,' Name of Class : ',getstring);
  1888. writeln(space,' Import lib/pkg : ',getstring);
  1889. write (space,' Options : ');
  1890. readobjectdefoptions;
  1891. b:=getbyte;
  1892. write (space,' Type : ');
  1893. case tobjecttyp(b) of
  1894. odt_class : writeln('class');
  1895. odt_object : writeln('object');
  1896. odt_interfacecom : writeln('interfacecom');
  1897. odt_interfacecorba : writeln('interfacecorba');
  1898. odt_cppclass : writeln('cppclass');
  1899. odt_dispinterface : writeln('dispinterface');
  1900. odt_objcclass : writeln('objcclass');
  1901. odt_objcprotocol : writeln('objcprotocol');
  1902. odt_helper : writeln('helper');
  1903. odt_objccategory : writeln('objccategory');
  1904. odt_javaclass : writeln('Java class');
  1905. odt_interfacejava : writeln('Java interface');
  1906. else writeln('!! Warning: Invalid object type ',b);
  1907. end;
  1908. writeln(space,' External name : ',getstring);
  1909. writeln(space,' DataSize : ',getasizeint);
  1910. writeln(space,' PaddingSize : ',getword);
  1911. writeln(space,' FieldAlign : ',shortint(getbyte));
  1912. writeln(space,' RecordAlign : ',shortint(getbyte));
  1913. writeln(space,' Vmt offset : ',getlongint);
  1914. write (space, ' Ancestor Class : ');
  1915. readderef('');
  1916. if tobjecttyp(b) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  1917. begin
  1918. { IIDGUID }
  1919. for j:=1to 16 do
  1920. getbyte;
  1921. writeln(space,' IID String : ',getstring);
  1922. end;
  1923. writeln(space,' Abstract methods : ',getlongint);
  1924. if (tobjecttyp(b)=odt_helper) or
  1925. (oo_is_classhelper in current_objectoptions) then
  1926. begin
  1927. write(space,' Helper parent : ');
  1928. readderef('');
  1929. end;
  1930. l:=getlongint;
  1931. writeln(space,' VMT entries: ',l);
  1932. for j:=1 to l do
  1933. begin
  1934. write(space,' ');
  1935. readderef('');
  1936. writeln(space,' Visibility: ',Visibility2Str(getbyte));
  1937. end;
  1938. if tobjecttyp(b) in [odt_class,odt_interfacecorba,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  1939. begin
  1940. l:=getlongint;
  1941. writeln(space,' Impl Intf Count : ',l);
  1942. for j:=1 to l do
  1943. begin
  1944. write (space,' - Definition : ');
  1945. readderef('');
  1946. writeln(space,' IOffset : ',getlongint);
  1947. end;
  1948. end;
  1949. if df_copied_def in current_defoptions then
  1950. begin
  1951. writeln(' Copy of def: ');
  1952. readderef('');
  1953. end;
  1954. if not EndOfEntry then
  1955. HasMoreInfos;
  1956. if not(df_copied_def in current_defoptions) then
  1957. begin
  1958. {read the record definitions and symbols}
  1959. space:=' '+space;
  1960. readrecsymtableoptions;
  1961. readsymtableoptions('fields');
  1962. readdefinitions('fields');
  1963. readsymbols('fields');
  1964. Delete(space,1,4);
  1965. end;
  1966. end;
  1967. ibfiledef :
  1968. begin
  1969. ReadCommonDef('File definition',defoptions);
  1970. write (space,' Type : ');
  1971. case getbyte of
  1972. 0 : writeln('Text');
  1973. 1 : begin
  1974. writeln('Typed');
  1975. write (space,' File of Type : ');
  1976. readderef('');
  1977. end;
  1978. 2 : writeln('Untyped');
  1979. end;
  1980. end;
  1981. ibformaldef :
  1982. begin
  1983. readcommondef('Generic definition (void-typ)',defoptions);
  1984. writeln(space,' Is Typed : ',(getbyte<>0));
  1985. end;
  1986. ibundefineddef :
  1987. readcommondef('Undefined definition (generic parameter)',defoptions);
  1988. ibenumdef :
  1989. begin
  1990. readcommondef('Enumeration type definition',defoptions);
  1991. writeln(space,' Smallest element : ',getaint);
  1992. writeln(space,' Largest element : ',getaint);
  1993. writeln(space,' Size : ',getaint);
  1994. {$ifdef jvm}
  1995. write(space,' Class def : ');
  1996. readderef('');
  1997. {$endif}
  1998. if df_copied_def in defoptions then
  1999. begin
  2000. write(space,'Base enumeration type : ');
  2001. readderef('');
  2002. end
  2003. else
  2004. begin
  2005. space:=' '+space;
  2006. readsymtableoptions('elements');
  2007. readdefinitions('elements');
  2008. readsymbols('elements');
  2009. delete(space,1,4);
  2010. end;
  2011. end;
  2012. ibclassrefdef :
  2013. begin
  2014. readcommondef('Class reference definition',defoptions);
  2015. write (space,' Pointed Type : ');
  2016. readderef('');
  2017. end;
  2018. ibsetdef :
  2019. begin
  2020. readcommondef('Set definition',defoptions);
  2021. write (space,' Element type : ');
  2022. readderef('');
  2023. writeln(space,' Size : ',getaint);
  2024. writeln(space,' Set Base : ',getaint);
  2025. writeln(space,' Set Max : ',getaint);
  2026. end;
  2027. ibvariantdef :
  2028. begin
  2029. readcommondef('Variant definition',defoptions);
  2030. write (space,' Varianttype : ');
  2031. b:=getbyte;
  2032. case tvarianttype(b) of
  2033. vt_normalvariant :
  2034. writeln('Normal');
  2035. vt_olevariant :
  2036. writeln('OLE');
  2037. else
  2038. writeln('!! Warning: Invalid varianttype ',b);
  2039. end;
  2040. end;
  2041. iberror :
  2042. begin
  2043. WriteError('!! Error in PPU');
  2044. exit;
  2045. end;
  2046. ibenddefs :
  2047. break;
  2048. else
  2049. begin
  2050. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  2051. has_errors:=true;
  2052. end;
  2053. end;
  2054. if not EndOfEntry then
  2055. HasMoreInfos;
  2056. until false;
  2057. end;
  2058. end;
  2059. procedure readmoduleoptions(space : string);
  2060. type
  2061. { tmoduleoption type is in unit fmodule }
  2062. tmoduleoption = (mo_none,
  2063. mo_hint_deprecated,
  2064. mo_hint_platform,
  2065. mo_hint_library,
  2066. mo_hint_unimplemented,
  2067. mo_hint_experimental,
  2068. mo_has_deprecated_msg
  2069. );
  2070. tmoduleoptions = set of tmoduleoption;
  2071. tmoduleopt=record
  2072. mask : tmoduleoption;
  2073. str : string[30];
  2074. end;
  2075. const
  2076. moduleopts=ord(high(tmoduleoption));
  2077. moduleopt : array[1..moduleopts] of tmoduleopt=(
  2078. (mask:mo_hint_deprecated; str:'Hint Deprecated'),
  2079. (mask:mo_hint_platform; str:'Hint Platform'),
  2080. (mask:mo_hint_library; str:'Hint Library'),
  2081. (mask:mo_hint_unimplemented; str:'Hint Unimplemented'),
  2082. (mask:mo_hint_experimental; str:'Hint Experimental'),
  2083. (mask:mo_has_deprecated_msg; str:'Has Deprecated Message')
  2084. );
  2085. var
  2086. moduleoptions : tmoduleoptions;
  2087. i : longint;
  2088. first : boolean;
  2089. begin
  2090. ppufile.getsmallset(moduleoptions);
  2091. if moduleoptions<>[] then
  2092. begin
  2093. first:=true;
  2094. for i:=1to moduleopts do
  2095. if (moduleopt[i].mask in moduleoptions) then
  2096. begin
  2097. if first then
  2098. first:=false
  2099. else
  2100. write(', ');
  2101. write(moduleopt[i].str);
  2102. end;
  2103. end;
  2104. writeln;
  2105. if mo_has_deprecated_msg in moduleoptions then
  2106. writeln(space,'Deprecated : ', ppufile.getstring);
  2107. end;
  2108. {****************************************************************************
  2109. Read General Part
  2110. ****************************************************************************}
  2111. procedure readinterface;
  2112. var
  2113. b : byte;
  2114. sourcenumber : longint;
  2115. begin
  2116. with ppufile do
  2117. begin
  2118. repeat
  2119. b:=readentry;
  2120. case b of
  2121. ibmodulename :
  2122. Writeln('Module Name: ',getstring);
  2123. ibmoduleoptions:
  2124. readmoduleoptions(' ');
  2125. ibsourcefiles :
  2126. begin
  2127. sourcenumber:=1;
  2128. while not EndOfEntry do
  2129. begin
  2130. Writeln('Source file ',sourcenumber,' : ',getstring,' ',filetimestring(getlongint));
  2131. inc(sourcenumber);
  2132. end;
  2133. end;
  2134. {$IFDEF MACRO_DIFF_HINT}
  2135. ibusedmacros :
  2136. begin
  2137. while not EndOfEntry do
  2138. begin
  2139. Write('Conditional ',getstring);
  2140. b:=getbyte;
  2141. if boolean(b)=true then
  2142. write(' defined at startup')
  2143. else
  2144. write(' not defined at startup');
  2145. b:=getbyte;
  2146. if boolean(b)=true then
  2147. writeln(' was used')
  2148. else
  2149. writeln;
  2150. end;
  2151. end;
  2152. {$ENDIF}
  2153. ibloadunit :
  2154. ReadLoadUnit;
  2155. iblinkunitofiles :
  2156. ReadLinkContainer('Link unit object file: ');
  2157. iblinkunitstaticlibs :
  2158. ReadLinkContainer('Link unit static lib: ');
  2159. iblinkunitsharedlibs :
  2160. ReadLinkContainer('Link unit shared lib: ');
  2161. iblinkotherofiles :
  2162. ReadLinkContainer('Link other object file: ');
  2163. iblinkotherstaticlibs :
  2164. ReadLinkContainer('Link other static lib: ');
  2165. iblinkothersharedlibs :
  2166. ReadLinkContainer('Link other shared lib: ');
  2167. iblinkotherframeworks:
  2168. ReadLinkContainer('Link framework: ');
  2169. ibmainname:
  2170. Writeln('Specified main program symbol name: ',getstring);
  2171. ibImportSymbols :
  2172. ReadImportSymbols;
  2173. ibderefdata :
  2174. ReadDerefData;
  2175. ibderefmap :
  2176. ReadDerefMap;
  2177. ibwpofile :
  2178. ReadWpoFileInfo;
  2179. ibresources :
  2180. ReadLinkContainer('Resource file: ');
  2181. iberror :
  2182. begin
  2183. WriteError('Error in PPU');
  2184. exit;
  2185. end;
  2186. ibendinterface :
  2187. break;
  2188. else
  2189. begin
  2190. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  2191. has_errors:=true;
  2192. end;
  2193. end;
  2194. until false;
  2195. end;
  2196. end;
  2197. {****************************************************************************
  2198. Read Implementation Part
  2199. ****************************************************************************}
  2200. procedure readimplementation;
  2201. var
  2202. b : byte;
  2203. begin
  2204. with ppufile do
  2205. begin
  2206. repeat
  2207. b:=readentry;
  2208. case b of
  2209. ibasmsymbols :
  2210. ReadAsmSymbols;
  2211. ibloadunit :
  2212. ReadLoadUnit;
  2213. iberror :
  2214. begin
  2215. WriteError('Error in PPU');
  2216. exit;
  2217. end;
  2218. ibendimplementation :
  2219. break;
  2220. else
  2221. begin
  2222. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  2223. has_errors:=true;
  2224. end;
  2225. end;
  2226. until false;
  2227. end;
  2228. end;
  2229. procedure dofile (filename : string);
  2230. begin
  2231. { reset }
  2232. space:='';
  2233. { fix filename }
  2234. if pos('.',filename)=0 then
  2235. filename:=filename+'.ppu';
  2236. ppufile:=tppufile.create(filename);
  2237. if not ppufile.openfile then
  2238. begin
  2239. WriteError('IO-Error when opening : '+filename+', Skipping');
  2240. exit;
  2241. end;
  2242. { PPU File is open, check for PPU Id }
  2243. if not ppufile.CheckPPUID then
  2244. begin
  2245. writeln(Filename,' : Not a valid PPU file, Skipping');
  2246. has_errors:=true;
  2247. exit;
  2248. end;
  2249. { Check PPU Version }
  2250. ppuversion:=ppufile.GetPPUVersion;
  2251. Writeln('Analyzing ',filename,' (v',PPUVersion,')');
  2252. if PPUVersion<16 then
  2253. begin
  2254. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  2255. has_errors:=true;
  2256. exit;
  2257. end;
  2258. { Write PPU Header Information }
  2259. if (verbose and v_header)<>0 then
  2260. begin
  2261. Writeln;
  2262. Writeln('Header');
  2263. Writeln('-------');
  2264. with ppufile.header do
  2265. begin
  2266. Writeln('Compiler version : ',ppufile.header.compiler shr 14,'.',
  2267. (ppufile.header.compiler shr 7) and $7f,'.',
  2268. ppufile.header.compiler and $7f);
  2269. WriteLn('Target processor : ',Cpu2Str(cpu));
  2270. WriteLn('Target operating system : ',Target2Str(target));
  2271. Writeln('Unit flags : ',PPUFlags2Str(flags));
  2272. Writeln('FileSize (w/o header) : ',size);
  2273. Writeln('Checksum : ',hexstr(checksum,8));
  2274. Writeln('Interface Checksum : ',hexstr(interface_checksum,8));
  2275. Writeln('Indirect Checksum : ',hexstr(indirect_checksum,8));
  2276. Writeln('Definitions stored : ',tostr(deflistsize));
  2277. Writeln('Symbols stored : ',tostr(symlistsize));
  2278. end;
  2279. end;
  2280. {read the general stuff}
  2281. if (verbose and v_interface)<>0 then
  2282. begin
  2283. Writeln;
  2284. Writeln('Interface section');
  2285. Writeln('------------------');
  2286. readinterface;
  2287. end
  2288. else
  2289. ppufile.skipuntilentry(ibendinterface);
  2290. Writeln;
  2291. Writeln('Interface symtable');
  2292. Writeln('----------------------');
  2293. readsymtableoptions('interface');
  2294. {read the definitions}
  2295. if (verbose and v_defs)<>0 then
  2296. begin
  2297. Writeln;
  2298. Writeln('Interface definitions');
  2299. Writeln('----------------------');
  2300. readdefinitions('interface');
  2301. end
  2302. else
  2303. ppufile.skipuntilentry(ibenddefs);
  2304. {read the symbols}
  2305. if (verbose and v_syms)<>0 then
  2306. begin
  2307. Writeln;
  2308. Writeln('Interface Symbols');
  2309. Writeln('------------------');
  2310. readsymbols('interface');
  2311. end
  2312. else
  2313. ppufile.skipuntilentry(ibendsyms);
  2314. {read the macro symbols}
  2315. if (verbose and v_syms)<>0 then
  2316. begin
  2317. Writeln;
  2318. Writeln('Interface Macro Symbols');
  2319. Writeln('-----------------------');
  2320. end;
  2321. if ppufile.readentry<>ibexportedmacros then
  2322. begin
  2323. WriteError('!! Error in PPU');
  2324. exit;
  2325. end;
  2326. if boolean(ppufile.getbyte) then
  2327. begin
  2328. readsymtableoptions('interface macro');
  2329. {skip the definition section for macros (since they are never used) }
  2330. ppufile.skipuntilentry(ibenddefs);
  2331. {read the macro symbols}
  2332. if (verbose and v_syms)<>0 then
  2333. readsymbols('interface macro')
  2334. else
  2335. ppufile.skipuntilentry(ibendsyms);
  2336. end
  2337. else
  2338. Writeln('(no exported macros)');
  2339. {read the implementation stuff}
  2340. if (verbose and v_implementation)<>0 then
  2341. begin
  2342. Writeln;
  2343. Writeln('Implementation section');
  2344. Writeln('-----------------------');
  2345. readimplementation;
  2346. end
  2347. else
  2348. ppufile.skipuntilentry(ibendimplementation);
  2349. {read the static symtable}
  2350. Writeln;
  2351. Writeln('Implementation symtable');
  2352. Writeln('----------------------');
  2353. readsymtableoptions('implementation');
  2354. if (ppufile.header.flags and uf_local_symtable)<>0 then
  2355. begin
  2356. if (verbose and v_defs)<>0 then
  2357. begin
  2358. Writeln;
  2359. Writeln('Static definitions');
  2360. Writeln('----------------------');
  2361. readdefinitions('implementation');
  2362. end
  2363. else
  2364. ppufile.skipuntilentry(ibenddefs);
  2365. {read the symbols}
  2366. if (verbose and v_syms)<>0 then
  2367. begin
  2368. Writeln;
  2369. Writeln('Static Symbols');
  2370. Writeln('------------------');
  2371. readsymbols('implementation');
  2372. end
  2373. else
  2374. ppufile.skipuntilentry(ibendsyms);
  2375. end;
  2376. ReadCreatedObjTypes;
  2377. FreeDerefdata;
  2378. {shutdown ppufile}
  2379. ppufile.closefile;
  2380. ppufile.free;
  2381. Writeln;
  2382. end;
  2383. procedure help;
  2384. begin
  2385. writeln('usage: ppudump [options] <filename1> <filename2>...');
  2386. writeln;
  2387. writeln('[options] can be:');
  2388. writeln(' -M Exit with ExitCode=2 if more information is available');
  2389. writeln(' -V<verbose> Set verbosity to <verbose>');
  2390. writeln(' H - Show header info');
  2391. writeln(' I - Show interface');
  2392. writeln(' M - Show implementation');
  2393. writeln(' S - Show interface symbols');
  2394. writeln(' D - Show interface definitions');
  2395. // writeln(' B - Show browser info');
  2396. writeln(' A - Show all');
  2397. writeln(' -h, -? This helpscreen');
  2398. halt;
  2399. end;
  2400. var
  2401. startpara,
  2402. nrfile,i : longint;
  2403. para : string;
  2404. const
  2405. error_on_more : boolean = false;
  2406. begin
  2407. writeln(Title+' '+Version);
  2408. writeln(Copyright);
  2409. writeln;
  2410. if paramcount<1 then
  2411. begin
  2412. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  2413. halt(1);
  2414. end;
  2415. { turn verbose on by default }
  2416. verbose:=v_all;
  2417. { read options }
  2418. startpara:=1;
  2419. while copy(paramstr(startpara),1,1)='-' do
  2420. begin
  2421. para:=paramstr(startpara);
  2422. case upcase(para[2]) of
  2423. 'M' : error_on_more:=true;
  2424. 'V' : begin
  2425. verbose:=0;
  2426. for i:=3 to length(para) do
  2427. case upcase(para[i]) of
  2428. 'H' : verbose:=verbose or v_header;
  2429. 'I' : verbose:=verbose or v_interface;
  2430. 'M' : verbose:=verbose or v_implementation;
  2431. 'D' : verbose:=verbose or v_defs;
  2432. 'S' : verbose:=verbose or v_syms;
  2433. 'A' : verbose:=verbose or v_all;
  2434. end;
  2435. end;
  2436. 'H' : help;
  2437. '?' : help;
  2438. end;
  2439. inc(startpara);
  2440. end;
  2441. { process files }
  2442. for nrfile:=startpara to paramcount do
  2443. dofile (paramstr(nrfile));
  2444. if has_errors then
  2445. Halt(1);
  2446. if error_on_more and has_more_infos then
  2447. Halt(2);
  2448. end.