+/*
+ * Prints the expected format for a --params option.
+ */
+static
+void print_expected_params_format(FILE *fp)
+{
+ fprintf(fp, "Expected format of PARAMS\n");
+ fprintf(fp, "-------------------------\n");
+ fprintf(fp, "\n");
+ fprintf(fp, " PARAM=VALUE[,PARAM=VALUE]...\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
+ fprintf(fp, "where PARAM is the parameter name (C identifier plus the [:.-] characters),\n");
+ fprintf(fp, "and VALUE can be one of:\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
+ fprintf(fp, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
+ fprintf(fp, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
+ fprintf(fp, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
+ fprintf(fp, " (`0x` prefix) signed 64-bit integer.\n");
+ fprintf(fp, "* Double precision floating point number (scientific notation is accepted).\n");
+ fprintf(fp, "* Unquoted string with no special characters, and not matching any of\n");
+ fprintf(fp, " the null and boolean value symbols above.\n");
+ fprintf(fp, "* Double-quoted string (accepts escape characters).\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "You can put whitespaces allowed around individual `=` and `,` symbols.\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "Example:\n");
+ fprintf(fp, "\n");
+ fprintf(fp, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
+ fprintf(fp, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
+ fprintf(fp, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "IMPORTANT: Make sure to single-quote the whole argument when you run babeltrace\n");
+ fprintf(fp, "from a shell.\n");
+}
+
+
+/*
+ * Prints the help command usage.
+ */
+static
+void print_help_usage(FILE *fp)
+{
+ fprintf(fp, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
+ fprintf(fp, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --source=PLUGIN.CLS\n");
+ fprintf(fp, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --filter=PLUGIN.CLS\n");
+ fprintf(fp, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --sink=PLUGIN.CLS\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "Options:\n");
+ fprintf(fp, "\n");
+ fprintf(fp, " -f, --filter=PLUGIN.CLS Get help for the filter component class\n");
+ fprintf(fp, " CLS found in the plugin PLUGIN\n");
+ fprintf(fp, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
+ fprintf(fp, " (~/.local/lib/babeltrace/plugins)\n");
+ fprintf(fp, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
+ fprintf(fp, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
+ fprintf(fp, " dynamic plugins can be loaded\n");
+ fprintf(fp, " -S, --sink=PLUGIN.CLS Get help for the sink component class\n");
+ fprintf(fp, " CLS found in the plugin PLUGIN\n");
+ fprintf(fp, " -s, --source=PLUGIN.CLS Get help for the source component class\n");
+ fprintf(fp, " CLS found in the plugin PLUGIN\n");
+ fprintf(fp, " -h --help Show this help and quit\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "See `babeltrace --help` for the list of general options.\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
+}
+
+static struct poptOption help_long_options[] = {
+ /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
+ { "filter", 'f', POPT_ARG_STRING, NULL, OPT_FILTER, NULL, NULL },
+ { "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL },
+ { "omit-home-plugin-path", '\0', POPT_ARG_NONE, NULL, OPT_OMIT_HOME_PLUGIN_PATH, NULL, NULL },
+ { "omit-system-plugin-path", '\0', POPT_ARG_NONE, NULL, OPT_OMIT_SYSTEM_PLUGIN_PATH, NULL, NULL },
+ { "plugin-path", '\0', POPT_ARG_STRING, NULL, OPT_PLUGIN_PATH, NULL, NULL },
+ { "sink", 'S', POPT_ARG_STRING, NULL, OPT_SINK, NULL, NULL },
+ { "source", 's', POPT_ARG_STRING, NULL, OPT_SOURCE, NULL, NULL },
+ { NULL, 0, 0, NULL, 0, NULL, NULL },
+};
+
+/*
+ * Creates a Babeltrace config object from the arguments of a help
+ * command.
+ *
+ * *retcode is set to the appropriate exit code to use.
+ */
+static
+struct bt_config *bt_config_help_from_args(int argc, const char *argv[],
+ int *retcode, bool omit_system_plugin_path,
+ bool omit_home_plugin_path,
+ struct bt_value *initial_plugin_paths)
+{
+ poptContext pc = NULL;
+ char *arg = NULL;
+ int opt;
+ int ret;
+ struct bt_config *cfg = NULL;
+ const char *leftover;
+ char *plugin_name = NULL, *comp_cls_name = NULL;
+ char *plug_comp_cls_names = NULL;
+
+ *retcode = 0;
+ cfg = bt_config_help_create(initial_plugin_paths);
+ if (!cfg) {
+ goto error;
+ }
+
+ cfg->omit_system_plugin_path = omit_system_plugin_path;
+ cfg->omit_home_plugin_path = omit_home_plugin_path;
+ ret = append_env_var_plugin_paths(cfg->plugin_paths);
+ if (ret) {
+ goto error;
+ }
+
+ /* Parse options */
+ pc = poptGetContext(NULL, argc, (const char **) argv,
+ help_long_options, 0);
+ if (!pc) {
+ printf_err("Cannot get popt context\n");
+ goto error;
+ }
+
+ poptReadDefaultConfig(pc, 0);
+
+ while ((opt = poptGetNextOpt(pc)) > 0) {
+ arg = poptGetOptArg(pc);
+
+ switch (opt) {
+ case OPT_PLUGIN_PATH:
+ if (bt_config_append_plugin_paths_check_setuid_setgid(
+ cfg->plugin_paths, arg)) {
+ goto error;
+ }
+ break;
+ case OPT_OMIT_SYSTEM_PLUGIN_PATH:
+ cfg->omit_system_plugin_path = true;
+ break;
+ case OPT_OMIT_HOME_PLUGIN_PATH:
+ cfg->omit_home_plugin_path = true;
+ break;
+ case OPT_SOURCE:
+ case OPT_FILTER:
+ case OPT_SINK:
+ if (cfg->cmd_data.help.cfg_component->type !=
+ BT_COMPONENT_CLASS_TYPE_UNKNOWN) {
+ printf_err("Cannot specify more than one plugin and component class:\n %s\n",
+ arg);
+ goto error;
+ }
+
+ switch (opt) {
+ case OPT_SOURCE:
+ cfg->cmd_data.help.cfg_component->type =
+ BT_COMPONENT_CLASS_TYPE_SOURCE;
+ break;
+ case OPT_FILTER:
+ cfg->cmd_data.help.cfg_component->type =
+ BT_COMPONENT_CLASS_TYPE_FILTER;
+ break;
+ case OPT_SINK:
+ cfg->cmd_data.help.cfg_component->type =
+ BT_COMPONENT_CLASS_TYPE_SINK;
+ break;
+ default:
+ assert(false);
+ }
+ plug_comp_cls_names = strdup(arg);
+ if (!plug_comp_cls_names) {
+ print_err_oom();
+ goto error;
+ }
+ break;
+ case OPT_HELP:
+ print_help_usage(stdout);
+ *retcode = -1;
+ BT_PUT(cfg);
+ goto end;
+ default:
+ printf_err("Unknown command-line option specified (option code %d)\n",
+ opt);
+ goto error;
+ }
+
+ free(arg);
+ arg = NULL;
+ }
+
+ /* Check for option parsing error */
+ if (opt < -1) {
+ printf_err("While parsing command-line options, at option %s: %s\n",
+ poptBadOption(pc, 0), poptStrerror(opt));
+ goto error;
+ }
+
+ leftover = poptGetArg(pc);
+ if (leftover) {
+ if (cfg->cmd_data.help.cfg_component->type !=
+ BT_COMPONENT_CLASS_TYPE_UNKNOWN) {
+ printf_err("Cannot specify plugin name and --source/--filter/--sink component class:\n %s\n",
+ leftover);
+ goto error;
+ }
+
+ g_string_assign(cfg->cmd_data.help.cfg_component->plugin_name,
+ leftover);
+ } else {
+ if (cfg->cmd_data.help.cfg_component->type ==
+ BT_COMPONENT_CLASS_TYPE_UNKNOWN) {
+ print_help_usage(stdout);
+ *retcode = -1;
+ BT_PUT(cfg);
+ goto end;
+ }
+
+ plugin_comp_cls_names(plug_comp_cls_names, NULL,
+ &plugin_name, &comp_cls_name);
+ if (plugin_name && comp_cls_name) {
+ g_string_assign(cfg->cmd_data.help.cfg_component->plugin_name,
+ plugin_name);
+ g_string_assign(cfg->cmd_data.help.cfg_component->comp_cls_name,
+ comp_cls_name);
+ } else {
+ printf_err("Invalid --source/--filter/--sink option's argument:\n %s\n",
+ plug_comp_cls_names);
+ goto error;
+ }
+ }
+
+ if (append_home_and_system_plugin_paths_cfg(cfg)) {
+ goto error;
+ }
+
+ goto end;
+
+error:
+ *retcode = 1;
+ BT_PUT(cfg);
+
+end:
+ free(plug_comp_cls_names);
+ g_free(plugin_name);
+ g_free(comp_cls_name);
+
+ if (pc) {
+ poptFreeContext(pc);
+ }
+
+ free(arg);
+ return cfg;
+}
+
+/*
+ * Prints the help command usage.
+ */
+static
+void print_query_usage(FILE *fp)
+{
+ fprintf(fp, "Usage: babeltrace [GEN OPTS] query [OPTS] OBJECT --source=PLUGIN.CLS\n");
+ fprintf(fp, " babeltrace [GEN OPTS] query [OPTS] OBJECT --filter=PLUGIN.CLS\n");
+ fprintf(fp, " babeltrace [GEN OPTS] query [OPTS] OBJECT --sink=PLUGIN.CLS\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "Options:\n");
+ fprintf(fp, "\n");
+ fprintf(fp, " -f. --filter=PLUGIN.CLS Query object from the filter component\n");
+ fprintf(fp, " class CLS found in the plugin PLUGIN\n");
+ fprintf(fp, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
+ fprintf(fp, " (~/.local/lib/babeltrace/plugins)\n");
+ fprintf(fp, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
+ fprintf(fp, " -p, --params=PARAMS Set the query parameters to PARAMS\n");
+ fprintf(fp, " (see the expected format of PARAMS below)\n");
+ fprintf(fp, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
+ fprintf(fp, " dynamic plugins can be loaded\n");
+ fprintf(fp, " -S, --sink=PLUGIN.CLS Query object from the sink component class\n");
+ fprintf(fp, " CLS found in the plugin PLUGIN\n");
+ fprintf(fp, " -s, --source=PLUGIN.CLS Query object from the source component\n");
+ fprintf(fp, " class CLS found in the plugin PLUGIN\n");
+ fprintf(fp, " -h --help Show this help and quit\n");
+ fprintf(fp, "\n\n");
+ print_expected_params_format(fp);
+}
+
+static struct poptOption query_long_options[] = {
+ /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
+ { "filter", 'f', POPT_ARG_STRING, NULL, OPT_FILTER, NULL, NULL },
+ { "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL },
+ { "omit-home-plugin-path", '\0', POPT_ARG_NONE, NULL, OPT_OMIT_HOME_PLUGIN_PATH, NULL, NULL },
+ { "omit-system-plugin-path", '\0', POPT_ARG_NONE, NULL, OPT_OMIT_SYSTEM_PLUGIN_PATH, NULL, NULL },
+ { "params", 'p', POPT_ARG_STRING, NULL, OPT_PARAMS, NULL, NULL },
+ { "plugin-path", '\0', POPT_ARG_STRING, NULL, OPT_PLUGIN_PATH, NULL, NULL },
+ { "sink", 'S', POPT_ARG_STRING, NULL, OPT_SINK, NULL, NULL },
+ { "source", 's', POPT_ARG_STRING, NULL, OPT_SOURCE, NULL, NULL },
+ { NULL, 0, 0, NULL, 0, NULL, NULL },
+};
+
+/*
+ * Creates a Babeltrace config object from the arguments of a query
+ * command.
+ *
+ * *retcode is set to the appropriate exit code to use.
+ */
+static
+struct bt_config *bt_config_query_from_args(int argc, const char *argv[],
+ int *retcode, bool omit_system_plugin_path,
+ bool omit_home_plugin_path,
+ struct bt_value *initial_plugin_paths)
+{
+ poptContext pc = NULL;
+ char *arg = NULL;
+ int opt;
+ int ret;
+ struct bt_config *cfg = NULL;
+ const char *leftover;
+ struct bt_value *params = bt_value_null;
+
+ *retcode = 0;
+ cfg = bt_config_query_create(initial_plugin_paths);
+ if (!cfg) {
+ goto error;
+ }
+
+ cfg->omit_system_plugin_path =
+ omit_system_plugin_path;
+ cfg->omit_home_plugin_path = omit_home_plugin_path;
+ ret = append_env_var_plugin_paths(cfg->plugin_paths);
+ if (ret) {
+ goto error;
+ }
+
+ /* Parse options */
+ pc = poptGetContext(NULL, argc, (const char **) argv,
+ query_long_options, 0);
+ if (!pc) {
+ printf_err("Cannot get popt context\n");
+ goto error;
+ }
+
+ poptReadDefaultConfig(pc, 0);
+
+ while ((opt = poptGetNextOpt(pc)) > 0) {
+ arg = poptGetOptArg(pc);
+
+ switch (opt) {
+ case OPT_PLUGIN_PATH:
+ if (bt_config_append_plugin_paths_check_setuid_setgid(
+ cfg->plugin_paths, arg)) {
+ goto error;
+ }
+ break;
+ case OPT_OMIT_SYSTEM_PLUGIN_PATH:
+ cfg->omit_system_plugin_path = true;
+ break;
+ case OPT_OMIT_HOME_PLUGIN_PATH:
+ cfg->omit_home_plugin_path = true;
+ break;
+ case OPT_SOURCE:
+ case OPT_FILTER:
+ case OPT_SINK:
+ {
+ enum bt_component_class_type type;
+
+ if (cfg->cmd_data.query.cfg_component) {
+ printf_err("Cannot specify more than one plugin and component class:\n %s\n",
+ arg);
+ goto error;
+ }
+
+ switch (opt) {
+ case OPT_SOURCE:
+ type = BT_COMPONENT_CLASS_TYPE_SOURCE;
+ break;
+ case OPT_FILTER:
+ type = BT_COMPONENT_CLASS_TYPE_FILTER;
+ break;
+ case OPT_SINK:
+ type = BT_COMPONENT_CLASS_TYPE_SINK;
+ break;
+ default:
+ assert(false);
+ }
+
+ cfg->cmd_data.query.cfg_component =
+ bt_config_component_from_arg(type, arg);
+ if (!cfg->cmd_data.query.cfg_component) {
+ printf_err("Invalid format for --source/--filter/--sink option's argument:\n %s\n",
+ arg);
+ goto error;
+ }
+
+ /* Default parameters: null */
+ bt_put(cfg->cmd_data.query.cfg_component->params);
+ cfg->cmd_data.query.cfg_component->params =
+ bt_value_null;
+ break;
+ }
+ case OPT_PARAMS:
+ {
+ params = bt_value_from_arg(arg);
+ if (!params) {
+ printf_err("Invalid format for --params option's argument:\n %s\n",
+ arg);
+ goto error;
+ }
+ break;
+ }
+ case OPT_HELP:
+ print_query_usage(stdout);
+ *retcode = -1;
+ BT_PUT(cfg);
+ goto end;
+ default:
+ printf_err("Unknown command-line option specified (option code %d)\n",
+ opt);
+ goto error;
+ }
+
+ free(arg);
+ arg = NULL;
+ }
+
+ if (!cfg->cmd_data.query.cfg_component) {
+ printf_err("No target component class specified with --source/--filter/--sink option\n");
+ goto error;
+ }
+
+ assert(params);
+ BT_MOVE(cfg->cmd_data.query.cfg_component->params, params);
+
+ /* Check for option parsing error */
+ if (opt < -1) {
+ printf_err("While parsing command-line options, at option %s: %s\n",
+ poptBadOption(pc, 0), poptStrerror(opt));
+ goto error;
+ }
+
+ /*
+ * We need exactly one leftover argument which is the
+ * mandatory object.
+ */
+ leftover = poptGetArg(pc);
+ if (leftover) {
+ if (strlen(leftover) == 0) {
+ printf_err("Invalid empty object\n");
+ goto error;
+ }
+
+ g_string_assign(cfg->cmd_data.query.object, leftover);
+ } else {
+ print_query_usage(stdout);
+ *retcode = -1;
+ BT_PUT(cfg);
+ goto end;
+ }
+
+ leftover = poptGetArg(pc);
+ if (leftover) {
+ printf_err("Unexpected argument: %s\n", leftover);
+ goto error;
+ }
+
+ if (append_home_and_system_plugin_paths_cfg(cfg)) {
+ goto error;
+ }
+
+ goto end;
+
+error:
+ *retcode = 1;
+ BT_PUT(cfg);
+
+end:
+ if (pc) {
+ poptFreeContext(pc);
+ }
+
+ BT_PUT(params);
+ free(arg);
+ return cfg;
+}
+
+/*
+ * Prints the list-plugins command usage.
+ */
+static
+void print_list_plugins_usage(FILE *fp)
+{
+ fprintf(fp, "Usage: babeltrace [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "Options:\n");
+ fprintf(fp, "\n");
+ fprintf(fp, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
+ fprintf(fp, " (~/.local/lib/babeltrace/plugins)\n");
+ fprintf(fp, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
+ fprintf(fp, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
+ fprintf(fp, " dynamic plugins can be loaded\n");
+ fprintf(fp, " -h --help Show this help and quit\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "See `babeltrace --help` for the list of general options.\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
+}
+
+static struct poptOption list_plugins_long_options[] = {
+ /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
+ { "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL },
+ { "omit-home-plugin-path", '\0', POPT_ARG_NONE, NULL, OPT_OMIT_HOME_PLUGIN_PATH, NULL, NULL },
+ { "omit-system-plugin-path", '\0', POPT_ARG_NONE, NULL, OPT_OMIT_SYSTEM_PLUGIN_PATH, NULL, NULL },
+ { "plugin-path", '\0', POPT_ARG_STRING, NULL, OPT_PLUGIN_PATH, NULL, NULL },
+ { NULL, 0, 0, NULL, 0, NULL, NULL },
+};
+
+/*
+ * Creates a Babeltrace config object from the arguments of a
+ * list-plugins command.
+ *
+ * *retcode is set to the appropriate exit code to use.
+ */
+static
+struct bt_config *bt_config_list_plugins_from_args(int argc, const char *argv[],
+ int *retcode, bool omit_system_plugin_path,
+ bool omit_home_plugin_path,
+ struct bt_value *initial_plugin_paths)
+{
+ poptContext pc = NULL;
+ char *arg = NULL;
+ int opt;
+ int ret;
+ struct bt_config *cfg = NULL;
+ const char *leftover;
+
+ *retcode = 0;
+ cfg = bt_config_list_plugins_create(initial_plugin_paths);
+ if (!cfg) {
+ goto error;
+ }
+
+ cfg->omit_system_plugin_path = omit_system_plugin_path;
+ cfg->omit_home_plugin_path = omit_home_plugin_path;
+ ret = append_env_var_plugin_paths(cfg->plugin_paths);
+ if (ret) {
+ goto error;
+ }
+
+ /* Parse options */
+ pc = poptGetContext(NULL, argc, (const char **) argv,
+ list_plugins_long_options, 0);
+ if (!pc) {
+ printf_err("Cannot get popt context\n");
+ goto error;
+ }
+
+ poptReadDefaultConfig(pc, 0);
+
+ while ((opt = poptGetNextOpt(pc)) > 0) {
+ arg = poptGetOptArg(pc);
+
+ switch (opt) {
+ case OPT_PLUGIN_PATH:
+ if (bt_config_append_plugin_paths_check_setuid_setgid(
+ cfg->plugin_paths, arg)) {
+ goto error;
+ }
+ break;
+ case OPT_OMIT_SYSTEM_PLUGIN_PATH:
+ cfg->omit_system_plugin_path = true;
+ break;
+ case OPT_OMIT_HOME_PLUGIN_PATH:
+ cfg->omit_home_plugin_path = true;
+ break;
+ case OPT_HELP:
+ print_list_plugins_usage(stdout);
+ *retcode = -1;
+ BT_PUT(cfg);
+ goto end;
+ default:
+ printf_err("Unknown command-line option specified (option code %d)\n",
+ opt);
+ goto error;
+ }
+
+ free(arg);
+ arg = NULL;
+ }
+
+ /* Check for option parsing error */
+ if (opt < -1) {
+ printf_err("While parsing command-line options, at option %s: %s\n",
+ poptBadOption(pc, 0), poptStrerror(opt));
+ goto error;
+ }
+
+ leftover = poptGetArg(pc);
+ if (leftover) {
+ printf_err("Unexpected argument: %s\n", leftover);
+ goto error;
+ }
+
+ if (append_home_and_system_plugin_paths_cfg(cfg)) {
+ goto error;
+ }
+
+ goto end;
+
+error:
+ *retcode = 1;
+ BT_PUT(cfg);
+
+end:
+ if (pc) {
+ poptFreeContext(pc);
+ }
+
+ free(arg);
+ return cfg;
+}
+
+/*
+ * Prints the run command usage.
+ */
+static
+void print_run_usage(FILE *fp)
+{
+ fprintf(fp, "Usage: babeltrace [GENERAL OPTIONS] run [OPTIONS]\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "Options:\n");
+ fprintf(fp, "\n");
+ fprintf(fp, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
+ fprintf(fp, " for all the following components until\n");
+ fprintf(fp, " --reset-base-params is encountered\n");
+ fprintf(fp, " (see the expected format of PARAMS below)\n");
+ fprintf(fp, " -c, --connect=CONNECTION Connect two created components (see the\n");
+ fprintf(fp, " expected format of CONNECTION below)\n");
+ fprintf(fp, " -f, --filter=[NAME:]PLUGIN.CLS Instantiate a filter component from plugin\n");
+ fprintf(fp, " PLUGIN and component class CLS, set it as\n");
+ fprintf(fp, " the current component, and if NAME is\n");
+ fprintf(fp, " given, set its instance name to NAME\n");
+ fprintf(fp, " --key=KEY Set the current initialization string\n");
+ fprintf(fp, " parameter key to KEY (see --value)\n");
+ fprintf(fp, " -n, --name=NAME Set the name of the current component\n");
+ fprintf(fp, " to NAME (must be unique amongst all the\n");
+ fprintf(fp, " names of the created components)\n");
+ fprintf(fp, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
+ fprintf(fp, " (~/.local/lib/babeltrace/plugins)\n");
+ fprintf(fp, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
+ fprintf(fp, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
+ fprintf(fp, " current component (see the expected format\n");
+ fprintf(fp, " of PARAMS below)\n");
+ fprintf(fp, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
+ fprintf(fp, " dynamic plugins can be loaded\n");
+ fprintf(fp, " -r, --reset-base-params Reset the current base parameters to an\n");
+ fprintf(fp, " empty map\n");
+ fprintf(fp, " -S, --sink=[NAME:]PLUGIN.CLS Instantiate a sink component from plugin\n");
+ fprintf(fp, " PLUGIN and component class CLS, set it as\n");
+ fprintf(fp, " the current component, and if NAME is\n");
+ fprintf(fp, " given, set its instance name to NAME\n");
+ fprintf(fp, " -s, --source=[NAME:]PLUGIN.CLS Instantiate a source component from plugin\n");
+ fprintf(fp, " PLUGIN and component class CLS, set it as\n");
+ fprintf(fp, " the current component, and if NAME is\n");
+ fprintf(fp, " given, set its instance name to NAME\n");
+ fprintf(fp, " --value=VAL Add a string initialization parameter to\n");
+ fprintf(fp, " the current component with a name given by\n");
+ fprintf(fp, " the last argument of the --key option and a\n");
+ fprintf(fp, " value set to VAL\n");
+ fprintf(fp, " -h --help Show this help and quit\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "See `babeltrace --help` for the list of general options.\n");
+ fprintf(fp, "\n\n");
+ fprintf(fp, "Expected format of CONNECTION\n");
+ fprintf(fp, "-----------------------------\n");
+ fprintf(fp, "\n");
+ fprintf(fp, " UPSTREAM[.UPSTREAM-PORT]:DOWNSTREAM[.DOWNSTREAM-PORT]\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "UPSTREAM and DOWNSTREAM are the names of the upstream and downstream components\n");
+ fprintf(fp, "to connect together. You can set the name of the current component with the\n");
+ fprintf(fp, "--name option.\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "UPSTREAM-PORT and DOWNSTREAM-PORT are the optional upstream and downstream\n");
+ fprintf(fp, "ports to use for the connection. When the port is not specified, the default\n");
+ fprintf(fp, "port is used.\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "You can connect a source component to a filter or sink component. You\n");
+ fprintf(fp, "can connect a filter component to a sink component.\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "Example:\n");
+ fprintf(fp, "\n");
+ fprintf(fp, " my-filter.top10:json-out\n");
+ fprintf(fp, "\n\n");
+ print_expected_params_format(fp);
+}
+
+static struct poptOption run_long_options[] = {
+ /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
+ { "base-params", 'b', POPT_ARG_STRING, NULL, OPT_BASE_PARAMS, NULL, NULL },
+ { "connect", 'c', POPT_ARG_STRING, NULL, OPT_CONNECT, NULL, NULL },
+ { "filter", 'f', POPT_ARG_STRING, NULL, OPT_FILTER, NULL, NULL },
+ { "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL },
+ { "key", '\0', POPT_ARG_STRING, NULL, OPT_KEY, NULL, NULL },
+ { "name", 'n', POPT_ARG_STRING, NULL, OPT_NAME, NULL, NULL },
+ { "omit-home-plugin-path", '\0', POPT_ARG_NONE, NULL, OPT_OMIT_HOME_PLUGIN_PATH, NULL, NULL },
+ { "omit-system-plugin-path", '\0', POPT_ARG_NONE, NULL, OPT_OMIT_SYSTEM_PLUGIN_PATH, NULL, NULL },
+ { "params", 'p', POPT_ARG_STRING, NULL, OPT_PARAMS, NULL, NULL },
+ { "plugin-path", '\0', POPT_ARG_STRING, NULL, OPT_PLUGIN_PATH, NULL, NULL },
+ { "reset-base-params", 'r', POPT_ARG_NONE, NULL, OPT_RESET_BASE_PARAMS, NULL, NULL },
+ { "sink", 'S', POPT_ARG_STRING, NULL, OPT_SINK, NULL, NULL },
+ { "source", 's', POPT_ARG_STRING, NULL, OPT_SOURCE, NULL, NULL },
+ { "value", '\0', POPT_ARG_STRING, NULL, OPT_VALUE, NULL, NULL },
+ { NULL, 0, 0, NULL, 0, NULL, NULL },
+};
+
+/*
+ * Creates a Babeltrace config object from the arguments of a run
+ * command.
+ *
+ * *retcode is set to the appropriate exit code to use.
+ */
+static
+struct bt_config *bt_config_run_from_args(int argc, const char *argv[],
+ int *retcode, bool omit_system_plugin_path,
+ bool omit_home_plugin_path,
+ struct bt_value *initial_plugin_paths)
+{
+ poptContext pc = NULL;
+ char *arg = NULL;
+ struct bt_config_component *cur_cfg_comp = NULL;
+ enum bt_config_component_dest cur_cfg_comp_dest;
+ struct bt_value *cur_base_params = NULL;
+ int opt, ret = 0;
+ struct bt_config *cfg = NULL;
+ struct bt_value *instance_names = NULL;
+ struct bt_value *connection_args = NULL;
+ GString *cur_param_key = NULL;
+ char error_buf[256] = { 0 };
+
+ *retcode = 0;
+ cur_param_key = g_string_new(NULL);
+ if (!cur_param_key) {
+ print_err_oom();
+ goto error;
+ }
+
+ if (argc <= 1) {
+ print_run_usage(stdout);
+ *retcode = -1;
+ goto end;
+ }
+
+ cfg = bt_config_run_create(initial_plugin_paths);
+ if (!cfg) {
+ goto error;
+ }
+
+ cfg->omit_system_plugin_path = omit_system_plugin_path;
+ cfg->omit_home_plugin_path = omit_home_plugin_path;
+ cur_base_params = bt_value_map_create();
+ if (!cur_base_params) {
+ print_err_oom();
+ goto error;
+ }
+
+ instance_names = bt_value_map_create();
+ if (!instance_names) {
+ print_err_oom();
+ goto error;
+ }
+
+ connection_args = bt_value_array_create();
+ if (!connection_args) {
+ print_err_oom();
+ goto error;
+ }
+
+ ret = append_env_var_plugin_paths(cfg->plugin_paths);
+ if (ret) {
+ goto error;
+ }
+
+ /* Parse options */
+ pc = poptGetContext(NULL, argc, (const char **) argv,
+ run_long_options, 0);
+ if (!pc) {
+ printf_err("Cannot get popt context\n");
+ goto error;
+ }
+
+ poptReadDefaultConfig(pc, 0);
+
+ while ((opt = poptGetNextOpt(pc)) > 0) {
+ arg = poptGetOptArg(pc);
+
+ switch (opt) {
+ case OPT_PLUGIN_PATH:
+ if (bt_config_append_plugin_paths_check_setuid_setgid(
+ cfg->plugin_paths, arg)) {
+ goto error;
+ }
+ break;
+ case OPT_OMIT_SYSTEM_PLUGIN_PATH:
+ cfg->omit_system_plugin_path = true;
+ break;
+ case OPT_OMIT_HOME_PLUGIN_PATH:
+ cfg->omit_home_plugin_path = true;
+ break;
+ case OPT_SOURCE:
+ case OPT_FILTER:
+ case OPT_SINK:
+ {
+ enum bt_component_class_type new_comp_type;
+ enum bt_config_component_dest new_dest;
+ const char *opt_name;
+
+ switch (opt) {
+ case OPT_SOURCE:
+ new_comp_type = BT_COMPONENT_CLASS_TYPE_SOURCE;
+ new_dest = BT_CONFIG_COMPONENT_DEST_SOURCE;
+ opt_name = "--source";
+ break;
+ case OPT_FILTER:
+ new_comp_type = BT_COMPONENT_CLASS_TYPE_FILTER;
+ new_dest = BT_CONFIG_COMPONENT_DEST_FILTER;
+ opt_name = "--filter";
+ break;
+ case OPT_SINK:
+ new_comp_type = BT_COMPONENT_CLASS_TYPE_SINK;
+ new_dest = BT_CONFIG_COMPONENT_DEST_SINK;
+ opt_name = "--sink";
+ break;
+ default:
+ assert(false);
+ }
+
+ if (cur_cfg_comp) {
+ ret = add_run_cfg_comp_check_name(cfg,
+ cur_cfg_comp, cur_cfg_comp_dest,
+ instance_names);
+ BT_PUT(cur_cfg_comp);
+ if (ret) {
+ goto error;
+ }
+ }
+
+ cur_cfg_comp = bt_config_component_from_arg(
+ new_comp_type, arg);
+ if (!cur_cfg_comp) {
+ printf_err("Invalid format for %s option's argument:\n %s\n",
+ opt_name, arg);
+ goto error;
+ }
+
+ assert(cur_base_params);
+ bt_put(cur_cfg_comp->params);
+ cur_cfg_comp->params = bt_value_copy(cur_base_params);
+ if (!cur_cfg_comp->params) {
+ print_err_oom();
+ goto error;
+ }
+
+ cur_cfg_comp_dest = new_dest;
+ break;
+ }
+ case OPT_PARAMS:
+ {
+ struct bt_value *params;
+ struct bt_value *params_to_set;
+
+ if (!cur_cfg_comp) {
+ printf_err("Cannot add parameters to unavailable component:\n %s\n",
+ arg);
+ goto error;
+ }
+
+ params = bt_value_from_arg(arg);
+ if (!params) {
+ printf_err("Invalid format for --params option's argument:\n %s\n",
+ arg);
+ goto error;
+ }
+
+ params_to_set = bt_value_map_extend(cur_cfg_comp->params,
+ params);
+ BT_PUT(params);
+ if (!params_to_set) {
+ printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
+ arg);
+ goto error;
+ }
+
+ BT_MOVE(cur_cfg_comp->params, params_to_set);
+ break;
+ }
+ case OPT_KEY:
+ if (strlen(arg) == 0) {
+ printf_err("Cannot set an empty string as the current parameter key\n");
+ goto error;
+ }
+
+ g_string_assign(cur_param_key, arg);
+ break;
+ case OPT_VALUE:
+ if (!cur_cfg_comp) {
+ printf_err("Cannot set a parameter's value of unavailable component:\n %s\n",
+ arg);
+ goto error;
+ }
+
+ if (cur_param_key->len == 0) {
+ printf_err("--value option specified without preceding --key option:\n %s\n",
+ arg);
+ goto error;
+ }
+
+ if (bt_value_map_insert_string(cur_cfg_comp->params,
+ cur_param_key->str, arg)) {
+ print_err_oom();
+ goto error;
+ }
+ break;
+ case OPT_NAME:
+ if (!cur_cfg_comp) {
+ printf_err("Cannot set the name of unavailable component:\n %s\n",
+ arg);
+ goto error;
+ }
+
+ g_string_assign(cur_cfg_comp->instance_name, arg);
+ break;
+ case OPT_BASE_PARAMS:
+ {
+ struct bt_value *params = bt_value_from_arg(arg);
+
+ if (!params) {
+ printf_err("Invalid format for --base-params option's argument:\n %s\n",
+ arg);
+ goto error;
+ }
+
+ BT_MOVE(cur_base_params, params);
+ break;
+ }
+ case OPT_RESET_BASE_PARAMS:
+ BT_PUT(cur_base_params);
+ cur_base_params = bt_value_map_create();
+ if (!cur_base_params) {
+ print_err_oom();
+ goto error;
+ }
+ break;
+ case OPT_CONNECT:
+ if (bt_value_array_append_string(connection_args,
+ arg)) {
+ print_err_oom();
+ goto error;
+ }
+ break;
+ case OPT_HELP:
+ print_run_usage(stdout);
+ *retcode = -1;
+ BT_PUT(cfg);
+ goto end;
+ default:
+ printf_err("Unknown command-line option specified (option code %d)\n",
+ opt);
+ goto error;
+ }
+
+ free(arg);
+ arg = NULL;
+ }
+
+ /* Check for option parsing error */
+ if (opt < -1) {
+ printf_err("While parsing command-line options, at option %s: %s\n",
+ poptBadOption(pc, 0), poptStrerror(opt));
+ goto error;
+ }
+
+ /* This command does not accept leftover arguments */
+ if (poptPeekArg(pc)) {
+ printf_err("Unexpected argument: %s\n", poptPeekArg(pc));
+ goto error;
+ }
+
+ /* Add current component */
+ if (cur_cfg_comp) {
+ ret = add_run_cfg_comp_check_name(cfg, cur_cfg_comp,
+ cur_cfg_comp_dest, instance_names);
+ BT_PUT(cur_cfg_comp);
+ if (ret) {
+ goto error;
+ }
+ }
+
+ if (cfg->cmd_data.run.sources->len == 0) {
+ printf_err("Incomplete graph: no source component\n");
+ goto error;
+ }
+
+ if (cfg->cmd_data.run.sinks->len == 0) {
+ printf_err("Incomplete graph: no sink component\n");
+ goto error;
+ }
+
+ if (append_home_and_system_plugin_paths_cfg(cfg)) {
+ goto error;
+ }
+
+ ret = bt_config_create_connections(cfg, connection_args,
+ error_buf, 256);
+ if (ret) {
+ printf_err("Cannot creation connections:\n%s", error_buf);
+ goto error;
+ }
+
+ goto end;
+
+error:
+ *retcode = 1;
+ BT_PUT(cfg);
+
+end:
+ if (pc) {
+ poptFreeContext(pc);
+ }
+
+ if (cur_param_key) {
+ g_string_free(cur_param_key, TRUE);
+ }
+
+ free(arg);
+ BT_PUT(cur_cfg_comp);
+ BT_PUT(cur_base_params);
+ BT_PUT(instance_names);
+ BT_PUT(connection_args);
+ return cfg;
+}
+
+static
+struct bt_config *bt_config_run_from_args_array(struct bt_value *run_args,
+ int *retcode, bool omit_system_plugin_path,
+ bool omit_home_plugin_path,
+ struct bt_value *initial_plugin_paths)
+{
+ struct bt_config *cfg = NULL;
+ const char **argv;
+ size_t i;
+ const size_t argc = bt_value_array_size(run_args) + 1;
+
+ argv = calloc(argc, sizeof(*argv));
+ if (!argv) {
+ print_err_oom();
+ goto end;
+ }
+
+ argv[0] = "run";
+
+ for (i = 0; i < bt_value_array_size(run_args); i++) {
+ int ret;
+ struct bt_value *arg_value = bt_value_array_get(run_args, i);
+ const char *arg;
+
+ assert(arg_value);
+ ret = bt_value_string_get(arg_value, &arg);
+ assert(ret == 0);
+ assert(arg);
+ argv[i + 1] = arg;
+ bt_put(arg_value);
+ }
+
+ cfg = bt_config_run_from_args(argc, argv, retcode,
+ omit_system_plugin_path, omit_home_plugin_path,
+ initial_plugin_paths);
+
+end:
+ free(argv);
+ return cfg;
+}
+
+/*
+ * Prints the convert command usage.
+ */
+static
+void print_convert_usage(FILE *fp)
+{
+ fprintf(fp, "Usage: babeltrace [GENERAL OPTIONS] [convert] [OPTIONS] [PATH/URL]\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "Options:\n");
+ fprintf(fp, "\n");
+ fprintf(fp, " --filter=[NAME:]PLUGIN.CLS Instantiate a filter component from plugin\n");
+ fprintf(fp, " PLUGIN and component class CLS, set it as\n");
+ fprintf(fp, " the current component, and if NAME is\n");
+ fprintf(fp, " given, set its instance name to NAME\n");
+ fprintf(fp, " --name=NAME Set the name of the current component\n");
+ fprintf(fp, " to NAME (must be unique amongst all the\n");
+ fprintf(fp, " names of the created components)\n");
+ fprintf(fp, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
+ fprintf(fp, " (~/.local/lib/babeltrace/plugins)\n");
+ fprintf(fp, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
+ fprintf(fp, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
+ fprintf(fp, " current component (see the expected format\n");
+ fprintf(fp, " of PARAMS below)\n");
+ fprintf(fp, " -P, --path=PATH Set the `path` string parameter of the\n");
+ fprintf(fp, " current component to PATH\n");
+ fprintf(fp, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
+ fprintf(fp, " dynamic plugins can be loaded\n");
+ fprintf(fp, " --run-args Print the equivalent arguments for the\n");
+ fprintf(fp, " `run` command to the standard output,\n");
+ fprintf(fp, " formatted for a shell, and quit\n");
+ fprintf(fp, " --run-args-0 Print the equivalent arguments for the\n");
+ fprintf(fp, " `run` command to the standard output,\n");
+ fprintf(fp, " formatted for `xargs -0`, and quit\n");
+ fprintf(fp, " --sink=[NAME:]PLUGIN.CLS Instantiate a sink component from plugin\n");
+ fprintf(fp, " PLUGIN and component class CLS, set it as\n");
+ fprintf(fp, " the current component, and if NAME is\n");
+ fprintf(fp, " given, set its instance name to NAME\n");
+ fprintf(fp, " --source=[NAME:]PLUGIN.CLS Instantiate a source component from plugin\n");
+ fprintf(fp, " PLUGIN and component class CLS, set it as\n");
+ fprintf(fp, " the current component, and if NAME is\n");
+ fprintf(fp, " given, set its instance name to NAME\n");
+ fprintf(fp, " -u, --url=URL Set the `url` string parameter of the\n");
+ fprintf(fp, " current component to URL\n");
+ fprintf(fp, " -h --help Show this help and quit\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "Implicit `ctf.fs` source component options:\n");
+ fprintf(fp, "\n");
+ fprintf(fp, " --clock-offset=SEC Set clock offset to SEC seconds\n");
+ fprintf(fp, " --clock-offset-ns=NS Set clock offset to NS ns\n");
+ fprintf(fp, " --stream-intersection Only process events when all streams\n");
+ fprintf(fp, " are active\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "Implicit `text.text` sink component options:\n");
+ fprintf(fp, "\n");
+ fprintf(fp, " --clock-cycles Print timestamps in clock cycles\n");
+ fprintf(fp, " --clock-date Print timestamp dates\n");
+ fprintf(fp, " --clock-gmt Print and parse timestamps in the GMT\n");
+ fprintf(fp, " time zone instead of the local time zone\n");
+ fprintf(fp, " --clock-seconds Print the timestamps as `SEC.NS` instead\n");
+ fprintf(fp, " of `hh:mm:ss.nnnnnnnnn`\n");
+ fprintf(fp, " --color=(never | auto | always)\n");
+ fprintf(fp, " Never, automatically, or always emit\n");
+ fprintf(fp, " console color codes\n");
+ fprintf(fp, " -f, --fields=FIELD[,FIELD]... Print additional fields; FIELD can be:\n");
+ fprintf(fp, " `all`, `trace`, `trace:hostname`,\n");
+ fprintf(fp, " `trace:domain`, `trace:procname`,\n");
+ fprintf(fp, " `trace:vpid`, `loglevel`, `emf`\n");
+ fprintf(fp, " -n, --names=NAME[,NAME]... Print field names; NAME can be:\n");
+ fprintf(fp, " `payload` (or `arg` or `args`), `none`,\n");
+ fprintf(fp, " `all`, `scope`, `header`, `context`\n");
+ fprintf(fp, " (or `ctx`)\n");
+ fprintf(fp, " --no-delta Do not print time delta between\n");
+ fprintf(fp, " consecutive events\n");
+ fprintf(fp, " -w, --output=PATH Write output text to PATH instead of\n");
+ fprintf(fp, " the standard output\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "Implicit `utils.muxer` filter component options:\n");
+ fprintf(fp, "\n");
+ fprintf(fp, " --clock-force-correlate Assume that clocks are inherently\n");
+ fprintf(fp, " correlated across traces\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "Implicit `utils.trimmer` filter component options:\n");
+ fprintf(fp, "\n");
+ fprintf(fp, " -b, --begin=BEGIN Set the beginning time of the conversion\n");
+ fprintf(fp, " time range to BEGIN (see the format of\n");
+ fprintf(fp, " BEGIN below)\n");
+ fprintf(fp, " -e, --end=END Set the end time of the conversion time\n");
+ fprintf(fp, " range to END (see the format of END below)\n");
+ fprintf(fp, " -t, --timerange=TIMERANGE Set conversion time range to TIMERANGE:\n");
+ fprintf(fp, " BEGIN,END or [BEGIN,END] (literally `[` and\n");
+ fprintf(fp, " `]`) (see the format of BEGIN/END below)\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "Implicit `lttng-utils.debug-info` filter component options:\n");
+ fprintf(fp, "\n");
+ fprintf(fp, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
+ fprintf(fp, " instead of `/usr/lib/debug`\n");
+ fprintf(fp, " --debug-info-full-path Show full debug info source and\n");
+ fprintf(fp, " binary paths instead of just names\n");
+ fprintf(fp, " --debug-info-target-prefix=DIR\n");
+ fprintf(fp, " Use directory DIR as a prefix when\n");
+ fprintf(fp, " looking up executables during debug\n");
+ fprintf(fp, " info analysis\n");
+ fprintf(fp, " --no-debug-info Do not create an implicit\n");
+ fprintf(fp, " `lttng-utils.debug-info` filter component\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "Legacy options that still work:\n");
+ fprintf(fp, "\n");
+ fprintf(fp, " -i, --input-format=(ctf | lttng-live)\n");
+ fprintf(fp, " `ctf`:\n");
+ fprintf(fp, " Create an implicit `ctf.fs` source\n");
+ fprintf(fp, " component\n");
+ fprintf(fp, " `lttng-live`:\n");
+ fprintf(fp, " Create an implicit `ctf.lttng-live`\n");
+ fprintf(fp, " source component\n");
+ fprintf(fp, " -o, --output-format=(text | dummy | ctf-metadata)\n");
+ fprintf(fp, " `text`:\n");
+ fprintf(fp, " Create an implicit `text.text` sink\n");
+ fprintf(fp, " component\n");
+ fprintf(fp, " `dummy`:\n");
+ fprintf(fp, " Create an implicit `utils.dummy` sink\n");
+ fprintf(fp, " component\n");
+ fprintf(fp, " `ctf-metadata`:\n");
+ fprintf(fp, " Query the `ctf.fs` component class for\n");
+ fprintf(fp, " metadata text and quit\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "See `babeltrace --help` for the list of general options.\n");
+ fprintf(fp, "\n\n");
+ fprintf(fp, "Format of BEGIN and END\n");
+ fprintf(fp, "-----------------------\n");
+ fprintf(fp, "\n");
+ fprintf(fp, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
+ fprintf(fp, "\n\n");
+ print_expected_params_format(fp);
+}
+
+static struct poptOption convert_long_options[] = {
+ /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
+ { "begin", 'b', POPT_ARG_STRING, NULL, OPT_BEGIN, NULL, NULL },
+ { "clock-cycles", '\0', POPT_ARG_NONE, NULL, OPT_CLOCK_CYCLES, NULL, NULL },
+ { "clock-date", '\0', POPT_ARG_NONE, NULL, OPT_CLOCK_DATE, NULL, NULL },
+ { "clock-force-correlate", '\0', POPT_ARG_NONE, NULL, OPT_CLOCK_FORCE_CORRELATE, NULL, NULL },
+ { "clock-gmt", '\0', POPT_ARG_NONE, NULL, OPT_CLOCK_GMT, 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-seconds", '\0', POPT_ARG_NONE, NULL, OPT_CLOCK_SECONDS, NULL, NULL },
+ { "color", '\0', POPT_ARG_STRING, NULL, OPT_COLOR, NULL, NULL },
+ { "debug", 'd', POPT_ARG_NONE, NULL, OPT_DEBUG, NULL, NULL },
+ { "debug-info-dir", 0, POPT_ARG_STRING, NULL, OPT_DEBUG_INFO_DIR, NULL, NULL },
+ { "debug-info-full-path", 0, POPT_ARG_NONE, NULL, OPT_DEBUG_INFO_FULL_PATH, NULL, NULL },
+ { "debug-info-target-prefix", 0, POPT_ARG_STRING, NULL, OPT_DEBUG_INFO_TARGET_PREFIX, NULL, NULL },
+ { "end", 'e', POPT_ARG_STRING, NULL, OPT_END, NULL, NULL },
+ { "fields", 'f', POPT_ARG_STRING, NULL, OPT_FIELDS, NULL, NULL },
+ { "filter", '\0', POPT_ARG_STRING, NULL, OPT_FILTER, NULL, NULL },
+ { "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL },
+ { "input-format", 'i', POPT_ARG_STRING, NULL, OPT_INPUT_FORMAT, NULL, NULL },
+ { "name", '\0', POPT_ARG_STRING, NULL, OPT_NAME, NULL, NULL },
+ { "names", 'n', POPT_ARG_STRING, NULL, OPT_NAMES, NULL, NULL },
+ { "no-debug-info", '\0', POPT_ARG_NONE, NULL, OPT_NO_DEBUG_INFO, NULL, NULL },
+ { "no-delta", '\0', POPT_ARG_NONE, NULL, OPT_NO_DELTA, NULL, NULL },
+ { "omit-home-plugin-path", '\0', POPT_ARG_NONE, NULL, OPT_OMIT_HOME_PLUGIN_PATH, NULL, NULL },
+ { "omit-system-plugin-path", '\0', POPT_ARG_NONE, NULL, OPT_OMIT_SYSTEM_PLUGIN_PATH, NULL, NULL },
+ { "output", 'w', POPT_ARG_STRING, NULL, OPT_OUTPUT, NULL, NULL },
+ { "output-format", 'o', POPT_ARG_STRING, NULL, OPT_OUTPUT_FORMAT, NULL, NULL },
+ { "params", 'p', POPT_ARG_STRING, NULL, OPT_PARAMS, NULL, NULL },
+ { "path", 'P', POPT_ARG_STRING, NULL, OPT_PATH, NULL, NULL },
+ { "plugin-path", '\0', POPT_ARG_STRING, NULL, OPT_PLUGIN_PATH, NULL, NULL },
+ { "run-args", '\0', POPT_ARG_NONE, NULL, OPT_RUN_ARGS, NULL, NULL },
+ { "run-args-0", '\0', POPT_ARG_NONE, NULL, OPT_RUN_ARGS_0, NULL, NULL },
+ { "sink", '\0', POPT_ARG_STRING, NULL, OPT_SINK, NULL, NULL },
+ { "source", '\0', POPT_ARG_STRING, NULL, OPT_SOURCE, NULL, NULL },
+ { "stream-intersection", '\0', POPT_ARG_NONE, NULL, OPT_STREAM_INTERSECTION, NULL, NULL },
+ { "timerange", '\0', POPT_ARG_STRING, NULL, OPT_TIMERANGE, NULL, NULL },
+ { "url", 'u', POPT_ARG_STRING, NULL, OPT_URL, NULL, NULL },
+ { "verbose", 'v', POPT_ARG_NONE, NULL, OPT_VERBOSE, NULL, NULL },
+ { NULL, 0, 0, NULL, 0, NULL, NULL },
+};
+
+static
+GString *get_component_auto_name(const char *prefix,
+ struct bt_value *existing_names)
+{
+ unsigned int i = 0;
+ GString *auto_name = g_string_new(NULL);
+
+ if (!auto_name) {
+ print_err_oom();
+ goto end;
+ }
+
+ if (!bt_value_map_has_key(existing_names, prefix)) {
+ g_string_assign(auto_name, prefix);
+ goto end;
+ }
+
+ do {
+ g_string_printf(auto_name, "%s-%d", prefix, i);
+ i++;
+ } while (bt_value_map_has_key(existing_names, auto_name->str));
+
+end:
+ return auto_name;
+}
+
+struct implicit_component_args {
+ bool exists;
+ GString *plugin_comp_cls_arg;
+ GString *name_arg;
+ GString *params_arg;
+ struct bt_value *extra_args;
+};
+
+static
+int assign_name_to_implicit_component(struct implicit_component_args *args,
+ const char *prefix, struct bt_value *existing_names,
+ GList **comp_names, bool append_to_comp_names)
+{
+ int ret = 0;
+ GString *name = NULL;
+
+ if (!args->exists) {
+ goto end;
+ }
+
+ name = get_component_auto_name(prefix, existing_names);
+
+ if (!name) {
+ ret = -1;
+ goto end;
+ }
+
+ g_string_assign(args->name_arg, name->str);
+
+ if (bt_value_map_insert(existing_names, name->str,
+ bt_value_null)) {
+ print_err_oom();
+ ret = -1;
+ goto end;
+ }
+
+ if (append_to_comp_names) {
+ *comp_names = g_list_append(*comp_names, name);
+ name = NULL;
+ }
+
+end:
+ if (name) {
+ g_string_free(name, TRUE);
+ }
+
+ return ret;
+}
+
+static
+int append_run_args_for_implicit_component(
+ enum bt_component_class_type type,
+ struct implicit_component_args *impl_args,
+ struct bt_value *run_args)
+{
+ int ret = 0;
+ size_t i;
+
+ if (!impl_args->exists) {
+ goto end;
+ }
+
+ switch (type) {
+ case BT_COMPONENT_CLASS_TYPE_SOURCE:
+ if (bt_value_array_append_string(run_args, "--source")) {
+ print_err_oom();
+ goto error;
+ }
+ break;
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ if (bt_value_array_append_string(run_args, "--filter")) {
+ print_err_oom();
+ goto error;
+ }