tie in static memory debug callback

This commit is contained in:
JacobBarthelmeh 2024-05-29 15:24:22 -06:00
parent 288fe430f5
commit 6cca3a0d92
3 changed files with 41 additions and 2 deletions

View File

@ -8077,6 +8077,10 @@ do
ENABLED_STATICMEMORY=yes
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_LEAN_STATIC_MEMORY"
;;
debug)
ENABLED_STATICMEMORY=yes
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_DEBUG_MEMORY_CALLBACK"
;;
*)
AC_MSG_ERROR([Invalid choice for staticmemory.])
break;;

View File

@ -1865,6 +1865,38 @@ static int client_srtp_test(WOLFSSL *ssl, func_args *args)
}
#endif /* WOLFSSL_SRTP */
#ifdef WOLFSSL_DEBUG_MEMORY_CALLBACK
static void ExampleDebugMemoryCb(size_t sz, int bucketSz, byte st, int type) {
switch (st) {
case WOLFSSL_DEBUG_MEMORY_ALLOC:
if (type == DYNAMIC_TYPE_IN_BUFFER) {
printf("IN BUFFER: ");
}
if (type == DYNAMIC_TYPE_OUT_BUFFER) {
printf("OUT BUFFER: ");
}
printf("Alloc'd %d bytes using bucket size %d\n", (int)sz,
bucketSz);
break;
case WOLFSSL_DEBUG_MEMORY_FAIL:
printf("Failed when trying to allocate %d bytes\n", (int)sz);
break;
case WOLFSSL_DEBUG_MEMORY_FREE:
printf("Free'ing : %d\n", (int)sz);
break;
case WOLFSSL_DEBUG_MEMORY_INIT:
printf("Creating memory bucket of size : %d\n", bucketSz);
break;
}
}
#endif
THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
{
@ -3045,6 +3077,9 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
err_sys("unable to load static memory");
}
#ifdef WOLFSSL_DEBUG_MEMORY_CALLBACK
wolfSSL_SetDebugMemoryCb(ExampleDebugMemoryCb);
#endif
ctx = wolfSSL_CTX_new_ex(method(heap), heap);
if (ctx == NULL)
err_sys("unable to get ctx");

View File

@ -531,9 +531,9 @@ static DebugMemoryCb DebugCb = NULL;
/* Used to set a debug memory callback. Helpful in cases where
* printf is not available. */
void wolfSSL_SetDebugCallback(DebugMemoryCb in)
void wolfSSL_SetDebugMemoryCb(DebugMemoryCb cb)
{
DebugCb = in;
DebugCb = cb;
}
#endif