X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fadd_context.cpp;h=5db0c5664888193d1b943558faf2ae4d3556a4aa;hb=f149493493fbd8a3efa4748832c03278c96c38ca;hp=d078471d3d784ca88e041bddf96b5c2acc95b8c3;hpb=48a4000561343808724f7cb5fa8c131877489ccd;p=lttng-tools.git diff --git a/src/bin/lttng/commands/add_context.cpp b/src/bin/lttng/commands/add_context.cpp index d078471d3..5db0c5664 100644 --- a/src/bin/lttng/commands/add_context.cpp +++ b/src/bin/lttng/commands/add_context.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 David Goulet + * Copyright (C) 2011 EfficiOS Inc. * Copyright (C) 2016 Jérémie Galarneau * * SPDX-License-Identifier: GPL-2.0-only @@ -18,10 +18,10 @@ #include -#include -#include +#include +#include -#include "../command.h" +#include "../command.hpp" static char *opt_channel_name; static char *opt_session_name; @@ -51,9 +51,10 @@ static struct lttng_handle *handle; static struct mi_writer *writer; /* - * Taken from the LTTng ABI + * Taken from the LTTng ABI except for "UNKNOWN". */ enum context_type { + CONTEXT_UNKNOWN = -1, CONTEXT_PID = 0, CONTEXT_PERF_COUNTER = 1, /* Backward compat. */ CONTEXT_PROCNAME = 2, @@ -216,11 +217,11 @@ static struct poptOption long_options[] = { _PERF_HW_CACHE(optstr "-prefetch-misses", name, type, \ PREFETCH, MISS, hide) -static +namespace { const struct ctx_opts { /* Needed for end-of-list item. */ ctx_opts() - : symbol(nullptr) + : ctx_opts(nullptr, CONTEXT_UNKNOWN) {} ctx_opts(const char *symbol_, context_type ctx_type_, bool hide_help_ = false) @@ -287,7 +288,7 @@ const struct ctx_opts { { (char *) "need_reschedule", CONTEXT_NEED_RESCHEDULE }, { (char *) "migratable", CONTEXT_MIGRATABLE }, { (char *) "callstack-kernel", CONTEXT_CALLSTACK_KERNEL }, -#if HAVE_MODULES_USERSPACE_CALLSTACK_CONTEXT +#ifdef HAVE_MODULES_USERSPACE_CALLSTACK_CONTEXT { (char *) "callstack-user", CONTEXT_CALLSTACK_USER }, #endif { (char *) "cgroup_ns", CONTEXT_CGROUP_NS }, @@ -551,8 +552,7 @@ struct ctx_type_list { } ctx_type_list = { .head = CDS_LIST_HEAD_INIT(ctx_type_list.head), }; - - +} /* namespace */ /* * Find context numerical value from string. @@ -901,21 +901,21 @@ void destroy_ctx_type(struct ctx_type *type) if (type->opt) { free(type->opt->symbol); } - free(type->opt); + delete type->opt; free(type); } static struct ctx_type *create_ctx_type(void) { - struct ctx_type *type = (ctx_type *) zmalloc(sizeof(*type)); + struct ctx_type *type = zmalloc(); if (!type) { PERROR("malloc ctx_type"); goto end; } - type->opt = (struct ctx_opts *) zmalloc(sizeof(*type->opt)); + type->opt = new struct ctx_opts; if (!type->opt) { PERROR("malloc ctx_type options"); destroy_ctx_type(type); @@ -1090,7 +1090,7 @@ struct ctx_type *get_context_type(const char *ctx) } provider_name_len = colon_pos - sizeof(app_ctx_prefix) + 2; - provider_name = (char *) zmalloc(provider_name_len); + provider_name = calloc(provider_name_len); if (!provider_name) { PERROR("malloc provider_name"); goto not_found; @@ -1100,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 = (char *) zmalloc(ctx_name_len); + ctx_name = calloc(ctx_name_len); if (!ctx_name) { PERROR("malloc ctx_name"); goto not_found;