ppudump.pp 58 KB

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