]>
git.ipfire.org Git - thirdparty/bash.git/blob - lib/malloc/watch.c
6594a3f8eafd34d379faeb832bd7b5361e6b0adb
1 /* watch.c - watchpoint functions for malloc */
3 /* Copyright (C) 2001 Free Software Foundation, Inc.
5 This file is part of GNU Bash, the Bourne Again SHell.
7 Bash is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License along
18 with Bash; see the file COPYING. If not, write to the Free Software
19 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
34 static PTR_T _malloc_watch_list
[WATCH_MAX
];
37 watch_warn (addr
, file
, line
, type
, data
)
47 else if (type
== W_FREE
)
49 else if (type
== W_REALLOC
)
50 tag
= "requesting resize";
51 else if (type
== W_RESIZED
)
54 tag
= "bug: unknown operation";
56 fprintf (stderr
, "malloc: watch alert: %p %s ", addr
, tag
);
57 if (data
!= (unsigned long)-1)
58 fprintf (stderr
, "(size %lu) ", data
);
59 fprintf (stderr
, "from '%s:%d'\n", file
? file
: "unknown", line
);
63 _malloc_ckwatch (addr
, file
, line
, type
, data
)
71 for (i
= _malloc_nwatch
- 1; i
>= 0; i
--)
73 if (_malloc_watch_list
[i
] == addr
)
75 watch_warn (addr
, file
, line
, type
, data
);
80 #endif /* MALLOC_WATCH */
94 for (i
= _malloc_nwatch
- 1; i
>= 0; i
--)
96 if (_malloc_watch_list
[i
] == addr
)
101 if (_malloc_nwatch
== WATCH_MAX
) /* full, take out first */
103 ret
= _malloc_watch_list
[0];
105 for (i
= 0; i
< _malloc_nwatch
; i
++)
106 _malloc_watch_list
[i
] = _malloc_watch_list
[i
+1];
108 _malloc_watch_list
[_malloc_nwatch
++] = addr
;
115 /* Remove a watchpoint set on ADDR. If ADDR is NULL, remove all
116 watchpoints. Returns ADDR if everything went OK, NULL if ADDR was
117 not being watched. */
119 malloc_unwatch (addr
)
127 for (i
= 0; i
< _malloc_nwatch
; i
++)
128 _malloc_watch_list
[i
] = (PTR_T
)0;
134 for (i
= 0; i
< _malloc_nwatch
; i
++)
136 if (_malloc_watch_list
[i
] == addr
)
139 if (i
== _malloc_nwatch
)
140 return ((PTR_T
)0); /* not found */
141 /* shuffle everything from i+1 to end down 1 */
143 for ( ; i
< _malloc_nwatch
; i
++)
144 _malloc_watch_list
[i
] = _malloc_watch_list
[i
+1];