2
0

ppudump.pp 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by the FPC Development Team
  4. Dumps the contents of a FPC unit file (PPU File)
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************}
  17. {$ifdef TP}
  18. {$N+,E+}
  19. {$endif}
  20. program pppdump;
  21. uses
  22. dos,
  23. ppu;
  24. const
  25. Version = 'Version 1.10';
  26. Title = 'PPU-Analyser';
  27. Copyright = 'Copyright (c) 1998-2003 by the Free Pascal Development Team';
  28. { verbosity }
  29. v_none = $0;
  30. v_header = $1;
  31. v_defs = $2;
  32. v_syms = $4;
  33. v_interface = $8;
  34. v_implementation = $10;
  35. v_browser = $20;
  36. v_all = $ff;
  37. type
  38. { Copied from systems.pas }
  39. ttargetcpu=
  40. (
  41. no_cpu, { 0 }
  42. i386, { 1 }
  43. m68k, { 2 }
  44. alpha, { 3 }
  45. powerpc, { 4 }
  46. sparc, { 5 }
  47. vm { 6 }
  48. );
  49. var
  50. ppufile : tppufile;
  51. space : string;
  52. read_member : boolean;
  53. unitnumber,
  54. unitindex : longint;
  55. verbose : longint;
  56. derefdata : pbyte;
  57. derefdatalen : longint;
  58. {****************************************************************************
  59. Helper Routines
  60. ****************************************************************************}
  61. const has_errors : boolean = false;
  62. Procedure Error(const S : string);
  63. Begin
  64. Writeln(S);
  65. has_errors:=true;
  66. End;
  67. Function Target2Str(w:longint):string;
  68. type
  69. { taken from systems.pas }
  70. ttarget =
  71. (
  72. target_none, { 0 }
  73. target_i386_GO32V1, { 1 }
  74. target_i386_GO32V2, { 2 }
  75. target_i386_linux, { 3 }
  76. target_i386_OS2, { 4 }
  77. target_i386_Win32, { 5 }
  78. target_i386_freebsd, { 6 }
  79. target_m68k_Amiga, { 7 }
  80. target_m68k_Atari, { 8 }
  81. target_m68k_Mac, { 9 }
  82. target_m68k_linux, { 10 }
  83. target_m68k_PalmOS, { 11 }
  84. target_alpha_linux, { 12 }
  85. target_powerpc_linux, { 13 }
  86. target_powerpc_macos, { 14 }
  87. target_i386_sunos, { 15 }
  88. target_i386_beos, { 16 }
  89. target_i386_netbsd, { 17 }
  90. target_m68k_netbsd, { 18 }
  91. target_i386_Netware, { 19 }
  92. target_i386_qnx, { 20 }
  93. target_i386_wdosx, { 21 }
  94. target_sparc_sunos, { 22 }
  95. target_sparc_linux, { 23 }
  96. target_i386_openbsd, { 24 }
  97. target_m68k_openbsd, { 25 }
  98. system_x86_64_linux, { 26 }
  99. system_powerpc_macosx, { 27 }
  100. target_i386_emx { 28 }
  101. );
  102. const
  103. Targets : array[ttarget] of string[16]=(
  104. { 0 } 'none',
  105. { 1 } 'GO32V1',
  106. { 2 } 'GO32V2',
  107. { 3 } 'Linux-i386',
  108. { 4 } 'OS/2',
  109. { 5 } 'Win32',
  110. { 6 } 'FreeBSD-i386',
  111. { 7 } 'Amiga',
  112. { 8 } 'Atari',
  113. { 9 } 'MacOS-m68k',
  114. { 10 } 'Linux-m68k',
  115. { 11 } 'PalmOS-m68k',
  116. { 12 } 'Linux-alpha',
  117. { 13 } 'Linux-ppc',
  118. { 14 } 'MacOS-ppc',
  119. { 15 } 'Solaris-i386',
  120. { 16 } 'BeOS-i386',
  121. { 17 } 'NetBSD-i386',
  122. { 18 } 'NetBSD-m68k',
  123. { 19 } 'Netware',
  124. { 20 } 'Qnx-i386',
  125. { 21 } 'WDOSX-i386',
  126. { 22 } 'Solaris-sparc',
  127. { 23 } 'Linux-sparc',
  128. { 24 } 'OpenBSD-i386',
  129. { 25 } 'OpenBSD-m68k',
  130. { 26 } 'Linux-x86-64',
  131. { 27 } 'MacOSX-ppc',
  132. { 28 } 'OS/2 via EMX'
  133. );
  134. begin
  135. if w<=ord(high(ttarget)) then
  136. Target2Str:=Targets[ttarget(w)]
  137. else
  138. Target2Str:='<Unknown>';
  139. end;
  140. Function Cpu2Str(w:longint):string;
  141. const
  142. CpuTxt : array[ttargetcpu] of string[7]=
  143. ('none','i386','m68k','alpha','powerpc','sparc','vis');
  144. begin
  145. if w<=ord(high(ttargetcpu)) then
  146. Cpu2Str:=CpuTxt[ttargetcpu(w)]
  147. else
  148. Cpu2Str:='<Unknown>';
  149. end;
  150. Function Varspez2Str(w:longint):string;
  151. const
  152. varspezstr : array[0..4] of string[6]=('Value','Const','Var','Out','Hidden');
  153. begin
  154. if w<=ord(high(varspezstr)) then
  155. Varspez2Str:=varspezstr[w]
  156. else
  157. Varspez2Str:='<Unknown>';
  158. end;
  159. function PPUFlags2Str(flags:longint):string;
  160. type
  161. tflagopt=record
  162. mask : longint;
  163. str : string[30];
  164. end;
  165. const
  166. flagopts=16;
  167. flagopt : array[1..flagopts] of tflagopt=(
  168. (mask: $1 ;str:'init'),
  169. (mask: $2 ;str:'final'),
  170. (mask: $4 ;str:'big_endian'),
  171. (mask: $8 ;str:'dbx'),
  172. (mask: $10 ;str:'browser'),
  173. (mask: $20 ;str:'in_library'),
  174. (mask: $40 ;str:'smart_linked'),
  175. (mask: $80 ;str:'static_linked'),
  176. (mask: $100 ;str:'shared_linked'),
  177. (mask: $200 ;str:'local_browser'),
  178. (mask: $400 ;str:'no_link'),
  179. (mask: $800 ;str:'has_resources'),
  180. (mask: $1000 ;str:'little_endian'),
  181. (mask: $2000 ;str:'release'),
  182. (mask: $4000 ;str:'local_threadvars'),
  183. (mask: $8000 ;str:'fpu emulation on')
  184. );
  185. var
  186. i : longint;
  187. first : boolean;
  188. s : string;
  189. begin
  190. s:='';
  191. if flags<>0 then
  192. begin
  193. first:=true;
  194. for i:=1to flagopts do
  195. if (flags and flagopt[i].mask)<>0 then
  196. begin
  197. if first then
  198. first:=false
  199. else
  200. s:=s+', ';
  201. s:=s+flagopt[i].str;
  202. end;
  203. end
  204. else
  205. s:='none';
  206. PPUFlags2Str:=s;
  207. end;
  208. const
  209. HexTbl : array[0..15] of char='0123456789ABCDEF';
  210. function HexB(b:byte):string;
  211. begin
  212. HexB[0]:=#2;
  213. HexB[1]:=HexTbl[b shr 4];
  214. HexB[2]:=HexTbl[b and $f];
  215. end;
  216. function hexstr(val : cardinal;cnt : byte) : string;
  217. const
  218. HexTbl : array[0..15] of char='0123456789ABCDEF';
  219. var
  220. i : longint;
  221. begin
  222. hexstr[0]:=char(cnt);
  223. for i:=cnt downto 1 do
  224. begin
  225. hexstr[i]:=hextbl[val and $f];
  226. val:=val shr 4;
  227. end;
  228. end;
  229. Function L0(l:longint):string;
  230. {
  231. return the string of value l, if l<10 then insert a zero, so
  232. the string is always at least 2 chars '01','02',etc
  233. }
  234. var
  235. s : string;
  236. begin
  237. Str(l,s);
  238. if l<10 then
  239. s:='0'+s;
  240. L0:=s;
  241. end;
  242. function filetimestring( t : longint) : string;
  243. {
  244. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  245. }
  246. var
  247. DT : DateTime;
  248. begin
  249. if t=-1 then
  250. begin
  251. FileTimeString:='Not Found';
  252. exit;
  253. end;
  254. unpacktime(t,DT);
  255. filetimestring:=L0(dt.Year)+'/'+L0(dt.Month)+'/'+L0(dt.Day)+' '+L0(dt.Hour)+':'+L0(dt.min)+':'+L0(dt.sec);
  256. end;
  257. {****************************************************************************
  258. Read Routines
  259. ****************************************************************************}
  260. function getint64:int64;
  261. var
  262. l1,l2 : longint;
  263. begin
  264. l1:=ppufile.getlongint;
  265. l2:=ppufile.getlongint;
  266. getint64:=(int64(l2) shl 32) or qword(l1);
  267. end;
  268. Procedure ReadLinkContainer(const prefix:string);
  269. {
  270. Read a serie of strings and write to the screen starting every line
  271. with prefix
  272. }
  273. function maskstr(m:longint):string;
  274. const
  275. { link options }
  276. link_none = $0;
  277. link_allways = $1;
  278. link_static = $2;
  279. link_smart = $4;
  280. link_shared = $8;
  281. var
  282. s : string;
  283. begin
  284. s:='';
  285. if (m and link_allways)<>0 then
  286. s:=s+'always ';
  287. if (m and link_static)<>0 then
  288. s:=s+'static ';
  289. if (m and link_smart)<>0 then
  290. s:=s+'smart ';
  291. if (m and link_shared)<>0 then
  292. s:=s+'shared ';
  293. maskstr:=s;
  294. end;
  295. var
  296. s : string;
  297. m : longint;
  298. begin
  299. while not ppufile.endofentry do
  300. begin
  301. s:=ppufile.getstring;
  302. m:=ppufile.getlongint;
  303. WriteLn(prefix,s,' (',maskstr(m),')');
  304. end;
  305. end;
  306. Procedure ReadContainer(const prefix:string);
  307. {
  308. Read a serie of strings and write to the screen starting every line
  309. with prefix
  310. }
  311. begin
  312. while not ppufile.endofentry do
  313. WriteLn(prefix,ppufile.getstring);
  314. end;
  315. procedure ReadLoadUnit;
  316. var
  317. ucrc,uintfcrc : longint;
  318. begin
  319. while not ppufile.EndOfEntry do
  320. begin
  321. inc(unitnumber);
  322. write('Uses unit: ',ppufile.getstring,' (Number: ',unitnumber,')');
  323. ucrc:=ppufile.getlongint;
  324. uintfcrc:=ppufile.getlongint;
  325. write(' (Crc: ',hexstr(ucrc,8),', IntfcCrc: ',hexstr(uintfcrc,8),')');
  326. end;
  327. end;
  328. Procedure ReadDerefdata;
  329. begin
  330. derefdatalen:=ppufile.entrysize;
  331. if derefdatalen=0 then
  332. begin
  333. writeln('!! Error: derefdatalen=0');
  334. exit;
  335. end;
  336. Writeln('Derefdata length: ',derefdatalen);
  337. derefdata:=allocmem(derefdatalen);
  338. ppufile.getdata(derefdata^,derefdatalen);
  339. end;
  340. Procedure ReadRef;
  341. begin
  342. if (verbose and v_browser)=0 then
  343. exit;
  344. while (not ppufile.endofentry) and (not ppufile.error) do
  345. Writeln(space,' - Refered : ',ppufile.getword,', (',ppufile.getlongint,',',ppufile.getword,')');
  346. end;
  347. Procedure ReadAsmSymbols;
  348. type
  349. { Copied from aasmbase.pas }
  350. TAsmsymbind=(AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL);
  351. TAsmsymtype=(AT_NONE,AT_FUNCTION,AT_DATA,AT_SECTION);
  352. var
  353. s,
  354. bindstr,
  355. typestr : string;
  356. i : longint;
  357. begin
  358. writeln(space,'Number of AsmSymbols: ',ppufile.getlongint);
  359. i:=0;
  360. while (not ppufile.endofentry) and (not ppufile.error) do
  361. begin
  362. s:=ppufile.getstring;
  363. case tasmsymbind(ppufile.getbyte) of
  364. AB_EXTERNAL :
  365. bindstr:='External';
  366. AB_COMMON :
  367. bindstr:='Common';
  368. AB_LOCAL :
  369. bindstr:='Local';
  370. AB_GLOBAL :
  371. bindstr:='Global';
  372. else
  373. bindstr:='<Error !!>'
  374. end;
  375. case tasmsymtype(ppufile.getbyte) of
  376. AT_FUNCTION :
  377. typestr:='Function';
  378. AT_DATA :
  379. typestr:='Data';
  380. AT_SECTION :
  381. typestr:='Section';
  382. else
  383. typestr:='<Error !!>'
  384. end;
  385. Writeln(space,' ',i,' : ',s,' [',bindstr,',',typestr,']');
  386. inc(i);
  387. end;
  388. end;
  389. Procedure ReadPosInfo;
  390. var
  391. info : byte;
  392. fileindex,line,column : longint;
  393. begin
  394. with ppufile do
  395. begin
  396. {
  397. info byte layout in bits:
  398. 0-1 - amount of bytes for fileindex
  399. 2-3 - amount of bytes for line
  400. 4-5 - amount of bytes for column
  401. }
  402. info:=getbyte;
  403. case (info and $03) of
  404. 0 : fileindex:=getbyte;
  405. 1 : fileindex:=getword;
  406. 2 : fileindex:=(getbyte shl 16) or getword;
  407. 3 : fileindex:=getlongint;
  408. end;
  409. case ((info shr 2) and $03) of
  410. 0 : line:=getbyte;
  411. 1 : line:=getword;
  412. 2 : line:=(getbyte shl 16) or getword;
  413. 3 : line:=getlongint;
  414. end;
  415. case ((info shr 4) and $03) of
  416. 0 : column:=getbyte;
  417. 1 : column:=getword;
  418. 2 : column:=(getbyte shl 16) or getword;
  419. 3 : column:=getlongint;
  420. end;
  421. Writeln(fileindex,' (',line,',',column,')');
  422. end;
  423. end;
  424. procedure readderef;
  425. type
  426. tdereftype = (deref_nil,
  427. deref_sym,
  428. deref_def,
  429. deref_aktrecord,
  430. deref_aktstatic,
  431. deref_aktglobal,
  432. deref_aktlocal,
  433. deref_aktpara,
  434. deref_unit,
  435. deref_record,
  436. deref_local,
  437. deref_para,
  438. deref_parent_object
  439. );
  440. var
  441. b : tdereftype;
  442. first : boolean;
  443. idx : word;
  444. i,n : byte;
  445. pdata : pbyte;
  446. begin
  447. if not assigned(derefdata) then
  448. exit;
  449. first:=true;
  450. idx:=ppufile.getlongint;
  451. if (idx>derefdatalen) then
  452. begin
  453. writeln('!! Error: Deref idx ',idx,' > ',derefdatalen);
  454. exit;
  455. end;
  456. write('(',idx,') ');
  457. pdata:=@derefdata[idx];
  458. i:=0;
  459. n:=pdata[i];
  460. inc(i);
  461. if n<1 then
  462. begin
  463. writeln('!! Error: Deref len < 1');
  464. exit;
  465. end;
  466. while (i<n) do
  467. begin
  468. if not first then
  469. write(', ')
  470. else
  471. first:=false;
  472. b:=tdereftype(pdata[i]);
  473. inc(i);
  474. case b of
  475. deref_nil :
  476. write('Nil');
  477. deref_def :
  478. begin
  479. idx:=pdata[i] shl 8;
  480. idx:=idx or pdata[i+1];
  481. inc(i,2);
  482. write('Definition ',idx);
  483. end;
  484. deref_sym :
  485. begin
  486. idx:=pdata[i] shl 8;
  487. idx:=idx or pdata[i+1];
  488. inc(i,2);
  489. write('Symbol ',idx);
  490. end;
  491. deref_aktrecord :
  492. write('AktRecord');
  493. deref_aktstatic :
  494. write('AktStatic');
  495. deref_aktglobal :
  496. write('AktGlobal');
  497. deref_aktlocal :
  498. write('AktLocal');
  499. deref_aktpara :
  500. write('AktPara');
  501. deref_unit :
  502. begin
  503. idx:=pdata[i] shl 8;
  504. idx:=idx or pdata[i+1];
  505. inc(i,2);
  506. write('Unit ',idx);
  507. end;
  508. deref_record :
  509. write('RecordDef');
  510. deref_para :
  511. write('Parameter of procdef');
  512. deref_local :
  513. write('Local of procdef');
  514. deref_parent_object :
  515. write('Parent object');
  516. else
  517. begin
  518. writeln('!! unsupported dereftyp: ',ord(b));
  519. break;
  520. end;
  521. end;
  522. end;
  523. writeln;
  524. end;
  525. procedure readtype;
  526. begin
  527. readderef;
  528. end;
  529. procedure readsymlist(const s:string);
  530. type
  531. tsltype = (sl_none,
  532. sl_load,
  533. sl_call,
  534. sl_subscript,
  535. sl_vec
  536. );
  537. const
  538. slstr : array[tsltype] of string[9] = ('',
  539. 'load',
  540. 'call',
  541. 'subscript',
  542. 'vec'
  543. );
  544. var
  545. sl : tsltype;
  546. begin
  547. readderef;
  548. repeat
  549. sl:=tsltype(ppufile.getbyte);
  550. if sl=sl_none then
  551. break;
  552. write(s,'(',slstr[sl],') ');
  553. case sl of
  554. sl_call,
  555. sl_load,
  556. sl_subscript :
  557. readderef;
  558. sl_vec :
  559. writeln(ppufile.getlongint);
  560. end;
  561. until false;
  562. end;
  563. procedure readsymoptions;
  564. type
  565. tsymoption=(sp_none,
  566. sp_public,
  567. sp_private,
  568. sp_published,
  569. sp_protected,
  570. sp_forwarddef,
  571. sp_static,
  572. sp_primary_typesym { this is for typesym, to know who is the primary symbol of a def }
  573. );
  574. tsymoptions=set of tsymoption;
  575. tsymopt=record
  576. mask : tsymoption;
  577. str : string[30];
  578. end;
  579. const
  580. symopts=7;
  581. symopt : array[1..symopts] of tsymopt=(
  582. (mask:sp_public; str:'Public'),
  583. (mask:sp_private; str:'Private'),
  584. (mask:sp_published; str:'Published'),
  585. (mask:sp_protected; str:'Protected'),
  586. (mask:sp_forwarddef; str:'ForwardDef'),
  587. (mask:sp_static; str:'Static'),
  588. (mask:sp_primary_typesym;str:'PrimaryTypeSym')
  589. );
  590. var
  591. symoptions : tsymoptions;
  592. i : longint;
  593. first : boolean;
  594. begin
  595. ppufile.getsmallset(symoptions);
  596. if symoptions<>[] then
  597. begin
  598. first:=true;
  599. for i:=1to symopts do
  600. if (symopt[i].mask in symoptions) then
  601. begin
  602. if first then
  603. first:=false
  604. else
  605. write(', ');
  606. write(symopt[i].str);
  607. end;
  608. end;
  609. writeln;
  610. end;
  611. { Read abstract procdef and return if inline procdef }
  612. type
  613. tproccalloption=(pocall_none,
  614. pocall_cdecl, { procedure uses C styled calling }
  615. pocall_cppdecl, { C++ calling conventions }
  616. pocall_compilerproc, { Procedure is used for internal compiler calls }
  617. pocall_far16, { Far16 for OS/2 }
  618. pocall_fpccall, { FPC default calling }
  619. pocall_inline, { Procedure is an assembler macro }
  620. pocall_internproc, { Procedure has compiler magic}
  621. pocall_palmossyscall, { procedure is a PalmOS system call }
  622. pocall_pascal, { pascal standard left to right }
  623. pocall_register, { procedure uses register (fastcall) calling }
  624. pocall_safecall, { safe call calling conventions }
  625. pocall_stdcall, { procedure uses stdcall call }
  626. pocall_system { system call }
  627. );
  628. tproccalloptions=set of tproccalloption;
  629. tproctypeoption=(potype_none,
  630. potype_proginit, { Program initialization }
  631. potype_unitinit, { unit initialization }
  632. potype_unitfinalize, { unit finalization }
  633. potype_constructor, { Procedure is a constructor }
  634. potype_destructor, { Procedure is a destructor }
  635. potype_operator { Procedure defines an operator }
  636. );
  637. tproctypeoptions=set of tproctypeoption;
  638. tprocoption=(po_none,
  639. po_classmethod, { class method }
  640. po_virtualmethod, { Procedure is a virtual method }
  641. po_abstractmethod, { Procedure is an abstract method }
  642. po_staticmethod, { static method }
  643. po_overridingmethod, { method with override directive }
  644. po_methodpointer, { method pointer, only in procvardef, also used for 'with object do' }
  645. po_interrupt, { Procedure is an interrupt handler }
  646. po_iocheck, { IO checking should be done after a call to the procedure }
  647. po_assembler, { Procedure is written in assembler }
  648. po_msgstr, { method for string message handling }
  649. po_msgint, { method for int message handling }
  650. po_exports, { Procedure has export directive (needed for OS/2) }
  651. po_external, { Procedure is external (in other object or lib)}
  652. po_savestdregs, { save std regs cdecl and stdcall need that ! }
  653. po_saveregisters, { save all registers }
  654. po_overload, { procedure is declared with overload directive }
  655. po_varargs, { printf like arguments }
  656. po_leftright, { push arguments from left to right }
  657. po_clearstack, { caller clears the stack }
  658. po_internconst, { procedure has constant evaluator intern }
  659. po_addressonly, { flag that only the address of a method is returned and not a full methodpointer }
  660. po_public { procedure is exported }
  661. );
  662. tprocoptions=set of tprocoption;
  663. function read_abstract_proc_def:tproccalloption;
  664. type
  665. tproccallopt=record
  666. mask : tproccalloption;
  667. str : string[30];
  668. end;
  669. tproctypeopt=record
  670. mask : tproctypeoption;
  671. str : string[30];
  672. end;
  673. tprocopt=record
  674. mask : tprocoption;
  675. str : string[30];
  676. end;
  677. const
  678. proccalloptionStr : array[tproccalloption] of string[14]=('',
  679. 'CDecl',
  680. 'CPPDecl',
  681. 'CompilerProc',
  682. 'Far16',
  683. 'FPCCall',
  684. 'Inline',
  685. 'InternProc',
  686. 'PalmOSSysCall',
  687. 'Pascal',
  688. 'Register',
  689. 'SafeCall',
  690. 'StdCall',
  691. 'System'
  692. );
  693. proctypeopts=6;
  694. proctypeopt : array[1..proctypeopts] of tproctypeopt=(
  695. (mask:potype_proginit; str:'ProgInit'),
  696. (mask:potype_unitinit; str:'UnitInit'),
  697. (mask:potype_unitfinalize;str:'UnitFinalize'),
  698. (mask:potype_constructor; str:'Constructor'),
  699. (mask:potype_destructor; str:'Destructor'),
  700. (mask:potype_operator; str:'Operator')
  701. );
  702. procopts=22;
  703. procopt : array[1..procopts] of tprocopt=(
  704. (mask:po_classmethod; str:'ClassMethod'),
  705. (mask:po_virtualmethod; str:'VirtualMethod'),
  706. (mask:po_abstractmethod; str:'AbstractMethod'),
  707. (mask:po_staticmethod; str:'StaticMethod'),
  708. (mask:po_overridingmethod;str:'OverridingMethod'),
  709. (mask:po_methodpointer; str:'MethodPointer'),
  710. (mask:po_interrupt; str:'Interrupt'),
  711. (mask:po_iocheck; str:'IOCheck'),
  712. (mask:po_assembler; str:'Assembler'),
  713. (mask:po_msgstr; str:'MsgStr'),
  714. (mask:po_msgint; str:'MsgInt'),
  715. (mask:po_exports; str:'Exports'),
  716. (mask:po_external; str:'External'),
  717. (mask:po_savestdregs; str:'SaveStdRegs'),
  718. (mask:po_saveregisters; str:'SaveRegisters'),
  719. (mask:po_overload; str:'Overload'),
  720. (mask:po_varargs; str:'VarArgs'),
  721. (mask:po_leftright; str:'LeftRight'),
  722. (mask:po_clearstack; str:'ClearStack'),
  723. (mask:po_internconst; str:'InternConst'),
  724. (mask:po_addressonly; str:'AddressOnly'),
  725. (mask:po_public; str:'Public')
  726. );
  727. var
  728. proctypeoption : tproctypeoption;
  729. proccalloption : tproccalloption;
  730. procoptions : tprocoptions;
  731. i,params : longint;
  732. first : boolean;
  733. begin
  734. write(space,' Return type : ');
  735. readtype;
  736. writeln(space,' Fpu used : ',ppufile.getbyte);
  737. proctypeoption:=tproctypeoption(ppufile.getbyte);
  738. if proctypeoption<>potype_none then
  739. begin
  740. write(space,' TypeOption : ');
  741. first:=true;
  742. for i:=1 to proctypeopts do
  743. if (proctypeopt[i].mask=proctypeoption) then
  744. begin
  745. if first then
  746. first:=false
  747. else
  748. write(', ');
  749. write(proctypeopt[i].str);
  750. end;
  751. writeln;
  752. end;
  753. proccalloption:=tproccalloption(ppufile.getbyte);
  754. read_abstract_proc_def:=proccalloption;
  755. writeln(space,' CallOption : ',proccalloptionStr[proccalloption]);
  756. ppufile.getsmallset(procoptions);
  757. if procoptions<>[] then
  758. begin
  759. write(space,' Options : ');
  760. first:=true;
  761. for i:=1to procopts do
  762. if (procopt[i].mask in procoptions) then
  763. begin
  764. if first then
  765. first:=false
  766. else
  767. write(', ');
  768. write(procopt[i].str);
  769. end;
  770. writeln;
  771. end;
  772. params:=ppufile.getbyte;
  773. writeln(space,' Nr of parameters : ',params);
  774. for i:=1 to params do
  775. begin
  776. writeln(space,' - Parameter ',i);
  777. writeln(space,' Spez : ',Varspez2Str(ppufile.getbyte));
  778. write (space,' Type : ');
  779. readtype;
  780. write (space,' Default : ');
  781. readderef;
  782. write (space,' Symbol : ');
  783. readderef;
  784. writeln(space,' Is Hidden : ',(ppufile.getbyte<>0));
  785. end;
  786. end;
  787. procedure readcommonsym(const s:string);
  788. begin
  789. writeln(space,'** Symbol Nr. ',ppufile.getword,' **');
  790. writeln(space,s,ppufile.getstring);
  791. write(space,' File Pos: ');
  792. readposinfo;
  793. write(space,' SymOptions: ');
  794. readsymoptions;
  795. end;
  796. procedure readcommondef(const s:string);
  797. type
  798. tdefoption=(df_none,
  799. df_has_inittable, { init data has been generated }
  800. df_has_rttitable, { rtti data has been generated }
  801. df_unique
  802. );
  803. tdefoptions=set of tdefoption;
  804. var
  805. defopts : tdefoptions;
  806. begin
  807. writeln(space,'** Definition Nr. ',ppufile.getword,' **');
  808. writeln(space,s);
  809. write (space,' Type symbol : ');
  810. readderef;
  811. ppufile.getsmallset(defopts);
  812. if df_unique in defopts then
  813. writeln (space,' Unique type symbol');
  814. if df_has_rttitable in defopts then
  815. begin
  816. write (space,' RTTI symbol : ');
  817. readderef;
  818. end;
  819. if df_has_inittable in defopts then
  820. begin
  821. write (space,' Init symbol : ');
  822. readderef;
  823. end;
  824. end;
  825. {****************************************************************************
  826. Read Symbols Part
  827. ****************************************************************************}
  828. procedure readsymbols;
  829. type
  830. { options for variables }
  831. tvaroption=(vo_none,
  832. vo_regable,
  833. vo_is_C_var,
  834. vo_is_external,
  835. vo_is_dll_var,
  836. vo_is_thread_var,
  837. vo_fpuregable,
  838. vo_is_local_copy,
  839. vo_is_const, { variable is declared as const (parameter) and can't be written to }
  840. vo_is_exported,
  841. vo_is_high_value
  842. );
  843. tvaroptions=set of tvaroption;
  844. pguid = ^tguid;
  845. tguid = packed record
  846. D1: LongWord;
  847. D2: Word;
  848. D3: Word;
  849. D4: array[0..7] of Byte;
  850. end;
  851. absolutetyp = (tovar,toasm,toaddr);
  852. tconsttyp = (constnone,
  853. constord,conststring,constreal,constbool,
  854. constint,constchar,constset,constpointer,constnil,
  855. constresourcestring,constwstring,constwchar,constguid
  856. );
  857. var
  858. b : byte;
  859. pc : pchar;
  860. totalsyms,
  861. symcnt,
  862. i,j,len : longint;
  863. guid : tguid;
  864. begin
  865. symcnt:=1;
  866. with ppufile do
  867. begin
  868. if space<>'' then
  869. Writeln(space,'-----------------------------');
  870. if readentry=ibstartsyms then
  871. begin
  872. totalsyms:=getlongint;
  873. Writeln(space,'Number of symbols : ',totalsyms);
  874. Writeln(space,'Symtable datasize : ',getlongint);
  875. Writeln(space,'Symtable alignment: ',getlongint);
  876. end
  877. else
  878. begin
  879. totalsyms:=-1;
  880. Writeln('!! ibstartsym not found');
  881. end;
  882. repeat
  883. b:=readentry;
  884. if not (b in [iberror,ibendsyms]) then
  885. inc(symcnt);
  886. case b of
  887. ibunitsym :
  888. readcommonsym('Unit symbol ');
  889. iblabelsym :
  890. readcommonsym('Label symbol ');
  891. ibtypesym :
  892. begin
  893. readcommonsym('Type symbol ');
  894. write(space,' Result Type: ');
  895. readtype;
  896. end;
  897. ibprocsym :
  898. begin
  899. readcommonsym('Procedure symbol ');
  900. len:=ppufile.getword;
  901. for i:=1 to len do
  902. begin
  903. write(space,' Definition: ');
  904. readderef;
  905. end;
  906. end;
  907. ibconstsym :
  908. begin
  909. readcommonsym('Constant symbol ');
  910. b:=getbyte;
  911. case tconsttyp(b) of
  912. constord :
  913. begin
  914. write (space,'OrdinalType: ');
  915. readtype;
  916. writeln (space,' Value: ',getlongint)
  917. end;
  918. constpointer :
  919. begin
  920. write (space,' Pointer Type: ');
  921. readtype;
  922. writeln (space,' Value: ',getlongint)
  923. end;
  924. conststring,
  925. constresourcestring :
  926. begin
  927. len:=getlongint;
  928. getmem(pc,len+1);
  929. getdata(pc^,len);
  930. writeln(space,' Length: ',len);
  931. writeln(space,' Value: "',pc,'"');
  932. freemem(pc,len+1);
  933. if tconsttyp(b)=constresourcestring then
  934. writeln(space,' Index: ',getlongint);
  935. end;
  936. constreal :
  937. writeln(space,' Value: ',getreal);
  938. constbool :
  939. if getlongint<>0 then
  940. writeln (space,' Value : True')
  941. else
  942. writeln (space,' Value: False');
  943. constint :
  944. writeln(space,' Value: ',getint64);
  945. constchar :
  946. writeln(space,' Value: "'+chr(getlongint)+'"');
  947. constset :
  948. begin
  949. write (space,' Set Type: ');
  950. readtype;
  951. for i:=1to 4 do
  952. begin
  953. write (space,' Value: ');
  954. for j:=1to 8 do
  955. begin
  956. if j>1 then
  957. write(',');
  958. write(hexb(getbyte));
  959. end;
  960. writeln;
  961. end;
  962. end;
  963. constwstring:
  964. begin
  965. end;
  966. constwchar:
  967. writeln(space,' Value: #',getlongint);
  968. constguid:
  969. begin
  970. getdata(guid,sizeof(guid));
  971. write (space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-');
  972. for i:=0 to 7 do
  973. begin
  974. write(hexstr(guid.d4[i],2));
  975. if i=1 then write('-');
  976. end;
  977. writeln('}');
  978. end
  979. else
  980. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  981. end;
  982. end;
  983. ibvarsym :
  984. begin
  985. readcommonsym('Variable symbol ');
  986. writeln(space,' Spez: ',Varspez2Str(getbyte));
  987. writeln(space,' Address: ',getlongint);
  988. write (space,' Var Type: ');
  989. readtype;
  990. i:=getlongint;
  991. writeln(space,' Options: ',i);
  992. if (vo_is_C_var in tvaroptions(i)) then
  993. writeln(space,' Mangledname: ',getstring);
  994. end;
  995. ibenumsym :
  996. begin
  997. readcommonsym('Enumeration symbol ');
  998. write (space,' Definition: ');
  999. readderef;
  1000. writeln(space,' Value: ',getlongint);
  1001. end;
  1002. ibsyssym :
  1003. begin
  1004. readcommonsym('Internal system symbol ');
  1005. writeln(space,' Internal Nr: ',getlongint);
  1006. end;
  1007. ibrttisym :
  1008. begin
  1009. readcommonsym('RTTI symbol ');
  1010. writeln(space,' RTTI Type: ',getbyte);
  1011. end;
  1012. ibtypedconstsym :
  1013. begin
  1014. readcommonsym('Typed constant ');
  1015. write (space,' Constant Type: ');
  1016. readtype;
  1017. writeln(space,' ReallyConst: ',(getbyte<>0));
  1018. end;
  1019. ibabsolutesym :
  1020. begin
  1021. readcommonsym('Absolute variable symbol ');
  1022. writeln(space,' Type: ',getbyte);
  1023. writeln(space,' Address: ',getlongint);
  1024. write (space,' Var Type: ');
  1025. readtype;
  1026. writeln(space,' Options: ',getlongint);
  1027. Write (space,' Relocated to ');
  1028. b:=getbyte;
  1029. case absolutetyp(b) of
  1030. tovar :
  1031. Writeln('Name : ',getstring);
  1032. toasm :
  1033. Writeln('Assembler name : ',getstring);
  1034. toaddr :
  1035. begin
  1036. Write('Address : ',getlongint);
  1037. WriteLn(' (Far: ',getbyte<>0,')');
  1038. end;
  1039. else
  1040. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  1041. end;
  1042. end;
  1043. ibpropertysym :
  1044. begin
  1045. readcommonsym('Property ');
  1046. i:=getlongint;
  1047. writeln(space,' PropOptions: ',i);
  1048. if (i and 32)>0 then
  1049. begin
  1050. write (space,'OverrideProp: ');
  1051. readderef;
  1052. end
  1053. else
  1054. begin
  1055. write (space,' Prop Type: ');
  1056. readtype;
  1057. writeln(space,' Index: ',getlongint);
  1058. writeln(space,' Default: ',getlongint);
  1059. write (space,' Index Type: ');
  1060. readtype;
  1061. write (space,' Readaccess: ');
  1062. readsymlist(space+' Sym: ');
  1063. write (space,' Writeaccess: ');
  1064. readsymlist(space+' Sym: ');
  1065. write (space,'Storedaccess: ');
  1066. readsymlist(space+' Sym: ');
  1067. end;
  1068. end;
  1069. iberror :
  1070. begin
  1071. Writeln('!! Error in PPU');
  1072. exit;
  1073. end;
  1074. ibendsyms :
  1075. break;
  1076. else
  1077. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  1078. end;
  1079. if not EndOfEntry then
  1080. Writeln('!! Entry has more information stored');
  1081. until false;
  1082. if (totalsyms<>-1) and (symcnt-1<>totalsyms) then
  1083. Writeln('!! Only read ',symcnt-1,' of ',totalsyms,' symbols');
  1084. end;
  1085. end;
  1086. {****************************************************************************
  1087. Read defintions Part
  1088. ****************************************************************************}
  1089. procedure readdefinitions(start_read : boolean);
  1090. type
  1091. tsettype = (normset,smallset,varset);
  1092. tbasetype = (
  1093. uvoid,
  1094. u8bit,u16bit,u32bit,u64bit,
  1095. s8bit,s16bit,s32bit,s64bit,
  1096. bool8bit,bool16bit,bool32bit,
  1097. uchar,uwidechar
  1098. );
  1099. tobjectdeftype = (odt_none,
  1100. odt_class,
  1101. odt_object,
  1102. odt_interfacecom,
  1103. odt_interfacecorba,
  1104. odt_cppclass
  1105. );
  1106. tvarianttype = (
  1107. vt_normalvariant,vt_olevariant
  1108. );
  1109. var
  1110. b : byte;
  1111. oldread_member : boolean;
  1112. totaldefs,l,j,
  1113. defcnt : longint;
  1114. calloption : tproccalloption;
  1115. begin
  1116. defcnt:=0;
  1117. with ppufile do
  1118. begin
  1119. if space<>'' then
  1120. Writeln(space,'-----------------------------');
  1121. if not start_read then
  1122. if readentry=ibstartdefs then
  1123. begin
  1124. totaldefs:=getlongint;
  1125. Writeln(space,'Number of definitions: ',totaldefs);
  1126. end
  1127. else
  1128. begin
  1129. totaldefs:=-1;
  1130. Writeln('!! ibstartdef not found');
  1131. end;
  1132. repeat
  1133. b:=readentry;
  1134. if not (b in [iberror,ibenddefs]) then
  1135. inc(defcnt);
  1136. case b of
  1137. ibpointerdef :
  1138. begin
  1139. readcommondef('Pointer definition');
  1140. write (space,' Pointed Type : ');
  1141. readtype;
  1142. writeln(space,' Is Far : ',(getbyte<>0));
  1143. end;
  1144. iborddef :
  1145. begin
  1146. readcommondef('Ordinal definition');
  1147. write (space,' Base type : ');
  1148. b:=getbyte;
  1149. case tbasetype(b) of
  1150. uvoid : writeln('uvoid');
  1151. u8bit : writeln('u8bit');
  1152. u16bit : writeln('u16bit');
  1153. u32bit : writeln('s32bit');
  1154. u64bit : writeln('u64bit');
  1155. s8bit : writeln('s8bit');
  1156. s16bit : writeln('s16bit');
  1157. s32bit : writeln('s32bit');
  1158. s64bit : writeln('s64bit');
  1159. bool8bit : writeln('bool8bit');
  1160. bool16bit : writeln('bool16bit');
  1161. bool32bit : writeln('bool32bit');
  1162. uchar : writeln('uchar');
  1163. uwidechar : writeln('uwidechar');
  1164. else writeln('!! Warning: Invalid base type ',b);
  1165. end;
  1166. writeln(space,' Range : ',getint64,' to ',getint64);
  1167. end;
  1168. ibfloatdef :
  1169. begin
  1170. readcommondef('Float definition');
  1171. writeln(space,' Float type : ',getbyte);
  1172. end;
  1173. ibarraydef :
  1174. begin
  1175. readcommondef('Array definition');
  1176. write (space,' Element type : ');
  1177. readtype;
  1178. write (space,' Range Type : ');
  1179. readtype;
  1180. writeln(space,' Range : ',getlongint,' to ',getlongint);
  1181. writeln(space,' Is Constructor : ',(getbyte<>0));
  1182. writeln(space,' Is Dynamic : ',(getbyte<>0));
  1183. end;
  1184. ibprocdef :
  1185. begin
  1186. readcommondef('Procedure definition');
  1187. calloption:=read_abstract_proc_def;
  1188. if (getbyte<>0) then
  1189. writeln(space,' Mangled name : ',getstring);
  1190. writeln(space,' Overload Number : ',getword);
  1191. writeln(space,' Number : ',getword);
  1192. write (space,' Class : ');
  1193. readderef;
  1194. write (space,' Procsym : ');
  1195. readderef;
  1196. write (space,' File Pos : ');
  1197. readposinfo;
  1198. write (space,' SymOptions : ');
  1199. readsymoptions;
  1200. if (calloption=pocall_inline) then
  1201. begin
  1202. write (space,' FuncretSym : ');
  1203. readderef;
  1204. end;
  1205. space:=' '+space;
  1206. { parast }
  1207. readdefinitions(false);
  1208. readsymbols;
  1209. { localst }
  1210. if (calloption=pocall_inline) or
  1211. ((ppufile.header.flags and uf_local_browser) <> 0) then
  1212. begin
  1213. readdefinitions(false);
  1214. readsymbols;
  1215. end;
  1216. delete(space,1,4);
  1217. end;
  1218. ibprocvardef :
  1219. begin
  1220. readcommondef('Procedural type (ProcVar) definition');
  1221. read_abstract_proc_def;
  1222. space:=' '+space;
  1223. { parast }
  1224. readdefinitions(false);
  1225. readsymbols;
  1226. delete(space,1,4);
  1227. end;
  1228. ibshortstringdef :
  1229. begin
  1230. readcommondef('ShortString definition');
  1231. writeln(space,' Length : ',getbyte);
  1232. end;
  1233. ibwidestringdef :
  1234. begin
  1235. readcommondef('WideString definition');
  1236. writeln(space,' Length : ',getlongint);
  1237. end;
  1238. ibansistringdef :
  1239. begin
  1240. readcommondef('AnsiString definition');
  1241. writeln(space,' Length : ',getlongint);
  1242. end;
  1243. iblongstringdef :
  1244. begin
  1245. readcommondef('Longstring definition');
  1246. writeln(space,' Length : ',getlongint);
  1247. end;
  1248. ibrecorddef :
  1249. begin
  1250. readcommondef('Record definition');
  1251. writeln(space,' Size : ',getlongint);
  1252. {read the record definitions and symbols}
  1253. space:=' '+space;
  1254. oldread_member:=read_member;
  1255. read_member:=true;
  1256. readdefinitions(false);
  1257. readsymbols;
  1258. read_member:=oldread_member;
  1259. Delete(space,1,4);
  1260. end;
  1261. ibobjectdef :
  1262. begin
  1263. readcommondef('Object/Class definition');
  1264. b:=getbyte;
  1265. write (space,' Type : ');
  1266. case tobjectdeftype(b) of
  1267. odt_class : writeln('class');
  1268. odt_object : writeln('object');
  1269. odt_interfacecom : writeln('interfacecom');
  1270. odt_interfacecorba : writeln('interfacecorba');
  1271. odt_cppclass : writeln('cppclass');
  1272. else writeln('!! Warning: Invalid object type ',b);
  1273. end;
  1274. writeln(space,' Size : ',getlongint);
  1275. writeln(space,' Vmt offset : ',getlongint);
  1276. writeln(space,' Name of Class : ',getstring);
  1277. write(space, ' Ancestor Class : ');
  1278. readderef;
  1279. writeln(space,' Options : ',getlongint);
  1280. if tobjectdeftype(b) in [odt_interfacecom,odt_interfacecorba] then
  1281. begin
  1282. { IIDGUID }
  1283. for j:=1to 16 do
  1284. getbyte;
  1285. writeln(space,' IID String : ',getstring);
  1286. writeln(space,' Last VTable idx : ',getlongint);
  1287. end;
  1288. if tobjectdeftype(b) in [odt_class,odt_interfacecorba] then
  1289. begin
  1290. l:=getlongint;
  1291. writeln(space,' Impl Intf Count : ',l);
  1292. for j:=1 to l do
  1293. begin
  1294. write (space,' - Definition : ');
  1295. readderef;
  1296. writeln(space,' IOffset : ',getlongint);
  1297. end;
  1298. end;
  1299. {read the record definitions and symbols}
  1300. space:=' '+space;
  1301. oldread_member:=read_member;
  1302. read_member:=true;
  1303. readdefinitions(false);
  1304. readsymbols;
  1305. read_member:=oldread_member;
  1306. Delete(space,1,4);
  1307. end;
  1308. ibfiledef :
  1309. begin
  1310. ReadCommonDef('File definition');
  1311. write (space,' Type : ');
  1312. case getbyte of
  1313. 0 : writeln('Text');
  1314. 1 : begin
  1315. writeln('Typed');
  1316. write (space,' File of Type : ');
  1317. Readtype;
  1318. end;
  1319. 2 : writeln('Untyped');
  1320. end;
  1321. end;
  1322. ibformaldef :
  1323. readcommondef('Generic Definition (void-typ)');
  1324. ibenumdef :
  1325. begin
  1326. readcommondef('Enumeration type definition');
  1327. write(space,'Base enumeration type : ');
  1328. readderef;
  1329. writeln(space,' Smallest element : ',getlongint);
  1330. writeln(space,' Largest element : ',getlongint);
  1331. writeln(space,' Size : ',getlongint);
  1332. end;
  1333. ibclassrefdef :
  1334. begin
  1335. readcommondef('Class reference definition');
  1336. write (space,' Pointed Type : ');
  1337. readtype;
  1338. end;
  1339. ibsetdef :
  1340. begin
  1341. readcommondef('Set definition');
  1342. write (space,' Element type : ');
  1343. readtype;
  1344. b:=getbyte;
  1345. case tsettype(b) of
  1346. smallset : writeln(space,' Set with 32 Elements');
  1347. normset : writeln(space,' Set with 256 Elements');
  1348. varset : writeln(space,' Set with ',getlongint,' Elements');
  1349. else writeln('!! Warning: Invalid set type ',b);
  1350. end;
  1351. end;
  1352. ibvariantdef :
  1353. begin
  1354. readcommondef('Variant definition');
  1355. write (space,' Varianttype : ');
  1356. b:=getbyte;
  1357. case tvarianttype(b) of
  1358. vt_normalvariant :
  1359. writeln('Normal');
  1360. vt_olevariant :
  1361. writeln('OLE');
  1362. else
  1363. writeln('!! Warning: Invalid varianttype ',b);
  1364. end;
  1365. end;
  1366. iberror :
  1367. begin
  1368. Writeln('!! Error in PPU');
  1369. exit;
  1370. end;
  1371. ibenddefs :
  1372. break;
  1373. else
  1374. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  1375. end;
  1376. if not EndOfEntry then
  1377. Writeln('!! Entry has more information stored');
  1378. until false;
  1379. if (totaldefs<>-1) and (defcnt<>totaldefs) then
  1380. Writeln('!! Only read ',defcnt,' of ',totaldefs,' definitions');
  1381. end;
  1382. end;
  1383. {****************************************************************************
  1384. Read General Part
  1385. ****************************************************************************}
  1386. procedure readinterface;
  1387. var
  1388. b : byte;
  1389. sourcenumber : longint;
  1390. begin
  1391. with ppufile do
  1392. begin
  1393. repeat
  1394. b:=readentry;
  1395. case b of
  1396. ibmodulename :
  1397. Writeln('Module Name: ',getstring);
  1398. ibsourcefiles :
  1399. begin
  1400. sourcenumber:=1;
  1401. while not EndOfEntry do
  1402. begin
  1403. Writeln('Source file ',sourcenumber,' : ',getstring,' ',filetimestring(getlongint));
  1404. inc(sourcenumber);
  1405. end;
  1406. end;
  1407. ibusedmacros :
  1408. begin
  1409. while not EndOfEntry do
  1410. begin
  1411. Write('Conditional ',getstring);
  1412. b:=getbyte;
  1413. if boolean(b)=true then
  1414. write(' defined at startup')
  1415. else
  1416. write(' not defined at startup');
  1417. b:=getbyte;
  1418. if boolean(b)=true then
  1419. writeln(' was used')
  1420. else
  1421. writeln;
  1422. end;
  1423. end;
  1424. ibloadunit :
  1425. ReadLoadUnit;
  1426. iblinkunitofiles :
  1427. ReadLinkContainer('Link unit object file: ');
  1428. iblinkunitstaticlibs :
  1429. ReadLinkContainer('Link unit static lib: ');
  1430. iblinkunitsharedlibs :
  1431. ReadLinkContainer('Link unit shared lib: ');
  1432. iblinkotherofiles :
  1433. ReadLinkContainer('Link other object file: ');
  1434. iblinkotherstaticlibs :
  1435. ReadLinkContainer('Link other static lib: ');
  1436. iblinkothersharedlibs :
  1437. ReadLinkContainer('Link other shared lib: ');
  1438. ibderefdata :
  1439. ReadDerefData;
  1440. iberror :
  1441. begin
  1442. Writeln('Error in PPU');
  1443. exit;
  1444. end;
  1445. ibendinterface :
  1446. break;
  1447. else
  1448. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  1449. end;
  1450. until false;
  1451. end;
  1452. end;
  1453. {****************************************************************************
  1454. Read Implementation Part
  1455. ****************************************************************************}
  1456. procedure readimplementation;
  1457. var
  1458. b : byte;
  1459. begin
  1460. with ppufile do
  1461. begin
  1462. repeat
  1463. b:=readentry;
  1464. case b of
  1465. ibasmsymbols :
  1466. ReadAsmSymbols;
  1467. ibloadunit :
  1468. ReadLoadUnit;
  1469. iberror :
  1470. begin
  1471. Writeln('Error in PPU');
  1472. exit;
  1473. end;
  1474. ibendimplementation :
  1475. break;
  1476. else
  1477. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  1478. end;
  1479. until false;
  1480. end;
  1481. end;
  1482. {****************************************************************************
  1483. Read Browser Part
  1484. ****************************************************************************}
  1485. procedure readbrowser;
  1486. var
  1487. b : byte;
  1488. const indent : string = '';
  1489. begin
  1490. Writeln(indent,'Start of symtable browser');
  1491. indent:=indent+'**';
  1492. with ppufile do
  1493. begin
  1494. repeat
  1495. b:=readentry;
  1496. case b of
  1497. ibbeginsymtablebrowser :
  1498. begin
  1499. { here we must read object and record symtables !! }
  1500. indent:=indent+' ';
  1501. Writeln(indent,'Record/Object symtable');
  1502. readbrowser;
  1503. Indent:=Copy(Indent,1,Length(Indent)-2);
  1504. end;
  1505. ibsymref :
  1506. begin
  1507. readderef;
  1508. readref;
  1509. end;
  1510. ibdefref :
  1511. begin
  1512. readderef;
  1513. readref;
  1514. if ((ppufile.header.flags and uf_local_browser)<>0) and
  1515. (UnitIndex=0) then
  1516. begin
  1517. { parast and localst }
  1518. indent:=indent+' ';
  1519. b:=ppufile.readentry;
  1520. if b=ibbeginsymtablebrowser then
  1521. readbrowser;
  1522. b:=ppufile.readentry;
  1523. if b=ibbeginsymtablebrowser then
  1524. readbrowser;
  1525. Indent:=Copy(Indent,1,Length(Indent)-2);
  1526. end;
  1527. end;
  1528. iberror :
  1529. begin
  1530. Writeln('Error in PPU');
  1531. exit;
  1532. end;
  1533. ibendsymtablebrowser :
  1534. break;
  1535. else
  1536. begin
  1537. WriteLn('!! Skipping unsupported PPU Entry in Browser: ',b);
  1538. Halt;
  1539. end;
  1540. end;
  1541. until false;
  1542. end;
  1543. Indent:=Copy(Indent,1,Length(Indent)-2);
  1544. Writeln(Indent,'End of symtable browser');
  1545. end;
  1546. procedure dofile (filename : string);
  1547. var
  1548. b : byte;
  1549. begin
  1550. { reset }
  1551. space:='';
  1552. { fix filename }
  1553. if pos('.',filename)=0 then
  1554. filename:=filename+'.ppu';
  1555. ppufile:=tppufile.create(filename);
  1556. if not ppufile.openfile then
  1557. begin
  1558. writeln ('IO-Error when opening : ',filename,', Skipping');
  1559. exit;
  1560. end;
  1561. { PPU File is open, check for PPU Id }
  1562. if not ppufile.CheckPPUID then
  1563. begin
  1564. writeln(Filename,' : Not a valid PPU file, Skipping');
  1565. exit;
  1566. end;
  1567. { Check PPU Version }
  1568. Writeln('Analyzing ',filename,' (v',ppufile.GetPPUVersion,')');
  1569. if ppufile.GetPPUVersion<16 then
  1570. begin
  1571. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  1572. exit;
  1573. end;
  1574. { Write PPU Header Information }
  1575. if (verbose and v_header)<>0 then
  1576. begin
  1577. Writeln;
  1578. Writeln('Header');
  1579. Writeln('-------');
  1580. with ppufile.header do
  1581. begin
  1582. Writeln('Compiler version : ',ppufile.header.compiler shr 14,'.',
  1583. (ppufile.header.compiler shr 7) and $7f,'.',
  1584. ppufile.header.compiler and $7f);
  1585. WriteLn('Target processor : ',Cpu2Str(cpu));
  1586. WriteLn('Target operating system : ',Target2Str(target));
  1587. Writeln('Unit flags : ',PPUFlags2Str(flags));
  1588. Writeln('FileSize (w/o header) : ',size);
  1589. Writeln('Checksum : ',hexstr(checksum,8));
  1590. Writeln('Interface Checksum : ',hexstr(interface_checksum,8));
  1591. end;
  1592. end;
  1593. {read the general stuff}
  1594. if (verbose and v_interface)<>0 then
  1595. begin
  1596. Writeln;
  1597. Writeln('Interface section');
  1598. Writeln('------------------');
  1599. readinterface;
  1600. end
  1601. else
  1602. ppufile.skipuntilentry(ibendinterface);
  1603. {read the definitions}
  1604. if (verbose and v_defs)<>0 then
  1605. begin
  1606. Writeln;
  1607. Writeln('Interface definitions');
  1608. Writeln('----------------------');
  1609. readdefinitions(false);
  1610. end
  1611. else
  1612. ppufile.skipuntilentry(ibenddefs);
  1613. {read the symbols}
  1614. if (verbose and v_syms)<>0 then
  1615. begin
  1616. Writeln;
  1617. Writeln('Interface Symbols');
  1618. Writeln('------------------');
  1619. readsymbols;
  1620. end
  1621. else
  1622. ppufile.skipuntilentry(ibendsyms);
  1623. {read the implementation stuff}
  1624. if (verbose and v_implementation)<>0 then
  1625. begin
  1626. Writeln;
  1627. Writeln('Implementation section');
  1628. Writeln('-----------------------');
  1629. readimplementation;
  1630. end
  1631. else
  1632. ppufile.skipuntilentry(ibendimplementation);
  1633. {read the static browser units stuff}
  1634. if (ppufile.header.flags and uf_local_browser)<>0 then
  1635. begin
  1636. if (verbose and v_defs)<>0 then
  1637. begin
  1638. Writeln;
  1639. Writeln('Static definitions');
  1640. Writeln('----------------------');
  1641. readdefinitions(false);
  1642. end
  1643. else
  1644. ppufile.skipuntilentry(ibenddefs);
  1645. {read the symbols}
  1646. if (verbose and v_syms)<>0 then
  1647. begin
  1648. Writeln;
  1649. Writeln('Static Symbols');
  1650. Writeln('------------------');
  1651. readsymbols;
  1652. end;
  1653. end;
  1654. {read the browser units stuff}
  1655. if (ppufile.header.flags and uf_has_browser)<>0 then
  1656. begin
  1657. if (verbose and v_browser)<>0 then
  1658. begin
  1659. Writeln;
  1660. Writeln('Browser section');
  1661. Writeln('---------------');
  1662. UnitIndex:=0;
  1663. repeat
  1664. b:=ppufile.readentry;
  1665. if b = ibendbrowser then break;
  1666. if b=ibbeginsymtablebrowser then
  1667. begin
  1668. Writeln('Unit ',UnitIndex);
  1669. readbrowser;
  1670. Inc(UnitIndex);
  1671. end
  1672. else
  1673. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  1674. until false;
  1675. end;
  1676. end;
  1677. {read the static browser units stuff}
  1678. if (ppufile.header.flags and uf_local_browser)<>0 then
  1679. begin
  1680. if (verbose and v_browser)<>0 then
  1681. begin
  1682. Writeln;
  1683. Writeln('Static browser section');
  1684. Writeln('---------------');
  1685. UnitIndex:=0;
  1686. b:=ppufile.readentry;
  1687. if b=ibbeginsymtablebrowser then
  1688. readbrowser
  1689. else
  1690. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  1691. end;
  1692. end;
  1693. {shutdown ppufile}
  1694. ppufile.closefile;
  1695. ppufile.free;
  1696. Writeln;
  1697. end;
  1698. procedure help;
  1699. begin
  1700. writeln('usage: ppudump [options] <filename1> <filename2>...');
  1701. writeln;
  1702. writeln('[options] can be:');
  1703. writeln(' -V<verbose> Set verbosity to <verbose>');
  1704. writeln(' H - Show header info');
  1705. writeln(' I - Show interface');
  1706. writeln(' M - Show implementation');
  1707. writeln(' S - Show interface symbols');
  1708. writeln(' D - Show interface definitions');
  1709. writeln(' B - Show browser info');
  1710. writeln(' A - Show all');
  1711. writeln(' -? This helpscreen');
  1712. halt;
  1713. end;
  1714. var
  1715. startpara,
  1716. nrfile,i : longint;
  1717. para : string;
  1718. begin
  1719. writeln(Title+' '+Version);
  1720. writeln(Copyright);
  1721. writeln;
  1722. if paramcount<1 then
  1723. begin
  1724. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  1725. halt(1);
  1726. end;
  1727. { turn verbose on by default }
  1728. verbose:=v_all;
  1729. { read options }
  1730. startpara:=1;
  1731. while copy(paramstr(startpara),1,1)='-' do
  1732. begin
  1733. para:=paramstr(startpara);
  1734. case upcase(para[2]) of
  1735. 'V' : begin
  1736. verbose:=0;
  1737. for i:=3to length(para) do
  1738. case upcase(para[i]) of
  1739. 'H' : verbose:=verbose or v_header;
  1740. 'I' : verbose:=verbose or v_interface;
  1741. 'M' : verbose:=verbose or v_implementation;
  1742. 'D' : verbose:=verbose or v_defs;
  1743. 'S' : verbose:=verbose or v_syms;
  1744. 'B' : verbose:=verbose or v_browser;
  1745. 'A' : verbose:=verbose or v_all;
  1746. end;
  1747. end;
  1748. '?' : help;
  1749. end;
  1750. inc(startpara);
  1751. end;
  1752. { process files }
  1753. for nrfile:=startpara to paramcount do
  1754. dofile (paramstr(nrfile));
  1755. if has_errors then
  1756. Halt(1);
  1757. end.
  1758. {
  1759. $Log$
  1760. Revision 1.47 2003-10-22 20:40:00 peter
  1761. * write derefdata in a separate ppu entry
  1762. Revision 1.46 2003/07/02 22:18:04 peter
  1763. * paraloc splitted in callerparaloc,calleeparaloc
  1764. * sparc calling convention updates
  1765. Revision 1.45 2003/06/25 18:31:23 peter
  1766. * sym,def resolving partly rewritten to support also parent objects
  1767. not directly available through the uses clause
  1768. Revision 1.44 2003/06/09 12:59:00 peter
  1769. * updated for new deref info
  1770. Revision 1.43 2003/06/05 20:06:11 peter
  1771. * new procoptions
  1772. Revision 1.42 2003/05/09 17:47:03 peter
  1773. * self moved to hidden parameter
  1774. * removed hdisposen,hnewn,selfn
  1775. Revision 1.41 2003/04/27 07:29:52 peter
  1776. * aktprocdef cleanup, aktprocdef is now always nil when parsing
  1777. a new procdef declaration
  1778. * aktprocsym removed
  1779. * lexlevel removed, use symtable.symtablelevel instead
  1780. * implicit init/final code uses the normal genentry/genexit
  1781. * funcret state checking updated for new funcret handling
  1782. Revision 1.39 2003/04/25 20:59:35 peter
  1783. * removed funcretn,funcretsym, function result is now in varsym
  1784. and aliases for result and function name are added using absolutesym
  1785. * vs_hidden parameter for funcret passed in parameter
  1786. * vs_hidden fixes
  1787. * writenode changed to printnode and released from extdebug
  1788. * -vp option added to generate a tree.log with the nodetree
  1789. * nicer printnode for statements, callnode
  1790. Revision 1.38 2003/04/10 17:57:53 peter
  1791. * vs_hidden released
  1792. Revision 1.37 2003/03/24 19:57:54 hajny
  1793. + emx target added
  1794. Revision 1.36 2003/03/17 15:54:22 peter
  1795. * store symoptions also for procdef
  1796. * check symoptions (private,public) when calculating possible
  1797. overload candidates
  1798. Revision 1.35 2003/01/03 22:16:29 peter
  1799. * updated for absolutesym and varsym
  1800. Revision 1.34 2002/11/17 16:32:04 carl
  1801. * memory optimization (3-4%) : cleanup of tai fields,
  1802. cleanup of tdef and tsym fields.
  1803. * make it work for m68k
  1804. Revision 1.33 2002/10/20 14:49:31 peter
  1805. * store original source time in ppu so it can be compared instead of
  1806. comparing with the ppu time
  1807. Revision 1.32 2002/10/06 12:25:53 florian
  1808. + dump of tdefoptions.df_unique
  1809. Revision 1.31 2002/09/27 21:22:04 carl
  1810. * update system information
  1811. Revision 1.30 2002/09/26 12:03:54 florian
  1812. + support of constguid and constwchar const symbols added
  1813. Revision 1.29 2002/08/20 16:54:40 peter
  1814. * write address of varsym always
  1815. Revision 1.28 2002/08/19 19:36:44 peter
  1816. * More fixes for cross unit inlining, all tnodes are now implemented
  1817. * Moved pocall_internconst to po_internconst because it is not a
  1818. calling type at all and it conflicted when inlining of these small
  1819. functions was requested
  1820. Revision 1.27 2002/08/15 15:15:56 carl
  1821. * jmpbuf size allocation for exceptions is now cpu specific (as it should)
  1822. * more generic nodes for maths
  1823. * several fixes for better m68k support
  1824. Revision 1.26 2002/08/11 13:24:20 peter
  1825. * saving of asmsymbols in ppu supported
  1826. * asmsymbollist global is removed and moved into a new class
  1827. tasmlibrarydata that will hold the info of a .a file which
  1828. corresponds with a single module. Added librarydata to tmodule
  1829. to keep the library info stored for the module. In the future the
  1830. objectfiles will also be stored to the tasmlibrarydata class
  1831. * all getlabel/newasmsymbol and friends are moved to the new class
  1832. Revision 1.25 2002/05/18 13:34:27 peter
  1833. * readded missing revisions
  1834. Revision 1.24 2002/05/16 19:46:54 carl
  1835. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1836. + try to fix temp allocation (still in ifdef)
  1837. + generic constructor calls
  1838. + start of tassembler / tmodulebase class cleanup
  1839. Revision 1.22 2002/05/12 16:53:18 peter
  1840. * moved entry and exitcode to ncgutil and cgobj
  1841. * foreach gets extra argument for passing local data to the
  1842. iterator function
  1843. * -CR checks also class typecasts at runtime by changing them
  1844. into as
  1845. * fixed compiler to cycle with the -CR option
  1846. * fixed stabs with elf writer, finally the global variables can
  1847. be watched
  1848. * removed a lot of routines from cga unit and replaced them by
  1849. calls to cgobj
  1850. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1851. u32bit then the other is typecasted also to u32bit without giving
  1852. a rangecheck warning/error.
  1853. * fixed pascal calling method with reversing also the high tree in
  1854. the parast, detected by tcalcst3 test
  1855. Revision 1.21 2002/04/23 13:12:58 peter
  1856. * updated for posinfo change
  1857. * updated for mangledname change
  1858. * include i386 registers, removed reference to cpubase unit that would
  1859. make ppudump dependent on the source processor
  1860. Revision 1.20 2002/04/15 19:15:09 carl
  1861. + write std_reg2str instead of gas registers
  1862. Revision 1.19 2002/04/14 17:02:19 carl
  1863. + att_reg2str -> gas_reg2str
  1864. Revision 1.18 2002/04/07 10:23:36 carl
  1865. + added vm / sparc targets
  1866. Revision 1.17 2002/04/04 19:06:14 peter
  1867. * removed unused units
  1868. * use tlocation.size in cg.a_*loc*() routines
  1869. Revision 1.16 2002/04/04 18:50:27 carl
  1870. + added wdosx support (patch from Pavel)
  1871. Revision 1.15 2002/03/31 20:26:42 jonas
  1872. + a_loadfpu_* and a_loadmm_* methods in tcg
  1873. * register allocation is now handled by a class and is mostly processor
  1874. independent (+rgobj.pas and i386/rgcpu.pas)
  1875. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  1876. * some small improvements and fixes to the optimizer
  1877. * some register allocation fixes
  1878. * some fpuvaroffset fixes in the unary minus node
  1879. * push/popusedregisters is now called rg.save/restoreusedregisters and
  1880. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  1881. also better optimizable)
  1882. * fixed and optimized register saving/restoring for new/dispose nodes
  1883. * LOC_FPU locations now also require their "register" field to be set to
  1884. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  1885. - list field removed of the tnode class because it's not used currently
  1886. and can cause hard-to-find bugs
  1887. Revision 1.14 2002/03/28 20:48:52 carl
  1888. - remove go32v1 support
  1889. Revision 1.13 2002/03/28 16:44:59 armin
  1890. + new flag if unit has local threadvars
  1891. Revision 1.12 2002/03/01 14:08:47 peter
  1892. * parasym added
  1893. Revision 1.11 2002/01/06 12:08:16 peter
  1894. * removed uauto from orddef, use new range_to_basetype generating
  1895. the correct ordinal type for a range
  1896. }