summaryrefslogtreecommitdiff
path: root/Zend/zend_alloc.c
diff options
context:
space:
mode:
authorZeev Suraski <zeev@php.net>1999-08-28 10:18:54 +0000
committerZeev Suraski <zeev@php.net>1999-08-28 10:18:54 +0000
commitcda27ae9acadf46ace265f5e53900680a21c65f8 (patch)
tree20e3a718538b510def12bea41d0ee5d7e7dd5f17 /Zend/zend_alloc.c
parent023cb6474bb81f64d607acb36302362c01b8fe4f (diff)
downloadphp-git-cda27ae9acadf46ace265f5e53900680a21c65f8.tar.gz
Beef up debug macros
Diffstat (limited to 'Zend/zend_alloc.c')
-rw-r--r--Zend/zend_alloc.c63
1 files changed, 27 insertions, 36 deletions
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c
index 7992c4c93e..1f78882cc3 100644
--- a/Zend/zend_alloc.c
+++ b/Zend/zend_alloc.c
@@ -97,7 +97,7 @@ static zend_alloc_globals alloc_globals;
-ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC)
+ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
{
mem_header *p;
ALS_FETCH();
@@ -109,6 +109,8 @@ ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC)
#if ZEND_DEBUG
p->filename = __zend_filename;
p->lineno = __zend_lineno;
+ p->orig_filename = __zend_orig_filename;
+ p->orig_lineno = __zend_orig_lineno;
p->magic = MEM_BLOCK_START_MAGIC;
p->reported = 0;
#endif
@@ -136,6 +138,8 @@ ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC)
#if ZEND_DEBUG
p->filename = __zend_filename;
p->lineno = __zend_lineno;
+ p->orig_filename = __zend_orig_filename;
+ p->orig_lineno = __zend_orig_lineno;
p->magic = MEM_BLOCK_START_MAGIC;
p->reported = 0;
*((long *)(((char *) p) + sizeof(mem_header)+size+PLATFORM_PADDING+END_ALIGNMENT(size))) = MEM_BLOCK_END_MAGIC;
@@ -148,13 +152,13 @@ ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC)
}
-ZEND_API void _efree(void *ptr ZEND_FILE_LINE_DC)
+ZEND_API void _efree(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
{
mem_header *p = (mem_header *) ((char *)ptr - sizeof(mem_header) - PLATFORM_PADDING);
ALS_FETCH();
#if ZEND_DEBUG
- if (!_mem_block_check(ptr, 1 ZEND_FILE_LINE_RELAY_CC)) {
+ if (!_mem_block_check(ptr, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC)) {
return;
}
memset(ptr, 0x5a, p->size);
@@ -180,17 +184,13 @@ ZEND_API void _efree(void *ptr ZEND_FILE_LINE_DC)
}
-ZEND_API void *_ecalloc(size_t nmemb, size_t size ZEND_FILE_LINE_DC)
+ZEND_API void *_ecalloc(size_t nmemb, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
{
void *p;
int final_size=size*nmemb;
HANDLE_BLOCK_INTERRUPTIONS();
-#if ZEND_DEBUG
- p = _emalloc(final_size ZEND_FILE_LINE_RELAY_CC);
-#else
- p = emalloc(final_size);
-#endif
+ p = _emalloc(final_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
if (!p) {
HANDLE_UNBLOCK_INTERRUPTIONS();
return (void *) p;
@@ -201,18 +201,14 @@ ZEND_API void *_ecalloc(size_t nmemb, size_t size ZEND_FILE_LINE_DC)
}
-ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LINE_DC)
+ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
{
mem_header *p = (mem_header *) ((char *)ptr-sizeof(mem_header)-PLATFORM_PADDING);
mem_header *orig = p;
ALS_FETCH();
if (!ptr) {
-#if ZEND_DEBUG
- return _emalloc(size ZEND_FILE_LINE_RELAY_CC);
-#else
- return emalloc(size);
-#endif
+ return _emalloc(size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
}
HANDLE_BLOCK_INTERRUPTIONS();
REMOVE_POINTER_FROM_LIST(p);
@@ -247,18 +243,14 @@ ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LIN
}
-ZEND_API char *_estrdup(const char *s ZEND_FILE_LINE_DC)
+ZEND_API char *_estrdup(const char *s ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
{
int length;
char *p;
length = strlen(s)+1;
HANDLE_BLOCK_INTERRUPTIONS();
-#if ZEND_DEBUG
- p = (char *) _emalloc(length ZEND_FILE_LINE_RELAY_CC);
-#else
- p = (char *) emalloc(length);
-#endif
+ p = (char *) _emalloc(length ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
if (!p) {
HANDLE_UNBLOCK_INTERRUPTIONS();
return (char *)NULL;
@@ -269,16 +261,12 @@ ZEND_API char *_estrdup(const char *s ZEND_FILE_LINE_DC)
}
-ZEND_API char *_estrndup(const char *s, uint length ZEND_FILE_LINE_DC)
+ZEND_API char *_estrndup(const char *s, uint length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
{
char *p;
HANDLE_BLOCK_INTERRUPTIONS();
-#if ZEND_DEBUG
- p = (char *) _emalloc(length+1 ZEND_FILE_LINE_RELAY_CC);
-#else
- p = (char *) emalloc(length+1);
-#endif
+ p = (char *) _emalloc(length+1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
if (!p) {
HANDLE_UNBLOCK_INTERRUPTIONS();
return (char *)NULL;
@@ -400,7 +388,7 @@ void zend_debug_alloc_output(char *format, ...)
}
-ZEND_API int _mem_block_check(void *ptr, int silent ZEND_FILE_LINE_DC)
+ZEND_API int _mem_block_check(void *ptr, int silent ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
{
mem_header *p = (mem_header *) ((char *)ptr - sizeof(mem_header) - PLATFORM_PADDING);
int no_cache_notice=0;
@@ -419,6 +407,9 @@ ZEND_API int _mem_block_check(void *ptr, int silent ZEND_FILE_LINE_DC)
zend_message_dispatcher(ZMSG_LOG_SCRIPT_NAME, NULL);
zend_debug_alloc_output("---------------------------------------\n");
zend_debug_alloc_output("%s(%d) : Block 0x%0.8lX status:\n" ZEND_FILE_LINE_RELAY_CC, (long) p);
+ if (__zend_orig_filename) {
+ zend_debug_alloc_output("%s(%d) : Actual location (location was relayed)\n" ZEND_FILE_LINE_ORIG_RELAY_CC);
+ }
zend_debug_alloc_output("%10s\t","Beginning: ");
}
@@ -433,7 +424,7 @@ ZEND_API int _mem_block_check(void *ptr, int silent ZEND_FILE_LINE_DC)
zend_debug_alloc_output("Freed\n");
had_problems=1;
} else {
- return _mem_block_check(ptr, 0 ZEND_FILE_LINE_RELAY_CC);
+ return _mem_block_check(ptr, 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
}
break;
case MEM_BLOCK_CACHED_MAGIC:
@@ -444,7 +435,7 @@ ZEND_API int _mem_block_check(void *ptr, int silent ZEND_FILE_LINE_DC)
}
} else {
if (!no_cache_notice) {
- return _mem_block_check(ptr, 0 ZEND_FILE_LINE_RELAY_CC);
+ return _mem_block_check(ptr, 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
}
}
break;
@@ -452,7 +443,7 @@ ZEND_API int _mem_block_check(void *ptr, int silent ZEND_FILE_LINE_DC)
if (!silent) {
zend_debug_alloc_output("Overrun (magic=0x%0.8lX, expected=0x%0.8lX)\n", p->magic, MEM_BLOCK_START_MAGIC);
} else {
- return _mem_block_check(ptr, 0 ZEND_FILE_LINE_RELAY_CC);
+ return _mem_block_check(ptr, 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
}
had_problems=1;
valid_beginning=0;
@@ -468,7 +459,7 @@ ZEND_API int _mem_block_check(void *ptr, int silent ZEND_FILE_LINE_DC)
int i;
if (silent) {
- return _mem_block_check(ptr, 0 ZEND_FILE_LINE_RELAY_CC);
+ return _mem_block_check(ptr, 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
}
had_problems=1;
overflow_ptr = ((char *) p)+sizeof(mem_header)+p->size+PLATFORM_PADDING;
@@ -510,7 +501,7 @@ ZEND_API int _mem_block_check(void *ptr, int silent ZEND_FILE_LINE_DC)
}
-ZEND_API void _full_mem_check(int silent ZEND_FILE_LINE_DC)
+ZEND_API void _full_mem_check(int silent ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
{
mem_header *p;
int errors=0;
@@ -523,7 +514,7 @@ ZEND_API void _full_mem_check(int silent ZEND_FILE_LINE_DC)
zend_debug_alloc_output("Full Memory Check at %s:%d\n" ZEND_FILE_LINE_RELAY_CC);
while (p) {
- if (!_mem_block_check((void *)((char *)p + sizeof(mem_header) + PLATFORM_PADDING), (silent?2:3) ZEND_FILE_LINE_RELAY_CC)) {
+ if (!_mem_block_check((void *)((char *)p + sizeof(mem_header) + PLATFORM_PADDING), (silent?2:3) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC)) {
errors++;
}
p = p->pNext;
@@ -534,13 +525,13 @@ ZEND_API void _full_mem_check(int silent ZEND_FILE_LINE_DC)
#endif
-ZEND_API void _persist_alloc(void *ptr ZEND_FILE_LINE_DC)
+ZEND_API void _persist_alloc(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
{
mem_header *p = (mem_header *) ((char *)ptr-sizeof(mem_header)-PLATFORM_PADDING);
ALS_FETCH();
#if ZEND_DEBUG
- _mem_block_check(ptr, 1 ZEND_FILE_LINE_RELAY_CC);
+ _mem_block_check(ptr, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
#endif
HANDLE_BLOCK_INTERRUPTIONS();