symify.pp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 GDBInt;
  12. var
  13. gdb : tgdbinterface;
  14. procedure processlog(const fn:string);
  15. var
  16. t : text;
  17. hs,s : string;
  18. code : word;
  19. i,
  20. addr : longint;
  21. sym : tsyminfo;
  22. begin
  23. assign(t,fn);
  24. {$I-}
  25. reset(t);
  26. {$I+}
  27. if ioresult<>0 then
  28. exit;
  29. while not eof(t) do
  30. begin
  31. readln(t,s);
  32. i:=pos('0x',s);
  33. if i=3 then
  34. begin
  35. hs:='$'+Copy(s,5,8);
  36. Val(hs,addr,code);
  37. if code=0 then
  38. begin
  39. gdb.GetAddrSymInfo(addr,sym);
  40. Write(Copy(s,1,12));
  41. if assigned(sym.funcname) then
  42. write(' in ',sym.funcname,'+',sym.offset);
  43. if assigned(sym.fname) then
  44. writeln(' ',sym.fname,':',sym.line)
  45. else
  46. writeln;
  47. end
  48. else
  49. writeln(s);
  50. end
  51. else
  52. writeln(s);
  53. end;
  54. close(t);
  55. end;
  56. begin
  57. if paramcount<2 then
  58. begin
  59. writeln('usage: symify <log> <file>');
  60. halt(1);
  61. end;
  62. gdb.init;
  63. writeln('loading ',paramstr(2));
  64. gdb.gdb_command('file '+paramstr(2));
  65. writeln('parsing ',paramstr(1));
  66. processlog(paramstr(1));
  67. gdb.done;
  68. end.