1
0
Fork 0
forked from len0rd/rockbox

buflib: Refactor various debugging features

Gate buflib_get_data() checking, debug printing, and buflib
integrity checks behind individual defines in buflib.h, and
turn them all off by default. If needed, they can be turned
on manually when compiling.

The buflib debug menu is only available if debug printing is
enabled, so after this commit it will no longer be included
in normal builds -- it isn't very useful to end users.

Change-Id: Iab25b7852bc7c5592ce04c9c45762046a87d5bc3
This commit is contained in:
Aidan MacDonald 2023-01-02 19:18:02 +00:00
parent e492b51d83
commit 719d48afc4
7 changed files with 75 additions and 43 deletions

View file

@ -35,8 +35,11 @@ unsigned char *audiobufend = audiobuffer + sizeof(audiobuffer);
extern unsigned char *audiobufend;
#endif
#ifdef BUFLIB_DEBUG_PRINT
/* debug test alloc */
static int test_alloc;
#endif
void core_allocator_init(void)
{
unsigned char *start = ALIGN_UP(audiobuffer, sizeof(intptr_t));
@ -51,16 +54,9 @@ void core_allocator_init(void)
buflib_init(&core_ctx, start, audiobufend - start);
#ifdef BUFLIB_DEBUG_PRINT
test_alloc = core_alloc(112);
}
bool core_test_free(void)
{
bool ret = test_alloc > 0;
if (ret)
test_alloc = core_free(test_alloc);
return ret;
#endif
}
/* Allocate memory in the "core" context. See documentation
@ -119,17 +115,28 @@ unsigned core_pin_count(int handle)
return buflib_pin_count(&core_ctx, handle);
}
#ifdef BUFLIB_DEBUG_PRINT
int core_get_num_blocks(void)
{
return buflib_get_num_blocks(&core_ctx);
}
void core_print_block_at(int block_num, char* buf, size_t bufsize)
bool core_print_block_at(int block_num, char* buf, size_t bufsize)
{
buflib_print_block_at(&core_ctx, block_num, buf, bufsize);
return buflib_print_block_at(&core_ctx, block_num, buf, bufsize);
}
#ifdef DEBUG
bool core_test_free(void)
{
bool ret = test_alloc > 0;
if (ret)
test_alloc = core_free(test_alloc);
return ret;
}
#endif
#ifdef BUFLIB_DEBUG_CHECK_VALID
void core_check_valid(void)
{
buflib_check_valid(&core_ctx);