ppheap.pas 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 fpcdefs.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. type
  29. pextra_info = ^textra_info;
  30. textra_info = record
  31. line,
  32. col,
  33. fileindex : longint;
  34. end;
  35. procedure set_extra_info(p : pointer);
  36. begin
  37. with pextra_info(p)^ do
  38. begin
  39. line:=aktfilepos.line;
  40. col:=aktfilepos.column;
  41. if assigned(current_module) then
  42. fileindex:=current_module.unit_index*100000+aktfilepos.fileindex
  43. else
  44. fileindex:=aktfilepos.fileindex;
  45. end;
  46. end;
  47. procedure show_extra_info(var t : text;p : pointer);
  48. begin
  49. with pextra_info(p)^ do
  50. begin
  51. writeln(t,'fileinfo: (',line,',',col,') ',fileindex);
  52. end;
  53. end;
  54. const
  55. pp_heap_inited : boolean = false;
  56. procedure pp_heap_init;
  57. begin
  58. if not pp_heap_inited then
  59. begin
  60. keepreleased:=true;
  61. SetHeapTraceOutput('heap.log');
  62. SetHeapExtraInfo(sizeof(textra_info),
  63. {$ifdef FPCPROCVAR}@{$endif}set_extra_info,
  64. {$ifdef FPCPROCVAR}@{$endif}show_extra_info);
  65. end;
  66. pp_heap_inited:=true;
  67. end;
  68. begin
  69. pp_heap_init;
  70. end.
  71. {
  72. $Log$
  73. Revision 1.9 2002-05-16 19:46:43 carl
  74. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  75. + try to fix temp allocation (still in ifdef)
  76. + generic constructor calls
  77. + start of tassembler / tmodulebase class cleanup
  78. Revision 1.7 2001/04/13 01:22:13 peter
  79. * symtable change to classes
  80. * range check generation and errors fixed, make cycle DEBUG=1 works
  81. * memory leaks fixed
  82. Revision 1.5 2001/03/13 18:43:17 peter
  83. * made memdebug and heaptrc compilable again
  84. Revision 1.4 2000/10/14 21:52:56 peter
  85. * fixed memory leaks
  86. Revision 1.3 2000/09/24 15:06:24 peter
  87. * use defines.inc
  88. Revision 1.2 2000/07/13 11:32:45 michael
  89. + removed logs
  90. }