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.

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.hu...@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
_______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Reply via email to