ppudump.pp 59 KB

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