summaryrefslogtreecommitdiffstats
path: root/cpukit/libtrace
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-03-12 18:29:48 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-03-18 07:20:52 +0100
commitab42b3e1002306ed343adc47c460788ed31df66f (patch)
tree9438ff83b8ca107047563a7b63d9edb3f5c94b0d /cpukit/libtrace
parentrtems: Add rtems_put_char() (diff)
downloadrtems-ab42b3e1002306ed343adc47c460788ed31df66f.tar.bz2
record: Add rtems_record_dump()
Add rtems_record_dump_base64() and rtems_record_dump_base64_zlib(). Add CONFIGURE_RECORD_FATAL_DUMP_BASE64 and CONFIGURE_RECORD_FATAL_DUMP_BASE64_ZLIB configuration options. Update #3904.
Diffstat (limited to 'cpukit/libtrace')
-rw-r--r--cpukit/libtrace/record/record-dump-base64.c110
-rw-r--r--cpukit/libtrace/record/record-dump-fatal.c50
-rw-r--r--cpukit/libtrace/record/record-dump-zbase64.c160
-rw-r--r--cpukit/libtrace/record/record-dump-zfatal.c52
-rw-r--r--cpukit/libtrace/record/record-dump.c108
5 files changed, 480 insertions, 0 deletions
diff --git a/cpukit/libtrace/record/record-dump-base64.c b/cpukit/libtrace/record/record-dump-base64.c
new file mode 100644
index 0000000000..618a00414e
--- /dev/null
+++ b/cpukit/libtrace/record/record-dump-base64.c
@@ -0,0 +1,110 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/*
+ * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+ *
+ * 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/recorddump.h>
+#include <rtems/score/io.h>
+
+#include <limits.h>
+#include <string.h>
+
+typedef struct {
+ IO_Put_char put_char;
+ void *arg;
+ int out;
+ size_t index;
+ char buf[ 57 ];
+} dump_context;
+
+static void put_char( int c, void *arg )
+{
+ dump_context *ctx;
+
+ ctx = arg;
+
+ ( *ctx->put_char )( c, ctx->arg );
+ ++ctx->out;
+
+ if ( ctx->out >= 76 ) {
+ ctx->out = 0;
+ ( *ctx->put_char )( '\n', ctx->arg );
+ }
+}
+
+static void chunk( void *arg, const void *data, size_t length )
+{
+ dump_context *ctx;
+ size_t index;
+ const char *in;
+ const void *end;
+
+ ctx = arg;
+ index = ctx->index;
+ in = data;
+ end = in + length;
+
+ while ( in != end ) {
+ ctx->buf[ index ] = *in;
+ ++in;
+
+ if ( index == RTEMS_ARRAY_SIZE( ctx->buf ) - 1 ) {
+ index = 0;
+ _IO_Base64(
+ put_char,
+ ctx,
+ ctx->buf,
+ sizeof( ctx->buf ),
+ NULL,
+ INT_MAX
+ );
+ } else {
+ ++index;
+ }
+ }
+
+ ctx->index = index;
+}
+
+static void flush( dump_context *ctx )
+{
+ _IO_Base64( put_char, ctx, ctx->buf, ctx->index, NULL, INT_MAX );
+}
+
+void rtems_record_dump_base64( IO_Put_char put_char, void *arg )
+{
+ dump_context ctx;
+
+ memset( &ctx, 0, sizeof( ctx ) );
+ ctx.put_char = put_char;
+ ctx.arg = arg;
+
+ rtems_record_dump( chunk, &ctx );
+ flush( &ctx );
+}
diff --git a/cpukit/libtrace/record/record-dump-fatal.c b/cpukit/libtrace/record/record-dump-fatal.c
new file mode 100644
index 0000000000..e50913cb7d
--- /dev/null
+++ b/cpukit/libtrace/record/record-dump-fatal.c
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/*
+ * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+ *
+ * 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/recorddump.h>
+#include <rtems/bspIo.h>
+
+void _Record_Fatal_dump_base64(
+ Internal_errors_Source source,
+ bool always_set_to_false,
+ Internal_errors_t code
+)
+{
+ rtems_record_produce_2(
+ RTEMS_RECORD_FATAL_SOURCE,
+ source,
+ RTEMS_RECORD_FATAL_CODE,
+ code
+ );
+ printk( "\n*** BEGIN OF RECORDS BASE64 ***\n" );
+ rtems_record_dump_base64( rtems_put_char, NULL );
+ printk( "\n*** END OF RECORDS BASE64 ***\n" );
+}
diff --git a/cpukit/libtrace/record/record-dump-zbase64.c b/cpukit/libtrace/record/record-dump-zbase64.c
new file mode 100644
index 0000000000..08b4d92c53
--- /dev/null
+++ b/cpukit/libtrace/record/record-dump-zbase64.c
@@ -0,0 +1,160 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/*
+ * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+ *
+ * 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/recorddump.h>
+#include <rtems/score/io.h>
+
+#include <limits.h>
+#include <string.h>
+
+static void *dump_zalloc( void *opaque, unsigned items, unsigned size )
+{
+ rtems_record_dump_base64_zlib_context *ctx;
+ char *mem_begin;
+ size_t mem_available;
+
+ ctx = opaque;
+ size *= items;
+ mem_available = ctx->mem_available;
+
+ if ( mem_available < size ) {
+ return NULL;
+ }
+
+ mem_begin = ctx->mem_begin;
+ ctx->mem_begin = mem_begin + size;
+ ctx->mem_available = mem_available - size;
+ return mem_begin;
+}
+
+static void dump_zfree( void *opaque, void *ptr )
+{
+ (void) opaque;
+ (void) ptr;
+}
+
+static void put_char( int c, void *arg )
+{
+ rtems_record_dump_base64_zlib_context *ctx;
+
+ ctx = arg;
+
+ ( *ctx->put_char )( c, ctx->arg );
+ ++ctx->out;
+
+ if ( ctx->out >= 76 ) {
+ ctx->out = 0;
+ ( *ctx->put_char )( '\n', ctx->arg );
+ }
+}
+
+static void chunk( void *arg, const void *data, size_t length )
+{
+ rtems_record_dump_base64_zlib_context *ctx;
+
+ ctx = arg;
+ ctx->stream.next_in = RTEMS_DECONST( void *, data );
+ ctx->stream.avail_in = length;
+
+ while ( ctx->stream.avail_in > 0 ) {
+ int err;
+
+ err = deflate( &ctx->stream, Z_NO_FLUSH );
+ if ( err != Z_OK ) {
+ return;
+ }
+
+ if ( ctx->stream.avail_out == 0 ) {
+ ctx->stream.next_out = &ctx->buf[ 0 ];
+ ctx->stream.avail_out = sizeof( ctx->buf );
+
+ _IO_Base64( put_char, ctx, ctx->buf, sizeof( ctx->buf ), NULL, INT_MAX );
+ }
+ }
+}
+
+static void flush( rtems_record_dump_base64_zlib_context *ctx )
+{
+ while ( true ) {
+ int err;
+
+ err = deflate( &ctx->stream, Z_FINISH );
+ if ( err != Z_OK ) {
+ break;
+ }
+
+ if ( ctx->stream.avail_out == 0 ) {
+ ctx->stream.next_out = &ctx->buf[ 0 ];
+ ctx->stream.avail_out = sizeof( ctx->buf );
+
+ _IO_Base64( put_char, ctx, ctx->buf, sizeof( ctx->buf ), NULL, INT_MAX );
+ }
+ }
+
+ _IO_Base64(
+ put_char,
+ ctx,
+ ctx->buf,
+ sizeof( ctx->buf ) - ctx->stream.avail_out,
+ NULL,
+ INT_MAX
+ );
+}
+
+void rtems_record_dump_zlib_base64(
+ rtems_record_dump_base64_zlib_context *ctx,
+ void ( *put_char )( int, void * ),
+ void *arg
+)
+{
+ int err;
+
+ ctx->put_char = put_char;
+ ctx->arg = arg;
+ ctx->out = 0;
+ ctx->stream.zalloc = dump_zalloc;
+ ctx->stream.zfree = dump_zfree;
+ ctx->stream.opaque = ctx;
+ ctx->mem_begin = &ctx->mem[ 0 ];
+ ctx->mem_available = sizeof( ctx->mem );
+
+ err = deflateInit( &ctx->stream, Z_BEST_COMPRESSION );
+ if (err != Z_OK) {
+ return;
+ }
+
+ ctx->stream.next_out = &ctx->buf[ 0 ];
+ ctx->stream.avail_out = sizeof( ctx->buf );
+
+ rtems_record_dump( chunk, ctx );
+ flush( ctx );
+ deflateEnd( &ctx->stream );
+}
diff --git a/cpukit/libtrace/record/record-dump-zfatal.c b/cpukit/libtrace/record/record-dump-zfatal.c
new file mode 100644
index 0000000000..8002e7a8f6
--- /dev/null
+++ b/cpukit/libtrace/record/record-dump-zfatal.c
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/*
+ * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+ *
+ * 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/recorddump.h>
+#include <rtems/bspIo.h>
+
+static rtems_record_dump_base64_zlib_context context;
+
+void _Record_Fatal_dump_base64_zlib(
+ Internal_errors_Source source,
+ bool always_set_to_false,
+ Internal_errors_t code
+)
+{
+ rtems_record_produce_2(
+ RTEMS_RECORD_FATAL_SOURCE,
+ source,
+ RTEMS_RECORD_FATAL_CODE,
+ code
+ );
+ printk( "\n*** BEGIN OF RECORDS BASE64 ZLIB ***\n" );
+ rtems_record_dump_zlib_base64( &context, rtems_put_char, NULL );
+ printk( "\n*** END OF RECORDS BASE64 ZLIB ***\n" );
+}
diff --git a/cpukit/libtrace/record/record-dump.c b/cpukit/libtrace/record/record-dump.c
new file mode 100644
index 0000000000..b3c757226a
--- /dev/null
+++ b/cpukit/libtrace/record/record-dump.c
@@ -0,0 +1,108 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/*
+ * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+ *
+ * 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/recorddump.h>
+#include <rtems/score/threadimpl.h>
+
+typedef struct {
+ rtems_record_dump_chunk chunk;
+ void *arg;
+} dump_context;
+
+static void dump_chunk( dump_context *ctx, const void *data, size_t length )
+{
+ ( *ctx->chunk )( ctx->arg, data, length );
+}
+
+static bool thread_names_visitor( rtems_tcb *tcb, void *arg )
+{
+ dump_context *ctx;
+ char name[ 2 * THREAD_DEFAULT_MAXIMUM_NAME_SIZE ];
+ size_t n;
+ size_t i;
+ rtems_record_item item;
+ rtems_record_data data;
+
+ ctx = arg;
+ item.event = RTEMS_RECORD_THREAD_ID;
+ item.data = tcb->Object.id;
+ dump_chunk( ctx, &item, sizeof( item ) );
+
+ n = _Thread_Get_name( tcb, name, sizeof( name ) );
+ i = 0;
+
+ while ( i < n ) {
+ size_t j;
+
+ data = 0;
+
+ for ( j = 0; i < n && j < sizeof( data ); ++j ) {
+ rtems_record_data c;
+
+ c = (unsigned char) name[ i ];
+ data |= c << ( j * 8 );
+ ++i;
+ }
+
+ item.event = RTEMS_RECORD_THREAD_NAME;
+ item.data = data;
+ dump_chunk( ctx, &item, sizeof( item ) );
+ }
+
+ return false;
+}
+
+static void drain_visitor(
+ const rtems_record_item *items,
+ size_t count,
+ void *arg
+)
+{
+ dump_chunk( arg, items, count * sizeof( *items ) );
+}
+
+void rtems_record_dump(
+ rtems_record_dump_chunk chunk,
+ void *arg
+)
+{
+ Record_Stream_header header;
+ size_t size;
+ dump_context ctx;
+
+ ctx.chunk = chunk;
+ ctx.arg = arg;
+
+ size = _Record_Stream_header_initialize( &header );
+ dump_chunk( &ctx, &header, size );
+ rtems_task_iterate( thread_names_visitor, &ctx );
+ rtems_record_drain( drain_visitor, &ctx );
+}