[PATCH] record: Add wrappers for malloc() functions
Chris Johns
chrisj at rtems.org
Mon Sep 2 07:00:00 UTC 2019
On 2/9/19 4:11 pm, Sebastian Huber wrote:
> On 02/09/2019 08:00, Chris Johns wrote:
>>>> I do not see any upside adding this library or wrapping specific functions
>>>> this way.
>>> The benefits are:
>>>
>>> * Slightly more compact (the event indicates the function and the data can be
>>> used for the caller address instead, the generic function entry/exit needs two
>>> events for this).
>> Could you please explain this, sorry I am not sure what this means? If the code
>> is what needs to be generated then why not generate?
>
> The record items is defined like this:
>
> /**
> * @brief The record data integer type.
> *
> * It is big enough to store 32-bit integers and pointers.
> */
> typedef unsigned long rtems_record_data;
>
> /**
> * @brief The native record item.
> */
> typedef struct __attribute__((__packed__)) {
> uint32_t event;
> rtems_record_data data;
> } rtems_record_item;
>
> The event member contains a 22-bit time stamp and a 10-bit event number.
>
> The malloc entry/exit wrapper with a special event number looks like this:
>
> void *__wrap_malloc( size_t size )
> {
> void *ptr;
>
> rtems_record_produce_2(
> RTEMS_RECORD_MALLOC_ENTRY,
> (rtems_record_data) RTEMS_RETURN_ADDRESS(),
> RTEMS_RECORD_ARG_0,
> size
> )
> ptr = __real_malloc( size );
> rtems_record_produce_2(
> RTEMS_RECORD_MALLOC_EXIT,
> (rtems_record_data) RTEMS_RETURN_ADDRESS(),
> RTEMS_RECORD_RETURN_0,
> (rtems_record_data) ptr
> )
> return ptr;
> }
>
> If you have to encode the function in the event data, then you need two extra
> items:
>
> void *__wrap_malloc( size_t size )
> {
> rtems_record_item items[ 3 ];
> void *ptr;
>
> items[ 0 ].event = RTEMS_RECORD_FUNCTION_ENTRY;
> items[ 1 ].data = (rtems_record_data) __real_malloc;
> items[ 1 ].event = RTEMS_RECORD_CALLER;
> items[ 1 ].data = (rtems_record_data) RTEMS_RETURN_ADDRESS();
> items[ 2 ].event = RTEMS_RECORD_ARG_0;
> items[ 2 ].data = size;
> rtems_record_produce_n( items, RTEMS_ARRAY_SIZE( items ) );
> ptr = __real_malloc( size );
> items[ 0 ].event = RTEMS_RECORD_FUNCTION_EXIT;
> items[ 1 ].data = (rtems_record_data) __real_malloc;
> items[ 1 ].event = RTEMS_RECORD_CALLER;
> items[ 1 ].data = (rtems_record_data) RTEMS_RETURN_ADDRESS();
> items[ 2 ].event = RTEMS_RECORD_RETURN_0;
> items[ 2 ].data = (rtems_record_data) ptr;
> rtems_record_produce_n( items, RTEMS_ARRAY_SIZE( items ) );
> return ptr;
> }
>
> For this simple one argument function, this is a 50% increase.
>
Why not generate the call to `rtems_record_produce_2`? You should be able to
determine this give you will know there in a single item plus the return address
to record. In fact there is little need for `rtems_record_produce_n` if you have
[1..n] already defined.
Chris
More information about the devel
mailing list