ppheap.pas 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Pierre Muller
  4. Simple unit to add source line and column to each
  5. memory allocation made with heaptrc unit
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************}
  18. unit ppheap;
  19. {$i defines.inc}
  20. interface
  21. uses heaptrc;
  22. { call this function before any memory allocation
  23. in a unit initialization code (PM) }
  24. procedure pp_heap_init;
  25. implementation
  26. uses
  27. globtype,globals,fmodule;
  28. procedure ppextra_info(p : pointer);
  29. var pl : plongint;
  30. begin
  31. longint(p^):=aktfilepos.line;
  32. pl:=plongint(cardinal(p)+4);
  33. pl^:=aktfilepos.column;
  34. pl:=plongint(cardinal(p)+8);
  35. if assigned(current_module) then
  36. pl^:=current_module^.unit_index*100000+aktfilepos.fileindex
  37. else
  38. pl^:=aktfilepos.fileindex
  39. end;
  40. const
  41. pp_heap_inited : boolean = false;
  42. procedure pp_heap_init;
  43. begin
  44. if not pp_heap_inited then
  45. begin
  46. setheaptraceoutput('heap.log');
  47. SetExtraInfo(12,{$ifdef FPCPROCVAR}@{$endif}ppextra_info);
  48. end;
  49. pp_heap_inited:=true;
  50. end;
  51. begin
  52. pp_heap_init;
  53. end.
  54. {
  55. $Log$
  56. Revision 1.4 2000-10-14 21:52:56 peter
  57. * fixed memory leaks
  58. Revision 1.3 2000/09/24 15:06:24 peter
  59. * use defines.inc
  60. Revision 1.2 2000/07/13 11:32:45 michael
  61. + removed logs
  62. }