ppheap.pas 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 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.10 2002-05-18 13:34:13 peter
  74. * readded missing revisions
  75. Revision 1.9 2002/05/16 19:46:43 carl
  76. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  77. + try to fix temp allocation (still in ifdef)
  78. + generic constructor calls
  79. + start of tassembler / tmodulebase class cleanup
  80. }