-/tests/test-bitfield
*~
+/tests/lib/test-bitfield
/tests/lib/test-seeks
*.o
*.a
bindings/python/babeltrace.i
bindings/python/babeltrace.py
bindings/python/babeltrace_wrap.c
+babeltrace.pc
+2013-06-18 Babeltrace 1.1.1
+ * Compare traces by stream path as secondary key
+ * Fix: use index, not cur_index, for SEEK_SET validation
+ * Fix: ctf-text irregular output with disabled field names
+ * Support old compilers
+ * Remove useless variable assignment
+ * Fix: Remove extra quote after an include directive
+ * Don't dereference before NULL check
+ * eliminate dead code
+ * fix babeltrace-log error checking
+ * Fix resource leak on error path
+ * Fix: handle error checking should compare against NULL
+ * Remove unused array in bt_context_add_traces_recursive
+ * Fix: Suppress a compiler warning (always-false condition)
+ * Cleanup: remove trailing whitespaces
+ * Move memstream.h and uuid.h to include/babeltrace/compat directory
+ * Fix: handling of empty streams
+ * Add new option --clock-offset-ns
+ * Fix: add missing error return when create_event_definitions fails
+ * Fix: ctf-text should link on libbabeltrace-ctf
+ * Move clock to bt_trace_descriptor
+ * Remove unused stream_heap
+ * Move trace collection pointer to bt_trace_descriptor
+ * Move bt_handle to bt_trace_descriptor
+ * Move bt_context to bt_trace_descriptor
+ * Privatize struct bt_trace descriptor, move trace path
+ * Add backward ref from bt_stream_pos to bt_trace_descriptor
+ * Fix kFreeBSD build
+ * Fix: babeltrace-log timestamps should be in nsec
+ * Use objstack for AST allocation
+ * Remove unused gc field
+ * Use objstack to store nodes
+ * Use objstack for strings
+ * Implement objstack for parser
+ * Fix: octal and hex string handling
+ * Simplify error node
+ * Lexer cleanup
+ * Fix: invalid integer suffix parsing
+ * Test cleanup
+ * Test cleanup
+ * Test cleanup
+ * Fix: bootstrap should call libtoolize
+ * Fix bootstrap script
+ * Use uint64_t for packet_map_len
+ * Add smalltrace succeed/fail test cases
+ * Support packets and trace files smaller than page size
+ * Move ctf-metadata plugin into its own shared object
+ * Implement ctf-metadata output plugin
+ * Handle make_node errors with TLS dummy node
+ * Remove nested expressions
+ * Eliminate dead code
+ * Fix: trace_collection_add() add after check
+ * Handle integers in lexer rather than grammar
+ * Implement perror printf
+ * Support escape characters in metadata strings
+ * Add error node to AST
+ * Introduce macro to enforce matching enum to string for node types
+ * Fix: add semantic check in grammar
+ * Implement likely/unlikely ifdefs
+ * Fix unary constant use after error
+ * Use new print macros in ctf-parser.y
+ * Print error on invalid token
+ * Implement macros for error printout
+ * Add line number to parser nodes
+ * Fix: handle errors gracefully
+ * Fix: memleak on error path
+ * Add missing NULL pointer check
+ * Show token in CTF parser error
+ * Remove unused lineno from struct ctf_scanner
+ * Show line numbers in CTF parser errors
+ * Ignore Windows-style EOL character in metadata
+ * Replace AM_PROG_MKDIR obsolete macro with AC_PROG_MKDIR_P
+
+2013-03-23 Babeltrace 1.1.0
+ * Reinsert "at end of stream" message for discarded events
+ * Improvement: Message from babeltrace concerning discarded events needs i
+ * Cleanup: typo fix
+ * Cleanup: add end of line at end of verbose message
+ * Fix: misleading message from babeltrace --verbose
+ * Fix: babeltrace --fields all overrides --no-delta
+ * Add verbosity to stream id error message
+ * Fix: Ensure the specified input format is CTF
+ * Fix: Undefined behavior of double free on strlist in get_names_args
+ * Fix: ctf-text: don't close stdout
+ * Fix: warning message for unexpected trace byte order
+ * Namespace the struct declaration
+ * Namespace the struct definition
+ * Namespace the struct format
+ * Namespace the struct mmap_stream
+ * Namespace the struct trace_descriptor
+ * Namespace struct stream_pos
+ * Namespace compliance for dependencies function
+ * Cleanup error messages
+ * Fix: babeltrace: make '-w' actually work
+ * Convert the unit tests to the TAP format
+ * Spelling cleanups within comments
+ * Move the bitfield test to tests/lib/
+ * Fix: Added a null pointer check to bt_ctf_field_name
+ * Add babeltrace.pc to gitignore
+ * namespacing: place flex/bison symbols under bt_yy namespace
+ * namespace the lookup_integer function
+ * namespace the definition functions
+ * namespace the variant functions
+ * namespace the declaration functions
+ * namespace the collection functions
+ * namespace the heap functions
+ * namespace the struct functions
+ * namespace the string functions
+ * namespace the sequence functions
+ * namespace the int functions
+ * namespace the enum functions
+ * namespace definition_ref and definition_unref
+ * namespace declaration_ref and declaration_unref
+ * namespace the array functions
+ * namespace the scope_path functions
+ * Hide internal functions of libbabeltrace-ctf
+ * Hide internal functions of ctf-text
+ * BT_HIDDEN macro
+ * Namespace the lookup_enum function
+
+2012-01-24 Babeltrace 1.0.3
+ * Fix: Double free when calling bt_context_remove_trace()
+ * Add missing runall.sh to dist packaging
+ * Fix: alignment of compound types containing array field
+
2012-01-11 Babeltrace 1.0.2
* Fix: add tests/lib missing files to Makefile.am
if [ ! -e config ]; then
mkdir config
fi
-aclocal -I m4
-libtoolize --force --copy
-autoheader
-automake --add-missing --copy
-autoconf
+libtoolize --force --copy
+autoreconf -i
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
-AC_INIT([babeltrace],[1.0.2],[mathieu dot desnoyers at efficios dot com])
+AC_INIT([babeltrace],[1.1.1],[mathieu dot desnoyers at efficios dot com])
AC_CONFIG_AUX_DIR([config])
AC_CANONICAL_TARGET
AC_CANONICAL_HOST
AC_CONFIG_MACRO_DIR([m4])
-AM_PROG_MKDIR_P
+AC_PROG_MKDIR_P
AC_CONFIG_HEADERS([config.h])
AC_SYS_LARGEFILE
# Checks for programs.
-AC_PROG_CC
+AC_PROG_CC_STDC
AC_PROG_MAKE_SET
LT_INIT
AC_PROG_YACC
formats/ctf/types/Makefile
formats/ctf-text/Makefile
formats/ctf-text/types/Makefile
+ formats/ctf-metadata/Makefile
formats/bt-dummy/Makefile
formats/ctf/metadata/Makefile
converter/Makefile
$(top_builddir)/lib/libbabeltrace.la \
$(top_builddir)/formats/ctf/libbabeltrace-ctf.la \
$(top_builddir)/formats/ctf-text/libbabeltrace-ctf-text.la \
+ $(top_builddir)/formats/ctf-metadata/libbabeltrace-ctf-metadata.la \
$(top_builddir)/formats/bt-dummy/libbabeltrace-dummy.la
babeltrace_log_SOURCES = babeltrace-log.c
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/ctf/types.h>
-#include <babeltrace/uuid.h>
+#include <babeltrace/compat/uuid.h>
+#include <babeltrace/compat/utc.h>
#include <babeltrace/endian.h>
+#define NSEC_PER_USEC 1000UL
+#define NSEC_PER_MSEC 1000000UL
+#define NSEC_PER_SEC 1000000000ULL
#define USEC_PER_SEC 1000000UL
int babeltrace_debug, babeltrace_verbose;
ctf_align_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
ctf_move_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
assert(!ctf_pos_packet(&dummy));
-
+
ctf_align_pos(pos, sizeof(uint32_t) * CHAR_BIT);
*(uint32_t *) ctf_get_pos_addr(pos) = 0xC1FC1FC1;
ctf_move_pos(pos, sizeof(uint32_t) * CHAR_BIT);
ctf_align_pos(&dummy, sizeof(uint64_t) * CHAR_BIT);
ctf_move_pos(&dummy, sizeof(uint64_t) * CHAR_BIT);
assert(!ctf_pos_packet(&dummy));
-
+
ctf_align_pos(pos, sizeof(uint64_t) * CHAR_BIT);
*(uint64_t *) ctf_get_pos_addr(pos) = ~0ULL; /* Not known yet */
pos->content_size_loc = (uint64_t *) ctf_get_pos_addr(pos);
ctf_align_pos(&dummy, sizeof(uint64_t) * CHAR_BIT);
ctf_move_pos(&dummy, sizeof(uint64_t) * CHAR_BIT);
assert(!ctf_pos_packet(&dummy));
-
+
ctf_align_pos(pos, sizeof(uint64_t) * CHAR_BIT);
*(uint64_t *) ctf_get_pos_addr(pos) = pos->packet_size;
ctf_move_pos(pos, sizeof(uint64_t) * CHAR_BIT);
char **tline, size_t len, size_t *tlen,
uint64_t *ts)
{
- unsigned long sec, usec;
-
if (!s_timestamp)
return;
/* Only need to be executed on first pass (dummy) */
- if (pos->dummy) {
- int ret;
+ if (pos->dummy) {
+ int has_timestamp = 0;
+ unsigned long sec, usec, msec;
+ unsigned int year, mon, mday, hour, min;
/* Extract time from input line */
- ret = sscanf(line, "[%lu.%lu] ", &sec, &usec);
- if (ret == 2) {
+ if (sscanf(line, "[%lu.%lu] ", &sec, &usec) == 2) {
+ *ts = (uint64_t) sec * USEC_PER_SEC + (uint64_t) usec;
+ /*
+ * Default CTF clock has 1GHz frequency. Convert
+ * from usec to nsec.
+ */
+ *ts *= NSEC_PER_USEC;
+ has_timestamp = 1;
+ } else if (sscanf(line, "[%u-%u-%u %u:%u:%lu.%lu] ",
+ &year, &mon, &mday, &hour, &min,
+ &sec, &msec) == 7) {
+ time_t ep_sec;
+ struct tm ti;
+
+ memset(&ti, 0, sizeof(ti));
+ ti.tm_year = year - 1900; /* from 1900 */
+ ti.tm_mon = mon - 1; /* 0 to 11 */
+ ti.tm_mday = mday;
+ ti.tm_hour = hour;
+ ti.tm_min = min;
+ ti.tm_sec = sec;
+
+ ep_sec = babeltrace_timegm(&ti);
+ if (ep_sec != (time_t) -1) {
+ *ts = (uint64_t) ep_sec * NSEC_PER_SEC
+ + (uint64_t) msec * NSEC_PER_MSEC;
+ }
+ has_timestamp = 1;
+ }
+ if (has_timestamp) {
*tline = strchr(line, ']');
assert(*tline);
(*tline)++;
(*tline)++;
}
*tlen = len + line - *tline;
- *ts = (uint64_t) sec * USEC_PER_SEC + (uint64_t) usec;
}
}
/* timestamp */
int ret;
memset(&pos, 0, sizeof(pos));
- ret = ctf_init_pos(&pos, output, O_RDWR);
+ ret = ctf_init_pos(&pos, NULL, output, O_RDWR);
if (ret) {
fprintf(stderr, "Error in ctf_init_pos\n");
return;
fprintf(fp, " OUTPUT Output trace path\n");
fprintf(fp, "\n");
fprintf(fp, " -t With timestamps (format: [sec.usec] string\\n)\n");
+ fprintf(fp, " (format: [YYYY-MM-DD HH:MM:SS.MS] string\\n)\n");
fprintf(fp, "\n");
}
metadata_fd = openat(dir_fd, "metadata", O_RDWR|O_CREAT,
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
- if (fd < 0) {
+ if (metadata_fd < 0) {
perror("openat");
goto error_closedatastream;
}
#include <babeltrace/babeltrace.h>
#include <babeltrace/format.h>
#include <babeltrace/context.h>
+#include <babeltrace/context-internal.h>
#include <babeltrace/ctf/types.h>
#include <babeltrace/ctf/events.h>
/* TODO: fix object model for format-agnostic callbacks */
static GPtrArray *opt_input_paths;
static char *opt_output_path;
-static struct format *fmt_read;
+static struct bt_format *fmt_read;
static
void strlower(char *str)
OPT_FIELDS,
OPT_NO_DELTA,
OPT_CLOCK_OFFSET,
+ OPT_CLOCK_OFFSET_NS,
OPT_CLOCK_CYCLES,
OPT_CLOCK_SECONDS,
OPT_CLOCK_DATE,
*/
static struct poptOption long_options[] = {
/* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
- { "output", 'w', POPT_ARG_STRING, NULL, OPT_NONE, NULL, NULL },
+ { "output", 'w', POPT_ARG_STRING, NULL, OPT_OUTPUT_PATH, NULL, NULL },
{ "input-format", 'i', POPT_ARG_STRING, NULL, OPT_INPUT_FORMAT, NULL, NULL },
{ "output-format", 'o', POPT_ARG_STRING, NULL, OPT_OUTPUT_FORMAT, NULL, NULL },
{ "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL },
{ "fields", 'f', POPT_ARG_STRING, NULL, OPT_FIELDS, NULL, NULL },
{ "no-delta", 0, POPT_ARG_NONE, NULL, OPT_NO_DELTA, NULL, NULL },
{ "clock-offset", 0, POPT_ARG_STRING, NULL, OPT_CLOCK_OFFSET, NULL, NULL },
+ { "clock-offset-ns", 0, POPT_ARG_STRING, NULL, OPT_CLOCK_OFFSET_NS, NULL, NULL },
{ "clock-cycles", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_CYCLES, NULL, NULL },
{ "clock-seconds", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_SECONDS, NULL, NULL },
{ "clock-date", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_DATE, NULL, NULL },
fprintf(fp, " (default: trace:hostname,trace:procname,trace:vpid)\n");
fprintf(fp, " --clock-cycles Timestamp in cycles\n");
fprintf(fp, " --clock-offset seconds Clock offset in seconds\n");
+ fprintf(fp, " --clock-offset-ns ns Clock offset in nanoseconds\n");
fprintf(fp, " --clock-seconds Print the timestamps as [sec.ns]\n");
fprintf(fp, " (default is: [hh:mm:ss.ns])\n");
fprintf(fp, " --clock-date Print clock date\n");
opt_payload_field_names = 0;
} else {
fprintf(stderr, "[error] unknown field name type %s\n", str);
- free(strlist);
ret = -EINVAL;
goto end;
}
case OPT_CLOCK_SECONDS:
opt_clock_seconds = 1;
break;
+ case OPT_CLOCK_OFFSET_NS:
+ {
+ char *str;
+ char *endptr;
+
+ str = (char *) poptGetOptArg(pc);
+ if (!str) {
+ fprintf(stderr, "[error] Missing --clock-offset-ns argument\n");
+ ret = -EINVAL;
+ goto end;
+ }
+ errno = 0;
+ opt_clock_offset_ns = strtoull(str, &endptr, 0);
+ if (*endptr != '\0' || str == endptr || errno != 0) {
+ fprintf(stderr, "[error] Incorrect --clock-offset-ns argument: %s\n", str);
+ ret = -EINVAL;
+ free(str);
+ goto end;
+ }
+ free(str);
+ break;
+ }
+
case OPT_CLOCK_DATE:
opt_clock_date = 1;
break;
/* No meta data, just return */
return 0;
} else {
+ int err_close = 0;
+
closeret = close(metafd);
if (closeret < 0) {
perror("close");
- return -1; /* failure */
+ err_close = 1;
}
closeret = close(dirfd);
if (closeret < 0) {
perror("close");
- return -1; /* failure */
+ err_close = 1;
+ }
+ if (err_close) {
+ return -1;
}
/* Add path to the global list */
*/
int bt_context_add_traces_recursive(struct bt_context *ctx, const char *path,
const char *format_str,
- void (*packet_seek)(struct stream_pos *pos,
+ void (*packet_seek)(struct bt_stream_pos *pos,
size_t offset, int whence))
{
-
- GArray *trace_ids;
- int ret = 0;
+ int ret = 0, trace_ids = 0;
/* Should lock traversed_paths mutex here if used in multithread */
traversed_paths = g_ptr_array_new();
- trace_ids = g_array_new(FALSE, TRUE, sizeof(int));
-
ret = nftw(path, traverse_trace_dir, 10, 0);
/* Process the array if ntfw did not return a fatal error */
/* Allow to skip erroneous traces. */
ret = 1; /* partial error */
} else {
- g_array_append_val(trace_ids, trace_id);
+ trace_ids++;
}
g_string_free(trace_path, TRUE);
}
/*
* Return an error if no trace can be opened.
*/
- if (trace_ids->len == 0) {
+ if (trace_ids == 0) {
fprintf(stderr, "[error] Cannot open any trace for reading.\n\n");
ret = -ENOENT; /* failure */
}
- g_array_free(trace_ids, TRUE);
return ret;
}
-int convert_trace(struct trace_descriptor *td_write,
+static
+int trace_pre_handler(struct bt_trace_descriptor *td_write,
+ struct bt_context *ctx)
+{
+ struct ctf_text_stream_pos *sout;
+ struct trace_collection *tc;
+ int ret, i;
+
+ sout = container_of(td_write, struct ctf_text_stream_pos,
+ trace_descriptor);
+
+ if (!sout->parent.pre_trace_cb)
+ return 0;
+
+ tc = ctx->tc;
+ for (i = 0; i < tc->array->len; i++) {
+ struct bt_trace_descriptor *td =
+ g_ptr_array_index(tc->array, i);
+
+ ret = sout->parent.pre_trace_cb(&sout->parent, td);
+ if (ret) {
+ fprintf(stderr, "[error] Writing to trace pre handler failed.\n");
+ goto end;
+ }
+ }
+ ret = 0;
+end:
+ return ret;
+}
+
+static
+int trace_post_handler(struct bt_trace_descriptor *td_write,
+ struct bt_context *ctx)
+{
+ struct ctf_text_stream_pos *sout;
+ struct trace_collection *tc;
+ int ret, i;
+
+ sout = container_of(td_write, struct ctf_text_stream_pos,
+ trace_descriptor);
+
+ if (!sout->parent.post_trace_cb)
+ return 0;
+
+ tc = ctx->tc;
+ for (i = 0; i < tc->array->len; i++) {
+ struct bt_trace_descriptor *td =
+ g_ptr_array_index(tc->array, i);
+
+ ret = sout->parent.post_trace_cb(&sout->parent, td);
+ if (ret) {
+ fprintf(stderr, "[error] Writing to trace post handler failed.\n");
+ goto end;
+ }
+ }
+ ret = 0;
+end:
+ return ret;
+}
+
+static
+int convert_trace(struct bt_trace_descriptor *td_write,
struct bt_context *ctx)
{
struct bt_ctf_iter *iter;
sout = container_of(td_write, struct ctf_text_stream_pos,
trace_descriptor);
+ if (!sout->parent.event_cb)
+ return 0;
+
begin_pos.type = BT_SEEK_BEGIN;
iter = bt_ctf_iter_create(ctx, &begin_pos, NULL);
if (!iter) {
int main(int argc, char **argv)
{
int ret, partial_error = 0, open_success = 0;
- struct format *fmt_write;
- struct trace_descriptor *td_write;
+ struct bt_format *fmt_write;
+ struct bt_trace_descriptor *td_write;
struct bt_context *ctx;
int i;
}
printf_verbose("Converting from format: %s\n",
opt_input_format ? : "ctf <default>");
- printf_verbose("Converting to directory: %s\n",
+ printf_verbose("Converting to target: %s\n",
opt_output_path ? : "<stdout>");
printf_verbose("Converting to format: %s\n",
opt_output_format ? : "text <default>");
}
}
fmt_read = bt_lookup_format(g_quark_from_static_string(opt_input_format));
- if (!fmt_read) {
+ if (!fmt_read || fmt_read->name != g_quark_from_static_string("ctf")) {
fprintf(stderr, "[error] Format \"%s\" is not supported.\n\n",
opt_input_format);
partial_error = 1;
if (partial_error)
sleep(PARTIAL_ERROR_SLEEP);
+ ret = trace_pre_handler(td_write, ctx);
+ if (ret) {
+ fprintf(stderr, "Error in trace pre handle.\n\n");
+ goto error_copy_trace;
+ }
+
ret = convert_trace(td_write, ctx);
if (ret) {
fprintf(stderr, "Error printing trace.\n\n");
goto error_copy_trace;
}
+ ret = trace_post_handler(td_write, ctx);
+ if (ret) {
+ fprintf(stderr, "Error in trace post handle.\n\n");
+ goto error_copy_trace;
+ }
+
fmt_write->close_trace(td_write);
bt_context_put(ctx);
Output trace path (default: stdout)
.TP
.BR "-i, --input-format FORMAT"
-Input trace format (default: ctf)
+Input trace format (default: ctf). CTF is currently the only supported input format.
.TP
.BR "-o, --output-format FORMAT"
Output trace format (default: text)
AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
-SUBDIRS = . ctf ctf-text bt-dummy
+SUBDIRS = . ctf ctf-text ctf-metadata bt-dummy
#include <stdlib.h>
static
-int bt_dummy_write_event(struct stream_pos *ppos, struct ctf_stream_definition *stream)
+int bt_dummy_write_event(struct bt_stream_pos *ppos, struct ctf_stream_definition *stream)
{
return 0;
}
static
-struct trace_descriptor *bt_dummy_open_trace(const char *path, int flags,
- void (*packet_seek)(struct stream_pos *pos, size_t index,
+struct bt_trace_descriptor *bt_dummy_open_trace(const char *path, int flags,
+ void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence), FILE *metadata_fp)
{
struct ctf_text_stream_pos *pos;
pos = g_new0(struct ctf_text_stream_pos, 1);
pos->parent.rw_table = NULL;
pos->parent.event_cb = bt_dummy_write_event;
+ pos->parent.trace = &pos->trace_descriptor;
return &pos->trace_descriptor;
}
static
-int bt_dummy_close_trace(struct trace_descriptor *td)
+int bt_dummy_close_trace(struct bt_trace_descriptor *td)
{
struct ctf_text_stream_pos *pos =
container_of(td, struct ctf_text_stream_pos,
}
static
-struct format bt_dummy_format = {
+struct bt_format bt_dummy_format = {
.open_trace = bt_dummy_open_trace,
.close_trace = bt_dummy_close_trace,
};
--- /dev/null
+AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
+
+lib_LTLIBRARIES = libbabeltrace-ctf-metadata.la
+
+libbabeltrace_ctf_metadata_la_SOURCES = \
+ ctf-metadata.c
+
+libbabeltrace_ctf_metadata_la_LDFLAGS = \
+ -Wl,--no-as-needed
+
+libbabeltrace_ctf_metadata_la_LIBADD = \
+ $(top_builddir)/lib/libbabeltrace.la
--- /dev/null
+/*
+ * BabelTrace - Common Trace Format (CTF)
+ *
+ * CTF Metadata Dump.
+ *
+ * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
+ *
+ * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <babeltrace/format.h>
+#include <babeltrace/ctf-text/types.h>
+#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/ctf/events-internal.h>
+#include <inttypes.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <glib.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+static
+struct bt_trace_descriptor *ctf_metadata_open_trace(const char *path, int flags,
+ void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
+ int whence), FILE *metadata_fp);
+static
+int ctf_metadata_close_trace(struct bt_trace_descriptor *descriptor);
+
+static
+struct bt_format ctf_metadata_format = {
+ .open_trace = ctf_metadata_open_trace,
+ .close_trace = ctf_metadata_close_trace,
+};
+
+static
+int ctf_metadata_trace_pre_handler(struct bt_stream_pos *ppos,
+ struct bt_trace_descriptor *td)
+{
+ struct ctf_text_stream_pos *pos =
+ container_of(ppos, struct ctf_text_stream_pos, parent);
+ struct ctf_trace *trace;
+
+ trace = container_of(td, struct ctf_trace, parent);
+ if (!trace->metadata_string)
+ return -EINVAL;
+ if (trace->metadata_packetized) {
+ fprintf(pos->fp, "/* CTF %u.%u */\n",
+ BT_CTF_MAJOR, BT_CTF_MINOR);
+ }
+ fprintf(pos->fp, "%s", trace->metadata_string);
+ return 0;
+}
+
+static
+struct bt_trace_descriptor *ctf_metadata_open_trace(const char *path, int flags,
+ void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
+ int whence), FILE *metadata_fp)
+{
+ struct ctf_text_stream_pos *pos;
+ FILE *fp;
+
+ pos = g_new0(struct ctf_text_stream_pos, 1);
+
+ pos->last_real_timestamp = -1ULL;
+ pos->last_cycles_timestamp = -1ULL;
+ switch (flags & O_ACCMODE) {
+ case O_RDWR:
+ if (!path)
+ fp = stdout;
+ else
+ fp = fopen(path, "w");
+ if (!fp)
+ goto error;
+ pos->fp = fp;
+ pos->parent.pre_trace_cb = ctf_metadata_trace_pre_handler;
+ pos->parent.trace = &pos->trace_descriptor;
+ pos->print_names = 0;
+ break;
+ case O_RDONLY:
+ default:
+ fprintf(stderr, "[error] Incorrect open flags.\n");
+ goto error;
+ }
+
+ return &pos->trace_descriptor;
+error:
+ g_free(pos);
+ return NULL;
+}
+
+static
+int ctf_metadata_close_trace(struct bt_trace_descriptor *td)
+{
+ int ret;
+ struct ctf_text_stream_pos *pos =
+ container_of(td, struct ctf_text_stream_pos, trace_descriptor);
+ if (pos->fp != stdout) {
+ ret = fclose(pos->fp);
+ if (ret) {
+ perror("Error on fclose");
+ return -1;
+ }
+ }
+ g_free(pos);
+ return 0;
+}
+
+static
+void __attribute__((constructor)) ctf_metadata_init(void)
+{
+ int ret;
+
+ ctf_metadata_format.name = g_quark_from_static_string("ctf-metadata");
+ ret = bt_register_format(&ctf_metadata_format);
+ assert(!ret);
+}
+
+static
+void __attribute__((destructor)) ctf_metadata_exit(void)
+{
+ bt_unregister_format(&ctf_metadata_format);
+}
types/libctf-text-types.la
libbabeltrace_ctf_text_la_LIBADD = \
- $(top_builddir)/lib/libbabeltrace.la
+ $(top_builddir)/lib/libbabeltrace.la \
+ $(top_builddir)/formats/ctf/libbabeltrace-ctf.la
};
static
-struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
- void (*packet_seek)(struct stream_pos *pos, size_t index,
+struct bt_trace_descriptor *ctf_text_open_trace(const char *path, int flags,
+ void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence), FILE *metadata_fp);
static
-int ctf_text_close_trace(struct trace_descriptor *descriptor);
+int ctf_text_close_trace(struct bt_trace_descriptor *descriptor);
static
rw_dispatch write_dispatch_table[] = {
};
static
-struct format ctf_text_format = {
+struct bt_format ctf_text_format = {
.open_trace = ctf_text_open_trace,
.close_trace = ctf_text_close_trace,
};
(gpointer) (unsigned long) callsite_name);
}
-int print_field(struct definition *definition)
+int print_field(struct bt_definition *definition)
{
/* Print all fields in verbose mode */
if (babeltrace_verbose)
}
static
-int ctf_text_write_event(struct stream_pos *ppos, struct ctf_stream_definition *stream)
+int ctf_text_write_event(struct bt_stream_pos *ppos, struct ctf_stream_definition *stream)
{
struct ctf_text_stream_pos *pos =
/* Print events discarded */
if (stream->events_discarded) {
fflush(pos->fp);
- fprintf(stderr, "[warning] Tracer discarded %" PRIu64 " events between [",
- stream->events_discarded);
- if (opt_clock_cycles) {
- ctf_print_timestamp(stderr, stream,
- stream->prev_cycles_timestamp);
- fprintf(stderr, "] and [");
- ctf_print_timestamp(stderr, stream,
- stream->prev_cycles_timestamp_end);
- } else {
- ctf_print_timestamp(stderr, stream,
- stream->prev_real_timestamp);
- fprintf(stderr, "] and [");
- ctf_print_timestamp(stderr, stream,
- stream->prev_real_timestamp_end);
- }
- fprintf(stderr, "]. You should consider recording a new trace with larger buffers or with fewer events enabled.\n");
- fflush(stderr);
+ ctf_print_discarded(stderr, stream, 0);
stream->events_discarded = 0;
}
else
fprintf(pos->fp, " ");
}
- if ((opt_delta_field || opt_all_fields) && stream->has_timestamp) {
+ if (opt_delta_field && stream->has_timestamp) {
uint64_t delta, delta_sec, delta_nsec;
set_field_names_print(pos, ITEM_HEADER);
pos->last_cycles_timestamp = stream->cycles_timestamp;
}
- if ((opt_trace_field || opt_all_fields) && stream_class->trace->path[0] != '\0') {
+ if ((opt_trace_field || opt_all_fields) && stream_class->trace->parent.path[0] != '\0') {
set_field_names_print(pos, ITEM_HEADER);
if (pos->print_names) {
fprintf(pos->fp, "trace = ");
}
- fprintf(pos->fp, "%s", stream_class->trace->path);
+ fprintf(pos->fp, "%s", stream_class->trace->parent.path);
if (pos->print_names)
fprintf(pos->fp, ", ");
else
}
static
-struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
- void (*packet_seek)(struct stream_pos *pos, size_t index,
+struct bt_trace_descriptor *ctf_text_open_trace(const char *path, int flags,
+ void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence), FILE *metadata_fp)
{
struct ctf_text_stream_pos *pos;
pos->fp = fp;
pos->parent.rw_table = write_dispatch_table;
pos->parent.event_cb = ctf_text_write_event;
+ pos->parent.trace = &pos->trace_descriptor;
pos->print_names = 0;
break;
case O_RDONLY:
}
static
-int ctf_text_close_trace(struct trace_descriptor *td)
+int ctf_text_close_trace(struct bt_trace_descriptor *td)
{
int ret;
struct ctf_text_stream_pos *pos =
container_of(td, struct ctf_text_stream_pos, trace_descriptor);
- ret = fclose(pos->fp);
- if (ret) {
- perror("Error on fclose");
- return -1;
+ if (pos->fp != stdout) {
+ ret = fclose(pos->fp);
+ if (ret) {
+ perror("Error on fclose");
+ return -1;
+ }
}
g_free(pos);
return 0;
#include <babeltrace/ctf-text/types.h>
#include <stdio.h>
-int ctf_text_array_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_array_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
struct definition_array *array_definition =
container_of(definition, struct definition_array, p);
struct declaration_array *array_declaration =
array_definition->declaration;
- struct declaration *elem = array_declaration->elem;
+ struct bt_declaration *elem = array_declaration->elem;
int field_nr_saved;
int ret = 0;
&& integer_declaration->p.alignment == CHAR_BIT)) {
pos->string = array_definition->string;
g_string_assign(array_definition->string, "");
- ret = array_rw(ppos, definition);
+ ret = bt_array_rw(ppos, definition);
pos->string = NULL;
}
fprintf(pos->fp, "\"%s\"", array_definition->string->str);
}
field_nr_saved = pos->field_nr;
pos->field_nr = 0;
- ret = array_rw(ppos, definition);
+ ret = bt_array_rw(ppos, definition);
if (!pos->dummy) {
pos->depth--;
fprintf(pos->fp, " ]");
#include <stdio.h>
#include <stdint.h>
-int ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_enum_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct definition_enum *enum_definition =
container_of(definition, struct definition_enum, p);
#include <babeltrace/ctf-text/types.h>
#include <stdio.h>
-int ctf_text_float_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_float_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct definition_float *float_definition =
container_of(definition, struct definition_float, p);
#include <stdint.h>
#include <babeltrace/bitfield.h>
-int ctf_text_integer_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_integer_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct definition_integer *integer_definition =
container_of(definition, struct definition_integer, p);
#include <babeltrace/ctf-text/types.h>
#include <stdio.h>
-int ctf_text_sequence_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_sequence_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
struct definition_sequence *sequence_definition =
container_of(definition, struct definition_sequence, p);
struct declaration_sequence *sequence_declaration =
sequence_definition->declaration;
- struct declaration *elem = sequence_declaration->elem;
+ struct bt_declaration *elem = sequence_declaration->elem;
int field_nr_saved;
int ret = 0;
&& integer_declaration->p.alignment == CHAR_BIT)) {
pos->string = sequence_definition->string;
g_string_assign(sequence_definition->string, "");
- ret = sequence_rw(ppos, definition);
+ ret = bt_sequence_rw(ppos, definition);
pos->string = NULL;
}
fprintf(pos->fp, "\"%s\"", sequence_definition->string->str);
}
field_nr_saved = pos->field_nr;
pos->field_nr = 0;
- ret = sequence_rw(ppos, definition);
+ ret = bt_sequence_rw(ppos, definition);
if (!pos->dummy) {
pos->depth--;
fprintf(pos->fp, " ]");
#include <limits.h> /* C99 limits */
#include <string.h>
-int ctf_text_string_write(struct stream_pos *ppos,
- struct definition *definition)
+int ctf_text_string_write(struct bt_stream_pos *ppos,
+ struct bt_definition *definition)
{
struct definition_string *string_definition =
container_of(definition, struct definition_string, p);
#include <babeltrace/ctf-text/types.h>
#include <stdio.h>
-int ctf_text_struct_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_struct_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
- struct declaration *declaration = definition->declaration;
- struct declaration_struct *struct_declaration =
- container_of(declaration, struct declaration_struct, p);
struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
- uint64_t len = struct_declaration_len(struct_declaration);
int field_nr_saved;
int ret;
if (pos->depth >= 0) {
if (pos->field_nr++ != 0)
fprintf(pos->fp, ",");
- if (pos->print_names || len > 1)
- fprintf(pos->fp, " ");
+ fprintf(pos->fp, " ");
if (pos->print_names && definition->name != 0)
fprintf(pos->fp, "%s = ",
rem_(g_quark_to_string(definition->name)));
- if (pos->print_names || len > 1)
- fprintf(pos->fp, "{");
+ fprintf(pos->fp, "{");
}
pos->depth++;
}
field_nr_saved = pos->field_nr;
pos->field_nr = 0;
- ret = struct_rw(ppos, definition);
+ ret = bt_struct_rw(ppos, definition);
if (!pos->dummy) {
pos->depth--;
- if (pos->depth >= 0 && (pos->print_names || len > 1)) {
+ if (pos->depth >= 0) {
fprintf(pos->fp, " }");
}
}
#include <babeltrace/ctf-text/types.h>
#include <stdio.h>
-int ctf_text_variant_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_variant_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
int field_nr_saved;
}
field_nr_saved = pos->field_nr;
pos->field_nr = 0;
- ret = variant_rw(ppos, definition);
+ ret = bt_variant_rw(ppos, definition);
if (!pos->dummy) {
pos->depth--;
if (pos->depth >= 0) {
events.c \
iterator.c \
callbacks.c \
- events-private.h \
- memstream.h
+ events-private.h
# Request that the linker keeps all static libraries objects.
libbabeltrace_ctf_la_LDFLAGS = \
#include <inttypes.h>
static
-struct bt_dependencies *_babeltrace_dependencies_create(const char *first,
+struct bt_dependencies *_bt_dependencies_create(const char *first,
va_list ap)
{
const char *iter;
return dep;
}
-struct bt_dependencies *babeltrace_dependencies_create(const char *first, ...)
+struct bt_dependencies *bt_dependencies_create(const char *first, ...)
{
va_list ap;
struct bt_dependencies *deps;
va_start(ap, first);
- deps = _babeltrace_dependencies_create(first, ap);
+ deps = _bt_dependencies_create(first, ap);
va_end(ap);
return deps;
}
tc = iter->parent.ctx->tc;
for (i = 0; i < tc->array->len; i++) {
struct ctf_trace *tin;
- struct trace_descriptor *td_read;
+ struct bt_trace_descriptor *td_read;
td_read = g_ptr_array_index(tc->array, i);
tin = container_of(td_read, struct ctf_trace, parent);
for (i = 0; i < bt_chain->callback->len; i++) {
cb = &g_array_index(bt_chain->callback, struct bt_callback, i);
- if (!cb)
- goto end;
ret = cb->callback(&ctf_data, cb->private_data);
switch (ret) {
case BT_CB_OK_STOP:
#include <babeltrace/ctf/events-internal.h>
#include <babeltrace/trace-handle-internal.h>
#include <babeltrace/context-internal.h>
-#include <babeltrace/uuid.h>
+#include <babeltrace/compat/uuid.h>
#include <babeltrace/endian.h>
#include <inttypes.h>
#include <stdio.h>
#include "metadata/ctf-parser.h"
#include "metadata/ctf-ast.h"
#include "events-private.h"
-#include "memstream.h"
+#include <babeltrace/compat/memstream.h>
+
+#define LOG2_CHAR_BIT 3
+
+/*
+ * Length of first attempt at mapping a packet header, in bits.
+ */
+#define DEFAULT_HEADER_LEN (getpagesize() * CHAR_BIT)
/*
- * We currently simply map a page to read the packet header and packet
- * context to get the packet length and content length. (in bits)
+ * Lenght of packet to write, in bits.
*/
-#define MAX_PACKET_HEADER_LEN (getpagesize() * CHAR_BIT)
#define WRITE_PACKET_LEN (getpagesize() * 8 * CHAR_BIT)
#ifndef min
opt_clock_gmt;
uint64_t opt_clock_offset;
+uint64_t opt_clock_offset_ns;
extern int yydebug;
static
-struct trace_descriptor *ctf_open_trace(const char *path, int flags,
- void (*packet_seek)(struct stream_pos *pos, size_t index,
+struct bt_trace_descriptor *ctf_open_trace(const char *path, int flags,
+ void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence),
FILE *metadata_fp);
static
-struct trace_descriptor *ctf_open_mmap_trace(
- struct mmap_stream_list *mmap_list,
- void (*packet_seek)(struct stream_pos *pos, size_t index,
+struct bt_trace_descriptor *ctf_open_mmap_trace(
+ struct bt_mmap_stream_list *mmap_list,
+ void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence),
FILE *metadata_fp);
static
-void ctf_set_context(struct trace_descriptor *descriptor,
+void ctf_set_context(struct bt_trace_descriptor *descriptor,
struct bt_context *ctx);
static
-void ctf_set_handle(struct trace_descriptor *descriptor,
+void ctf_set_handle(struct bt_trace_descriptor *descriptor,
struct bt_trace_handle *handle);
static
-int ctf_close_trace(struct trace_descriptor *descriptor);
+int ctf_close_trace(struct bt_trace_descriptor *descriptor);
static
-uint64_t ctf_timestamp_begin(struct trace_descriptor *descriptor,
+uint64_t ctf_timestamp_begin(struct bt_trace_descriptor *descriptor,
struct bt_trace_handle *handle, enum bt_clock_type type);
static
-uint64_t ctf_timestamp_end(struct trace_descriptor *descriptor,
+uint64_t ctf_timestamp_end(struct bt_trace_descriptor *descriptor,
struct bt_trace_handle *handle, enum bt_clock_type type);
static
-int ctf_convert_index_timestamp(struct trace_descriptor *tdp);
+int ctf_convert_index_timestamp(struct bt_trace_descriptor *tdp);
static
rw_dispatch read_dispatch_table[] = {
};
static
-struct format ctf_format = {
+struct bt_format ctf_format = {
.open_trace = ctf_open_trace,
.open_mmap_trace = ctf_open_mmap_trace,
.close_trace = ctf_close_trace,
};
static
-uint64_t ctf_timestamp_begin(struct trace_descriptor *descriptor,
+uint64_t ctf_timestamp_begin(struct bt_trace_descriptor *descriptor,
struct bt_trace_handle *handle, enum bt_clock_type type)
{
struct ctf_trace *tin;
}
static
-uint64_t ctf_timestamp_end(struct trace_descriptor *descriptor,
+uint64_t ctf_timestamp_end(struct bt_trace_descriptor *descriptor,
struct bt_trace_handle *handle, enum bt_clock_type type)
{
struct ctf_trace *tin;
* Print timestamp, rescaling clock frequency to nanoseconds and
* applying offsets as needed (unix time).
*/
+static
void ctf_print_timestamp_real(FILE *fp,
struct ctf_stream_definition *stream,
uint64_t timestamp)
ts_nsec = timestamp;
+ /* Add command-line offset in ns*/
+ ts_nsec += opt_clock_offset_ns;
+
/* Add command-line offset */
ts_sec += opt_clock_offset;
/*
* Print timestamp, in cycles
*/
+static
void ctf_print_timestamp_cycles(FILE *fp,
struct ctf_stream_definition *stream,
uint64_t timestamp)
}
static
-int ctf_read_event(struct stream_pos *ppos, struct ctf_stream_definition *stream)
+void print_uuid(FILE *fp, unsigned char *uuid)
+{
+ int i;
+
+ for (i = 0; i < BABELTRACE_UUID_LEN; i++)
+ fprintf(fp, "%x", (unsigned int) uuid[i]);
+}
+
+void ctf_print_discarded(FILE *fp, struct ctf_stream_definition *stream,
+ int end_stream)
+{
+ fprintf(fp, "[warning] Tracer discarded %" PRIu64 " events %sbetween [",
+ stream->events_discarded,
+ end_stream ? "at end of stream " : "");
+ if (opt_clock_cycles) {
+ ctf_print_timestamp(fp, stream,
+ stream->prev_cycles_timestamp);
+ fprintf(fp, "] and [");
+ ctf_print_timestamp(fp, stream,
+ stream->prev_cycles_timestamp_end);
+ } else {
+ ctf_print_timestamp(fp, stream,
+ stream->prev_real_timestamp);
+ fprintf(fp, "] and [");
+ ctf_print_timestamp(fp, stream,
+ stream->prev_real_timestamp_end);
+ }
+ fprintf(fp, "] in trace UUID ");
+ print_uuid(fp, stream->stream_class->trace->uuid);
+ if (stream->stream_class->trace->parent.path[0])
+ fprintf(fp, ", at path: \"%s\"",
+ stream->stream_class->trace->parent.path);
+
+ fprintf(fp, ", within stream id %" PRIu64, stream->stream_id);
+ if (stream->path[0])
+ fprintf(fp, ", at relative path: \"%s\"", stream->path);
+ fprintf(fp, ". ");
+ fprintf(fp, "You should consider recording a new trace with larger "
+ "buffers or with fewer events enabled.\n");
+ fflush(fp);
+}
+
+static
+int ctf_read_event(struct bt_stream_pos *ppos, struct ctf_stream_definition *stream)
{
struct ctf_stream_pos *pos =
container_of(ppos, struct ctf_stream_pos, parent);
/* Read event header */
if (likely(stream->stream_event_header)) {
struct definition_integer *integer_definition;
- struct definition *variant;
+ struct bt_definition *variant;
ret = generic_rw(ppos, &stream->stream_event_header->p);
if (unlikely(ret))
goto error;
/* lookup event id */
- integer_definition = lookup_integer(&stream->stream_event_header->p, "id", FALSE);
+ integer_definition = bt_lookup_integer(&stream->stream_event_header->p, "id", FALSE);
if (integer_definition) {
id = integer_definition->value._unsigned;
} else {
struct definition_enum *enum_definition;
- enum_definition = lookup_enum(&stream->stream_event_header->p, "id", FALSE);
+ enum_definition = bt_lookup_enum(&stream->stream_event_header->p, "id", FALSE);
if (enum_definition) {
id = enum_definition->integer->value._unsigned;
}
}
- variant = lookup_variant(&stream->stream_event_header->p, "v");
+ variant = bt_lookup_variant(&stream->stream_event_header->p, "v");
if (variant) {
- integer_definition = lookup_integer(variant, "id", FALSE);
+ integer_definition = bt_lookup_integer(variant, "id", FALSE);
if (integer_definition) {
id = integer_definition->value._unsigned;
}
/* lookup timestamp */
stream->has_timestamp = 0;
- integer_definition = lookup_integer(&stream->stream_event_header->p, "timestamp", FALSE);
+ integer_definition = bt_lookup_integer(&stream->stream_event_header->p, "timestamp", FALSE);
if (integer_definition) {
ctf_update_timestamp(stream, integer_definition);
stream->has_timestamp = 1;
} else {
if (variant) {
- integer_definition = lookup_integer(variant, "timestamp", FALSE);
+ integer_definition = bt_lookup_integer(variant, "timestamp", FALSE);
if (integer_definition) {
ctf_update_timestamp(stream, integer_definition);
stream->has_timestamp = 1;
}
static
-int ctf_write_event(struct stream_pos *pos, struct ctf_stream_definition *stream)
+int ctf_write_event(struct bt_stream_pos *pos, struct ctf_stream_definition *stream)
{
struct ctf_stream_declaration *stream_class = stream->stream_class;
struct ctf_event_definition *event;
return ret;
}
-int ctf_init_pos(struct ctf_stream_pos *pos, int fd, int open_flags)
+int ctf_init_pos(struct ctf_stream_pos *pos, struct bt_trace_descriptor *trace,
+ int fd, int open_flags)
{
pos->fd = fd;
if (fd >= 0) {
pos->flags = MAP_PRIVATE;
pos->parent.rw_table = read_dispatch_table;
pos->parent.event_cb = ctf_read_event;
+ pos->parent.trace = trace;
break;
case O_RDWR:
pos->prot = PROT_WRITE; /* Write has priority */
pos->flags = MAP_SHARED;
pos->parent.rw_table = write_dispatch_table;
pos->parent.event_cb = ctf_write_event;
+ pos->parent.trace = trace;
if (fd >= 0)
ctf_packet_seek(&pos->parent, 0, SEEK_SET); /* position for write */
break;
/*
* for SEEK_CUR: go to next packet.
- * for SEEK_POS: go to packet numer (index).
+ * for SEEK_SET: go to packet numer (index).
*/
-void ctf_packet_seek(struct stream_pos *stream_pos, size_t index, int whence)
+void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence)
{
struct ctf_stream_pos *pos =
container_of(stream_pos, struct ctf_stream_pos, parent);
off_t off;
struct packet_index *packet_index;
+ switch (whence) {
+ case SEEK_CUR:
+ case SEEK_SET: /* Fall-through */
+ break; /* OK */
+ default:
+ assert(0);
+ }
+
if (pos->prot == PROT_WRITE && pos->content_size_loc)
*pos->content_size_loc = pos->offset;
if (pos->offset == EOF) {
return;
}
+ assert(pos->cur_index < pos->packet_cycles_index->len);
+ assert(pos->cur_index < pos->packet_real_index->len);
+
/* For printing discarded event count */
packet_index = &g_array_index(pos->packet_cycles_index,
struct packet_index, pos->cur_index);
break;
}
case SEEK_SET:
+ if (index >= pos->packet_cycles_index->len) {
+ pos->offset = EOF;
+ return;
+ }
packet_index = &g_array_index(pos->packet_cycles_index,
struct packet_index, index);
pos->last_events_discarded = packet_index->events_discarded;
}
if (pos->cur_index >= pos->packet_real_index->len) {
/*
- * When a stream reaches the end of the
- * file, we need to show the number of
- * events discarded ourselves, because
- * there is no next event scheduled to
- * be printed in the output.
+ * We need to check if we are in trace read or
+ * called from packet indexing. In this last
+ * case, the collection is not there, so we
+ * cannot print the timestamps.
*/
- if (file_stream->parent.events_discarded) {
+ if ((&file_stream->parent)->stream_class->trace->parent.collection) {
/*
- * We need to check if we are in trace
- * read or called from packet indexing.
- * In this last case, the collection is
- * not there, so we cannot print the
- * timestamps.
+ * When a stream reaches the end of the
+ * file, we need to show the number of
+ * events discarded ourselves, because
+ * there is no next event scheduled to
+ * be printed in the output.
*/
- if ((&file_stream->parent)->stream_class->trace->collection) {
+ if (file_stream->parent.events_discarded) {
fflush(stdout);
- fprintf(stderr, "[warning] Tracer discarded %" PRIu64 " events at end of stream between [",
- file_stream->parent.events_discarded);
- if (opt_clock_cycles) {
- ctf_print_timestamp(stderr,
- &file_stream->parent,
- file_stream->parent.prev_cycles_timestamp);
- fprintf(stderr, "] and [");
- ctf_print_timestamp(stderr, &file_stream->parent,
- file_stream->parent.prev_cycles_timestamp_end);
- } else {
- ctf_print_timestamp(stderr,
- &file_stream->parent,
- file_stream->parent.prev_real_timestamp);
- fprintf(stderr, "] and [");
- ctf_print_timestamp(stderr, &file_stream->parent,
- file_stream->parent.prev_real_timestamp_end);
- }
- fprintf(stderr, "]. You should consider recording a new trace with larger buffers or with fewer events enabled.\n");
- fflush(stderr);
+ ctf_print_discarded(stderr,
+ &file_stream->parent,
+ 1);
+ file_stream->parent.events_discarded = 0;
}
- file_stream->parent.events_discarded = 0;
}
pos->offset = EOF;
return;
char **buf)
{
FILE *in, *out;
- size_t size;
+ size_t size, buflen;
int ret;
in = *fp;
perror("Error in fclose");
}
/* open for reading */
- *fp = babeltrace_fmemopen(*buf, strlen(*buf), "rb");
+ buflen = strlen(*buf);
+ if (!buflen) {
+ *fp = NULL;
+ return -ENOENT;
+ }
+ *fp = babeltrace_fmemopen(*buf, buflen, "rb");
if (!*fp) {
perror("Metadata fmemopen");
return -errno;
static
int ctf_open_trace_metadata_read(struct ctf_trace *td,
- void (*packet_seek)(struct stream_pos *pos, size_t index,
+ void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence), FILE *metadata_fp)
{
struct ctf_scanner *scanner;
if (packet_metadata(td, fp)) {
ret = ctf_open_trace_metadata_stream_read(td, &fp, &buf);
- if (ret)
+ if (ret) {
+ /* Warn about empty metadata */
+ fprintf(stderr, "[warning] Empty metadata.\n");
goto end_packet_read;
+ }
+ td->metadata_string = buf;
+ td->metadata_packetized = 1;
} else {
unsigned int major, minor;
ssize_t nr_items;
perror("Error on fclose");
}
}
- free(buf);
end_stream:
if (metadata_stream->pos.fd >= 0) {
closeret = close(metadata_stream->pos.fd);
struct ctf_event_definition *stream_event = g_new0(struct ctf_event_definition, 1);
if (event->context_decl) {
- struct definition *definition =
+ struct bt_definition *definition =
event->context_decl->p.definition_new(&event->context_decl->p,
stream->parent_def_scope, 0, 0, "event.context");
if (!definition) {
stream->parent_def_scope = stream_event->event_context->p.scope;
}
if (event->fields_decl) {
- struct definition *definition =
+ struct bt_definition *definition =
event->fields_decl->p.definition_new(&event->fields_decl->p,
stream->parent_def_scope, 0, 0, "event.fields");
if (!definition) {
error:
if (stream_event->event_fields)
- definition_unref(&stream_event->event_fields->p);
+ bt_definition_unref(&stream_event->event_fields->p);
if (stream_event->event_context)
- definition_unref(&stream_event->event_context->p);
+ bt_definition_unref(&stream_event->event_context->p);
+ fprintf(stderr, "[error] Unable to create event definition for event \"%s\".\n",
+ g_quark_to_string(event->name));
return NULL;
}
stream_class = stream->stream_class;
if (stream_class->packet_context_decl) {
- struct definition *definition =
+ struct bt_definition *definition =
stream_class->packet_context_decl->p.definition_new(&stream_class->packet_context_decl->p,
stream->parent_def_scope, 0, 0, "stream.packet.context");
if (!definition) {
stream->parent_def_scope = stream->stream_packet_context->p.scope;
}
if (stream_class->event_header_decl) {
- struct definition *definition =
+ struct bt_definition *definition =
stream_class->event_header_decl->p.definition_new(&stream_class->event_header_decl->p,
stream->parent_def_scope, 0, 0, "stream.event.header");
if (!definition) {
stream->parent_def_scope = stream->stream_event_header->p.scope;
}
if (stream_class->event_context_decl) {
- struct definition *definition =
+ struct bt_definition *definition =
stream_class->event_context_decl->p.definition_new(&stream_class->event_context_decl->p,
stream->parent_def_scope, 0, 0, "stream.event.context");
if (!definition) {
if (!event)
continue;
stream_event = create_event_definitions(td, stream, event);
- if (!stream_event)
+ if (!stream_event) {
+ ret = -EINVAL;
goto error_event;
+ }
g_ptr_array_index(stream->events_by_id, i) = stream_event;
}
return 0;
g_ptr_array_free(stream->events_by_id, TRUE);
error:
if (stream->stream_event_context)
- definition_unref(&stream->stream_event_context->p);
+ bt_definition_unref(&stream->stream_event_context->p);
if (stream->stream_event_header)
- definition_unref(&stream->stream_event_header->p);
+ bt_definition_unref(&stream->stream_event_header->p);
if (stream->stream_packet_context)
- definition_unref(&stream->stream_packet_context->p);
+ bt_definition_unref(&stream->stream_packet_context->p);
+ fprintf(stderr, "[error] Unable to create stream (%" PRIu64 ") definitions: %s\n",
+ stream_class->stream_id, strerror(-ret));
return ret;
}
-
static
-int create_stream_packet_index(struct ctf_trace *td,
- struct ctf_file_stream *file_stream)
+int stream_assign_class(struct ctf_trace *td,
+ struct ctf_file_stream *file_stream,
+ uint64_t stream_id)
{
struct ctf_stream_declaration *stream;
- int len_index;
- struct ctf_stream_pos *pos;
- struct stat filestats;
- struct packet_index packet_index;
- int first_packet = 1;
int ret;
- pos = &file_stream->pos;
-
- ret = fstat(pos->fd, &filestats);
- if (ret < 0)
+ file_stream->parent.stream_id = stream_id;
+ if (stream_id >= td->streams->len) {
+ fprintf(stderr, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
+ return -EINVAL;
+ }
+ stream = g_ptr_array_index(td->streams, stream_id);
+ if (!stream) {
+ fprintf(stderr, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
+ return -EINVAL;
+ }
+ file_stream->parent.stream_class = stream;
+ ret = create_stream_definitions(td, &file_stream->parent);
+ if (ret)
return ret;
+ return 0;
+}
- if (filestats.st_size < MAX_PACKET_HEADER_LEN / CHAR_BIT)
- return -EINVAL;
+static
+int create_stream_one_packet_index(struct ctf_stream_pos *pos,
+ struct ctf_trace *td,
+ struct ctf_file_stream *file_stream,
+ size_t filesize)
+{
+ struct packet_index packet_index;
+ uint64_t stream_id = 0;
+ uint64_t packet_map_len = DEFAULT_HEADER_LEN, tmp_map_len;
+ int first_packet = 0;
+ int len_index;
+ int ret;
- for (pos->mmap_offset = 0; pos->mmap_offset < filestats.st_size; ) {
- uint64_t stream_id = 0;
+begin:
+ if (!pos->mmap_offset) {
+ first_packet = 1;
+ }
- if (pos->base_mma) {
- /* unmap old base */
- ret = munmap_align(pos->base_mma);
- if (ret) {
- fprintf(stderr, "[error] Unable to unmap old base: %s.\n",
- strerror(errno));
- return ret;
- }
- pos->base_mma = NULL;
+ if (filesize - pos->mmap_offset < (packet_map_len >> LOG2_CHAR_BIT)) {
+ packet_map_len = (filesize - pos->mmap_offset) << LOG2_CHAR_BIT;
+ }
+
+ if (pos->base_mma) {
+ /* unmap old base */
+ ret = munmap_align(pos->base_mma);
+ if (ret) {
+ fprintf(stderr, "[error] Unable to unmap old base: %s.\n",
+ strerror(errno));
+ return ret;
}
- /* map new base. Need mapping length from header. */
- pos->base_mma = mmap_align(MAX_PACKET_HEADER_LEN / CHAR_BIT, PROT_READ,
- MAP_PRIVATE, pos->fd, pos->mmap_offset);
- assert(pos->base_mma != MAP_FAILED);
- pos->content_size = MAX_PACKET_HEADER_LEN; /* Unknown at this point */
- pos->packet_size = MAX_PACKET_HEADER_LEN; /* Unknown at this point */
- pos->offset = 0; /* Position of the packet header */
-
- packet_index.offset = pos->mmap_offset;
- packet_index.content_size = 0;
- packet_index.packet_size = 0;
- packet_index.timestamp_begin = 0;
- packet_index.timestamp_end = 0;
- packet_index.events_discarded = 0;
- packet_index.events_discarded_len = 0;
-
- /* read and check header, set stream id (and check) */
- if (file_stream->parent.trace_packet_header) {
- /* Read packet header */
- ret = generic_rw(&pos->parent, &file_stream->parent.trace_packet_header->p);
- if (ret)
- return ret;
- len_index = struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("magic"));
- if (len_index >= 0) {
- struct definition *field;
- uint64_t magic;
-
- field = struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
- magic = get_unsigned_int(field);
- if (magic != CTF_MAGIC) {
- fprintf(stderr, "[error] Invalid magic number 0x%" PRIX64 " at packet %u (file offset %zd).\n",
- magic,
- file_stream->pos.packet_cycles_index->len,
- (ssize_t) pos->mmap_offset);
- return -EINVAL;
- }
+ pos->base_mma = NULL;
+ }
+ /* map new base. Need mapping length from header. */
+ pos->base_mma = mmap_align(packet_map_len >> LOG2_CHAR_BIT, PROT_READ,
+ MAP_PRIVATE, pos->fd, pos->mmap_offset);
+ assert(pos->base_mma != MAP_FAILED);
+ /*
+ * Use current mapping size as temporary content and packet
+ * size.
+ */
+ pos->content_size = packet_map_len;
+ pos->packet_size = packet_map_len;
+ pos->offset = 0; /* Position of the packet header */
+
+ packet_index.offset = pos->mmap_offset;
+ packet_index.content_size = 0;
+ packet_index.packet_size = 0;
+ packet_index.timestamp_begin = 0;
+ packet_index.timestamp_end = 0;
+ packet_index.events_discarded = 0;
+ packet_index.events_discarded_len = 0;
+
+ /* read and check header, set stream id (and check) */
+ if (file_stream->parent.trace_packet_header) {
+ /* Read packet header */
+ ret = generic_rw(&pos->parent, &file_stream->parent.trace_packet_header->p);
+ if (ret) {
+ if (ret == -EFAULT)
+ goto retry;
+ fprintf(stderr, "[error] Unable to read packet header: %s\n", strerror(-ret));
+ return ret;
+ }
+ len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("magic"));
+ if (len_index >= 0) {
+ struct bt_definition *field;
+ uint64_t magic;
+
+ field = bt_struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
+ magic = bt_get_unsigned_int(field);
+ if (magic != CTF_MAGIC) {
+ fprintf(stderr, "[error] Invalid magic number 0x%" PRIX64 " at packet %u (file offset %zd).\n",
+ magic,
+ file_stream->pos.packet_cycles_index->len,
+ (ssize_t) pos->mmap_offset);
+ return -EINVAL;
}
+ }
- /* check uuid */
- len_index = struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("uuid"));
- if (len_index >= 0) {
- struct definition_array *defarray;
- struct definition *field;
- uint64_t i;
- uint8_t uuidval[BABELTRACE_UUID_LEN];
+ /* check uuid */
+ len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("uuid"));
+ if (len_index >= 0) {
+ struct definition_array *defarray;
+ struct bt_definition *field;
+ uint64_t i;
+ uint8_t uuidval[BABELTRACE_UUID_LEN];
- field = struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
- assert(field->declaration->id == CTF_TYPE_ARRAY);
- defarray = container_of(field, struct definition_array, p);
- assert(array_len(defarray) == BABELTRACE_UUID_LEN);
+ field = bt_struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
+ assert(field->declaration->id == CTF_TYPE_ARRAY);
+ defarray = container_of(field, struct definition_array, p);
+ assert(bt_array_len(defarray) == BABELTRACE_UUID_LEN);
- for (i = 0; i < BABELTRACE_UUID_LEN; i++) {
- struct definition *elem;
+ for (i = 0; i < BABELTRACE_UUID_LEN; i++) {
+ struct bt_definition *elem;
- elem = array_index(defarray, i);
- uuidval[i] = get_unsigned_int(elem);
- }
- ret = babeltrace_uuid_compare(td->uuid, uuidval);
- if (ret) {
- fprintf(stderr, "[error] Unique Universal Identifiers do not match.\n");
- return -EINVAL;
- }
+ elem = bt_array_index(defarray, i);
+ uuidval[i] = bt_get_unsigned_int(elem);
+ }
+ ret = babeltrace_uuid_compare(td->uuid, uuidval);
+ if (ret) {
+ fprintf(stderr, "[error] Unique Universal Identifiers do not match.\n");
+ return -EINVAL;
}
+ }
+ len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("stream_id"));
+ if (len_index >= 0) {
+ struct bt_definition *field;
- len_index = struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("stream_id"));
- if (len_index >= 0) {
- struct definition *field;
+ field = bt_struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
+ stream_id = bt_get_unsigned_int(field);
+ }
+ }
- field = struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
- stream_id = get_unsigned_int(field);
- }
+ if (!first_packet && file_stream->parent.stream_id != stream_id) {
+ fprintf(stderr, "[error] Stream ID is changing within a stream: expecting %" PRIu64 ", but packet has %" PRIu64 "\n",
+ stream_id,
+ file_stream->parent.stream_id);
+ return -EINVAL;
+ }
+ if (first_packet) {
+ ret = stream_assign_class(td, file_stream, stream_id);
+ if (ret)
+ return ret;
+ }
+
+ if (file_stream->parent.stream_packet_context) {
+ /* Read packet context */
+ ret = generic_rw(&pos->parent, &file_stream->parent.stream_packet_context->p);
+ if (ret) {
+ if (ret == -EFAULT)
+ goto retry;
+ fprintf(stderr, "[error] Unable to read packet context: %s\n", strerror(-ret));
+ return ret;
}
+ /* read content size from header */
+ len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("content_size"));
+ if (len_index >= 0) {
+ struct bt_definition *field;
- if (!first_packet && file_stream->parent.stream_id != stream_id) {
- fprintf(stderr, "[error] Stream ID is changing within a stream.\n");
- return -EINVAL;
+ field = bt_struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
+ packet_index.content_size = bt_get_unsigned_int(field);
+ } else {
+ /* Use file size for packet size */
+ packet_index.content_size = filesize * CHAR_BIT;
}
- if (first_packet) {
- file_stream->parent.stream_id = stream_id;
- if (stream_id >= td->streams->len) {
- fprintf(stderr, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
- return -EINVAL;
+
+ /* read packet size from header */
+ len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("packet_size"));
+ if (len_index >= 0) {
+ struct bt_definition *field;
+
+ field = bt_struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
+ packet_index.packet_size = bt_get_unsigned_int(field);
+ } else {
+ /* Use content size if non-zero, else file size */
+ packet_index.packet_size = packet_index.content_size ? : filesize * CHAR_BIT;
+ }
+
+ /* read timestamp begin from header */
+ len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("timestamp_begin"));
+ if (len_index >= 0) {
+ struct bt_definition *field;
+
+ field = bt_struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
+ packet_index.timestamp_begin = bt_get_unsigned_int(field);
+ if (file_stream->parent.stream_class->trace->parent.collection) {
+ packet_index.timestamp_begin =
+ ctf_get_real_timestamp(
+ &file_stream->parent,
+ packet_index.timestamp_begin);
}
- stream = g_ptr_array_index(td->streams, stream_id);
- if (!stream) {
- fprintf(stderr, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
- return -EINVAL;
+ }
+
+ /* read timestamp end from header */
+ len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("timestamp_end"));
+ if (len_index >= 0) {
+ struct bt_definition *field;
+
+ field = bt_struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
+ packet_index.timestamp_end = bt_get_unsigned_int(field);
+ if (file_stream->parent.stream_class->trace->parent.collection) {
+ packet_index.timestamp_end =
+ ctf_get_real_timestamp(
+ &file_stream->parent,
+ packet_index.timestamp_end);
}
- file_stream->parent.stream_class = stream;
- ret = create_stream_definitions(td, &file_stream->parent);
- if (ret)
- return ret;
}
- first_packet = 0;
- if (file_stream->parent.stream_packet_context) {
- /* Read packet context */
- ret = generic_rw(&pos->parent, &file_stream->parent.stream_packet_context->p);
- if (ret)
- return ret;
- /* read content size from header */
- len_index = struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("content_size"));
- if (len_index >= 0) {
- struct definition *field;
+ /* read events discarded from header */
+ len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("events_discarded"));
+ if (len_index >= 0) {
+ struct bt_definition *field;
- field = struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
- packet_index.content_size = get_unsigned_int(field);
- } else {
- /* Use file size for packet size */
- packet_index.content_size = filestats.st_size * CHAR_BIT;
- }
+ field = bt_struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
+ packet_index.events_discarded = bt_get_unsigned_int(field);
+ packet_index.events_discarded_len = bt_get_int_len(field);
+ }
+ } else {
+ /* Use file size for packet size */
+ packet_index.content_size = filesize * CHAR_BIT;
+ /* Use content size if non-zero, else file size */
+ packet_index.packet_size = packet_index.content_size ? : filesize * CHAR_BIT;
+ }
- /* read packet size from header */
- len_index = struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("packet_size"));
- if (len_index >= 0) {
- struct definition *field;
+ /* Validate content size and packet size values */
+ if (packet_index.content_size > packet_index.packet_size) {
+ fprintf(stderr, "[error] Content size (%" PRIu64 " bits) is larger than packet size (%" PRIu64 " bits).\n",
+ packet_index.content_size, packet_index.packet_size);
+ return -EINVAL;
+ }
- field = struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
- packet_index.packet_size = get_unsigned_int(field);
- } else {
- /* Use content size if non-zero, else file size */
- packet_index.packet_size = packet_index.content_size ? : filestats.st_size * CHAR_BIT;
- }
+ if (packet_index.packet_size > ((uint64_t) filesize - packet_index.offset) * CHAR_BIT) {
+ fprintf(stderr, "[error] Packet size (%" PRIu64 " bits) is larger than remaining file size (%" PRIu64 " bits).\n",
+ packet_index.packet_size, ((uint64_t) filesize - packet_index.offset) * CHAR_BIT);
+ return -EINVAL;
+ }
- /* read timestamp begin from header */
- len_index = struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("timestamp_begin"));
- if (len_index >= 0) {
- struct definition *field;
-
- field = struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
- packet_index.timestamp_begin = get_unsigned_int(field);
- if (file_stream->parent.stream_class->trace->collection) {
- packet_index.timestamp_begin =
- ctf_get_real_timestamp(
- &file_stream->parent,
- packet_index.timestamp_begin);
- }
- }
+ /* Save position after header and context */
+ packet_index.data_offset = pos->offset;
- /* read timestamp end from header */
- len_index = struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("timestamp_end"));
- if (len_index >= 0) {
- struct definition *field;
-
- field = struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
- packet_index.timestamp_end = get_unsigned_int(field);
- if (file_stream->parent.stream_class->trace->collection) {
- packet_index.timestamp_end =
- ctf_get_real_timestamp(
- &file_stream->parent,
- packet_index.timestamp_end);
- }
- }
+ /* add index to packet array */
+ g_array_append_val(file_stream->pos.packet_cycles_index, packet_index);
- /* read events discarded from header */
- len_index = struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("events_discarded"));
- if (len_index >= 0) {
- struct definition *field;
+ pos->mmap_offset += packet_index.packet_size >> LOG2_CHAR_BIT;
- field = struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
- packet_index.events_discarded = get_unsigned_int(field);
- packet_index.events_discarded_len = get_int_len(field);
- }
- } else {
- /* Use file size for packet size */
- packet_index.content_size = filestats.st_size * CHAR_BIT;
- /* Use content size if non-zero, else file size */
- packet_index.packet_size = packet_index.content_size ? : filestats.st_size * CHAR_BIT;
- }
+ return 0;
- /* Validate content size and packet size values */
- if (packet_index.content_size > packet_index.packet_size) {
- fprintf(stderr, "[error] Content size (%" PRIu64 " bits) is larger than packet size (%" PRIu64 " bits).\n",
- packet_index.content_size, packet_index.packet_size);
- return -EINVAL;
- }
+ /* Retry with larger mapping */
+retry:
+ if (packet_map_len == ((filesize - pos->mmap_offset) << LOG2_CHAR_BIT)) {
+ /*
+ * Reached EOF, but still expecting header/context data.
+ */
+ fprintf(stderr, "[error] Reached end of file, but still expecting header or context fields.\n");
+ return -EFAULT;
+ }
+ /* Double the mapping len, and retry */
+ tmp_map_len = packet_map_len << 1;
+ if (tmp_map_len >> 1 != packet_map_len) {
+ /* Overflow */
+ fprintf(stderr, "[error] Packet mapping length overflow\n");
+ return -EFAULT;
+ }
+ packet_map_len = tmp_map_len;
+ goto begin;
+}
- if (packet_index.packet_size > ((uint64_t)filestats.st_size - packet_index.offset) * CHAR_BIT) {
- fprintf(stderr, "[error] Packet size (%" PRIu64 " bits) is larger than remaining file size (%" PRIu64 " bits).\n",
- packet_index.packet_size, ((uint64_t)filestats.st_size - packet_index.offset) * CHAR_BIT);
- return -EINVAL;
- }
+static
+int create_stream_packet_index(struct ctf_trace *td,
+ struct ctf_file_stream *file_stream)
+{
+ struct ctf_stream_pos *pos;
+ struct stat filestats;
+ int ret;
- /* Save position after header and context */
- packet_index.data_offset = pos->offset;
+ pos = &file_stream->pos;
- /* add index to packet array */
- g_array_append_val(file_stream->pos.packet_cycles_index, packet_index);
+ ret = fstat(pos->fd, &filestats);
+ if (ret < 0)
+ return ret;
- pos->mmap_offset += packet_index.packet_size / CHAR_BIT;
+ /* Deal with empty files */
+ if (!filestats.st_size) {
+ if (file_stream->parent.trace_packet_header
+ || file_stream->parent.stream_packet_context) {
+ /*
+ * We expect a trace packet header and/or stream packet
+ * context. Since a trace needs to have at least one
+ * packet, empty files are therefore not accepted.
+ */
+ fprintf(stderr, "[error] Encountered an empty file, but expecting a trace packet header.\n");
+ return -EINVAL;
+ } else {
+ /*
+ * Without trace packet header nor stream packet
+ * context, a one-packet trace can indeed be empty. This
+ * is only valid if there is only one stream class: 0.
+ */
+ ret = stream_assign_class(td, file_stream, 0);
+ if (ret)
+ return ret;
+ return 0;
+ }
}
+ for (pos->mmap_offset = 0; pos->mmap_offset < filestats.st_size; ) {
+ ret = create_stream_one_packet_index(pos, td, file_stream,
+ filestats.st_size);
+ if (ret)
+ return ret;
+ }
return 0;
}
int ret;
if (td->packet_header_decl) {
- struct definition *definition =
+ struct bt_definition *definition =
td->packet_header_decl->p.definition_new(&td->packet_header_decl->p,
stream->parent_def_scope, 0, 0, "trace.packet.header");
if (!definition) {
return 0;
error:
+ fprintf(stderr, "[error] Unable to create trace definitions: %s\n", strerror(-ret));
return ret;
}
*/
static
int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags,
- void (*packet_seek)(struct stream_pos *pos, size_t index,
+ void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence))
{
int ret, fd, closeret;
file_stream = g_new0(struct ctf_file_stream, 1);
file_stream->pos.last_offset = LAST_OFFSET_POISON;
+ strncpy(file_stream->parent.path, path, PATH_MAX);
+ file_stream->parent.path[PATH_MAX - 1] = '\0';
+
if (packet_seek) {
file_stream->pos.packet_seek = packet_seek;
} else {
goto error_def;
}
- ret = ctf_init_pos(&file_stream->pos, fd, flags);
+ ret = ctf_init_pos(&file_stream->pos, &td->parent, fd, flags);
if (ret)
goto error_def;
ret = create_trace_definitions(td, &file_stream->parent);
/*
* For now, only a single clock per trace is supported.
*/
- file_stream->parent.current_clock = td->single_clock;
+ file_stream->parent.current_clock = td->parent.single_clock;
ret = create_stream_packet_index(td, file_stream);
- if (ret)
+ if (ret) {
+ fprintf(stderr, "[error] Stream index creation error.\n");
goto error_index;
+ }
/* Add stream file to stream class */
g_ptr_array_add(file_stream->parent.stream_class->streams,
&file_stream->parent);
error_index:
if (file_stream->parent.trace_packet_header)
- definition_unref(&file_stream->parent.trace_packet_header->p);
+ bt_definition_unref(&file_stream->parent.trace_packet_header->p);
error_def:
closeret = ctf_fini_pos(&file_stream->pos);
if (closeret) {
static
int ctf_open_trace_read(struct ctf_trace *td,
const char *path, int flags,
- void (*packet_seek)(struct stream_pos *pos, size_t index,
+ void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence), FILE *metadata_fp)
{
int ret, closeret;
ret = -errno;
goto error_dirfd;
}
- strncpy(td->path, path, sizeof(td->path));
- td->path[sizeof(td->path) - 1] = '\0';
+ strncpy(td->parent.path, path, sizeof(td->parent.path));
+ td->parent.path[sizeof(td->parent.path) - 1] = '\0';
/*
* Keep the metadata file separate.
* since the index creation read it entirely.
*/
static
-struct trace_descriptor *ctf_open_trace(const char *path, int flags,
- void (*packet_seek)(struct stream_pos *pos, size_t index,
+struct bt_trace_descriptor *ctf_open_trace(const char *path, int flags,
+ void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence), FILE *metadata_fp)
{
struct ctf_trace *td;
return NULL;
}
-
+static
void ctf_init_mmap_pos(struct ctf_stream_pos *pos,
- struct mmap_stream *mmap_info)
+ struct bt_mmap_stream *mmap_info)
{
pos->mmap_offset = 0;
pos->packet_size = 0;
static
int ctf_open_mmap_stream_read(struct ctf_trace *td,
- struct mmap_stream *mmap_info,
- void (*packet_seek)(struct stream_pos *pos, size_t index,
+ struct bt_mmap_stream *mmap_info,
+ void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence))
{
int ret;
/*
* For now, only a single clock per trace is supported.
*/
- file_stream->parent.current_clock = td->single_clock;
+ file_stream->parent.current_clock = td->parent.single_clock;
/* Add stream file to stream class */
g_ptr_array_add(file_stream->parent.stream_class->streams,
error_index:
if (file_stream->parent.trace_packet_header)
- definition_unref(&file_stream->parent.trace_packet_header->p);
+ bt_definition_unref(&file_stream->parent.trace_packet_header->p);
error_def:
g_free(file_stream);
return ret;
}
+static
int ctf_open_mmap_trace_read(struct ctf_trace *td,
- struct mmap_stream_list *mmap_list,
- void (*packet_seek)(struct stream_pos *pos, size_t index,
+ struct bt_mmap_stream_list *mmap_list,
+ void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence),
FILE *metadata_fp)
{
int ret;
- struct mmap_stream *mmap_info;
+ struct bt_mmap_stream *mmap_info;
ret = ctf_open_trace_metadata_read(td, ctf_packet_seek, metadata_fp);
if (ret) {
}
static
-struct trace_descriptor *ctf_open_mmap_trace(
- struct mmap_stream_list *mmap_list,
- void (*packet_seek)(struct stream_pos *pos, size_t index,
+struct bt_trace_descriptor *ctf_open_mmap_trace(
+ struct bt_mmap_stream_list *mmap_list,
+ void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence),
FILE *metadata_fp)
{
}
static
-int ctf_convert_index_timestamp(struct trace_descriptor *tdp)
+int ctf_convert_index_timestamp(struct bt_trace_descriptor *tdp)
{
int i, j, k;
struct ctf_trace *td = container_of(tdp, struct ctf_trace, parent);
}
static
-int ctf_close_trace(struct trace_descriptor *tdp)
+int ctf_close_trace(struct bt_trace_descriptor *tdp)
{
struct ctf_trace *td = container_of(tdp, struct ctf_trace, parent);
int ret;
perror("Error closedir");
return ret;
}
+ free(td->metadata_string);
g_free(td);
return 0;
}
static
-void ctf_set_context(struct trace_descriptor *descriptor,
+void ctf_set_context(struct bt_trace_descriptor *descriptor,
struct bt_context *ctx)
{
struct ctf_trace *td = container_of(descriptor, struct ctf_trace,
parent);
- td->ctx = ctx;
+ td->parent.ctx = ctx;
}
static
-void ctf_set_handle(struct trace_descriptor *descriptor,
+void ctf_set_handle(struct bt_trace_descriptor *descriptor,
struct bt_trace_handle *handle)
{
struct ctf_trace *td = container_of(descriptor, struct ctf_trace,
parent);
- td->handle = handle;
+ td->parent.handle = handle;
}
static
{
uint64_t ts_nsec;
struct ctf_trace *trace = stream->stream_class->trace;
- struct trace_collection *tc = trace->collection;
+ struct trace_collection *tc = trace->parent.collection;
uint64_t tc_offset;
if (tc->clock_use_offset_avg)
tc_offset = tc->single_clock_offset_avg;
else
- tc_offset = trace->single_clock->offset;
+ tc_offset = trace->parent.single_clock->offset;
ts_nsec = clock_cycles_to_ns(stream->current_clock, timestamp);
ts_nsec += tc_offset; /* Add offset */
*/
__thread int bt_ctf_last_field_error = 0;
-const struct definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
+const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
enum bt_ctf_scope scope)
{
- const struct definition *tmp = NULL;
+ const struct bt_definition *tmp = NULL;
const struct ctf_event_definition *event;
if (!ctf_event)
return NULL;
}
-const struct definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
- const struct definition *scope,
+const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
+ const struct bt_definition *scope,
const char *field)
{
- const struct definition *def;
+ const struct bt_definition *def;
char *field_underscore;
if (!ctf_event || !scope || !field)
return NULL;
- def = lookup_definition(scope, field);
+ def = bt_lookup_definition(scope, field);
/*
* optionally a field can have an underscore prefix, try
* to lookup the field with this prefix if it failed
field_underscore = g_new(char, strlen(field) + 2);
field_underscore[0] = '_';
strcpy(&field_underscore[1], field);
- def = lookup_definition(scope, field_underscore);
+ def = bt_lookup_definition(scope, field_underscore);
g_free(field_underscore);
}
if (bt_ctf_field_type(bt_ctf_get_decl_from_def(def)) == CTF_TYPE_VARIANT) {
return def;
}
-const struct definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
- const struct definition *field,
+const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
+ const struct bt_definition *field,
unsigned int index)
{
- struct definition *ret = NULL;
+ struct bt_definition *ret = NULL;
if (!ctf_event || !field)
return NULL;
struct definition_array *array_definition;
array_definition = container_of(field,
struct definition_array, p);
- ret = array_index(array_definition, index);
+ ret = bt_array_index(array_definition, index);
} else if (bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_SEQUENCE) {
struct definition_sequence *sequence_definition;
sequence_definition = container_of(field,
struct definition_sequence, p);
- ret = sequence_index(sequence_definition, index);
+ ret = bt_sequence_index(sequence_definition, index);
}
return ret;
}
return g_quark_to_string(event_class->name);
}
-const char *bt_ctf_field_name(const struct definition *def)
+const char *bt_ctf_field_name(const struct bt_definition *def)
{
if (!def || !def->name)
return NULL;
return rem_(g_quark_to_string(def->name));
}
-enum ctf_type_id bt_ctf_field_type(const struct declaration *decl)
+enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *decl)
{
if (!decl)
return CTF_TYPE_UNKNOWN;
}
int bt_ctf_get_field_list(const struct bt_ctf_event *ctf_event,
- const struct definition *scope,
- struct definition const * const **list,
+ const struct bt_definition *scope,
+ struct bt_definition const * const **list,
unsigned int *count)
{
if (!ctf_event || !scope || !list || !count)
if (!def_struct)
goto error;
if (def_struct->fields->pdata) {
- *list = (struct definition const* const*) def_struct->fields->pdata;
+ *list = (struct bt_definition const* const*) def_struct->fields->pdata;
*count = def_struct->fields->len;
goto end;
} else {
if (!def_variant)
goto error;
if (def_variant->fields->pdata) {
- *list = (struct definition const* const*) def_variant->fields->pdata;
+ *list = (struct bt_definition const* const*) def_variant->fields->pdata;
*count = def_variant->fields->len;
goto end;
} else {
if (!def_array)
goto error;
if (def_array->elems->pdata) {
- *list = (struct definition const* const*) def_array->elems->pdata;
+ *list = (struct bt_definition const* const*) def_array->elems->pdata;
*count = def_array->elems->len;
goto end;
} else {
if (!def_sequence)
goto error;
if (def_sequence->elems->pdata) {
- *list = (struct definition const* const*) def_sequence->elems->pdata;
+ *list = (struct bt_definition const* const*) def_sequence->elems->pdata;
*count = def_sequence->elems->len;
goto end;
} else {
cfs = container_of(event->stream, const struct ctf_file_stream,
parent);
trace = cfs->parent.stream_class->trace;
- if (trace->ctx)
- ret = trace->ctx;
+ if (trace->parent.ctx)
+ ret = trace->parent.ctx;
return ret;
}
cfs = container_of(event->stream, const struct ctf_file_stream,
parent);
trace = cfs->parent.stream_class->trace;
- if (trace->handle)
- ret = trace->handle->id;
+ if (trace->parent.handle)
+ ret = trace->parent.handle->id;
return ret;
}
}
static const struct declaration_integer *
-get_declaration_integer(const struct declaration *decl)
+get_declaration_integer(const struct bt_declaration *decl)
{
if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_INTEGER)
return NULL;
}
static const struct declaration_string *
-get_declaration_string(const struct declaration *decl)
+get_declaration_string(const struct bt_declaration *decl)
{
if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_STRING)
return NULL;
}
static const struct declaration_array *
-get_declaration_array(const struct declaration *decl)
+get_declaration_array(const struct bt_declaration *decl)
{
if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_ARRAY)
return NULL;
}
static const struct declaration_sequence *
-get_declaration_sequence(const struct declaration *decl)
+get_declaration_sequence(const struct bt_declaration *decl)
{
if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_SEQUENCE)
return NULL;
return container_of(decl, const struct declaration_sequence, p);
}
-int bt_ctf_get_int_signedness(const struct declaration *decl)
+int bt_ctf_get_int_signedness(const struct bt_declaration *decl)
{
const struct declaration_integer *integer;
return integer->signedness;
}
-int bt_ctf_get_int_base(const struct declaration *decl)
+int bt_ctf_get_int_base(const struct bt_declaration *decl)
{
const struct declaration_integer *integer;
return integer->base;
}
-int bt_ctf_get_int_byte_order(const struct declaration *decl)
+int bt_ctf_get_int_byte_order(const struct bt_declaration *decl)
{
const struct declaration_integer *integer;
return integer->byte_order;
}
-ssize_t bt_ctf_get_int_len(const struct declaration *decl)
+ssize_t bt_ctf_get_int_len(const struct bt_declaration *decl)
{
const struct declaration_integer *integer;
return (ssize_t) integer->len;
}
-const struct definition *bt_ctf_get_enum_int(const struct definition *field)
+const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field)
{
const struct definition_enum *def_enum;
return &def_enum->integer->p;
}
-const char *bt_ctf_get_enum_str(const struct definition *field)
+const char *bt_ctf_get_enum_str(const struct bt_definition *field)
{
const struct definition_enum *def_enum;
const struct declaration_enum *decl_enum;
}
def_enum = container_of(field, const struct definition_enum, p);
decl_enum = def_enum->declaration;
- if (get_int_signedness(&def_enum->integer->p)) {
- array = enum_int_to_quark_set(decl_enum,
- get_signed_int(&def_enum->integer->p));
+ if (bt_get_int_signedness(&def_enum->integer->p)) {
+ array = bt_enum_int_to_quark_set(decl_enum,
+ bt_get_signed_int(&def_enum->integer->p));
} else {
- array = enum_uint_to_quark_set(decl_enum,
- get_unsigned_int(&def_enum->integer->p));
+ array = bt_enum_uint_to_quark_set(decl_enum,
+ bt_get_unsigned_int(&def_enum->integer->p));
}
if (!array) {
bt_ctf_field_set_error(-ENOENT);
return ret;
}
-enum ctf_string_encoding bt_ctf_get_encoding(const struct declaration *decl)
+enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *decl)
{
enum ctf_string_encoding ret = 0;
enum ctf_type_id type;
return -1;
}
-int bt_ctf_get_array_len(const struct declaration *decl)
+int bt_ctf_get_array_len(const struct bt_declaration *decl)
{
const struct declaration_array *array;
return -1;
}
-uint64_t bt_ctf_get_uint64(const struct definition *field)
+uint64_t bt_ctf_get_uint64(const struct bt_definition *field)
{
uint64_t ret = 0;
if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_INTEGER)
- ret = get_unsigned_int(field);
+ ret = bt_get_unsigned_int(field);
else
bt_ctf_field_set_error(-EINVAL);
return ret;
}
-int64_t bt_ctf_get_int64(const struct definition *field)
+int64_t bt_ctf_get_int64(const struct bt_definition *field)
{
int64_t ret = 0;
if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_INTEGER)
- ret = get_signed_int(field);
+ ret = bt_get_signed_int(field);
else
bt_ctf_field_set_error(-EINVAL);
return ret;
}
-char *bt_ctf_get_char_array(const struct definition *field)
+char *bt_ctf_get_char_array(const struct bt_definition *field)
{
char *ret = NULL;
GString *char_array;
if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_ARRAY) {
- char_array = get_char_array(field);
+ char_array = bt_get_char_array(field);
if (char_array) {
ret = char_array->str;
goto end;
return ret;
}
-char *bt_ctf_get_string(const struct definition *field)
+char *bt_ctf_get_string(const struct bt_definition *field)
{
char *ret = NULL;
if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_STRING)
- ret = get_string(field);
+ ret = bt_get_string(field);
else
bt_ctf_field_set_error(-EINVAL);
unsigned int *count)
{
struct bt_trace_handle *handle;
- struct trace_descriptor *td;
+ struct bt_trace_descriptor *td;
struct ctf_trace *tin;
if (!ctx || !list || !count)
gpointer *ret_list = NULL;
GPtrArray *fields_array = NULL;
int ret = 0;
- *count = 0;
if (!event_decl || !list || !count)
return -EINVAL;
+ *count = 0;
switch (scope) {
case BT_EVENT_CONTEXT:
if (event_decl->context_decl) {
return rem_(g_quark_to_string(((struct declaration_field *) field)->name));
}
-const struct declaration *bt_ctf_get_decl_from_def(const struct definition *def)
+const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *def)
{
if (def)
return def->declaration;
return NULL;
}
-const struct declaration *bt_ctf_get_decl_from_field_decl(
+const struct bt_declaration *bt_ctf_get_decl_from_field_decl(
const struct bt_ctf_field_decl *field)
{
if (field)
assert(iter);
ret = &iter->current_ctf_event;
- file_stream = heap_maximum(iter->parent.stream_heap);
+ file_stream = bt_heap_maximum(iter->parent.stream_heap);
if (!file_stream) {
/* end of file for all streams */
goto stop;
+++ /dev/null
-#ifndef _BABELTRACE_FORMAT_CTF_MEMSTREAM_H
-#define _BABELTRACE_FORMAT_CTF_MEMSTREAM_H
-
-/*
- * format/ctf/memstream.h
- *
- * Copyright 2012 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * memstream compatibility layer.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#define _GNU_SOURCE
-#include <config.h>
-
-#ifdef BABELTRACE_HAVE_FMEMOPEN
-#include <stdio.h>
-
-static inline
-FILE *babeltrace_fmemopen(void *buf, size_t size, const char *mode)
-{
- return fmemopen(buf, size, mode);
-}
-
-#else /* BABELTRACE_HAVE_FMEMOPEN */
-
-#include <stdlib.h>
-#include <stdio.h>
-
-/*
- * Fallback for systems which don't have fmemopen. Copy buffer to a
- * temporary file, and use that file as FILE * input.
- */
-static inline
-FILE *babeltrace_fmemopen(void *buf, size_t size, const char *mode)
-{
- char tmpname[PATH_MAX];
- size_t len;
- FILE *fp;
- int ret;
-
- /*
- * Support reading only.
- */
- if (strcmp(mode, "rb") != 0) {
- return NULL;
- }
- strncpy(tmpname, "/tmp/babeltrace-tmp-XXXXXX", PATH_MAX);
- ret = mkstemp(tmpname);
- if (ret < 0) {
- return NULL;
- }
- /*
- * We need to write to the file.
- */
- fp = fdopen(ret, "w+");
- if (!fp) {
- goto error_unlink;
- }
- /* Copy the entire buffer to the file */
- len = fwrite(buf, sizeof(char), size, fp);
- if (len != size) {
- goto error_close;
- }
- ret = fseek(fp, 0L, SEEK_SET);
- if (ret < 0) {
- perror("fseek");
- goto error_close;
- }
- /* We keep the handle open, but can unlink the file on the VFS. */
- ret = unlink(tmpname);
- if (ret < 0) {
- perror("unlink");
- }
- return fp;
-
-error_close:
- ret = fclose(fp);
- if (ret < 0) {
- perror("close");
- }
-error_unlink:
- ret = unlink(tmpname);
- if (ret < 0) {
- perror("unlink");
- }
- return NULL;
-}
-
-#endif /* BABELTRACE_HAVE_FMEMOPEN */
-
-#ifdef BABELTRACE_HAVE_OPEN_MEMSTREAM
-
-#include <stdio.h>
-
-static inline
-FILE *babeltrace_open_memstream(char **ptr, size_t *sizeloc)
-{
- return open_memstream(ptr, sizeloc);
-}
-
-static inline
-int babeltrace_close_memstream(char **buf, size_t *size, FILE *fp)
-{
- return fclose(fp);
-}
-
-#else /* BABELTRACE_HAVE_OPEN_MEMSTREAM */
-
-#include <stdlib.h>
-#include <stdio.h>
-
-/*
- * Fallback for systems which don't have open_memstream. Create FILE *
- * with babeltrace_open_memstream, but require call to
- * babeltrace_close_memstream to flush all data written to the FILE *
- * into the buffer (which we allocate).
- */
-static inline
-FILE *babeltrace_open_memstream(char **ptr, size_t *sizeloc)
-{
- char tmpname[PATH_MAX];
- int ret;
- FILE *fp;
-
- strncpy(tmpname, "/tmp/babeltrace-tmp-XXXXXX", PATH_MAX);
- ret = mkstemp(tmpname);
- if (ret < 0) {
- return NULL;
- }
- fp = fdopen(ret, "w+");
- if (!fp) {
- goto error_unlink;
- }
- /*
- * babeltrace_flush_memstream will update the buffer content
- * with read from fp. No need to keep the file around, just the
- * handle.
- */
- ret = unlink(tmpname);
- if (ret < 0) {
- perror("unlink");
- }
- return fp;
-
-error_unlink:
- ret = unlink(tmpname);
- if (ret < 0) {
- perror("unlink");
- }
- return NULL;
-}
-
-/* Get file size, allocate buffer, copy. */
-static inline
-int babeltrace_close_memstream(char **buf, size_t *size, FILE *fp)
-{
- size_t len, n;
- long pos;
- int ret;
-
- ret = fflush(fp);
- if (ret < 0) {
- perror("fflush");
- return ret;
- }
- ret = fseek(fp, 0L, SEEK_END);
- if (ret < 0) {
- perror("fseek");
- return ret;
- }
- pos = ftell(fp);
- if (ret < 0) {
- perror("ftell");
- return ret;
- }
- *size = pos;
- /* add final \0 */
- *buf = calloc(pos + 1, sizeof(char));
- if (!*buf) {
- return -ENOMEM;
- }
- ret = fseek(fp, 0L, SEEK_SET);
- if (ret < 0) {
- perror("fseek");
- goto error_free;
- }
- /* Copy the entire file into the buffer */
- n = 0;
- clearerr(fp);
- while (!feof(fp) && !ferror(fp) && (*size - n > 0)) {
- len = fread(*buf, sizeof(char), *size - n, fp);
- n += len;
- }
- if (n != *size) {
- ret = -1;
- goto error_close;
- }
- ret = fclose(fp);
- if (ret < 0) {
- perror("fclose");
- return ret;
- }
- return 0;
-
-error_close:
- ret = fclose(fp);
- if (ret < 0) {
- perror("fclose");
- }
-error_free:
- free(*buf);
- *buf = NULL;
- return ret;
-}
-
-#endif /* BABELTRACE_HAVE_OPEN_MEMSTREAM */
-
-#endif /* _BABELTRACE_FORMAT_CTF_MEMSTREAM_H */
noinst_HEADERS = \
ctf-scanner.h \
- ctf-ast.h
+ ctf-ast.h \
+ ctf-scanner-symbols.h \
+ objstack.h
-libctf_parser_la_SOURCES = ctf-lexer.l ctf-parser.y
+libctf_parser_la_SOURCES = ctf-lexer.l ctf-parser.y objstack.c
+libctf_parser_la_CFLAGS = $(AM_CFLAGS) -include ctf-scanner-symbols.h
libctf_ast_la_SOURCES = ctf-visitor-xml.c \
ctf-visitor-parent-links.c \
struct ctf_node;
struct ctf_parser;
-enum node_type {
- NODE_UNKNOWN = 0,
- NODE_ROOT,
-
- NODE_EVENT,
- NODE_STREAM,
- NODE_ENV,
- NODE_TRACE,
- NODE_CLOCK,
- NODE_CALLSITE,
-
- NODE_CTF_EXPRESSION,
- NODE_UNARY_EXPRESSION,
-
- NODE_TYPEDEF,
- NODE_TYPEALIAS_TARGET,
- NODE_TYPEALIAS_ALIAS,
- NODE_TYPEALIAS,
-
- NODE_TYPE_SPECIFIER,
- NODE_TYPE_SPECIFIER_LIST,
- NODE_POINTER,
- NODE_TYPE_DECLARATOR,
-
- NODE_FLOATING_POINT,
- NODE_INTEGER,
- NODE_STRING,
- NODE_ENUMERATOR,
- NODE_ENUM,
- NODE_STRUCT_OR_VARIANT_DECLARATION,
- NODE_VARIANT,
- NODE_STRUCT,
+#define FOREACH_CTF_NODES(F) \
+ F(NODE_UNKNOWN) \
+ F(NODE_ROOT) \
+ F(NODE_ERROR) \
+ F(NODE_EVENT) \
+ F(NODE_STREAM) \
+ F(NODE_ENV) \
+ F(NODE_TRACE) \
+ F(NODE_CLOCK) \
+ F(NODE_CALLSITE) \
+ F(NODE_CTF_EXPRESSION) \
+ F(NODE_UNARY_EXPRESSION) \
+ F(NODE_TYPEDEF) \
+ F(NODE_TYPEALIAS_TARGET) \
+ F(NODE_TYPEALIAS_ALIAS) \
+ F(NODE_TYPEALIAS) \
+ F(NODE_TYPE_SPECIFIER) \
+ F(NODE_TYPE_SPECIFIER_LIST) \
+ F(NODE_POINTER) \
+ F(NODE_TYPE_DECLARATOR) \
+ F(NODE_FLOATING_POINT) \
+ F(NODE_INTEGER) \
+ F(NODE_STRING) \
+ F(NODE_ENUMERATOR) \
+ F(NODE_ENUM) \
+ F(NODE_STRUCT_OR_VARIANT_DECLARATION) \
+ F(NODE_VARIANT) \
+ F(NODE_STRUCT)
+enum node_type {
+#define ENTRY(S) S,
+ FOREACH_CTF_NODES(ENTRY)
+#undef ENTRY
NR_NODE_TYPES,
};
struct ctf_node *parent;
struct bt_list_head siblings;
struct bt_list_head tmp_head;
- struct bt_list_head gc;
+ unsigned int lineno;
enum node_type type;
union {
UNARY_SIGNED_CONSTANT,
UNARY_UNSIGNED_CONSTANT,
UNARY_SBRAC,
- UNARY_NESTED,
} type;
union {
/*
int64_t signed_constant;
uint64_t unsigned_constant;
struct ctf_node *sbrac_exp;
- struct ctf_node *nested_exp;
} u;
enum {
UNARY_LINK_UNKNOWN = 0,
struct ctf_ast {
struct ctf_node root;
- struct bt_list_head allocated_nodes;
};
const char *node_type(struct ctf_node *node);
struct ctf_trace;
+BT_HIDDEN
int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node);
+BT_HIDDEN
int ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node);
+BT_HIDDEN
int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node);
+BT_HIDDEN
int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node,
struct ctf_trace *trace, int byte_order);
+BT_HIDDEN
int ctf_destroy_metadata(struct ctf_trace *trace);
#endif /* _CTF_AST_H */
*/
#include <stdio.h>
+#include <ctype.h>
#include <babeltrace/babeltrace-internal.h>
#include "ctf-scanner.h"
#include "ctf-parser.h"
#include "ctf-ast.h"
-__attribute__((visibility("hidden")))
+#define PARSE_INTEGER_LITERAL(base) \
+ do { \
+ errno = 0; \
+ yylval->ull = strtoull(yytext, NULL, base); \
+ if (errno) { \
+ printfl_perror(yylineno, "Integer literal"); \
+ return ERROR; \
+ } \
+ } while (0)
+
+BT_HIDDEN
void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src);
static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner)
__attribute__((unused));
static int input (yyscan_t yyscanner) __attribute__((unused));
+BT_HIDDEN
+int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src, char delim);
+
%}
%x comment_ml comment_sl string_lit char_const
%option reentrant yylineno noyywrap bison-bridge
%option extra-type="struct ctf_scanner *"
/* bison-locations */
-INTEGER_SUFFIX [ \n\t]*(U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu)
+INTEGER_SUFFIX (U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu)
DIGIT [0-9]
NONDIGIT [a-zA-Z_]
HEXDIGIT [0-9A-Fa-f]
UCHARUPPERCASE \\U{HEXDIGIT}{8}
ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE}
IDENTIFIER {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})*
-ESCSEQ \\(\'|\"|\?|\\|a|b|f|n|r|t|v|{OCTALDIGIT}{1,3}|u{HEXDIGIT}{4}|U{HEXDIGIT}{8}|x{HEXDIGIT}+)
%%
/*
"/*" BEGIN(comment_ml);
<comment_ml>[^*\n]* /* eat anything that's not a '*' */
<comment_ml>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
-<comment_ml>\n ++yylineno;
+<comment_ml>\n
<comment_ml>"*"+"/" BEGIN(INITIAL);
-"//" BEGIN(comment_sl);
-<comment_sl>[^\n]*\n ++yylineno; BEGIN(INITIAL);
-
-L\' BEGIN(char_const); return CHARACTER_CONSTANT_START;
-\' BEGIN(char_const); return CHARACTER_CONSTANT_START;
-<char_const>\' BEGIN(INITIAL); return SQUOTE;
+"//"[^\n]*\n /* skip comment */
-L\" BEGIN(string_lit); return STRING_LITERAL_START;
-\" BEGIN(string_lit); return STRING_LITERAL_START;
-<string_lit>\" BEGIN(INITIAL); return DQUOTE;
-
-<char_const,string_lit>ESCSEQ return ESCSEQ;
-<char_const,string_lit>\n ; /* ignore */
-<char_const,string_lit>. setstring(yyextra, yylval, yytext); return CHAR_STRING_TOKEN;
+L?\"(\\.|[^\\"])*\" { if (import_string(yyextra, yylval, yytext, '\"') < 0) return ERROR; else return STRING_LITERAL; }
+L?\'(\\.|[^\\'])*\' { if (import_string(yyextra, yylval, yytext, '\'') < 0) return ERROR; else return CHARACTER_LITERAL; }
"[" return LSBRAC;
"]" return RSBRAC;
_Bool setstring(yyextra, yylval, yytext); return _BOOL;
_Complex setstring(yyextra, yylval, yytext); return _COMPLEX;
_Imaginary setstring(yyextra, yylval, yytext); return _IMAGINARY;
-[1-9]{DIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return DECIMAL_CONSTANT;
-0{OCTALDIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return OCTAL_CONSTANT;
-0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return HEXADECIMAL_CONSTANT;
+[1-9]{DIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(10); return INTEGER_LITERAL;
+0{OCTALDIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(8); return INTEGER_LITERAL;
+0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(16); return INTEGER_LITERAL;
+
{IDENTIFIER} printf_debug("<IDENTIFIER %s>\n", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER;
-[ \t\n]+ ; /* ignore */
-. return ERROR;
+[ \t\r\n] ; /* ignore */
+. printfl_error(yylineno, "invalid character '0x%02X'", yytext[0]); return ERROR;
%%
*/
#include <stdio.h>
+#include <ctype.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include "ctf-scanner.h"
#include "ctf-parser.h"
#include "ctf-ast.h"
+#include "objstack.h"
-__attribute__((visibility("hidden")))
+BT_HIDDEN
int yydebug;
/* Join two lists, put "add" at the end of "head". */
}
}
-__attribute__((visibility("hidden")))
+BT_HIDDEN
int yyparse(struct ctf_scanner *scanner);
-__attribute__((visibility("hidden")))
+BT_HIDDEN
int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
-__attribute__((visibility("hidden")))
+BT_HIDDEN
int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
-__attribute__((visibility("hidden")))
+BT_HIDDEN
int yylex_destroy(yyscan_t yyscanner);
-__attribute__((visibility("hidden")))
+BT_HIDDEN
void yyrestart(FILE * in_str, yyscan_t scanner);
+BT_HIDDEN
+int yyget_lineno(yyscan_t yyscanner);
+BT_HIDDEN
+char *yyget_text(yyscan_t yyscanner);
-struct gc_string {
- struct bt_list_head gc;
- size_t alloclen;
- char s[];
+static const char *node_type_to_str[] = {
+#define ENTRY(S) [S] = #S,
+ FOREACH_CTF_NODES(ENTRY)
+#undef ENTRY
};
-static const char *node_type_to_str[] = {
- [ NODE_UNKNOWN ] = "NODE_UNKNOWN",
- [ NODE_ROOT ] = "NODE_ROOT",
- [ NODE_EVENT ] = "NODE_EVENT",
- [ NODE_ENV ] = "NODE_ENV",
- [ NODE_STREAM ] = "NODE_STREAM",
- [ NODE_TRACE ] = "NODE_TRACE",
- [ NODE_CLOCK ] = "NODE_CLOCK",
- [ NODE_CALLSITE ] = "NODE_CALLSITE",
- [ NODE_CTF_EXPRESSION ] = "NODE_CTF_EXPRESSION",
- [ NODE_UNARY_EXPRESSION ] = "NODE_UNARY_EXPRESSION",
- [ NODE_TYPEDEF ] = "NODE_TYPEDEF",
- [ NODE_TYPEALIAS_TARGET ] = "NODE_TYPEALIAS_TARGET",
- [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS",
- [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS",
- [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER",
- [ NODE_TYPE_SPECIFIER_LIST ] = "NODE_TYPE_SPECIFIER_LIST",
- [ NODE_POINTER ] = "NODE_POINTER",
- [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR",
- [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT",
- [ NODE_INTEGER ] = "NODE_INTEGER",
- [ NODE_STRING ] = "NODE_STRING",
- [ NODE_ENUMERATOR ] = "NODE_ENUMERATOR",
- [ NODE_ENUM ] = "NODE_ENUM",
- [ NODE_STRUCT_OR_VARIANT_DECLARATION ] = "NODE_STRUCT_OR_VARIANT_DECLARATION",
- [ NODE_VARIANT ] = "NODE_VARIANT",
- [ NODE_STRUCT ] = "NODE_STRUCT",
+/*
+ * Static node for out of memory errors. Only "type" is used. lineno is
+ * always left at 0. The rest of the node content can be overwritten,
+ * but is never used.
+ */
+static struct ctf_node error_node = {
+ .type = NODE_ERROR,
};
-__attribute__((visibility("hidden")))
+BT_HIDDEN
const char *node_type(struct ctf_node *node)
{
if (node->type < NR_NODE_TYPES)
return NULL;
}
-static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
- size_t len)
+void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
{
- struct gc_string *gstr;
- size_t alloclen;
-
- /* TODO: could be faster with find first bit or glib Gstring */
- /* sizeof long to account for malloc header (int or long ?) */
- for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
- alloclen *= 2);
-
- gstr = malloc(alloclen);
- bt_list_add(&gstr->gc, &scanner->allocated_strings);
- gstr->alloclen = alloclen;
- return gstr;
+ lvalp->s = objstack_alloc(scanner->objstack, strlen(src) + 1);
+ strcpy(lvalp->s, src);
}
-/*
- * note: never use gc_string_append on a string that has external references.
- * gsrc will be garbage collected immediately, and gstr might be.
- * Should only be used to append characters to a string literal or constant.
- */
-__attribute__((visibility("hidden")))
-struct gc_string *gc_string_append(struct ctf_scanner *scanner,
- struct gc_string *gstr,
- struct gc_string *gsrc)
+static
+int str_check(size_t str_len, size_t offset, size_t len)
{
- size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
- size_t alloclen;
-
- /* TODO: could be faster with find first bit or glib Gstring */
- /* sizeof long to account for malloc header (int or long ?) */
- for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
- alloclen *= 2);
-
- if (alloclen > gstr->alloclen) {
- struct gc_string *newgstr;
-
- newgstr = gc_string_alloc(scanner, newlen);
- strcpy(newgstr->s, gstr->s);
- strcat(newgstr->s, gsrc->s);
- bt_list_del(&gstr->gc);
- free(gstr);
- gstr = newgstr;
- } else {
- strcat(gstr->s, gsrc->s);
+ /* check overflow */
+ if (offset + len < offset)
+ return -1;
+ if (offset + len > str_len)
+ return -1;
+ return 0;
+}
+
+static
+int bt_isodigit(int c)
+{
+ switch (c) {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ return 1;
+ default:
+ return 0;
}
- bt_list_del(&gsrc->gc);
- free(gsrc);
- return gstr;
}
-void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
+static
+int parse_base_sequence(const char *src, size_t len, size_t pos,
+ char *buffer, size_t *buf_len, int base)
{
- lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
- strcpy(lvalp->gs->s, src);
+ const size_t max_char = 3;
+ int nr_char = 0;
+
+ while (!str_check(len, pos, 1) && nr_char < max_char) {
+ char c = src[pos++];
+
+ if (base == 8) {
+ if (bt_isodigit(c))
+ buffer[nr_char++] = c;
+ else
+ break;
+ } else if (base == 16) {
+ if (isxdigit(c))
+ buffer[nr_char++] = c;
+ else
+ break;
+
+ } else {
+ /* Unsupported base */
+ return -1;
+ }
+ }
+ assert(nr_char > 0);
+ buffer[nr_char] = '\0';
+ *buf_len = nr_char;
+ return 0;
+}
+
+static
+int import_basic_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
+ size_t len, const char *src, char delim)
+{
+ size_t pos = 0, dpos = 0;
+
+ if (str_check(len, pos, 1))
+ return -1;
+ if (src[pos++] != delim)
+ return -1;
+
+ while (src[pos] != delim) {
+ char c;
+
+ if (str_check(len, pos, 1))
+ return -1;
+ c = src[pos++];
+ if (c == '\\') {
+ if (str_check(len, pos, 1))
+ return -1;
+ c = src[pos++];
+
+ switch (c) {
+ case 'a':
+ c = '\a';
+ break;
+ case 'b':
+ c = '\b';
+ break;
+ case 'f':
+ c = '\f';
+ break;
+ case 'n':
+ c = '\n';
+ break;
+ case 'r':
+ c = '\r';
+ break;
+ case 't':
+ c = '\t';
+ break;
+ case 'v':
+ c = '\v';
+ break;
+ case '\\':
+ c = '\\';
+ break;
+ case '\'':
+ c = '\'';
+ break;
+ case '\"':
+ c = '\"';
+ break;
+ case '?':
+ c = '?';
+ break;
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ {
+ char oct_buffer[4];
+ size_t oct_len;
+
+ if (parse_base_sequence(src, len, pos - 1,
+ oct_buffer, &oct_len, 8))
+ return -1;
+ c = strtoul(&oct_buffer[0], NULL, 8);
+ pos += oct_len - 1;
+ break;
+ }
+ case 'x':
+ {
+ char hex_buffer[4];
+ size_t hex_len;
+
+ if (parse_base_sequence(src, len, pos,
+ hex_buffer, &hex_len, 16))
+ return -1;
+ c = strtoul(&hex_buffer[0], NULL, 16);
+ pos += hex_len;
+ break;
+ }
+ default:
+ return -1;
+ }
+ }
+ if (str_check(len, dpos, 1))
+ return -1;
+ lvalp->s[dpos++] = c;
+ }
+
+ if (str_check(len, dpos, 1))
+ return -1;
+ lvalp->s[dpos++] = '\0';
+
+ if (str_check(len, pos, 1))
+ return -1;
+ if (src[pos++] != delim)
+ return -1;
+
+ if (str_check(len, pos, 1))
+ return -1;
+ if (src[pos] != '\0')
+ return -1;
+ return 0;
+}
+
+int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
+ const char *src, char delim)
+{
+ size_t len;
+
+ len = strlen(src) + 1;
+ lvalp->s = objstack_alloc(scanner->objstack, len);
+ if (src[0] == 'L') {
+ // TODO: import wide string
+ printfl_error(yyget_lineno(scanner),
+ "Wide string not supported yet.");
+ return -1;
+ } else {
+ return import_basic_string(scanner, lvalp, len, src, delim);
+ }
}
static void init_scope(struct ctf_scanner_scope *scope,
return ret;
}
-__attribute__((visibility("hidden")))
+BT_HIDDEN
int is_type(struct ctf_scanner *scanner, const char *id)
{
struct ctf_scanner_scope *it;
return ret;
}
-static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
+static void add_type(struct ctf_scanner *scanner, char *id)
{
- printf_debug("add type %s\n", id->s);
- if (lookup_type(scanner->cs, id->s))
+ printf_debug("add type %s\n", id);
+ if (lookup_type(scanner->cs, id))
return;
- g_hash_table_insert(scanner->cs->types, id->s, id->s);
+ g_hash_table_insert(scanner->cs->types, id, id);
}
static struct ctf_node *make_node(struct ctf_scanner *scanner,
enum node_type type)
{
- struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
struct ctf_node *node;
- node = malloc(sizeof(*node));
- if (!node)
- return NULL;
- memset(node, 0, sizeof(*node));
+ node = objstack_alloc(scanner->objstack, sizeof(*node));
+ if (!node) {
+ printfl_fatal(yyget_lineno(scanner->scanner), "out of memory");
+ return &error_node;
+ }
node->type = type;
+ node->lineno = yyget_lineno(scanner->scanner);
BT_INIT_LIST_HEAD(&node->tmp_head);
- bt_list_add(&node->gc, &ast->allocated_nodes);
bt_list_add(&node->siblings, &node->tmp_head);
switch (type) {
case NODE_ROOT:
- fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
+ node->type = NODE_ERROR;
+ printfn_fatal(node, "trying to create root node");
break;
case NODE_EVENT:
case NODE_UNKNOWN:
default:
- fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
- (int) type);
+ node->type = NODE_ERROR;
+ printfn_fatal(node, "unknown node type '%d'", (int) type);
break;
}
case NODE_UNKNOWN:
default:
- fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
- (int) parent->type);
+ printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
return -EINVAL;
}
return 0;
case NODE_UNKNOWN:
default:
- fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
- (int) parent->type);
+ printfn_fatal(node, "unknown node type %d", parent->type);
return -EINVAL;
}
return 0;
case NODE_UNKNOWN:
default:
- fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
- (int) parent->type);
+ printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
return -EINVAL;
}
return 0;
case NODE_UNKNOWN:
default:
- fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
- (int) parent->type);
+ printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
return -EINVAL;
}
return 0;
case NODE_UNKNOWN:
default:
- fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
- (int) parent->type);
+ printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
return -EINVAL;
}
return 0;
case NODE_UNKNOWN:
default:
- fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
- (int) parent->type);
+ printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
return -EINVAL;
}
return 0;
switch (node->type) {
case NODE_ROOT:
- fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
+ printfn_fatal(node, "trying to reparent root node");
return -EINVAL;
case NODE_EVENT:
case NODE_UNKNOWN:
default:
- fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
- (int) parent->type);
+ printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
return -EINVAL;
}
return 0;
}
-__attribute__((visibility("hidden")))
+BT_HIDDEN
void yyerror(struct ctf_scanner *scanner, const char *str)
{
- fprintf(stderr, "error %s\n", str);
+ printfl_error(yyget_lineno(scanner->scanner),
+ "token \"%s\": %s\n",
+ yyget_text(scanner->scanner), str);
}
-__attribute__((visibility("hidden")))
+BT_HIDDEN
int yywrap(void)
{
return 1;
#define reparent_error(scanner, str) \
do { \
- yyerror(scanner, YY_("reparent_error: " str "\n")); \
+ yyerror(scanner, YY_("reparent_error: " str)); \
YYERROR; \
} while (0)
-static void free_strings(struct bt_list_head *list)
-{
- struct gc_string *gstr, *tmp;
-
- bt_list_for_each_entry_safe(gstr, tmp, list, gc)
- free(gstr);
-}
-
-static struct ctf_ast *ctf_ast_alloc(void)
+static struct ctf_ast *ctf_ast_alloc(struct ctf_scanner *scanner)
{
struct ctf_ast *ast;
- ast = malloc(sizeof(*ast));
+ ast = objstack_alloc(scanner->objstack, sizeof(*ast));
if (!ast)
return NULL;
- memset(ast, 0, sizeof(*ast));
- BT_INIT_LIST_HEAD(&ast->allocated_nodes);
ast->root.type = NODE_ROOT;
BT_INIT_LIST_HEAD(&ast->root.tmp_head);
BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
return ast;
}
-static void ctf_ast_free(struct ctf_ast *ast)
-{
- struct ctf_node *node, *tmp;
-
- bt_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
- free(node);
- free(ast);
-}
-
int ctf_scanner_append_ast(struct ctf_scanner *scanner)
{
return yyparse(scanner);
ret = yylex_init_extra(scanner, &scanner->scanner);
if (ret) {
- fprintf(stderr, "yylex_init error\n");
+ printf_fatal("yylex_init error");
goto cleanup_scanner;
}
/* Start processing new stream */
yyrestart(input, scanner->scanner);
- scanner->ast = ctf_ast_alloc();
- if (!scanner->ast)
+ scanner->objstack = objstack_create();
+ if (!scanner->objstack)
goto cleanup_lexer;
+ scanner->ast = ctf_ast_alloc(scanner);
+ if (!scanner->ast)
+ goto cleanup_objstack;
init_scope(&scanner->root_scope, NULL);
scanner->cs = &scanner->root_scope;
- BT_INIT_LIST_HEAD(&scanner->allocated_strings);
if (yydebug)
fprintf(stdout, "Scanner input is a%s.\n",
return scanner;
+cleanup_objstack:
+ objstack_destroy(scanner->objstack);
cleanup_lexer:
ret = yylex_destroy(scanner->scanner);
if (!ret)
- fprintf(stderr, "yylex_destroy error\n");
+ printf_fatal("yylex_destroy error");
cleanup_scanner:
free(scanner);
return NULL;
int ret;
finalize_scope(&scanner->root_scope);
- free_strings(&scanner->allocated_strings);
- ctf_ast_free(scanner->ast);
+ objstack_destroy(scanner->objstack);
ret = yylex_destroy(scanner->scanner);
if (ret)
- fprintf(stderr, "yylex_destroy error\n");
+ printf_error("yylex_destroy error");
free(scanner);
}
%define api.pure
/* %locations */
+%error-verbose
%parse-param {struct ctf_scanner *scanner}
%lex-param {struct ctf_scanner *scanner}
/*
*/
%expect 2
%start file
-%token CHARACTER_CONSTANT_START SQUOTE STRING_LITERAL_START DQUOTE ESCSEQ CHAR_STRING_TOKEN LSBRAC RSBRAC LPAREN RPAREN LBRAC RBRAC RARROW STAR PLUS MINUS LT GT TYPEASSIGN COLON SEMICOLON DOTDOTDOT DOT EQUAL COMMA CONST CHAR DOUBLE ENUM ENV EVENT FLOATING_POINT FLOAT INTEGER INT LONG SHORT SIGNED STREAM STRING STRUCT TRACE CALLSITE CLOCK TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY DECIMAL_CONSTANT OCTAL_CONSTANT HEXADECIMAL_CONSTANT TOK_ALIGN
-%token <gs> IDENTIFIER ID_TYPE
+%token INTEGER_LITERAL STRING_LITERAL CHARACTER_LITERAL LSBRAC RSBRAC LPAREN RPAREN LBRAC RBRAC RARROW STAR PLUS MINUS LT GT TYPEASSIGN COLON SEMICOLON DOTDOTDOT DOT EQUAL COMMA CONST CHAR DOUBLE ENUM ENV EVENT FLOATING_POINT FLOAT INTEGER INT LONG SHORT SIGNED STREAM STRING STRUCT TRACE CALLSITE CLOCK TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY TOK_ALIGN
+%token <s> IDENTIFIER ID_TYPE
%token ERROR
%union
{
long long ll;
+ unsigned long long ull;
char c;
- struct gc_string *gs;
+ char *s;
struct ctf_node *n;
}
-%type <gs> keywords
-%type <gs> s_char s_char_sequence c_char c_char_sequence
+%type <s> STRING_LITERAL CHARACTER_LITERAL
+
+%type <s> keywords
+%type <ull> INTEGER_LITERAL
%type <n> postfix_expression unary_expression unary_expression_or_range
%type <n> declaration
keywords:
VOID
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| CHAR
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| SHORT
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| INT
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| LONG
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| FLOAT
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| DOUBLE
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| SIGNED
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| UNSIGNED
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| _BOOL
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| _COMPLEX
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| _IMAGINARY
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| FLOATING_POINT
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| INTEGER
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| STRING
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| ENUM
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| VARIANT
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| STRUCT
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| CONST
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| TYPEDEF
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| EVENT
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| STREAM
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| ENV
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| TRACE
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| CLOCK
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| CALLSITE
- { $$ = yylval.gs; }
+ { $$ = yylval.s; }
| TOK_ALIGN
- { $$ = yylval.gs; }
- ;
-
-/* 1.5 Constants */
-
-c_char_sequence:
- c_char
- { $$ = $1; }
- | c_char_sequence c_char
- { $$ = gc_string_append(scanner, $1, $2); }
- ;
-
-c_char:
- CHAR_STRING_TOKEN
- { $$ = yylval.gs; }
- | ESCSEQ
- {
- reparent_error(scanner, "escape sequences not supported yet");
- }
+ { $$ = yylval.s; }
;
-/* 1.6 String literals */
-
-s_char_sequence:
- s_char
- { $$ = $1; }
- | s_char_sequence s_char
- { $$ = gc_string_append(scanner, $1, $2); }
- ;
-
-s_char:
- CHAR_STRING_TOKEN
- { $$ = yylval.gs; }
- | ESCSEQ
- {
- reparent_error(scanner, "escape sequences not supported yet");
- }
- ;
/* 2: Phrase structure grammar */
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_STRING;
- $$->u.unary_expression.u.string = yylval.gs->s;
+ $$->u.unary_expression.u.string = yylval.s;
}
| ID_TYPE
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_STRING;
- $$->u.unary_expression.u.string = yylval.gs->s;
+ $$->u.unary_expression.u.string = yylval.s;
}
| keywords
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_STRING;
- $$->u.unary_expression.u.string = yylval.gs->s;
- }
- | DECIMAL_CONSTANT
- {
- $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
- $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
- sscanf(yylval.gs->s, "%" PRIu64,
- &$$->u.unary_expression.u.unsigned_constant);
- }
- | OCTAL_CONSTANT
- {
- $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
- $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
- sscanf(yylval.gs->s, "0%" PRIo64,
- &$$->u.unary_expression.u.unsigned_constant);
+ $$->u.unary_expression.u.string = yylval.s;
}
- | HEXADECIMAL_CONSTANT
+ | INTEGER_LITERAL
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
- sscanf(yylval.gs->s, "0x%" PRIx64,
- &$$->u.unary_expression.u.unsigned_constant);
+ $$->u.unary_expression.u.unsigned_constant = $1;
}
- | STRING_LITERAL_START DQUOTE
+ | STRING_LITERAL
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_STRING;
- $$->u.unary_expression.u.string = "";
+ $$->u.unary_expression.u.string = $1;
}
- | STRING_LITERAL_START s_char_sequence DQUOTE
+ | CHARACTER_LITERAL
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_STRING;
- $$->u.unary_expression.u.string = $2->s;
- }
- | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
- {
- $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
- $$->u.unary_expression.type = UNARY_STRING;
- $$->u.unary_expression.u.string = $2->s;
+ $$->u.unary_expression.u.string = $1;
}
| LPAREN unary_expression RPAREN
{
- $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
- $$->u.unary_expression.type = UNARY_NESTED;
- $$->u.unary_expression.u.nested_exp = $2;
+ $$ = $2;
}
| postfix_expression LSBRAC unary_expression RSBRAC
{
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_STRING;
- $$->u.unary_expression.u.string = yylval.gs->s;
+ $$->u.unary_expression.u.string = yylval.s;
$$->u.unary_expression.link = UNARY_DOTLINK;
bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_STRING;
- $$->u.unary_expression.u.string = yylval.gs->s;
+ $$->u.unary_expression.u.string = yylval.s;
$$->u.unary_expression.link = UNARY_DOTLINK;
bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_STRING;
- $$->u.unary_expression.u.string = yylval.gs->s;
+ $$->u.unary_expression.u.string = yylval.s;
$$->u.unary_expression.link = UNARY_ARROWLINK;
bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_STRING;
- $$->u.unary_expression.u.string = yylval.gs->s;
+ $$->u.unary_expression.u.string = yylval.s;
$$->u.unary_expression.link = UNARY_ARROWLINK;
bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
postfix_expression
{ $$ = $1; }
| PLUS postfix_expression
- { $$ = $2; }
- | MINUS postfix_expression
{
$$ = $2;
- if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
- && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
+ if ($$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
+ && $$->u.unary_expression.type != UNARY_SIGNED_CONSTANT) {
reparent_error(scanner, "expecting numeric constant");
-
+ }
+ }
+ | MINUS postfix_expression
+ {
+ $$ = $2;
if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
$$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
$$->u.unary_expression.u.signed_constant =
-($$->u.unary_expression.u.unsigned_constant);
- } else {
+ } else if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
$$->u.unary_expression.u.signed_constant =
-($$->u.unary_expression.u.signed_constant);
+ } else {
+ reparent_error(scanner, "expecting numeric constant");
}
}
;
{
$$ = make_node(scanner, NODE_TYPE_SPECIFIER);
$$->u.type_specifier.type = TYPESPEC_ID_TYPE;
- $$->u.type_specifier.id_type = yylval.gs->s;
+ $$->u.type_specifier.id_type = yylval.s;
}
| INTEGER LBRAC RBRAC
{
{
$$ = make_node(scanner, NODE_TYPE_SPECIFIER);
$$->u.type_specifier.type = TYPESPEC_ID_TYPE;
- $$->u.type_specifier.id_type = yylval.gs->s;
+ $$->u.type_specifier.id_type = yylval.s;
}
| FLOATING_POINT LBRAC RBRAC
{
{
$$ = make_node(scanner, NODE_STRUCT);
$$->u._struct.has_body = 1;
- $$->u._struct.name = $1->s;
+ $$->u._struct.name = $1;
if ($3 && set_parent_node($3, $$))
reparent_error(scanner, "struct reparent error");
}
{
$$ = make_node(scanner, NODE_STRUCT);
$$->u._struct.has_body = 1;
- $$->u._struct.name = $1->s;
+ $$->u._struct.name = $1;
if ($3 && set_parent_node($3, $$))
reparent_error(scanner, "struct reparent error");
}
{
$$ = make_node(scanner, NODE_STRUCT);
$$->u._struct.has_body = 0;
- $$->u._struct.name = $1->s;
+ $$->u._struct.name = $1;
}
| ID_TYPE
{
$$ = make_node(scanner, NODE_STRUCT);
$$->u._struct.has_body = 0;
- $$->u._struct.name = $1->s;
+ $$->u._struct.name = $1;
}
| struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
{
{
$$ = make_node(scanner, NODE_STRUCT);
$$->u._struct.has_body = 1;
- $$->u._struct.name = $1->s;
+ $$->u._struct.name = $1;
bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
if ($3 && set_parent_node($3, $$))
reparent_error(scanner, "struct reparent error");
{
$$ = make_node(scanner, NODE_STRUCT);
$$->u._struct.has_body = 1;
- $$->u._struct.name = $1->s;
+ $$->u._struct.name = $1;
bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
if ($3 && set_parent_node($3, $$))
reparent_error(scanner, "struct reparent error");
{
$$ = make_node(scanner, NODE_VARIANT);
$$->u.variant.has_body = 1;
- $$->u.variant.choice = $2->s;
+ $$->u.variant.choice = $2;
if ($5 && set_parent_node($5, $$))
reparent_error(scanner, "variant reparent error");
}
{
$$ = make_node(scanner, NODE_VARIANT);
$$->u.variant.has_body = 1;
- $$->u.variant.choice = $2->s;
+ $$->u.variant.choice = $2;
if ($5 && set_parent_node($5, $$))
reparent_error(scanner, "variant reparent error");
}
{
$$ = make_node(scanner, NODE_VARIANT);
$$->u.variant.has_body = 1;
- $$->u.variant.name = $1->s;
+ $$->u.variant.name = $1;
if ($3 && set_parent_node($3, $$))
reparent_error(scanner, "variant reparent error");
}
{
$$ = make_node(scanner, NODE_VARIANT);
$$->u.variant.has_body = 1;
- $$->u.variant.name = $1->s;
- $$->u.variant.choice = $3->s;
+ $$->u.variant.name = $1;
+ $$->u.variant.choice = $3;
if ($6 && set_parent_node($6, $$))
reparent_error(scanner, "variant reparent error");
}
{
$$ = make_node(scanner, NODE_VARIANT);
$$->u.variant.has_body = 0;
- $$->u.variant.name = $1->s;
- $$->u.variant.choice = $3->s;
+ $$->u.variant.name = $1;
+ $$->u.variant.choice = $3;
}
| IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
{
$$ = make_node(scanner, NODE_VARIANT);
$$->u.variant.has_body = 1;
- $$->u.variant.name = $1->s;
- $$->u.variant.choice = $3->s;
+ $$->u.variant.name = $1;
+ $$->u.variant.choice = $3;
if ($6 && set_parent_node($6, $$))
reparent_error(scanner, "variant reparent error");
}
{
$$ = make_node(scanner, NODE_VARIANT);
$$->u.variant.has_body = 0;
- $$->u.variant.name = $1->s;
- $$->u.variant.choice = $3->s;
+ $$->u.variant.name = $1;
+ $$->u.variant.choice = $3;
}
| ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
{
$$ = make_node(scanner, NODE_VARIANT);
$$->u.variant.has_body = 1;
- $$->u.variant.name = $1->s;
+ $$->u.variant.name = $1;
if ($3 && set_parent_node($3, $$))
reparent_error(scanner, "variant reparent error");
}
{
$$ = make_node(scanner, NODE_VARIANT);
$$->u.variant.has_body = 1;
- $$->u.variant.name = $1->s;
- $$->u.variant.choice = $3->s;
+ $$->u.variant.name = $1;
+ $$->u.variant.choice = $3;
if ($6 && set_parent_node($6, $$))
reparent_error(scanner, "variant reparent error");
}
{
$$ = make_node(scanner, NODE_VARIANT);
$$->u.variant.has_body = 0;
- $$->u.variant.name = $1->s;
- $$->u.variant.choice = $3->s;
+ $$->u.variant.name = $1;
+ $$->u.variant.choice = $3;
}
| ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
{
$$ = make_node(scanner, NODE_VARIANT);
$$->u.variant.has_body = 1;
- $$->u.variant.name = $1->s;
- $$->u.variant.choice = $3->s;
+ $$->u.variant.name = $1;
+ $$->u.variant.choice = $3;
if ($6 && set_parent_node($6, $$))
reparent_error(scanner, "variant reparent error");
}
{
$$ = make_node(scanner, NODE_VARIANT);
$$->u.variant.has_body = 0;
- $$->u.variant.name = $1->s;
- $$->u.variant.choice = $3->s;
+ $$->u.variant.name = $1;
+ $$->u.variant.choice = $3;
}
;
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
- $$->u._enum.enum_id = $1->s;
+ $$->u._enum.enum_id = $1;
_bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
}
| IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
- $$->u._enum.enum_id = $1->s;
+ $$->u._enum.enum_id = $1;
($$)->u._enum.container_type = $3;
_bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
}
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
- $$->u._enum.enum_id = $1->s;
+ $$->u._enum.enum_id = $1;
_bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
}
| ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
- $$->u._enum.enum_id = $1->s;
+ $$->u._enum.enum_id = $1;
($$)->u._enum.container_type = $3;
_bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
}
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
- $$->u._enum.enum_id = $1->s;
+ $$->u._enum.enum_id = $1;
_bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
}
| IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
- $$->u._enum.enum_id = $1->s;
+ $$->u._enum.enum_id = $1;
($$)->u._enum.container_type = $3;
_bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
}
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 0;
- $$->u._enum.enum_id = $1->s;
+ $$->u._enum.enum_id = $1;
}
| ID_TYPE LBRAC enumerator_list COMMA RBRAC
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
- $$->u._enum.enum_id = $1->s;
+ $$->u._enum.enum_id = $1;
_bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
}
| ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
- $$->u._enum.enum_id = $1->s;
+ $$->u._enum.enum_id = $1;
($$)->u._enum.container_type = $3;
_bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
}
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 0;
- $$->u._enum.enum_id = $1->s;
+ $$->u._enum.enum_id = $1;
}
;
$$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
node = make_node(scanner, NODE_TYPE_SPECIFIER);
node->u.type_specifier.type = TYPESPEC_ID_TYPE;
- node->u.type_specifier.id_type = yylval.gs->s;
+ node->u.type_specifier.id_type = yylval.s;
bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
}
| alias_declaration_specifiers CONST
$$ = $1;
node = make_node(scanner, NODE_TYPE_SPECIFIER);
node->u.type_specifier.type = TYPESPEC_ID_TYPE;
- node->u.type_specifier.id_type = yylval.gs->s;
+ node->u.type_specifier.id_type = yylval.s;
bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
}
;
IDENTIFIER
{
$$ = make_node(scanner, NODE_ENUMERATOR);
- $$->u.enumerator.id = $1->s;
+ $$->u.enumerator.id = $1;
}
| ID_TYPE
{
$$ = make_node(scanner, NODE_ENUMERATOR);
- $$->u.enumerator.id = $1->s;
+ $$->u.enumerator.id = $1;
}
| keywords
{
$$ = make_node(scanner, NODE_ENUMERATOR);
- $$->u.enumerator.id = $1->s;
+ $$->u.enumerator.id = $1;
}
- | STRING_LITERAL_START DQUOTE
+ | STRING_LITERAL
{
$$ = make_node(scanner, NODE_ENUMERATOR);
- $$->u.enumerator.id = "";
- }
- | STRING_LITERAL_START s_char_sequence DQUOTE
- {
- $$ = make_node(scanner, NODE_ENUMERATOR);
- $$->u.enumerator.id = $2->s;
+ $$->u.enumerator.id = $1;
}
| IDENTIFIER EQUAL unary_expression_or_range
{
$$ = make_node(scanner, NODE_ENUMERATOR);
- $$->u.enumerator.id = $1->s;
+ $$->u.enumerator.id = $1;
bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
}
| ID_TYPE EQUAL unary_expression_or_range
{
$$ = make_node(scanner, NODE_ENUMERATOR);
- $$->u.enumerator.id = $1->s;
+ $$->u.enumerator.id = $1;
bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
}
| keywords EQUAL unary_expression_or_range
{
$$ = make_node(scanner, NODE_ENUMERATOR);
- $$->u.enumerator.id = $1->s;
+ $$->u.enumerator.id = $1;
bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
}
- | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
+ | STRING_LITERAL EQUAL unary_expression_or_range
{
$$ = make_node(scanner, NODE_ENUMERATOR);
- $$->u.enumerator.id = "";
- bt_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
- }
- | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
- {
- $$ = make_node(scanner, NODE_ENUMERATOR);
- $$->u.enumerator.id = $2->s;
- bt_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
+ $$->u.enumerator.id = $1;
+ bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
}
;
{
$$ = make_node(scanner, NODE_TYPE_DECLARATOR);
$$->u.type_declarator.type = TYPEDEC_ID;
- $$->u.type_declarator.u.id = $1->s;
+ $$->u.type_declarator.u.id = $1;
}
| LPAREN abstract_declarator RPAREN
{
{
$$ = make_node(scanner, NODE_TYPE_DECLARATOR);
$$->u.type_declarator.type = TYPEDEC_ID;
- $$->u.type_declarator.u.id = $1->s;
+ $$->u.type_declarator.u.id = $1;
}
| LPAREN declarator RPAREN
{
add_type(scanner, $1);
$$ = make_node(scanner, NODE_TYPE_DECLARATOR);
$$->u.type_declarator.type = TYPEDEC_ID;
- $$->u.type_declarator.u.id = $1->s;
+ $$->u.type_declarator.u.id = $1;
}
| LPAREN type_declarator RPAREN
{
--- /dev/null
+#ifndef _CTF_SCANNER_SYMBOLS
+#define _CTF_SCANNER_SYMBOLS
+
+/*
+ * ctf-scanner-symbols.h
+ *
+ * Copyright 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ */
+
+#define yy_create_buffer bt_yy_create_buffer
+#define yy_delete_buffer bt_yy_delete_buffer
+#define yy_flush_buffer bt_yy_flush_buffer
+#define yy_scan_buffer bt_yy_scan_buffer
+#define yy_scan_bytes bt_yy_scan_bytes
+#define yy_scan_string bt_yy_scan_string
+#define yy_switch_to_buffer bt_yy_switch_to_buffer
+#define yyalloc bt_yyalloc
+#define yyfree bt_yyfree
+#define yyget_column bt_yyget_column
+#define yyget_debug bt_yyget_debug
+#define yyget_extra bt_yyget_extra
+#define yyget_in bt_yyget_in
+#define yyget_leng bt_yyget_leng
+#define yyget_lineno bt_yyget_lineno
+#define yyget_lval bt_yyget_lval
+#define yyget_out bt_yyget_out
+#define yyget_text bt_yyget_text
+#define yylex_init bt_yylex_init
+#define yypop_buffer_state bt_yypop_buffer_state
+#define yypush_buffer_state bt_yypush_buffer_state
+#define yyrealloc bt_yyrealloc
+#define yyset_column bt_yyset_column
+#define yyset_debug bt_yyset_debug
+#define yyset_extra bt_yyset_extra
+#define yyset_in bt_yyset_in
+#define yyset_lineno bt_yyset_lineno
+#define yyset_lval bt_yyset_lval
+#define yyset_out bt_yyset_out
+
+#endif /* _CTF_SCANNER_SYMBOLS */
struct ctf_ast *ast;
struct ctf_scanner_scope root_scope;
struct ctf_scanner_scope *cs;
- struct bt_list_head allocated_strings;
+ struct objstack *objstack;
};
struct ctf_scanner *ctf_scanner_alloc(FILE *input);
return scanner->ast;
}
-__attribute__((visibility("hidden")))
+BT_HIDDEN
int is_type(struct ctf_scanner *scanner, const char *id);
#endif /* _CTF_SCANNER_H */
#include <babeltrace/list.h>
#include <babeltrace/types.h>
#include <babeltrace/ctf/metadata.h>
-#include <babeltrace/uuid.h>
+#include <babeltrace/compat/uuid.h>
#include <babeltrace/endian.h>
#include <babeltrace/ctf/events-internal.h>
#include "ctf-scanner.h"
int opt_clock_force_correlate;
static
-struct declaration *ctf_type_specifier_list_visit(FILE *fd,
+struct bt_declaration *ctf_type_specifier_list_visit(FILE *fd,
int depth, struct ctf_node *type_specifier_list,
struct declaration_scope *declaration_scope,
struct ctf_trace *trace);
bt_list_for_each_entry(node, head, siblings) {
char *src_string;
- assert(node->type == NODE_UNARY_EXPRESSION);
- assert(node->u.unary_expression.type == UNARY_STRING);
- assert((node->u.unary_expression.link == UNARY_LINK_UNKNOWN)
- ^ (i != 0));
+ if (node->type != NODE_UNARY_EXPRESSION
+ || node->u.unary_expression.type != UNARY_STRING
+ || !((node->u.unary_expression.link != UNARY_LINK_UNKNOWN)
+ ^ (i == 0)))
+ return NULL;
switch (node->u.unary_expression.link) {
case UNARY_DOTLINK:
g_string_append(str, ".");
bt_list_for_each_entry(node, head, siblings) {
char *src_string;
- assert(node->type == NODE_UNARY_EXPRESSION);
- assert(node->u.unary_expression.type == UNARY_STRING);
- assert((node->u.unary_expression.link == UNARY_LINK_UNKNOWN)
- ^ (i != 0));
+ if (node->type != NODE_UNARY_EXPRESSION
+ || node->u.unary_expression.type != UNARY_STRING
+ || !((node->u.unary_expression.link != UNARY_LINK_UNKNOWN)
+ ^ (i == 0)))
+ return 0;
/* needs to be chained with . */
switch (node->u.unary_expression.link) {
case UNARY_DOTLINK:
int i = 0;
bt_list_for_each_entry(node, head, siblings) {
- assert(node->type == NODE_UNARY_EXPRESSION);
- assert(node->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT);
- assert(node->u.unary_expression.link == UNARY_LINK_UNKNOWN);
- assert(i == 0);
+ if (node->type != NODE_UNARY_EXPRESSION
+ || node->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
+ || node->u.unary_expression.link != UNARY_LINK_UNKNOWN
+ || i != 0)
+ return -EINVAL;
*value = node->u.unary_expression.u.unsigned_constant;
i++;
}
int i = 0;
bt_list_for_each_entry(node, head, siblings) {
- assert(node->type == NODE_UNARY_EXPRESSION);
- assert(node->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT
- || node->u.unary_expression.type == UNARY_SIGNED_CONSTANT);
- assert(node->u.unary_expression.link == UNARY_LINK_UNKNOWN);
- assert(i == 0);
+ if (node->type != NODE_UNARY_EXPRESSION
+ || node->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
+ || (node->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT && node->u.unary_expression.type != UNARY_SIGNED_CONSTANT)
+ || node->u.unary_expression.link != UNARY_LINK_UNKNOWN
+ || i != 0)
+ return -EINVAL;
switch (node->u.unary_expression.type) {
case UNARY_UNSIGNED_CONSTANT:
*value = (int64_t) node->u.unary_expression.u.unsigned_constant;
*value = node->u.unary_expression.u.signed_constant;
break;
default:
- assert(0);
+ return -EINVAL;
}
i++;
}
bt_list_for_each_entry(node, head, siblings) {
const char *src_string;
- assert(node->type == NODE_UNARY_EXPRESSION);
- assert(node->u.unary_expression.type == UNARY_STRING);
- assert(node->u.unary_expression.link == UNARY_LINK_UNKNOWN);
- assert(i == 0);
+ if (node->type != NODE_UNARY_EXPRESSION
+ || node->u.unary_expression.type != UNARY_STRING
+ || node->u.unary_expression.link != UNARY_LINK_UNKNOWN
+ || i != 0)
+ return -EINVAL;
src_string = node->u.unary_expression.u.string;
ret = babeltrace_uuid_parse(src_string, uuid);
}
static
struct ctf_clock *trace_clock_lookup(struct ctf_trace *trace, GQuark clock_name)
{
- return g_hash_table_lookup(trace->clocks, (gpointer) (unsigned long) clock_name);
+ return g_hash_table_lookup(trace->parent.clocks, (gpointer) (unsigned long) clock_name);
}
static
int visit_type_specifier(FILE *fd, struct ctf_node *type_specifier, GString *str)
{
- assert(type_specifier->type == NODE_TYPE_SPECIFIER);
+ if (type_specifier->type != NODE_TYPE_SPECIFIER)
+ return -EINVAL;
switch (type_specifier->u.type_specifier.type) {
case TYPESPEC_VOID:
}
static
-struct declaration *ctf_type_declarator_visit(FILE *fd, int depth,
+struct bt_declaration *ctf_type_declarator_visit(FILE *fd, int depth,
struct ctf_node *type_specifier_list,
GQuark *field_name,
struct ctf_node *node_type_declarator,
struct declaration_scope *declaration_scope,
- struct declaration *nested_declaration,
+ struct bt_declaration *nested_declaration,
struct ctf_trace *trace)
{
/*
*/
if (node_type_declarator) {
- assert(node_type_declarator->u.type_declarator.type != TYPEDEC_UNKNOWN);
+ if (node_type_declarator->u.type_declarator.type == TYPEDEC_UNKNOWN) {
+ return NULL;
+ }
/* TODO: gcc bitfields not supported yet. */
if (node_type_declarator->u.type_declarator.bitfield_len != NULL) {
*/
alias_q = create_typealias_identifier(fd, depth,
type_specifier_list, node_type_declarator);
- nested_declaration = lookup_declaration(alias_q, declaration_scope);
+ nested_declaration = bt_lookup_declaration(alias_q, declaration_scope);
if (!nested_declaration) {
fprintf(fd, "[error] %s: cannot find typealias \"%s\".\n", __func__, g_quark_to_string(alias_q));
return NULL;
* integer declaration to modify it. There could be other references to
* it.
*/
- integer_declaration = integer_declaration_new(integer_declaration->len,
+ integer_declaration = bt_integer_declaration_new(integer_declaration->len,
integer_declaration->byte_order, integer_declaration->signedness,
integer_declaration->p.alignment, 16, integer_declaration->encoding,
integer_declaration->clock);
*field_name = 0;
return nested_declaration;
} else {
- struct declaration *declaration;
+ struct bt_declaration *declaration;
struct ctf_node *first;
/* TYPEDEC_NESTED */
}
first = _bt_list_first_entry(&node_type_declarator->u.type_declarator.u.nested.length,
struct ctf_node, siblings);
- assert(first->type == NODE_UNARY_EXPRESSION);
+ if (first->type != NODE_UNARY_EXPRESSION) {
+ return NULL;
+ }
switch (first->u.unary_expression.type) {
case UNARY_UNSIGNED_CONSTANT:
size_t len;
len = first->u.unary_expression.u.unsigned_constant;
- array_declaration = array_declaration_new(len, nested_declaration,
+ array_declaration = bt_array_declaration_new(len, nested_declaration,
declaration_scope);
if (!array_declaration) {
fprintf(fd, "[error] %s: cannot create array declaration.\n", __func__);
return NULL;
}
- declaration_unref(nested_declaration);
+ bt_declaration_unref(nested_declaration);
declaration = &array_declaration->p;
break;
}
char *length_name = concatenate_unary_strings(&node_type_declarator->u.type_declarator.u.nested.length);
struct declaration_sequence *sequence_declaration;
- sequence_declaration = sequence_declaration_new(length_name, nested_declaration, declaration_scope);
+ if (!length_name)
+ return NULL;
+ sequence_declaration = bt_sequence_declaration_new(length_name, nested_declaration, declaration_scope);
if (!sequence_declaration) {
fprintf(fd, "[error] %s: cannot create sequence declaration.\n", __func__);
g_free(length_name);
return NULL;
}
- declaration_unref(nested_declaration);
+ bt_declaration_unref(nested_declaration);
declaration = &sequence_declaration->p;
g_free(length_name);
break;
}
default:
- assert(0);
+ return NULL;
}
/* Pass it as content of outer container */
GQuark field_name;
bt_list_for_each_entry(iter, type_declarators, siblings) {
- struct declaration *field_declaration;
+ struct bt_declaration *field_declaration;
field_declaration = ctf_type_declarator_visit(fd, depth,
type_specifier_list,
}
/* Check if field with same name already exists */
- if (struct_declaration_lookup_field_index(struct_declaration, field_name) >= 0) {
+ if (bt_struct_declaration_lookup_field_index(struct_declaration, field_name) >= 0) {
fprintf(fd, "[error] %s: duplicate field %s in struct\n", __func__, g_quark_to_string(field_name));
return -EINVAL;
}
- struct_declaration_add_field(struct_declaration,
+ bt_struct_declaration_add_field(struct_declaration,
g_quark_to_string(field_name),
field_declaration);
- declaration_unref(field_declaration);
+ bt_declaration_unref(field_declaration);
}
return 0;
}
GQuark field_name;
bt_list_for_each_entry(iter, type_declarators, siblings) {
- struct declaration *field_declaration;
+ struct bt_declaration *field_declaration;
field_declaration = ctf_type_declarator_visit(fd, depth,
type_specifier_list,
return -EINVAL;
}
- if (untagged_variant_declaration_get_field_from_tag(untagged_variant_declaration, field_name) != NULL) {
+ if (bt_untagged_variant_declaration_get_field_from_tag(untagged_variant_declaration, field_name) != NULL) {
fprintf(fd, "[error] %s: duplicate field %s in variant\n", __func__, g_quark_to_string(field_name));
return -EINVAL;
}
- untagged_variant_declaration_add_field(untagged_variant_declaration,
+ bt_untagged_variant_declaration_add_field(untagged_variant_declaration,
g_quark_to_string(field_name),
field_declaration);
- declaration_unref(field_declaration);
+ bt_declaration_unref(field_declaration);
}
return 0;
}
GQuark identifier;
bt_list_for_each_entry(iter, type_declarators, siblings) {
- struct declaration *type_declaration;
+ struct bt_declaration *type_declaration;
int ret;
-
+
type_declaration = ctf_type_declarator_visit(fd, depth,
type_specifier_list,
&identifier, iter,
*/
if (type_declaration->id == CTF_TYPE_UNTAGGED_VARIANT) {
fprintf(fd, "[error] %s: typedef of untagged variant is not permitted.\n", __func__);
- declaration_unref(type_declaration);
+ bt_declaration_unref(type_declaration);
return -EPERM;
}
- ret = register_declaration(identifier, type_declaration, scope);
+ ret = bt_register_declaration(identifier, type_declaration, scope);
if (ret) {
type_declaration->declaration_free(type_declaration);
return ret;
}
- declaration_unref(type_declaration);
+ bt_declaration_unref(type_declaration);
}
return 0;
}
struct ctf_node *target, struct ctf_node *alias,
struct ctf_trace *trace)
{
- struct declaration *type_declaration;
+ struct bt_declaration *type_declaration;
struct ctf_node *node;
GQuark dummy_id;
GQuark alias_q;
*/
if (type_declaration->id == CTF_TYPE_UNTAGGED_VARIANT) {
fprintf(fd, "[error] %s: typedef of untagged variant is not permitted.\n", __func__);
- declaration_unref(type_declaration);
+ bt_declaration_unref(type_declaration);
return -EPERM;
}
/*
struct ctf_node, siblings);
alias_q = create_typealias_identifier(fd, depth,
alias->u.typealias_alias.type_specifier_list, node);
- err = register_declaration(alias_q, type_declaration, scope);
+ err = bt_register_declaration(alias_q, type_declaration, scope);
if (err)
goto error;
- declaration_unref(type_declaration);
+ bt_declaration_unref(type_declaration);
return 0;
error:
switch (iter->type) {
case NODE_TYPEDEF:
- /* For each declarator, declare type and add type to struct declaration scope */
+ /* For each declarator, declare type and add type to struct bt_declaration scope */
ret = ctf_typedef_visit(fd, depth,
struct_declaration->scope,
iter->u._typedef.type_specifier_list,
return ret;
break;
case NODE_TYPEALIAS:
- /* Declare type with declarator and add type to struct declaration scope */
+ /* Declare type with declarator and add type to struct bt_declaration scope */
ret = ctf_typealias_visit(fd, depth,
struct_declaration->scope,
iter->u.typealias.target,
break;
default:
fprintf(fd, "[error] %s: unexpected node type %d\n", __func__, (int) iter->type);
- assert(0);
+ return -EINVAL;
}
return 0;
}
break;
default:
fprintf(fd, "[error] %s: unexpected node type %d\n", __func__, (int) iter->type);
- assert(0);
+ return -EINVAL;
}
return 0;
}
static
-struct declaration *ctf_declaration_struct_visit(FILE *fd,
+struct bt_declaration *ctf_declaration_struct_visit(FILE *fd,
int depth, const char *name, struct bt_list_head *declaration_list,
int has_body, struct bt_list_head *min_align,
struct declaration_scope *declaration_scope,
* declaration: ref is only taken upon definition.
*/
if (!has_body) {
- assert(name);
+ if (!name)
+ return NULL;
struct_declaration =
- lookup_struct_declaration(g_quark_from_string(name),
+ bt_lookup_struct_declaration(g_quark_from_string(name),
declaration_scope);
- declaration_ref(&struct_declaration->p);
+ bt_declaration_ref(&struct_declaration->p);
return &struct_declaration->p;
} else {
uint64_t min_align_value = 0;
/* For unnamed struct, create type */
/* For named struct (with body), create type and add to declaration scope */
if (name) {
- if (lookup_struct_declaration(g_quark_from_string(name),
+ if (bt_lookup_struct_declaration(g_quark_from_string(name),
declaration_scope)) {
-
fprintf(fd, "[error] %s: struct %s already declared in scope\n", __func__, name);
return NULL;
}
ret = get_unary_unsigned(min_align, &min_align_value);
if (ret) {
fprintf(fd, "[error] %s: unexpected unary expression for structure \"align\" attribute\n", __func__);
- ret = -EINVAL;
goto error;
}
}
- struct_declaration = struct_declaration_new(declaration_scope,
+ struct_declaration = bt_struct_declaration_new(declaration_scope,
min_align_value);
bt_list_for_each_entry(iter, declaration_list, siblings) {
int ret;
if (name) {
int ret;
- ret = register_struct_declaration(g_quark_from_string(name),
+ ret = bt_register_struct_declaration(g_quark_from_string(name),
struct_declaration,
declaration_scope);
- assert(!ret);
+ if (ret)
+ return NULL;
}
return &struct_declaration->p;
}
}
static
-struct declaration *ctf_declaration_variant_visit(FILE *fd,
+struct bt_declaration *ctf_declaration_variant_visit(FILE *fd,
int depth, const char *name, const char *choice,
struct bt_list_head *declaration_list,
int has_body, struct declaration_scope *declaration_scope,
* declaration: ref is only taken upon definition.
*/
if (!has_body) {
- assert(name);
+ if (!name)
+ return NULL;
untagged_variant_declaration =
- lookup_variant_declaration(g_quark_from_string(name),
+ bt_lookup_variant_declaration(g_quark_from_string(name),
declaration_scope);
- declaration_ref(&untagged_variant_declaration->p);
+ bt_declaration_ref(&untagged_variant_declaration->p);
} else {
/* For unnamed variant, create type */
/* For named variant (with body), create type and add to declaration scope */
if (name) {
- if (lookup_variant_declaration(g_quark_from_string(name),
+ if (bt_lookup_variant_declaration(g_quark_from_string(name),
declaration_scope)) {
-
fprintf(fd, "[error] %s: variant %s already declared in scope\n", __func__, name);
return NULL;
}
}
- untagged_variant_declaration = untagged_variant_declaration_new(declaration_scope);
+ untagged_variant_declaration = bt_untagged_bt_variant_declaration_new(declaration_scope);
bt_list_for_each_entry(iter, declaration_list, siblings) {
int ret;
if (name) {
int ret;
- ret = register_variant_declaration(g_quark_from_string(name),
+ ret = bt_register_variant_declaration(g_quark_from_string(name),
untagged_variant_declaration,
declaration_scope);
- assert(!ret);
+ if (ret)
+ return NULL;
}
}
/*
if (!choice) {
return &untagged_variant_declaration->p;
} else {
- variant_declaration = variant_declaration_new(untagged_variant_declaration, choice);
+ variant_declaration = bt_variant_declaration_new(untagged_variant_declaration, choice);
if (!variant_declaration)
goto error;
- declaration_unref(&untagged_variant_declaration->p);
+ bt_declaration_unref(&untagged_variant_declaration->p);
return &variant_declaration->p;
}
error:
bt_list_for_each_entry(iter, &enumerator->u.enumerator.values, siblings) {
int64_t *target;
- assert(iter->type == NODE_UNARY_EXPRESSION);
+ if (iter->type != NODE_UNARY_EXPRESSION)
+ return -EINVAL;
if (nr_vals == 0)
target = &start;
else
if (nr_vals <= 1)
end = start;
last->u.s = end + 1;
- enum_signed_insert(enum_declaration, start, end, q);
+ bt_enum_signed_insert(enum_declaration, start, end, q);
} else {
uint64_t start, end;
int nr_vals = 0;
bt_list_for_each_entry(iter, &enumerator->u.enumerator.values, siblings) {
uint64_t *target;
- assert(iter->type == NODE_UNARY_EXPRESSION);
+ if (iter->type != NODE_UNARY_EXPRESSION)
+ return -EINVAL;
if (nr_vals == 0)
target = &start;
else
if (nr_vals <= 1)
end = start;
last->u.u = end + 1;
- enum_unsigned_insert(enum_declaration, start, end, q);
+ bt_enum_unsigned_insert(enum_declaration, start, end, q);
}
return 0;
}
static
-struct declaration *ctf_declaration_enum_visit(FILE *fd, int depth,
+struct bt_declaration *ctf_declaration_enum_visit(FILE *fd, int depth,
const char *name,
struct ctf_node *container_type,
struct bt_list_head *enumerator_list,
struct declaration_scope *declaration_scope,
struct ctf_trace *trace)
{
- struct declaration *declaration;
+ struct bt_declaration *declaration;
struct declaration_enum *enum_declaration;
struct declaration_integer *integer_declaration;
struct last_enum_value last_value;
* declaration: ref is only taken upon definition.
*/
if (!has_body) {
- assert(name);
+ if (!name)
+ return NULL;
enum_declaration =
- lookup_enum_declaration(g_quark_from_string(name),
+ bt_lookup_enum_declaration(g_quark_from_string(name),
declaration_scope);
- declaration_ref(&enum_declaration->p);
+ bt_declaration_ref(&enum_declaration->p);
return &enum_declaration->p;
} else {
/* For unnamed enum, create type */
/* For named enum (with body), create type and add to declaration scope */
if (name) {
- if (lookup_enum_declaration(g_quark_from_string(name),
+ if (bt_lookup_enum_declaration(g_quark_from_string(name),
declaration_scope)) {
-
fprintf(fd, "[error] %s: enum %s already declared in scope\n", __func__, name);
return NULL;
}
}
if (!container_type) {
- declaration = lookup_declaration(g_quark_from_static_string("int"),
+ declaration = bt_lookup_declaration(g_quark_from_static_string("int"),
declaration_scope);
if (!declaration) {
fprintf(fd, "[error] %s: \"int\" type declaration missing for enumeration\n", __func__);
return NULL;
}
integer_declaration = container_of(declaration, struct declaration_integer, p);
- enum_declaration = enum_declaration_new(integer_declaration);
- declaration_unref(&integer_declaration->p); /* leave ref to enum */
+ enum_declaration = bt_enum_declaration_new(integer_declaration);
+ bt_declaration_unref(&integer_declaration->p); /* leave ref to enum */
if (enum_declaration->integer_declaration->signedness) {
last_value.u.s = 0;
} else {
if (name) {
int ret;
- ret = register_enum_declaration(g_quark_from_string(name),
+ ret = bt_register_enum_declaration(g_quark_from_string(name),
enum_declaration,
declaration_scope);
- assert(!ret);
- declaration_unref(&enum_declaration->p);
+ if (ret)
+ return NULL;
+ bt_declaration_unref(&enum_declaration->p);
}
return &enum_declaration->p;
}
}
static
-struct declaration *ctf_declaration_type_specifier_visit(FILE *fd, int depth,
+struct bt_declaration *ctf_declaration_type_specifier_visit(FILE *fd, int depth,
struct ctf_node *type_specifier_list,
struct declaration_scope *declaration_scope)
{
GString *str;
- struct declaration *declaration;
+ struct bt_declaration *declaration;
char *str_c;
int ret;
GQuark id_q;
str = g_string_new("");
ret = visit_type_specifier_list(fd, type_specifier_list, str);
- if (ret)
+ if (ret) {
+ (void) g_string_free(str, TRUE);
return NULL;
+ }
str_c = g_string_free(str, FALSE);
id_q = g_quark_from_string(str_c);
g_free(str_c);
- declaration = lookup_declaration(id_q, declaration_scope);
- declaration_ref(declaration);
+ declaration = bt_lookup_declaration(id_q, declaration_scope);
+ if (!declaration)
+ return NULL;
+ bt_declaration_ref(declaration);
return declaration;
}
fprintf(fd, "[error] %s: unexpected unary expression type\n",
__func__);
return -EINVAL;
- }
+ }
}
else if (!strcmp(unary_expression->u.unary_expression.u.string, "le"))
byte_order = LITTLE_ENDIAN;
else {
- fprintf(fd, "[error] %s: unexpected string \"%s\". Should be \"native\", \"network\", \"be\" or \"le\".\n",
+ fprintf(fd, "[error] %s: unexpected string \"%s\". Should be \"be\" or \"le\".\n",
__func__, unary_expression->u.unary_expression.u.string);
return -EINVAL;
}
}
static
-struct declaration *ctf_declaration_integer_visit(FILE *fd, int depth,
+struct bt_declaration *ctf_declaration_integer_visit(FILE *fd, int depth,
struct bt_list_head *expressions,
struct ctf_trace *trace)
{
left = _bt_list_first_entry(&expression->u.ctf_expression.left, struct ctf_node, siblings);
right = _bt_list_first_entry(&expression->u.ctf_expression.right, struct ctf_node, siblings);
- assert(left->u.unary_expression.type == UNARY_STRING);
+ if (left->u.unary_expression.type != UNARY_STRING)
+ return NULL;
if (!strcmp(left->u.unary_expression.u.string, "signed")) {
signedness = get_boolean(fd, depth, right);
if (signedness < 0)
alignment = CHAR_BIT;
}
}
- integer_declaration = integer_declaration_new(size,
+ integer_declaration = bt_integer_declaration_new(size,
byte_order, signedness, alignment,
base, encoding, clock);
return &integer_declaration->p;
}
static
-struct declaration *ctf_declaration_floating_point_visit(FILE *fd, int depth,
+struct bt_declaration *ctf_declaration_floating_point_visit(FILE *fd, int depth,
struct bt_list_head *expressions,
struct ctf_trace *trace)
{
struct ctf_node *expression;
- uint64_t alignment = 1, exp_dig = 0, mant_dig = 0,
- byte_order = trace->byte_order;
- int has_alignment = 0, has_exp_dig = 0, has_mant_dig = 0;
+ uint64_t alignment = 1, exp_dig = 0, mant_dig = 0;
+ int byte_order = trace->byte_order, has_alignment = 0,
+ has_exp_dig = 0, has_mant_dig = 0;
struct declaration_float *float_declaration;
bt_list_for_each_entry(expression, expressions, siblings) {
left = _bt_list_first_entry(&expression->u.ctf_expression.left, struct ctf_node, siblings);
right = _bt_list_first_entry(&expression->u.ctf_expression.right, struct ctf_node, siblings);
- assert(left->u.unary_expression.type == UNARY_STRING);
+ if (left->u.unary_expression.type != UNARY_STRING)
+ return NULL;
if (!strcmp(left->u.unary_expression.u.string, "byte_order")) {
byte_order = get_byte_order(fd, depth, right, trace);
if (byte_order < 0)
alignment = CHAR_BIT;
}
}
- float_declaration = float_declaration_new(mant_dig, exp_dig,
+ float_declaration = bt_float_declaration_new(mant_dig, exp_dig,
byte_order, alignment);
return &float_declaration->p;
}
static
-struct declaration *ctf_declaration_string_visit(FILE *fd, int depth,
+struct bt_declaration *ctf_declaration_string_visit(FILE *fd, int depth,
struct bt_list_head *expressions,
struct ctf_trace *trace)
{
left = _bt_list_first_entry(&expression->u.ctf_expression.left, struct ctf_node, siblings);
right = _bt_list_first_entry(&expression->u.ctf_expression.right, struct ctf_node, siblings);
- assert(left->u.unary_expression.type == UNARY_STRING);
+ if (left->u.unary_expression.type != UNARY_STRING)
+ return NULL;
if (!strcmp(left->u.unary_expression.u.string, "encoding")) {
if (right->u.unary_expression.type != UNARY_STRING) {
fprintf(fd, "[error] %s: encoding: expecting string\n",
}
if (encoding_c && !strcmp(encoding_c, "ASCII"))
encoding = CTF_STRING_ASCII;
- string_declaration = string_declaration_new(encoding);
+ string_declaration = bt_string_declaration_new(encoding);
return &string_declaration->p;
}
static
-struct declaration *ctf_type_specifier_list_visit(FILE *fd,
+struct bt_declaration *ctf_type_specifier_list_visit(FILE *fd,
int depth, struct ctf_node *type_specifier_list,
struct declaration_scope *declaration_scope,
struct ctf_trace *trace)
struct ctf_node *first;
struct ctf_node *node;
- assert(type_specifier_list->type == NODE_TYPE_SPECIFIER_LIST);
+ if (type_specifier_list->type != NODE_TYPE_SPECIFIER_LIST)
+ return NULL;
first = _bt_list_first_entry(&type_specifier_list->u.type_specifier_list.head, struct ctf_node, siblings);
- assert(first->type == NODE_TYPE_SPECIFIER);
+ if (first->type != NODE_TYPE_SPECIFIER)
+ return NULL;
node = first->u.type_specifier.node;
char *left;
left = concatenate_unary_strings(&node->u.ctf_expression.left);
+ if (!left)
+ return -EINVAL;
if (!strcmp(left, "name")) {
char *right;
}
CTF_EVENT_SET_FIELD(event, stream_id);
} else if (!strcmp(left, "context")) {
- struct declaration *declaration;
+ struct bt_declaration *declaration;
if (event->context_decl) {
fprintf(fd, "[error] %s: context already declared in event declaration\n", __func__);
}
event->context_decl = container_of(declaration, struct declaration_struct, p);
} else if (!strcmp(left, "fields")) {
- struct declaration *declaration;
+ struct bt_declaration *declaration;
if (event->fields_decl) {
fprintf(fd, "[error] %s: fields already declared in event declaration\n", __func__);
event_decl = g_new0(struct bt_ctf_event_decl, 1);
event = &event_decl->parent;
- event->declaration_scope = new_declaration_scope(parent_declaration_scope);
+ event->declaration_scope = bt_new_declaration_scope(parent_declaration_scope);
event->loglevel = -1;
bt_list_for_each_entry(iter, &node->u.event.declaration_list, siblings) {
ret = ctf_event_declaration_visit(fd, depth + 1, iter, event, trace);
error:
if (event->fields_decl)
- declaration_unref(&event->fields_decl->p);
+ bt_declaration_unref(&event->fields_decl->p);
if (event->context_decl)
- declaration_unref(&event->context_decl->p);
- free_declaration_scope(event->declaration_scope);
+ bt_declaration_unref(&event->context_decl->p);
+ bt_free_declaration_scope(event->declaration_scope);
g_free(event_decl);
return ret;
}
char *left;
left = concatenate_unary_strings(&node->u.ctf_expression.left);
+ if (!left)
+ return -EINVAL;
if (!strcmp(left, "id")) {
if (CTF_STREAM_FIELD_IS_SET(stream, stream_id)) {
fprintf(fd, "[error] %s: id already declared in stream declaration\n", __func__);
}
CTF_STREAM_SET_FIELD(stream, stream_id);
} else if (!strcmp(left, "event.header")) {
- struct declaration *declaration;
+ struct bt_declaration *declaration;
if (stream->event_header_decl) {
fprintf(fd, "[error] %s: event.header already declared in stream declaration\n", __func__);
}
stream->event_header_decl = container_of(declaration, struct declaration_struct, p);
} else if (!strcmp(left, "event.context")) {
- struct declaration *declaration;
+ struct bt_declaration *declaration;
if (stream->event_context_decl) {
fprintf(fd, "[error] %s: event.context already declared in stream declaration\n", __func__);
}
stream->event_context_decl = container_of(declaration, struct declaration_struct, p);
} else if (!strcmp(left, "packet.context")) {
- struct declaration *declaration;
+ struct bt_declaration *declaration;
if (stream->packet_context_decl) {
fprintf(fd, "[error] %s: packet.context already declared in stream declaration\n", __func__);
struct ctf_stream_declaration *stream;
stream = g_new0(struct ctf_stream_declaration, 1);
- stream->declaration_scope = new_declaration_scope(parent_declaration_scope);
+ stream->declaration_scope = bt_new_declaration_scope(parent_declaration_scope);
stream->events_by_id = g_ptr_array_new();
stream->event_quark_to_id = g_hash_table_new(g_direct_hash, g_direct_equal);
stream->streams = g_ptr_array_new();
if (CTF_STREAM_FIELD_IS_SET(stream, stream_id)) {
/* check that packet header has stream_id field. */
if (!trace->packet_header_decl
- || struct_declaration_lookup_field_index(trace->packet_header_decl, g_quark_from_static_string("stream_id")) < 0) {
+ || bt_struct_declaration_lookup_field_index(trace->packet_header_decl, g_quark_from_static_string("stream_id")) < 0) {
ret = -EPERM;
fprintf(fd, "[error] %s: missing stream_id field in packet header declaration, but stream_id attribute is declared for stream.\n", __func__);
goto error;
error:
if (stream->event_header_decl)
- declaration_unref(&stream->event_header_decl->p);
+ bt_declaration_unref(&stream->event_header_decl->p);
if (stream->event_context_decl)
- declaration_unref(&stream->event_context_decl->p);
+ bt_declaration_unref(&stream->event_context_decl->p);
if (stream->packet_context_decl)
- declaration_unref(&stream->packet_context_decl->p);
+ bt_declaration_unref(&stream->packet_context_decl->p);
g_ptr_array_free(stream->streams, TRUE);
g_ptr_array_free(stream->events_by_id, TRUE);
g_hash_table_destroy(stream->event_quark_to_id);
- free_declaration_scope(stream->declaration_scope);
+ bt_free_declaration_scope(stream->declaration_scope);
g_free(stream);
return ret;
}
char *left;
left = concatenate_unary_strings(&node->u.ctf_expression.left);
+ if (!left)
+ return -EINVAL;
if (!strcmp(left, "major")) {
if (CTF_TRACE_FIELD_IS_SET(trace, major)) {
fprintf(fd, "[error] %s: major already declared in trace declaration\n", __func__);
right = _bt_list_first_entry(&node->u.ctf_expression.right, struct ctf_node, siblings);
byte_order = get_trace_byte_order(fd, depth, right);
- if (byte_order < 0)
- return -EINVAL;
+ if (byte_order < 0) {
+ ret = -EINVAL;
+ goto error;
+ }
if (CTF_TRACE_FIELD_IS_SET(trace, byte_order)
&& byte_order != trace->byte_order) {
}
CTF_TRACE_SET_FIELD(trace, byte_order);
} else if (!strcmp(left, "packet.header")) {
- struct declaration *declaration;
+ struct bt_declaration *declaration;
if (trace->packet_header_decl) {
fprintf(fd, "[error] %s: packet.header already declared in trace declaration\n", __func__);
if (trace->declaration_scope)
return -EEXIST;
- trace->declaration_scope = new_declaration_scope(trace->root_declaration_scope);
+ trace->declaration_scope = bt_new_declaration_scope(trace->root_declaration_scope);
trace->streams = g_ptr_array_new();
trace->event_declarations = g_ptr_array_new();
bt_list_for_each_entry(iter, &node->u.trace.declaration_list, siblings) {
if (!CTF_TRACE_FIELD_IS_SET(trace, byte_order)) {
/* check that the packet header contains a "magic" field */
if (!trace->packet_header_decl
- || struct_declaration_lookup_field_index(trace->packet_header_decl, g_quark_from_static_string("magic")) < 0) {
+ || bt_struct_declaration_lookup_field_index(trace->packet_header_decl, g_quark_from_static_string("magic")) < 0) {
ret = -EPERM;
fprintf(fd, "[error] %s: missing both byte_order and packet header magic number in trace declaration\n", __func__);
goto error;
error:
if (trace->packet_header_decl) {
- declaration_unref(&trace->packet_header_decl->p);
+ bt_declaration_unref(&trace->packet_header_decl->p);
trace->packet_header_decl = NULL;
}
g_ptr_array_free(trace->streams, TRUE);
g_ptr_array_free(trace->event_declarations, TRUE);
- free_declaration_scope(trace->declaration_scope);
+ bt_free_declaration_scope(trace->declaration_scope);
trace->declaration_scope = NULL;
return ret;
}
char *left;
left = concatenate_unary_strings(&node->u.ctf_expression.left);
+ if (!left)
+ return -EINVAL;
if (!strcmp(left, "name")) {
char *right;
if (opt_clock_force_correlate) {
/*
* User requested to forcibly correlate the clock
- * sources, even if we have no correlatation
+ * sources, even if we have no correlation
* information.
*/
if (!clock->absolute) {
fprintf(fd, "[error] %s: missing name field in clock declaration\n", __func__);
goto error;
}
- if (g_hash_table_size(trace->clocks) > 0) {
+ if (g_hash_table_size(trace->parent.clocks) > 0) {
fprintf(fd, "[error] Only CTF traces with a single clock description are supported by this babeltrace version.\n");
ret = -EINVAL;
goto error;
}
- trace->single_clock = clock;
- g_hash_table_insert(trace->clocks, (gpointer) (unsigned long) clock->name, clock);
+ trace->parent.single_clock = clock;
+ g_hash_table_insert(trace->parent.clocks, (gpointer) (unsigned long) clock->name, clock);
return 0;
error:
clock->absolute = 0; /* Not an absolute reference across traces */
}
- trace->single_clock = clock;
- g_hash_table_insert(trace->clocks, (gpointer) (unsigned long) clock->name, clock);
+ trace->parent.single_clock = clock;
+ g_hash_table_insert(trace->parent.clocks, (gpointer) (unsigned long) clock->name, clock);
}
static
char *left;
left = concatenate_unary_strings(&node->u.ctf_expression.left);
+ if (!left)
+ return -EINVAL;
if (!strcmp(left, "name")) {
char *right;
char *left;
left = concatenate_unary_strings(&node->u.ctf_expression.left);
+ if (!left)
+ return -EINVAL;
if (!strcmp(left, "vpid")) {
uint64_t v;
char *right;
right = concatenate_unary_strings(&node->u.ctf_expression.right);
+ if (!right) {
+ fprintf(fd, "[warning] %s: unexpected unary expression for env\n", __func__);
+ ret = -EINVAL;
+ goto error;
+ }
printf_verbose("env.%s = \"%s\"\n", left, right);
g_free(right);
} else if (is_unary_unsigned(&node->u.ctf_expression.right)) {
int ret;
ret = get_unary_unsigned(&node->u.ctf_expression.right, &v);
- assert(ret == 0);
+ if (ret)
+ goto error;
printf_verbose("env.%s = %" PRIu64 "\n", left, v);
} else if (is_unary_signed(&node->u.ctf_expression.right)) {
int64_t v;
int ret;
ret = get_unary_signed(&node->u.ctf_expression.right, &v);
- assert(ret == 0);
+ if (ret)
+ goto error;
printf_verbose("env.%s = %" PRId64 "\n", left, v);
} else {
printf_verbose("%s: attribute \"%s\" has unknown type.\n", __func__, left);
break;
case NODE_TYPE_SPECIFIER_LIST:
{
- struct declaration *declaration;
+ struct bt_declaration *declaration;
/*
* Just add the type specifier to the root scope
node, trace->root_declaration_scope, trace);
if (!declaration)
return -ENOMEM;
- declaration_unref(declaration);
+ bt_declaration_unref(declaration);
break;
}
default:
struct ctf_node *iter;
int env_clock_done = 0;
- printf_verbose("CTF visitor: metadata construction... ");
+ printf_verbose("CTF visitor: metadata construction...\n");
trace->byte_order = byte_order;
- trace->clocks = g_hash_table_new_full(g_direct_hash, g_direct_equal,
- NULL, clock_free);
+ trace->parent.clocks = g_hash_table_new_full(g_direct_hash,
+ g_direct_equal, NULL, clock_free);
trace->callsites = g_hash_table_new_full(g_direct_hash, g_direct_equal,
NULL, callsite_free);
retry:
- trace->root_declaration_scope = new_declaration_scope(NULL);
+ trace->root_declaration_scope = bt_new_declaration_scope(NULL);
switch (node->type) {
case NODE_ROOT:
bt_list_for_each_entry(iter, &node->u.root.trace, siblings) {
ret = ctf_trace_visit(fd, depth + 1, iter, trace);
if (ret == -EINTR) {
- free_declaration_scope(trace->root_declaration_scope);
+ bt_free_declaration_scope(trace->root_declaration_scope);
/*
* Need to restart creation of type
* definitions, aliases and
return ret;
error:
- free_declaration_scope(trace->root_declaration_scope);
+ bt_free_declaration_scope(trace->root_declaration_scope);
g_hash_table_destroy(trace->callsites);
- g_hash_table_destroy(trace->clocks);
+ g_hash_table_destroy(trace->parent.clocks);
return ret;
}
if (!event)
continue;
if (&event->event_fields->p)
- definition_unref(&event->event_fields->p);
+ bt_definition_unref(&event->event_fields->p);
if (&event->event_context->p)
- definition_unref(&event->event_context->p);
+ bt_definition_unref(&event->event_context->p);
g_free(event);
}
if (&stream_def->trace_packet_header->p)
- definition_unref(&stream_def->trace_packet_header->p);
+ bt_definition_unref(&stream_def->trace_packet_header->p);
if (&stream_def->stream_event_header->p)
- definition_unref(&stream_def->stream_event_header->p);
+ bt_definition_unref(&stream_def->stream_event_header->p);
if (&stream_def->stream_packet_context->p)
- definition_unref(&stream_def->stream_packet_context->p);
+ bt_definition_unref(&stream_def->stream_packet_context->p);
if (&stream_def->stream_event_context->p)
- definition_unref(&stream_def->stream_event_context->p);
+ bt_definition_unref(&stream_def->stream_event_context->p);
g_ptr_array_free(stream_def->events_by_id, TRUE);
g_free(stream_def);
}
if (stream->event_header_decl)
- declaration_unref(&stream->event_header_decl->p);
+ bt_declaration_unref(&stream->event_header_decl->p);
if (stream->event_context_decl)
- declaration_unref(&stream->event_context_decl->p);
+ bt_declaration_unref(&stream->event_context_decl->p);
if (stream->packet_context_decl)
- declaration_unref(&stream->packet_context_decl->p);
+ bt_declaration_unref(&stream->packet_context_decl->p);
g_ptr_array_free(stream->streams, TRUE);
g_ptr_array_free(stream->events_by_id, TRUE);
g_hash_table_destroy(stream->event_quark_to_id);
- free_declaration_scope(stream->declaration_scope);
+ bt_free_declaration_scope(stream->declaration_scope);
g_free(stream);
}
g_ptr_array_free(trace->streams, TRUE);
event = &event_decl->parent;
if (event->fields_decl)
- declaration_unref(&event->fields_decl->p);
+ bt_declaration_unref(&event->fields_decl->p);
if (event->context_decl)
- declaration_unref(&event->context_decl->p);
- free_declaration_scope(event->declaration_scope);
+ bt_declaration_unref(&event->context_decl->p);
+ bt_free_declaration_scope(event->declaration_scope);
g_free(event);
}
g_ptr_array_free(trace->event_declarations, TRUE);
}
if (trace->packet_header_decl)
- declaration_unref(&trace->packet_header_decl->p);
+ bt_declaration_unref(&trace->packet_header_decl->p);
- free_declaration_scope(trace->root_declaration_scope);
- free_declaration_scope(trace->declaration_scope);
+ bt_free_declaration_scope(trace->root_declaration_scope);
+ bt_free_declaration_scope(trace->declaration_scope);
g_hash_table_destroy(trace->callsites);
- g_hash_table_destroy(trace->clocks);
+ g_hash_table_destroy(trace->parent.clocks);
metadata_stream = container_of(trace->metadata, struct ctf_file_stream, parent);
g_free(metadata_stream);
if (ret)
return ret;
break;
- case UNARY_NESTED:
- node->u.unary_expression.u.nested_exp->parent = node;
- ret = ctf_visitor_unary_expression(fd, depth + 1,
- node->u.unary_expression.u.nested_exp);
- if (ret)
- return ret;
- break;
case UNARY_UNKNOWN:
default:
print_tabs(fd, depth);
fprintf(fd, "</unary_expression_sbrac>\n");
break;
- case UNARY_NESTED:
- print_tabs(fd, depth);
- fprintf(fd, "<unary_expression_nested>\n");
- ret = ctf_visitor_print_unary_expression(fd, depth + 1,
- node->u.unary_expression.u.nested_exp);
- if (ret)
- return ret;
- print_tabs(fd, depth);
- fprintf(fd, "</unary_expression_nested>\n");
- break;
case UNARY_UNKNOWN:
default:
--- /dev/null
+/*
+ * objstack.c
+ *
+ * Common Trace Format Object Stack.
+ *
+ * Copyright 2013 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <babeltrace/list.h>
+#include <babeltrace/babeltrace-internal.h>
+
+#define OBJSTACK_INIT_LEN 128
+#define OBJSTACK_POISON 0xcc
+
+struct objstack {
+ struct bt_list_head head; /* list of struct objstack_node */
+};
+
+struct objstack_node {
+ struct bt_list_head node;
+ size_t len;
+ size_t used_len;
+ char data[];
+};
+
+BT_HIDDEN
+struct objstack *objstack_create(void)
+{
+ struct objstack *objstack;
+ struct objstack_node *node;
+
+ objstack = calloc(1, sizeof(*objstack));
+ if (!objstack)
+ return NULL;
+ node = calloc(sizeof(struct objstack_node) + OBJSTACK_INIT_LEN,
+ sizeof(char));
+ if (!node) {
+ free(objstack);
+ return NULL;
+ }
+ BT_INIT_LIST_HEAD(&objstack->head);
+ bt_list_add_tail(&node->node, &objstack->head);
+ node->len = OBJSTACK_INIT_LEN;
+ return objstack;
+}
+
+static
+void objstack_node_free(struct objstack_node *node)
+{
+ size_t offset, len;
+ char *p;
+
+ if (!node)
+ return;
+ p = (char *) node;
+ len = sizeof(*node) + node->len;
+ for (offset = 0; offset < len; offset++)
+ p[offset] = OBJSTACK_POISON;
+ free(node);
+}
+
+BT_HIDDEN
+void objstack_destroy(struct objstack *objstack)
+{
+ struct objstack_node *node, *p;
+
+ if (!objstack)
+ return;
+ bt_list_for_each_entry_safe(node, p, &objstack->head, node) {
+ bt_list_del(&node->node);
+ objstack_node_free(node);
+ }
+ free(objstack);
+}
+
+static
+struct objstack_node *objstack_append_node(struct objstack *objstack)
+{
+ struct objstack_node *last_node, *new_node;
+
+ /* Get last node */
+ last_node = bt_list_entry(objstack->head.prev,
+ struct objstack_node, node);
+
+ /* Allocate new node with double of size of last node */
+ new_node = calloc(sizeof(struct objstack_node) + (last_node->len << 1),
+ sizeof(char));
+ if (!new_node) {
+ return NULL;
+ }
+ bt_list_add_tail(&new_node->node, &objstack->head);
+ new_node->len = last_node->len << 1;
+ return new_node;
+}
+
+BT_HIDDEN
+void *objstack_alloc(struct objstack *objstack, size_t len)
+{
+ struct objstack_node *last_node;
+ void *p;
+
+ /* Get last node */
+ last_node = bt_list_entry(objstack->head.prev,
+ struct objstack_node, node);
+ while (last_node->len - last_node->used_len < len) {
+ last_node = objstack_append_node(objstack);
+ if (!last_node) {
+ return NULL;
+ }
+ }
+ p = &last_node->data[last_node->used_len];
+ last_node->used_len += len;
+ return p;
+}
--- /dev/null
+#ifndef _OBJSTACK_H
+#define _OBJSTACK_H
+
+/*
+ * objstack.h
+ *
+ * Common Trace Format Object Stack.
+ *
+ * Copyright 2013 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+struct objstack;
+
+BT_HIDDEN
+struct objstack *objstack_create(void);
+BT_HIDDEN
+void objstack_destroy(struct objstack *objstack);
+
+/*
+ * Allocate len bytes of zeroed memory.
+ * Return NULL on error.
+ */
+BT_HIDDEN
+void *objstack_alloc(struct objstack *objstack, size_t len);
+
+#endif /* _OBJSTACK_H */
#include <babeltrace/ctf/types.h>
-int ctf_array_read(struct stream_pos *ppos, struct definition *definition)
+int ctf_array_read(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct definition_array *array_definition =
container_of(definition, struct definition_array, p);
struct declaration_array *array_declaration =
array_definition->declaration;
- struct declaration *elem = array_declaration->elem;
+ struct bt_declaration *elem = array_declaration->elem;
struct ctf_stream_pos *pos =
container_of(ppos, struct ctf_stream_pos, parent);
}
}
}
- return array_rw(ppos, definition);
+ return bt_array_rw(ppos, definition);
}
-int ctf_array_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_array_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct definition_array *array_definition =
container_of(definition, struct definition_array, p);
struct declaration_array *array_declaration =
array_definition->declaration;
- struct declaration *elem = array_declaration->elem;
+ struct bt_declaration *elem = array_declaration->elem;
struct ctf_stream_pos *pos =
container_of(ppos, struct ctf_stream_pos, parent);
}
}
}
- return array_rw(ppos, definition);
+ return bt_array_rw(ppos, definition);
}
#include <stdint.h>
#include <glib.h>
-int ctf_enum_read(struct stream_pos *ppos, struct definition *definition)
+int ctf_enum_read(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct definition_enum *enum_definition =
container_of(definition, struct definition_enum, p);
if (ret)
return ret;
if (!integer_declaration->signedness) {
- qs = enum_uint_to_quark_set(enum_declaration,
+ qs = bt_enum_uint_to_quark_set(enum_declaration,
integer_definition->value._unsigned);
if (!qs) {
fprintf(stderr, "[warning] Unknown value %" PRIu64 " in enum.\n",
integer_definition->value._unsigned);
}
} else {
- qs = enum_int_to_quark_set(enum_declaration,
+ qs = bt_enum_int_to_quark_set(enum_declaration,
integer_definition->value._signed);
if (!qs) {
fprintf(stderr, "[warning] Unknown value %" PRId64 " in enum.\n",
return 0;
}
-int ctf_enum_write(struct stream_pos *pos, struct definition *definition)
+int ctf_enum_write(struct bt_stream_pos *pos, struct bt_definition *definition)
{
struct definition_enum *enum_definition =
container_of(definition, struct definition_enum, p);
assert(!ret);
}
-int _ctf_float_copy(struct stream_pos *destp,
+static int _ctf_float_copy(struct bt_stream_pos *destp,
struct definition_float *dest_definition,
- struct stream_pos *srcp,
+ struct bt_stream_pos *srcp,
const struct definition_float *src_definition)
{
int ret;
return 0;
}
-int ctf_float_read(struct stream_pos *ppos, struct definition *definition)
+int ctf_float_read(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct definition_float *float_definition =
container_of(definition, struct definition_float, p);
float_definition->declaration;
struct ctf_stream_pos *pos = ctf_pos(ppos);
union doubleIEEE754 u;
- struct definition *tmpdef;
+ struct bt_definition *tmpdef;
struct definition_float *tmpfloat;
struct ctf_stream_pos destp;
struct mmap_align mma;
}
tmpfloat = container_of(tmpdef, struct definition_float, p);
memset(&destp, 0, sizeof(destp));
- ctf_init_pos(&destp, -1, O_RDWR);
+ ctf_init_pos(&destp, NULL, -1, O_RDWR);
mmap_align_set_addr(&mma, (char *) u.bits);
destp.base_mma = &mma;
destp.packet_size = sizeof(u) * CHAR_BIT;
}
end_unref:
- definition_unref(tmpdef);
+ bt_definition_unref(tmpdef);
end:
float_unlock();
return ret;
}
-int ctf_float_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_float_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct definition_float *float_definition =
container_of(definition, struct definition_float, p);
float_definition->declaration;
struct ctf_stream_pos *pos = ctf_pos(ppos);
union doubleIEEE754 u;
- struct definition *tmpdef;
+ struct bt_definition *tmpdef;
struct definition_float *tmpfloat;
struct ctf_stream_pos srcp;
struct mmap_align mma;
goto end;
}
tmpfloat = container_of(tmpdef, struct definition_float, p);
- ctf_init_pos(&srcp, -1, O_RDONLY);
+ ctf_init_pos(&srcp, NULL, -1, O_RDONLY);
mmap_align_set_addr(&mma, (char *) u.bits);
srcp.base_mma = &mma;
srcp.packet_size = sizeof(u) * CHAR_BIT;
ret = _ctf_float_copy(ppos, float_definition, &srcp.parent, tmpfloat);
end_unref:
- definition_unref(tmpdef);
+ bt_definition_unref(tmpdef);
end:
float_unlock();
return ret;
}
+static
void __attribute__((constructor)) ctf_float_init(void)
{
static_float_declaration =
- float_declaration_new(FLT_MANT_DIG,
+ bt_float_declaration_new(FLT_MANT_DIG,
sizeof(float) * CHAR_BIT - FLT_MANT_DIG,
BYTE_ORDER,
__alignof__(float));
static_double_declaration =
- float_declaration_new(DBL_MANT_DIG,
+ bt_float_declaration_new(DBL_MANT_DIG,
sizeof(double) * CHAR_BIT - DBL_MANT_DIG,
BYTE_ORDER,
__alignof__(double));
}
+static
void __attribute__((destructor)) ctf_float_fini(void)
{
- declaration_unref(&static_float_declaration->p);
- declaration_unref(&static_double_declaration->p);
+ bt_declaration_unref(&static_float_declaration->p);
+ bt_declaration_unref(&static_double_declaration->p);
}
*/
static
-int _aligned_integer_read(struct stream_pos *ppos,
- struct definition *definition)
+int _aligned_integer_read(struct bt_stream_pos *ppos,
+ struct bt_definition *definition)
{
struct definition_integer *integer_definition =
container_of(definition, struct definition_integer, p);
}
static
-int _aligned_integer_write(struct stream_pos *ppos,
- struct definition *definition)
+int _aligned_integer_write(struct bt_stream_pos *ppos,
+ struct bt_definition *definition)
{
struct definition_integer *integer_definition =
container_of(definition, struct definition_integer, p);
return 0;
}
-int ctf_integer_read(struct stream_pos *ppos, struct definition *definition)
+int ctf_integer_read(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct definition_integer *integer_definition =
container_of(definition, struct definition_integer, p);
return 0;
}
-int ctf_integer_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_integer_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct definition_integer *integer_definition =
container_of(definition, struct definition_integer, p);
#include <babeltrace/ctf/types.h>
-int ctf_sequence_read(struct stream_pos *ppos, struct definition *definition)
+int ctf_sequence_read(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct definition_sequence *sequence_definition =
container_of(definition, struct definition_sequence, p);
struct declaration_sequence *sequence_declaration =
sequence_definition->declaration;
- struct declaration *elem = sequence_declaration->elem;
+ struct bt_declaration *elem = sequence_declaration->elem;
struct ctf_stream_pos *pos = ctf_pos(ppos);
if (elem->id == CTF_TYPE_INTEGER) {
if (integer_declaration->len == CHAR_BIT
&& integer_declaration->p.alignment == CHAR_BIT) {
- uint64_t len = sequence_len(sequence_definition);
+ uint64_t len = bt_sequence_len(sequence_definition);
ctf_align_pos(pos, integer_declaration->p.alignment);
if (!ctf_pos_access_ok(pos, len * CHAR_BIT))
}
}
}
- return sequence_rw(ppos, definition);
+ return bt_sequence_rw(ppos, definition);
}
-int ctf_sequence_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_sequence_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct definition_sequence *sequence_definition =
container_of(definition, struct definition_sequence, p);
struct declaration_sequence *sequence_declaration =
sequence_definition->declaration;
- struct declaration *elem = sequence_declaration->elem;
+ struct bt_declaration *elem = sequence_declaration->elem;
struct ctf_stream_pos *pos = ctf_pos(ppos);
if (elem->id == CTF_TYPE_INTEGER) {
if (integer_declaration->len == CHAR_BIT
&& integer_declaration->p.alignment == CHAR_BIT) {
- uint64_t len = sequence_len(sequence_definition);
+ uint64_t len = bt_sequence_len(sequence_definition);
ctf_align_pos(pos, integer_declaration->p.alignment);
if (!ctf_pos_access_ok(pos, len * CHAR_BIT))
}
}
}
- return sequence_rw(ppos, definition);
+ return bt_sequence_rw(ppos, definition);
}
#include <limits.h> /* C99 limits */
#include <string.h>
-int ctf_string_read(struct stream_pos *ppos, struct definition *definition)
+int ctf_string_read(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct definition_string *string_definition =
container_of(definition, struct definition_string, p);
return 0;
}
-int ctf_string_write(struct stream_pos *ppos,
- struct definition *definition)
+int ctf_string_write(struct bt_stream_pos *ppos,
+ struct bt_definition *definition)
{
struct definition_string *string_definition =
container_of(definition, struct definition_string, p);
#include <babeltrace/ctf/types.h>
-int ctf_struct_rw(struct stream_pos *ppos, struct definition *definition)
+int ctf_struct_rw(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
- struct declaration *declaration = definition->declaration;
+ struct bt_declaration *declaration = definition->declaration;
struct ctf_stream_pos *pos = ctf_pos(ppos);
ctf_align_pos(pos, declaration->alignment);
- return struct_rw(ppos, definition);
+ return bt_struct_rw(ppos, definition);
}
#include <babeltrace/ctf/types.h>
-int ctf_variant_rw(struct stream_pos *ppos, struct definition *definition)
+int ctf_variant_rw(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
- struct declaration *declaration = definition->declaration;
+ struct bt_declaration *declaration = definition->declaration;
struct ctf_stream_pos *pos = ctf_pos(ppos);
ctf_align_pos(pos, declaration->alignment);
- return variant_rw(ppos, definition);
+ return bt_variant_rw(ppos, definition);
}
babeltrace/clock-internal.h \
babeltrace/compiler.h \
babeltrace/context-internal.h \
+ babeltrace/format-internal.h \
babeltrace/iterator-internal.h \
babeltrace/trace-collection.h \
babeltrace/prio_heap.h \
babeltrace/ctf/types.h \
babeltrace/ctf/callbacks-internal.h \
babeltrace/trace-handle-internal.h \
- babeltrace/uuid.h \
+ babeltrace/compat/uuid.h \
+ babeltrace/compat/memstream.h \
+ babeltrace/compat/utc.h \
babeltrace/endian.h \
babeltrace/mmap-align.h
#include <stdio.h>
#include <glib.h>
#include <stdint.h>
+#include <string.h>
+
+#define PERROR_BUFLEN 200
extern int babeltrace_verbose, babeltrace_debug;
fprintf(stdout, "[debug] " fmt, ## args); \
} while (0)
-#define likely(x) __builtin_expect(!!(x), 1)
-#define unlikely(x) __builtin_expect(!!(x), 0)
+#define _bt_printf(fp, kindstr, fmt, args...) \
+ fprintf(fp, "[%s]%s%s%s: " fmt "\n", \
+ kindstr, \
+ babeltrace_debug ? " \"" : "", \
+ babeltrace_debug ? __func__ : "", \
+ babeltrace_debug ? "\"" : "", \
+ ## args)
+
+#define _bt_printfl(fp, kindstr, lineno, fmt, args...) \
+ fprintf(fp, "[%s]%s%s%s at line %u: " fmt "\n", \
+ kindstr, \
+ babeltrace_debug ? " \"" : "", \
+ babeltrace_debug ? __func__ : "", \
+ babeltrace_debug ? "\"" : "", \
+ lineno, \
+ ## args)
+
+#define _bt_printfe(fp, kindstr, perrorstr, fmt, args...) \
+ fprintf(fp, "[%s]%s%s%s: %s: " fmt "\n", \
+ kindstr, \
+ babeltrace_debug ? " \"" : "", \
+ babeltrace_debug ? __func__ : "", \
+ babeltrace_debug ? "\"" : "", \
+ perrorstr, \
+ ## args)
+
+#define _bt_printfle(fp, kindstr, lineno, perrorstr, fmt, args...) \
+ fprintf(fp, "[%s]%s%s%s at line %u: %s: " fmt "\n", \
+ kindstr, \
+ babeltrace_debug ? " \"" : "", \
+ babeltrace_debug ? __func__ : "", \
+ babeltrace_debug ? "\"" : "", \
+ lineno, \
+ perrorstr, \
+ ## args)
+
+#if !defined(__linux__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE))
+
+#define _bt_printf_perror(fp, fmt, args...) \
+ ({ \
+ char buf[PERROR_BUFLEN] = "Error in strerror_r()"; \
+ strerror_r(errno, buf, sizeof(buf)); \
+ _bt_printfe(fp, "error", buf, fmt, ## args); \
+ })
+
+#define _bt_printfl_perror(fp, lineno, fmt, args...) \
+ ({ \
+ char buf[PERROR_BUFLEN] = "Error in strerror_r()"; \
+ strerror_r(errno, buf, sizeof(buf)); \
+ _bt_printfle(fp, "error", lineno, buf, fmt, ## args); \
+ })
+
+#else
+
+/*
+ * Version using GNU strerror_r, for linux with appropriate defines.
+ */
+
+#define _bt_printf_perror(fp, fmt, args...) \
+ ({ \
+ char *buf; \
+ char tmp[PERROR_BUFLEN] = "Error in strerror_r()"; \
+ buf = strerror_r(errno, tmp, sizeof(tmp)); \
+ _bt_printfe(fp, "error", buf, fmt, ## args); \
+ })
+
+#define _bt_printfl_perror(fp, lineno, fmt, args...) \
+ ({ \
+ char *buf; \
+ char tmp[PERROR_BUFLEN] = "Error in strerror_r()"; \
+ buf = strerror_r(errno, tmp, sizeof(tmp)); \
+ _bt_printfle(fp, "error", lineno, buf, fmt, ## args); \
+ })
+
+#endif
+
+/* printf without lineno information */
+#define printf_fatal(fmt, args...) \
+ _bt_printf(stderr, "fatal", fmt, ## args)
+#define printf_error(fmt, args...) \
+ _bt_printf(stderr, "error", fmt, ## args)
+#define printf_warning(fmt, args...) \
+ _bt_printf(stderr, "warning", fmt, ## args)
+#define printf_perror(fmt, args...) \
+ _bt_printf_perror(stderr, fmt, ## args)
+
+/* printf with lineno information */
+#define printfl_fatal(lineno, fmt, args...) \
+ _bt_printfl(stderr, "fatal", lineno, fmt, ## args)
+#define printfl_error(lineno, fmt, args...) \
+ _bt_printfl(stderr, "error", lineno, fmt, ## args)
+#define printfl_warning(lineno, fmt, args...) \
+ _bt_printfl(stderr, "warning", lineno, fmt, ## args)
+#define printfl_perror(lineno, fmt, args...) \
+ _bt_printfl_perror(stderr, lineno, fmt, ## args)
+
+/* printf with node lineno information */
+#define printfn_fatal(node, fmt, args...) \
+ _bt_printfl(stderr, "fatal", (node)->lineno, fmt, ## args)
+#define printfn_error(node, fmt, args...) \
+ _bt_printfl(stderr, "error", (node)->lineno, fmt, ## args)
+#define printfn_warning(node, fmt, args...) \
+ _bt_printfl(stderr, "warning", (node)->lineno, fmt, ## args)
+#define printfn_perror(node, fmt, args...) \
+ _bt_printfl_perror(stderr, (node)->lineno, fmt, ## args)
+
+/* fprintf with Node lineno information */
+#define fprintfn_fatal(fp, node, fmt, args...) \
+ _bt_printfl(fp, "fatal", (node)->lineno, fmt, ## args)
+#define fprintfn_error(fp, node, fmt, args...) \
+ _bt_printfl(fp, "error", (node)->lineno, fmt, ## args)
+#define fprintfn_warning(fp, node, fmt, args...) \
+ _bt_printfl(fp, "warning", (node)->lineno, fmt, ## args)
+#define fprintfn_perror(fp, node, fmt, args...) \
+ _bt_printfl_perror(fp, (node)->lineno, fmt, ## args)
+
+#ifndef likely
+# ifdef __GNUC__
+# define likely(x) __builtin_expect(!!(x), 1)
+# else
+# define likely(x) (!!(x))
+# endif
+#endif
+
+#ifndef unlikely
+# ifdef __GNUC__
+# define unlikely(x) __builtin_expect(!!(x), 0)
+# else
+# define unlikely(x) (!!(x))
+# endif
+#endif
+
+/*
+ * BT_HIDDEN: set the hidden attribute for internal functions
+ */
+#define BT_HIDDEN __attribute__((visibility("hidden")))
+
+#define BT_CTF_MAJOR 1
+#define BT_CTF_MINOR 8
-struct trace_descriptor;
+struct bt_trace_descriptor;
struct trace_collection {
- GPtrArray *array; /* struct trace_descriptor */
+ GPtrArray *array; /* struct bt_trace_descriptor */
GHashTable *clocks; /* struct ctf_clock */
uint64_t single_clock_offset_avg;
opt_clock_force_correlate;
extern uint64_t opt_clock_offset;
+extern uint64_t opt_clock_offset_ns;
#endif
--- /dev/null
+#ifndef _BABELTRACE_FORMAT_CTF_MEMSTREAM_H
+#define _BABELTRACE_FORMAT_CTF_MEMSTREAM_H
+
+/*
+ * format/ctf/memstream.h
+ *
+ * Copyright 2012 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * memstream compatibility layer.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#define _GNU_SOURCE
+#include <config.h>
+
+#ifdef BABELTRACE_HAVE_FMEMOPEN
+#include <stdio.h>
+
+static inline
+FILE *babeltrace_fmemopen(void *buf, size_t size, const char *mode)
+{
+ return fmemopen(buf, size, mode);
+}
+
+#else /* BABELTRACE_HAVE_FMEMOPEN */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+/*
+ * Fallback for systems which don't have fmemopen. Copy buffer to a
+ * temporary file, and use that file as FILE * input.
+ */
+static inline
+FILE *babeltrace_fmemopen(void *buf, size_t size, const char *mode)
+{
+ char tmpname[PATH_MAX];
+ size_t len;
+ FILE *fp;
+ int ret;
+
+ /*
+ * Support reading only.
+ */
+ if (strcmp(mode, "rb") != 0) {
+ return NULL;
+ }
+ strncpy(tmpname, "/tmp/babeltrace-tmp-XXXXXX", PATH_MAX);
+ ret = mkstemp(tmpname);
+ if (ret < 0) {
+ return NULL;
+ }
+ /*
+ * We need to write to the file.
+ */
+ fp = fdopen(ret, "w+");
+ if (!fp) {
+ goto error_unlink;
+ }
+ /* Copy the entire buffer to the file */
+ len = fwrite(buf, sizeof(char), size, fp);
+ if (len != size) {
+ goto error_close;
+ }
+ ret = fseek(fp, 0L, SEEK_SET);
+ if (ret < 0) {
+ perror("fseek");
+ goto error_close;
+ }
+ /* We keep the handle open, but can unlink the file on the VFS. */
+ ret = unlink(tmpname);
+ if (ret < 0) {
+ perror("unlink");
+ }
+ return fp;
+
+error_close:
+ ret = fclose(fp);
+ if (ret < 0) {
+ perror("close");
+ }
+error_unlink:
+ ret = unlink(tmpname);
+ if (ret < 0) {
+ perror("unlink");
+ }
+ return NULL;
+}
+
+#endif /* BABELTRACE_HAVE_FMEMOPEN */
+
+#ifdef BABELTRACE_HAVE_OPEN_MEMSTREAM
+
+#include <stdio.h>
+
+static inline
+FILE *babeltrace_open_memstream(char **ptr, size_t *sizeloc)
+{
+ return open_memstream(ptr, sizeloc);
+}
+
+static inline
+int babeltrace_close_memstream(char **buf, size_t *size, FILE *fp)
+{
+ return fclose(fp);
+}
+
+#else /* BABELTRACE_HAVE_OPEN_MEMSTREAM */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+/*
+ * Fallback for systems which don't have open_memstream. Create FILE *
+ * with babeltrace_open_memstream, but require call to
+ * babeltrace_close_memstream to flush all data written to the FILE *
+ * into the buffer (which we allocate).
+ */
+static inline
+FILE *babeltrace_open_memstream(char **ptr, size_t *sizeloc)
+{
+ char tmpname[PATH_MAX];
+ int ret;
+ FILE *fp;
+
+ strncpy(tmpname, "/tmp/babeltrace-tmp-XXXXXX", PATH_MAX);
+ ret = mkstemp(tmpname);
+ if (ret < 0) {
+ return NULL;
+ }
+ fp = fdopen(ret, "w+");
+ if (!fp) {
+ goto error_unlink;
+ }
+ /*
+ * babeltrace_flush_memstream will update the buffer content
+ * with read from fp. No need to keep the file around, just the
+ * handle.
+ */
+ ret = unlink(tmpname);
+ if (ret < 0) {
+ perror("unlink");
+ }
+ return fp;
+
+error_unlink:
+ ret = unlink(tmpname);
+ if (ret < 0) {
+ perror("unlink");
+ }
+ return NULL;
+}
+
+/* Get file size, allocate buffer, copy. */
+static inline
+int babeltrace_close_memstream(char **buf, size_t *size, FILE *fp)
+{
+ size_t len, n;
+ long pos;
+ int ret;
+
+ ret = fflush(fp);
+ if (ret < 0) {
+ perror("fflush");
+ return ret;
+ }
+ ret = fseek(fp, 0L, SEEK_END);
+ if (ret < 0) {
+ perror("fseek");
+ return ret;
+ }
+ pos = ftell(fp);
+ if (ret < 0) {
+ perror("ftell");
+ return ret;
+ }
+ *size = pos;
+ /* add final \0 */
+ *buf = calloc(pos + 1, sizeof(char));
+ if (!*buf) {
+ return -ENOMEM;
+ }
+ ret = fseek(fp, 0L, SEEK_SET);
+ if (ret < 0) {
+ perror("fseek");
+ goto error_free;
+ }
+ /* Copy the entire file into the buffer */
+ n = 0;
+ clearerr(fp);
+ while (!feof(fp) && !ferror(fp) && (*size - n > 0)) {
+ len = fread(*buf, sizeof(char), *size - n, fp);
+ n += len;
+ }
+ if (n != *size) {
+ ret = -1;
+ goto error_close;
+ }
+ ret = fclose(fp);
+ if (ret < 0) {
+ perror("fclose");
+ return ret;
+ }
+ return 0;
+
+error_close:
+ ret = fclose(fp);
+ if (ret < 0) {
+ perror("fclose");
+ }
+error_free:
+ free(*buf);
+ *buf = NULL;
+ return ret;
+}
+
+#endif /* BABELTRACE_HAVE_OPEN_MEMSTREAM */
+
+#endif /* _BABELTRACE_FORMAT_CTF_MEMSTREAM_H */
--- /dev/null
+#ifndef _BABELTRACE_UTC_H
+#define _BABELTRACE_UTC_H
+
+/*
+ * Copyright (C) 2011-2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <time.h>
+
+/* If set, use GNU or BSD timegm(3) */
+#if defined(_BSD_SOURCE) || defined(_SVID_SOURCE)
+
+static inline
+time_t babeltrace_timegm(struct tm *tm)
+{
+ return timegm(tm);
+}
+
+#else
+
+#include <string.h>
+#include <stdlib.h>
+
+/*
+ * Note: Below implementation of timegm() is not thread safe
+ * as it changes the environment
+ * variable TZ. It is OK as long as it is kept in self-contained program,
+ * but should not be used within thread-safe library code.
+ */
+
+static inline
+time_t babeltrace_timegm(struct tm *tm)
+{
+ time_t ret;
+ char *tz;
+
+ tz = getenv("TZ");
+ /*
+ * Make a temporary copy, as the environment variable will be
+ * modified.
+ */
+ if (tz) {
+ tz = strdup(tz);
+ if (!tz) {
+ /*
+ * Memory allocation error.
+ */
+ return (time_t) -1;
+ }
+ }
+
+ /* Temporarily setting TZ to 1 for UTC */
+ setenv("TZ", "", 1);
+ tzset();
+ ret = mktime(tm);
+ if (tz) {
+ setenv("TZ", tz, 1);
+ free(tz);
+ } else {
+ unsetenv("TZ");
+ }
+ tzset();
+ return ret;
+}
+
+#endif
+
+#endif /* _BABELTRACE_UTC_H */
--- /dev/null
+#ifndef _BABELTRACE_UUID_H
+#define _BABELTRACE_UUID_H
+
+/*
+ * babeltrace/uuid.h
+ *
+ * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <config.h>
+
+/* Includes final \0. */
+#define BABELTRACE_UUID_STR_LEN 37
+#define BABELTRACE_UUID_LEN 16
+
+#ifdef BABELTRACE_HAVE_LIBUUID
+#include <uuid/uuid.h>
+
+static inline
+int babeltrace_uuid_generate(unsigned char *uuid_out)
+{
+ uuid_generate(uuid_out);
+ return 0;
+}
+
+static inline
+int babeltrace_uuid_unparse(const unsigned char *uuid_in, char *str_out)
+{
+ uuid_unparse(uuid_in, str_out);
+ return 0;
+}
+
+static inline
+int babeltrace_uuid_parse(const char *str_in, unsigned char *uuid_out)
+{
+ return uuid_parse(str_in, uuid_out);
+}
+
+static inline
+int babeltrace_uuid_compare(const unsigned char *uuid_a,
+ const unsigned char *uuid_b)
+{
+ return uuid_compare(uuid_a, uuid_b);
+}
+
+#elif defined(BABELTRACE_HAVE_LIBC_UUID)
+#include <uuid.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+
+static inline
+int babeltrace_uuid_generate(unsigned char *uuid_out)
+{
+ uint32_t status;
+
+ uuid_create((uuid_t *) uuid_out, &status);
+ if (status == uuid_s_ok)
+ return 0;
+ else
+ return -1;
+}
+
+static inline
+int babeltrace_uuid_unparse(const unsigned char *uuid_in, char *str_out)
+{
+ uint32_t status;
+ char *alloc_str;
+ int ret;
+
+ uuid_to_string((uuid_t *) uuid_in, &alloc_str, &status);
+ if (status == uuid_s_ok) {
+ strcpy(str_out, alloc_str);
+ ret = 0;
+ } else {
+ ret = -1;
+ }
+ free(alloc_str);
+ return ret;
+}
+
+static inline
+int babeltrace_uuid_parse(const char *str_in, unsigned char *uuid_out)
+{
+ uint32_t status;
+
+ uuid_from_string(str_in, (uuid_t *) uuid_out, &status);
+ if (status == uuid_s_ok)
+ return 0;
+ else
+ return -1;
+}
+
+static inline
+int babeltrace_uuid_compare(const unsigned char *uuid_a,
+ const unsigned char *uuid_b)
+{
+ uint32_t status;
+
+ uuid_compare((uuid_t *) uuid_a, (uuid_t *) uuid_b, &status);
+ if (status == uuid_s_ok)
+ return 0;
+ else
+ return -1;
+}
+
+#else
+#error "Babeltrace needs to have a UUID generator configured."
+#endif
+
+#endif /* _BABELTRACE_UUID_H */
/* struct bt_context is opaque to the user */
struct bt_context;
-struct stream_pos;
+struct bt_stream_pos;
struct bt_ctf_event;
/*
*/
int bt_context_add_trace(struct bt_context *ctx, const char *path,
const char *format,
- void (*packet_seek)(struct stream_pos *pos,
+ void (*packet_seek)(struct bt_stream_pos *pos,
size_t index, int whence),
- struct mmap_stream_list *stream_list,
+ struct bt_mmap_stream_list *stream_list,
FILE *metadata);
/*
#include <babeltrace/types.h>
#include <babeltrace/format.h>
+#include <babeltrace/format-internal.h>
#include <babeltrace/ctf/types.h>
#include <sys/types.h>
#include <dirent.h>
-#include <babeltrace/uuid.h>
+#include <babeltrace/compat/uuid.h>
#include <assert.h>
#include <glib.h>
uint64_t prev_real_timestamp_end; /* End-of-last-packet timestamp in ns */
uint64_t prev_cycles_timestamp; /* Start-of-last-packet timestamp in cycles */
uint64_t prev_cycles_timestamp_end; /* End-of-last-packet timestamp in cycles */
+ char path[PATH_MAX]; /* Path to stream. '\0' for mmap traces */
};
struct ctf_event_definition {
};
struct ctf_trace {
- struct trace_descriptor parent;
+ struct bt_trace_descriptor parent;
+
/* root scope */
struct declaration_scope *root_declaration_scope;
struct definition_scope *definition_scope;
GPtrArray *streams; /* Array of struct ctf_stream_declaration pointers */
struct ctf_stream_definition *metadata;
- GHashTable *clocks;
+ char *metadata_string;
+ int metadata_packetized;
GHashTable *callsites;
- struct ctf_clock *single_clock; /* currently supports only one clock */
- struct trace_collection *collection; /* Container of this trace */
GPtrArray *event_declarations; /* Array of all the struct bt_ctf_event_decl */
struct declaration_struct *packet_header_decl;
DIR *dir;
int dirfd;
int flags; /* open flags */
-
- /* Heap of streams, ordered to always get the lowest timestam */
- struct ptr_heap *stream_heap;
- char path[PATH_MAX];
-
- struct bt_context *ctx;
- struct bt_trace_handle *handle;
};
#define CTF_STREAM_SET_FIELD(ctf_stream, field) \
struct ctf_stream_declaration {
struct ctf_trace *trace;
- /* parent is lexical scope conaining the stream scope */
+ /* parent is lexical scope containing the stream scope */
struct declaration_scope *declaration_scope;
/* innermost definition scope. to be used as parent of event. */
struct definition_scope *definition_scope;
struct ctf_event_declaration {
/* stream mapped by stream_id */
struct ctf_stream_declaration *stream;
- /* parent is lexical scope conaining the event scope */
+ /* parent is lexical scope containing the event scope */
struct declaration_scope *declaration_scope;
struct declaration_struct *context_decl;
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/types.h>
#include <babeltrace/format.h>
+#include <babeltrace/format-internal.h>
/*
- * Inherit from both struct stream_pos and struct trace_descriptor.
+ * Inherit from both struct bt_stream_pos and struct bt_trace_descriptor.
*/
struct ctf_text_stream_pos {
- struct stream_pos parent;
- struct trace_descriptor trace_descriptor;
+ struct bt_stream_pos parent;
+ struct bt_trace_descriptor trace_descriptor;
FILE *fp; /* File pointer. NULL if unset. */
int depth;
int dummy; /* disable output */
};
static inline
-struct ctf_text_stream_pos *ctf_text_pos(struct stream_pos *pos)
+struct ctf_text_stream_pos *ctf_text_pos(struct bt_stream_pos *pos)
{
return container_of(pos, struct ctf_text_stream_pos, parent);
}
/*
* Write only is supported for now.
*/
-int ctf_text_integer_write(struct stream_pos *pos, struct definition *definition);
-int ctf_text_float_write(struct stream_pos *pos, struct definition *definition);
-int ctf_text_string_write(struct stream_pos *pos, struct definition *definition);
-int ctf_text_enum_write(struct stream_pos *pos, struct definition *definition);
-int ctf_text_struct_write(struct stream_pos *pos, struct definition *definition);
-int ctf_text_variant_write(struct stream_pos *pos, struct definition *definition);
-int ctf_text_array_write(struct stream_pos *pos, struct definition *definition);
-int ctf_text_sequence_write(struct stream_pos *pos, struct definition *definition);
+BT_HIDDEN
+int ctf_text_integer_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_text_float_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_text_string_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_text_enum_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_text_struct_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_text_variant_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_text_array_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_text_sequence_write(struct bt_stream_pos *pos, struct bt_definition *definition);
static inline
void print_pos_tabs(struct ctf_text_stream_pos *pos)
/*
* Check if the field must be printed.
*/
-int print_field(struct definition *definition);
+BT_HIDDEN
+int print_field(struct bt_definition *definition);
#endif /* _BABELTRACE_CTF_TEXT_TYPES_H */
int refcount; /* free when decremented to 0 */
};
+BT_HIDDEN
void process_callbacks(struct bt_ctf_iter *iter, struct ctf_stream_definition *stream);
#endif /* _BABELTRACE_CALLBACKS_INTERNAL_H */
/*
* Receives a variable number of strings as parameter, ended with NULL.
*/
-struct bt_dependencies *babeltrace_dependencies_create(const char *first, ...);
+struct bt_dependencies *bt_dependencies_create(const char *first, ...);
/*
* struct bt_dependencies must be destroyed explicitly if not passed as
* parameter to a bt_ctf_iter_add_callback().
*/
-void babeltrace_dependencies_destroy(struct bt_dependencies *dep);
+void bt_dependencies_destroy(struct bt_dependencies *dep);
/*
* bt_ctf_iter_add_callback: Add a callback to iterator.
uint64_t events_lost;
};
+void ctf_print_discarded(FILE *fp, struct ctf_stream_definition *stream,
+ int end_stream);
+
#endif /*_BABELTRACE_CTF_EVENTS_INTERNAL_H */
extern "C" {
#endif
-struct definition;
-struct declaration;
+struct bt_definition;
+struct bt_declaration;
struct bt_ctf_event;
struct bt_ctf_event_decl;
struct bt_ctf_field_decl;
* between the enum and the actual definition of top-level scopes.
* On error return NULL.
*/
-const struct definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *event,
+const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *event,
enum bt_ctf_scope scope);
/*
* from which the event is extracted is unchanged).
*/
int bt_ctf_get_field_list(const struct bt_ctf_event *event,
- const struct definition *scope,
- struct definition const * const **list,
+ const struct bt_definition *scope,
+ struct bt_definition const * const **list,
unsigned int *count);
/*
* bt_ctf_get_field: returns the definition of a specific field
*/
-const struct definition *bt_ctf_get_field(const struct bt_ctf_event *event,
- const struct definition *scope,
+const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *event,
+ const struct bt_definition *scope,
const char *field);
/*
* bt_ctf_get_index: if the field is an array or a sequence, return the element
* at position index, otherwise return NULL;
*/
-const struct definition *bt_ctf_get_index(const struct bt_ctf_event *event,
- const struct definition *field,
+const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *event,
+ const struct bt_definition *field,
unsigned int index);
/*
* bt_ctf_field_name: returns the name of a field or NULL on error
*/
-const char *bt_ctf_field_name(const struct definition *def);
+const char *bt_ctf_field_name(const struct bt_definition *def);
/*
* bt_ctf_get_decl_from_def: return the declaration of a field from
* its definition or NULL on error
*/
-const struct declaration *bt_ctf_get_decl_from_def(const struct definition *def);
+const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *def);
/*
* bt_ctf_get_decl_from_field_decl: return the declaration of a field from
* a field_decl or NULL on error
*/
-const struct declaration *bt_ctf_get_decl_from_field_decl(
+const struct bt_declaration *bt_ctf_get_decl_from_field_decl(
const struct bt_ctf_field_decl *field);
/*
* bt_ctf_field_type: returns the type of a field or -1 if unknown
*/
-enum ctf_type_id bt_ctf_field_type(const struct declaration *decl);
+enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *decl);
/*
* bt_ctf_get_int_signedness: return the signedness of an integer
* return 1 if signed
* return -1 on error
*/
-int bt_ctf_get_int_signedness(const struct declaration *decl);
+int bt_ctf_get_int_signedness(const struct bt_declaration *decl);
/*
* bt_ctf_get_int_base: return the base of an int or a negative value on error
*/
-int bt_ctf_get_int_base(const struct declaration *decl);
+int bt_ctf_get_int_base(const struct bt_declaration *decl);
/*
* bt_ctf_get_int_byte_order: return the byte order of an int or a negative
* value on error
*/
-int bt_ctf_get_int_byte_order(const struct declaration *decl);
+int bt_ctf_get_int_byte_order(const struct bt_declaration *decl);
/*
* bt_ctf_get_int_len: return the size, in bits, of an int or a negative
* value on error
*/
-ssize_t bt_ctf_get_int_len(const struct declaration *decl);
+ssize_t bt_ctf_get_int_len(const struct bt_declaration *decl);
/*
* bt_ctf_get_encoding: return the encoding of an int, a string, or of
* the integer contained in a char array or a sequence.
* return a negative value on error
*/
-enum ctf_string_encoding bt_ctf_get_encoding(const struct declaration *decl);
+enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *decl);
/*
* bt_ctf_get_array_len: return the len of an array or a negative
* value on error
*/
-int bt_ctf_get_array_len(const struct declaration *decl);
+int bt_ctf_get_array_len(const struct bt_declaration *decl);
/*
* Field access functions
* bt_ctf_get_enum_str gets the string matching the current enumeration
* value, or NULL if the current value does not match any string.
*/
-uint64_t bt_ctf_get_uint64(const struct definition *field);
-int64_t bt_ctf_get_int64(const struct definition *field);
-const struct definition *bt_ctf_get_enum_int(const struct definition *field);
-const char *bt_ctf_get_enum_str(const struct definition *field);
-char *bt_ctf_get_char_array(const struct definition *field);
-char *bt_ctf_get_string(const struct definition *field);
+uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
+int64_t bt_ctf_get_int64(const struct bt_definition *field);
+const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
+const char *bt_ctf_get_enum_str(const struct bt_definition *field);
+char *bt_ctf_get_char_array(const struct bt_definition *field);
+char *bt_ctf_get_string(const struct bt_definition *field);
/*
* bt_ctf_field_get_error: returns the last error code encountered while
* Always update ctf_stream_pos with ctf_move_pos and ctf_init_pos.
*/
struct ctf_stream_pos {
- struct stream_pos parent;
+ struct bt_stream_pos parent;
int fd; /* backing file fd. -1 if unset. */
GArray *packet_cycles_index; /* contains struct packet_index in cycles */
GArray *packet_real_index; /* contains struct packet_index in ns */
int64_t last_offset; /* offset before the last read_event */
uint64_t cur_index; /* current index in packet index */
uint64_t last_events_discarded; /* last known amount of event discarded */
- void (*packet_seek)(struct stream_pos *pos, size_t index,
+ void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence); /* function called to switch packet */
int dummy; /* dummy position, for length calculation */
};
static inline
-struct ctf_stream_pos *ctf_pos(struct stream_pos *pos)
+struct ctf_stream_pos *ctf_pos(struct bt_stream_pos *pos)
{
return container_of(pos, struct ctf_stream_pos, parent);
}
-int ctf_integer_read(struct stream_pos *pos, struct definition *definition);
-int ctf_integer_write(struct stream_pos *pos, struct definition *definition);
-int ctf_float_read(struct stream_pos *pos, struct definition *definition);
-int ctf_float_write(struct stream_pos *pos, struct definition *definition);
-int ctf_string_read(struct stream_pos *pos, struct definition *definition);
-int ctf_string_write(struct stream_pos *pos, struct definition *definition);
-int ctf_enum_read(struct stream_pos *pos, struct definition *definition);
-int ctf_enum_write(struct stream_pos *pos, struct definition *definition);
-int ctf_struct_rw(struct stream_pos *pos, struct definition *definition);
-int ctf_variant_rw(struct stream_pos *pos, struct definition *definition);
-int ctf_array_read(struct stream_pos *pos, struct definition *definition);
-int ctf_array_write(struct stream_pos *pos, struct definition *definition);
-int ctf_sequence_read(struct stream_pos *pos, struct definition *definition);
-int ctf_sequence_write(struct stream_pos *pos, struct definition *definition);
-
-void ctf_packet_seek(struct stream_pos *pos, size_t index, int whence);
-
-int ctf_init_pos(struct ctf_stream_pos *pos, int fd, int open_flags);
+BT_HIDDEN
+int ctf_integer_read(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_integer_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_float_read(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_float_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_string_read(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_string_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_enum_read(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_enum_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_struct_rw(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_variant_rw(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_array_read(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_array_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_sequence_read(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_sequence_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+
+void ctf_packet_seek(struct bt_stream_pos *pos, size_t index, int whence);
+
+int ctf_init_pos(struct ctf_stream_pos *pos, struct bt_trace_descriptor *trace,
+ int fd, int open_flags);
int ctf_fini_pos(struct ctf_stream_pos *pos);
/*
--- /dev/null
+#ifndef _BABELTRACE_FORMAT_INTERNAL_H
+#define _BABELTRACE_FORMAT_INTERNAL_H
+
+/*
+ * BabelTrace
+ *
+ * Trace Format Internal Header
+ *
+ * Copyright 2010-2013 EfficiOS Inc. and Linux Foundation
+ *
+ * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <limits.h>
+#include <babeltrace/context-internal.h>
+#include <babeltrace/babeltrace-internal.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Parent trace descriptor */
+struct bt_trace_descriptor {
+ char path[PATH_MAX]; /* trace path */
+ struct bt_context *ctx;
+ struct bt_trace_handle *handle;
+ struct trace_collection *collection; /* Container of this trace */
+ GHashTable *clocks;
+ struct ctf_clock *single_clock; /* currently supports only one clock */
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _BABELTRACE_FORMAT_INTERNAL_H */
typedef int bt_intern_str;
/* forward declaration */
-struct stream_pos;
+struct bt_stream_pos;
struct bt_context;
struct bt_trace_handle;
+struct bt_trace_descriptor;
-/* Parent trace descriptor */
-struct trace_descriptor {
-};
-
-struct mmap_stream {
+struct bt_mmap_stream {
int fd;
struct bt_list_head list;
};
-struct mmap_stream_list {
+struct bt_mmap_stream_list {
struct bt_list_head head;
};
-struct format {
+struct bt_format {
bt_intern_str name;
- struct trace_descriptor *(*open_trace)(const char *path, int flags,
- void (*packet_seek)(struct stream_pos *pos,
+ struct bt_trace_descriptor *(*open_trace)(const char *path, int flags,
+ void (*packet_seek)(struct bt_stream_pos *pos,
size_t index, int whence),
FILE *metadata_fp);
- struct trace_descriptor *(*open_mmap_trace)(
- struct mmap_stream_list *mmap_list,
- void (*packet_seek)(struct stream_pos *pos,
+ struct bt_trace_descriptor *(*open_mmap_trace)(
+ struct bt_mmap_stream_list *mmap_list,
+ void (*packet_seek)(struct bt_stream_pos *pos,
size_t index, int whence),
FILE *metadata_fp);
- int (*close_trace)(struct trace_descriptor *descriptor);
- void (*set_context)(struct trace_descriptor *descriptor,
+ int (*close_trace)(struct bt_trace_descriptor *descriptor);
+ void (*set_context)(struct bt_trace_descriptor *descriptor,
struct bt_context *ctx);
- void (*set_handle)(struct trace_descriptor *descriptor,
+ void (*set_handle)(struct bt_trace_descriptor *descriptor,
struct bt_trace_handle *handle);
- uint64_t (*timestamp_begin)(struct trace_descriptor *descriptor,
+ uint64_t (*timestamp_begin)(struct bt_trace_descriptor *descriptor,
struct bt_trace_handle *handle, enum bt_clock_type type);
- uint64_t (*timestamp_end)(struct trace_descriptor *descriptor,
+ uint64_t (*timestamp_end)(struct bt_trace_descriptor *descriptor,
struct bt_trace_handle *handle, enum bt_clock_type type);
- int (*convert_index_timestamp)(struct trace_descriptor *descriptor);
+ int (*convert_index_timestamp)(struct bt_trace_descriptor *descriptor);
};
-extern struct format *bt_lookup_format(bt_intern_str qname);
+extern struct bt_format *bt_lookup_format(bt_intern_str qname);
extern void bt_fprintf_format_list(FILE *fp);
-extern int bt_register_format(struct format *format);
-extern void bt_unregister_format(struct format *format);
+extern int bt_register_format(struct bt_format *format);
+extern void bt_unregister_format(struct bt_format *format);
#ifdef __cplusplus
}
#endif
/**
- * heap_maximum - return the largest element in the heap
+ * bt_heap_maximum - return the largest element in the heap
* @heap: the heap to be operated on
*
* Returns the largest element in the heap, without performing any modification
* to the heap structure. Returns NULL if the heap is empty.
*/
-static inline void *heap_maximum(const struct ptr_heap *heap)
+static inline void *bt_heap_maximum(const struct ptr_heap *heap)
{
check_heap(heap);
return likely(heap->len) ? heap->ptrs[0] : NULL;
}
/**
- * heap_init - initialize the heap
+ * bt_heap_init - initialize the heap
* @heap: the heap to initialize
* @alloc_len: number of elements initially allocated
* @gt: function to compare the elements
*
* Returns -ENOMEM if out of memory.
*/
-extern int heap_init(struct ptr_heap *heap,
+extern int bt_heap_init(struct ptr_heap *heap,
size_t alloc_len,
int gt(void *a, void *b));
/**
- * heap_free - free the heap
+ * bt_heap_free - free the heap
* @heap: the heap to free
*/
-extern void heap_free(struct ptr_heap *heap);
+extern void bt_heap_free(struct ptr_heap *heap);
/**
- * heap_insert - insert an element into the heap
+ * bt_heap_insert - insert an element into the heap
* @heap: the heap to be operated on
* @p: the element to add
*
*
* Returns -ENOMEM if out of memory.
*/
-extern int heap_insert(struct ptr_heap *heap, void *p);
+extern int bt_heap_insert(struct ptr_heap *heap, void *p);
/**
- * heap_remove - remove the largest element from the heap
+ * bt_heap_remove - remove the largest element from the heap
* @heap: the heap to be operated on
*
* Returns the largest element in the heap. It removes this element from the
* heap. Returns NULL if the heap is empty.
*/
-extern void *heap_remove(struct ptr_heap *heap);
+extern void *bt_heap_remove(struct ptr_heap *heap);
/**
- * heap_cherrypick - remove a given element from the heap
+ * bt_heap_cherrypick - remove a given element from the heap
* @heap: the heap to be operated on
* @p: the element
*
* return NULL. This algorithm has a complexity of O(n), which is higher than
* O(log(n)) provided by the rest of this API.
*/
-extern void *heap_cherrypick(struct ptr_heap *heap, void *p);
+extern void *bt_heap_cherrypick(struct ptr_heap *heap, void *p);
/**
- * heap_replace_max - replace the the largest element from the heap
+ * bt_heap_replace_max - replace the the largest element from the heap
* @heap: the heap to be operated on
* @p: the pointer to be inserted as topmost element replacement
*
* heap. The heap is rebalanced only once after the insertion. Returns NULL if
* the heap is empty.
*
- * This is the equivalent of calling heap_remove() and then heap_insert(), but
+ * This is the equivalent of calling bt_heap_remove() and then bt_heap_insert(), but
* it only rebalances the heap once. It never allocates memory.
*/
-extern void *heap_replace_max(struct ptr_heap *heap, void *p);
+extern void *bt_heap_replace_max(struct ptr_heap *heap, void *p);
/**
- * heap_copy - copy a heap
+ * bt_heap_copy - copy a heap
* @dst: the destination heap (must be allocated)
* @src: the source heap
*
* Returns -ENOMEM if out of memory.
*/
-extern int heap_copy(struct ptr_heap *dst, struct ptr_heap *src);
+extern int bt_heap_copy(struct ptr_heap *dst, struct ptr_heap *src);
#endif /* _BABELTRACE_PRIO_HEAP_H */
struct trace_collection;
-void init_trace_collection(struct trace_collection *tc);
-void finalize_trace_collection(struct trace_collection *tc);
-int trace_collection_add(struct trace_collection *tc,
- struct trace_descriptor *td);
-int trace_collection_remove(struct trace_collection *tc,
- struct trace_descriptor *td);
+void bt_init_trace_collection(struct trace_collection *tc);
+void bt_finalize_trace_collection(struct trace_collection *tc);
+int bt_trace_collection_add(struct trace_collection *tc,
+ struct bt_trace_descriptor *td);
+int bt_trace_collection_remove(struct trace_collection *tc,
+ struct bt_trace_descriptor *td);
#ifdef __cplusplus
}
*/
struct bt_trace_handle {
int id;
- struct trace_descriptor *td;
- struct format *format;
+ struct bt_trace_descriptor *td;
+ struct bt_format *format;
char path[PATH_MAX];
uint64_t real_timestamp_begin;
uint64_t real_timestamp_end;
#define DEFAULT_NR_STRUCT_FIELDS 8
struct ctf_stream_definition;
-struct stream_pos;
-struct format;
-struct definition;
+struct bt_stream_pos;
+struct bt_format;
+struct bt_definition;
struct ctf_clock;
/* type scope */
GArray *scope_path; /* array of GQuark */
};
-struct declaration {
+struct bt_declaration {
enum ctf_type_id id;
size_t alignment; /* type alignment, in bits */
int ref; /* number of references to the type */
/*
* declaration_free called with declaration ref is decremented to 0.
*/
- void (*declaration_free)(struct declaration *declaration);
- struct definition *
- (*definition_new)(struct declaration *declaration,
+ void (*declaration_free)(struct bt_declaration *declaration);
+ struct bt_definition *
+ (*definition_new)(struct bt_declaration *declaration,
struct definition_scope *parent_scope,
GQuark field_name, int index,
const char *root_name);
/*
* definition_free called with definition ref is decremented to 0.
*/
- void (*definition_free)(struct definition *definition);
+ void (*definition_free)(struct bt_definition *definition);
};
-struct definition {
- struct declaration *declaration;
+struct bt_definition {
+ struct bt_declaration *declaration;
int index; /* Position of the definition in its container */
GQuark name; /* Field name in its container (or 0 if unset) */
int ref; /* number of references to the definition */
struct definition_scope *scope;
};
-typedef int (*rw_dispatch)(struct stream_pos *pos,
- struct definition *definition);
+typedef int (*rw_dispatch)(struct bt_stream_pos *pos,
+ struct bt_definition *definition);
/* Parent of per-plugin positions */
-struct stream_pos {
+struct bt_stream_pos {
/* read/write dispatch table. Specific to plugin used for stream. */
rw_dispatch *rw_table; /* rw dispatch table */
- int (*event_cb)(struct stream_pos *pos,
+ int (*event_cb)(struct bt_stream_pos *pos,
struct ctf_stream_definition *stream);
+ int (*pre_trace_cb)(struct bt_stream_pos *pos,
+ struct bt_trace_descriptor *trace);
+ int (*post_trace_cb)(struct bt_stream_pos *pos,
+ struct bt_trace_descriptor *trace);
+ struct bt_trace_descriptor *trace;
};
static inline
-int generic_rw(struct stream_pos *pos, struct definition *definition)
+int generic_rw(struct bt_stream_pos *pos, struct bt_definition *definition)
{
enum ctf_type_id dispatch_id = definition->declaration->id;
rw_dispatch call;
* read/write non aligned on CHAR_BIT.
*/
struct declaration_integer {
- struct declaration p;
+ struct bt_declaration p;
size_t len; /* length, in bits. */
int byte_order; /* byte order */
int signedness;
};
struct definition_integer {
- struct definition p;
+ struct bt_definition p;
struct declaration_integer *declaration;
/* Last values read */
union {
};
struct declaration_float {
- struct declaration p;
+ struct bt_declaration p;
struct declaration_integer *sign;
struct declaration_integer *mantissa;
struct declaration_integer *exp;
};
struct definition_float {
- struct definition p;
+ struct bt_definition p;
struct declaration_float *declaration;
struct definition_integer *sign;
struct definition_integer *mantissa;
};
struct declaration_enum {
- struct declaration p;
+ struct bt_declaration p;
struct declaration_integer *integer_declaration;
struct enum_table table;
};
struct definition_enum {
- struct definition p;
+ struct bt_definition p;
struct definition_integer *integer;
struct declaration_enum *declaration;
/* Last GQuark values read. Keeping a reference on the GQuark array. */
};
struct declaration_string {
- struct declaration p;
+ struct bt_declaration p;
enum ctf_string_encoding encoding;
};
struct definition_string {
- struct definition p;
+ struct bt_definition p;
struct declaration_string *declaration;
char *value; /* freed at definition_string teardown */
size_t len, alloc_len;
struct declaration_field {
GQuark name;
- struct declaration *declaration;
+ struct bt_declaration *declaration;
};
struct declaration_struct {
- struct declaration p;
+ struct bt_declaration p;
GHashTable *fields_by_name; /* Tuples (field name, field index) */
struct declaration_scope *scope;
GArray *fields; /* Array of declaration_field */
};
struct definition_struct {
- struct definition p;
+ struct bt_definition p;
struct declaration_struct *declaration;
- GPtrArray *fields; /* Array of pointers to struct definition */
+ GPtrArray *fields; /* Array of pointers to struct bt_definition */
};
struct declaration_untagged_variant {
- struct declaration p;
+ struct bt_declaration p;
GHashTable *fields_by_tag; /* Tuples (field tag, field index) */
struct declaration_scope *scope;
GArray *fields; /* Array of declaration_field */
};
struct declaration_variant {
- struct declaration p;
+ struct bt_declaration p;
struct declaration_untagged_variant *untagged_variant;
GArray *tag_name; /* Array of GQuark */
};
/* A variant needs to be tagged to be defined. */
struct definition_variant {
- struct definition p;
+ struct bt_definition p;
struct declaration_variant *declaration;
- struct definition *enum_tag;
- GPtrArray *fields; /* Array of pointers to struct definition */
- struct definition *current_field; /* Last field read */
+ struct bt_definition *enum_tag;
+ GPtrArray *fields; /* Array of pointers to struct bt_definition */
+ struct bt_definition *current_field; /* Last field read */
};
struct declaration_array {
- struct declaration p;
+ struct bt_declaration p;
size_t len;
- struct declaration *elem;
+ struct bt_declaration *elem;
struct declaration_scope *scope;
};
struct definition_array {
- struct definition p;
+ struct bt_definition p;
struct declaration_array *declaration;
- GPtrArray *elems; /* Array of pointers to struct definition */
+ GPtrArray *elems; /* Array of pointers to struct bt_definition */
GString *string; /* String for encoded integer children */
};
struct declaration_sequence {
- struct declaration p;
+ struct bt_declaration p;
GArray *length_name; /* Array of GQuark */
- struct declaration *elem;
+ struct bt_declaration *elem;
struct declaration_scope *scope;
};
struct definition_sequence {
- struct definition p;
+ struct bt_definition p;
struct declaration_sequence *declaration;
struct definition_integer *length;
- GPtrArray *elems; /* Array of pointers to struct definition */
+ GPtrArray *elems; /* Array of pointers to struct bt_definition */
GString *string; /* String for encoded integer children */
};
-int register_declaration(GQuark declaration_name,
- struct declaration *declaration,
+int bt_register_declaration(GQuark declaration_name,
+ struct bt_declaration *declaration,
struct declaration_scope *scope);
-struct declaration *lookup_declaration(GQuark declaration_name,
+struct bt_declaration *bt_lookup_declaration(GQuark declaration_name,
struct declaration_scope *scope);
/*
* that a named variant can be declared without specifying its target
* "choice" tag field immediately.
*/
-int register_struct_declaration(GQuark struct_name,
+int bt_register_struct_declaration(GQuark struct_name,
struct declaration_struct *struct_declaration,
struct declaration_scope *scope);
struct declaration_struct *
- lookup_struct_declaration(GQuark struct_name,
+ bt_lookup_struct_declaration(GQuark struct_name,
struct declaration_scope *scope);
-int register_variant_declaration(GQuark variant_name,
+int bt_register_variant_declaration(GQuark variant_name,
struct declaration_untagged_variant *untagged_variant_declaration,
struct declaration_scope *scope);
-struct declaration_untagged_variant *lookup_variant_declaration(GQuark variant_name,
+struct declaration_untagged_variant *bt_lookup_variant_declaration(GQuark variant_name,
struct declaration_scope *scope);
-int register_enum_declaration(GQuark enum_name,
+int bt_register_enum_declaration(GQuark enum_name,
struct declaration_enum *enum_declaration,
struct declaration_scope *scope);
struct declaration_enum *
- lookup_enum_declaration(GQuark enum_name,
+ bt_lookup_enum_declaration(GQuark enum_name,
struct declaration_scope *scope);
struct declaration_scope *
- new_declaration_scope(struct declaration_scope *parent_scope);
-void free_declaration_scope(struct declaration_scope *scope);
+ bt_new_declaration_scope(struct declaration_scope *parent_scope);
+void bt_free_declaration_scope(struct declaration_scope *scope);
/*
* field_definition is for field definitions. They are registered into
* definition scopes.
*/
-struct definition *
- lookup_path_definition(GArray *cur_path, /* array of GQuark */
+struct bt_definition *
+ bt_lookup_path_definition(GArray *cur_path, /* array of GQuark */
GArray *lookup_path, /* array of GQuark */
struct definition_scope *scope);
-int register_field_definition(GQuark field_name,
- struct definition *definition,
+int bt_register_field_definition(GQuark field_name,
+ struct bt_definition *definition,
struct definition_scope *scope);
struct definition_scope *
- new_definition_scope(struct definition_scope *parent_scope,
+ bt_new_definition_scope(struct definition_scope *parent_scope,
GQuark field_name, const char *root_name);
-void free_definition_scope(struct definition_scope *scope);
+void bt_free_definition_scope(struct definition_scope *scope);
-GQuark new_definition_path(struct definition_scope *parent_scope,
+GQuark bt_new_definition_path(struct definition_scope *parent_scope,
GQuark field_name, const char *root_name);
static inline
-int compare_definition_path(struct definition *definition, GQuark path)
+int compare_definition_path(struct bt_definition *definition, GQuark path)
{
return definition->path == path;
}
-void declaration_ref(struct declaration *declaration);
-void declaration_unref(struct declaration *declaration);
+void bt_declaration_ref(struct bt_declaration *declaration);
+void bt_declaration_unref(struct bt_declaration *declaration);
-void definition_ref(struct definition *definition);
-void definition_unref(struct definition *definition);
+void bt_definition_ref(struct bt_definition *definition);
+void bt_definition_unref(struct bt_definition *definition);
-struct declaration_integer *integer_declaration_new(size_t len, int byte_order,
+struct declaration_integer *bt_integer_declaration_new(size_t len, int byte_order,
int signedness, size_t alignment,
int base, enum ctf_string_encoding encoding,
struct ctf_clock *clock);
-uint64_t get_unsigned_int(const struct definition *field);
-int64_t get_signed_int(const struct definition *field);
-int get_int_signedness(const struct definition *field);
-int get_int_byte_order(const struct definition *field);
-int get_int_base(const struct definition *field);
-size_t get_int_len(const struct definition *field); /* in bits */
-enum ctf_string_encoding get_int_encoding(const struct definition *field);
+uint64_t bt_get_unsigned_int(const struct bt_definition *field);
+int64_t bt_get_signed_int(const struct bt_definition *field);
+int bt_get_int_signedness(const struct bt_definition *field);
+int bt_get_int_byte_order(const struct bt_definition *field);
+int bt_get_int_base(const struct bt_definition *field);
+size_t bt_get_int_len(const struct bt_definition *field); /* in bits */
+enum ctf_string_encoding bt_get_int_encoding(const struct bt_definition *field);
/*
* mantissa_len is the length of the number of bytes represented by the mantissa
* (e.g. result of DBL_MANT_DIG). It includes the leading 1.
*/
-struct declaration_float *float_declaration_new(size_t mantissa_len,
+struct declaration_float *bt_float_declaration_new(size_t mantissa_len,
size_t exp_len, int byte_order,
size_t alignment);
* Returns a GArray of GQuark or NULL.
* Caller must release the GArray with g_array_unref().
*/
-GArray *enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
+GArray *bt_enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
uint64_t v);
/*
* Returns a GArray of GQuark or NULL.
* Caller must release the GArray with g_array_unref().
*/
-GArray *enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
+GArray *bt_enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
int64_t v);
/*
* Callers do _not_ own the returned GArray (and therefore _don't_ need to
* release it).
*/
-GArray *enum_quark_to_range_set(const struct declaration_enum *enum_declaration,
+GArray *bt_enum_quark_to_range_set(const struct declaration_enum *enum_declaration,
GQuark q);
-void enum_signed_insert(struct declaration_enum *enum_declaration,
+void bt_enum_signed_insert(struct declaration_enum *enum_declaration,
int64_t start, int64_t end, GQuark q);
-void enum_unsigned_insert(struct declaration_enum *enum_declaration,
+void bt_enum_unsigned_insert(struct declaration_enum *enum_declaration,
uint64_t start, uint64_t end, GQuark q);
-size_t enum_get_nr_enumerators(struct declaration_enum *enum_declaration);
+size_t bt_enum_get_nr_enumerators(struct declaration_enum *enum_declaration);
struct declaration_enum *
- enum_declaration_new(struct declaration_integer *integer_declaration);
+ bt_enum_declaration_new(struct declaration_integer *integer_declaration);
struct declaration_string *
- string_declaration_new(enum ctf_string_encoding encoding);
-char *get_string(const struct definition *field);
-enum ctf_string_encoding get_string_encoding(const struct definition *field);
+ bt_string_declaration_new(enum ctf_string_encoding encoding);
+char *bt_get_string(const struct bt_definition *field);
+enum ctf_string_encoding bt_get_string_encoding(const struct bt_definition *field);
struct declaration_struct *
- struct_declaration_new(struct declaration_scope *parent_scope,
+ bt_struct_declaration_new(struct declaration_scope *parent_scope,
uint64_t min_align);
-void struct_declaration_add_field(struct declaration_struct *struct_declaration,
+void bt_struct_declaration_add_field(struct declaration_struct *struct_declaration,
const char *field_name,
- struct declaration *field_declaration);
+ struct bt_declaration *field_declaration);
/*
* Returns the index of a field within a structure.
*/
-int struct_declaration_lookup_field_index(struct declaration_struct *struct_declaration,
+int bt_struct_declaration_lookup_field_index(struct declaration_struct *struct_declaration,
GQuark field_name);
/*
* field returned only valid as long as the field structure is not appended to.
*/
struct declaration_field *
-struct_declaration_get_field_from_index(struct declaration_struct *struct_declaration,
+bt_struct_declaration_get_field_from_index(struct declaration_struct *struct_declaration,
int index);
-struct definition *
-struct_definition_get_field_from_index(struct definition_struct *struct_definition,
+struct bt_definition *
+bt_struct_definition_get_field_from_index(struct definition_struct *struct_definition,
int index);
-int struct_rw(struct stream_pos *pos, struct definition *definition);
-uint64_t struct_declaration_len(struct declaration_struct *struct_declaration);
+int bt_struct_rw(struct bt_stream_pos *pos, struct bt_definition *definition);
+uint64_t bt_struct_declaration_len(struct declaration_struct *struct_declaration);
/*
* The tag enumeration is validated to ensure that it contains only mappings
* from numeric values to a single tag. Overlapping tag value ranges are
* therefore forbidden.
*/
-struct declaration_untagged_variant *untagged_variant_declaration_new(
+struct declaration_untagged_variant *bt_untagged_bt_variant_declaration_new(
struct declaration_scope *parent_scope);
-struct declaration_variant *variant_declaration_new(struct declaration_untagged_variant *untagged_variant,
+struct declaration_variant *bt_variant_declaration_new(struct declaration_untagged_variant *untagged_variant,
const char *tag);
-void untagged_variant_declaration_add_field(struct declaration_untagged_variant *untagged_variant_declaration,
+void bt_untagged_variant_declaration_add_field(struct declaration_untagged_variant *untagged_variant_declaration,
const char *field_name,
- struct declaration *field_declaration);
+ struct bt_declaration *field_declaration);
struct declaration_field *
- untagged_variant_declaration_get_field_from_tag(struct declaration_untagged_variant *untagged_variant_declaration,
+ bt_untagged_variant_declaration_get_field_from_tag(struct declaration_untagged_variant *untagged_variant_declaration,
GQuark tag);
/*
* Returns 0 on success, -EPERM on error.
*/
int variant_definition_set_tag(struct definition_variant *variant,
- struct definition *enum_tag);
+ struct bt_definition *enum_tag);
/*
* Returns the field selected by the current tag value.
* field returned only valid as long as the variant structure is not appended
* to.
*/
-struct definition *variant_get_current_field(struct definition_variant *variant);
-int variant_rw(struct stream_pos *pos, struct definition *definition);
+struct bt_definition *bt_variant_get_current_field(struct definition_variant *variant);
+int bt_variant_rw(struct bt_stream_pos *pos, struct bt_definition *definition);
/*
* elem_declaration passed as parameter now belongs to the array. No
* array.
*/
struct declaration_array *
- array_declaration_new(size_t len, struct declaration *elem_declaration,
+ bt_array_declaration_new(size_t len, struct bt_declaration *elem_declaration,
struct declaration_scope *parent_scope);
-uint64_t array_len(struct definition_array *array);
-struct definition *array_index(struct definition_array *array, uint64_t i);
-int array_rw(struct stream_pos *pos, struct definition *definition);
-GString *get_char_array(const struct definition *field);
-int get_array_len(const struct definition *field);
+uint64_t bt_array_len(struct definition_array *array);
+struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
+int bt_array_rw(struct bt_stream_pos *pos, struct bt_definition *definition);
+GString *bt_get_char_array(const struct bt_definition *field);
+int bt_get_array_len(const struct bt_definition *field);
/*
* int_declaration and elem_declaration passed as parameter now belong
* to the sequence. No need to free them explicitly.
*/
struct declaration_sequence *
- sequence_declaration_new(const char *length_name,
- struct declaration *elem_declaration,
+ bt_sequence_declaration_new(const char *length_name,
+ struct bt_declaration *elem_declaration,
struct declaration_scope *parent_scope);
-uint64_t sequence_len(struct definition_sequence *sequence);
-struct definition *sequence_index(struct definition_sequence *sequence, uint64_t i);
-int sequence_rw(struct stream_pos *pos, struct definition *definition);
+uint64_t bt_sequence_len(struct definition_sequence *sequence);
+struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
+int bt_sequence_rw(struct bt_stream_pos *pos, struct bt_definition *definition);
/*
* in: path (dot separated), out: q (GArray of GQuark)
*/
-void append_scope_path(const char *path, GArray *q);
+void bt_append_scope_path(const char *path, GArray *q);
/*
* Lookup helpers.
*/
-struct definition *lookup_definition(const struct definition *definition,
+struct bt_definition *bt_lookup_definition(const struct bt_definition *definition,
const char *field_name);
-struct definition_integer *lookup_integer(const struct definition *definition,
+struct definition_integer *bt_lookup_integer(const struct bt_definition *definition,
const char *field_name,
int signedness);
-struct definition_enum *lookup_enum(const struct definition *definition,
+struct definition_enum *bt_lookup_enum(const struct bt_definition *definition,
const char *field_name,
int signedness);
-struct definition *lookup_variant(const struct definition *definition,
+struct bt_definition *bt_lookup_variant(const struct bt_definition *definition,
const char *field_name);
static inline
+++ /dev/null
-#ifndef _BABELTRACE_UUID_H
-#define _BABELTRACE_UUID_H
-
-/*
- * babeltrace/uuid.h
- *
- * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include <config.h>
-
-/* Includes final \0. */
-#define BABELTRACE_UUID_STR_LEN 37
-#define BABELTRACE_UUID_LEN 16
-
-#ifdef BABELTRACE_HAVE_LIBUUID
-#include <uuid/uuid.h>
-
-static inline
-int babeltrace_uuid_generate(unsigned char *uuid_out)
-{
- uuid_generate(uuid_out);
- return 0;
-}
-
-static inline
-int babeltrace_uuid_unparse(const unsigned char *uuid_in, char *str_out)
-{
- uuid_unparse(uuid_in, str_out);
- return 0;
-}
-
-static inline
-int babeltrace_uuid_parse(const char *str_in, unsigned char *uuid_out)
-{
- return uuid_parse(str_in, uuid_out);
-}
-
-static inline
-int babeltrace_uuid_compare(const unsigned char *uuid_a,
- const unsigned char *uuid_b)
-{
- return uuid_compare(uuid_a, uuid_b);
-}
-
-#elif defined(BABELTRACE_HAVE_LIBC_UUID)
-#include <uuid.h>
-#include <stdint.h>
-#include <string.h>
-#include <stdlib.h>
-
-static inline
-int babeltrace_uuid_generate(unsigned char *uuid_out)
-{
- uint32_t status;
-
- uuid_create((uuid_t *) uuid_out, &status);
- if (status == uuid_s_ok)
- return 0;
- else
- return -1;
-}
-
-static inline
-int babeltrace_uuid_unparse(const unsigned char *uuid_in, char *str_out)
-{
- uint32_t status;
- char *alloc_str;
- int ret;
-
- uuid_to_string((uuid_t *) uuid_in, &alloc_str, &status);
- if (status == uuid_s_ok) {
- strcpy(str_out, alloc_str);
- ret = 0;
- } else {
- ret = -1;
- }
- free(alloc_str);
- return ret;
-}
-
-static inline
-int babeltrace_uuid_parse(const char *str_in, unsigned char *uuid_out)
-{
- uint32_t status;
-
- uuid_from_string(str_in, (uuid_t *) uuid_out, &status);
- if (status == uuid_s_ok)
- return 0;
- else
- return -1;
-}
-
-static inline
-int babeltrace_uuid_compare(const unsigned char *uuid_a,
- const unsigned char *uuid_b)
-{
- uint32_t status;
-
- uuid_compare((uuid_t *) uuid_a, (uuid_t *) uuid_b, &status);
- if (status == uuid_s_ok)
- return 0;
- else
- return -1;
-}
-
-#else
-#error "Babeltrace needs to have a UUID generator configured."
-#endif
-
-#endif /* _BABELTRACE_UUID_H */
ctx->current_iterator = NULL;
ctx->tc = g_new0(struct trace_collection, 1);
- init_trace_collection(ctx->tc);
+ bt_init_trace_collection(ctx->tc);
return ctx;
}
int bt_context_add_trace(struct bt_context *ctx, const char *path,
const char *format_name,
- void (*packet_seek)(struct stream_pos *pos, size_t index,
+ void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence),
- struct mmap_stream_list *stream_list,
+ struct bt_mmap_stream_list *stream_list,
FILE *metadata)
{
- struct trace_descriptor *td;
- struct format *fmt;
+ struct bt_trace_descriptor *td;
+ struct bt_format *fmt;
struct bt_trace_handle *handle;
int ret, closeret;
if (path) {
td = fmt->open_trace(path, O_RDONLY, packet_seek, NULL);
if (!td) {
- fprintf(stderr, "[warning] [Context] Cannot open_trace of format %s at path %s.\n\n",
+ fprintf(stderr, "[warning] [Context] Cannot open_trace of format %s at path %s.\n",
format_name, path);
ret = -1;
goto end;
/* Create an handle for the trace */
handle = bt_trace_handle_create(ctx);
- if (handle < 0) {
+ if (!handle) {
fprintf(stderr, "[error] [Context] Creating trace handle %s .\n\n",
path);
ret = -1;
g_hash_table_insert(ctx->trace_handles,
(gpointer) (unsigned long) handle->id,
handle);
- ret = trace_collection_add(ctx->tc, td);
+ ret = bt_trace_collection_add(ctx->tc, td);
if (ret != 0)
goto error;
return -ENOENT;
/* Remove from containers */
- trace_collection_remove(ctx->tc, handle->td);
+ bt_trace_collection_remove(ctx->tc, handle->td);
/* Close the trace */
ret = handle->format->close_trace(handle->td);
if (ret) {
void bt_context_destroy(struct bt_context *ctx)
{
assert(ctx);
- finalize_trace_collection(ctx->tc);
+ bt_finalize_trace_collection(ctx->tc);
/*
* Remove all traces. The g_hash_table_destroy will call
}
/*
- * returns true if a < b, false otherwise.
+ * Return true if a < b, false otherwise.
+ * If time stamps are exactly the same, compare by stream path. This
+ * ensures we get the same result between runs on the same trace
+ * collection on different environments.
+ * The result will be random for memory-mapped traces since there is no
+ * fixed path leading to those (they have empty path string).
*/
static int stream_compare(void *a, void *b)
{
struct ctf_file_stream *s_a = a, *s_b = b;
- if (s_a->parent.real_timestamp < s_b->parent.real_timestamp)
+ if (s_a->parent.real_timestamp < s_b->parent.real_timestamp) {
return 1;
- else
+ } else if (likely(s_a->parent.real_timestamp > s_b->parent.real_timestamp)) {
return 0;
+ } else {
+ return strcmp(s_a->parent.path, s_b->parent.path);
+ }
}
void bt_iter_free_pos(struct bt_iter_pos *iter_pos)
ret = seek_file_stream_by_timestamp(cfs, timestamp);
if (ret == 0) {
/* Add to heap */
- ret = heap_insert(stream_heap, cfs);
+ ret = bt_heap_insert(stream_heap, cfs);
if (ret) {
/* Return positive error. */
return -ret;
/* For each trace in the trace_collection */
for (i = 0; i < tc->array->len; i++) {
struct ctf_trace *tin;
- struct trace_descriptor *td_read;
+ struct bt_trace_descriptor *td_read;
td_read = g_ptr_array_index(tc->array, i);
if (!td_read)
if (!iter_pos->u.restore)
return -EINVAL;
- heap_free(iter->stream_heap);
- ret = heap_init(iter->stream_heap, 0, stream_compare);
+ bt_heap_free(iter->stream_heap);
+ ret = bt_heap_init(iter->stream_heap, 0, stream_compare);
if (ret < 0)
goto error_heap_init;
}
/* Add to heap */
- ret = heap_insert(iter->stream_heap,
+ ret = bt_heap_insert(iter->stream_heap,
saved_pos->file_stream);
if (ret)
goto error;
case BT_SEEK_TIME:
tc = iter->ctx->tc;
- heap_free(iter->stream_heap);
- ret = heap_init(iter->stream_heap, 0, stream_compare);
+ bt_heap_free(iter->stream_heap);
+ ret = bt_heap_init(iter->stream_heap, 0, stream_compare);
if (ret < 0)
goto error_heap_init;
/* for each trace in the trace_collection */
for (i = 0; i < tc->array->len; i++) {
struct ctf_trace *tin;
- struct trace_descriptor *td_read;
+ struct bt_trace_descriptor *td_read;
td_read = g_ptr_array_index(tc->array, i);
if (!td_read)
return 0;
case BT_SEEK_BEGIN:
tc = iter->ctx->tc;
- heap_free(iter->stream_heap);
- ret = heap_init(iter->stream_heap, 0, stream_compare);
+ bt_heap_free(iter->stream_heap);
+ ret = bt_heap_init(iter->stream_heap, 0, stream_compare);
if (ret < 0)
goto error_heap_init;
for (i = 0; i < tc->array->len; i++) {
struct ctf_trace *tin;
- struct trace_descriptor *td_read;
+ struct bt_trace_descriptor *td_read;
int stream_id;
td_read = g_ptr_array_index(tc->array, i);
/* Do not add EOF streams */
continue;
}
- ret = heap_insert(iter->stream_heap, file_stream);
+ ret = bt_heap_insert(iter->stream_heap, file_stream);
if (ret)
goto error;
}
if (ret != 0 || !cfs)
goto error;
/* remove all streams from the heap */
- heap_free(iter->stream_heap);
+ bt_heap_free(iter->stream_heap);
/* Create a new empty heap */
- ret = heap_init(iter->stream_heap, 0, stream_compare);
+ ret = bt_heap_init(iter->stream_heap, 0, stream_compare);
if (ret < 0)
goto error;
/* Insert the stream that contains the last event */
- ret = heap_insert(iter->stream_heap, cfs);
+ ret = bt_heap_insert(iter->stream_heap, cfs);
if (ret)
goto error;
break;
return 0;
error:
- heap_free(iter->stream_heap);
+ bt_heap_free(iter->stream_heap);
error_heap_init:
- if (heap_init(iter->stream_heap, 0, stream_compare) < 0) {
- heap_free(iter->stream_heap);
+ if (bt_heap_init(iter->stream_heap, 0, stream_compare) < 0) {
+ bt_heap_free(iter->stream_heap);
g_free(iter->stream_heap);
iter->stream_heap = NULL;
ret = -ENOMEM;
if (!pos->u.restore->stream_saved_pos)
goto error;
- ret = heap_copy(&iter_heap_copy, iter->stream_heap);
+ ret = bt_heap_copy(&iter_heap_copy, iter->stream_heap);
if (ret < 0)
goto error_heap;
/* iterate over each stream in the heap */
- file_stream = heap_maximum(&iter_heap_copy);
+ file_stream = bt_heap_maximum(&iter_heap_copy);
while (file_stream != NULL) {
struct stream_saved_pos saved_pos;
saved_pos.current_real_timestamp);
/* remove the stream from the heap copy */
- removed = heap_remove(&iter_heap_copy);
+ removed = bt_heap_remove(&iter_heap_copy);
assert(removed == file_stream);
- file_stream = heap_maximum(&iter_heap_copy);
+ file_stream = bt_heap_maximum(&iter_heap_copy);
}
- heap_free(&iter_heap_copy);
+ bt_heap_free(&iter_heap_copy);
return pos;
error_heap:
bt_context_get(ctx);
iter->ctx = ctx;
- ret = heap_init(iter->stream_heap, 0, stream_compare);
+ ret = bt_heap_init(iter->stream_heap, 0, stream_compare);
if (ret < 0)
goto error_heap_init;
for (i = 0; i < ctx->tc->array->len; i++) {
struct ctf_trace *tin;
- struct trace_descriptor *td_read;
+ struct bt_trace_descriptor *td_read;
td_read = g_ptr_array_index(ctx->tc->array, i);
if (!td_read)
goto error;
}
/* Add to heap */
- ret = heap_insert(iter->stream_heap, file_stream);
+ ret = bt_heap_insert(iter->stream_heap, file_stream);
if (ret)
goto error;
}
return 0;
error:
- heap_free(iter->stream_heap);
+ bt_heap_free(iter->stream_heap);
error_heap_init:
g_free(iter->stream_heap);
iter->stream_heap = NULL;
{
assert(iter);
if (iter->stream_heap) {
- heap_free(iter->stream_heap);
+ bt_heap_free(iter->stream_heap);
g_free(iter->stream_heap);
}
iter->ctx->current_iterator = NULL;
if (!iter)
return -EINVAL;
- file_stream = heap_maximum(iter->stream_heap);
+ file_stream = bt_heap_maximum(iter->stream_heap);
if (!file_stream) {
/* end of file for all streams */
ret = 0;
ret = stream_read_event(file_stream);
if (ret == EOF) {
- removed = heap_remove(iter->stream_heap);
+ removed = bt_heap_remove(iter->stream_heap);
assert(removed == file_stream);
ret = 0;
goto end;
goto end;
}
/* Reinsert the file stream into the heap, and rebalance. */
- removed = heap_replace_max(iter->stream_heap, file_stream);
+ removed = bt_heap_replace_max(iter->stream_heap, file_stream);
assert(removed == file_stream);
end:
return 0;
}
-int heap_init(struct ptr_heap *heap, size_t alloc_len,
+int bt_heap_init(struct ptr_heap *heap, size_t alloc_len,
int gt(void *a, void *b))
{
heap->ptrs = NULL;
heap->gt = gt;
/*
* Minimum size allocated is 1 entry to ensure memory allocation
- * never fails within heap_replace_max.
+ * never fails within bt_heap_replace_max.
*/
return heap_grow(heap, max_t(size_t, 1, alloc_len));
}
-void heap_free(struct ptr_heap *heap)
+void bt_heap_free(struct ptr_heap *heap)
{
free(heap->ptrs);
}
check_heap(heap);
}
-void *heap_replace_max(struct ptr_heap *heap, void *p)
+void *bt_heap_replace_max(struct ptr_heap *heap, void *p)
{
void *res;
return res;
}
-int heap_insert(struct ptr_heap *heap, void *p)
+int bt_heap_insert(struct ptr_heap *heap, void *p)
{
void **ptrs;
size_t pos;
return 0;
}
-void *heap_remove(struct ptr_heap *heap)
+void *bt_heap_remove(struct ptr_heap *heap)
{
switch (heap->len) {
case 0:
/* Shrink, replace the current max by previous last entry and heapify */
heap_set_len(heap, heap->len - 1);
/* len changed. previous last entry is at heap->len */
- return heap_replace_max(heap, heap->ptrs[heap->len]);
+ return bt_heap_replace_max(heap, heap->ptrs[heap->len]);
}
-void *heap_cherrypick(struct ptr_heap *heap, void *p)
+void *bt_heap_cherrypick(struct ptr_heap *heap, void *p)
{
size_t pos, len = heap->len;
return p;
}
-int heap_copy(struct ptr_heap *dst, struct ptr_heap *src)
+int bt_heap_copy(struct ptr_heap *dst, struct ptr_heap *src)
{
int ret;
- ret = heap_init(dst, src->alloc_len, src->gt);
+ ret = bt_heap_init(dst, src->alloc_len, src->gt);
if (ret < 0)
goto end;
format_cleanup();
}
-struct format *bt_lookup_format(bt_intern_str name)
+struct bt_format *bt_lookup_format(bt_intern_str name)
{
if (!init_done)
return NULL;
fprintf(fp, ".\n");
}
-int bt_register_format(struct format *format)
+int bt_register_format(struct bt_format *format)
{
if (!format)
return -EINVAL;
return 0;
}
-void bt_unregister_format(struct format *format)
+void bt_unregister_format(struct bt_format *format)
{
assert(bt_lookup_format(format->name));
g_hash_table_remove(format_registry,
* correlate this trace with at least one other clock in the trace and
* convert the index from cycles to real time.
*/
-int trace_collection_add(struct trace_collection *tc,
- struct trace_descriptor *td)
+int bt_trace_collection_add(struct trace_collection *tc,
+ struct bt_trace_descriptor *trace)
{
- struct ctf_trace *trace;
-
- if (!tc || !td)
+ if (!tc || !trace)
return -EINVAL;
- trace = container_of(td, struct ctf_trace, parent);
- g_ptr_array_add(tc->array, td);
- trace->collection = tc;
-
if (tc->array->len > 1) {
struct clock_match clock_match = {
.clocks = tc->clocks,
}
}
+ g_ptr_array_add(tc->array, trace);
+ trace->collection = tc;
+
{
struct clock_match clock_match = {
.clocks = tc->clocks,
return -EPERM;
}
-int trace_collection_remove(struct trace_collection *tc,
- struct trace_descriptor *td)
+int bt_trace_collection_remove(struct trace_collection *tc,
+ struct bt_trace_descriptor *td)
{
if (!tc || !td)
return -EINVAL;
}
-void init_trace_collection(struct trace_collection *tc)
+void bt_init_trace_collection(struct trace_collection *tc)
{
assert(tc);
tc->array = g_ptr_array_new();
}
/*
- * finalize_trace_collection() closes the opened traces for read
+ * bt_finalize_trace_collection() closes the opened traces for read
* and free the memory allocated for trace collection
*/
-void finalize_trace_collection(struct trace_collection *tc)
+void bt_finalize_trace_collection(struct trace_collection *tc)
{
assert(tc);
g_ptr_array_free(tc->array, TRUE);
g_free(th);
}
-int bt_trace_handle_get_id(struct bt_trace_handle *th)
-{
- if (!th)
- return -1;
-
- return th->id;
-}
-
const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id)
{
struct bt_trace_handle *handle;
SUBDIRS = lib
-noinst_PROGRAMS = test-bitfield
-
-test_bitfield_SOURCES = test-bitfield.c
-
EXTRA_DIST = runall.sh ctf-traces/**
check-am:
--- /dev/null
+/* CTF 1.8 */
+typealias integer { size = 8; align = 8; signed = false; } := uint8_t;
+typealias integer { size = 32; align = 32; signed = false; } := uint32_t;
+
+trace {
+ /* Integer out of range */
+ major = 23452397856348975623897562893746589237465289374658923764598237645897234658723648579236;
+ minor = 1;
+ uuid = "2a6422d0-6cee-11e0-8c08-cb07d7b3a564";
+ byte_order = le;
+ packet.header := struct {
+ uint32_t magic;
+ uint8_t uuid[16];
+ };
+};
+
+stream {
+ packet.context := struct {
+ uint32_t content_size;
+ uint32_t packet_size;
+ };
+};
+
+event {
+ name = string;
+ fields := struct { string str; };
+};
--- /dev/null
+Á\1füÁ*d
\ No newline at end of file
--- /dev/null
+/* CTF 1.8 */
+typealias integer { size = 8; align = 8; signed = false; base = 10; } := uint8_t;
+typealias integer { size = 32; align = 32; signed = false; base = hex; } := uint32_t;
+
+trace {
+ major = 0;
+ minor = 1;
+ uuid = "2a6422d0-6cee-11e0-8c08-cb07d7b3a564";
+ byte_order = le;
+ packet.header := struct {
+ uint32_t magic;
+ uint8_t uuid[16];
+ };
+};
+
+event {
+ name = string;
+ fields := struct { string str; };
+};
--- /dev/null
+/* CTF 1.8 */
+typealias integer { size = 8; align = 8; signed = false; base = 10; } := uint8_t;
+typealias integer { size = 32; align = 32; signed = false; base = hex; } := uint32_t;
+
+trace {
+ major = 0;
+ minor = 1;
+ uuid = "2a6422d0-6cee-11e0-8c08-cb07d7b3a564";
+ byte_order = le;
+ packet.header := struct {
+ uint32_t magic;
+ uint8_t uuid[16];
+ };
+};
+
+event {
+ name = string;
+ fields := struct { string str; };
+};
--- /dev/null
+/* CTF 1.8 */
+typealias integer { size = 8; align = 8; signed = false; base = 10; } := uint8_t;
+typealias integer { size = 32; align = 32; signed = false; base = hex; } := uint32_t;
+
+trace {
+ major = 0;
+ minor = 1;
+ test = "\"";
+ test2 = "?\x20\o040?";
+ test3 = '\n';
+ uuid = "2a6422d0-6cee-11e0-8c08-cb07d7b3a564";
+ byte_order = le;
+ packet.header := struct {
+ uint32_t magic;
+ uint8_t uuid[16];
+ };
+};
+
+stream {
+ packet.context := struct {
+ uint32_t content_size;
+ uint32_t packet_size;
+ };
+};
+
+event {
+ name = string;
+ fields := struct { string str; };
+};
--- /dev/null
+/* CTF 1.8 */
+typealias integer { size = 8; align = 8; signed = false; } := uint8_t;
+typealias integer { size = 32; align = 32; signed = false; } := uint32_t;
+
+trace {
+ major = 0;
+ minor = 1;
+ test = 0xABC234; /* hexadecimal */
+ test1 = 06534; /* octal */
+ test2 = 1234; /* decimal */
+ test3 = +1234; /* decimal with + unary op */
+ test4 = -1234; /* decimal (negated) */
+ uuid = "2a6422d0-6cee-11e0-8c08-cb07d7b3a564";
+ byte_order = le;
+ packet.header := struct {
+ uint32_t magic;
+ uint8_t uuid[16];
+ };
+};
+
+stream {
+ packet.context := struct {
+ uint32_t content_size;
+ uint32_t packet_size;
+ };
+};
+
+event {
+ name = string;
+ fields := struct { string str; };
+};
$(top_builddir)/lib/libbabeltrace.la \
$(top_builddir)/formats/ctf/libbabeltrace-ctf.la
-noinst_PROGRAMS = test-seeks
+test_bitfield_LDADD = libtestcommon.a
+
+noinst_PROGRAMS = test-seeks test-bitfield
test_seeks_SOURCES = test-seeks.c
+test_bitfield_SOURCES = test-bitfield.c
EXTRA_DIST = README.tap runall.sh
# With a trace than contains empty packets
./test-seeks ../ctf-traces/succeed/wk-heartbeat-u/ 1351532897586558519 1351532897591331194
# With a bigger trace
-./test-seeks ../ctf-traces/succeed/lttng-modules-2.0-pre5/ 61334174524234 61336381998396
\ No newline at end of file
+./test-seeks ../ctf-traces/succeed/lttng-modules-2.0-pre5/ 61334174524234 61336381998396
+
+# run bitfield tests
+./test-bitfield
--- /dev/null
+/*
+ * test-bitfield.c
+ *
+ * BabelTrace - bitfield test program
+ *
+ * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; under version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define _GNU_SOURCE
+#include <babeltrace/bitfield.h>
+#include <time.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "tap.h"
+
+unsigned int glob;
+
+/*
+ * This function is only declared to show the size of a bitfield write in
+ * objdump.
+ */
+void fct(void)
+{
+ bt_bitfield_write(&glob, unsigned int, 12, 15, 0x12345678);
+}
+
+/* Test array size, in bytes */
+#define TEST_LEN 128
+#define NR_TESTS 10
+#define SIGNED_TEST_DESC_FMT_STR "Writing and reading back 0x%X, signed"
+#define UNSIGNED_TEST_DESC_FMT_STR "Writing and reading back 0x%X, unsigned"
+#define DIAG_FMT_STR "Failed reading value written \"%s\"-wise, with start=%i" \
+ " and length=%i. Read %llX"
+
+unsigned int srcrand;
+
+#if defined(__i386) || defined(__x86_64)
+
+static inline int fls(int x)
+{
+ int r;
+ asm("bsrl %1,%0\n\t"
+ "cmovzl %2,%0"
+ : "=&r" (r) : "rm" (x), "rm" (-1));
+ return r + 1;
+}
+
+#elif defined(__PPC__)
+
+static __inline__ int fls(unsigned int x)
+{
+ int lz;
+
+ asm ("cntlzw %0,%1" : "=r" (lz) : "r" (x));
+ return 32 - lz;
+}
+
+#else
+
+static int fls(unsigned int x)
+{
+ int r = 32;
+
+ if (!x)
+ return 0;
+ if (!(x & 0xFFFF0000U)) {
+ x <<= 16;
+ r -= 16;
+ }
+ if (!(x & 0xFF000000U)) {
+ x <<= 8;
+ r -= 8;
+ }
+ if (!(x & 0xF0000000U)) {
+ x <<= 4;
+ r -= 4;
+ }
+ if (!(x & 0xC0000000U)) {
+ x <<= 2;
+ r -= 2;
+ }
+ if (!(x & 0x80000000U)) {
+ x <<= 1;
+ r -= 1;
+ }
+ return r;
+}
+
+#endif
+
+#define print_byte_array(c, len) \
+do { \
+ unsigned long i; \
+ \
+ for (i = 0; i < (len); i++) { \
+ printf("0x%X", (c)[i]); \
+ if (i != (len) - 1) \
+ printf(" "); \
+ } \
+ printf("\n"); \
+} while (0)
+
+#define init_byte_array(c, len, val) \
+do { \
+ unsigned long i; \
+ \
+ for (i = 0; i < (len); i++) \
+ (c)[i] = (val); \
+} while (0)
+
+#define check_result(ref, val, buffer, typename, start, len, \
+ desc_fmt_str) \
+({ \
+ if ((val) != (ref)) { \
+ fail(desc_fmt_str, ref); \
+ diag(DIAG_FMT_STR, #typename, start, len, val); \
+ printf("# "); \
+ print_byte_array(buffer, TEST_LEN); \
+ } \
+ (val) != (ref); \
+})
+
+void run_test_unsigned(void)
+{
+ unsigned int src, nrbits;
+ union {
+ unsigned char c[TEST_LEN];
+ unsigned short s[TEST_LEN/sizeof(unsigned short)];
+ unsigned int i[TEST_LEN/sizeof(unsigned int)];
+ unsigned long l[TEST_LEN/sizeof(unsigned long)];
+ unsigned long long ll[TEST_LEN/sizeof(unsigned long long)];
+ } target;
+ unsigned long long readval;
+ unsigned int s, l;
+
+ src = srcrand;
+ nrbits = fls(src);
+
+ for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
+ for (l = nrbits; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+ init_byte_array(target.c, TEST_LEN, 0xFF);
+ bt_bitfield_write(target.c, unsigned char, s, l, src);
+ bt_bitfield_read(target.c, unsigned char, s, l, &readval);
+ if (check_result(src, readval, target.c, unsigned char,
+ s, l, UNSIGNED_TEST_DESC_FMT_STR)) {
+ return;
+ }
+
+ init_byte_array(target.c, TEST_LEN, 0xFF);
+ bt_bitfield_write(target.s, unsigned short, s, l, src);
+ bt_bitfield_read(target.c, unsigned char, s, l, &readval);
+ if (check_result(src, readval, target.c, unsigned short,
+ s, l, UNSIGNED_TEST_DESC_FMT_STR)) {
+ return;
+ }
+
+ init_byte_array(target.c, TEST_LEN, 0xFF);
+ bt_bitfield_write(target.i, unsigned int, s, l, src);
+ bt_bitfield_read(target.c, unsigned char, s, l, &readval);
+ if (check_result(src, readval, target.c, unsigned int,
+ s, l, UNSIGNED_TEST_DESC_FMT_STR)) {
+ return;
+ }
+
+ init_byte_array(target.c, TEST_LEN, 0xFF);
+ bt_bitfield_write(target.l, unsigned long, s, l, src);
+ bt_bitfield_read(target.c, unsigned char, s, l, &readval);
+ if (check_result(src, readval, target.c, unsigned long,
+ s, l, UNSIGNED_TEST_DESC_FMT_STR)) {
+ return;
+ }
+
+ init_byte_array(target.c, TEST_LEN, 0xFF);
+ bt_bitfield_write(target.ll, unsigned long long, s, l, src);
+ bt_bitfield_read(target.c, unsigned char, s, l, &readval);
+ if (check_result(src, readval, target.c, unsigned long long,
+ s, l, UNSIGNED_TEST_DESC_FMT_STR)) {
+ return;
+ }
+ }
+ }
+
+ pass(UNSIGNED_TEST_DESC_FMT_STR, src);
+}
+
+void run_test_signed(void)
+{
+ int src, nrbits;
+ union {
+ signed char c[TEST_LEN];
+ short s[TEST_LEN/sizeof(short)];
+ int i[TEST_LEN/sizeof(int)];
+ long l[TEST_LEN/sizeof(long)];
+ long long ll[TEST_LEN/sizeof(long long)];
+ } target;
+ long long readval;
+ unsigned int s, l;
+
+ src = srcrand;
+ if (src & 0x80000000U)
+ nrbits = fls(~src) + 1; /* Find least significant bit conveying sign */
+ else
+ nrbits = fls(src) + 1; /* Keep sign at 0 */
+
+ for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
+ for (l = nrbits; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+ init_byte_array(target.c, TEST_LEN, 0x0);
+ bt_bitfield_write(target.c, signed char, s, l, src);
+ bt_bitfield_read(target.c, signed char, s, l, &readval);
+ if (check_result(src, readval, target.c, signed char,
+ s, l, SIGNED_TEST_DESC_FMT_STR)) {
+ return;
+ }
+
+ init_byte_array(target.c, TEST_LEN, 0x0);
+ bt_bitfield_write(target.s, short, s, l, src);
+ bt_bitfield_read(target.c, signed char, s, l, &readval);
+ if (check_result(src, readval, target.c, short,
+ s, l, SIGNED_TEST_DESC_FMT_STR)) {
+ return;
+ }
+
+ init_byte_array(target.c, TEST_LEN, 0x0);
+ bt_bitfield_write(target.i, int, s, l, src);
+ bt_bitfield_read(target.c, signed char, s, l, &readval);
+ if (check_result(src, readval, target.c, int,
+ s, l, SIGNED_TEST_DESC_FMT_STR)) {
+ return;
+ }
+
+ init_byte_array(target.c, TEST_LEN, 0x0);
+ bt_bitfield_write(target.l, long, s, l, src);
+ bt_bitfield_read(target.c, signed char, s, l, &readval);
+ if (check_result(src, readval, target.c, long,
+ s, l, SIGNED_TEST_DESC_FMT_STR)) {
+ return;
+ }
+
+ init_byte_array(target.c, TEST_LEN, 0x0);
+ bt_bitfield_write(target.ll, long long, s, l, src);
+ bt_bitfield_read(target.c, signed char, s, l, &readval);
+ if (check_result(src, readval, target.c, long long,
+ s, l, SIGNED_TEST_DESC_FMT_STR)) {
+ return;
+ }
+ }
+ }
+
+ pass(SIGNED_TEST_DESC_FMT_STR, src);
+}
+
+void run_test(void)
+{
+ int i;
+ plan_tests(NR_TESTS * 2 + 6);
+
+ srand(time(NULL));
+
+ srcrand = 0;
+ run_test_unsigned();
+ srcrand = 0;
+ run_test_signed();
+
+ srcrand = 1;
+ run_test_unsigned();
+
+ srcrand = ~0U;
+ run_test_unsigned();
+
+ srcrand = -1;
+ run_test_signed();
+
+ srcrand = (int)0x80000000U;
+ run_test_signed();
+
+ for (i = 0; i < NR_TESTS; i++) {
+ srcrand = rand();
+ run_test_unsigned();
+ run_test_signed();
+ }
+}
+
+static
+int print_encodings(unsigned long src, unsigned int shift, unsigned int len)
+{
+ union {
+ unsigned char c[8];
+ unsigned short s[4];
+ unsigned int i[2];
+ unsigned long l[2];
+ unsigned long long ll[1];
+ } target;
+ unsigned long long readval;
+
+ init_byte_array(target.c, 8, 0xFF);
+ bt_bitfield_write(target.c, unsigned char, shift, len, src);
+ printf("bytewise\n");
+ print_byte_array(target.c, 8);
+
+ init_byte_array(target.c, 8, 0xFF);
+ bt_bitfield_write(target.s, unsigned short, shift, len, src);
+ printf("shortwise\n");
+ print_byte_array(target.c, 8);
+
+ init_byte_array(target.c, 8, 0xFF);
+ bt_bitfield_write(target.i, unsigned int, shift, len, src);
+ printf("intwise\n");
+ print_byte_array(target.c, 8);
+
+ init_byte_array(target.c, 8, 0xFF);
+ bt_bitfield_write(target.l, unsigned long, shift, len, src);
+ printf("longwise\n");
+ print_byte_array(target.c, 8);
+
+ init_byte_array(target.c, 8, 0xFF);
+ bt_bitfield_write(target.ll, unsigned long long, shift, len, src);
+ printf("lluwise\n");
+ print_byte_array(target.c, 8);
+
+ bt_bitfield_read(target.c, unsigned char, shift, len, &readval);
+ printf("read: %llX\n", readval);
+ print_byte_array(target.c, 8);
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ if (argc > 1) {
+ /* Print encodings */
+ unsigned long src;
+ unsigned int shift, len;
+
+ src = atoi(argv[1]);
+ if (argc > 2)
+ shift = atoi(argv[2]);
+ else
+ shift = 12;
+ if (argc > 3)
+ len = atoi(argv[3]);
+ else
+ len = 40;
+ return print_encodings(src, shift, len);
+ }
+
+ /* Run tap-formated tests */
+ run_test();
+ return exit_status();
+}
#include "common.h"
#include "tap.h"
-#define NR_TESTS 23
+#define NR_TESTS 29
void run_seek_begin(char *path, uint64_t expected_begin)
{
bt_context_put(ctx);
}
+void run_seek_time_at_last(char *path, uint64_t expected_last)
+{
+ struct bt_context *ctx;
+ struct bt_ctf_iter *iter;
+ struct bt_ctf_event *event;
+ struct bt_iter_pos newpos;
+ int ret;
+ uint64_t timestamp_last;
+
+ /* Open the trace */
+ ctx = create_context_with_path(path);
+ if (!ctx) {
+ plan_skip_all("Cannot create valid context");
+ }
+
+ /* Create iterator with null last and end */
+ iter = bt_ctf_iter_create(ctx, NULL, NULL);
+ if (!iter) {
+ plan_skip_all("Cannot create valid iterator");
+ }
+
+ event = bt_ctf_iter_read_event(iter);
+
+ ok(event, "Event valid at beginning");
+
+ /* Seek to last */
+ newpos.type = BT_SEEK_TIME;
+ newpos.u.seek_time = expected_last;
+ ret = bt_iter_set_pos(bt_ctf_get_iter(iter), &newpos);
+
+ ok(ret == 0, "Seek time at last retval %d", ret);
+
+ event = bt_ctf_iter_read_event(iter);
+
+ ok(event, "Event valid at last position");
+
+ timestamp_last = bt_ctf_get_timestamp(event);
+
+ ok1(timestamp_last == expected_last);
+
+ /* Try to read next event */
+ ret = bt_iter_next(bt_ctf_get_iter(iter));
+
+ ok(ret == 0, "iter next should return an error");
+
+ event = bt_ctf_iter_read_event(iter);
+
+ ok(event == 0, "Event after last should be invalid");
+
+ bt_context_put(ctx);
+}
+
void run_seek_cycles(char *path,
uint64_t expected_begin,
uint64_t expected_last)
}
run_seek_begin(path, expected_begin);
+ run_seek_time_at_last(path, expected_last);
run_seek_last(path, expected_last);
run_seek_cycles(path, expected_begin, expected_last);
BABELTRACE_BIN=${DIR}/../converter/babeltrace
CTF_TRACES=${DIR}/ctf-traces
-function print_ok ()
-{
- # Check if we are a terminal
- if [ -t 1 ]; then
- echo -e "\e[1;32mOK\e[0m"
- else
- echo -e "OK"
- fi
-}
-
-function print_fail ()
-{
- # Check if we are a terminal
- if [ -t 1 ]; then
- echo -e "\e[1;31mFAIL\e[0m"
- else
- echo -e "FAIL"
- fi
-}
-
-function test_check ()
+function test_check_success ()
{
if [ $? -ne 0 ] ; then
- print_fail
return 1
else
- print_ok
return 0
fi
}
function test_check_fail ()
{
- if [ $? -ne 1 ] ; then
- print_fail
+ if [ $? -eq 0 ] ; then
return 1
else
- print_ok
return 0
fi
}
return $?
}
-echo -e "Running test-bitfield..."
-./test-bitfield
-test_check
-if [ $? -ne 0 ]; then
- exit 1
-fi
-
-#run babeltrace expects success
-echo -e "Running babeltrace without argument..."
-run_babeltrace
-test_check
-if [ $? -ne 0 ]; then
- exit 1
-fi
-
-for a in ${CTF_TRACES}/succeed/*; do
- echo -e "Running babeltrace for trace ${a}..."
- run_babeltrace ${a}
- test_check
- if [ $? -ne 0 ]; then
+function print_test_result ()
+{
+ if [ $# -ne 3 ] ; then
+ echo "Invalid arguments provided"
exit 1
fi
-done
-#run babeltrace expects failure
-echo -e "Running babeltrace with bogus argument..."
+ if [ ${2} -eq 0 ] ; then
+ echo -n "ok"
+ else
+ echo -n "not ok"
+ fi
+ echo -e " "${1}" - "${3}
+}
+
+successTraces=(${CTF_TRACES}/succeed/*)
+failTraces=(${CTF_TRACES}/fail/*)
+testCount=$((2 + ${#successTraces[@]} + ${#failTraces[@]}))
+
+currentTestIndex=1
+echo -e 1..${testCount}
+
+#run babeltrace, expects success
+run_babeltrace
+test_check_success
+print_test_result $((currentTestIndex++)) $? "Running babeltrace without arguments"
+
+#run babeltrace with a bogus argument, expects failure
run_babeltrace --bogusarg
test_check_fail
-if [ $? -ne 0 ]; then
- exit 1
-fi
+print_test_result $((currentTestIndex++)) $? "Running babeltrace with a bogus argument"
+
+for tracePath in ${successTraces[@]}; do
+ run_babeltrace ${tracePath}
+ test_check_success
+ print_test_result $((currentTestIndex++)) $? "Running babeltrace with trace ${tracePath}"
+done
-for a in ${CTF_TRACES}/fail/*; do
- echo -e "Running babeltrace for trace ${a}..."
- run_babeltrace ${a}
+for tracePath in ${failTraces[@]}; do
+ run_babeltrace ${tracePath}
test_check_fail
- if [ $? -ne 0 ]; then
- exit 1
- fi
+ print_test_result $((currentTestIndex++)) $? "Running babeltrace with trace ${tracePath}"
done
exit 0
+++ /dev/null
-/*
- * test-bitfield.c
- *
- * BabelTrace - bitfield test program
- *
- * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; under version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#define _GNU_SOURCE
-#include <babeltrace/bitfield.h>
-#include <time.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-unsigned int glob;
-
-/*
- * This function is only declared to show the size of a bitfield write in
- * objdump.
- */
-void fct(void)
-{
- bt_bitfield_write(&glob, unsigned int, 12, 15, 0x12345678);
-}
-
-/* Test array size, in bytes */
-#define TEST_LEN 128
-#define NR_TESTS 10
-
-unsigned int srcrand;
-
-#if defined(__i386) || defined(__x86_64)
-
-static inline int fls(int x)
-{
- int r;
- asm("bsrl %1,%0\n\t"
- "cmovzl %2,%0"
- : "=&r" (r) : "rm" (x), "rm" (-1));
- return r + 1;
-}
-
-#elif defined(__PPC__)
-
-static __inline__ int fls(unsigned int x)
-{
- int lz;
-
- asm ("cntlzw %0,%1" : "=r" (lz) : "r" (x));
- return 32 - lz;
-}
-
-#else
-
-static int fls(unsigned int x)
-{
- int r = 32;
-
- if (!x)
- return 0;
- if (!(x & 0xFFFF0000U)) {
- x <<= 16;
- r -= 16;
- }
- if (!(x & 0xFF000000U)) {
- x <<= 8;
- r -= 8;
- }
- if (!(x & 0xF0000000U)) {
- x <<= 4;
- r -= 4;
- }
- if (!(x & 0xC0000000U)) {
- x <<= 2;
- r -= 2;
- }
- if (!(x & 0x80000000U)) {
- x <<= 1;
- r -= 1;
- }
- return r;
-}
-
-#endif
-
-#define print_byte_array(c, len) \
-do { \
- unsigned long i; \
- \
- for (i = 0; i < (len); i++) { \
- printf("0x%X", (c)[i]); \
- if (i != (len) - 1) \
- printf(" "); \
- } \
- printf("\n"); \
-} while (0)
-
-#define init_byte_array(c, len, val) \
-do { \
- unsigned long i; \
- \
- for (i = 0; i < (len); i++) \
- (c)[i] = (val); \
-} while (0)
-
-int run_test_unsigned(void)
-{
- unsigned int src, nrbits;
- union {
- unsigned char c[TEST_LEN];
- unsigned short s[TEST_LEN/sizeof(unsigned short)];
- unsigned int i[TEST_LEN/sizeof(unsigned int)];
- unsigned long l[TEST_LEN/sizeof(unsigned long)];
- unsigned long long ll[TEST_LEN/sizeof(unsigned long long)];
- } target;
- unsigned long long readval;
- unsigned int s, l;
- int err = 0;
-
- printf("Running unsigned test with 0x%X\n", srcrand);
-
- src = srcrand;
- nrbits = fls(src);
-
- for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
- for (l = nrbits; l < (CHAR_BIT * TEST_LEN) - s; l++) {
- init_byte_array(target.c, TEST_LEN, 0xFF);
- bt_bitfield_write(target.c, unsigned char, s, l, src);
- bt_bitfield_read(target.c, unsigned char, s, l, &readval);
- if (readval != src) {
- printf("Error (bytewise) src %X read %llX shift %d len %d\n",
- src, readval, s, l);
- print_byte_array(target.c, TEST_LEN);
- err = 1;
- }
-
- init_byte_array(target.c, TEST_LEN, 0xFF);
- bt_bitfield_write(target.s, unsigned short, s, l, src);
- bt_bitfield_read(target.c, unsigned char, s, l, &readval);
- if (readval != src) {
- printf("Error (shortwise) src %X read %llX shift %d len %d\n",
- src, readval, s, l);
- print_byte_array(target.c, TEST_LEN);
- err = 1;
- }
-
- init_byte_array(target.c, TEST_LEN, 0xFF);
- bt_bitfield_write(target.i, unsigned int, s, l, src);
- bt_bitfield_read(target.c, unsigned char, s, l, &readval);
- if (readval != src) {
- printf("Error (intwise) src %X read %llX shift %d len %d\n",
- src, readval, s, l);
- print_byte_array(target.c, TEST_LEN);
- err = 1;
- }
-
- init_byte_array(target.c, TEST_LEN, 0xFF);
- bt_bitfield_write(target.l, unsigned long, s, l, src);
- bt_bitfield_read(target.c, unsigned char, s, l, &readval);
- if (readval != src) {
- printf("Error (longwise) src %X read %llX shift %d len %d\n",
- src, readval, s, l);
- print_byte_array(target.c, TEST_LEN);
- err = 1;
- }
-
- init_byte_array(target.c, TEST_LEN, 0xFF);
- bt_bitfield_write(target.ll, unsigned long long, s, l, src);
- bt_bitfield_read(target.c, unsigned char, s, l, &readval);
- if (readval != src) {
- printf("Error (longlongwise) src %X read %llX shift %d len %d\n",
- src, readval, s, l);
- print_byte_array(target.c, TEST_LEN);
- err = 1;
- }
- }
- }
- if (!err)
- printf("Success!\n");
- else
- printf("Failed!\n");
- return err;
-}
-
-int run_test_signed(void)
-{
- int src, nrbits;
- union {
- signed char c[TEST_LEN];
- short s[TEST_LEN/sizeof(short)];
- int i[TEST_LEN/sizeof(int)];
- long l[TEST_LEN/sizeof(long)];
- long long ll[TEST_LEN/sizeof(long long)];
- } target;
- long long readval;
- unsigned int s, l;
- int err = 0;
-
- printf("Running signed test with 0x%X\n", srcrand);
-
- src = srcrand;
- if (src & 0x80000000U)
- nrbits = fls(~src) + 1; /* Find least significant bit conveying sign */
- else
- nrbits = fls(src) + 1; /* Keep sign at 0 */
-
- for (s = 0; s < 8 * TEST_LEN; s++) {
- for (l = nrbits; l < (8 * TEST_LEN) - s; l++) {
- init_byte_array(target.c, TEST_LEN, 0x0);
- bt_bitfield_write(target.c, signed char, s, l, src);
- bt_bitfield_read(target.c, signed char, s, l, &readval);
- if (readval != src) {
- printf("Error (bytewise) src %X read %llX shift %d len %d\n",
- src, readval, s, l);
- print_byte_array(target.c, TEST_LEN);
- err = 1;
- }
-
- init_byte_array(target.c, TEST_LEN, 0x0);
- bt_bitfield_write(target.s, short, s, l, src);
- bt_bitfield_read(target.c, signed char, s, l, &readval);
- if (readval != src) {
- printf("Error (shortwise) src %X read %llX shift %d len %d\n",
- src, readval, s, l);
- print_byte_array(target.c, TEST_LEN);
- err = 1;
- }
-
- init_byte_array(target.c, TEST_LEN, 0x0);
- bt_bitfield_write(target.i, int, s, l, src);
- bt_bitfield_read(target.c, signed char, s, l, &readval);
- if (readval != src) {
- printf("Error (intwise) src %X read %llX shift %d len %d\n",
- src, readval, s, l);
- print_byte_array(target.c, TEST_LEN);
- err = 1;
- }
-
- init_byte_array(target.c, TEST_LEN, 0x0);
- bt_bitfield_write(target.l, long, s, l, src);
- bt_bitfield_read(target.c, signed char, s, l, &readval);
- if (readval != src) {
- printf("Error (longwise) src %X read %llX shift %d len %d\n",
- src, readval, s, l);
- print_byte_array(target.c, TEST_LEN);
- err = 1;
- }
-
- init_byte_array(target.c, TEST_LEN, 0x0);
- bt_bitfield_write(target.ll, long long, s, l, src);
- bt_bitfield_read(target.c, signed char, s, l, &readval);
- if (readval != src) {
- printf("Error (longlongwise) src %X read %llX shift %d len %d\n",
- src, readval, s, l);
- print_byte_array(target.c, TEST_LEN);
- err = 1;
- }
- }
- }
- if (!err)
- printf("Success!\n");
- else
- printf("Failed!\n");
- return err;
-}
-
-int run_test(void)
-{
- int err = 0;
- int i;
-
- srand(time(NULL));
-
- srcrand = 0;
- err |= run_test_unsigned();
- srcrand = 0;
- err |= run_test_signed();
- srcrand = 1;
- err |= run_test_unsigned();
- srcrand = ~0U;
- err |= run_test_unsigned();
- srcrand = -1;
- err |= run_test_signed();
- srcrand = (int)0x80000000U;
- err |= run_test_signed();
-
- for (i = 0; i < NR_TESTS; i++) {
- srcrand = rand();
- err |= run_test_unsigned();
- err |= run_test_signed();
- }
- return err;
-}
-
-int main(int argc, char **argv)
-{
- unsigned long src;
- unsigned int shift, len;
- int ret;
- union {
- unsigned char c[8];
- unsigned short s[4];
- unsigned int i[2];
- unsigned long l[2];
- unsigned long long ll[1];
- } target;
- unsigned long long readval;
-
- if (argc > 1)
- src = atoi(argv[1]);
- else
- src = 0x12345678;
- if (argc > 2)
- shift = atoi(argv[2]);
- else
- shift = 12;
- if (argc > 3)
- len = atoi(argv[3]);
- else
- len = 40;
-
- target.i[0] = 0xFFFFFFFF;
- target.i[1] = 0xFFFFFFFF;
- bt_bitfield_write(target.c, unsigned char, shift, len, src);
- printf("bytewise\n");
- print_byte_array(target.c, 8);
-
- target.i[0] = 0xFFFFFFFF;
- target.i[1] = 0xFFFFFFFF;
- bt_bitfield_write(target.s, unsigned short, shift, len, src);
- printf("shortwise\n");
- print_byte_array(target.c, 8);
-
- target.i[0] = 0xFFFFFFFF;
- target.i[1] = 0xFFFFFFFF;
- bt_bitfield_write(target.i, unsigned int, shift, len, src);
- printf("intwise\n");
- print_byte_array(target.c, 8);
-
- target.i[0] = 0xFFFFFFFF;
- target.i[1] = 0xFFFFFFFF;
- bt_bitfield_write(target.l, unsigned long, shift, len, src);
- printf("longwise\n");
- print_byte_array(target.c, 8);
-
- target.i[0] = 0xFFFFFFFF;
- target.i[1] = 0xFFFFFFFF;
- bt_bitfield_write(target.ll, unsigned long long, shift, len, src);
- printf("lluwise\n");
- print_byte_array(target.c, 8);
-
- bt_bitfield_read(target.c, unsigned char, shift, len, &readval);
- printf("read: %llX\n", readval);
-
- ret = run_test();
-
- return ret;
-}
#include <inttypes.h>
static
-struct definition *_array_definition_new(struct declaration *declaration,
+struct bt_definition *_array_definition_new(struct bt_declaration *declaration,
struct definition_scope *parent_scope,
GQuark field_name, int index, const char *root_name);
static
-void _array_definition_free(struct definition *definition);
+void _array_definition_free(struct bt_definition *definition);
-int array_rw(struct stream_pos *pos, struct definition *definition)
+int bt_array_rw(struct bt_stream_pos *pos, struct bt_definition *definition)
{
struct definition_array *array_definition =
container_of(definition, struct definition_array, p);
/* No need to align, because the first field will align itself. */
for (i = 0; i < array_declaration->len; i++) {
- struct definition *field =
+ struct bt_definition *field =
g_ptr_array_index(array_definition->elems, i);
ret = generic_rw(pos, field);
if (ret)
}
static
-void _array_declaration_free(struct declaration *declaration)
+void _array_declaration_free(struct bt_declaration *declaration)
{
struct declaration_array *array_declaration =
container_of(declaration, struct declaration_array, p);
- free_declaration_scope(array_declaration->scope);
- declaration_unref(array_declaration->elem);
+ bt_free_declaration_scope(array_declaration->scope);
+ bt_declaration_unref(array_declaration->elem);
g_free(array_declaration);
}
struct declaration_array *
- array_declaration_new(size_t len,
- struct declaration *elem_declaration,
+ bt_array_declaration_new(size_t len,
+ struct bt_declaration *elem_declaration,
struct declaration_scope *parent_scope)
{
struct declaration_array *array_declaration;
- struct declaration *declaration;
+ struct bt_declaration *declaration;
array_declaration = g_new(struct declaration_array, 1);
declaration = &array_declaration->p;
array_declaration->len = len;
- declaration_ref(elem_declaration);
+ bt_declaration_ref(elem_declaration);
array_declaration->elem = elem_declaration;
- array_declaration->scope = new_declaration_scope(parent_scope);
+ array_declaration->scope = bt_new_declaration_scope(parent_scope);
declaration->id = CTF_TYPE_ARRAY;
declaration->alignment = elem_declaration->alignment;
declaration->declaration_free = _array_declaration_free;
}
static
-struct definition *
- _array_definition_new(struct declaration *declaration,
+struct bt_definition *
+ _array_definition_new(struct bt_declaration *declaration,
struct definition_scope *parent_scope,
GQuark field_name, int index, const char *root_name)
{
int i;
array = g_new(struct definition_array, 1);
- declaration_ref(&array_declaration->p);
+ bt_declaration_ref(&array_declaration->p);
array->p.declaration = declaration;
array->declaration = array_declaration;
array->p.ref = 1;
*/
array->p.index = root_name ? INT_MAX : index;
array->p.name = field_name;
- array->p.path = new_definition_path(parent_scope, field_name, root_name);
- array->p.scope = new_definition_scope(parent_scope, field_name, root_name);
- ret = register_field_definition(field_name, &array->p,
+ array->p.path = bt_new_definition_path(parent_scope, field_name, root_name);
+ array->p.scope = bt_new_definition_scope(parent_scope, field_name, root_name);
+ ret = bt_register_field_definition(field_name, &array->p,
parent_scope);
assert(!ret);
array->string = NULL;
array->elems = g_ptr_array_sized_new(array_declaration->len);
g_ptr_array_set_size(array->elems, array_declaration->len);
for (i = 0; i < array_declaration->len; i++) {
- struct definition **field;
+ struct bt_definition **field;
GString *str;
GQuark name;
name = g_quark_from_string(str->str);
(void) g_string_free(str, TRUE);
- field = (struct definition **) &g_ptr_array_index(array->elems, i);
+ field = (struct bt_definition **) &g_ptr_array_index(array->elems, i);
*field = array_declaration->elem->definition_new(array_declaration->elem,
array->p.scope,
name, i, NULL);
error:
for (i--; i >= 0; i--) {
- struct definition *field;
+ struct bt_definition *field;
field = g_ptr_array_index(array->elems, i);
field->declaration->definition_free(field);
}
(void) g_ptr_array_free(array->elems, TRUE);
- free_definition_scope(array->p.scope);
- declaration_unref(array->p.declaration);
+ bt_free_definition_scope(array->p.scope);
+ bt_declaration_unref(array->p.declaration);
g_free(array);
return NULL;
}
static
-void _array_definition_free(struct definition *definition)
+void _array_definition_free(struct bt_definition *definition)
{
struct definition_array *array =
container_of(definition, struct definition_array, p);
(void) g_string_free(array->string, TRUE);
if (array->elems) {
for (i = 0; i < array->elems->len; i++) {
- struct definition *field;
+ struct bt_definition *field;
field = g_ptr_array_index(array->elems, i);
field->declaration->definition_free(field);
}
(void) g_ptr_array_free(array->elems, TRUE);
}
- free_definition_scope(array->p.scope);
- declaration_unref(array->p.declaration);
+ bt_free_definition_scope(array->p.scope);
+ bt_declaration_unref(array->p.declaration);
g_free(array);
}
-uint64_t array_len(struct definition_array *array)
+uint64_t bt_array_len(struct definition_array *array)
{
if (!array->elems)
return array->string->len;
return array->elems->len;
}
-struct definition *array_index(struct definition_array *array, uint64_t i)
+struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i)
{
if (!array->elems)
return NULL;
return g_ptr_array_index(array->elems, i);
}
-int get_array_len(const struct definition *field)
+int bt_get_array_len(const struct bt_definition *field)
{
struct definition_array *array_definition;
struct declaration_array *array_declaration;
return array_declaration->len;
}
-GString *get_char_array(const struct definition *field)
+GString *bt_get_char_array(const struct bt_definition *field)
{
struct definition_array *array_definition;
struct declaration_array *array_declaration;
- struct declaration *elem;
+ struct bt_declaration *elem;
array_definition = container_of(field, struct definition_array, p);
array_declaration = array_definition->declaration;
#endif
static
-struct definition *_enum_definition_new(struct declaration *declaration,
+struct bt_definition *_enum_definition_new(struct bt_declaration *declaration,
struct definition_scope *parent_scope,
GQuark field_name, int index,
const char *root_name);
static
-void _enum_definition_free(struct definition *definition);
+void _enum_definition_free(struct bt_definition *definition);
static
void enum_range_set_free(void *ptr)
* Returns a GArray or NULL.
* Caller must release the GArray with g_array_unref().
*/
-GArray *enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
+GArray *bt_enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
uint64_t v)
{
struct enum_range_to_quark *iter;
* Returns a GArray or NULL.
* Caller must release the GArray with g_array_unref().
*/
-GArray *enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
+GArray *bt_enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
int64_t v)
{
struct enum_range_to_quark *iter;
}
static
-void enum_unsigned_insert_value_to_quark_set(struct declaration_enum *enum_declaration,
+void bt_enum_unsigned_insert_value_to_quark_set(struct declaration_enum *enum_declaration,
uint64_t v, GQuark q)
{
uint64_t *valuep;
}
static
-void enum_signed_insert_value_to_quark_set(struct declaration_enum *enum_declaration,
+void bt_enum_signed_insert_value_to_quark_set(struct declaration_enum *enum_declaration,
int64_t v, GQuark q)
{
int64_t *valuep;
}
}
-GArray *enum_quark_to_range_set(const struct declaration_enum *enum_declaration,
+GArray *bt_enum_quark_to_range_set(const struct declaration_enum *enum_declaration,
GQuark q)
{
return g_hash_table_lookup(enum_declaration->table.quark_to_range_set,
}
static
-void enum_signed_insert_range_to_quark(struct declaration_enum *enum_declaration,
+void bt_enum_signed_insert_range_to_quark(struct declaration_enum *enum_declaration,
int64_t start, int64_t end, GQuark q)
{
struct enum_range_to_quark *rtoq;
}
static
-void enum_unsigned_insert_range_to_quark(struct declaration_enum *enum_declaration,
+void bt_enum_unsigned_insert_range_to_quark(struct declaration_enum *enum_declaration,
uint64_t start, uint64_t end, GQuark q)
{
struct enum_range_to_quark *rtoq;
rtoq->quark = q;
}
-void enum_signed_insert(struct declaration_enum *enum_declaration,
+void bt_enum_signed_insert(struct declaration_enum *enum_declaration,
int64_t start, int64_t end, GQuark q)
{
GArray *array;
struct enum_range *range;
if (start == end) {
- enum_signed_insert_value_to_quark_set(enum_declaration, start, q);
+ bt_enum_signed_insert_value_to_quark_set(enum_declaration, start, q);
} else {
if (start > end) {
uint64_t tmp;
start = end;
end = tmp;
}
- enum_signed_insert_range_to_quark(enum_declaration, start, end, q);
+ bt_enum_signed_insert_range_to_quark(enum_declaration, start, end, q);
}
array = g_hash_table_lookup(enum_declaration->table.quark_to_range_set,
range->end._signed = end;
}
-void enum_unsigned_insert(struct declaration_enum *enum_declaration,
+void bt_enum_unsigned_insert(struct declaration_enum *enum_declaration,
uint64_t start, uint64_t end, GQuark q)
{
GArray *array;
if (start == end) {
- enum_unsigned_insert_value_to_quark_set(enum_declaration, start, q);
+ bt_enum_unsigned_insert_value_to_quark_set(enum_declaration, start, q);
} else {
if (start > end) {
uint64_t tmp;
start = end;
end = tmp;
}
- enum_unsigned_insert_range_to_quark(enum_declaration, start, end, q);
+ bt_enum_unsigned_insert_range_to_quark(enum_declaration, start, end, q);
}
array = g_hash_table_lookup(enum_declaration->table.quark_to_range_set,
range->end._unsigned = end;
}
-size_t enum_get_nr_enumerators(struct declaration_enum *enum_declaration)
+size_t bt_enum_get_nr_enumerators(struct declaration_enum *enum_declaration)
{
return g_hash_table_size(enum_declaration->table.quark_to_range_set);
}
static
-void _enum_declaration_free(struct declaration *declaration)
+void _enum_declaration_free(struct bt_declaration *declaration)
{
struct declaration_enum *enum_declaration =
container_of(declaration, struct declaration_enum, p);
g_free(iter);
}
g_hash_table_destroy(enum_declaration->table.quark_to_range_set);
- declaration_unref(&enum_declaration->integer_declaration->p);
+ bt_declaration_unref(&enum_declaration->integer_declaration->p);
g_free(enum_declaration);
}
struct declaration_enum *
- enum_declaration_new(struct declaration_integer *integer_declaration)
+ bt_enum_declaration_new(struct declaration_integer *integer_declaration)
{
struct declaration_enum *enum_declaration;
enum_declaration->table.quark_to_range_set = g_hash_table_new_full(g_direct_hash,
g_direct_equal,
NULL, enum_range_set_free);
- declaration_ref(&integer_declaration->p);
+ bt_declaration_ref(&integer_declaration->p);
enum_declaration->integer_declaration = integer_declaration;
enum_declaration->p.id = CTF_TYPE_ENUM;
enum_declaration->p.alignment = 1;
}
static
-struct definition *
- _enum_definition_new(struct declaration *declaration,
+struct bt_definition *
+ _enum_definition_new(struct bt_declaration *declaration,
struct definition_scope *parent_scope,
GQuark field_name, int index,
const char *root_name)
struct declaration_enum *enum_declaration =
container_of(declaration, struct declaration_enum, p);
struct definition_enum *_enum;
- struct definition *definition_integer_parent;
+ struct bt_definition *definition_integer_parent;
int ret;
_enum = g_new(struct definition_enum, 1);
- declaration_ref(&enum_declaration->p);
+ bt_declaration_ref(&enum_declaration->p);
_enum->p.declaration = declaration;
_enum->declaration = enum_declaration;
_enum->p.ref = 1;
*/
_enum->p.index = root_name ? INT_MAX : index;
_enum->p.name = field_name;
- _enum->p.path = new_definition_path(parent_scope, field_name, root_name);
- _enum->p.scope = new_definition_scope(parent_scope, field_name, root_name);
+ _enum->p.path = bt_new_definition_path(parent_scope, field_name, root_name);
+ _enum->p.scope = bt_new_definition_scope(parent_scope, field_name, root_name);
_enum->value = NULL;
- ret = register_field_definition(field_name, &_enum->p,
+ ret = bt_register_field_definition(field_name, &_enum->p,
parent_scope);
assert(!ret);
definition_integer_parent =
}
static
-void _enum_definition_free(struct definition *definition)
+void _enum_definition_free(struct bt_definition *definition)
{
struct definition_enum *_enum =
container_of(definition, struct definition_enum, p);
- definition_unref(&_enum->integer->p);
- free_definition_scope(_enum->p.scope);
- declaration_unref(_enum->p.declaration);
+ bt_definition_unref(&_enum->integer->p);
+ bt_free_definition_scope(_enum->p.scope);
+ bt_declaration_unref(_enum->p.declaration);
if (_enum->value)
g_array_unref(_enum->value);
g_free(_enum);
#include <babeltrace/endian.h>
static
-struct definition *_float_definition_new(struct declaration *declaration,
+struct bt_definition *_float_definition_new(struct bt_declaration *declaration,
struct definition_scope *parent_scope,
GQuark field_name, int index,
const char *root_name);
static
-void _float_definition_free(struct definition *definition);
+void _float_definition_free(struct bt_definition *definition);
static
-void _float_declaration_free(struct declaration *declaration)
+void _float_declaration_free(struct bt_declaration *declaration)
{
struct declaration_float *float_declaration =
container_of(declaration, struct declaration_float, p);
- declaration_unref(&float_declaration->exp->p);
- declaration_unref(&float_declaration->mantissa->p);
- declaration_unref(&float_declaration->sign->p);
+ bt_declaration_unref(&float_declaration->exp->p);
+ bt_declaration_unref(&float_declaration->mantissa->p);
+ bt_declaration_unref(&float_declaration->sign->p);
g_free(float_declaration);
}
struct declaration_float *
- float_declaration_new(size_t mantissa_len,
+ bt_float_declaration_new(size_t mantissa_len,
size_t exp_len, int byte_order, size_t alignment)
{
struct declaration_float *float_declaration;
- struct declaration *declaration;
+ struct bt_declaration *declaration;
float_declaration = g_new(struct declaration_float, 1);
declaration = &float_declaration->p;
declaration->ref = 1;
float_declaration->byte_order = byte_order;
- float_declaration->sign = integer_declaration_new(1,
+ float_declaration->sign = bt_integer_declaration_new(1,
byte_order, false, 1, 2,
CTF_STRING_NONE, NULL);
- float_declaration->mantissa = integer_declaration_new(mantissa_len - 1,
+ float_declaration->mantissa = bt_integer_declaration_new(mantissa_len - 1,
byte_order, false, 1, 10,
CTF_STRING_NONE, NULL);
- float_declaration->exp = integer_declaration_new(exp_len,
+ float_declaration->exp = bt_integer_declaration_new(exp_len,
byte_order, true, 1, 10,
CTF_STRING_NONE, NULL);
return float_declaration;
}
static
-struct definition *
- _float_definition_new(struct declaration *declaration,
+struct bt_definition *
+ _float_definition_new(struct bt_declaration *declaration,
struct definition_scope *parent_scope,
GQuark field_name, int index,
const char *root_name)
struct declaration_float *float_declaration =
container_of(declaration, struct declaration_float, p);
struct definition_float *_float;
- struct definition *tmp;
+ struct bt_definition *tmp;
_float = g_new(struct definition_float, 1);
- declaration_ref(&float_declaration->p);
+ bt_declaration_ref(&float_declaration->p);
_float->p.declaration = declaration;
_float->declaration = float_declaration;
- _float->p.scope = new_definition_scope(parent_scope, field_name, root_name);
- _float->p.path = new_definition_path(parent_scope, field_name, root_name);
+ _float->p.scope = bt_new_definition_scope(parent_scope, field_name, root_name);
+ _float->p.path = bt_new_definition_path(parent_scope, field_name, root_name);
if (float_declaration->byte_order == LITTLE_ENDIAN) {
tmp = float_declaration->mantissa->p.definition_new(&float_declaration->mantissa->p,
_float->p.scope, g_quark_from_static_string("mantissa"), 0, NULL);
if (parent_scope) {
int ret;
- ret = register_field_definition(field_name, &_float->p,
+ ret = bt_register_field_definition(field_name, &_float->p,
parent_scope);
assert(!ret);
}
}
static
-void _float_definition_free(struct definition *definition)
+void _float_definition_free(struct bt_definition *definition)
{
struct definition_float *_float =
container_of(definition, struct definition_float, p);
- definition_unref(&_float->sign->p);
- definition_unref(&_float->exp->p);
- definition_unref(&_float->mantissa->p);
- free_definition_scope(_float->p.scope);
- declaration_unref(_float->p.declaration);
+ bt_definition_unref(&_float->sign->p);
+ bt_definition_unref(&_float->exp->p);
+ bt_definition_unref(&_float->mantissa->p);
+ bt_free_definition_scope(_float->p.scope);
+ bt_declaration_unref(_float->p.declaration);
g_free(_float);
}
#include <stdint.h>
static
-struct definition *_integer_definition_new(struct declaration *declaration,
+struct bt_definition *_integer_definition_new(struct bt_declaration *declaration,
struct definition_scope *parent_scope,
GQuark field_name, int index,
const char *root_name);
static
-void _integer_definition_free(struct definition *definition);
+void _integer_definition_free(struct bt_definition *definition);
static
-void _integer_declaration_free(struct declaration *declaration)
+void _integer_declaration_free(struct bt_declaration *declaration)
{
struct declaration_integer *integer_declaration =
container_of(declaration, struct declaration_integer, p);
}
struct declaration_integer *
- integer_declaration_new(size_t len, int byte_order,
+ bt_integer_declaration_new(size_t len, int byte_order,
int signedness, size_t alignment, int base,
enum ctf_string_encoding encoding,
struct ctf_clock *clock)
}
static
-struct definition *
- _integer_definition_new(struct declaration *declaration,
+struct bt_definition *
+ _integer_definition_new(struct bt_declaration *declaration,
struct definition_scope *parent_scope,
GQuark field_name, int index,
const char *root_name)
int ret;
integer = g_new(struct definition_integer, 1);
- declaration_ref(&integer_declaration->p);
+ bt_declaration_ref(&integer_declaration->p);
integer->p.declaration = declaration;
integer->declaration = integer_declaration;
integer->p.ref = 1;
*/
integer->p.index = root_name ? INT_MAX : index;
integer->p.name = field_name;
- integer->p.path = new_definition_path(parent_scope, field_name,
+ integer->p.path = bt_new_definition_path(parent_scope, field_name,
root_name);
integer->p.scope = NULL;
integer->value._unsigned = 0;
- ret = register_field_definition(field_name, &integer->p,
+ ret = bt_register_field_definition(field_name, &integer->p,
parent_scope);
assert(!ret);
return &integer->p;
}
static
-void _integer_definition_free(struct definition *definition)
+void _integer_definition_free(struct bt_definition *definition)
{
struct definition_integer *integer =
container_of(definition, struct definition_integer, p);
- declaration_unref(integer->p.declaration);
+ bt_declaration_unref(integer->p.declaration);
g_free(integer);
}
-enum ctf_string_encoding get_int_encoding(const struct definition *field)
+enum ctf_string_encoding bt_get_int_encoding(const struct bt_definition *field)
{
struct definition_integer *integer_definition;
const struct declaration_integer *integer_declaration;
return integer_declaration->encoding;
}
-int get_int_base(const struct definition *field)
+int bt_get_int_base(const struct bt_definition *field)
{
struct definition_integer *integer_definition;
const struct declaration_integer *integer_declaration;
return integer_declaration->base;
}
-size_t get_int_len(const struct definition *field)
+size_t bt_get_int_len(const struct bt_definition *field)
{
struct definition_integer *integer_definition;
const struct declaration_integer *integer_declaration;
return integer_declaration->len;
}
-int get_int_byte_order(const struct definition *field)
+int bt_get_int_byte_order(const struct bt_definition *field)
{
struct definition_integer *integer_definition;
const struct declaration_integer *integer_declaration;
return integer_declaration->byte_order;
}
-int get_int_signedness(const struct definition *field)
+int bt_get_int_signedness(const struct bt_definition *field)
{
struct definition_integer *integer_definition;
const struct declaration_integer *integer_declaration;
return integer_declaration->signedness;
}
-uint64_t get_unsigned_int(const struct definition *field)
+uint64_t bt_get_unsigned_int(const struct bt_definition *field)
{
struct definition_integer *integer_definition;
const struct declaration_integer *integer_declaration;
return (uint64_t)integer_definition->value._signed;
}
-int64_t get_signed_int(const struct definition *field)
+int64_t bt_get_signed_int(const struct bt_definition *field)
{
struct definition_integer *integer_definition;
const struct declaration_integer *integer_declaration;
#include <inttypes.h>
static
-struct definition *_sequence_definition_new(struct declaration *declaration,
+struct bt_definition *_sequence_definition_new(struct bt_declaration *declaration,
struct definition_scope *parent_scope,
GQuark field_name, int index,
const char *root_name);
static
-void _sequence_definition_free(struct definition *definition);
+void _sequence_definition_free(struct bt_definition *definition);
-int sequence_rw(struct stream_pos *pos, struct definition *definition)
+int bt_sequence_rw(struct bt_stream_pos *pos, struct bt_definition *definition)
{
struct definition_sequence *sequence_definition =
container_of(definition, struct definition_sequence, p);
g_ptr_array_set_size(sequence_definition->elems, len);
for (i = oldlen; i < len; i++) {
- struct definition **field;
+ struct bt_definition **field;
GString *str;
GQuark name;
name = g_quark_from_string(str->str);
(void) g_string_free(str, TRUE);
- field = (struct definition **) &g_ptr_array_index(sequence_definition->elems, i);
+ field = (struct bt_definition **) &g_ptr_array_index(sequence_definition->elems, i);
*field = sequence_declaration->elem->definition_new(sequence_declaration->elem,
sequence_definition->p.scope,
name, i, NULL);
}
for (i = 0; i < len; i++) {
- struct definition **field;
+ struct bt_definition **field;
- field = (struct definition **) &g_ptr_array_index(sequence_definition->elems, i);
+ field = (struct bt_definition **) &g_ptr_array_index(sequence_definition->elems, i);
ret = generic_rw(pos, *field);
if (ret)
return ret;
}
static
-void _sequence_declaration_free(struct declaration *declaration)
+void _sequence_declaration_free(struct bt_declaration *declaration)
{
struct declaration_sequence *sequence_declaration =
container_of(declaration, struct declaration_sequence, p);
- free_declaration_scope(sequence_declaration->scope);
+ bt_free_declaration_scope(sequence_declaration->scope);
g_array_free(sequence_declaration->length_name, TRUE);
- declaration_unref(sequence_declaration->elem);
+ bt_declaration_unref(sequence_declaration->elem);
g_free(sequence_declaration);
}
struct declaration_sequence *
- sequence_declaration_new(const char *length,
- struct declaration *elem_declaration,
+ bt_sequence_declaration_new(const char *length,
+ struct bt_declaration *elem_declaration,
struct declaration_scope *parent_scope)
{
struct declaration_sequence *sequence_declaration;
- struct declaration *declaration;
+ struct bt_declaration *declaration;
sequence_declaration = g_new(struct declaration_sequence, 1);
declaration = &sequence_declaration->p;
sequence_declaration->length_name = g_array_new(FALSE, TRUE, sizeof(GQuark));
- append_scope_path(length, sequence_declaration->length_name);
+ bt_append_scope_path(length, sequence_declaration->length_name);
- declaration_ref(elem_declaration);
+ bt_declaration_ref(elem_declaration);
sequence_declaration->elem = elem_declaration;
- sequence_declaration->scope = new_declaration_scope(parent_scope);
+ sequence_declaration->scope = bt_new_declaration_scope(parent_scope);
declaration->id = CTF_TYPE_SEQUENCE;
declaration->alignment = elem_declaration->alignment;
declaration->declaration_free = _sequence_declaration_free;
}
static
-struct definition *_sequence_definition_new(struct declaration *declaration,
+struct bt_definition *_sequence_definition_new(struct bt_declaration *declaration,
struct definition_scope *parent_scope,
GQuark field_name, int index,
const char *root_name)
struct declaration_sequence *sequence_declaration =
container_of(declaration, struct declaration_sequence, p);
struct definition_sequence *sequence;
- struct definition *len_parent;
+ struct bt_definition *len_parent;
int ret;
sequence = g_new(struct definition_sequence, 1);
- declaration_ref(&sequence_declaration->p);
+ bt_declaration_ref(&sequence_declaration->p);
sequence->p.declaration = declaration;
sequence->declaration = sequence_declaration;
sequence->p.ref = 1;
*/
sequence->p.index = root_name ? INT_MAX : index;
sequence->p.name = field_name;
- sequence->p.path = new_definition_path(parent_scope, field_name, root_name);
- sequence->p.scope = new_definition_scope(parent_scope, field_name, root_name);
- ret = register_field_definition(field_name, &sequence->p,
+ sequence->p.path = bt_new_definition_path(parent_scope, field_name, root_name);
+ sequence->p.scope = bt_new_definition_scope(parent_scope, field_name, root_name);
+ ret = bt_register_field_definition(field_name, &sequence->p,
parent_scope);
assert(!ret);
- len_parent = lookup_path_definition(sequence->p.scope->scope_path,
+ len_parent = bt_lookup_path_definition(sequence->p.scope->scope_path,
sequence_declaration->length_name,
parent_scope);
if (!len_parent) {
printf("[error] Sequence length field should be unsigned.\n");
goto error;
}
- definition_ref(len_parent);
+ bt_definition_ref(len_parent);
sequence->string = NULL;
sequence->elems = NULL;
return &sequence->p;
error:
- free_definition_scope(sequence->p.scope);
- declaration_unref(&sequence_declaration->p);
+ bt_free_definition_scope(sequence->p.scope);
+ bt_declaration_unref(&sequence_declaration->p);
g_free(sequence);
return NULL;
}
static
-void _sequence_definition_free(struct definition *definition)
+void _sequence_definition_free(struct bt_definition *definition)
{
struct definition_sequence *sequence =
container_of(definition, struct definition_sequence, p);
- struct definition *len_definition = &sequence->length->p;
+ struct bt_definition *len_definition = &sequence->length->p;
uint64_t i;
if (sequence->string)
(void) g_string_free(sequence->string, TRUE);
if (sequence->elems) {
for (i = 0; i < sequence->elems->len; i++) {
- struct definition *field;
+ struct bt_definition *field;
field = g_ptr_array_index(sequence->elems, i);
field->declaration->definition_free(field);
}
(void) g_ptr_array_free(sequence->elems, TRUE);
}
- definition_unref(len_definition);
- free_definition_scope(sequence->p.scope);
- declaration_unref(sequence->p.declaration);
+ bt_definition_unref(len_definition);
+ bt_free_definition_scope(sequence->p.scope);
+ bt_declaration_unref(sequence->p.declaration);
g_free(sequence);
}
-uint64_t sequence_len(struct definition_sequence *sequence)
+uint64_t bt_sequence_len(struct definition_sequence *sequence)
{
return sequence->length->value._unsigned;
}
-struct definition *sequence_index(struct definition_sequence *sequence, uint64_t i)
+struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i)
{
if (!sequence->elems)
return NULL;
#include <babeltrace/types.h>
static
-struct definition *_string_definition_new(struct declaration *declaration,
+struct bt_definition *_string_definition_new(struct bt_declaration *declaration,
struct definition_scope *parent_scope,
GQuark field_name, int index,
const char *root_name);
static
-void _string_definition_free(struct definition *definition);
+void _string_definition_free(struct bt_definition *definition);
static
-void _string_declaration_free(struct declaration *declaration)
+void _string_declaration_free(struct bt_declaration *declaration)
{
struct declaration_string *string_declaration =
container_of(declaration, struct declaration_string, p);
}
struct declaration_string *
- string_declaration_new(enum ctf_string_encoding encoding)
+ bt_string_declaration_new(enum ctf_string_encoding encoding)
{
struct declaration_string *string_declaration;
}
static
-struct definition *
- _string_definition_new(struct declaration *declaration,
+struct bt_definition *
+ _string_definition_new(struct bt_declaration *declaration,
struct definition_scope *parent_scope,
GQuark field_name, int index,
const char *root_name)
int ret;
string = g_new(struct definition_string, 1);
- declaration_ref(&string_declaration->p);
+ bt_declaration_ref(&string_declaration->p);
string->p.declaration = declaration;
string->declaration = string_declaration;
string->p.ref = 1;
*/
string->p.index = root_name ? INT_MAX : index;
string->p.name = field_name;
- string->p.path = new_definition_path(parent_scope, field_name,
+ string->p.path = bt_new_definition_path(parent_scope, field_name,
root_name);
string->p.scope = NULL;
string->value = NULL;
string->len = 0;
string->alloc_len = 0;
- ret = register_field_definition(field_name, &string->p,
+ ret = bt_register_field_definition(field_name, &string->p,
parent_scope);
assert(!ret);
return &string->p;
}
static
-void _string_definition_free(struct definition *definition)
+void _string_definition_free(struct bt_definition *definition)
{
struct definition_string *string =
container_of(definition, struct definition_string, p);
- declaration_unref(string->p.declaration);
+ bt_declaration_unref(string->p.declaration);
g_free(string->value);
g_free(string);
}
-enum ctf_string_encoding get_string_encoding(const struct definition *field)
+enum ctf_string_encoding bt_get_string_encoding(const struct bt_definition *field)
{
struct definition_string *string_definition;
const struct declaration_string *string_declaration;
return string_declaration->encoding;
}
-char *get_string(const struct definition *field)
+char *bt_get_string(const struct bt_definition *field)
{
struct definition_string *string_definition =
container_of(field, struct definition_string, p);
#endif
static
-struct definition *_struct_definition_new(struct declaration *declaration,
+struct bt_definition *_struct_definition_new(struct bt_declaration *declaration,
struct definition_scope *parent_scope,
GQuark field_name, int index,
const char *root_name);
static
-void _struct_definition_free(struct definition *definition);
+void _struct_definition_free(struct bt_definition *definition);
-int struct_rw(struct stream_pos *ppos, struct definition *definition)
+int bt_struct_rw(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct definition_struct *struct_definition =
container_of(definition, struct definition_struct, p);
int ret;
for (i = 0; i < struct_definition->fields->len; i++) {
- struct definition *field =
+ struct bt_definition *field =
g_ptr_array_index(struct_definition->fields, i);
ret = generic_rw(ppos, field);
if (ret)
}
static
-void _struct_declaration_free(struct declaration *declaration)
+void _struct_declaration_free(struct bt_declaration *declaration)
{
struct declaration_struct *struct_declaration =
container_of(declaration, struct declaration_struct, p);
unsigned long i;
- free_declaration_scope(struct_declaration->scope);
+ bt_free_declaration_scope(struct_declaration->scope);
g_hash_table_destroy(struct_declaration->fields_by_name);
for (i = 0; i < struct_declaration->fields->len; i++) {
struct declaration_field *declaration_field =
&g_array_index(struct_declaration->fields,
struct declaration_field, i);
- declaration_unref(declaration_field->declaration);
+ bt_declaration_unref(declaration_field->declaration);
}
g_array_free(struct_declaration->fields, true);
g_free(struct_declaration);
}
struct declaration_struct *
- struct_declaration_new(struct declaration_scope *parent_scope,
+ bt_struct_declaration_new(struct declaration_scope *parent_scope,
uint64_t min_align)
{
struct declaration_struct *struct_declaration;
- struct declaration *declaration;
+ struct bt_declaration *declaration;
struct_declaration = g_new(struct declaration_struct, 1);
declaration = &struct_declaration->p;
struct_declaration->fields = g_array_sized_new(FALSE, TRUE,
sizeof(struct declaration_field),
DEFAULT_NR_STRUCT_FIELDS);
- struct_declaration->scope = new_declaration_scope(parent_scope);
+ struct_declaration->scope = bt_new_declaration_scope(parent_scope);
declaration->id = CTF_TYPE_STRUCT;
declaration->alignment = max(1, min_align);
declaration->declaration_free = _struct_declaration_free;
}
static
-struct definition *
- _struct_definition_new(struct declaration *declaration,
+struct bt_definition *
+ _struct_definition_new(struct bt_declaration *declaration,
struct definition_scope *parent_scope,
GQuark field_name, int index,
const char *root_name)
int ret;
_struct = g_new(struct definition_struct, 1);
- declaration_ref(&struct_declaration->p);
+ bt_declaration_ref(&struct_declaration->p);
_struct->p.declaration = declaration;
_struct->declaration = struct_declaration;
_struct->p.ref = 1;
*/
_struct->p.index = root_name ? INT_MAX : index;
_struct->p.name = field_name;
- _struct->p.path = new_definition_path(parent_scope, field_name, root_name);
- _struct->p.scope = new_definition_scope(parent_scope, field_name, root_name);
+ _struct->p.path = bt_new_definition_path(parent_scope, field_name, root_name);
+ _struct->p.scope = bt_new_definition_scope(parent_scope, field_name, root_name);
- ret = register_field_definition(field_name, &_struct->p,
+ ret = bt_register_field_definition(field_name, &_struct->p,
parent_scope);
assert(!ret || ret == -EPERM);
struct declaration_field *declaration_field =
&g_array_index(struct_declaration->fields,
struct declaration_field, i);
- struct definition **field =
- (struct definition **) &g_ptr_array_index(_struct->fields, i);
+ struct bt_definition **field =
+ (struct bt_definition **) &g_ptr_array_index(_struct->fields, i);
*field = declaration_field->declaration->definition_new(declaration_field->declaration,
_struct->p.scope,
error:
for (i--; i >= 0; i--) {
- struct definition *field = g_ptr_array_index(_struct->fields, i);
- definition_unref(field);
+ struct bt_definition *field = g_ptr_array_index(_struct->fields, i);
+ bt_definition_unref(field);
}
- free_definition_scope(_struct->p.scope);
- declaration_unref(&struct_declaration->p);
+ bt_free_definition_scope(_struct->p.scope);
+ bt_declaration_unref(&struct_declaration->p);
g_free(_struct);
return NULL;
}
static
-void _struct_definition_free(struct definition *definition)
+void _struct_definition_free(struct bt_definition *definition)
{
struct definition_struct *_struct =
container_of(definition, struct definition_struct, p);
assert(_struct->fields->len == _struct->declaration->fields->len);
for (i = 0; i < _struct->fields->len; i++) {
- struct definition *field = g_ptr_array_index(_struct->fields, i);
- definition_unref(field);
+ struct bt_definition *field = g_ptr_array_index(_struct->fields, i);
+ bt_definition_unref(field);
}
- free_definition_scope(_struct->p.scope);
- declaration_unref(_struct->p.declaration);
+ bt_free_definition_scope(_struct->p.scope);
+ bt_declaration_unref(_struct->p.declaration);
g_ptr_array_free(_struct->fields, TRUE);
g_free(_struct);
}
-void struct_declaration_add_field(struct declaration_struct *struct_declaration,
+void bt_struct_declaration_add_field(struct declaration_struct *struct_declaration,
const char *field_name,
- struct declaration *field_declaration)
+ struct bt_declaration *field_declaration)
{
struct declaration_field *field;
unsigned long index;
index = struct_declaration->fields->len - 1; /* last field (new) */
field = &g_array_index(struct_declaration->fields, struct declaration_field, index);
field->name = g_quark_from_string(field_name);
- declaration_ref(field_declaration);
+ bt_declaration_ref(field_declaration);
field->declaration = field_declaration;
/* Keep index in hash rather than pointer, because array can relocate */
g_hash_table_insert(struct_declaration->fields_by_name,
}
/*
- * struct_declaration_lookup_field_index - returns field index
+ * bt_struct_declaration_lookup_field_index - returns field index
*
* Returns the index of a field in a structure, or -1 if it does not
* exist.
*/
-int struct_declaration_lookup_field_index(struct declaration_struct *struct_declaration,
+int bt_struct_declaration_lookup_field_index(struct declaration_struct *struct_declaration,
GQuark field_name)
{
gpointer index;
* field returned only valid as long as the field structure is not appended to.
*/
struct declaration_field *
- struct_declaration_get_field_from_index(struct declaration_struct *struct_declaration,
+ bt_struct_declaration_get_field_from_index(struct declaration_struct *struct_declaration,
int index)
{
if (index < 0)
/*
* field returned only valid as long as the field structure is not appended to.
*/
-struct definition *
-struct_definition_get_field_from_index(struct definition_struct *_struct,
+struct bt_definition *
+bt_struct_definition_get_field_from_index(struct definition_struct *_struct,
int index)
{
if (index < 0)
return g_ptr_array_index(_struct->fields, index);
}
-uint64_t struct_declaration_len(struct declaration_struct *struct_declaration)
+uint64_t bt_struct_declaration_len(struct declaration_struct *struct_declaration)
{
return struct_declaration->fields->len;
}
}
static
-struct declaration *
- lookup_declaration_scope(GQuark declaration_name,
+struct bt_declaration *
+ bt_lookup_declaration_scope(GQuark declaration_name,
struct declaration_scope *scope)
{
return g_hash_table_lookup(scope->typedef_declarations,
(gconstpointer) (unsigned long) declaration_name);
}
-struct declaration *lookup_declaration(GQuark declaration_name,
+struct bt_declaration *bt_lookup_declaration(GQuark declaration_name,
struct declaration_scope *scope)
{
- struct declaration *declaration;
+ struct bt_declaration *declaration;
while (scope) {
- declaration = lookup_declaration_scope(declaration_name,
+ declaration = bt_lookup_declaration_scope(declaration_name,
scope);
if (declaration)
return declaration;
return NULL;
}
-int register_declaration(GQuark name, struct declaration *declaration,
+int bt_register_declaration(GQuark name, struct bt_declaration *declaration,
struct declaration_scope *scope)
{
if (!name)
return -EPERM;
/* Only lookup in local scope */
- if (lookup_declaration_scope(name, scope))
+ if (bt_lookup_declaration_scope(name, scope))
return -EEXIST;
g_hash_table_insert(scope->typedef_declarations,
(gpointer) (unsigned long) name,
declaration);
- declaration_ref(declaration);
+ bt_declaration_ref(declaration);
return 0;
}
static
-struct definition *
+struct bt_definition *
lookup_field_definition_scope(GQuark field_name,
struct definition_scope *scope)
{
}
static struct definition_scope *
- get_definition_scope(const struct definition *definition)
+ get_definition_scope(const struct bt_definition *definition)
{
return definition->scope;
}
* lookup_path: the path leading to the enum we want to look for.
* scope: the definition scope containing the variant definition.
*/
-struct definition *
- lookup_path_definition(GArray *cur_path,
+struct bt_definition *
+ bt_lookup_path_definition(GArray *cur_path,
GArray *lookup_path,
struct definition_scope *scope)
{
- struct definition *definition, *lookup_definition;
+ struct bt_definition *definition, *lookup_definition;
GQuark last;
int index;
return NULL;
}
-int register_field_definition(GQuark field_name, struct definition *definition,
+int bt_register_field_definition(GQuark field_name, struct bt_definition *definition,
struct definition_scope *scope)
{
if (!scope || !field_name)
return 0;
}
-void declaration_ref(struct declaration *declaration)
+void bt_declaration_ref(struct bt_declaration *declaration)
{
declaration->ref++;
}
-void declaration_unref(struct declaration *declaration)
+void bt_declaration_unref(struct bt_declaration *declaration)
{
if (!declaration)
return;
declaration->declaration_free(declaration);
}
-void definition_ref(struct definition *definition)
+void bt_definition_ref(struct bt_definition *definition)
{
definition->ref++;
}
-void definition_unref(struct definition *definition)
+void bt_definition_unref(struct bt_definition *definition)
{
if (!definition)
return;
}
struct declaration_scope *
- new_declaration_scope(struct declaration_scope *parent_scope)
+ bt_new_declaration_scope(struct declaration_scope *parent_scope)
{
struct declaration_scope *scope = g_new(struct declaration_scope, 1);
scope->typedef_declarations = g_hash_table_new_full(g_direct_hash,
g_direct_equal, NULL,
- (GDestroyNotify) declaration_unref);
+ (GDestroyNotify) bt_declaration_unref);
scope->struct_declarations = g_hash_table_new_full(g_direct_hash,
g_direct_equal, NULL,
- (GDestroyNotify) declaration_unref);
+ (GDestroyNotify) bt_declaration_unref);
scope->variant_declarations = g_hash_table_new_full(g_direct_hash,
g_direct_equal, NULL,
- (GDestroyNotify) declaration_unref);
+ (GDestroyNotify) bt_declaration_unref);
scope->enum_declarations = g_hash_table_new_full(g_direct_hash,
g_direct_equal, NULL,
- (GDestroyNotify) declaration_unref);
+ (GDestroyNotify) bt_declaration_unref);
scope->parent_scope = parent_scope;
return scope;
}
-void free_declaration_scope(struct declaration_scope *scope)
+void bt_free_declaration_scope(struct declaration_scope *scope)
{
g_hash_table_destroy(scope->enum_declarations);
g_hash_table_destroy(scope->variant_declarations);
}
static
-struct declaration_struct *lookup_struct_declaration_scope(GQuark struct_name,
+struct declaration_struct *bt_lookup_struct_declaration_scope(GQuark struct_name,
struct declaration_scope *scope)
{
return g_hash_table_lookup(scope->struct_declarations,
(gconstpointer) (unsigned long) struct_name);
}
-struct declaration_struct *lookup_struct_declaration(GQuark struct_name,
+struct declaration_struct *bt_lookup_struct_declaration(GQuark struct_name,
struct declaration_scope *scope)
{
struct declaration_struct *declaration;
while (scope) {
- declaration = lookup_struct_declaration_scope(struct_name, scope);
+ declaration = bt_lookup_struct_declaration_scope(struct_name, scope);
if (declaration)
return declaration;
scope = scope->parent_scope;
return NULL;
}
-int register_struct_declaration(GQuark struct_name,
+int bt_register_struct_declaration(GQuark struct_name,
struct declaration_struct *struct_declaration,
struct declaration_scope *scope)
{
return -EPERM;
/* Only lookup in local scope */
- if (lookup_struct_declaration_scope(struct_name, scope))
+ if (bt_lookup_struct_declaration_scope(struct_name, scope))
return -EEXIST;
g_hash_table_insert(scope->struct_declarations,
(gpointer) (unsigned long) struct_name,
struct_declaration);
- declaration_ref(&struct_declaration->p);
+ bt_declaration_ref(&struct_declaration->p);
/* Also add in typedef/typealias scopes */
prefix_name = prefix_quark("struct ", struct_name);
- ret = register_declaration(prefix_name, &struct_declaration->p, scope);
+ ret = bt_register_declaration(prefix_name, &struct_declaration->p, scope);
assert(!ret);
return 0;
}
static
struct declaration_untagged_variant *
- lookup_variant_declaration_scope(GQuark variant_name,
+ bt_lookup_variant_declaration_scope(GQuark variant_name,
struct declaration_scope *scope)
{
return g_hash_table_lookup(scope->variant_declarations,
}
struct declaration_untagged_variant *
- lookup_variant_declaration(GQuark variant_name,
+ bt_lookup_variant_declaration(GQuark variant_name,
struct declaration_scope *scope)
{
struct declaration_untagged_variant *declaration;
while (scope) {
- declaration = lookup_variant_declaration_scope(variant_name, scope);
+ declaration = bt_lookup_variant_declaration_scope(variant_name, scope);
if (declaration)
return declaration;
scope = scope->parent_scope;
return NULL;
}
-int register_variant_declaration(GQuark variant_name,
+int bt_register_variant_declaration(GQuark variant_name,
struct declaration_untagged_variant *untagged_variant_declaration,
struct declaration_scope *scope)
{
return -EPERM;
/* Only lookup in local scope */
- if (lookup_variant_declaration_scope(variant_name, scope))
+ if (bt_lookup_variant_declaration_scope(variant_name, scope))
return -EEXIST;
g_hash_table_insert(scope->variant_declarations,
(gpointer) (unsigned long) variant_name,
untagged_variant_declaration);
- declaration_ref(&untagged_variant_declaration->p);
+ bt_declaration_ref(&untagged_variant_declaration->p);
/* Also add in typedef/typealias scopes */
prefix_name = prefix_quark("variant ", variant_name);
- ret = register_declaration(prefix_name,
+ ret = bt_register_declaration(prefix_name,
&untagged_variant_declaration->p, scope);
assert(!ret);
return 0;
static
struct declaration_enum *
- lookup_enum_declaration_scope(GQuark enum_name,
+ bt_lookup_enum_declaration_scope(GQuark enum_name,
struct declaration_scope *scope)
{
return g_hash_table_lookup(scope->enum_declarations,
}
struct declaration_enum *
- lookup_enum_declaration(GQuark enum_name,
+ bt_lookup_enum_declaration(GQuark enum_name,
struct declaration_scope *scope)
{
struct declaration_enum *declaration;
while (scope) {
- declaration = lookup_enum_declaration_scope(enum_name, scope);
+ declaration = bt_lookup_enum_declaration_scope(enum_name, scope);
if (declaration)
return declaration;
scope = scope->parent_scope;
return NULL;
}
-int register_enum_declaration(GQuark enum_name,
+int bt_register_enum_declaration(GQuark enum_name,
struct declaration_enum *enum_declaration,
struct declaration_scope *scope)
{
return -EPERM;
/* Only lookup in local scope */
- if (lookup_enum_declaration_scope(enum_name, scope))
+ if (bt_lookup_enum_declaration_scope(enum_name, scope))
return -EEXIST;
g_hash_table_insert(scope->enum_declarations,
(gpointer) (unsigned long) enum_name,
enum_declaration);
- declaration_ref(&enum_declaration->p);
+ bt_declaration_ref(&enum_declaration->p);
/* Also add in typedef/typealias scopes */
prefix_name = prefix_quark("enum ", enum_name);
- ret = register_declaration(prefix_name, &enum_declaration->p, scope);
+ ret = bt_register_declaration(prefix_name, &enum_declaration->p, scope);
assert(!ret);
return 0;
}
static struct definition_scope *
- _new_definition_scope(struct definition_scope *parent_scope,
+ _bt_new_definition_scope(struct definition_scope *parent_scope,
int scope_path_len)
{
struct definition_scope *scope = g_new(struct definition_scope, 1);
return scope;
}
-GQuark new_definition_path(struct definition_scope *parent_scope,
+GQuark bt_new_definition_path(struct definition_scope *parent_scope,
GQuark field_name, const char *root_name)
{
GQuark path;
}
struct definition_scope *
- new_definition_scope(struct definition_scope *parent_scope,
+ bt_new_definition_scope(struct definition_scope *parent_scope,
GQuark field_name, const char *root_name)
{
struct definition_scope *scope;
if (root_name) {
- scope = _new_definition_scope(parent_scope, 0);
- append_scope_path(root_name, scope->scope_path);
+ scope = _bt_new_definition_scope(parent_scope, 0);
+ bt_append_scope_path(root_name, scope->scope_path);
} else {
int scope_path_len = 1;
assert(parent_scope);
scope_path_len += parent_scope->scope_path->len;
- scope = _new_definition_scope(parent_scope, scope_path_len);
+ scope = _bt_new_definition_scope(parent_scope, scope_path_len);
memcpy(scope->scope_path->data, parent_scope->scope_path->data,
sizeof(GQuark) * (scope_path_len - 1));
g_array_index(scope->scope_path, GQuark, scope_path_len - 1) =
/*
* in: path (dot separated), out: q (GArray of GQuark)
*/
-void append_scope_path(const char *path, GArray *q)
+void bt_append_scope_path(const char *path, GArray *q)
{
const char *ptrbegin, *ptrend = path;
GQuark quark;
}
}
-void free_definition_scope(struct definition_scope *scope)
+void bt_free_definition_scope(struct definition_scope *scope)
{
g_array_free(scope->scope_path, TRUE);
g_hash_table_destroy(scope->definitions);
g_free(scope);
}
-struct definition *lookup_definition(const struct definition *definition,
+struct bt_definition *bt_lookup_definition(const struct bt_definition *definition,
const char *field_name)
{
struct definition_scope *scope = get_definition_scope(definition);
scope);
}
-struct definition_integer *lookup_integer(const struct definition *definition,
+struct definition_integer *bt_lookup_integer(const struct bt_definition *definition,
const char *field_name,
int signedness)
{
- struct definition *lookup;
+ struct bt_definition *lookup;
struct definition_integer *lookup_integer;
- lookup = lookup_definition(definition, field_name);
+ lookup = bt_lookup_definition(definition, field_name);
if (!lookup)
return NULL;
if (lookup->declaration->id != CTF_TYPE_INTEGER)
return lookup_integer;
}
-struct definition_enum *lookup_enum(const struct definition *definition,
+struct definition_enum *bt_lookup_enum(const struct bt_definition *definition,
const char *field_name,
int signedness)
{
- struct definition *lookup;
+ struct bt_definition *lookup;
struct definition_enum *lookup_enum;
- lookup = lookup_definition(definition, field_name);
+ lookup = bt_lookup_definition(definition, field_name);
if (!lookup)
return NULL;
if (lookup->declaration->id != CTF_TYPE_ENUM)
return lookup_enum;
}
-struct definition *lookup_variant(const struct definition *definition,
+struct bt_definition *bt_lookup_variant(const struct bt_definition *definition,
const char *field_name)
{
- struct definition *lookup;
- struct definition_variant *lookup_variant;
+ struct bt_definition *lookup;
+ struct definition_variant *bt_lookup_variant;
- lookup = lookup_definition(definition, field_name);
+ lookup = bt_lookup_definition(definition, field_name);
if (!lookup)
return NULL;
if (lookup->declaration->id != CTF_TYPE_VARIANT)
return NULL;
- lookup_variant = container_of(lookup, struct definition_variant, p);
- lookup = variant_get_current_field(lookup_variant);
+ bt_lookup_variant = container_of(lookup, struct definition_variant, p);
+ lookup = bt_variant_get_current_field(bt_lookup_variant);
assert(lookup);
return lookup;
}
#include <errno.h>
static
-struct definition *_variant_definition_new(struct declaration *declaration,
+struct bt_definition *_variant_definition_new(struct bt_declaration *declaration,
struct definition_scope *parent_scope,
GQuark field_name, int index,
const char *root_name);
static
-void _variant_definition_free(struct definition *definition);
+void _variant_definition_free(struct bt_definition *definition);
-int variant_rw(struct stream_pos *ppos, struct definition *definition)
+int bt_variant_rw(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
struct definition_variant *variant_definition =
container_of(definition, struct definition_variant, p);
- struct definition *field;
+ struct bt_definition *field;
- field = variant_get_current_field(variant_definition);
+ field = bt_variant_get_current_field(variant_definition);
return generic_rw(ppos, field);
}
static
-void _untagged_variant_declaration_free(struct declaration *declaration)
+void _untagged_variant_declaration_free(struct bt_declaration *declaration)
{
struct declaration_untagged_variant *untagged_variant_declaration =
container_of(declaration, struct declaration_untagged_variant, p);
unsigned long i;
- free_declaration_scope(untagged_variant_declaration->scope);
+ bt_free_declaration_scope(untagged_variant_declaration->scope);
g_hash_table_destroy(untagged_variant_declaration->fields_by_tag);
for (i = 0; i < untagged_variant_declaration->fields->len; i++) {
struct declaration_field *declaration_field =
&g_array_index(untagged_variant_declaration->fields,
struct declaration_field, i);
- declaration_unref(declaration_field->declaration);
+ bt_declaration_unref(declaration_field->declaration);
}
g_array_free(untagged_variant_declaration->fields, true);
g_free(untagged_variant_declaration);
}
-struct declaration_untagged_variant *untagged_variant_declaration_new(
+struct declaration_untagged_variant *bt_untagged_bt_variant_declaration_new(
struct declaration_scope *parent_scope)
{
struct declaration_untagged_variant *untagged_variant_declaration;
- struct declaration *declaration;
+ struct bt_declaration *declaration;
untagged_variant_declaration = g_new(struct declaration_untagged_variant, 1);
declaration = &untagged_variant_declaration->p;
untagged_variant_declaration->fields = g_array_sized_new(FALSE, TRUE,
sizeof(struct declaration_field),
DEFAULT_NR_STRUCT_FIELDS);
- untagged_variant_declaration->scope = new_declaration_scope(parent_scope);
+ untagged_variant_declaration->scope = bt_new_declaration_scope(parent_scope);
declaration->id = CTF_TYPE_UNTAGGED_VARIANT;
declaration->alignment = 1;
declaration->declaration_free = _untagged_variant_declaration_free;
}
static
-void _variant_declaration_free(struct declaration *declaration)
+void _variant_declaration_free(struct bt_declaration *declaration)
{
struct declaration_variant *variant_declaration =
container_of(declaration, struct declaration_variant, p);
- declaration_unref(&variant_declaration->untagged_variant->p);
+ bt_declaration_unref(&variant_declaration->untagged_variant->p);
g_array_free(variant_declaration->tag_name, TRUE);
g_free(variant_declaration);
}
struct declaration_variant *
- variant_declaration_new(struct declaration_untagged_variant *untagged_variant, const char *tag)
+ bt_variant_declaration_new(struct declaration_untagged_variant *untagged_variant, const char *tag)
{
struct declaration_variant *variant_declaration;
- struct declaration *declaration;
+ struct bt_declaration *declaration;
variant_declaration = g_new(struct declaration_variant, 1);
declaration = &variant_declaration->p;
variant_declaration->untagged_variant = untagged_variant;
- declaration_ref(&untagged_variant->p);
+ bt_declaration_ref(&untagged_variant->p);
variant_declaration->tag_name = g_array_new(FALSE, TRUE, sizeof(GQuark));
- append_scope_path(tag, variant_declaration->tag_name);
+ bt_append_scope_path(tag, variant_declaration->tag_name);
declaration->id = CTF_TYPE_VARIANT;
declaration->alignment = 1;
declaration->declaration_free = _variant_declaration_free;
*/
static
int check_enum_tag(struct definition_variant *variant,
- struct definition *enum_tag)
+ struct bt_definition *enum_tag)
{
struct definition_enum *_enum =
container_of(enum_tag, struct definition_enum, p);
* variant choice map to an enumerator too. We then validate that the
* number of enumerators equals the number of variant choices.
*/
- if (variant->declaration->untagged_variant->fields->len != enum_get_nr_enumerators(enum_declaration))
+ if (variant->declaration->untagged_variant->fields->len != bt_enum_get_nr_enumerators(enum_declaration))
return -EPERM;
for (i = 0; i < variant->declaration->untagged_variant->fields->len; i++) {
struct declaration_field *field_declaration =
&g_array_index(variant->declaration->untagged_variant->fields,
struct declaration_field, i);
- if (!enum_quark_to_range_set(enum_declaration, field_declaration->name)) {
+ if (!bt_enum_quark_to_range_set(enum_declaration, field_declaration->name)) {
missing_field = 1;
break;
}
static
-struct definition *
- _variant_definition_new(struct declaration *declaration,
+struct bt_definition *
+ _variant_definition_new(struct bt_declaration *declaration,
struct definition_scope *parent_scope,
GQuark field_name, int index,
const char *root_name)
int ret;
variant = g_new(struct definition_variant, 1);
- declaration_ref(&variant_declaration->p);
+ bt_declaration_ref(&variant_declaration->p);
variant->p.declaration = declaration;
variant->declaration = variant_declaration;
variant->p.ref = 1;
*/
variant->p.index = root_name ? INT_MAX : index;
variant->p.name = field_name;
- variant->p.path = new_definition_path(parent_scope, field_name, root_name);
- variant->p.scope = new_definition_scope(parent_scope, field_name, root_name);
+ variant->p.path = bt_new_definition_path(parent_scope, field_name, root_name);
+ variant->p.scope = bt_new_definition_scope(parent_scope, field_name, root_name);
- ret = register_field_definition(field_name, &variant->p,
+ ret = bt_register_field_definition(field_name, &variant->p,
parent_scope);
assert(!ret);
- variant->enum_tag = lookup_path_definition(variant->p.scope->scope_path,
+ variant->enum_tag = bt_lookup_path_definition(variant->p.scope->scope_path,
variant_declaration->tag_name,
parent_scope);
if (!variant->enum_tag
|| check_enum_tag(variant, variant->enum_tag) < 0)
goto error;
- definition_ref(variant->enum_tag);
+ bt_definition_ref(variant->enum_tag);
variant->fields = g_ptr_array_sized_new(variant_declaration->untagged_variant->fields->len);
g_ptr_array_set_size(variant->fields, variant_declaration->untagged_variant->fields->len);
for (i = 0; i < variant_declaration->untagged_variant->fields->len; i++) {
struct declaration_field *declaration_field =
&g_array_index(variant_declaration->untagged_variant->fields,
struct declaration_field, i);
- struct definition **field =
- (struct definition **) &g_ptr_array_index(variant->fields, i);
+ struct bt_definition **field =
+ (struct bt_definition **) &g_ptr_array_index(variant->fields, i);
/*
* All child definition are at index 0, because they are
variant->current_field = NULL;
return &variant->p;
error:
- free_definition_scope(variant->p.scope);
- declaration_unref(&variant_declaration->p);
+ bt_free_definition_scope(variant->p.scope);
+ bt_declaration_unref(&variant_declaration->p);
g_free(variant);
return NULL;
}
static
-void _variant_definition_free(struct definition *definition)
+void _variant_definition_free(struct bt_definition *definition)
{
struct definition_variant *variant =
container_of(definition, struct definition_variant, p);
assert(variant->fields->len == variant->declaration->untagged_variant->fields->len);
for (i = 0; i < variant->fields->len; i++) {
- struct definition *field = g_ptr_array_index(variant->fields, i);
- definition_unref(field);
+ struct bt_definition *field = g_ptr_array_index(variant->fields, i);
+ bt_definition_unref(field);
}
- definition_unref(variant->enum_tag);
- free_definition_scope(variant->p.scope);
- declaration_unref(variant->p.declaration);
+ bt_definition_unref(variant->enum_tag);
+ bt_free_definition_scope(variant->p.scope);
+ bt_declaration_unref(variant->p.declaration);
g_ptr_array_free(variant->fields, TRUE);
g_free(variant);
}
-void untagged_variant_declaration_add_field(struct declaration_untagged_variant *untagged_variant_declaration,
+void bt_untagged_variant_declaration_add_field(struct declaration_untagged_variant *untagged_variant_declaration,
const char *field_name,
- struct declaration *field_declaration)
+ struct bt_declaration *field_declaration)
{
struct declaration_field *field;
unsigned long index;
index = untagged_variant_declaration->fields->len - 1; /* last field (new) */
field = &g_array_index(untagged_variant_declaration->fields, struct declaration_field, index);
field->name = g_quark_from_string(field_name);
- declaration_ref(field_declaration);
+ bt_declaration_ref(field_declaration);
field->declaration = field_declaration;
/* Keep index in hash rather than pointer, because array can relocate */
g_hash_table_insert(untagged_variant_declaration->fields_by_tag,
}
struct declaration_field *
-untagged_variant_declaration_get_field_from_tag(struct declaration_untagged_variant *untagged_variant_declaration, GQuark tag)
+bt_untagged_variant_declaration_get_field_from_tag(struct declaration_untagged_variant *untagged_variant_declaration, GQuark tag)
{
gpointer index;
gboolean found;
/*
* field returned only valid as long as the field structure is not appended to.
*/
-struct definition *variant_get_current_field(struct definition_variant *variant)
+struct bt_definition *bt_variant_get_current_field(struct definition_variant *variant)
{
struct definition_enum *_enum =
container_of(variant->enum_tag, struct definition_enum, p);