From 48a4000561343808724f7cb5fa8c131877489ccd Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 3 Sep 2021 17:31:28 -0400 Subject: [PATCH] bin: compile lttng as C++ MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Compile the code of the lttng binary as C++ source. - start by renaming all files under src/bin/lttng to have the .cpp extension, adjust Makefile.am accordingly - apply the sophisticated algorithm: while does_not_build(): fix_error() until completion Fixes fall in these categories: - add extern "C" to headers of functions implemented in C. This is likely temporary: at some point some of these things will be implemented in C++, at which point we'll remove the extern "C". - rename mi_lttng_version to mi_lttng_version_data, to avoid a -Wshadow warning about the mi_lttng_version function hiding the mi_lttng_version's struct constructor - we have the same warning about lttng_calibrate, but we can't rename it, it's exposed in a public header. Add some pragmas to disable the warning around there. We will need more macro smartness in case we need to support a compiler that doesn't understand these pragmas. - in filter-ast.h, add a dummy field to the empty struct, to avoid a -Wextern-c-compat warning with clang++ (it warns us that the struct has size 0 in C but size 1 in C++). - in add_context.cpp, we can't initialize ctx_opts' union field like we did in C. Fix that by adding a ctx_opts constructor for each kind of context and implement the PERF_* macros to use them. - need to explicitly cast void pointer to type of the destination, for example the eturn value of allocation functions, or parameter of "destroy" functions - need to explicitly cast when passing an int to an enum parameter, for example an lttng_error_code parameter - remove use of designated array initializers, for example for schedule_type_str in disable_rotation.cpp - fix order of struct initializers to match order of field declarations, for example in list_triggers.cpp, function cmd_list_triggers - rename some things to avoid clashing with keywords, for example in runas.h Change-Id: Id743b141552a412b4104af4dda8969eef5032388 Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau --- configure.ac | 3 + include/lttng/condition/condition-internal.h | 8 +++ .../lttng/event-rule/event-rule-internal.h | 8 +++ .../event-rule/kernel-syscall-internal.h | 9 +++ include/lttng/lttng.h | 3 + include/lttng/trigger/trigger-internal.h | 8 +++ src/bin/lttng/Makefile.am | 52 +++++++------- .../{add_context.c => add_context.cpp} | 68 +++++++++++++------ .../{add_trigger.c => add_trigger.cpp} | 14 ++-- src/bin/lttng/commands/{clear.c => clear.cpp} | 0 .../lttng/commands/{create.c => create.cpp} | 0 .../lttng/commands/{destroy.c => destroy.cpp} | 0 ...isable_channels.c => disable_channels.cpp} | 0 .../{disable_events.c => disable_events.cpp} | 8 +-- ...isable_rotation.c => disable_rotation.cpp} | 4 +- ...{enable_channels.c => enable_channels.cpp} | 0 .../{enable_events.c => enable_events.cpp} | 24 +++---- ...{enable_rotation.c => enable_rotation.cpp} | 4 +- src/bin/lttng/commands/{help.c => help.cpp} | 0 src/bin/lttng/commands/{list.c => list.cpp} | 8 +-- .../{list_triggers.c => list_triggers.cpp} | 2 +- src/bin/lttng/commands/{load.c => load.cpp} | 0 .../commands/{metadata.c => metadata.cpp} | 0 .../commands/{regenerate.c => regenerate.cpp} | 0 .../{remove_trigger.c => remove_trigger.cpp} | 0 .../lttng/commands/{rotate.c => rotate.cpp} | 2 +- src/bin/lttng/commands/{save.c => save.cpp} | 0 .../{set_session.c => set_session.cpp} | 0 .../commands/{snapshot.c => snapshot.cpp} | 4 +- src/bin/lttng/commands/{start.c => start.cpp} | 0 .../lttng/commands/{status.c => status.cpp} | 0 src/bin/lttng/commands/{stop.c => stop.cpp} | 0 .../{track-untrack.c => track-untrack.cpp} | 4 +- .../lttng/commands/{version.c => version.cpp} | 4 +- src/bin/lttng/commands/{view.c => view.cpp} | 0 src/bin/lttng/{conf.c => conf.cpp} | 2 +- src/bin/lttng/{loglevel.c => loglevel.cpp} | 16 ++--- src/bin/lttng/loglevel.h | 8 +++ src/bin/lttng/{lttng.c => lttng.cpp} | 0 src/bin/lttng/{uprobe.c => uprobe.cpp} | 22 +++--- src/bin/lttng/{utils.c => utils.cpp} | 0 src/common/argpar/argpar.h | 7 ++ src/common/compat/string.h | 2 +- src/common/dynamic-array.h | 12 +++- src/common/error.h | 8 +++ src/common/filter/filter-ast.h | 10 +++ src/common/mi-lttng.c | 2 +- src/common/mi-lttng.h | 12 +++- src/common/runas.h | 6 +- src/common/spawn-viewer.h | 8 +++ src/common/string-utils/string-utils.h | 8 +++ src/common/time.h | 8 +++ src/common/tracker.h | 8 +++ src/common/uri.h | 8 +++ src/common/utils.h | 8 +++ 55 files changed, 279 insertions(+), 113 deletions(-) rename src/bin/lttng/commands/{add_context.c => add_context.cpp} (94%) rename src/bin/lttng/commands/{add_trigger.c => add_trigger.cpp} (99%) rename src/bin/lttng/commands/{clear.c => clear.cpp} (100%) rename src/bin/lttng/commands/{create.c => create.cpp} (100%) rename src/bin/lttng/commands/{destroy.c => destroy.cpp} (100%) rename src/bin/lttng/commands/{disable_channels.c => disable_channels.cpp} (100%) rename src/bin/lttng/commands/{disable_events.c => disable_events.cpp} (97%) rename src/bin/lttng/commands/{disable_rotation.c => disable_rotation.cpp} (98%) rename src/bin/lttng/commands/{enable_channels.c => enable_channels.cpp} (100%) rename src/bin/lttng/commands/{enable_events.c => enable_events.cpp} (97%) rename src/bin/lttng/commands/{enable_rotation.c => enable_rotation.cpp} (98%) rename src/bin/lttng/commands/{help.c => help.cpp} (100%) rename src/bin/lttng/commands/{list.c => list.cpp} (99%) rename src/bin/lttng/commands/{list_triggers.c => list_triggers.cpp} (100%) rename src/bin/lttng/commands/{load.c => load.cpp} (100%) rename src/bin/lttng/commands/{metadata.c => metadata.cpp} (100%) rename src/bin/lttng/commands/{regenerate.c => regenerate.cpp} (100%) rename src/bin/lttng/commands/{remove_trigger.c => remove_trigger.cpp} (100%) rename src/bin/lttng/commands/{rotate.c => rotate.cpp} (98%) rename src/bin/lttng/commands/{save.c => save.cpp} (100%) rename src/bin/lttng/commands/{set_session.c => set_session.cpp} (100%) rename src/bin/lttng/commands/{snapshot.c => snapshot.cpp} (99%) rename src/bin/lttng/commands/{start.c => start.cpp} (100%) rename src/bin/lttng/commands/{status.c => status.cpp} (100%) rename src/bin/lttng/commands/{stop.c => stop.cpp} (100%) rename src/bin/lttng/commands/{track-untrack.c => track-untrack.cpp} (99%) rename src/bin/lttng/commands/{version.c => version.cpp} (97%) rename src/bin/lttng/commands/{view.c => view.cpp} (100%) rename src/bin/lttng/{conf.c => conf.cpp} (99%) rename src/bin/lttng/{loglevel.c => loglevel.cpp} (97%) rename src/bin/lttng/{lttng.c => lttng.cpp} (100%) rename src/bin/lttng/{uprobe.c => uprobe.cpp} (91%) rename src/bin/lttng/{utils.c => utils.cpp} (100%) diff --git a/configure.ac b/configure.ac index ea327f9b8..12cc7a17e 100644 --- a/configure.ac +++ b/configure.ac @@ -71,6 +71,9 @@ m4_define([WARN_FLAGS_LIST], [ dnl -Wmissing-parameter-type dnl -Wshadow dnl -Wno-gnu-folding-constant dnl + dnl GCC enables this with -Wall in C++, and that generates a + dnl lot of warnings that have on average a low value to fix. + -Wno-sign-compare dnl ]) # Pass -Werror as an extra flag during the test: this is needed to make the diff --git a/include/lttng/condition/condition-internal.h b/include/lttng/condition/condition-internal.h index 5bafaf05b..a491d3fe3 100644 --- a/include/lttng/condition/condition-internal.h +++ b/include/lttng/condition/condition-internal.h @@ -19,6 +19,10 @@ #include #include +#if defined(__cplusplus) +extern "C" { +#endif + struct mi_writer; struct mi_lttng_error_query_callbacks; struct lttng_trigger; @@ -82,4 +86,8 @@ enum lttng_error_code lttng_condition_mi_serialize( const char *lttng_condition_type_str(enum lttng_condition_type type); +#if defined(__cplusplus) +} +#endif + #endif /* LTTNG_CONDITION_INTERNAL_H */ diff --git a/include/lttng/event-rule/event-rule-internal.h b/include/lttng/event-rule/event-rule-internal.h index 802674863..98d1f449d 100644 --- a/include/lttng/event-rule/event-rule-internal.h +++ b/include/lttng/event-rule/event-rule-internal.h @@ -20,6 +20,10 @@ #include #include +#if defined(__cplusplus) +extern "C" { +#endif + struct lttng_payload; struct lttng_payload_view; struct mi_writer; @@ -153,4 +157,8 @@ bool lttng_event_rule_targets_agent_domain(const struct lttng_event_rule *rule); enum lttng_error_code lttng_event_rule_mi_serialize( const struct lttng_event_rule *rule, struct mi_writer *writer); +#if defined(__cplusplus) +} +#endif + #endif /* LTTNG_EVENT_RULE_INTERNAL_H */ diff --git a/include/lttng/event-rule/kernel-syscall-internal.h b/include/lttng/event-rule/kernel-syscall-internal.h index 31905cef6..3e5e0991d 100644 --- a/include/lttng/event-rule/kernel-syscall-internal.h +++ b/include/lttng/event-rule/kernel-syscall-internal.h @@ -13,6 +13,10 @@ #include #include +#if defined(__cplusplus) +extern "C" { +#endif + struct lttng_event_rule_kernel_syscall { struct lttng_event_rule parent; enum lttng_event_rule_kernel_syscall_emission_site emission_site; @@ -46,4 +50,9 @@ ssize_t lttng_event_rule_kernel_syscall_create_from_payload( const char *lttng_event_rule_kernel_syscall_emission_site_str( enum lttng_event_rule_kernel_syscall_emission_site emission_site); + +#if defined(__cplusplus) +} +#endif + #endif /* LTTNG_EVENT_RULE_KERNEL_SYSCALL_INTERNAL_H */ diff --git a/include/lttng/lttng.h b/include/lttng/lttng.h index 5f3df9113..01c4089e5 100644 --- a/include/lttng/lttng.h +++ b/include/lttng/lttng.h @@ -148,8 +148,11 @@ extern int lttng_stop_tracing_no_wait(const char *session_name); * Deprecated: As of LTTng 2.9, this function always returns * -LTTNG_ERR_UND. */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" extern int lttng_calibrate(struct lttng_handle *handle, struct lttng_calibrate *calibrate); +#pragma GCC diagnostic pop /* * Set URL for a consumer for a session and domain. diff --git a/include/lttng/trigger/trigger-internal.h b/include/lttng/trigger/trigger-internal.h index dab46ae07..69226bce7 100644 --- a/include/lttng/trigger/trigger-internal.h +++ b/include/lttng/trigger/trigger-internal.h @@ -19,6 +19,10 @@ #include #include +#if defined(__cplusplus) +extern "C" { +#endif + struct lttng_payload; struct lttng_payload_view; struct mi_writer; @@ -278,4 +282,8 @@ enum lttng_trigger_status lttng_trigger_add_action_error_query_results( enum lttng_trigger_status lttng_trigger_set_name( struct lttng_trigger *trigger, const char *name); +#if defined(__cplusplus) +} +#endif + #endif /* LTTNG_TRIGGER_INTERNAL_H */ diff --git a/src/bin/lttng/Makefile.am b/src/bin/lttng/Makefile.am index 50ab92988..5d01c45a8 100644 --- a/src/bin/lttng/Makefile.am +++ b/src/bin/lttng/Makefile.am @@ -10,33 +10,33 @@ AUTOMAKE_OPTIONS = subdir-objects bin_PROGRAMS = lttng -lttng_SOURCES = command.h conf.c conf.h commands/start.c \ - commands/list.c commands/create.c commands/destroy.c \ - commands/stop.c commands/enable_events.c \ - commands/disable_events.c commands/enable_channels.c \ - commands/disable_channels.c commands/add_context.c \ - commands/set_session.c commands/version.c \ - commands/view.c \ - commands/snapshot.c \ - commands/save.c \ - commands/load.c \ - commands/track-untrack.c \ - commands/status.c \ - commands/metadata.c \ - commands/regenerate.c \ - commands/help.c \ - commands/rotate.c \ - commands/enable_rotation.c \ - commands/disable_rotation.c \ - commands/clear.c \ - loglevel.c loglevel.h \ - commands/add_trigger.c \ - commands/list_triggers.c \ - commands/remove_trigger.c \ - utils.c utils.h lttng.c \ - uprobe.c uprobe.h +lttng_SOURCES = command.h conf.cpp conf.h commands/start.cpp \ + commands/list.cpp commands/create.cpp commands/destroy.cpp \ + commands/stop.cpp commands/enable_events.cpp \ + commands/disable_events.cpp commands/enable_channels.cpp \ + commands/disable_channels.cpp commands/add_context.cpp \ + commands/set_session.cpp commands/version.cpp \ + commands/view.cpp \ + commands/snapshot.cpp \ + commands/save.cpp \ + commands/load.cpp \ + commands/track-untrack.cpp \ + commands/status.cpp \ + commands/metadata.cpp \ + commands/regenerate.cpp \ + commands/help.cpp \ + commands/rotate.cpp \ + commands/enable_rotation.cpp \ + commands/disable_rotation.cpp \ + commands/clear.cpp \ + loglevel.cpp loglevel.h \ + commands/add_trigger.cpp \ + commands/list_triggers.cpp \ + commands/remove_trigger.cpp \ + utils.cpp utils.h lttng.cpp \ + uprobe.cpp uprobe.h -lttng_CFLAGS = $(AM_CFLAGS) $(POPT_CFLAGS) +lttng_CXXFLAGS = $(AM_CXXFLAGS) $(POPT_CFLAGS) lttng_LDADD = $(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la \ $(top_builddir)/src/common/libcommon.la \ diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.cpp similarity index 94% rename from src/bin/lttng/commands/add_context.c rename to src/bin/lttng/commands/add_context.cpp index 90a54f7ee..d078471d3 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.cpp @@ -185,25 +185,21 @@ static struct poptOption long_options[] = { */ #define PERF_HW(optstr, name, type, hide) \ { \ - (char *) optstr, type, hide, \ - .u.perf = { PERF_TYPE_HARDWARE, PERF_COUNT_HW_##name, },\ + optstr, type, PERF_COUNT_HW_##name, hide \ } #define PERF_SW(optstr, name, type, hide) \ { \ - (char *) optstr, type, hide, \ - .u.perf = { PERF_TYPE_SOFTWARE, PERF_COUNT_SW_##name, },\ + optstr, type, PERF_COUNT_SW_##name, hide \ } #define _PERF_HW_CACHE(optstr, name, type, op, result, hide) \ { \ - (char *) optstr, type, hide, \ - .u.perf = { \ - PERF_TYPE_HW_CACHE, \ - (uint64_t) PERF_COUNT_HW_CACHE_##name \ - | ((uint64_t) PERF_COUNT_HW_CACHE_OP_##op << 8) \ - | ((uint64_t) PERF_COUNT_HW_CACHE_RESULT_##result << 16), \ - }, \ + optstr, type, \ + PERF_COUNT_HW_CACHE_##name, \ + PERF_COUNT_HW_CACHE_OP_##op, \ + PERF_COUNT_HW_CACHE_RESULT_##result, \ + hide, \ } #define PERF_HW_CACHE(optstr, name, type, hide) \ @@ -222,9 +218,43 @@ static struct poptOption long_options[] = { static const struct ctx_opts { + /* Needed for end-of-list item. */ + ctx_opts() + : symbol(nullptr) + {} + + ctx_opts(const char *symbol_, context_type ctx_type_, bool hide_help_ = false) + : symbol((char *) symbol_), ctx_type(ctx_type_), hide_help(hide_help_) + {} + + ctx_opts(const char *symbol_, context_type ctx_type_, perf_count_hard perf_count_hard, bool hide_help_) + : ctx_opts(symbol_, ctx_type_, hide_help_) + { + u.perf.type = PERF_TYPE_HARDWARE; + u.perf.config = perf_count_hard; + } + + ctx_opts(const char *symbol_, context_type ctx_type_, perf_count_soft perf_count_soft, bool hide_help_) + : ctx_opts(symbol_, ctx_type_, hide_help_) + { + u.perf.type = PERF_TYPE_SOFTWARE; + u.perf.config = perf_count_soft; + } + + ctx_opts(const char *symbol_, context_type ctx_type_, + perf_hw_cache_id perf_hw_cache_id, + perf_hw_cache_op_id perf_hw_cache_op_id, + perf_hw_cache_op_result_id perf_hw_cache_op_result_id, + bool hide_help_) + : ctx_opts(symbol_, ctx_type_, hide_help_) + { + u.perf.type = PERF_TYPE_HW_CACHE; + u.perf.config = perf_hw_cache_id | perf_hw_cache_op_id << 8 | perf_hw_cache_op_result_id << 16; + } + char *symbol; enum context_type ctx_type; - int hide_help; /* Hide from --help */ + bool hide_help; /* Hide from --help */ union { struct { uint32_t type; @@ -496,7 +526,7 @@ const struct ctx_opts { PERF_SW("perf:emulation-faults", EMULATION_FAULTS, CONTEXT_PERF_COUNTER, 1), - { NULL, -1 }, /* Closure */ + {}, /* Closure */ }; #undef PERF_HW_CACHE @@ -744,7 +774,7 @@ int print_ctx_type(void) } end: - ret = mi_close(ret); + ret = mi_close((cmd_error_code) ret); if (ret) { ret = CMD_ERROR; } @@ -878,14 +908,14 @@ void destroy_ctx_type(struct ctx_type *type) static struct ctx_type *create_ctx_type(void) { - struct ctx_type *type = zmalloc(sizeof(*type)); + struct ctx_type *type = (ctx_type *) zmalloc(sizeof(*type)); if (!type) { PERROR("malloc ctx_type"); goto end; } - type->opt = zmalloc(sizeof(*type->opt)); + type->opt = (struct ctx_opts *) zmalloc(sizeof(*type->opt)); if (!type->opt) { PERROR("malloc ctx_type options"); destroy_ctx_type(type); @@ -1060,7 +1090,7 @@ struct ctx_type *get_context_type(const char *ctx) } provider_name_len = colon_pos - sizeof(app_ctx_prefix) + 2; - provider_name = zmalloc(provider_name_len); + provider_name = (char *) zmalloc(provider_name_len); if (!provider_name) { PERROR("malloc provider_name"); goto not_found; @@ -1070,7 +1100,7 @@ struct ctx_type *get_context_type(const char *ctx) type->opt->u.app_ctx.provider_name = provider_name; ctx_name_len = len - colon_pos; - ctx_name = zmalloc(ctx_name_len); + ctx_name = (char *) zmalloc(ctx_name_len); if (!ctx_name) { PERROR("malloc ctx_name"); goto not_found; @@ -1180,7 +1210,7 @@ int cmd_add_context(int argc, const char **argv) } command_ret = add_context(session_name); - ret = mi_close(command_ret); + ret = mi_close((cmd_error_code) command_ret); if (ret) { goto end; } diff --git a/src/bin/lttng/commands/add_trigger.c b/src/bin/lttng/commands/add_trigger.cpp similarity index 99% rename from src/bin/lttng/commands/add_trigger.c rename to src/bin/lttng/commands/add_trigger.cpp index 27f6cc8c6..939d51080 100644 --- a/src/bin/lttng/commands/add_trigger.c +++ b/src/bin/lttng/commands/add_trigger.cpp @@ -635,7 +635,7 @@ struct lttng_event_expr *ir_op_root_to_event_expr(const struct ir_op *ir, static void destroy_event_expr(void *ptr) { - lttng_event_expr_destroy(ptr); + lttng_event_expr_destroy((lttng_event_expr *) ptr); } struct parse_event_rule_res { @@ -1040,7 +1040,7 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) for (n = 0; n < count; n++) { const char *exclude_name = - lttng_dynamic_pointer_array_get_pointer( + (const char *) lttng_dynamic_pointer_array_get_pointer( &exclude_names, n); @@ -1382,7 +1382,7 @@ struct lttng_condition *handle_condition_event(int *argc, const char ***argv) i++) { enum lttng_condition_status status; struct lttng_event_expr **expr = - lttng_dynamic_array_get_element( + (lttng_event_expr **) lttng_dynamic_array_get_element( &res.capture_descriptors.array, i); LTTNG_ASSERT(expr); @@ -1485,8 +1485,8 @@ static struct lttng_rate_policy *parse_rate_policy(const char *policy_str) goto end; } - policy_type_str = lttng_dynamic_pointer_array_get_pointer(&tokens, 0); - policy_value_str = lttng_dynamic_pointer_array_get_pointer(&tokens, 1); + policy_type_str = (char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 0); + policy_value_str = (char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 1); /* Parse the type. */ if (strcmp(policy_type_str, "once-after") == 0) { @@ -2167,7 +2167,7 @@ struct argpar_opt_descr add_trigger_options[] = { static void lttng_actions_destructor(void *p) { - struct lttng_action *action = p; + struct lttng_action *action = (lttng_action *) p; lttng_action_destroy(action); } @@ -2352,7 +2352,7 @@ int cmd_add_trigger(int argc, const char **argv) for (i = 0; i < lttng_dynamic_pointer_array_get_count(&actions); i++) { enum lttng_action_status status; - action = lttng_dynamic_pointer_array_steal_pointer(&actions, i); + action = (lttng_action *) lttng_dynamic_pointer_array_steal_pointer(&actions, i); status = lttng_action_list_add_action(action_list, action); if (status != LTTNG_ACTION_STATUS_OK) { diff --git a/src/bin/lttng/commands/clear.c b/src/bin/lttng/commands/clear.cpp similarity index 100% rename from src/bin/lttng/commands/clear.c rename to src/bin/lttng/commands/clear.cpp diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.cpp similarity index 100% rename from src/bin/lttng/commands/create.c rename to src/bin/lttng/commands/create.cpp diff --git a/src/bin/lttng/commands/destroy.c b/src/bin/lttng/commands/destroy.cpp similarity index 100% rename from src/bin/lttng/commands/destroy.c rename to src/bin/lttng/commands/destroy.cpp diff --git a/src/bin/lttng/commands/disable_channels.c b/src/bin/lttng/commands/disable_channels.cpp similarity index 100% rename from src/bin/lttng/commands/disable_channels.c rename to src/bin/lttng/commands/disable_channels.cpp diff --git a/src/bin/lttng/commands/disable_events.c b/src/bin/lttng/commands/disable_events.cpp similarity index 97% rename from src/bin/lttng/commands/disable_events.c rename to src/bin/lttng/commands/disable_events.cpp index 687da1f92..5ce36e50a 100644 --- a/src/bin/lttng/commands/disable_events.c +++ b/src/bin/lttng/commands/disable_events.cpp @@ -213,7 +213,7 @@ static int disable_events(char *session_name) event.loglevel = -1; /* opt_event_type contain the event type to disable at this point */ - event.type = opt_event_type; + event.type = (lttng_event_type) opt_event_type; if (opt_disable_all) { command_ret = lttng_disable_event_ext(handle, &event, channel_name, NULL); @@ -227,7 +227,7 @@ static int disable_events(char *session_name) success = 1; MSG("All %s events of type %s are disabled in channel %s", lttng_domain_type_str(dom.type), - print_event_type(opt_event_type), + print_event_type((lttng_event_type) opt_event_type), print_channel_name(channel_name)); } @@ -250,7 +250,7 @@ static int disable_events(char *session_name) if (command_ret < 0) { ERR("%s of type %s : %s (channel %s, session %s)", event_name, - print_event_type(opt_event_type), + print_event_type((lttng_event_type) opt_event_type), lttng_strerror(command_ret), command_ret == -LTTNG_ERR_NEED_CHANNEL_NAME ? print_raw_channel_name(channel_name) @@ -267,7 +267,7 @@ static int disable_events(char *session_name) MSG("%s %s of type %s disabled in channel %s for session %s", lttng_domain_type_str(dom.type), event_name, - print_event_type(opt_event_type), + print_event_type((lttng_event_type) opt_event_type), print_channel_name(channel_name), session_name); success = 1; diff --git a/src/bin/lttng/commands/disable_rotation.c b/src/bin/lttng/commands/disable_rotation.cpp similarity index 98% rename from src/bin/lttng/commands/disable_rotation.c rename to src/bin/lttng/commands/disable_rotation.cpp index ff5749c97..8229f63e0 100644 --- a/src/bin/lttng/commands/disable_rotation.c +++ b/src/bin/lttng/commands/disable_rotation.cpp @@ -49,8 +49,8 @@ static struct poptOption long_options[] = { }; static const char *schedule_type_str[] = { - [LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC] = "periodic", - [LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD] = "size-based", + "periodic", + "size-based", }; static const struct lttng_rotation_schedule *get_schedule( diff --git a/src/bin/lttng/commands/enable_channels.c b/src/bin/lttng/commands/enable_channels.cpp similarity index 100% rename from src/bin/lttng/commands/enable_channels.c rename to src/bin/lttng/commands/enable_channels.cpp diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.cpp similarity index 97% rename from src/bin/lttng/commands/enable_events.c rename to src/bin/lttng/commands/enable_events.cpp index bbf7c5699..50854faaa 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.cpp @@ -212,7 +212,7 @@ int mi_print_exclusion(const struct lttng_dynamic_pointer_array *exclusions) } for (i = 0; i < count; i++) { - const char *exclusion = lttng_dynamic_pointer_array_get_pointer( + const char *exclusion = (const char *) lttng_dynamic_pointer_array_get_pointer( exclusions, i); ret = mi_lttng_writer_write_element_string(writer, @@ -247,21 +247,21 @@ char *print_exclusions(const struct lttng_dynamic_pointer_array *exclusions) /* Calculate total required length. */ for (i = 0; i < count; i++) { - const char *exclusion = lttng_dynamic_pointer_array_get_pointer( + const char *exclusion = (const char *) lttng_dynamic_pointer_array_get_pointer( exclusions, i); length += strlen(exclusion) + 4; } length += sizeof(preamble); - ret = zmalloc(length); + ret = (char *) zmalloc(length); if (!ret) { return NULL; } strncpy(ret, preamble, length); for (i = 0; i < count; i++) { - const char *exclusion = lttng_dynamic_pointer_array_get_pointer( + const char *exclusion = (const char *) lttng_dynamic_pointer_array_get_pointer( exclusions, i); strcat(ret, "\""); @@ -359,7 +359,7 @@ int validate_exclusion_list(const char *event_name, for (i = 0; i < num_exclusions; i++) { const char *exclusion = - lttng_dynamic_pointer_array_get_pointer( + (const char *) lttng_dynamic_pointer_array_get_pointer( exclusions, i); if (!strutils_is_star_glob_pattern(exclusion) || @@ -416,7 +416,7 @@ static void warn_on_truncated_exclusion_names(const struct lttng_dynamic_pointer const size_t num_exclusions = lttng_dynamic_pointer_array_get_count(exclusions); for (i = 0; i < num_exclusions; i++) { - const char * const exclusion = lttng_dynamic_pointer_array_get_pointer(exclusions, i); + const char * const exclusion = (const char *) lttng_dynamic_pointer_array_get_pointer(exclusions, i); if (strlen(exclusion) >= LTTNG_SYMBOL_NAME_LEN) { WARN("Event exclusion \"%s\" will be truncated", @@ -512,7 +512,7 @@ static int enable_events(char *session_name) case LTTNG_EVENT_USERSPACE_PROBE: case LTTNG_EVENT_FUNCTION: ERR("Filter expressions are not supported for %s events", - get_event_type_str(opt_event_type)); + get_event_type_str((lttng_event_type) opt_event_type)); ret = CMD_ERROR; goto error; default: @@ -542,14 +542,14 @@ static int enable_events(char *session_name) if (opt_enable_all) { /* Default setup for enable all */ if (opt_kernel) { - ev->type = opt_event_type; + ev->type = (lttng_event_type) opt_event_type; strcpy(ev->name, "*"); /* kernel loglevels not implemented */ ev->loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; } else { ev->type = LTTNG_EVENT_TRACEPOINT; strcpy(ev->name, "*"); - ev->loglevel_type = opt_loglevel_type; + ev->loglevel_type = (lttng_loglevel_type) opt_loglevel_type; if (opt_loglevel) { int name_search_ret; @@ -817,7 +817,7 @@ static int enable_events(char *session_name) /* Copy name and type of the event */ strncpy(ev->name, event_name, LTTNG_SYMBOL_NAME_LEN); ev->name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; - ev->type = opt_event_type; + ev->type = (lttng_event_type) opt_event_type; /* Kernel tracer action */ if (opt_kernel) { @@ -935,7 +935,7 @@ static int enable_events(char *session_name) &exclusions, &warn); } - ev->loglevel_type = opt_loglevel_type; + ev->loglevel_type = (lttng_loglevel_type) opt_loglevel_type; if (opt_loglevel) { enum lttng_loglevel loglevel; const int name_search_ret = loglevel_name_to_value(opt_loglevel, &loglevel); @@ -958,7 +958,7 @@ static int enable_events(char *session_name) goto error; } - ev->loglevel_type = opt_loglevel_type; + ev->loglevel_type = (lttng_loglevel_type) opt_loglevel_type; if (opt_loglevel) { int name_search_ret; diff --git a/src/bin/lttng/commands/enable_rotation.c b/src/bin/lttng/commands/enable_rotation.cpp similarity index 98% rename from src/bin/lttng/commands/enable_rotation.c rename to src/bin/lttng/commands/enable_rotation.cpp index c10c6a2d7..0210f9cb6 100644 --- a/src/bin/lttng/commands/enable_rotation.c +++ b/src/bin/lttng/commands/enable_rotation.cpp @@ -50,8 +50,8 @@ static struct poptOption long_options[] = { }; static const char *schedule_type_str[] = { - [LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC] = "periodic", - [LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD] = "size-based", + "periodic", + "size-based", }; static enum cmd_error_code add_schedule(const char *session_name, diff --git a/src/bin/lttng/commands/help.c b/src/bin/lttng/commands/help.cpp similarity index 100% rename from src/bin/lttng/commands/help.c rename to src/bin/lttng/commands/help.cpp diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.cpp similarity index 99% rename from src/bin/lttng/commands/list.c rename to src/bin/lttng/commands/list.cpp index f4c97cbd1..4bb681e09 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.cpp @@ -91,7 +91,7 @@ static char *get_cmdline_by_pid(pid_t pid) } /* Caller must free() *cmdline */ - cmdline = zmalloc(PATH_MAX); + cmdline = (char *) zmalloc(PATH_MAX); if (!cmdline) { PERROR("malloc cmdline"); goto end; @@ -207,7 +207,7 @@ static char *get_exclusion_names_msg(struct lttng_event *event) * a comma per entry, the entry count (fixed-size), a closing * bracket, and a trailing \0. */ - exclusion_msg = malloc(exclusion_count + + exclusion_msg = (char *) malloc(exclusion_count + exclusion_count * LTTNG_SYMBOL_NAME_LEN + exclusion_fmt_len + 1); if (!exclusion_msg) { @@ -340,7 +340,7 @@ static void print_events(struct lttng_event *event) } else if (filter_str) { const char * const filter_fmt = " [filter: '%s']"; - filter_msg = malloc(strlen(filter_str) + + filter_msg = (char *) malloc(strlen(filter_str) + strlen(filter_fmt) + 1); if (filter_msg) { sprintf(filter_msg, filter_fmt, @@ -1154,7 +1154,7 @@ static int list_session_agent_events(void) const char * const filter_fmt = " [filter: '%s']"; - filter_msg = malloc(strlen(filter_str) + + filter_msg = (char *) malloc(strlen(filter_str) + strlen(filter_fmt) + 1); if (filter_msg) { sprintf(filter_msg, filter_fmt, diff --git a/src/bin/lttng/commands/list_triggers.c b/src/bin/lttng/commands/list_triggers.cpp similarity index 100% rename from src/bin/lttng/commands/list_triggers.c rename to src/bin/lttng/commands/list_triggers.cpp index 50c5894df..9a57714b6 100644 --- a/src/bin/lttng/commands/list_triggers.c +++ b/src/bin/lttng/commands/list_triggers.cpp @@ -1395,8 +1395,8 @@ int cmd_list_triggers(int argc, const char **argv) if (lttng_opt_mi) { const struct mi_lttng_error_query_callbacks callbacks = { .trigger_cb = mi_error_query_trigger_callback, - .action_cb = mi_error_query_action_callback, .condition_cb = mi_error_query_condition_callback, + .action_cb = mi_error_query_action_callback, }; ret = lttng_triggers_mi_serialize( diff --git a/src/bin/lttng/commands/load.c b/src/bin/lttng/commands/load.cpp similarity index 100% rename from src/bin/lttng/commands/load.c rename to src/bin/lttng/commands/load.cpp diff --git a/src/bin/lttng/commands/metadata.c b/src/bin/lttng/commands/metadata.cpp similarity index 100% rename from src/bin/lttng/commands/metadata.c rename to src/bin/lttng/commands/metadata.cpp diff --git a/src/bin/lttng/commands/regenerate.c b/src/bin/lttng/commands/regenerate.cpp similarity index 100% rename from src/bin/lttng/commands/regenerate.c rename to src/bin/lttng/commands/regenerate.cpp diff --git a/src/bin/lttng/commands/remove_trigger.c b/src/bin/lttng/commands/remove_trigger.cpp similarity index 100% rename from src/bin/lttng/commands/remove_trigger.c rename to src/bin/lttng/commands/remove_trigger.cpp diff --git a/src/bin/lttng/commands/rotate.c b/src/bin/lttng/commands/rotate.cpp similarity index 98% rename from src/bin/lttng/commands/rotate.c rename to src/bin/lttng/commands/rotate.cpp index aa0923cc2..63cf3882a 100644 --- a/src/bin/lttng/commands/rotate.c +++ b/src/bin/lttng/commands/rotate.cpp @@ -221,7 +221,7 @@ int cmd_rotate(int argc, const char **argv) } } - cmd_ret = rotate_tracing(session_name); + cmd_ret = (cmd_error_code) rotate_tracing(session_name); /* Mi closing */ if (lttng_opt_mi) { diff --git a/src/bin/lttng/commands/save.c b/src/bin/lttng/commands/save.cpp similarity index 100% rename from src/bin/lttng/commands/save.c rename to src/bin/lttng/commands/save.cpp diff --git a/src/bin/lttng/commands/set_session.c b/src/bin/lttng/commands/set_session.cpp similarity index 100% rename from src/bin/lttng/commands/set_session.c rename to src/bin/lttng/commands/set_session.cpp diff --git a/src/bin/lttng/commands/snapshot.c b/src/bin/lttng/commands/snapshot.cpp similarity index 99% rename from src/bin/lttng/commands/snapshot.c rename to src/bin/lttng/commands/snapshot.cpp index c37e09a7d..8e19fa3d8 100644 --- a/src/bin/lttng/commands/snapshot.c +++ b/src/bin/lttng/commands/snapshot.cpp @@ -520,7 +520,7 @@ static enum cmd_error_code handle_command(const char **argv) * hack works since the values of the * two enums do not intersect. */ - cmd_ret = result; + cmd_ret = (cmd_error_code) result; break; case -LTTNG_ERR_SNAPSHOT_NODATA: WARN("%s", lttng_strerror(result)); @@ -610,7 +610,7 @@ int cmd_snapshot(int argc, const char **argv) /* SHOW_HELP assigns to ret. */ SHOW_HELP(); - cmd_ret = ret; + cmd_ret = (cmd_error_code) ret; goto end; } case OPT_LIST_OPTIONS: diff --git a/src/bin/lttng/commands/start.c b/src/bin/lttng/commands/start.cpp similarity index 100% rename from src/bin/lttng/commands/start.c rename to src/bin/lttng/commands/start.cpp diff --git a/src/bin/lttng/commands/status.c b/src/bin/lttng/commands/status.cpp similarity index 100% rename from src/bin/lttng/commands/status.c rename to src/bin/lttng/commands/status.cpp diff --git a/src/bin/lttng/commands/stop.c b/src/bin/lttng/commands/stop.cpp similarity index 100% rename from src/bin/lttng/commands/stop.c rename to src/bin/lttng/commands/stop.cpp diff --git a/src/bin/lttng/commands/track-untrack.c b/src/bin/lttng/commands/track-untrack.cpp similarity index 99% rename from src/bin/lttng/commands/track-untrack.c rename to src/bin/lttng/commands/track-untrack.cpp index f175e2a86..7db44883b 100644 --- a/src/bin/lttng/commands/track-untrack.c +++ b/src/bin/lttng/commands/track-untrack.cpp @@ -529,7 +529,7 @@ static enum cmd_error_code run_command(enum cmd_type cmd_type, bool error_occurred = false; for (i = 0; i < string_arg_count; i++) { - const char *arg = lttng_dynamic_pointer_array_get_pointer( + const char *arg = (const char *) lttng_dynamic_pointer_array_get_pointer( &command_args->string_args, i); cmd_ret = run_command_string(cmd_type, session_name, @@ -583,7 +583,7 @@ static int cmd_track_untrack(enum cmd_type cmd_type, size_t i; for (i = 0; i < command_count; i++) { - process_attr_command_init(&process_attr_commands[i], i); + process_attr_command_init(&process_attr_commands[i], (lttng_process_attr) i); } if (argc < 1) { diff --git a/src/bin/lttng/commands/version.c b/src/bin/lttng/commands/version.cpp similarity index 97% rename from src/bin/lttng/commands/version.c rename to src/bin/lttng/commands/version.cpp index 9f606bf44..ccc7f6633 100644 --- a/src/bin/lttng/commands/version.c +++ b/src/bin/lttng/commands/version.cpp @@ -42,7 +42,7 @@ static struct poptOption long_options[] = { /* * create_version */ -static void create_version(struct mi_lttng_version *version) +static void create_version(struct mi_lttng_version_data *version) { strncpy(version->version, VERSION, NAME_MAX); version->version_major = VERSION_MAJOR; @@ -60,7 +60,7 @@ static int print_mi(void) { int ret = CMD_SUCCESS; struct mi_writer *writer = NULL; - struct mi_lttng_version version; + struct mi_lttng_version_data version; create_version(&version); diff --git a/src/bin/lttng/commands/view.c b/src/bin/lttng/commands/view.cpp similarity index 100% rename from src/bin/lttng/commands/view.c rename to src/bin/lttng/commands/view.cpp diff --git a/src/bin/lttng/conf.c b/src/bin/lttng/conf.cpp similarity index 99% rename from src/bin/lttng/conf.c rename to src/bin/lttng/conf.cpp index 4079d6ed9..e347c4b3a 100644 --- a/src/bin/lttng/conf.c +++ b/src/bin/lttng/conf.cpp @@ -178,7 +178,7 @@ int _config_read_session_name(const char *path, char **name) #define NAME_MAX_SCANF_IS_A_BROKEN_API "254" #endif - session_name = zmalloc(NAME_MAX); + session_name = (char *) zmalloc(NAME_MAX); if (session_name == NULL) { ret = -ENOMEM; ERR("Out of memory"); diff --git a/src/bin/lttng/loglevel.c b/src/bin/lttng/loglevel.cpp similarity index 97% rename from src/bin/lttng/loglevel.c rename to src/bin/lttng/loglevel.cpp index 054510e85..83c7b3048 100644 --- a/src/bin/lttng/loglevel.c +++ b/src/bin/lttng/loglevel.cpp @@ -231,8 +231,8 @@ bool loglevel_parse_range_string(const char *str, bool ret = loglevel_parse_range_string_common(str, loglevel_values, ARRAY_SIZE(loglevel_values), &min_int, &max_int); - *min = min_int; - *max = max_int; + *min = (lttng_loglevel) min_int; + *max = (lttng_loglevel) max_int; return ret; } @@ -261,8 +261,8 @@ bool loglevel_log4j_parse_range_string(const char *str, loglevel_log4j_values, ARRAY_SIZE(loglevel_log4j_values), &min_int, &max_int); - *min = min_int; - *max = max_int; + *min = (lttng_loglevel_log4j) min_int; + *max = (lttng_loglevel_log4j) max_int; return ret; } @@ -290,8 +290,8 @@ bool loglevel_jul_parse_range_string(const char *str, bool ret = loglevel_parse_range_string_common(str, loglevel_jul_values, ARRAY_SIZE(loglevel_jul_values), &min_int, &max_int); - *min = min_int; - *max = max_int; + *min = (lttng_loglevel_jul) min_int; + *max = (lttng_loglevel_jul) max_int; return ret; } @@ -320,8 +320,8 @@ bool loglevel_python_parse_range_string(const char *str, loglevel_python_values, ARRAY_SIZE(loglevel_python_values), &min_int, &max_int); - *min = min_int; - *max = max_int; + *min = (lttng_loglevel_python) min_int; + *max = (lttng_loglevel_python) max_int; return ret; } diff --git a/src/bin/lttng/loglevel.h b/src/bin/lttng/loglevel.h index 43ae8e448..06dcbaa86 100644 --- a/src/bin/lttng/loglevel.h +++ b/src/bin/lttng/loglevel.h @@ -11,6 +11,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + int loglevel_name_to_value(const char *name, enum lttng_loglevel *loglevel); bool loglevel_parse_range_string(const char *str, @@ -46,4 +50,8 @@ const char *loglevel_jul_value_to_name(int loglevel); const char *loglevel_python_value_to_name(int loglevel); +#ifdef __cplusplus +} +#endif + #endif /* _LTTNG_LOGLEVEL_UTILS_H */ diff --git a/src/bin/lttng/lttng.c b/src/bin/lttng/lttng.cpp similarity index 100% rename from src/bin/lttng/lttng.c rename to src/bin/lttng/lttng.cpp diff --git a/src/bin/lttng/uprobe.c b/src/bin/lttng/uprobe.cpp similarity index 91% rename from src/bin/lttng/uprobe.c rename to src/bin/lttng/uprobe.cpp index 2a2890184..7a119ae61 100644 --- a/src/bin/lttng/uprobe.c +++ b/src/bin/lttng/uprobe.cpp @@ -57,7 +57,7 @@ int walk_command_search_path(const char *binary, char *binary_full_path) * This char array is used to concatenate path to binary to look for * the binary. */ - tentative_binary_path = zmalloc(LTTNG_PATH_MAX * sizeof(char)); + tentative_binary_path = (char *) zmalloc(LTTNG_PATH_MAX * sizeof(char)); if (!tentative_binary_path) { ret = -1; goto alloc_error; @@ -238,12 +238,12 @@ int parse_userspace_probe_opts(const char *opt, case 2: /* When the probe type is omitted we assume ELF for now. */ case 3: - if (num_token == 3 && strcmp(lttng_dynamic_pointer_array_get_pointer(&tokens, 0), "elf") == 0) { - target_path = lttng_dynamic_pointer_array_get_pointer(&tokens, 1); - symbol_name = lttng_dynamic_pointer_array_get_pointer(&tokens, 2); + if (num_token == 3 && strcmp((const char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 0), "elf") == 0) { + target_path = (char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 1); + symbol_name = (char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 2); } else if (num_token == 2) { - target_path = lttng_dynamic_pointer_array_get_pointer(&tokens, 0); - symbol_name = lttng_dynamic_pointer_array_get_pointer(&tokens, 1); + target_path = (char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 0); + symbol_name = (char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 1); } else { ret = CMD_ERROR; goto end; @@ -257,10 +257,10 @@ int parse_userspace_probe_opts(const char *opt, } break; case 4: - if (strcmp(lttng_dynamic_pointer_array_get_pointer(&tokens, 0), "sdt") == 0) { - target_path = lttng_dynamic_pointer_array_get_pointer(&tokens, 1); - provider_name = lttng_dynamic_pointer_array_get_pointer(&tokens, 2); - probe_name = lttng_dynamic_pointer_array_get_pointer(&tokens, 3); + if (strcmp((const char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 0), "sdt") == 0) { + target_path = (char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 1); + provider_name = (char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 2); + probe_name = (char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 3); } else { ret = CMD_ERROR; goto end; @@ -291,7 +291,7 @@ int parse_userspace_probe_opts(const char *opt, */ if (strchr(unescaped_target_path, '/') == NULL) { /* Walk the $PATH variable to find the targeted binary. */ - real_target_path = zmalloc(LTTNG_PATH_MAX * sizeof(char)); + real_target_path = (char *) zmalloc(LTTNG_PATH_MAX * sizeof(char)); if (!real_target_path) { PERROR("Error allocating path buffer"); ret = CMD_ERROR; diff --git a/src/bin/lttng/utils.c b/src/bin/lttng/utils.cpp similarity index 100% rename from src/bin/lttng/utils.c rename to src/bin/lttng/utils.cpp diff --git a/src/common/argpar/argpar.h b/src/common/argpar/argpar.h index 43dbd0d56..4bfc51d2b 100644 --- a/src/common/argpar/argpar.h +++ b/src/common/argpar/argpar.h @@ -9,6 +9,10 @@ #include +#if defined(__cplusplus) +extern "C" { +#endif + /* * argpar is a library that provides facilities for argument parsing. * @@ -310,5 +314,8 @@ void argpar_item_destroy(struct argpar_item *item); _item = NULL; \ } +#if defined(__cplusplus) +} +#endif #endif /* BABELTRACE_ARGPAR_H */ diff --git a/src/common/compat/string.h b/src/common/compat/string.h index a18d9e7ca..c9aa7f7fa 100644 --- a/src/common/compat/string.h +++ b/src/common/compat/string.h @@ -113,7 +113,7 @@ static inline int lttng_fls(int val) static inline void *lttng_memrchr(const void *s, int c, size_t n) { - return memrchr(s, c, n); + return (void *) memrchr(s, c, n); } #else static inline diff --git a/src/common/dynamic-array.h b/src/common/dynamic-array.h index 4ce2316f1..a37077404 100644 --- a/src/common/dynamic-array.h +++ b/src/common/dynamic-array.h @@ -10,6 +10,10 @@ #include +#if defined(__cplusplus) +extern "C" { +#endif + typedef void (*lttng_dynamic_array_element_destructor)(void *element); typedef void (*lttng_dynamic_pointer_array_destructor)(void *ptr); @@ -127,7 +131,7 @@ static inline void *lttng_dynamic_pointer_array_get_pointer( const struct lttng_dynamic_pointer_array *array, size_t index) { - void **element = lttng_dynamic_array_get_element(&array->array, index); + void **element = (void **) lttng_dynamic_array_get_element(&array->array, index); return *element; } @@ -141,7 +145,7 @@ static inline void *lttng_dynamic_pointer_array_steal_pointer( struct lttng_dynamic_pointer_array *array, size_t index) { - void **p_element = lttng_dynamic_array_get_element(&array->array, index); + void **p_element = (void **) lttng_dynamic_array_get_element(&array->array, index); void *element = *p_element; *p_element = NULL; @@ -177,4 +181,8 @@ void lttng_dynamic_pointer_array_reset( void lttng_dynamic_pointer_array_clear( struct lttng_dynamic_pointer_array *array); +#if defined(__cplusplus) +} +#endif + #endif /* LTTNG_DYNAMIC_ARRAY_H */ diff --git a/src/common/error.h b/src/common/error.h index f9b2ec2f9..6660cee6a 100644 --- a/src/common/error.h +++ b/src/common/error.h @@ -25,6 +25,10 @@ #include #include +#if defined(__cplusplus) +extern "C" { +#endif + /* Avoid conflict with Solaris */ #if defined(ERR) && defined(__sun__) #undef ERR @@ -264,4 +268,8 @@ const char *log_add_time(void); /* Name must be a statically-allocated string. */ void logger_set_thread_name(const char *name, bool set_pthread_name); +#if defined(__cplusplus) +} +#endif + #endif /* _ERROR_H */ diff --git a/src/common/filter/filter-ast.h b/src/common/filter/filter-ast.h index 93f9b9b25..d7a567445 100644 --- a/src/common/filter/filter-ast.h +++ b/src/common/filter/filter-ast.h @@ -20,6 +20,10 @@ #include #include +#if defined(__cplusplus) +extern "C" { +#endif + #define printf_debug(fmt, args...) \ do { \ if (filter_parser_debug) \ @@ -99,6 +103,8 @@ struct filter_node { enum node_type type; union { struct { + /* Avoid -Wextern-c-compat warning with clang++. */ + char unused; } unknown; struct { struct filter_node *child; @@ -186,4 +192,8 @@ int filter_visitor_ir_validate_string(struct filter_parser_ctx *ctx); int filter_visitor_ir_normalize_glob_patterns(struct filter_parser_ctx *ctx); int filter_visitor_ir_validate_globbing(struct filter_parser_ctx *ctx); +#if defined(__cplusplus) +} +#endif + #endif /* _FILTER_AST_H */ diff --git a/src/common/mi-lttng.c b/src/common/mi-lttng.c index fc3706616..b790f793a 100644 --- a/src/common/mi-lttng.c +++ b/src/common/mi-lttng.c @@ -933,7 +933,7 @@ int mi_lttng_writer_write_element_double(struct mi_writer *writer, writer->writer, element_name, value); } -int mi_lttng_version(struct mi_writer *writer, struct mi_lttng_version *version, +int mi_lttng_version(struct mi_writer *writer, struct mi_lttng_version_data *version, const char *lttng_description, const char *lttng_license) { int ret; diff --git a/src/common/mi-lttng.h b/src/common/mi-lttng.h index 414c731d2..2f27bf6cd 100644 --- a/src/common/mi-lttng.h +++ b/src/common/mi-lttng.h @@ -17,6 +17,10 @@ #include #include +#if defined(__cplusplus) +extern "C" { +#endif + /* Don't want to reference snapshot-internal.h here */ struct lttng_snapshot_output; @@ -29,7 +33,7 @@ struct mi_writer { /* * Version information for the machine interface. */ -struct mi_lttng_version { +struct mi_lttng_version_data { char version[LTTNG_NAME_MAX]; /* Version number of package */ uint32_t version_major; /* LTTng-Tools major version number */ uint32_t version_minor; /* LTTng-Tools minor version number */ @@ -563,7 +567,7 @@ int mi_lttng_writer_write_element_double(struct mi_writer *writer, * Returns zero if the element's value could be written. * Negative values indicate an error. */ -int mi_lttng_version(struct mi_writer *writer, struct mi_lttng_version *version, +int mi_lttng_version(struct mi_writer *writer, struct mi_lttng_version_data *version, const char *lttng_description, const char *lttng_license); /* @@ -1117,4 +1121,8 @@ int mi_lttng_rotate(struct mi_writer *writer, enum lttng_rotation_state rotation_state, const struct lttng_trace_archive_location *location); +#if defined(__cplusplus) +} +#endif + #endif /* _MI_LTTNG_H */ diff --git a/src/common/runas.h b/src/common/runas.h index 58c376fe1..406dfca22 100644 --- a/src/common/runas.h +++ b/src/common/runas.h @@ -46,9 +46,9 @@ int run_as_rmdir(const char *path, uid_t uid, gid_t gid); int run_as_rmdir_recursive(const char *path, uid_t uid, gid_t gid, int flags); int run_as_rmdirat(int dirfd, const char *path, uid_t uid, gid_t gid); int run_as_rmdirat_recursive(int dirfd, const char *path, uid_t uid, gid_t gid, int flags); -int run_as_rename(const char *old, const char *new, uid_t uid, gid_t gid); -int run_as_renameat(int old_dirfd, const char *old, - int new_dirfd, const char *new, uid_t uid, gid_t gid); +int run_as_rename(const char *old_name, const char *new_name, uid_t uid, gid_t gid); +int run_as_renameat(int old_dirfd, const char *old_name, + int new_dirfd, const char *new_name, uid_t uid, gid_t gid); int run_as_extract_elf_symbol_offset(int fd, const char* function, uid_t uid, gid_t gid, uint64_t *offset); int run_as_extract_sdt_probe_offsets(int fd, const char *provider_name, diff --git a/src/common/spawn-viewer.h b/src/common/spawn-viewer.h index 409c60ec8..316fe1998 100644 --- a/src/common/spawn-viewer.h +++ b/src/common/spawn-viewer.h @@ -10,6 +10,10 @@ #include +#if defined(__cplusplus) +extern "C" { +#endif + /* * Read the trace by `exec()ing` the provided viewer program if any. If * `opt_viewer` is NULL, try to read the trace with the default trace reader. @@ -22,4 +26,8 @@ */ int spawn_viewer(const char *trace_path, char *opt_viewer, bool opt_live_mode); +#if defined(__cplusplus) +} +#endif + #endif /* ifndef LTTNG_SPAWN_VIEWER_H */ diff --git a/src/common/string-utils/string-utils.h b/src/common/string-utils/string-utils.h index 1cf31e9d4..fb795b9dd 100644 --- a/src/common/string-utils/string-utils.h +++ b/src/common/string-utils/string-utils.h @@ -12,6 +12,10 @@ #include #include +#if defined(__cplusplus) +extern "C" { +#endif + void strutils_normalize_star_glob_pattern(char *pattern); bool strutils_is_star_glob_pattern(const char *pattern); @@ -27,4 +31,8 @@ void strutils_free_null_terminated_array_of_strings(char **array); size_t strutils_array_of_strings_len(char * const *array); +#if defined(__cplusplus) +} +#endif + #endif /* _STRING_UTILS_H */ diff --git a/src/common/time.h b/src/common/time.h index 87adf17d7..dc3f76342 100644 --- a/src/common/time.h +++ b/src/common/time.h @@ -13,6 +13,10 @@ #include #include +#if defined(__cplusplus) +extern "C" { +#endif + #define MSEC_PER_SEC 1000ULL #define NSEC_PER_SEC 1000000000ULL #define NSEC_PER_MSEC 1000000ULL @@ -62,4 +66,8 @@ int time_to_iso8601_str(time_t time, char *str, size_t len); int time_to_datetime_str(time_t time, char *str, size_t len); +#if defined(__cplusplus) +} +#endif + #endif /* LTTNG_TIME_H */ diff --git a/src/common/tracker.h b/src/common/tracker.h index 8b3794049..e81ee309e 100644 --- a/src/common/tracker.h +++ b/src/common/tracker.h @@ -17,6 +17,10 @@ #include #include +#if defined(__cplusplus) +extern "C" { +#endif + struct process_attr_value { enum lttng_process_attr_value_type type; union value { @@ -76,4 +80,8 @@ enum lttng_error_code process_attr_value_from_comm( const struct lttng_buffer_view *value_view, struct process_attr_value **value); +#if defined(__cplusplus) +} +#endif + #endif /* LTTNG_COMMON_TRACKER_H */ diff --git a/src/common/uri.h b/src/common/uri.h index ac1de9e0c..a270db9d9 100644 --- a/src/common/uri.h +++ b/src/common/uri.h @@ -12,6 +12,10 @@ #include #include +#if defined(__cplusplus) +extern "C" { +#endif + /* Destination type of lttng URI */ enum lttng_dst_type { LTTNG_DST_IPV4 = 1, @@ -72,4 +76,8 @@ ssize_t uri_parse_str_urls(const char *ctrl_url, const char *data_url, struct lttng_uri **uris); int uri_to_str_url(struct lttng_uri *uri, char *dst, size_t size); +#if defined(__cplusplus) +} +#endif + #endif /* _LTT_URI_H */ diff --git a/src/common/utils.h b/src/common/utils.h index a3250639b..6e478b39e 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -17,6 +17,10 @@ #include +#if defined(__cplusplus) +extern "C" { +#endif + #define KIBI_LOG2 10 #define MEBI_LOG2 20 #define GIBI_LOG2 30 @@ -68,4 +72,8 @@ enum lttng_error_code utils_group_id_from_name( int utils_parse_unsigned_long_long(const char *str, unsigned long long *value); +#if defined(__cplusplus) +} +#endif + #endif /* _COMMON_UTILS_H */ -- 2.34.1