take some steps towards reducing memory footprint in stack buffers
This commit is contained in:
+8
-5
@@ -16,7 +16,7 @@ void hexDump(const char *restrict desc, const void *restrict addr, uint32_t len)
|
||||
PRINTF ("%s:\r\n", desc);
|
||||
|
||||
if (len == 0) {
|
||||
PRINTF(" ZERO LENGTH\r\n");
|
||||
PUTS(" ZERO LENGTH\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -26,8 +26,11 @@ void hexDump(const char *restrict desc, const void *restrict addr, uint32_t len)
|
||||
|
||||
if ((i % 16) == 0) {
|
||||
// Just don't print ASCII for the zeroth line.
|
||||
if (i != 0)
|
||||
PRINTF (" %s\r\n", buff);
|
||||
if (i != 0) {
|
||||
PUTS(" ");
|
||||
PUTS((const char *) buff);
|
||||
PUTS("\r\n");
|
||||
}
|
||||
|
||||
// Output the offset.
|
||||
PRINTF (" %04"PRIx32" ", i);
|
||||
@@ -38,7 +41,7 @@ void hexDump(const char *restrict desc, const void *restrict addr, uint32_t len)
|
||||
|
||||
// And store a printable ASCII character for later.
|
||||
if ((pc[i] < 0x20) || (pc[i] > 0x7e))
|
||||
buff[i % 16] = '.';
|
||||
buff[i % 16] = (uint8_t) ((pc[i] == 0xA5) ? ' ' : '.'); // special treatment for 0xA5 which is used as a filler in stacks
|
||||
else
|
||||
buff[i % 16] = pc[i];
|
||||
buff[(i % 16) + 1] = '\0';
|
||||
@@ -46,7 +49,7 @@ void hexDump(const char *restrict desc, const void *restrict addr, uint32_t len)
|
||||
|
||||
// Pad out last line if not exactly 16 characters.
|
||||
while ((i % 16) != 0) {
|
||||
PRINTF (" ");
|
||||
PUTS(" ");
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
+24
-3
@@ -2,9 +2,10 @@
|
||||
// Created by MightyPork on 2017/12/01.
|
||||
//
|
||||
|
||||
#include <framework/system_settings.h>
|
||||
#include "platform.h"
|
||||
#include "framework/system_settings.h"
|
||||
#include "ini_writer.h"
|
||||
#include "malloc_safe.h"
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((a)>(b)?(b):(a))
|
||||
@@ -16,9 +17,27 @@
|
||||
|
||||
//#define IWBUFFER_LEN 128 // moved to plat_compat.h
|
||||
|
||||
// sprintf from varargs, allocating buffer on stack. Uses 'format' argument
|
||||
char *iwbuffer = NULL;
|
||||
|
||||
/** Allocate the helper buffer */
|
||||
void iw_begin(void)
|
||||
{
|
||||
assert_param(iwbuffer == NULL);
|
||||
bool suc = true;
|
||||
iwbuffer = malloc_ck(IWBUFFER_LEN, &suc);
|
||||
assert_param(suc);
|
||||
}
|
||||
|
||||
/** Release the helper buffer */
|
||||
void iw_end(void)
|
||||
{
|
||||
assert_param(iwbuffer != NULL);
|
||||
free(iwbuffer);
|
||||
iwbuffer = NULL;
|
||||
}
|
||||
|
||||
#define IW_VPRINTF() do { \
|
||||
char iwbuffer[IWBUFFER_LEN]; \
|
||||
assert_param(iwbuffer != NULL); \
|
||||
va_list args; \
|
||||
va_start(args, format); \
|
||||
uint32_t len = (int)fixup_vsnprintf(&iwbuffer[0], IWBUFFER_LEN, format, args); \
|
||||
@@ -95,7 +114,9 @@ void iw_entry(IniWriter *iw, const char *key, const char *format, ...)
|
||||
uint32_t iw_measure_total(void (*handler)(IniWriter *))
|
||||
{
|
||||
IniWriter iw = iw_init(NULL, 0xFFFFFFFF, 1);
|
||||
iw_begin();
|
||||
handler(&iw);
|
||||
iw_end();
|
||||
return 0xFFFFFFFF - iw.skip;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,21 @@ typedef struct iniwriter_ {
|
||||
uint32_t count;
|
||||
} IniWriter;
|
||||
|
||||
/**
|
||||
* IniWriter helper buffer, available within a IW-scope only.
|
||||
*
|
||||
* This buffer is used internally by printf-like iw functions.
|
||||
* It can be used to prepare buffer for iw_buff or iw_string,
|
||||
* but must not be used for %s substitutions in iw_* functions.
|
||||
*/
|
||||
extern char *iwbuffer;
|
||||
|
||||
/** Allocate the helper buffer */
|
||||
void iw_begin(void);
|
||||
|
||||
/** Release the helper buffer */
|
||||
void iw_end(void);
|
||||
|
||||
/**
|
||||
* Initialize a IniWriter struct (macro)
|
||||
*
|
||||
|
||||
@@ -67,6 +67,9 @@ extern "C" {
|
||||
|
||||
#define __at(_addr) __attribute__ ((at(_addr)))
|
||||
|
||||
#define VA_ARG_COUNT(...) INTERNAL_GET_ARG_COUNT_PRIVATE(0, ## __VA_ARGS__, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
|
||||
#define INTERNAL_GET_ARG_COUNT_PRIVATE(_0, _1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, _9_, _10_, _11_, _12_, _13_, _14_, _15_, _16_, _17_, _18_, _19_, _20_, _21_, _22_, _23_, _24_, _25_, _26_, _27_, _28_, _29_, _30_, _31_, _32_, _33_, _34_, _35_, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, count, ...) count
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "task_msg.h"
|
||||
#include "platform.h"
|
||||
#include "stacksmon.h"
|
||||
#include "hexdump.h"
|
||||
|
||||
#if USE_STACK_MONITOR
|
||||
|
||||
|
||||
Reference in New Issue
Block a user