Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #38576] [PATCH] Make DETAIL_MEMORY_DEBUG work.

0 views
Skip to first unread message

Andy Dougherty

unread,
Feb 15, 2006, 12:53:21 PM2/15/06
to bugs-bi...@rt.perl.org
# New Ticket Created by Andy Dougherty
# Please include the string: [perl #38576]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=38576 >


While trying to debug an "Out of mem" PANIC, I decided to try using
DETAIL_MEMORY_DEBUG in src/memory.c. Alas, it didn't help for two
reasons:
1. It prints to standard output, so that when you try to rebuild
parrot, you get things like

$ make parrot
Invoking Parrot to generate runtime/parrot/include/config.fpmc --cross your fingers
./miniparrot config_lib.pasm > runtime/parrot/include/config.fpmc
perl5.6 tools/build/parrot_config_c.pl > src/parrot_config.c
[ . . . ]
cc -o parrot [. . . ] src/parrot_config.o [ . . . ]

which ends up putting all that debug information into
src/parrot_config.o, and, eventually, into parrot. The resulting
parrot dumps core immediately. Not very helpful.

2. Some (but not all) of the debugging statements were *after* the
call to PANIC. That means that you never get to see the call to the
function that triggered the panic.

The following patch to src/memory.c re-orders statements, and prints to
stderr instead of stdout. I know stderr might not be available in
all situations, but this at least can work sometimes.

Finally, I put in a guard against calling free(0). It might not be
necessary, but we do end up trying to call it, and old habits die
hard.:-).

--- parrot-current/src/memory.c Sat Feb 11 12:23:31 2006
+++ parrot-andy/src/memory.c Wed Feb 15 12:36:51 2006
@@ -41,11 +41,11 @@
mem_sys_allocate(size_t size)
{
void *ptr = malloc((size_t)size);
- if (!ptr)
- PANIC("Out of mem");
#ifdef DETAIL_MEMORY_DEBUG
- printf("Allocated %i at %p\n", size, ptr);
+ fprintf(stderr, "Allocated %i at %p\n", size, ptr);
#endif
+ if (!ptr)
+ PANIC("Out of mem");
return ptr;
}

@@ -54,7 +54,7 @@
{
void *ptr = malloc((size_t)size);
#ifdef DETAIL_MEMORY_DEBUG
- printf("Internal malloc %i at %p (%s/%d)\n", size, ptr, file, line);
+ fprintf(stderr, "Internal malloc %i at %p (%s/%d)\n", size, ptr, file, line);
#endif
if (!ptr)
PANIC("Out of mem");
@@ -76,11 +76,11 @@
mem_sys_allocate_zeroed(size_t size)
{
void *ptr = calloc(1, (size_t)size);
- if (!ptr)
- PANIC("Out of mem");
#ifdef DETAIL_MEMORY_DEBUG
- printf("Allocated %i at %p\n", size, ptr);
+ fprintf(stderr, "Allocated %i at %p\n", size, ptr);
#endif
+ if (!ptr)
+ PANIC("Out of mem");
return ptr;
}

@@ -88,11 +88,11 @@
mem__internal_allocate_zeroed(size_t size, const char *file, int line)
{
void *ptr = calloc(1, (size_t)size);
- if (!ptr)
- PANIC("Out of mem");
#ifdef DETAIL_MEMORY_DEBUG
- printf("Internal malloc %i at %p (%s/%d)\n", size, ptr, file, line);
+ fprintf(stderr, "Internal malloc %i at %p (%s/%d)\n", size, ptr, file, line);
#endif
+ if (!ptr)
+ PANIC("Out of mem");
return ptr;
}

@@ -112,14 +112,14 @@
{
void *ptr;
#ifdef DETAIL_MEMORY_DEBUG
- printf("Freed %p (realloc -- %i bytes)\n", from, size);
+ fprintf(stderr, "Freed %p (realloc -- %i bytes)\n", from, size);
#endif
ptr = realloc(from, size);
- if (!ptr)
- PANIC("Out of mem");
#ifdef DETAIL_MEMORY_DEBUG
- printf("Allocated %i at %p\n", size, ptr);
+ fprintf(stderr, "Allocated %i at %p\n", size, ptr);
#endif
+ if (!ptr)
+ PANIC("Out of mem");
return ptr;
}

@@ -127,12 +127,12 @@
mem__internal_realloc(void *from, size_t size, const char *file, int line)
{
void *ptr = realloc(from, size);
- if (!ptr)
- PANIC("Out of mem");
#ifdef DETAIL_MEMORY_DEBUG
- printf("internal free of %p (realloc -- %i bytes) (%s/%d)\n", from, size, file, line);
- printf("Internal malloc %i at %p (%s/%d)\n", size, ptr, file, line);
+ fprintf(stderr, "internal free of %p (realloc -- %i bytes) (%s/%d)\n", from, size, file, line);
+ fprintf(stderr, "Internal malloc %i at %p (%s/%d)\n", size, ptr, file, line);
#endif
+ if (!ptr)
+ PANIC("Out of mem");
return ptr;
}
#undef interpreter
@@ -152,16 +152,17 @@
mem_sys_free(void *from)
{
#ifdef DETAIL_MEMORY_DEBUG
- printf("Freed %p\n", from);
+ fprintf(stderr, "Freed %p\n", from);
#endif
- free(from);
+ if (from)
+ free(from);
}

void
mem__internal_free(void *from, const char *file, int line)
{
#ifdef DETAIL_MEMORY_DEBUG
- printf("Internal free of %p (%s/%d)\n", from, file, line);
+ fprintf(stderr, "Internal free of %p (%s/%d)\n", from, file, line);
#endif
free(from);
}

--
Andy Dougherty doug...@lafayette.edu

Leopold Toetsch

unread,
Feb 15, 2006, 3:17:34 PM2/15/06
to perl6-i...@perl.org

On Feb 15, 2006, at 18:53, Andy Dougherty (via RT) wrote:

> # New Ticket Created by Andy Dougherty

Andy, I've already asked once: don't you have svn access? If no (and if
you want it) please mail me your auth.perl.org account data, to get you
svn priv bits.
If yes, I'd really prefer that such patches just go in. And honestly
all your patches are well-thought and hight quality.

Thanks,
leo

Andy Dougherty

unread,
Feb 16, 2006, 10:11:57 AM2/16/06
to Leopold Toetsch via RT
On Wed, 15 Feb 2006, Leopold Toetsch via RT wrote:

> Andy, I've already asked once: don't you have svn access? If no (and if
> you want it) please mail me your auth.perl.org account data, to get you
> svn priv bits.

I do have priv bits, and have on rare occasion used them, but I don't
usually have an svn repository available -- I usually work with the
snapshots or releases. And, since a checkout takes about an hour (last
time I checked) I tend to be too lazy to fetch one just to make a patch.

Still, I'll take your message to heart, and when feasible (and
appropriate!) just try to check stuff in directly.

--
Andy Dougherty doug...@lafayette.edu

0 new messages