summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-05-24 10:40:07 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-05-24 10:40:07 -0600
commitf3f00384b43f110c230725f0d75317fe1b0fcb85 (patch)
tree6aed4e32577a1b9b05bb56060d9751d91cd37668
parent97a8f813e234bc11b36c40b7bc9c674679bce262 (diff)
downloadpx4-nuttx-f3f00384b43f110c230725f0d75317fe1b0fcb85.tar.gz
px4-nuttx-f3f00384b43f110c230725f0d75317fe1b0fcb85.tar.bz2
px4-nuttx-f3f00384b43f110c230725f0d75317fe1b0fcb85.zip
Costmetic changes to memory manager debug output
-rw-r--r--apps/examples/mm/mm_main.c13
-rw-r--r--nuttx/mm/mm_mallinfo.c9
2 files changed, 19 insertions, 3 deletions
diff --git a/apps/examples/mm/mm_main.c b/apps/examples/mm/mm_main.c
index c15004a34..bf7e1f06d 100644
--- a/apps/examples/mm/mm_main.c
+++ b/apps/examples/mm/mm_main.c
@@ -149,11 +149,14 @@ static void do_mallocs(void **mem, const int *size, const int *seq, int n)
if (!mem[j])
{
printf("(%d)Allocating %d bytes\n", i, size[j]);
+
mem[j] = malloc(size[j]);
printf("(%d)Memory allocated at %p\n", i, mem[j]);
+
if (mem[j] == NULL)
{
int allocsize = MM_ALIGN_UP(size[j] + SIZEOF_MM_ALLOCNODE);
+
fprintf(stderr, "(%d)malloc failed for allocsize=%d\n", i, allocsize);
if (allocsize > alloc_info.mxordblk)
{
@@ -167,7 +170,7 @@ static void do_mallocs(void **mem, const int *size, const int *seq, int n)
}
else
{
- memset(mem[j], 0xAA, size[j]);
+ memset(mem[j], 0xaa, size[j]);
}
mm_showmallinfo();
@@ -185,11 +188,14 @@ static void do_reallocs(void **mem, const int *oldsize, const int *newsize, cons
j = seq[i];
printf("(%d)Re-allocating at %p from %d to %d bytes\n",
i, mem[j], oldsize[j], newsize[j]);
+
mem[j] = realloc(mem[j], newsize[j]);
printf("(%d)Memory re-allocated at %p\n", i, mem[j]);
+
if (mem[j] == NULL)
{
int allocsize = MM_ALIGN_UP(newsize[j] + SIZEOF_MM_ALLOCNODE);
+
fprintf(stderr, "(%d)realloc failed for allocsize=%d\n", i, allocsize);
if (allocsize > alloc_info.mxordblk)
{
@@ -220,11 +226,14 @@ static void do_memaligns(void **mem, const int *size, const int *align, const in
j = seq[i];
printf("(%d)Allocating %d bytes aligned to 0x%08x\n",
i, size[j], align[i]);
+
mem[j] = memalign(align[i], size[j]);
printf("(%d)Memory allocated at %p\n", i, mem[j]);
+
if (mem[j] == NULL)
{
int allocsize = MM_ALIGN_UP(size[j] + SIZEOF_MM_ALLOCNODE) + 2*align[i];
+
fprintf(stderr, "(%d)memalign failed for allocsize=%d\n", i, allocsize);
if (allocsize > alloc_info.mxordblk)
{
@@ -253,8 +262,10 @@ static void do_frees(void **mem, const int *size, const int *seq, int n)
for (i = 0; i < n; i++)
{
j = seq[i];
+
printf("(%d)Releasing memory at %p (size=%d bytes)\n",
i, mem[j], size[j]);
+
free(mem[j]);
mem[j] = NULL;
diff --git a/nuttx/mm/mm_mallinfo.c b/nuttx/mm/mm_mallinfo.c
index acda75d8f..e37f82266 100644
--- a/nuttx/mm/mm_mallinfo.c
+++ b/nuttx/mm/mm_mallinfo.c
@@ -99,8 +99,13 @@ int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info)
node < heap->mm_heapend[region];
node = (struct mm_allocnode_s *)((char*)node + node->size))
{
- mvdbg("region=%d node=%p size=%p preceding=%p\n", region, node, node->size, node->preceding);
- if (node->preceding & MM_ALLOC_BIT)
+ mvdbg("region=%d node=%p size=%p preceding=%p (%c)\n",
+ region, node, node->size, (node->preceding & ~MM_ALLOC_BIT),
+ (node->preceding & MM_ALLOC_BIT) ? 'A' : 'F');
+
+ /* Check if the node corresponds to an allocated memory chunk */
+
+ if ((node->preceding & MM_ALLOC_BIT) != 0)
{
uordblks += node->size;
}