symify.pp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. {
  2. Copyright (c) 1998 by Peter Vreman
  3. Translate backtrace addresses into file and line info
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. program symify;
  11. uses
  12. {$ifdef USE_MINGW_GDB}
  13. mingw,
  14. {$endif}
  15. GDBInt;
  16. var
  17. gdb : tgdbinterface;
  18. procedure processlog(const fn:string);
  19. var
  20. t : text;
  21. hs,s : string;
  22. code : word;
  23. i,
  24. addr : longint;
  25. sym : tsyminfo;
  26. begin
  27. assign(t,fn);
  28. {$push}{$I-}
  29. reset(t);
  30. {$pop}
  31. if ioresult<>0 then
  32. exit;
  33. while not eof(t) do
  34. begin
  35. readln(t,s);
  36. i:=pos('0x',s);
  37. if i=3 then
  38. begin
  39. hs:='$'+Copy(s,5,8);
  40. Val(hs,addr,code);
  41. if code=0 then
  42. begin
  43. gdb.GetAddrSymInfo(addr,sym);
  44. Write(Copy(s,1,12));
  45. if assigned(sym.funcname) then
  46. write(' in ',sym.funcname,'+',sym.offset);
  47. if assigned(sym.fname) then
  48. writeln(' ',sym.fname,':',sym.line)
  49. else
  50. writeln;
  51. end
  52. else
  53. writeln(s);
  54. end
  55. else
  56. writeln(s);
  57. end;
  58. close(t);
  59. end;
  60. begin
  61. if paramcount<2 then
  62. begin
  63. writeln('usage: symify <log> <file>');
  64. halt(1);
  65. end;
  66. gdb.init;
  67. writeln('loading ',paramstr(2));
  68. gdb.gdb_command('file '+paramstr(2));
  69. writeln('parsing ',paramstr(1));
  70. processlog(paramstr(1));
  71. gdb.done;
  72. end.