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:
parent
e492b51d83
commit
719d48afc4
7 changed files with 75 additions and 43 deletions
|
@ -496,6 +496,7 @@ static bool dbg_buffering_thread(void)
|
||||||
#undef STR_DATAREM
|
#undef STR_DATAREM
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef BUFLIB_DEBUG_PRINT
|
||||||
static const char* bf_getname(int selected_item, void *data,
|
static const char* bf_getname(int selected_item, void *data,
|
||||||
char *buffer, size_t buffer_len)
|
char *buffer, size_t buffer_len)
|
||||||
{
|
{
|
||||||
|
@ -536,6 +537,7 @@ static bool dbg_buflib_allocs(void)
|
||||||
info.timeout = HZ;
|
info.timeout = HZ;
|
||||||
return simplelist_show_list(&info);
|
return simplelist_show_list(&info);
|
||||||
}
|
}
|
||||||
|
#endif /* BUFLIB_DEBUG_PRINT */
|
||||||
|
|
||||||
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
|
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
|
||||||
static const char* dbg_partitions_getname(int selected_item, void *data,
|
static const char* dbg_partitions_getname(int selected_item, void *data,
|
||||||
|
@ -2619,7 +2621,9 @@ static const struct {
|
||||||
#ifdef PM_DEBUG
|
#ifdef PM_DEBUG
|
||||||
{ "pm histogram", peak_meter_histogram},
|
{ "pm histogram", peak_meter_histogram},
|
||||||
#endif /* PM_DEBUG */
|
#endif /* PM_DEBUG */
|
||||||
|
#ifdef BUFLIB_DEBUG_PRINT
|
||||||
{ "View buflib allocs", dbg_buflib_allocs },
|
{ "View buflib allocs", dbg_buflib_allocs },
|
||||||
|
#endif
|
||||||
#ifndef SIMULATOR
|
#ifndef SIMULATOR
|
||||||
#if CONFIG_TUNER
|
#if CONFIG_TUNER
|
||||||
{ "FM Radio", dbg_fm_radio },
|
{ "FM Radio", dbg_fm_radio },
|
||||||
|
|
|
@ -991,8 +991,7 @@ unsigned buflib_pin_count(struct buflib_context *ctx, int handle)
|
||||||
return data[idx_PIN].pincount;
|
return data[idx_PIN].pincount;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef BUFLIB_DEBUG_GET_DATA
|
||||||
|
|
||||||
void *buflib_get_data(struct buflib_context *ctx, int handle)
|
void *buflib_get_data(struct buflib_context *ctx, int handle)
|
||||||
{
|
{
|
||||||
if (handle <= 0)
|
if (handle <= 0)
|
||||||
|
@ -1000,7 +999,9 @@ void *buflib_get_data(struct buflib_context *ctx, int handle)
|
||||||
|
|
||||||
return (void*)(ctx->handle_table[-handle].alloc);
|
return (void*)(ctx->handle_table[-handle].alloc);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BUFLIB_DEBUG_CHECK_VALID
|
||||||
void buflib_check_valid(struct buflib_context *ctx)
|
void buflib_check_valid(struct buflib_context *ctx)
|
||||||
{
|
{
|
||||||
for(union buflib_data *block = ctx->buf_start;
|
for(union buflib_data *block = ctx->buf_start;
|
||||||
|
@ -1016,10 +1017,11 @@ void buflib_check_valid(struct buflib_context *ctx)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BUFLIB_DEBUG_BLOCK_SINGLE
|
#ifdef BUFLIB_DEBUG_PRINT
|
||||||
int buflib_get_num_blocks(struct buflib_context *ctx)
|
int buflib_get_num_blocks(struct buflib_context *ctx)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for(union buflib_data *block = ctx->buf_start;
|
for(union buflib_data *block = ctx->buf_start;
|
||||||
block < ctx->alloc_end;
|
block < ctx->alloc_end;
|
||||||
block += abs(block->val))
|
block += abs(block->val))
|
||||||
|
@ -1027,10 +1029,11 @@ int buflib_get_num_blocks(struct buflib_context *ctx)
|
||||||
check_block_length(ctx, block);
|
check_block_length(ctx, block);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void buflib_print_block_at(struct buflib_context *ctx, int block_num,
|
bool buflib_print_block_at(struct buflib_context *ctx, int block_num,
|
||||||
char *buf, size_t bufsize)
|
char *buf, size_t bufsize)
|
||||||
{
|
{
|
||||||
for(union buflib_data *block = ctx->buf_start;
|
for(union buflib_data *block = ctx->buf_start;
|
||||||
|
@ -1044,8 +1047,13 @@ void buflib_print_block_at(struct buflib_context *ctx, int block_num,
|
||||||
snprintf(buf, bufsize, "%8p: val: %4ld (%sallocated)",
|
snprintf(buf, bufsize, "%8p: val: %4ld (%sallocated)",
|
||||||
block, (long)block->val,
|
block, (long)block->val,
|
||||||
block->val > 0 ? "" : "un");
|
block->val > 0 ? "" : "un");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bufsize > 0)
|
||||||
|
*buf = '\0';
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,11 @@ unsigned char *audiobufend = audiobuffer + sizeof(audiobuffer);
|
||||||
extern unsigned char *audiobufend;
|
extern unsigned char *audiobufend;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef BUFLIB_DEBUG_PRINT
|
||||||
/* debug test alloc */
|
/* debug test alloc */
|
||||||
static int test_alloc;
|
static int test_alloc;
|
||||||
|
#endif
|
||||||
|
|
||||||
void core_allocator_init(void)
|
void core_allocator_init(void)
|
||||||
{
|
{
|
||||||
unsigned char *start = ALIGN_UP(audiobuffer, sizeof(intptr_t));
|
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);
|
buflib_init(&core_ctx, start, audiobufend - start);
|
||||||
|
|
||||||
|
#ifdef BUFLIB_DEBUG_PRINT
|
||||||
test_alloc = core_alloc(112);
|
test_alloc = core_alloc(112);
|
||||||
}
|
#endif
|
||||||
|
|
||||||
bool core_test_free(void)
|
|
||||||
{
|
|
||||||
bool ret = test_alloc > 0;
|
|
||||||
if (ret)
|
|
||||||
test_alloc = core_free(test_alloc);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate memory in the "core" context. See documentation
|
/* 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);
|
return buflib_pin_count(&core_ctx, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef BUFLIB_DEBUG_PRINT
|
||||||
int core_get_num_blocks(void)
|
int core_get_num_blocks(void)
|
||||||
{
|
{
|
||||||
return buflib_get_num_blocks(&core_ctx);
|
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)
|
void core_check_valid(void)
|
||||||
{
|
{
|
||||||
buflib_check_valid(&core_ctx);
|
buflib_check_valid(&core_ctx);
|
||||||
|
|
|
@ -23,15 +23,21 @@
|
||||||
* KIND, either express or implied.
|
* KIND, either express or implied.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef _BUFLIB_H_
|
#ifndef _BUFLIB_H_
|
||||||
#define _BUFLIB_H_
|
#define _BUFLIB_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* enable single block debugging */
|
/* add extra checks to buflib_get_data to catch bad handles */
|
||||||
#define BUFLIB_DEBUG_BLOCK_SINGLE
|
//#define BUFLIB_DEBUG_GET_DATA
|
||||||
|
|
||||||
|
/* support integrity check */
|
||||||
|
//#define BUFLIB_DEBUG_CHECK_VALID
|
||||||
|
|
||||||
|
/* support debug printing of memory blocks */
|
||||||
|
//#define BUFLIB_DEBUG_PRINT
|
||||||
|
|
||||||
union buflib_data
|
union buflib_data
|
||||||
{
|
{
|
||||||
|
@ -260,12 +266,12 @@ int buflib_alloc_maximum(struct buflib_context* ctx,
|
||||||
*
|
*
|
||||||
* Returns: The start pointer of the allocation
|
* Returns: The start pointer of the allocation
|
||||||
*/
|
*/
|
||||||
#ifdef DEBUG
|
#ifdef BUFLIB_DEBUG_GET_DATA
|
||||||
void *buflib_get_data(struct buflib_context *ctx, int handle);
|
void *buflib_get_data(struct buflib_context *ctx, int handle);
|
||||||
#else
|
#else
|
||||||
static inline void *buflib_get_data(struct buflib_context *ctx, int handle)
|
static inline void *buflib_get_data(struct buflib_context *ctx, int handle)
|
||||||
{
|
{
|
||||||
return (void*)(ctx->handle_table[-handle].alloc);
|
return (void *)ctx->handle_table[-handle].alloc;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -342,29 +348,34 @@ void* buflib_buffer_out(struct buflib_context *ctx, size_t *size);
|
||||||
*/
|
*/
|
||||||
void buflib_buffer_in(struct buflib_context *ctx, int size);
|
void buflib_buffer_in(struct buflib_context *ctx, int size);
|
||||||
|
|
||||||
/* debugging */
|
#ifdef BUFLIB_DEBUG_PRINT
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of blocks in the entire buffer, allocated or unallocated
|
* Return the number of blocks in the buffer, allocated or unallocated.
|
||||||
*
|
*
|
||||||
* Only available if BUFLIB_DEBUG_BLOCK_SIGNLE is defined
|
* Only available if BUFLIB_DEBUG_PRINT is defined.
|
||||||
*/
|
*/
|
||||||
int buflib_get_num_blocks(struct buflib_context *ctx);
|
int buflib_get_num_blocks(struct buflib_context *ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print information about a single block as indicated by block_num
|
* Write a string describing the block at index block_num to the
|
||||||
* into buf
|
* provided buffer. The buffer will always be null terminated and
|
||||||
|
* there is no provision to detect truncation. (A 40-byte buffer
|
||||||
|
* is enough to contain any returned string.)
|
||||||
*
|
*
|
||||||
* buflib_get_num_blocks() beforehand to get the total number of blocks,
|
* Returns false if the block index is out of bounds, and writes
|
||||||
* as passing an block_num higher than that is undefined
|
* an empty string.
|
||||||
*
|
*
|
||||||
* Only available if BUFLIB_DEBUG_BLOCK_SIGNLE is defined
|
* Only available if BUFLIB_DEBUG_PRINT is defined.
|
||||||
*/
|
*/
|
||||||
void buflib_print_block_at(struct buflib_context *ctx, int block_num,
|
bool buflib_print_block_at(struct buflib_context *ctx, int block_num,
|
||||||
char *buf, size_t bufsize);
|
char *buf, size_t bufsize);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BUFLIB_DEBUG_CHECK_VALID
|
||||||
/**
|
/**
|
||||||
* Check integrity of given buflib context
|
* Check integrity of given buflib context
|
||||||
*/
|
*/
|
||||||
void buflib_check_valid(struct buflib_context *ctx);
|
void buflib_check_valid(struct buflib_context *ctx);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif /* _BUFLIB_H_ */
|
||||||
|
|
|
@ -21,21 +21,23 @@ unsigned core_pin_count(int handle);
|
||||||
int core_free(int handle);
|
int core_free(int handle);
|
||||||
size_t core_available(void);
|
size_t core_available(void);
|
||||||
size_t core_allocatable(void);
|
size_t core_allocatable(void);
|
||||||
#ifdef DEBUG
|
|
||||||
|
#ifdef BUFLIB_DEBUG_CHECK_VALID
|
||||||
void core_check_valid(void);
|
void core_check_valid(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* DO NOT ADD wrappers for buflib_buffer_out/in. They do not call
|
/* DO NOT ADD wrappers for buflib_buffer_out/in. They do not call
|
||||||
* the move callbacks and are therefore unsafe in the core */
|
* the move callbacks and are therefore unsafe in the core */
|
||||||
|
|
||||||
#ifdef BUFLIB_DEBUG_BLOCK_SINGLE
|
#ifdef BUFLIB_DEBUG_PRINT
|
||||||
int core_get_num_blocks(void);
|
int core_get_num_blocks(void);
|
||||||
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);
|
||||||
#endif
|
|
||||||
|
|
||||||
/* frees the debug test alloc created at initialization,
|
/* frees the debug test alloc created at initialization,
|
||||||
* since this is the first any further alloc should force a compaction run */
|
* since this is the first any further alloc should force a compaction run
|
||||||
|
* only used if debug print is active */
|
||||||
bool core_test_free(void);
|
bool core_test_free(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
static inline void* core_get_data(int handle)
|
static inline void* core_get_data(int handle)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1019,7 +1019,7 @@ void switch_thread(void)
|
||||||
#ifdef RB_PROFILE
|
#ifdef RB_PROFILE
|
||||||
profile_thread_stopped(THREAD_ID_SLOT(thread->id));
|
profile_thread_stopped(THREAD_ID_SLOT(thread->id));
|
||||||
#endif
|
#endif
|
||||||
#ifdef DEBUG
|
#ifdef BUFLIB_DEBUG_CHECK_VALID
|
||||||
/* Check core_ctx buflib integrity */
|
/* Check core_ctx buflib integrity */
|
||||||
core_check_valid();
|
core_check_valid();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -215,7 +215,7 @@ void switch_thread(void)
|
||||||
} /* STATE_SLEEPING: */
|
} /* STATE_SLEEPING: */
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef BUFLIB_DEBUG_CHECK_VALID
|
||||||
core_check_valid();
|
core_check_valid();
|
||||||
#endif
|
#endif
|
||||||
__running_self_entry() = current;
|
__running_self_entry() = current;
|
||||||
|
|
Loading…
Reference in a new issue