Browse Source

[malloc] Tidy up debug output

Colourise debug output and move per-allocation messages to DBGLVL_EXTRA.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 years ago
parent
commit
998e69ae14
1 changed files with 23 additions and 19 deletions
  1. 23
    19
      src/core/malloc.c

+ 23
- 19
src/core/malloc.c View File

245
 	size = ( size + MIN_MEMBLOCK_SIZE - 1 ) & ~( MIN_MEMBLOCK_SIZE - 1 );
245
 	size = ( size + MIN_MEMBLOCK_SIZE - 1 ) & ~( MIN_MEMBLOCK_SIZE - 1 );
246
 	align_mask = ( align - 1 ) | ( MIN_MEMBLOCK_SIZE - 1 );
246
 	align_mask = ( align - 1 ) | ( MIN_MEMBLOCK_SIZE - 1 );
247
 
247
 
248
-	DBG ( "Allocating %#zx (aligned %#zx+%zx)\n", size, align, offset );
248
+	DBGC2 ( &heap, "Allocating %#zx (aligned %#zx+%zx)\n",
249
+		size, align, offset );
249
 	while ( 1 ) {
250
 	while ( 1 ) {
250
 		/* Search through blocks for the first one with enough space */
251
 		/* Search through blocks for the first one with enough space */
251
 		list_for_each_entry ( block, &free_blocks, list ) {
252
 		list_for_each_entry ( block, &free_blocks, list ) {
261
 				pre   = block;
262
 				pre   = block;
262
 				block = ( ( ( void * ) pre   ) + pre_size );
263
 				block = ( ( ( void * ) pre   ) + pre_size );
263
 				post  = ( ( ( void * ) block ) + size     );
264
 				post  = ( ( ( void * ) block ) + size     );
264
-				DBG ( "[%p,%p) -> [%p,%p) + [%p,%p)\n", pre,
265
-				      ( ( ( void * ) pre ) + pre->size ),
266
-				      pre, block, post,
267
-				      ( ( ( void * ) pre ) + pre->size ) );
265
+				DBGC2 ( &heap, "[%p,%p) -> [%p,%p) + [%p,%p)\n",
266
+					pre, ( ( ( void * ) pre ) + pre->size ),
267
+					pre, block, post,
268
+					( ( ( void * ) pre ) + pre->size ) );
268
 				/* If there is a "post" block, add it in to
269
 				/* If there is a "post" block, add it in to
269
 				 * the free list.  Leak it if it is too small
270
 				 * the free list.  Leak it if it is too small
270
 				 * (which can happen only at the very end of
271
 				 * (which can happen only at the very end of
291
 				/* Update total free memory */
292
 				/* Update total free memory */
292
 				freemem -= size;
293
 				freemem -= size;
293
 				/* Return allocated block */
294
 				/* Return allocated block */
294
-				DBG ( "Allocated [%p,%p)\n", block,
295
-				      ( ( ( void * ) block ) + size ) );
295
+				DBGC2 ( &heap, "Allocated [%p,%p)\n", block,
296
+					( ( ( void * ) block ) + size ) );
296
 				ptr = block;
297
 				ptr = block;
297
 				goto done;
298
 				goto done;
298
 			}
299
 			}
301
 		/* Try discarding some cached data to free up memory */
302
 		/* Try discarding some cached data to free up memory */
302
 		if ( ! discard_cache() ) {
303
 		if ( ! discard_cache() ) {
303
 			/* Nothing available to discard */
304
 			/* Nothing available to discard */
304
-			DBG ( "Failed to allocate %#zx (aligned %#zx)\n",
305
-			      size, align );
305
+			DBGC ( &heap, "Failed to allocate %#zx (aligned "
306
+			       "%#zx)\n", size, align );
306
 			ptr = NULL;
307
 			ptr = NULL;
307
 			goto done;
308
 			goto done;
308
 		}
309
 		}
341
 	freeing = ptr;
342
 	freeing = ptr;
342
 	VALGRIND_MAKE_MEM_DEFINED ( freeing, sizeof ( *freeing ) );
343
 	VALGRIND_MAKE_MEM_DEFINED ( freeing, sizeof ( *freeing ) );
343
 	freeing->size = size;
344
 	freeing->size = size;
344
-	DBG ( "Freeing [%p,%p)\n", freeing, ( ( ( void * ) freeing ) + size ));
345
+	DBGC2 ( &heap, "Freeing [%p,%p)\n",
346
+		freeing, ( ( ( void * ) freeing ) + size ) );
345
 
347
 
346
 	/* Insert/merge into free list */
348
 	/* Insert/merge into free list */
347
 	list_for_each_entry_safe ( block, tmp, &free_blocks, list ) {
349
 	list_for_each_entry_safe ( block, tmp, &free_blocks, list ) {
352
 			      ( ( ( void * ) freeing ) + freeing->size ) );
354
 			      ( ( ( void * ) freeing ) + freeing->size ) );
353
 		/* Merge with immediately preceding block, if possible */
355
 		/* Merge with immediately preceding block, if possible */
354
 		if ( gap_before == 0 ) {
356
 		if ( gap_before == 0 ) {
355
-			DBG ( "[%p,%p) + [%p,%p) -> [%p,%p)\n", block,
356
-			      ( ( ( void * ) block ) + block->size ), freeing,
357
-			      ( ( ( void * ) freeing ) + freeing->size ),block,
358
-			      ( ( ( void * ) freeing ) + freeing->size ) );
357
+			DBGC2 ( &heap, "[%p,%p) + [%p,%p) -> [%p,%p)\n", block,
358
+				( ( ( void * ) block ) + block->size ), freeing,
359
+				( ( ( void * ) freeing ) + freeing->size ),
360
+				block,
361
+				( ( ( void * ) freeing ) + freeing->size ) );
359
 			block->size += size;
362
 			block->size += size;
360
 			list_del ( &block->list );
363
 			list_del ( &block->list );
361
 			freeing = block;
364
 			freeing = block;
369
 	 * possible, merge the following block into the "freeing"
372
 	 * possible, merge the following block into the "freeing"
370
 	 * block.
373
 	 * block.
371
 	 */
374
 	 */
372
-	DBG ( "[%p,%p)\n", freeing, ( ( ( void * ) freeing ) + freeing->size));
375
+	DBGC2 ( &heap, "[%p,%p)\n",
376
+		freeing, ( ( ( void * ) freeing ) + freeing->size ) );
373
 	list_add_tail ( &freeing->list, &block->list );
377
 	list_add_tail ( &freeing->list, &block->list );
374
 	if ( gap_after == 0 ) {
378
 	if ( gap_after == 0 ) {
375
-		DBG ( "[%p,%p) + [%p,%p) -> [%p,%p)\n", freeing,
376
-		      ( ( ( void * ) freeing ) + freeing->size ), block,
377
-		      ( ( ( void * ) block ) + block->size ), freeing,
378
-		      ( ( ( void * ) block ) + block->size ) );
379
+		DBGC2 ( &heap, "[%p,%p) + [%p,%p) -> [%p,%p)\n", freeing,
380
+			( ( ( void * ) freeing ) + freeing->size ), block,
381
+			( ( ( void * ) block ) + block->size ), freeing,
382
+			( ( ( void * ) block ) + block->size ) );
379
 		freeing->size += block->size;
383
 		freeing->size += block->size;
380
 		list_del ( &block->list );
384
 		list_del ( &block->list );
381
 	}
385
 	}

Loading…
Cancel
Save