record: Add wrappers for malloc() functions

Introduce new library librtemsrecordwrap.a which contains wrappers for
operating system functions which produce entry/exit events.

The wrappers can be selected during link time via the GNU ld --wrap
option.

Update #3665.
This commit is contained in:
Sebastian Huber
2019-10-01 09:55:07 +02:00
parent 1ea7e3a76e
commit a314544a27
5 changed files with 642 additions and 230 deletions
+5
View File
@@ -1831,6 +1831,11 @@ project_lib_LIBRARIES += librtemsdefaultconfig.a
librtemsdefaultconfig_a_SOURCES =
librtemsdefaultconfig_a_SOURCES += libmisc/dummy/default-configuration.c
project_lib_LIBRARIES += librtemsrecordwrap.a
librtemsrecordwrap_a_SOURCES =
librtemsrecordwrap_a_SOURCES += libtrace/record/record-wrap-malloc.c
project_lib_LIBRARIES += librtemstest.a
librtemstest_a_SOURCES =
+145
View File
@@ -0,0 +1,145 @@
/*
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (C) 2018, 2019 embedded brains GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/record.h>
#include <stdlib.h>
typedef void *Record_Aligned_alloc(size_t, size_t);
Record_Aligned_alloc aligned_alloc;
Record_Aligned_alloc __real_aligned_alloc;
Record_Aligned_alloc __wrap_aligned_alloc;
void *__wrap_aligned_alloc( size_t alignment, size_t size )
{
void *ptr;
rtems_record_entry_2(
RTEMS_RECORD_ALIGNED_ALLOC_ENTRY,
alignment,
size
);
ptr = __real_aligned_alloc( alignment, size );
rtems_record_exit_1(
RTEMS_RECORD_ALIGNED_ALLOC_EXIT,
(rtems_record_data) ptr
);
return ptr;
}
typedef void *Record_Calloc( size_t, size_t );
Record_Calloc calloc;
Record_Calloc __real_calloc;
Record_Calloc __wrap_calloc;
void *__wrap_calloc( size_t nelem, size_t elsize )
{
void *ptr;
rtems_record_entry_2( RTEMS_RECORD_CALLOC_ENTRY, nelem, elsize );
ptr = __real_calloc( nelem, elsize );
rtems_record_exit_1( RTEMS_RECORD_CALLOC_EXIT, (rtems_record_data) ptr );
return ptr;
}
typedef void *Record_Malloc( size_t );
Record_Malloc malloc;
Record_Malloc __real_malloc;
Record_Malloc __wrap_malloc;
void *__wrap_malloc( size_t size )
{
void *ptr;
rtems_record_entry_1( RTEMS_RECORD_MALLOC_ENTRY, size );
ptr = __real_malloc( size );
rtems_record_exit_1( RTEMS_RECORD_MALLOC_EXIT, (rtems_record_data) ptr );
return ptr;
}
typedef void Record_Free( void *ptr );
Record_Free free;
Record_Free __real_free;
Record_Free __wrap_free;
void __wrap_free( void *ptr )
{
rtems_record_entry_1( RTEMS_RECORD_FREE_ENTRY, (rtems_record_data) ptr );
__real_free( ptr );
rtems_record_entry( RTEMS_RECORD_FREE_EXIT );
}
typedef int Record_POSIX_memalign( void **, size_t, size_t );
Record_POSIX_memalign posix_memalign;
Record_POSIX_memalign __real_posix_memalign;
Record_POSIX_memalign __wrap_posix_memalign;
int __wrap_posix_memalign( void **memptr, size_t alignment, size_t size )
{
int eno;
rtems_record_entry_3(
RTEMS_RECORD_POSIX_MEMALIGN_ENTRY,
(rtems_record_data) memptr,
alignment,
size
);
eno = __real_posix_memalign( memptr, alignment, size );
rtems_record_exit_2(
RTEMS_RECORD_POSIX_MEMALIGN_EXIT,
eno,
(rtems_record_data) ( memptr != NULL ? *memptr : NULL )
);
return eno;
}
typedef void *Record_Realloc( void *, size_t );
Record_Realloc realloc;
Record_Realloc __real_realloc;
Record_Realloc __wrap_realloc;
void *__wrap_realloc( void *ptr, size_t size )
{
rtems_record_entry_2(
RTEMS_RECORD_REALLOC_ENTRY,
(rtems_record_data) ptr,
size
);
ptr = __real_realloc( ptr, size );
rtems_record_exit_1( RTEMS_RECORD_REALLOC_EXIT, (rtems_record_data) ptr );
return ptr;
}
+8
View File
@@ -1160,6 +1160,14 @@ lib_docs += record02/record02.doc
record02_SOURCES = record02/init.c
record02_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_record02) \
$(support_includes)
record02_LDADD = $(LDADD) $(RTEMS_ROOT)cpukit/librtemsrecordwrap.a $(LDADD)
record02_LDFLAGS = $(AM_LDFLAGS)
record02_LDFLAGS += -Wl,--wrap=aligned_alloc
record02_LDFLAGS += -Wl,--wrap=calloc
record02_LDFLAGS += -Wl,--wrap=malloc
record02_LDFLAGS += -Wl,--wrap=free
record02_LDFLAGS += -Wl,--wrap=posix_memalign
record02_LDFLAGS += -Wl,--wrap=realloc
endif
if TEST_rtmonuse
+22 -1
View File
@@ -33,6 +33,7 @@
#include <rtems/recordclient.h>
#include <rtems.h>
#include <stdlib.h>
#include <string.h>
#include "tmacros.h"
@@ -94,6 +95,24 @@ static void drain_visitor(
rtems_test_assert(cs == RTEMS_RECORD_CLIENT_SUCCESS);
}
static void call_malloc_functions(void)
{
void *p;
int eno;
p = aligned_alloc(1, 1);
free(p);
p = calloc(1, 1);
free(p);
p = malloc(1);
free(p);
eno = posix_memalign(&p, 32, 32);
rtems_test_assert(eno == 0);
free(p);
p = realloc(NULL, 1);
free(p);
}
static void Init(rtems_task_argument arg)
{
test_context *ctx;
@@ -161,6 +180,8 @@ static void Init(rtems_task_argument arg)
level = rtems_record_interrupt_disable();
rtems_record_interrupt_enable(level);
call_malloc_functions();
rtems_record_client_init(&ctx->client, client_handler, NULL);
size = _Record_Stream_header_initialize(&header);
cs = rtems_record_client_run(&ctx->client, &header, size);
@@ -182,7 +203,7 @@ static void Init(rtems_task_argument arg)
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_RECORD_PER_PROCESSOR_ITEMS 256
#define CONFIGURE_RECORD_PER_PROCESSOR_ITEMS 512
#define CONFIGURE_RECORD_EXTENSIONS_ENABLED
File diff suppressed because it is too large Load Diff