SplitEmptyFunction: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: false
-BreakConstructorInitializers: AfterColon
BreakStringLiterals: false
ColumnLimit: 100
ConstructorInitializerAllOnOneLineOrOnePerLine: true
/.clangd/
compile_commands.json
*_flymake*
-/.vscode/*
# m4 macros not automatically generated
/m4/libtool.m4
--- /dev/null
+#!/usr/bin/env bash
+# Copyright (C) 2024 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+#
+# SPDX-License-Identifier: LGPL-2.1-only
+#
+
+source_dir="$1"
+
+# Run make quietly to check if a Makefile exists
+make_output=$(make -C "$source_dir" -q 2>&1)
+make_exit_status=$?
+
+# Check the return status of make -q
+if [ $make_exit_status -eq 2 ]; then
+ # It seems the Makefiles don't exist. Most likely the user forgot to
+ # setup their tree.
+ echo "$make_output"
+ echo -e "\033[33mMake couldn't find a Makefile: did you run ./bootstrap and ./configure ?\033[0m"
+ exit 1
+fi
+
+# Check if compile_commands.json does not exist in the source directory and if bear is installed
+if [ ! -f "$source_dir/compile_commands.json" ] && which bear >/dev/null 2>&1; then
+ # Bear is installed and compile_commands.json is not present
+ # Perform a make clean since compile_commands.json is missing and bear is installed
+ make -C "$source_dir" clean
+
+ # Prefix bear to the make command
+ command_prefix="bear -- "
+fi
+
+# Run make with or without bear prefix, depending on the condition above
+eval "${command_prefix}"make -C "$source_dir" -j "$(nproc)"
--- /dev/null
+{
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "Debug LTTng Client",
+ "type": "cppdbg",
+ "request": "launch",
+ "program": "${workspaceFolder}/src/bin/lttng/.libs/lttng",
+ // Replace with your args
+ "args": [
+ "help"
+ ],
+ "stopAtEntry": false,
+ "cwd": "${workspaceFolder}",
+ "environment": [],
+ "externalConsole": false,
+ "MIMode": "gdb",
+ "miDebuggerPath": "${workspaceFolder}/.vscode/libtool_gdb_wrapper.sh",
+ "setupCommands": [
+ {
+ "description": "Enable pretty-printing for gdb",
+ "text": "-enable-pretty-printing",
+ "ignoreFailures": true
+ }
+ ],
+ "preLaunchTask": "Build LTTng-tools"
+ },
+ {
+ "name": "Debug LTTng Session Daemon",
+ "type": "cppdbg",
+ "request": "launch",
+ "program": "${workspaceFolder}/src/bin/lttng-sessiond/.libs/lttng-sessiond",
+ "args": [],
+ "stopAtEntry": false,
+ "cwd": "${workspaceFolder}",
+ // The session daemon fails to launch if it can't find the session schema description
+ "environment": [
+ {
+ "name": "LTTNG_SESSION_CONFIG_XSD_PATH",
+ "value": "${workspaceFolder}/src/common/"
+ }
+ ],
+ "externalConsole": false,
+ "MIMode": "gdb",
+ "miDebuggerPath": "${workspaceFolder}/.vscode/libtool_gdb_wrapper.sh",
+ "setupCommands": [
+ {
+ "description": "Enable pretty-printing for gdb",
+ "text": "-enable-pretty-printing",
+ "ignoreFailures": true
+ }
+ ],
+ "preLaunchTask": "Build LTTng-tools"
+ },
+ {
+ "name": "Debug LTTng Relay Daemon",
+ "type": "cppdbg",
+ "request": "launch",
+ "program": "${workspaceFolder}/src/bin/lttng-relayd/lttng-relayd",
+ "args": [],
+ "cwd": "${workspaceFolder}",
+ "environment": [],
+ "externalConsole": false,
+ "MIMode": "gdb",
+ "miDebuggerPath": "${workspaceFolder}/.vscode/libtool_gdb_wrapper.sh",
+ "setupCommands": [
+ {
+ "description": "Enable pretty-printing for gdb",
+ "text": "-enable-pretty-printing",
+ "ignoreFailures": true
+ }
+ ],
+ "preLaunchTask": "Build LTTng-tools"
+ },
+ ]
+}
\ No newline at end of file
--- /dev/null
+#!/usr/bin/env sh
+# Copyright (C) 2024 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+#
+# SPDX-License-Identifier: LGPL-2.1-only
+#
+# Wrapper script to setup the environment before invoking gdb
+# on the in-tree binaries (under `.libs`)
+
+libtool --mode=execute gdb "$@"
--- /dev/null
+{
+ "version": "2.0.0",
+ "tasks": [
+ {
+ "type": "shell",
+ "label": "Build LTTng-tools",
+ // Assumes you ran ./bootstrap and ./configure with your preferred options
+ "command": "${workspaceFolder}/.vscode/build.sh ${workspaceFolder}",
+ "options": {
+ "cwd": "${workspaceFolder}"
+ },
+ "problemMatcher": [
+ "$gcc"
+ ],
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ }
+ }
+ ]
+}
\ No newline at end of file
static unsigned long trace_chunk_registry_ht_key_hash(const struct trace_chunk_registry_ht_key *key)
{
- const uint64_t uuid_h1 = *reinterpret_cast<const uint64_t *>(&key->sessiond_uuid[0]);
- const uint64_t uuid_h2 = *reinterpret_cast<const uint64_t *>(&key->sessiond_uuid[1]);
+ const uint64_t uuid_h1 = reinterpret_cast<const uint64_t *>(key->sessiond_uuid.data())[0];
+ const uint64_t uuid_h2 = reinterpret_cast<const uint64_t *>(key->sessiond_uuid.data())[1];
return hash_key_u64(&uuid_h1, lttng_ht_seed) ^ hash_key_u64(&uuid_h2, lttng_ht_seed);
}
* on error.
*/
int lttng_consumer_send_error(struct lttng_consumer_local_data *ctx,
- enum lttcomm_return_code error_code);
+ enum lttcomm_return_code error_code);
/*
* Called from signal handler to ensure a clean exit.
goto end;
}
+ if (a->emission_site != b->emission_site) {
+ goto end;
+ }
+
is_equal = true;
end:
return is_equal;
# SPDX-License-Identifier: GPL-2.0-only
+EXTRA_DIST = common.hpp
+
noinst_PROGRAMS = validate_xml extract_xml pretty_xml
validate_xml_SOURCES = validate_xml.cpp
validate_xml_CPPFLAGS = $(libxml2_CFLAGS) $(AM_CPPFLAGS)
extract_xml_CPPFLAGS = $(libxml2_CFLAGS) $(AM_CPPFLAGS)
extract_xml_LDADD = $(libxml2_LIBS)
-pretty_xml_SOURCES = pretty_xml.c
+pretty_xml_SOURCES = pretty_xml.cpp
pretty_xml_CPPFLAGS = $(libxml2_CFLAGS) $(AM_CPPFLAGS)
pretty_xml_LDADD = $(libxml2_LIBS)
--- /dev/null
+/*
+ * Copyright (C) 2024 EfficiOS Inc.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#ifndef TESTS_UTILS_XML_UTILS_COMMON_HPP
+#define TESTS_UTILS_XML_UTILS_COMMON_HPP
+
+#include "common/make-unique-wrapper.hpp"
+
+#include <libxml/parser.h>
+#include <memory>
+
+namespace lttng {
+namespace libxml {
+
+using parser_ctx_uptr = std::unique_ptr<
+ xmlParserCtxt,
+ lttng::memory::create_deleter_class<xmlParserCtxt, xmlFreeParserCtxt>::deleter>;
+using doc_uptr =
+ std::unique_ptr<xmlDoc, lttng::memory::create_deleter_class<xmlDoc, xmlFreeDoc>::deleter>;
+
+/*
+ * Manage the global parser context of libxml2.
+ * There should only be one instance of this class per process.
+ */
+class global_parser_context {
+public:
+ global_parser_context()
+ {
+ xmlInitParser();
+ }
+
+ ~global_parser_context()
+ {
+ xmlCleanupParser();
+ }
+
+ /* Deactivate copy and assignment. */
+ global_parser_context(const global_parser_context&) = delete;
+ global_parser_context(global_parser_context&&) = delete;
+ global_parser_context& operator=(const global_parser_context&) = delete;
+ global_parser_context& operator=(global_parser_context&&) = delete;
+};
+} /* namespace libxml */
+} /* namespace lttng */
+#endif /* TESTS_UTILS_XML_UTILS_COMMON_HPP */
* node;b;
* node;c;
*/
+#include "common.hpp"
+
#include <common/defaults.hpp>
#include <libxml/parser.h>
#include <string.h>
#include <unistd.h>
+namespace ll = lttng::libxml;
+
#if defined(LIBXML_XPATH_ENABLED)
static int opt_verbose;
LTTNG_ASSERT(xml_path);
LTTNG_ASSERT(xpath);
+ ll::parser_ctx_uptr parserCtx{ xmlNewParserCtxt() };
+
+ if (!parserCtx) {
+ fprintf(stderr, "ERR: could not allocate an XML parser context\n");
+ return -1;
+ }
+
/* Parse the xml file */
- doc = xmlParseFile(xml_path);
+ doc = xmlCtxtReadFile(parserCtx.get(), xml_path, nullptr, XML_PARSE_NOBLANKS);
if (!doc) {
fprintf(stderr, "ERR parsing: xml file invalid \"%s\"\n", xml_path);
return -1;
/* Init libxml */
xmlInitParser();
- xmlKeepBlanksDefault(0);
if (access(argv[optind], F_OK)) {
fprintf(stderr, "ERR:%s\n", "Xml path not valid");
return -1;
+++ /dev/null
-/*
- * Copyright (C) 2021 EfficiOS Inc.
- *
- * SPDX-License-Identifier: GPL-2.0-only
- *
- */
-
-/*
- * Prettyfi a xml input from stdin to stddout.
- * This allows a more human friendly format for xml testing when problems occur.
- */
-
-#include <libxml/parser.h>
-
-int main(void)
-{
- xmlDocPtr doc = NULL;
-
- /* Init libxml. */
- xmlInitParser();
- xmlKeepBlanksDefault(0);
-
- /* Parse the XML document from stdin. */
- doc = xmlParseFile("-");
- if (!doc) {
- fprintf(stderr, "ERR parsing: xml input invalid");
- return -1;
- }
-
- xmlDocFormatDump(stdout, doc, 1);
-
- xmlFreeDoc(doc);
- /* Shutdown libxml. */
- xmlCleanupParser();
-
- return 0;
-}
--- /dev/null
+/*
+ * Copyright (C) 2021 EfficiOS Inc.
+ *
+ * SPDX-License-Identifier: GPL-2.0-only
+ *
+ */
+
+/*
+ * Prettyfi a xml input from stdin to stddout.
+ * This allows a more human friendly format for xml testing when problems occur.
+ */
+
+#include "common.hpp"
+
+#include <common/scope-exit.hpp>
+
+#include <iostream>
+#include <libxml/parser.h>
+#include <unistd.h>
+
+namespace ll = lttng::libxml;
+
+int main()
+{
+ const ll::global_parser_context global_parser_context;
+ const ll::parser_ctx_uptr parserCtx{ xmlNewParserCtxt() };
+
+ /* Parse the XML document from stdin. */
+ const ll::doc_uptr doc{ xmlCtxtReadFd(
+ parserCtx.get(), STDIN_FILENO, nullptr, nullptr, XML_PARSE_NOBLANKS) };
+ if (!doc) {
+ std::cerr << "Error: invalid XML input on stdin\n";
+ return -1;
+ }
+
+ xmlDocFormatDump(stdout, doc.get(), 1);
+
+ return 0;
+}