2 * Babeltrace trace converter - parameter parsing
4 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 #include <babeltrace/babeltrace.h>
33 #include <babeltrace/common-internal.h>
34 #include <babeltrace/values.h>
37 #include <sys/types.h>
39 #include "babeltrace-cfg.h"
40 #include "babeltrace-cfg-cli-args.h"
41 #include "babeltrace-cfg-cli-args-connect.h"
44 * Error printf() macro which prepends "Error: " the first time it's
45 * called. This gives a nicer feel than having a bunch of error prefixes
46 * (since the following lines usually describe the error and possible
47 * solutions), or the error prefix just at the end.
49 #define printf_err(fmt, args...) \
51 if (is_first_error) { \
52 fprintf(stderr, "Command line error: "); \
53 is_first_error = false; \
55 fprintf(stderr, fmt, ##args); \
58 static bool is_first_error
= true;
60 /* INI-style parsing FSM states */
61 enum ini_parsing_fsm_state
{
62 /* Expect a map key (identifier) */
65 /* Expect an equal character ('=') */
71 /* Expect a negative number value */
72 INI_EXPECT_VALUE_NUMBER_NEG
,
74 /* Expect a comma character (',') */
78 /* INI-style parsing state variables */
79 struct ini_parsing_state
{
80 /* Lexical scanner (owned by this) */
83 /* Output map value object being filled (owned by this) */
84 struct bt_value
*params
;
86 /* Next expected FSM state */
87 enum ini_parsing_fsm_state expecting
;
89 /* Last decoded map key (owned by this) */
92 /* Complete INI-style string to parse (not owned by this) */
95 /* Error buffer (not owned by this) */
99 /* Offset option with "is set" boolean */
105 /* Legacy "ctf"/"lttng-live" format options */
106 struct ctf_legacy_opts
{
107 struct offset_opt offset_s
;
108 struct offset_opt offset_ns
;
109 bool stream_intersection
;
112 /* Legacy "text" format options */
113 struct text_legacy_opts
{
115 * output, dbg_info_dir, dbg_info_target_prefix, names,
116 * and fields are owned by this.
119 GString
*dbg_info_dir
;
120 GString
*dbg_info_target_prefix
;
121 struct bt_value
*names
;
122 struct bt_value
*fields
;
130 bool dbg_info_full_path
;
134 /* Legacy input format format */
135 enum legacy_input_format
{
136 LEGACY_INPUT_FORMAT_NONE
= 0,
137 LEGACY_INPUT_FORMAT_CTF
,
138 LEGACY_INPUT_FORMAT_LTTNG_LIVE
,
141 /* Legacy output format format */
142 enum legacy_output_format
{
143 LEGACY_OUTPUT_FORMAT_NONE
= 0,
144 LEGACY_OUTPUT_FORMAT_TEXT
,
145 LEGACY_OUTPUT_FORMAT_DUMMY
,
149 * Prints the "out of memory" error.
152 void print_err_oom(void)
154 printf_err("Out of memory\n");
158 * Appends an "expecting token" error to the INI-style parsing state's
162 void ini_append_error_expecting(struct ini_parsing_state
*state
,
163 GScanner
*scanner
, const char *expecting
)
168 g_string_append_printf(state
->ini_error
, "Expecting %s:\n", expecting
);
170 /* Only print error if there's one line */
171 if (strchr(state
->arg
, '\n') != NULL
|| strlen(state
->arg
) == 0) {
175 g_string_append_printf(state
->ini_error
, "\n %s\n", state
->arg
);
176 pos
= g_scanner_cur_position(scanner
) + 4;
178 if (!g_scanner_eof(scanner
)) {
182 for (i
= 0; i
< pos
; ++i
) {
183 g_string_append_printf(state
->ini_error
, " ");
186 g_string_append_printf(state
->ini_error
, "^\n\n");
190 int ini_handle_state(struct ini_parsing_state
*state
)
193 GTokenType token_type
;
194 struct bt_value
*value
= NULL
;
196 token_type
= g_scanner_get_next_token(state
->scanner
);
197 if (token_type
== G_TOKEN_EOF
) {
198 if (state
->expecting
!= INI_EXPECT_COMMA
) {
199 switch (state
->expecting
) {
200 case INI_EXPECT_EQUAL
:
201 ini_append_error_expecting(state
,
202 state
->scanner
, "'='");
204 case INI_EXPECT_VALUE
:
205 case INI_EXPECT_VALUE_NUMBER_NEG
:
206 ini_append_error_expecting(state
,
207 state
->scanner
, "value");
209 case INI_EXPECT_MAP_KEY
:
210 ini_append_error_expecting(state
,
211 state
->scanner
, "unquoted map key");
224 switch (state
->expecting
) {
225 case INI_EXPECT_MAP_KEY
:
226 if (token_type
!= G_TOKEN_IDENTIFIER
) {
227 ini_append_error_expecting(state
, state
->scanner
,
232 free(state
->last_map_key
);
233 state
->last_map_key
=
234 strdup(state
->scanner
->value
.v_identifier
);
235 if (!state
->last_map_key
) {
236 g_string_append(state
->ini_error
,
241 if (bt_value_map_has_key(state
->params
, state
->last_map_key
)) {
242 g_string_append_printf(state
->ini_error
,
243 "Duplicate parameter key: `%s`\n",
244 state
->last_map_key
);
248 state
->expecting
= INI_EXPECT_EQUAL
;
250 case INI_EXPECT_EQUAL
:
251 if (token_type
!= G_TOKEN_CHAR
) {
252 ini_append_error_expecting(state
,
253 state
->scanner
, "'='");
257 if (state
->scanner
->value
.v_char
!= '=') {
258 ini_append_error_expecting(state
,
259 state
->scanner
, "'='");
263 state
->expecting
= INI_EXPECT_VALUE
;
265 case INI_EXPECT_VALUE
:
267 switch (token_type
) {
269 if (state
->scanner
->value
.v_char
== '-') {
270 /* Negative number */
272 INI_EXPECT_VALUE_NUMBER_NEG
;
275 ini_append_error_expecting(state
,
276 state
->scanner
, "value");
282 /* Positive integer */
283 uint64_t int_val
= state
->scanner
->value
.v_int64
;
285 if (int_val
> (1ULL << 63) - 1) {
286 g_string_append_printf(state
->ini_error
,
287 "Integer value %" PRIu64
" is outside the range of a 64-bit signed integer\n",
292 value
= bt_value_integer_create_init(
297 /* Positive floating point number */
298 value
= bt_value_float_create_init(
299 state
->scanner
->value
.v_float
);
303 value
= bt_value_string_create_init(
304 state
->scanner
->value
.v_string
);
306 case G_TOKEN_IDENTIFIER
:
309 * Using symbols would be appropriate here,
310 * but said symbols are allowed as map key,
311 * so it's easier to consider everything an
314 * If one of the known symbols is not
315 * recognized here, then fall back to creating
318 const char *id
= state
->scanner
->value
.v_identifier
;
320 if (!strcmp(id
, "null") || !strcmp(id
, "NULL") ||
321 !strcmp(id
, "nul")) {
322 value
= bt_value_null
;
323 } else if (!strcmp(id
, "true") || !strcmp(id
, "TRUE") ||
324 !strcmp(id
, "yes") ||
325 !strcmp(id
, "YES")) {
326 value
= bt_value_bool_create_init(true);
327 } else if (!strcmp(id
, "false") ||
328 !strcmp(id
, "FALSE") ||
331 value
= bt_value_bool_create_init(false);
333 value
= bt_value_string_create_init(id
);
338 /* Unset value variable will trigger the error */
343 ini_append_error_expecting(state
,
344 state
->scanner
, "value");
348 state
->expecting
= INI_EXPECT_COMMA
;
351 case INI_EXPECT_VALUE_NUMBER_NEG
:
353 switch (token_type
) {
356 /* Negative integer */
357 uint64_t int_val
= state
->scanner
->value
.v_int64
;
359 if (int_val
> (1ULL << 63) - 1) {
360 g_string_append_printf(state
->ini_error
,
361 "Integer value -%" PRIu64
" is outside the range of a 64-bit signed integer\n",
366 value
= bt_value_integer_create_init(
367 -((int64_t) int_val
));
371 /* Negative floating point number */
372 value
= bt_value_float_create_init(
373 -state
->scanner
->value
.v_float
);
376 /* Unset value variable will trigger the error */
381 ini_append_error_expecting(state
,
382 state
->scanner
, "value");
386 state
->expecting
= INI_EXPECT_COMMA
;
389 case INI_EXPECT_COMMA
:
390 if (token_type
!= G_TOKEN_CHAR
) {
391 ini_append_error_expecting(state
,
392 state
->scanner
, "','");
396 if (state
->scanner
->value
.v_char
!= ',') {
397 ini_append_error_expecting(state
,
398 state
->scanner
, "','");
402 state
->expecting
= INI_EXPECT_MAP_KEY
;
414 if (bt_value_map_insert(state
->params
,
415 state
->last_map_key
, value
)) {
416 /* Only override return value on error */
427 * Converts an INI-style argument to an equivalent map value object.
429 * Return value is owned by the caller.
432 struct bt_value
*bt_value_from_ini(const char *arg
, GString
*ini_error
)
434 /* Lexical scanner configuration */
435 GScannerConfig scanner_config
= {
436 /* Skip whitespaces */
437 .cset_skip_characters
= " \t\n",
439 /* Identifier syntax is: [a-zA-Z_][a-zA-Z0-9_.:-]* */
440 .cset_identifier_first
=
444 .cset_identifier_nth
=
449 /* "hello" and "Hello" two different keys */
450 .case_sensitive
= TRUE
,
453 .cpair_comment_single
= NULL
,
454 .skip_comment_multi
= TRUE
,
455 .skip_comment_single
= TRUE
,
456 .scan_comment_multi
= FALSE
,
459 * Do scan identifiers, including 1-char identifiers,
460 * but NULL is a normal identifier.
462 .scan_identifier
= TRUE
,
463 .scan_identifier_1char
= TRUE
,
464 .scan_identifier_NULL
= FALSE
,
467 * No specific symbols: null and boolean "symbols" are
468 * scanned as plain identifiers.
470 .scan_symbols
= FALSE
,
471 .symbol_2_token
= FALSE
,
472 .scope_0_fallback
= FALSE
,
475 * Scan "0b"-, "0"-, and "0x"-prefixed integers, but not
476 * integers prefixed with "$".
482 .scan_hex_dollar
= FALSE
,
484 /* Convert scanned numbers to integer tokens */
485 .numbers_2_int
= TRUE
,
487 /* Support both integers and floating-point numbers */
488 .int_2_float
= FALSE
,
490 /* Scan integers as 64-bit signed integers */
493 /* Only scan double-quoted strings */
494 .scan_string_sq
= FALSE
,
495 .scan_string_dq
= TRUE
,
497 /* Do not converter identifiers to string tokens */
498 .identifier_2_string
= FALSE
,
500 /* Scan characters as G_TOKEN_CHAR token */
501 .char_2_token
= FALSE
,
503 struct ini_parsing_state state
= {
506 .expecting
= INI_EXPECT_MAP_KEY
,
508 .ini_error
= ini_error
,
511 state
.params
= bt_value_map_create();
516 state
.scanner
= g_scanner_new(&scanner_config
);
517 if (!state
.scanner
) {
521 /* Let the scan begin */
522 g_scanner_input_text(state
.scanner
, arg
, strlen(arg
));
525 int ret
= ini_handle_state(&state
);
530 } else if (ret
> 0) {
539 BT_PUT(state
.params
);
543 g_scanner_destroy(state
.scanner
);
546 free(state
.last_map_key
);
551 * Returns the parameters map value object from a command-line
552 * parameter option's argument.
554 * Return value is owned by the caller.
557 struct bt_value
*bt_value_from_arg(const char *arg
)
559 struct bt_value
*params
= NULL
;
560 GString
*ini_error
= NULL
;
562 ini_error
= g_string_new(NULL
);
568 /* Try INI-style parsing */
569 params
= bt_value_from_ini(arg
, ini_error
);
571 printf_err("%s", ini_error
->str
);
577 g_string_free(ini_error
, TRUE
);
583 * Returns the plugin and component class names, and the instance name,
584 * from a command-line source/filter/sink option's argument. arg must
585 * have the following format:
589 * where NAME is the optional component name, PLUGIN is the plugin name,
590 * and CLS is the component class name.
592 * On success, both *plugin and *component are not NULL. *plugin
593 * and *component are owned by the caller. On success, *name can be NULL
594 * if no component name was found.
597 void plugin_comp_cls_names(const char *arg
, char **name
, char **plugin
,
600 const char *at
= arg
;
601 GString
*gs_name
= NULL
;
602 GString
*gs_plugin
= NULL
;
603 GString
*gs_comp_cls
= NULL
;
610 if (!bt_common_string_is_printable(arg
)) {
611 printf_err("Argument contains a non-printable character\n");
615 /* Parse the component name */
616 gs_name
= bt_common_string_until(at
, ".:\\", ":", &end_pos
);
621 if (arg
[end_pos
] == ':') {
625 g_string_assign(gs_name
, "");
628 /* Parse the plugin name */
629 gs_plugin
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
630 if (!gs_plugin
|| gs_plugin
->len
== 0 || at
[end_pos
] == '\0') {
636 /* Parse the component class name */
637 gs_comp_cls
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
638 if (!gs_comp_cls
|| gs_comp_cls
->len
== 0) {
642 if (at
[end_pos
] != '\0') {
643 /* Found a non-escaped `.` */
648 if (gs_name
->len
== 0) {
650 g_string_free(gs_name
, TRUE
);
652 *name
= gs_name
->str
;
653 g_string_free(gs_name
, FALSE
);
656 g_string_free(gs_name
, TRUE
);
659 *plugin
= gs_plugin
->str
;
660 *comp_cls
= gs_comp_cls
->str
;
661 g_string_free(gs_plugin
, FALSE
);
662 g_string_free(gs_comp_cls
, FALSE
);
670 g_string_free(gs_name
, TRUE
);
674 g_string_free(gs_plugin
, TRUE
);
678 g_string_free(gs_comp_cls
, TRUE
);
693 * Prints the Babeltrace version.
696 void print_version(void)
698 puts("Babeltrace " VERSION
);
702 * Destroys a component configuration.
705 void bt_config_component_destroy(struct bt_object
*obj
)
707 struct bt_config_component
*bt_config_component
=
708 container_of(obj
, struct bt_config_component
, base
);
714 if (bt_config_component
->plugin_name
) {
715 g_string_free(bt_config_component
->plugin_name
, TRUE
);
718 if (bt_config_component
->comp_cls_name
) {
719 g_string_free(bt_config_component
->comp_cls_name
, TRUE
);
722 if (bt_config_component
->instance_name
) {
723 g_string_free(bt_config_component
->instance_name
, TRUE
);
726 BT_PUT(bt_config_component
->params
);
727 g_free(bt_config_component
);
734 * Creates a component configuration using the given plugin name and
735 * component name. `plugin_name` and `comp_cls_name` are copied (belong
736 * to the return value).
738 * Return value is owned by the caller.
741 struct bt_config_component
*bt_config_component_create(
742 enum bt_component_class_type type
,
743 const char *plugin_name
, const char *comp_cls_name
)
745 struct bt_config_component
*cfg_component
= NULL
;
747 cfg_component
= g_new0(struct bt_config_component
, 1);
748 if (!cfg_component
) {
753 bt_object_init(cfg_component
, bt_config_component_destroy
);
754 cfg_component
->type
= type
;
755 cfg_component
->plugin_name
= g_string_new(plugin_name
);
756 if (!cfg_component
->plugin_name
) {
761 cfg_component
->comp_cls_name
= g_string_new(comp_cls_name
);
762 if (!cfg_component
->comp_cls_name
) {
767 cfg_component
->instance_name
= g_string_new(NULL
);
768 if (!cfg_component
->instance_name
) {
773 /* Start with empty parameters */
774 cfg_component
->params
= bt_value_map_create();
775 if (!cfg_component
->params
) {
783 BT_PUT(cfg_component
);
786 return cfg_component
;
790 * Creates a component configuration from a command-line source/sink
794 struct bt_config_component
*bt_config_component_from_arg(
795 enum bt_component_class_type type
, const char *arg
)
797 struct bt_config_component
*cfg_comp
= NULL
;
799 char *plugin_name
= NULL
;
800 char *comp_cls_name
= NULL
;
802 plugin_comp_cls_names(arg
, &name
, &plugin_name
, &comp_cls_name
);
803 if (!plugin_name
|| !comp_cls_name
) {
804 printf_err("Cannot get plugin or component class name\n");
808 cfg_comp
= bt_config_component_create(type
, plugin_name
, comp_cls_name
);
814 g_string_assign(cfg_comp
->instance_name
, name
);
825 g_free(comp_cls_name
);
830 * Destroys a configuration.
833 void bt_config_destroy(struct bt_object
*obj
)
835 struct bt_config
*cfg
=
836 container_of(obj
, struct bt_config
, base
);
842 BT_PUT(cfg
->plugin_paths
);
844 switch (cfg
->command
) {
845 case BT_CONFIG_COMMAND_RUN
:
846 if (cfg
->cmd_data
.run
.sources
) {
847 g_ptr_array_free(cfg
->cmd_data
.run
.sources
, TRUE
);
850 if (cfg
->cmd_data
.run
.filters
) {
851 g_ptr_array_free(cfg
->cmd_data
.run
.filters
, TRUE
);
854 if (cfg
->cmd_data
.run
.sinks
) {
855 g_ptr_array_free(cfg
->cmd_data
.run
.sinks
, TRUE
);
858 if (cfg
->cmd_data
.run
.connections
) {
859 g_ptr_array_free(cfg
->cmd_data
.run
.connections
,
863 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
865 case BT_CONFIG_COMMAND_HELP
:
866 BT_PUT(cfg
->cmd_data
.help
.cfg_component
);
868 case BT_CONFIG_COMMAND_QUERY
:
869 BT_PUT(cfg
->cmd_data
.query
.cfg_component
);
871 if (cfg
->cmd_data
.query
.object
) {
872 g_string_free(cfg
->cmd_data
.query
.object
, TRUE
);
875 case BT_CONFIG_COMMAND_PRINT_CTF_METADATA
:
876 if (cfg
->cmd_data
.print_ctf_metadata
.path
) {
877 g_string_free(cfg
->cmd_data
.print_ctf_metadata
.path
,
881 case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
:
882 if (cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
884 cfg
->cmd_data
.print_lttng_live_sessions
.url
,
899 void destroy_glist_of_gstring(GList
*list
)
907 for (at
= list
; at
!= NULL
; at
= g_list_next(at
)) {
908 g_string_free(at
->data
, TRUE
);
915 * Creates a simple lexical scanner for parsing comma-delimited names
918 * Return value is owned by the caller.
921 GScanner
*create_csv_identifiers_scanner(void)
924 GScannerConfig scanner_config
= {
925 .cset_skip_characters
= " \t\n",
926 .cset_identifier_first
= G_CSET_a_2_z G_CSET_A_2_Z
"_",
927 .cset_identifier_nth
= G_CSET_a_2_z G_CSET_A_2_Z
":_-",
928 .case_sensitive
= TRUE
,
929 .cpair_comment_single
= NULL
,
930 .skip_comment_multi
= TRUE
,
931 .skip_comment_single
= TRUE
,
932 .scan_comment_multi
= FALSE
,
933 .scan_identifier
= TRUE
,
934 .scan_identifier_1char
= TRUE
,
935 .scan_identifier_NULL
= FALSE
,
936 .scan_symbols
= FALSE
,
937 .symbol_2_token
= FALSE
,
938 .scope_0_fallback
= FALSE
,
939 .scan_binary
= FALSE
,
943 .scan_hex_dollar
= FALSE
,
944 .numbers_2_int
= FALSE
,
945 .int_2_float
= FALSE
,
946 .store_int64
= FALSE
,
947 .scan_string_sq
= FALSE
,
948 .scan_string_dq
= FALSE
,
949 .identifier_2_string
= FALSE
,
950 .char_2_token
= TRUE
,
953 scanner
= g_scanner_new(&scanner_config
);
962 * Converts a comma-delimited list of known names (--names option) to
963 * an array value object containing those names as string value objects.
965 * Return value is owned by the caller.
968 struct bt_value
*names_from_arg(const char *arg
)
970 GScanner
*scanner
= NULL
;
971 struct bt_value
*names
= NULL
;
972 bool found_all
= false, found_none
= false, found_item
= false;
974 names
= bt_value_array_create();
980 scanner
= create_csv_identifiers_scanner();
985 g_scanner_input_text(scanner
, arg
, strlen(arg
));
988 GTokenType token_type
= g_scanner_get_next_token(scanner
);
990 switch (token_type
) {
991 case G_TOKEN_IDENTIFIER
:
993 const char *identifier
= scanner
->value
.v_identifier
;
995 if (!strcmp(identifier
, "payload") ||
996 !strcmp(identifier
, "args") ||
997 !strcmp(identifier
, "arg")) {
999 if (bt_value_array_append_string(names
,
1003 } else if (!strcmp(identifier
, "context") ||
1004 !strcmp(identifier
, "ctx")) {
1006 if (bt_value_array_append_string(names
,
1010 } else if (!strcmp(identifier
, "scope") ||
1011 !strcmp(identifier
, "header")) {
1013 if (bt_value_array_append_string(names
,
1017 } else if (!strcmp(identifier
, "all")) {
1019 if (bt_value_array_append_string(names
,
1023 } else if (!strcmp(identifier
, "none")) {
1025 if (bt_value_array_append_string(names
,
1030 printf_err("Unknown name: `%s`\n",
1046 if (found_none
&& found_all
) {
1047 printf_err("Only either `all` or `none` can be specified in the list given to the --names option, but not both.\n");
1051 * Legacy behavior is to clear the defaults (show none) when at
1052 * least one item is specified.
1054 if (found_item
&& !found_none
&& !found_all
) {
1055 if (bt_value_array_append_string(names
, "none")) {
1060 g_scanner_destroy(scanner
);
1067 g_scanner_destroy(scanner
);
1073 * Converts a comma-delimited list of known fields (--fields option) to
1074 * an array value object containing those fields as string
1077 * Return value is owned by the caller.
1080 struct bt_value
*fields_from_arg(const char *arg
)
1082 GScanner
*scanner
= NULL
;
1083 struct bt_value
*fields
;
1085 fields
= bt_value_array_create();
1091 scanner
= create_csv_identifiers_scanner();
1096 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1099 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1101 switch (token_type
) {
1102 case G_TOKEN_IDENTIFIER
:
1104 const char *identifier
= scanner
->value
.v_identifier
;
1106 if (!strcmp(identifier
, "trace") ||
1107 !strcmp(identifier
, "trace:hostname") ||
1108 !strcmp(identifier
, "trace:domain") ||
1109 !strcmp(identifier
, "trace:procname") ||
1110 !strcmp(identifier
, "trace:vpid") ||
1111 !strcmp(identifier
, "loglevel") ||
1112 !strcmp(identifier
, "emf") ||
1113 !strcmp(identifier
, "callsite") ||
1114 !strcmp(identifier
, "all")) {
1115 if (bt_value_array_append_string(fields
,
1120 printf_err("Unknown field: `%s`\n",
1142 g_scanner_destroy(scanner
);
1148 void append_param_arg(GString
*params_arg
, const char *key
, const char *value
)
1154 if (params_arg
->len
!= 0) {
1155 g_string_append_c(params_arg
, ',');
1158 g_string_append(params_arg
, key
);
1159 g_string_append_c(params_arg
, '=');
1160 g_string_append(params_arg
, value
);
1164 * Inserts the equivalent "prefix-NAME=yes" strings into params_arg
1165 * where the names are in names_array.
1168 int insert_flat_params_from_array(GString
*params_arg
,
1169 struct bt_value
*names_array
, const char *prefix
)
1173 GString
*tmpstr
= NULL
, *default_value
= NULL
;
1174 bool default_set
= false, non_default_set
= false;
1177 * names_array may be NULL if no CLI options were specified to
1178 * trigger its creation.
1184 tmpstr
= g_string_new(NULL
);
1191 default_value
= g_string_new(NULL
);
1192 if (!default_value
) {
1198 for (i
= 0; i
< bt_value_array_size(names_array
); i
++) {
1199 struct bt_value
*str_obj
= bt_value_array_get(names_array
, i
);
1201 bool is_default
= false;
1204 printf_err("Unexpected error\n");
1209 ret
= bt_value_string_get(str_obj
, &suffix
);
1212 printf_err("Unexpected error\n");
1216 g_string_assign(tmpstr
, prefix
);
1217 g_string_append(tmpstr
, "-");
1219 /* Special-case for "all" and "none". */
1220 if (!strcmp(suffix
, "all")) {
1222 g_string_assign(default_value
, "show");
1223 } else if (!strcmp(suffix
, "none")) {
1225 g_string_assign(default_value
, "hide");
1229 g_string_append(tmpstr
, "default");
1230 append_param_arg(params_arg
, tmpstr
->str
,
1231 default_value
->str
);
1233 non_default_set
= true;
1234 g_string_append(tmpstr
, suffix
);
1235 append_param_arg(params_arg
, tmpstr
->str
, "yes");
1239 /* Implicit field-default=hide if any non-default option is set. */
1240 if (non_default_set
&& !default_set
) {
1241 g_string_assign(tmpstr
, prefix
);
1242 g_string_append(tmpstr
, "-default");
1243 g_string_assign(default_value
, "hide");
1244 append_param_arg(params_arg
, tmpstr
->str
, default_value
->str
);
1248 if (default_value
) {
1249 g_string_free(default_value
, TRUE
);
1253 g_string_free(tmpstr
, TRUE
);
1266 OPT_CLOCK_FORCE_CORRELATE
,
1269 OPT_CLOCK_OFFSET_NS
,
1275 OPT_DEBUG_INFO_FULL_PATH
,
1276 OPT_DEBUG_INFO_TARGET_PREFIX
,
1288 OPT_OMIT_HOME_PLUGIN_PATH
,
1289 OPT_OMIT_SYSTEM_PLUGIN_PATH
,
1295 OPT_RESET_BASE_PARAMS
,
1301 OPT_STREAM_INTERSECTION
,
1308 enum bt_config_component_dest
{
1309 BT_CONFIG_COMPONENT_DEST_SOURCE
,
1310 BT_CONFIG_COMPONENT_DEST_FILTER
,
1311 BT_CONFIG_COMPONENT_DEST_SINK
,
1315 * Adds a configuration component to the appropriate configuration
1316 * array depending on the destination.
1319 void add_run_cfg_comp(struct bt_config
*cfg
,
1320 struct bt_config_component
*cfg_comp
,
1321 enum bt_config_component_dest dest
)
1326 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
1327 g_ptr_array_add(cfg
->cmd_data
.run
.sources
, cfg_comp
);
1329 case BT_CONFIG_COMPONENT_DEST_FILTER
:
1330 g_ptr_array_add(cfg
->cmd_data
.run
.filters
, cfg_comp
);
1332 case BT_CONFIG_COMPONENT_DEST_SINK
:
1333 g_ptr_array_add(cfg
->cmd_data
.run
.sinks
, cfg_comp
);
1341 int add_run_cfg_comp_check_name(struct bt_config
*cfg
,
1342 struct bt_config_component
*cfg_comp
,
1343 enum bt_config_component_dest dest
,
1344 struct bt_value
*instance_names
)
1348 if (cfg_comp
->instance_name
->len
== 0) {
1349 printf_err("Found an unnamed component\n");
1354 if (bt_value_map_has_key(instance_names
, cfg_comp
->instance_name
->str
)) {
1355 printf_err("Duplicate component instance name:\n %s\n",
1356 cfg_comp
->instance_name
->str
);
1361 if (bt_value_map_insert(instance_names
,
1362 cfg_comp
->instance_name
->str
, bt_value_null
)) {
1368 add_run_cfg_comp(cfg
, cfg_comp
, dest
);
1375 int append_env_var_plugin_paths(struct bt_value
*plugin_paths
)
1380 if (bt_common_is_setuid_setgid()) {
1381 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
1385 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
1390 ret
= bt_config_append_plugin_paths(plugin_paths
, envvar
);
1394 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
1401 int append_home_and_system_plugin_paths(struct bt_value
*plugin_paths
,
1402 bool omit_system_plugin_path
, bool omit_home_plugin_path
)
1406 if (!omit_home_plugin_path
) {
1407 if (bt_common_is_setuid_setgid()) {
1408 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
1410 char *home_plugin_dir
=
1411 bt_common_get_home_plugin_path();
1413 if (home_plugin_dir
) {
1414 ret
= bt_config_append_plugin_paths(
1415 plugin_paths
, home_plugin_dir
);
1416 free(home_plugin_dir
);
1419 printf_err("Invalid home plugin path\n");
1426 if (!omit_system_plugin_path
) {
1427 if (bt_config_append_plugin_paths(plugin_paths
,
1428 bt_common_get_system_plugin_path())) {
1429 printf_err("Invalid system plugin path\n");
1435 printf_err("Cannot append home and system plugin paths\n");
1440 int append_home_and_system_plugin_paths_cfg(struct bt_config
*cfg
)
1442 return append_home_and_system_plugin_paths(cfg
->plugin_paths
,
1443 cfg
->omit_system_plugin_path
, cfg
->omit_home_plugin_path
);
1447 struct bt_config
*bt_config_base_create(enum bt_config_command command
,
1448 struct bt_value
*initial_plugin_paths
, bool needs_plugins
)
1450 struct bt_config
*cfg
;
1453 cfg
= g_new0(struct bt_config
, 1);
1459 bt_object_init(cfg
, bt_config_destroy
);
1460 cfg
->command
= command
;
1461 cfg
->command_needs_plugins
= needs_plugins
;
1463 if (initial_plugin_paths
) {
1464 cfg
->plugin_paths
= bt_get(initial_plugin_paths
);
1466 cfg
->plugin_paths
= bt_value_array_create();
1467 if (!cfg
->plugin_paths
) {
1483 struct bt_config
*bt_config_run_create(
1484 struct bt_value
*initial_plugin_paths
)
1486 struct bt_config
*cfg
;
1489 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_RUN
,
1490 initial_plugin_paths
, true);
1495 cfg
->cmd_data
.run
.sources
= g_ptr_array_new_with_free_func(
1496 (GDestroyNotify
) bt_put
);
1497 if (!cfg
->cmd_data
.run
.sources
) {
1502 cfg
->cmd_data
.run
.filters
= g_ptr_array_new_with_free_func(
1503 (GDestroyNotify
) bt_put
);
1504 if (!cfg
->cmd_data
.run
.filters
) {
1509 cfg
->cmd_data
.run
.sinks
= g_ptr_array_new_with_free_func(
1510 (GDestroyNotify
) bt_put
);
1511 if (!cfg
->cmd_data
.run
.sinks
) {
1516 cfg
->cmd_data
.run
.connections
= g_ptr_array_new_with_free_func(
1517 (GDestroyNotify
) bt_config_connection_destroy
);
1518 if (!cfg
->cmd_data
.run
.connections
) {
1533 struct bt_config
*bt_config_list_plugins_create(
1534 struct bt_value
*initial_plugin_paths
)
1536 struct bt_config
*cfg
;
1539 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_LIST_PLUGINS
,
1540 initial_plugin_paths
, true);
1555 struct bt_config
*bt_config_help_create(
1556 struct bt_value
*initial_plugin_paths
)
1558 struct bt_config
*cfg
;
1561 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_HELP
,
1562 initial_plugin_paths
, true);
1567 cfg
->cmd_data
.help
.cfg_component
=
1568 bt_config_component_create(BT_COMPONENT_CLASS_TYPE_UNKNOWN
,
1570 if (!cfg
->cmd_data
.help
.cfg_component
) {
1584 struct bt_config
*bt_config_query_create(
1585 struct bt_value
*initial_plugin_paths
)
1587 struct bt_config
*cfg
;
1590 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_QUERY
,
1591 initial_plugin_paths
, true);
1596 cfg
->cmd_data
.query
.object
= g_string_new(NULL
);
1597 if (!cfg
->cmd_data
.query
.object
) {
1612 struct bt_config
*bt_config_print_ctf_metadata_create(
1613 struct bt_value
*initial_plugin_paths
)
1615 struct bt_config
*cfg
;
1618 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_CTF_METADATA
,
1619 initial_plugin_paths
, true);
1624 cfg
->cmd_data
.print_ctf_metadata
.path
= g_string_new(NULL
);
1625 if (!cfg
->cmd_data
.print_ctf_metadata
.path
) {
1640 struct bt_config
*bt_config_print_lttng_live_sessions_create(
1641 struct bt_value
*initial_plugin_paths
)
1643 struct bt_config
*cfg
;
1646 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
,
1647 initial_plugin_paths
, true);
1652 cfg
->cmd_data
.print_lttng_live_sessions
.url
= g_string_new(NULL
);
1653 if (!cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
1668 int bt_config_append_plugin_paths_check_setuid_setgid(
1669 struct bt_value
*plugin_paths
, const char *arg
)
1673 if (bt_common_is_setuid_setgid()) {
1674 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
1678 if (bt_config_append_plugin_paths(plugin_paths
, arg
)) {
1679 printf_err("Invalid --plugin-path option's argument:\n %s\n",
1690 * Prints the expected format for a --params option.
1693 void print_expected_params_format(FILE *fp
)
1695 fprintf(fp
, "Expected format of PARAMS\n");
1696 fprintf(fp
, "-------------------------\n");
1698 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
1700 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
1701 fprintf(fp
, "where PARAM is the parameter name (C identifier plus the [:.-] characters),\n");
1702 fprintf(fp
, "and VALUE can be one of:\n");
1704 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
1705 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
1706 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
1707 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
1708 fprintf(fp
, " (`0x` prefix) signed 64-bit integer.\n");
1709 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
1710 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
1711 fprintf(fp
, " the null and boolean value symbols above.\n");
1712 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
1714 fprintf(fp
, "You can put whitespaces allowed around individual `=` and `,` symbols.\n");
1716 fprintf(fp
, "Example:\n");
1718 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
1719 fprintf(fp
, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
1720 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
1722 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
1723 fprintf(fp
, "babeltrace from a shell.\n");
1728 * Prints the help command usage.
1731 void print_help_usage(FILE *fp
)
1733 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
1734 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --source=PLUGIN.CLS\n");
1735 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --filter=PLUGIN.CLS\n");
1736 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --sink=PLUGIN.CLS\n");
1738 fprintf(fp
, "Options:\n");
1740 fprintf(fp
, " -f, --filter=PLUGIN.CLS Get help for the filter component class\n");
1741 fprintf(fp
, " CLS found in the plugin PLUGIN\n");
1742 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1743 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1744 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1745 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1746 fprintf(fp
, " dynamic plugins can be loaded\n");
1747 fprintf(fp
, " -S, --sink=PLUGIN.CLS Get help for the sink component class\n");
1748 fprintf(fp
, " CLS found in the plugin PLUGIN\n");
1749 fprintf(fp
, " -s, --source=PLUGIN.CLS Get help for the source component class\n");
1750 fprintf(fp
, " CLS found in the plugin PLUGIN\n");
1751 fprintf(fp
, " -h --help Show this help and quit\n");
1753 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
1755 fprintf(fp
, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
1759 struct poptOption help_long_options
[] = {
1760 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1761 { "filter", 'f', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
1762 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1763 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1764 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1765 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1766 { "sink", 'S', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
1767 { "source", 's', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
1768 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1772 * Creates a Babeltrace config object from the arguments of a help
1775 * *retcode is set to the appropriate exit code to use.
1778 struct bt_config
*bt_config_help_from_args(int argc
, const char *argv
[],
1779 int *retcode
, bool force_omit_system_plugin_path
,
1780 bool force_omit_home_plugin_path
,
1781 struct bt_value
*initial_plugin_paths
)
1783 poptContext pc
= NULL
;
1787 struct bt_config
*cfg
= NULL
;
1788 const char *leftover
;
1789 char *plugin_name
= NULL
, *comp_cls_name
= NULL
;
1790 char *plug_comp_cls_names
= NULL
;
1793 cfg
= bt_config_help_create(initial_plugin_paths
);
1798 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
1799 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
1800 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
1806 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
1807 help_long_options
, 0);
1809 printf_err("Cannot get popt context\n");
1813 poptReadDefaultConfig(pc
, 0);
1815 while ((opt
= poptGetNextOpt(pc
)) > 0) {
1816 arg
= poptGetOptArg(pc
);
1819 case OPT_PLUGIN_PATH
:
1820 if (bt_config_append_plugin_paths_check_setuid_setgid(
1821 cfg
->plugin_paths
, arg
)) {
1825 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
1826 cfg
->omit_system_plugin_path
= true;
1828 case OPT_OMIT_HOME_PLUGIN_PATH
:
1829 cfg
->omit_home_plugin_path
= true;
1834 if (cfg
->cmd_data
.help
.cfg_component
->type
!=
1835 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
1836 printf_err("Cannot specify more than one plugin and component class:\n %s\n",
1843 cfg
->cmd_data
.help
.cfg_component
->type
=
1844 BT_COMPONENT_CLASS_TYPE_SOURCE
;
1847 cfg
->cmd_data
.help
.cfg_component
->type
=
1848 BT_COMPONENT_CLASS_TYPE_FILTER
;
1851 cfg
->cmd_data
.help
.cfg_component
->type
=
1852 BT_COMPONENT_CLASS_TYPE_SINK
;
1857 plug_comp_cls_names
= strdup(arg
);
1858 if (!plug_comp_cls_names
) {
1864 print_help_usage(stdout
);
1869 printf_err("Unknown command-line option specified (option code %d)\n",
1878 /* Check for option parsing error */
1880 printf_err("While parsing command-line options, at option %s: %s\n",
1881 poptBadOption(pc
, 0), poptStrerror(opt
));
1885 leftover
= poptGetArg(pc
);
1887 if (cfg
->cmd_data
.help
.cfg_component
->type
!=
1888 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
1889 printf_err("Cannot specify plugin name and --source/--filter/--sink component class:\n %s\n",
1894 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1897 if (cfg
->cmd_data
.help
.cfg_component
->type
==
1898 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
1899 print_help_usage(stdout
);
1905 plugin_comp_cls_names(plug_comp_cls_names
, NULL
,
1906 &plugin_name
, &comp_cls_name
);
1907 if (plugin_name
&& comp_cls_name
) {
1908 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1910 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
,
1913 printf_err("Invalid --source/--filter/--sink option's argument:\n %s\n",
1914 plug_comp_cls_names
);
1919 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
1930 free(plug_comp_cls_names
);
1931 g_free(plugin_name
);
1932 g_free(comp_cls_name
);
1935 poptFreeContext(pc
);
1943 * Prints the help command usage.
1946 void print_query_usage(FILE *fp
)
1948 fprintf(fp
, "Usage: babeltrace [GEN OPTS] query [OPTS] OBJECT --source=PLUGIN.CLS\n");
1949 fprintf(fp
, " babeltrace [GEN OPTS] query [OPTS] OBJECT --filter=PLUGIN.CLS\n");
1950 fprintf(fp
, " babeltrace [GEN OPTS] query [OPTS] OBJECT --sink=PLUGIN.CLS\n");
1952 fprintf(fp
, "Options:\n");
1954 fprintf(fp
, " -f. --filter=PLUGIN.CLS Query object from the filter component\n");
1955 fprintf(fp
, " class CLS found in the plugin PLUGIN\n");
1956 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1957 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1958 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1959 fprintf(fp
, " -p, --params=PARAMS Set the query parameters to PARAMS\n");
1960 fprintf(fp
, " (see the expected format of PARAMS below)\n");
1961 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1962 fprintf(fp
, " dynamic plugins can be loaded\n");
1963 fprintf(fp
, " -S, --sink=PLUGIN.CLS Query object from the sink component class\n");
1964 fprintf(fp
, " CLS found in the plugin PLUGIN\n");
1965 fprintf(fp
, " -s, --source=PLUGIN.CLS Query object from the source component\n");
1966 fprintf(fp
, " class CLS found in the plugin PLUGIN\n");
1967 fprintf(fp
, " -h --help Show this help and quit\n");
1968 fprintf(fp
, "\n\n");
1969 print_expected_params_format(fp
);
1973 struct poptOption query_long_options
[] = {
1974 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1975 { "filter", 'f', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
1976 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1977 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1978 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1979 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
1980 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1981 { "sink", 'S', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
1982 { "source", 's', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
1983 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1987 * Creates a Babeltrace config object from the arguments of a query
1990 * *retcode is set to the appropriate exit code to use.
1993 struct bt_config
*bt_config_query_from_args(int argc
, const char *argv
[],
1994 int *retcode
, bool force_omit_system_plugin_path
,
1995 bool force_omit_home_plugin_path
,
1996 struct bt_value
*initial_plugin_paths
)
1998 poptContext pc
= NULL
;
2002 struct bt_config
*cfg
= NULL
;
2003 const char *leftover
;
2004 struct bt_value
*params
= bt_value_null
;
2007 cfg
= bt_config_query_create(initial_plugin_paths
);
2012 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2013 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2014 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2020 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2021 query_long_options
, 0);
2023 printf_err("Cannot get popt context\n");
2027 poptReadDefaultConfig(pc
, 0);
2029 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2030 arg
= poptGetOptArg(pc
);
2033 case OPT_PLUGIN_PATH
:
2034 if (bt_config_append_plugin_paths_check_setuid_setgid(
2035 cfg
->plugin_paths
, arg
)) {
2039 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2040 cfg
->omit_system_plugin_path
= true;
2042 case OPT_OMIT_HOME_PLUGIN_PATH
:
2043 cfg
->omit_home_plugin_path
= true;
2049 enum bt_component_class_type type
;
2051 if (cfg
->cmd_data
.query
.cfg_component
) {
2052 printf_err("Cannot specify more than one plugin and component class:\n %s\n",
2059 type
= BT_COMPONENT_CLASS_TYPE_SOURCE
;
2062 type
= BT_COMPONENT_CLASS_TYPE_FILTER
;
2065 type
= BT_COMPONENT_CLASS_TYPE_SINK
;
2071 cfg
->cmd_data
.query
.cfg_component
=
2072 bt_config_component_from_arg(type
, arg
);
2073 if (!cfg
->cmd_data
.query
.cfg_component
) {
2074 printf_err("Invalid format for --source/--filter/--sink option's argument:\n %s\n",
2079 /* Default parameters: null */
2080 bt_put(cfg
->cmd_data
.query
.cfg_component
->params
);
2081 cfg
->cmd_data
.query
.cfg_component
->params
=
2087 params
= bt_value_from_arg(arg
);
2089 printf_err("Invalid format for --params option's argument:\n %s\n",
2096 print_query_usage(stdout
);
2101 printf_err("Unknown command-line option specified (option code %d)\n",
2110 if (!cfg
->cmd_data
.query
.cfg_component
) {
2111 printf_err("No target component class specified with --source/--filter/--sink option\n");
2116 BT_MOVE(cfg
->cmd_data
.query
.cfg_component
->params
, params
);
2118 /* Check for option parsing error */
2120 printf_err("While parsing command-line options, at option %s: %s\n",
2121 poptBadOption(pc
, 0), poptStrerror(opt
));
2126 * We need exactly one leftover argument which is the
2129 leftover
= poptGetArg(pc
);
2131 if (strlen(leftover
) == 0) {
2132 printf_err("Invalid empty object\n");
2136 g_string_assign(cfg
->cmd_data
.query
.object
, leftover
);
2138 print_query_usage(stdout
);
2144 leftover
= poptGetArg(pc
);
2146 printf_err("Unexpected argument: %s\n", leftover
);
2150 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2162 poptFreeContext(pc
);
2171 * Prints the list-plugins command usage.
2174 void print_list_plugins_usage(FILE *fp
)
2176 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
2178 fprintf(fp
, "Options:\n");
2180 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2181 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2182 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2183 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2184 fprintf(fp
, " dynamic plugins can be loaded\n");
2185 fprintf(fp
, " -h --help Show this help and quit\n");
2187 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2189 fprintf(fp
, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
2193 struct poptOption list_plugins_long_options
[] = {
2194 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2195 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2196 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2197 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2198 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2199 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2203 * Creates a Babeltrace config object from the arguments of a
2204 * list-plugins command.
2206 * *retcode is set to the appropriate exit code to use.
2209 struct bt_config
*bt_config_list_plugins_from_args(int argc
, const char *argv
[],
2210 int *retcode
, bool force_omit_system_plugin_path
,
2211 bool force_omit_home_plugin_path
,
2212 struct bt_value
*initial_plugin_paths
)
2214 poptContext pc
= NULL
;
2218 struct bt_config
*cfg
= NULL
;
2219 const char *leftover
;
2222 cfg
= bt_config_list_plugins_create(initial_plugin_paths
);
2227 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2228 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2229 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2235 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2236 list_plugins_long_options
, 0);
2238 printf_err("Cannot get popt context\n");
2242 poptReadDefaultConfig(pc
, 0);
2244 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2245 arg
= poptGetOptArg(pc
);
2248 case OPT_PLUGIN_PATH
:
2249 if (bt_config_append_plugin_paths_check_setuid_setgid(
2250 cfg
->plugin_paths
, arg
)) {
2254 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2255 cfg
->omit_system_plugin_path
= true;
2257 case OPT_OMIT_HOME_PLUGIN_PATH
:
2258 cfg
->omit_home_plugin_path
= true;
2261 print_list_plugins_usage(stdout
);
2266 printf_err("Unknown command-line option specified (option code %d)\n",
2275 /* Check for option parsing error */
2277 printf_err("While parsing command-line options, at option %s: %s\n",
2278 poptBadOption(pc
, 0), poptStrerror(opt
));
2282 leftover
= poptGetArg(pc
);
2284 printf_err("Unexpected argument: %s\n", leftover
);
2288 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2300 poptFreeContext(pc
);
2308 * Prints the run command usage.
2311 void print_run_usage(FILE *fp
)
2313 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] run [OPTIONS]\n");
2315 fprintf(fp
, "Options:\n");
2317 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
2318 fprintf(fp
, " for all the following components until\n");
2319 fprintf(fp
, " --reset-base-params is encountered\n");
2320 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2321 fprintf(fp
, " -c, --connect=CONNECTION Connect two created components (see the\n");
2322 fprintf(fp
, " expected format of CONNECTION below)\n");
2323 fprintf(fp
, " -f, --filter=[NAME:]PLUGIN.CLS Instantiate a filter component from plugin\n");
2324 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2325 fprintf(fp
, " the current component, and if NAME is\n");
2326 fprintf(fp
, " given, set its instance name to NAME\n");
2327 fprintf(fp
, " --key=KEY Set the current initialization string\n");
2328 fprintf(fp
, " parameter key to KEY (see --value)\n");
2329 fprintf(fp
, " -n, --name=NAME Set the name of the current component\n");
2330 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2331 fprintf(fp
, " names of the created components)\n");
2332 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2333 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2334 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2335 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2336 fprintf(fp
, " current component (see the expected format\n");
2337 fprintf(fp
, " of PARAMS below)\n");
2338 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2339 fprintf(fp
, " dynamic plugins can be loaded\n");
2340 fprintf(fp
, " -r, --reset-base-params Reset the current base parameters to an\n");
2341 fprintf(fp
, " empty map\n");
2342 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2343 fprintf(fp
, " the graph later, retry in DUR µs\n");
2344 fprintf(fp
, " (default: 100000)\n");
2345 fprintf(fp
, " -S, --sink=[NAME:]PLUGIN.CLS Instantiate a sink component from plugin\n");
2346 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2347 fprintf(fp
, " the current component, and if NAME is\n");
2348 fprintf(fp
, " given, set its instance name to NAME\n");
2349 fprintf(fp
, " -s, --source=[NAME:]PLUGIN.CLS Instantiate a source component from plugin\n");
2350 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2351 fprintf(fp
, " the current component, and if NAME is\n");
2352 fprintf(fp
, " given, set its instance name to NAME\n");
2353 fprintf(fp
, " --value=VAL Add a string initialization parameter to\n");
2354 fprintf(fp
, " the current component with a name given by\n");
2355 fprintf(fp
, " the last argument of the --key option and a\n");
2356 fprintf(fp
, " value set to VAL\n");
2357 fprintf(fp
, " -h --help Show this help and quit\n");
2359 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2360 fprintf(fp
, "\n\n");
2361 fprintf(fp
, "Expected format of CONNECTION\n");
2362 fprintf(fp
, "-----------------------------\n");
2364 fprintf(fp
, " UPSTREAM[.UPSTREAM-PORT]:DOWNSTREAM[.DOWNSTREAM-PORT]\n");
2366 fprintf(fp
, "UPSTREAM and DOWNSTREAM are names of the upstream and downstream\n");
2367 fprintf(fp
, "components to connect together. You must escape the following characters\n\n");
2368 fprintf(fp
, "with `\\`: `\\`, `.`, and `:`. You can set the name of the current\n");
2369 fprintf(fp
, "component with the --name option.\n");
2371 fprintf(fp
, "UPSTREAM-PORT and DOWNSTREAM-PORT are optional globbing patterns to\n");
2372 fprintf(fp
, "identify the upstream and downstream ports to use for the connection.\n");
2373 fprintf(fp
, "When the port is not specified, `*` is used.\n");
2375 fprintf(fp
, "When a component named UPSTREAM has an available port which matches the\n");
2376 fprintf(fp
, "UPSTREAM-PORT globbing pattern, it is connected to the first port which\n");
2377 fprintf(fp
, "matches the DOWNSTREAM-PORT globbing pattern of the component named\n");
2378 fprintf(fp
, "DOWNSTREAM.\n");
2380 fprintf(fp
, "The only special character in UPSTREAM-PORT and DOWNSTREAM-PORT is `*`\n");
2381 fprintf(fp
, "which matches anything. You must escape the following characters\n");
2382 fprintf(fp
, "with `\\`: `\\`, `*`, `?`, `[`, `.`, and `:`.\n");
2384 fprintf(fp
, "You can connect a source component to a filter or sink component. You\n");
2385 fprintf(fp
, "can connect a filter component to a sink component.\n");
2387 fprintf(fp
, "Examples:\n");
2389 fprintf(fp
, " my-src:my-sink\n");
2390 fprintf(fp
, " ctf-fs.*stream*:utils-muxer:*\n");
2392 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
2393 fprintf(fp
, "babeltrace from a shell.\n");
2394 fprintf(fp
, "\n\n");
2395 print_expected_params_format(fp
);
2399 * Creates a Babeltrace config object from the arguments of a run
2402 * *retcode is set to the appropriate exit code to use.
2405 struct bt_config
*bt_config_run_from_args(int argc
, const char *argv
[],
2406 int *retcode
, bool force_omit_system_plugin_path
,
2407 bool force_omit_home_plugin_path
,
2408 struct bt_value
*initial_plugin_paths
)
2410 poptContext pc
= NULL
;
2412 struct bt_config_component
*cur_cfg_comp
= NULL
;
2413 enum bt_config_component_dest cur_cfg_comp_dest
;
2414 struct bt_value
*cur_base_params
= NULL
;
2416 struct bt_config
*cfg
= NULL
;
2417 struct bt_value
*instance_names
= NULL
;
2418 struct bt_value
*connection_args
= NULL
;
2419 GString
*cur_param_key
= NULL
;
2420 char error_buf
[256] = { 0 };
2421 long long retry_duration
= -1;
2422 struct poptOption run_long_options
[] = {
2423 { "base-params", 'b', POPT_ARG_STRING
, NULL
, OPT_BASE_PARAMS
, NULL
, NULL
},
2424 { "connect", 'c', POPT_ARG_STRING
, NULL
, OPT_CONNECT
, NULL
, NULL
},
2425 { "filter", 'f', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
2426 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2427 { "key", '\0', POPT_ARG_STRING
, NULL
, OPT_KEY
, NULL
, NULL
},
2428 { "name", 'n', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2429 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2430 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2431 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2432 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2433 { "reset-base-params", 'r', POPT_ARG_NONE
, NULL
, OPT_RESET_BASE_PARAMS
, NULL
, NULL
},
2434 { "retry-duration", '\0', POPT_ARG_LONGLONG
, &retry_duration
, OPT_RETRY_DURATION
, NULL
, NULL
},
2435 { "sink", 'S', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
2436 { "source", 's', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
2437 { "value", '\0', POPT_ARG_STRING
, NULL
, OPT_VALUE
, NULL
, NULL
},
2438 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2442 cur_param_key
= g_string_new(NULL
);
2443 if (!cur_param_key
) {
2449 print_run_usage(stdout
);
2454 cfg
= bt_config_run_create(initial_plugin_paths
);
2459 cfg
->cmd_data
.run
.retry_duration_us
= 100000;
2460 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2461 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2462 cur_base_params
= bt_value_map_create();
2463 if (!cur_base_params
) {
2468 instance_names
= bt_value_map_create();
2469 if (!instance_names
) {
2474 connection_args
= bt_value_array_create();
2475 if (!connection_args
) {
2480 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2486 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2487 run_long_options
, 0);
2489 printf_err("Cannot get popt context\n");
2493 poptReadDefaultConfig(pc
, 0);
2495 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2496 arg
= poptGetOptArg(pc
);
2499 case OPT_PLUGIN_PATH
:
2500 if (bt_config_append_plugin_paths_check_setuid_setgid(
2501 cfg
->plugin_paths
, arg
)) {
2505 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2506 cfg
->omit_system_plugin_path
= true;
2508 case OPT_OMIT_HOME_PLUGIN_PATH
:
2509 cfg
->omit_home_plugin_path
= true;
2515 enum bt_component_class_type new_comp_type
;
2516 enum bt_config_component_dest new_dest
;
2517 const char *opt_name
;
2521 new_comp_type
= BT_COMPONENT_CLASS_TYPE_SOURCE
;
2522 new_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
2523 opt_name
= "--source";
2526 new_comp_type
= BT_COMPONENT_CLASS_TYPE_FILTER
;
2527 new_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
2528 opt_name
= "--filter";
2531 new_comp_type
= BT_COMPONENT_CLASS_TYPE_SINK
;
2532 new_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
2533 opt_name
= "--sink";
2540 ret
= add_run_cfg_comp_check_name(cfg
,
2541 cur_cfg_comp
, cur_cfg_comp_dest
,
2543 BT_PUT(cur_cfg_comp
);
2549 cur_cfg_comp
= bt_config_component_from_arg(
2550 new_comp_type
, arg
);
2551 if (!cur_cfg_comp
) {
2552 printf_err("Invalid format for %s option's argument:\n %s\n",
2557 assert(cur_base_params
);
2558 bt_put(cur_cfg_comp
->params
);
2559 cur_cfg_comp
->params
= bt_value_copy(cur_base_params
);
2560 if (!cur_cfg_comp
->params
) {
2565 cur_cfg_comp_dest
= new_dest
;
2570 struct bt_value
*params
;
2571 struct bt_value
*params_to_set
;
2573 if (!cur_cfg_comp
) {
2574 printf_err("Cannot add parameters to unavailable component:\n %s\n",
2579 params
= bt_value_from_arg(arg
);
2581 printf_err("Invalid format for --params option's argument:\n %s\n",
2586 params_to_set
= bt_value_map_extend(cur_cfg_comp
->params
,
2589 if (!params_to_set
) {
2590 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
2595 BT_MOVE(cur_cfg_comp
->params
, params_to_set
);
2599 if (strlen(arg
) == 0) {
2600 printf_err("Cannot set an empty string as the current parameter key\n");
2604 g_string_assign(cur_param_key
, arg
);
2607 if (!cur_cfg_comp
) {
2608 printf_err("Cannot set a parameter's value of unavailable component:\n %s\n",
2613 if (cur_param_key
->len
== 0) {
2614 printf_err("--value option specified without preceding --key option:\n %s\n",
2619 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
2620 cur_param_key
->str
, arg
)) {
2626 if (!cur_cfg_comp
) {
2627 printf_err("Cannot set the name of unavailable component:\n %s\n",
2632 g_string_assign(cur_cfg_comp
->instance_name
, arg
);
2634 case OPT_BASE_PARAMS
:
2636 struct bt_value
*params
= bt_value_from_arg(arg
);
2639 printf_err("Invalid format for --base-params option's argument:\n %s\n",
2644 BT_MOVE(cur_base_params
, params
);
2647 case OPT_RESET_BASE_PARAMS
:
2648 BT_PUT(cur_base_params
);
2649 cur_base_params
= bt_value_map_create();
2650 if (!cur_base_params
) {
2656 if (bt_value_array_append_string(connection_args
,
2662 case OPT_RETRY_DURATION
:
2663 if (retry_duration
< 0) {
2664 printf_err("--retry-duration option's argument must be positive or 0: %lld\n",
2669 cfg
->cmd_data
.run
.retry_duration_us
=
2670 (uint64_t) retry_duration
;
2673 print_run_usage(stdout
);
2678 printf_err("Unknown command-line option specified (option code %d)\n",
2687 /* Check for option parsing error */
2689 printf_err("While parsing command-line options, at option %s: %s\n",
2690 poptBadOption(pc
, 0), poptStrerror(opt
));
2694 /* This command does not accept leftover arguments */
2695 if (poptPeekArg(pc
)) {
2696 printf_err("Unexpected argument: %s\n", poptPeekArg(pc
));
2700 /* Add current component */
2702 ret
= add_run_cfg_comp_check_name(cfg
, cur_cfg_comp
,
2703 cur_cfg_comp_dest
, instance_names
);
2704 BT_PUT(cur_cfg_comp
);
2710 if (cfg
->cmd_data
.run
.sources
->len
== 0) {
2711 printf_err("Incomplete graph: no source component\n");
2715 if (cfg
->cmd_data
.run
.sinks
->len
== 0) {
2716 printf_err("Incomplete graph: no sink component\n");
2720 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2724 ret
= bt_config_cli_args_create_connections(cfg
, connection_args
,
2727 printf_err("Cannot creation connections:\n%s", error_buf
);
2739 poptFreeContext(pc
);
2742 if (cur_param_key
) {
2743 g_string_free(cur_param_key
, TRUE
);
2747 BT_PUT(cur_cfg_comp
);
2748 BT_PUT(cur_base_params
);
2749 BT_PUT(instance_names
);
2750 BT_PUT(connection_args
);
2755 struct bt_config
*bt_config_run_from_args_array(struct bt_value
*run_args
,
2756 int *retcode
, bool force_omit_system_plugin_path
,
2757 bool force_omit_home_plugin_path
,
2758 struct bt_value
*initial_plugin_paths
)
2760 struct bt_config
*cfg
= NULL
;
2763 const size_t argc
= bt_value_array_size(run_args
) + 1;
2765 argv
= calloc(argc
, sizeof(*argv
));
2773 for (i
= 0; i
< bt_value_array_size(run_args
); i
++) {
2775 struct bt_value
*arg_value
= bt_value_array_get(run_args
, i
);
2779 ret
= bt_value_string_get(arg_value
, &arg
);
2786 cfg
= bt_config_run_from_args(argc
, argv
, retcode
,
2787 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
2788 initial_plugin_paths
);
2796 * Prints the convert command usage.
2799 void print_convert_usage(FILE *fp
)
2801 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [convert] [OPTIONS] [PATH/URL]\n");
2803 fprintf(fp
, "Options:\n");
2805 fprintf(fp
, " --filter=[NAME:]PLUGIN.CLS Instantiate a filter component from plugin\n");
2806 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2807 fprintf(fp
, " the current component, and if NAME is\n");
2808 fprintf(fp
, " given, set its instance name to NAME\n");
2809 fprintf(fp
, " --name=NAME Set the name of the current component\n");
2810 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2811 fprintf(fp
, " names of the created components)\n");
2812 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2813 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2814 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2815 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2816 fprintf(fp
, " current component (see the expected format\n");
2817 fprintf(fp
, " of PARAMS below)\n");
2818 fprintf(fp
, " -P, --path=PATH Set the `path` string parameter of the\n");
2819 fprintf(fp
, " current component to PATH\n");
2820 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2821 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2822 fprintf(fp
, " the graph later, retry in DUR µs\n");
2823 fprintf(fp
, " (default: 100000)\n");
2824 fprintf(fp
, " dynamic plugins can be loaded\n");
2825 fprintf(fp
, " --run-args Print the equivalent arguments for the\n");
2826 fprintf(fp
, " `run` command to the standard output,\n");
2827 fprintf(fp
, " formatted for a shell, and quit\n");
2828 fprintf(fp
, " --run-args-0 Print the equivalent arguments for the\n");
2829 fprintf(fp
, " `run` command to the standard output,\n");
2830 fprintf(fp
, " formatted for `xargs -0`, and quit\n");
2831 fprintf(fp
, " --sink=[NAME:]PLUGIN.CLS Instantiate a sink component from plugin\n");
2832 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2833 fprintf(fp
, " the current component, and if NAME is\n");
2834 fprintf(fp
, " given, set its instance name to NAME\n");
2835 fprintf(fp
, " --source=[NAME:]PLUGIN.CLS Instantiate a source component from plugin\n");
2836 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2837 fprintf(fp
, " the current component, and if NAME is\n");
2838 fprintf(fp
, " given, set its instance name to NAME\n");
2839 fprintf(fp
, " -u, --url=URL Set the `url` string parameter of the\n");
2840 fprintf(fp
, " current component to URL\n");
2841 fprintf(fp
, " -h --help Show this help and quit\n");
2843 fprintf(fp
, "Implicit `ctf.fs` source component options:\n");
2845 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
2846 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS ns\n");
2847 fprintf(fp
, " --stream-intersection Only process events when all streams\n");
2848 fprintf(fp
, " are active\n");
2850 fprintf(fp
, "Implicit `text.text` sink component options:\n");
2852 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
2853 fprintf(fp
, " --clock-date Print timestamp dates\n");
2854 fprintf(fp
, " --clock-gmt Print and parse timestamps in the GMT\n");
2855 fprintf(fp
, " time zone instead of the local time zone\n");
2856 fprintf(fp
, " --clock-seconds Print the timestamps as `SEC.NS` instead\n");
2857 fprintf(fp
, " of `hh:mm:ss.nnnnnnnnn`\n");
2858 fprintf(fp
, " --color=(never | auto | always)\n");
2859 fprintf(fp
, " Never, automatically, or always emit\n");
2860 fprintf(fp
, " console color codes\n");
2861 fprintf(fp
, " -f, --fields=FIELD[,FIELD]... Print additional fields; FIELD can be:\n");
2862 fprintf(fp
, " `all`, `trace`, `trace:hostname`,\n");
2863 fprintf(fp
, " `trace:domain`, `trace:procname`,\n");
2864 fprintf(fp
, " `trace:vpid`, `loglevel`, `emf`\n");
2865 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names; NAME can be:\n");
2866 fprintf(fp
, " `payload` (or `arg` or `args`), `none`,\n");
2867 fprintf(fp
, " `all`, `scope`, `header`, `context`\n");
2868 fprintf(fp
, " (or `ctx`)\n");
2869 fprintf(fp
, " --no-delta Do not print time delta between\n");
2870 fprintf(fp
, " consecutive events\n");
2871 fprintf(fp
, " -w, --output=PATH Write output text to PATH instead of\n");
2872 fprintf(fp
, " the standard output\n");
2874 fprintf(fp
, "Implicit `utils.muxer` filter component options:\n");
2876 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently\n");
2877 fprintf(fp
, " correlated across traces\n");
2879 fprintf(fp
, "Implicit `utils.trimmer` filter component options:\n");
2881 fprintf(fp
, " -b, --begin=BEGIN Set the beginning time of the conversion\n");
2882 fprintf(fp
, " time range to BEGIN (see the format of\n");
2883 fprintf(fp
, " BEGIN below)\n");
2884 fprintf(fp
, " -e, --end=END Set the end time of the conversion time\n");
2885 fprintf(fp
, " range to END (see the format of END below)\n");
2886 fprintf(fp
, " -t, --timerange=TIMERANGE Set conversion time range to TIMERANGE:\n");
2887 fprintf(fp
, " BEGIN,END or [BEGIN,END] (literally `[` and\n");
2888 fprintf(fp
, " `]`) (see the format of BEGIN/END below)\n");
2890 fprintf(fp
, "Implicit `lttng-utils.debug-info` filter component options:\n");
2892 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
2893 fprintf(fp
, " instead of `/usr/lib/debug`\n");
2894 fprintf(fp
, " --debug-info-full-path Show full debug info source and\n");
2895 fprintf(fp
, " binary paths instead of just names\n");
2896 fprintf(fp
, " --debug-info-target-prefix=DIR\n");
2897 fprintf(fp
, " Use directory DIR as a prefix when\n");
2898 fprintf(fp
, " looking up executables during debug\n");
2899 fprintf(fp
, " info analysis\n");
2900 fprintf(fp
, " --no-debug-info Do not create an implicit\n");
2901 fprintf(fp
, " `lttng-utils.debug-info` filter component\n");
2903 fprintf(fp
, "Legacy options that still work:\n");
2905 fprintf(fp
, " -i, --input-format=(ctf | lttng-live)\n");
2906 fprintf(fp
, " `ctf`:\n");
2907 fprintf(fp
, " Create an implicit `ctf.fs` source\n");
2908 fprintf(fp
, " component\n");
2909 fprintf(fp
, " `lttng-live`:\n");
2910 fprintf(fp
, " Create an implicit `ctf.lttng-live`\n");
2911 fprintf(fp
, " source component\n");
2912 fprintf(fp
, " -o, --output-format=(text | dummy | ctf-metadata)\n");
2913 fprintf(fp
, " `text`:\n");
2914 fprintf(fp
, " Create an implicit `text.text` sink\n");
2915 fprintf(fp
, " component\n");
2916 fprintf(fp
, " `dummy`:\n");
2917 fprintf(fp
, " Create an implicit `utils.dummy` sink\n");
2918 fprintf(fp
, " component\n");
2919 fprintf(fp
, " `ctf-metadata`:\n");
2920 fprintf(fp
, " Query the `ctf.fs` component class for\n");
2921 fprintf(fp
, " metadata text and quit\n");
2923 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2924 fprintf(fp
, "\n\n");
2925 fprintf(fp
, "Format of BEGIN and END\n");
2926 fprintf(fp
, "-----------------------\n");
2928 fprintf(fp
, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
2929 fprintf(fp
, "\n\n");
2930 print_expected_params_format(fp
);
2934 struct poptOption convert_long_options
[] = {
2935 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2936 { "begin", 'b', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2937 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2938 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2939 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2940 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2941 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2942 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2943 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2944 { "color", '\0', POPT_ARG_STRING
, NULL
, OPT_COLOR
, NULL
, NULL
},
2945 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2946 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2947 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2948 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2949 { "end", 'e', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2950 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2951 { "filter", '\0', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
2952 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2953 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2954 { "name", '\0', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2955 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2956 { "no-debug-info", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DEBUG_INFO
, NULL
, NULL
},
2957 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2958 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2959 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2960 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT
, NULL
, NULL
},
2961 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2962 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2963 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2964 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2965 { "retry-duration", '\0', POPT_ARG_STRING
, NULL
, OPT_RETRY_DURATION
, NULL
, NULL
},
2966 { "run-args", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS
, NULL
, NULL
},
2967 { "run-args-0", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS_0
, NULL
, NULL
},
2968 { "sink", '\0', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
2969 { "source", '\0', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
2970 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2971 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2972 { "url", 'u', POPT_ARG_STRING
, NULL
, OPT_URL
, NULL
, NULL
},
2973 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2974 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2978 GString
*get_component_auto_name(const char *prefix
,
2979 struct bt_value
*existing_names
)
2982 GString
*auto_name
= g_string_new(NULL
);
2989 if (!bt_value_map_has_key(existing_names
, prefix
)) {
2990 g_string_assign(auto_name
, prefix
);
2995 g_string_printf(auto_name
, "%s-%d", prefix
, i
);
2997 } while (bt_value_map_has_key(existing_names
, auto_name
->str
));
3003 struct implicit_component_args
{
3005 GString
*plugin_comp_cls_arg
;
3007 GString
*params_arg
;
3008 struct bt_value
*extra_args
;
3012 int assign_name_to_implicit_component(struct implicit_component_args
*args
,
3013 const char *prefix
, struct bt_value
*existing_names
,
3014 GList
**comp_names
, bool append_to_comp_names
)
3017 GString
*name
= NULL
;
3019 if (!args
->exists
) {
3023 name
= get_component_auto_name(prefix
, existing_names
);
3030 g_string_assign(args
->name_arg
, name
->str
);
3032 if (bt_value_map_insert(existing_names
, name
->str
,
3039 if (append_to_comp_names
) {
3040 *comp_names
= g_list_append(*comp_names
, name
);
3046 g_string_free(name
, TRUE
);
3053 int append_run_args_for_implicit_component(
3054 enum bt_component_class_type type
,
3055 struct implicit_component_args
*impl_args
,
3056 struct bt_value
*run_args
)
3061 if (!impl_args
->exists
) {
3066 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
3067 if (bt_value_array_append_string(run_args
, "--source")) {
3072 case BT_COMPONENT_CLASS_TYPE_FILTER
:
3073 if (bt_value_array_append_string(run_args
, "--filter")) {
3078 case BT_COMPONENT_CLASS_TYPE_SINK
:
3079 if (bt_value_array_append_string(run_args
, "--sink")) {
3088 if (bt_value_array_append_string(run_args
,
3089 impl_args
->plugin_comp_cls_arg
->str
)) {
3094 if (bt_value_array_append_string(run_args
, "--name")) {
3099 if (bt_value_array_append_string(run_args
, impl_args
->name_arg
->str
)) {
3104 if (impl_args
->params_arg
->len
> 0) {
3105 if (bt_value_array_append_string(run_args
, "--params")) {
3110 if (bt_value_array_append_string(run_args
,
3111 impl_args
->params_arg
->str
)) {
3117 for (i
= 0; i
< bt_value_array_size(impl_args
->extra_args
); i
++) {
3118 struct bt_value
*elem
;
3121 elem
= bt_value_array_get(impl_args
->extra_args
, i
);
3126 assert(bt_value_is_string(elem
));
3127 if (bt_value_string_get(elem
, &arg
)) {
3131 ret
= bt_value_array_append_string(run_args
, arg
);
3149 void destroy_implicit_component_args(struct implicit_component_args
*args
)
3153 if (args
->plugin_comp_cls_arg
) {
3154 g_string_free(args
->plugin_comp_cls_arg
, TRUE
);
3157 if (args
->name_arg
) {
3158 g_string_free(args
->name_arg
, TRUE
);
3161 if (args
->params_arg
) {
3162 g_string_free(args
->params_arg
, TRUE
);
3165 bt_put(args
->extra_args
);
3169 int init_implicit_component_args(struct implicit_component_args
*args
,
3170 const char *plugin_comp_cls_arg
, bool exists
)
3174 args
->exists
= exists
;
3175 args
->plugin_comp_cls_arg
= g_string_new(plugin_comp_cls_arg
);
3176 args
->name_arg
= g_string_new(NULL
);
3177 args
->params_arg
= g_string_new(NULL
);
3178 args
->extra_args
= bt_value_array_create();
3180 if (!args
->plugin_comp_cls_arg
|| !args
->name_arg
||
3181 !args
->params_arg
|| !args
->extra_args
) {
3183 destroy_implicit_component_args(args
);
3193 void append_implicit_component_param(struct implicit_component_args
*args
,
3194 const char *key
, const char *value
)
3199 append_param_arg(args
->params_arg
, key
, value
);
3203 int append_implicit_component_extra_arg(struct implicit_component_args
*args
,
3204 const char *key
, const char *value
)
3212 if (bt_value_array_append_string(args
->extra_args
, "--key")) {
3218 if (bt_value_array_append_string(args
->extra_args
, key
)) {
3224 if (bt_value_array_append_string(args
->extra_args
, "--value")) {
3230 if (bt_value_array_append_string(args
->extra_args
, value
)) {
3241 int convert_append_name_param(enum bt_config_component_dest dest
,
3242 GString
*cur_name
, GString
*cur_name_prefix
,
3243 struct bt_value
*run_args
, struct bt_value
*all_names
,
3244 GList
**source_names
, GList
**filter_names
,
3249 if (cur_name_prefix
->len
> 0) {
3250 /* We're after a --source/--filter/--sink */
3251 GString
*name
= NULL
;
3252 bool append_name_opt
= false;
3254 if (cur_name
->len
== 0) {
3256 * No explicit name was provided for the user
3259 name
= get_component_auto_name(
3260 cur_name_prefix
->str
,
3262 append_name_opt
= true;
3265 * An explicit name was provided for the user
3268 if (bt_value_map_has_key(all_names
,
3270 printf_err("Duplicate component instance name:\n %s\n",
3275 name
= g_string_new(cur_name
->str
);
3284 * Remember this name globally, for the uniqueness of
3285 * all component names.
3287 if (bt_value_map_insert(all_names
, name
->str
, bt_value_null
)) {
3293 * Append the --name option if necessary.
3295 if (append_name_opt
) {
3296 if (bt_value_array_append_string(run_args
, "--name")) {
3301 if (bt_value_array_append_string(run_args
, name
->str
)) {
3308 * Remember this name specifically for the type of the
3309 * component. This is to create connection arguments.
3312 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
3313 *source_names
= g_list_append(*source_names
, name
);
3315 case BT_CONFIG_COMPONENT_DEST_FILTER
:
3316 *filter_names
= g_list_append(*filter_names
, name
);
3318 case BT_CONFIG_COMPONENT_DEST_SINK
:
3319 *sink_names
= g_list_append(*sink_names
, name
);
3325 g_string_assign(cur_name_prefix
, "");
3338 * Escapes `.`, `:`, and `\` of `input` with `\`.
3341 GString
*escape_dot_colon(const char *input
)
3343 GString
*output
= g_string_new(NULL
);
3351 for (ch
= input
; *ch
!= '\0'; ch
++) {
3352 if (*ch
== '\\' || *ch
== '.' || *ch
== ':') {
3353 g_string_append_c(output
, '\\');
3356 g_string_append_c(output
, *ch
);
3364 * Appends a --connect option to a list of arguments. `upstream_name`
3365 * and `downstream_name` are escaped with escape_dot_colon() in this
3369 int append_connect_arg(struct bt_value
*run_args
,
3370 const char *upstream_name
, const char *downstream_name
)
3373 GString
*e_upstream_name
= escape_dot_colon(upstream_name
);
3374 GString
*e_downstream_name
= escape_dot_colon(downstream_name
);
3375 GString
*arg
= g_string_new(NULL
);
3377 if (!e_upstream_name
|| !e_downstream_name
|| !arg
) {
3383 ret
= bt_value_array_append_string(run_args
, "--connect");
3390 g_string_append(arg
, e_upstream_name
->str
);
3391 g_string_append_c(arg
, ':');
3392 g_string_append(arg
, e_downstream_name
->str
);
3393 ret
= bt_value_array_append_string(run_args
, arg
->str
);
3402 g_string_free(arg
, TRUE
);
3405 if (e_upstream_name
) {
3406 g_string_free(e_upstream_name
, TRUE
);
3409 if (e_downstream_name
) {
3410 g_string_free(e_downstream_name
, TRUE
);
3417 * Appends the run command's --connect options for the convert command.
3420 int convert_auto_connect(struct bt_value
*run_args
,
3421 GList
*source_names
, GList
*filter_names
,
3425 GList
*source_at
= source_names
;
3426 GList
*filter_at
= filter_names
;
3428 GList
*sink_at
= sink_names
;
3430 assert(source_names
);
3431 assert(filter_names
);
3434 /* Connect all sources to the first filter */
3435 for (source_at
= source_names
; source_at
!= NULL
; source_at
= g_list_next(source_at
)) {
3436 GString
*source_name
= source_at
->data
;
3437 GString
*filter_name
= filter_at
->data
;
3439 ret
= append_connect_arg(run_args
, source_name
->str
,
3446 filter_prev
= filter_at
;
3447 filter_at
= g_list_next(filter_at
);
3449 /* Connect remaining filters */
3450 for (; filter_at
!= NULL
; filter_prev
= filter_at
, filter_at
= g_list_next(filter_at
)) {
3451 GString
*filter_name
= filter_at
->data
;
3452 GString
*filter_prev_name
= filter_prev
->data
;
3454 ret
= append_connect_arg(run_args
, filter_prev_name
->str
,
3461 /* Connect last filter to all sinks */
3462 for (sink_at
= sink_names
; sink_at
!= NULL
; sink_at
= g_list_next(sink_at
)) {
3463 GString
*filter_name
= filter_prev
->data
;
3464 GString
*sink_name
= sink_at
->data
;
3466 ret
= append_connect_arg(run_args
, filter_name
->str
,
3483 int split_timerange(const char *arg
, char **begin
, char **end
)
3486 const char *ch
= arg
;
3488 GString
*g_begin
= NULL
;
3489 GString
*g_end
= NULL
;
3497 g_begin
= bt_common_string_until(ch
, "", ",", &end_pos
);
3498 if (!g_begin
|| ch
[end_pos
] != ',' || g_begin
->len
== 0) {
3504 g_end
= bt_common_string_until(ch
, "", "]", &end_pos
);
3505 if (!g_end
|| g_end
->len
== 0) {
3511 *begin
= g_begin
->str
;
3513 g_string_free(g_begin
, FALSE
);
3514 g_string_free(g_end
, FALSE
);
3524 g_string_free(g_begin
, TRUE
);
3528 g_string_free(g_end
, TRUE
);
3535 int g_list_prepend_gstring(GList
**list
, const char *string
)
3538 GString
*gs
= g_string_new(string
);
3547 *list
= g_list_prepend(*list
, gs
);
3554 * Creates a Babeltrace config object from the arguments of a convert
3557 * *retcode is set to the appropriate exit code to use.
3560 struct bt_config
*bt_config_convert_from_args(int argc
, const char *argv
[],
3561 int *retcode
, bool force_omit_system_plugin_path
,
3562 bool force_omit_home_plugin_path
, bool force_no_debug_info
,
3563 struct bt_value
*initial_plugin_paths
)
3565 poptContext pc
= NULL
;
3567 enum bt_config_component_dest cur_comp_dest
;
3569 struct bt_config
*cfg
= NULL
;
3570 bool got_verbose_opt
= false;
3571 bool got_debug_opt
= false;
3572 bool got_input_format_opt
= false;
3573 bool got_output_format_opt
= false;
3574 bool trimmer_has_begin
= false;
3575 bool trimmer_has_end
= false;
3576 GString
*cur_name
= NULL
;
3577 GString
*cur_name_prefix
= NULL
;
3578 const char *leftover
= NULL
;
3579 bool print_run_args
= false;
3580 bool print_run_args_0
= false;
3581 bool print_ctf_metadata
= false;
3582 struct bt_value
*run_args
= NULL
;
3583 struct bt_value
*all_names
= NULL
;
3584 GList
*source_names
= NULL
;
3585 GList
*filter_names
= NULL
;
3586 GList
*sink_names
= NULL
;
3587 struct implicit_component_args implicit_ctf_args
= { 0 };
3588 struct implicit_component_args implicit_lttng_live_args
= { 0 };
3589 struct implicit_component_args implicit_dummy_args
= { 0 };
3590 struct implicit_component_args implicit_text_args
= { 0 };
3591 struct implicit_component_args implicit_debug_info_args
= { 0 };
3592 struct implicit_component_args implicit_muxer_args
= { 0 };
3593 struct implicit_component_args implicit_trimmer_args
= { 0 };
3594 struct bt_value
*plugin_paths
= bt_get(initial_plugin_paths
);
3595 char error_buf
[256] = { 0 };
3597 struct bt_common_lttng_live_url_parts lttng_live_url_parts
= { 0 };
3602 print_convert_usage(stdout
);
3607 if (init_implicit_component_args(&implicit_ctf_args
, "ctf.fs", false)) {
3611 if (init_implicit_component_args(&implicit_lttng_live_args
,
3612 "ctf.lttng-live", false)) {
3616 if (init_implicit_component_args(&implicit_text_args
, "text.pretty",
3621 if (init_implicit_component_args(&implicit_dummy_args
, "utils.dummy",
3626 if (init_implicit_component_args(&implicit_debug_info_args
,
3627 "lttng-utils.debug-info", !force_no_debug_info
)) {
3631 if (init_implicit_component_args(&implicit_muxer_args
, "utils.muxer",
3636 if (init_implicit_component_args(&implicit_trimmer_args
,
3637 "utils.trimmer", false)) {
3641 all_names
= bt_value_map_create();
3647 run_args
= bt_value_array_create();
3653 cur_name
= g_string_new(NULL
);
3659 cur_name_prefix
= g_string_new(NULL
);
3660 if (!cur_name_prefix
) {
3665 ret
= append_env_var_plugin_paths(plugin_paths
);
3671 * First pass: collect all arguments which need to be passed
3672 * as is to the run command. This pass can also add --name
3673 * arguments if needed to automatically name unnamed component
3674 * instances. Also it does the following transformations:
3676 * --path=PATH -> --key path --value PATH
3677 * --url=URL -> --key url --value URL
3679 * Also it appends the plugin paths of --plugin-path to
3682 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3683 convert_long_options
, 0);
3685 printf_err("Cannot get popt context\n");
3689 poptReadDefaultConfig(pc
, 0);
3691 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3693 char *plugin_name
= NULL
;
3694 char *comp_cls_name
= NULL
;
3696 arg
= poptGetOptArg(pc
);
3702 /* Append current component's name if needed */
3703 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3704 cur_name_prefix
, run_args
, all_names
,
3705 &source_names
, &filter_names
, &sink_names
);
3710 /* Parse the argument */
3711 plugin_comp_cls_names(arg
, &name
, &plugin_name
,
3713 if (!plugin_name
|| !comp_cls_name
) {
3714 printf_err("Invalid format for --source/--filter/--sink option's argument:\n %s\n",
3720 g_string_assign(cur_name
, name
);
3722 g_string_assign(cur_name
, "");
3728 BT_CONFIG_COMPONENT_DEST_SOURCE
;
3729 if (bt_value_array_append_string(run_args
,
3737 BT_CONFIG_COMPONENT_DEST_FILTER
;
3738 if (bt_value_array_append_string(run_args
,
3746 BT_CONFIG_COMPONENT_DEST_SINK
;
3747 if (bt_value_array_append_string(run_args
,
3757 if (bt_value_array_append_string(run_args
, arg
)) {
3762 g_string_assign(cur_name_prefix
, "");
3763 g_string_append(cur_name_prefix
, plugin_name
);
3764 g_string_append_c(cur_name_prefix
, '.');
3765 g_string_append(cur_name_prefix
, comp_cls_name
);
3768 free(comp_cls_name
);
3771 comp_cls_name
= NULL
;
3774 if (cur_name_prefix
->len
== 0) {
3775 printf_err("No current component of which to set parameters:\n %s\n",
3780 if (bt_value_array_append_string(run_args
,
3786 if (bt_value_array_append_string(run_args
, arg
)) {
3792 if (cur_name_prefix
->len
== 0) {
3793 printf_err("No current component of which to set `path` parameter:\n %s\n",
3798 if (bt_value_array_append_string(run_args
, "--key")) {
3803 if (bt_value_array_append_string(run_args
, "path")) {
3808 if (bt_value_array_append_string(run_args
, "--value")) {
3813 if (bt_value_array_append_string(run_args
, arg
)) {
3819 if (cur_name_prefix
->len
== 0) {
3820 printf_err("No current component of which to set `url` parameter:\n %s\n",
3825 if (bt_value_array_append_string(run_args
, "--key")) {
3830 if (bt_value_array_append_string(run_args
, "url")) {
3835 if (bt_value_array_append_string(run_args
, "--value")) {
3840 if (bt_value_array_append_string(run_args
, arg
)) {
3846 if (cur_name_prefix
->len
== 0) {
3847 printf_err("No current component to name:\n %s\n",
3852 if (bt_value_array_append_string(run_args
, "--name")) {
3857 if (bt_value_array_append_string(run_args
, arg
)) {
3862 g_string_assign(cur_name
, arg
);
3864 case OPT_OMIT_HOME_PLUGIN_PATH
:
3865 force_omit_home_plugin_path
= true;
3867 if (bt_value_array_append_string(run_args
,
3868 "--omit-home-plugin-path")) {
3873 case OPT_RETRY_DURATION
:
3874 if (bt_value_array_append_string(run_args
,
3875 "--retry-duration")) {
3880 if (bt_value_array_append_string(run_args
, arg
)) {
3885 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
3886 force_omit_system_plugin_path
= true;
3888 if (bt_value_array_append_string(run_args
,
3889 "--omit-system-plugin-path")) {
3894 case OPT_PLUGIN_PATH
:
3895 if (bt_config_append_plugin_paths_check_setuid_setgid(
3896 plugin_paths
, arg
)) {
3900 if (bt_value_array_append_string(run_args
,
3906 if (bt_value_array_append_string(run_args
, arg
)) {
3912 print_convert_usage(stdout
);
3917 case OPT_CLOCK_CYCLES
:
3918 case OPT_CLOCK_DATE
:
3919 case OPT_CLOCK_FORCE_CORRELATE
:
3921 case OPT_CLOCK_OFFSET
:
3922 case OPT_CLOCK_OFFSET_NS
:
3923 case OPT_CLOCK_SECONDS
:
3926 case OPT_DEBUG_INFO_DIR
:
3927 case OPT_DEBUG_INFO_FULL_PATH
:
3928 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3931 case OPT_INPUT_FORMAT
:
3933 case OPT_NO_DEBUG_INFO
:
3935 case OPT_OUTPUT_FORMAT
:
3938 case OPT_RUN_ARGS_0
:
3939 case OPT_STREAM_INTERSECTION
:
3942 /* Ignore in this pass */
3945 printf_err("Unknown command-line option specified (option code %d)\n",
3954 /* Append current component's name if needed */
3955 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3956 cur_name_prefix
, run_args
, all_names
, &source_names
,
3957 &filter_names
, &sink_names
);
3962 /* Check for option parsing error */
3964 printf_err("While parsing command-line options, at option %s: %s\n",
3965 poptBadOption(pc
, 0), poptStrerror(opt
));
3969 poptFreeContext(pc
);
3974 * Second pass: transform the convert-specific options and
3975 * arguments into implicit component instances for the run
3978 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3979 convert_long_options
, 0);
3981 printf_err("Cannot get popt context\n");
3985 poptReadDefaultConfig(pc
, 0);
3987 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3988 arg
= poptGetOptArg(pc
);
3992 if (trimmer_has_begin
) {
3993 printf("At --begin option: --begin or --timerange option already specified\n %s\n",
3998 trimmer_has_begin
= true;
3999 ret
= append_implicit_component_extra_arg(
4000 &implicit_trimmer_args
, "begin", arg
);
4001 implicit_trimmer_args
.exists
= true;
4007 if (trimmer_has_end
) {
4008 printf("At --end option: --end or --timerange option already specified\n %s\n",
4013 trimmer_has_end
= true;
4014 ret
= append_implicit_component_extra_arg(
4015 &implicit_trimmer_args
, "end", arg
);
4016 implicit_trimmer_args
.exists
= true;
4026 if (trimmer_has_begin
|| trimmer_has_end
) {
4027 printf("At --timerange option: --begin, --end, or --timerange option already specified\n %s\n",
4032 ret
= split_timerange(arg
, &begin
, &end
);
4034 printf_err("Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:\n %s\n",
4039 ret
= append_implicit_component_extra_arg(
4040 &implicit_trimmer_args
, "begin", begin
);
4041 ret
|= append_implicit_component_extra_arg(
4042 &implicit_trimmer_args
, "end", end
);
4043 implicit_trimmer_args
.exists
= true;
4051 case OPT_CLOCK_CYCLES
:
4052 append_implicit_component_param(
4053 &implicit_text_args
, "clock-cycles", "yes");
4054 implicit_text_args
.exists
= true;
4056 case OPT_CLOCK_DATE
:
4057 append_implicit_component_param(
4058 &implicit_text_args
, "clock-date", "yes");
4059 implicit_text_args
.exists
= true;
4061 case OPT_CLOCK_FORCE_CORRELATE
:
4062 append_implicit_component_param(
4063 &implicit_muxer_args
, "force-correlate", "yes");
4066 append_implicit_component_param(
4067 &implicit_text_args
, "clock-gmt", "yes");
4068 implicit_text_args
.exists
= true;
4070 case OPT_CLOCK_OFFSET
:
4071 ret
= append_implicit_component_extra_arg(
4072 &implicit_ctf_args
, "clock-offset-cycles", arg
);
4073 implicit_ctf_args
.exists
= true;
4078 case OPT_CLOCK_OFFSET_NS
:
4079 ret
= append_implicit_component_extra_arg(
4080 &implicit_ctf_args
, "clock-offset-ns", arg
);
4081 implicit_ctf_args
.exists
= true;
4086 case OPT_CLOCK_SECONDS
:
4087 append_implicit_component_param(
4088 &implicit_text_args
, "clock-seconds", "yes");
4089 implicit_text_args
.exists
= true;
4092 ret
= append_implicit_component_extra_arg(
4093 &implicit_text_args
, "color", arg
);
4094 implicit_text_args
.exists
= true;
4099 case OPT_NO_DEBUG_INFO
:
4100 implicit_debug_info_args
.exists
= false;
4102 case OPT_DEBUG_INFO_DIR
:
4103 ret
= append_implicit_component_extra_arg(
4104 &implicit_debug_info_args
, "dir", arg
);
4109 case OPT_DEBUG_INFO_FULL_PATH
:
4110 append_implicit_component_param(
4111 &implicit_debug_info_args
, "full-path", "yes");
4113 case OPT_DEBUG_INFO_TARGET_PREFIX
:
4114 ret
= append_implicit_component_extra_arg(
4115 &implicit_debug_info_args
,
4116 "target-prefix", arg
);
4123 struct bt_value
*fields
= fields_from_arg(arg
);
4129 ret
= insert_flat_params_from_array(
4130 implicit_text_args
.params_arg
,
4140 struct bt_value
*names
= names_from_arg(arg
);
4146 ret
= insert_flat_params_from_array(
4147 implicit_text_args
.params_arg
,
4156 append_implicit_component_param(
4157 &implicit_text_args
, "no-delta", "yes");
4158 implicit_text_args
.exists
= true;
4160 case OPT_INPUT_FORMAT
:
4161 if (got_input_format_opt
) {
4162 printf_err("Duplicate --input-format option\n");
4166 got_input_format_opt
= true;
4168 if (strcmp(arg
, "ctf") == 0) {
4169 implicit_ctf_args
.exists
= true;
4170 } else if (strcmp(arg
, "lttng-live") == 0) {
4171 implicit_lttng_live_args
.exists
= true;
4173 printf_err("Unknown legacy input format:\n %s\n",
4178 case OPT_OUTPUT_FORMAT
:
4179 if (got_output_format_opt
) {
4180 printf_err("Duplicate --output-format option\n");
4184 got_output_format_opt
= true;
4186 if (strcmp(arg
, "text") == 0) {
4187 implicit_text_args
.exists
= true;
4188 } else if (strcmp(arg
, "dummy") == 0) {
4189 implicit_dummy_args
.exists
= true;
4190 } else if (strcmp(arg
, "ctf-metadata") == 0) {
4191 print_ctf_metadata
= true;
4193 printf_err("Unknown legacy output format:\n %s\n",
4199 ret
= append_implicit_component_extra_arg(
4200 &implicit_text_args
, "path", arg
);
4201 implicit_text_args
.exists
= true;
4207 if (print_run_args_0
) {
4208 printf_err("Cannot specify --run-args and --run-args-0\n");
4212 print_run_args
= true;
4214 case OPT_RUN_ARGS_0
:
4215 if (print_run_args
) {
4216 printf_err("Cannot specify --run-args and --run-args-0\n");
4220 print_run_args_0
= true;
4222 case OPT_STREAM_INTERSECTION
:
4223 append_implicit_component_param(&implicit_ctf_args
,
4224 "stream-intersection", "yes");
4225 implicit_ctf_args
.exists
= true;
4228 if (got_verbose_opt
) {
4229 printf_err("Duplicate -v/--verbose option\n");
4233 append_implicit_component_param(&implicit_text_args
,
4235 implicit_text_args
.exists
= true;
4236 got_verbose_opt
= true;
4239 got_debug_opt
= true;
4247 /* Check for option parsing error */
4249 printf_err("While parsing command-line options, at option %s: %s\n",
4250 poptBadOption(pc
, 0), poptStrerror(opt
));
4255 * Append home and system plugin paths now that we possibly got
4258 if (append_home_and_system_plugin_paths(plugin_paths
,
4259 force_omit_system_plugin_path
,
4260 force_omit_home_plugin_path
)) {
4264 /* Consume leftover argument */
4265 leftover
= poptGetArg(pc
);
4267 if (poptPeekArg(pc
)) {
4268 printf_err("Unexpected argument:\n %s\n",
4273 /* Print CTF metadata or print LTTng live sessions */
4274 if (print_ctf_metadata
) {
4276 printf_err("--output-format=ctf-metadata specified without a path\n");
4280 cfg
= bt_config_print_ctf_metadata_create(plugin_paths
);
4285 cfg
->debug
= got_debug_opt
;
4286 cfg
->verbose
= got_verbose_opt
;
4287 g_string_assign(cfg
->cmd_data
.print_ctf_metadata
.path
,
4293 * If -o dummy was not specified, and if there are no explicit
4294 * sink components, then use an implicit `text.text` sink.
4296 if (!implicit_dummy_args
.exists
&& !sink_names
) {
4297 implicit_text_args
.exists
= true;
4300 /* Decide where the leftover argument goes */
4302 if (implicit_lttng_live_args
.exists
) {
4303 lttng_live_url_parts
=
4304 bt_common_parse_lttng_live_url(leftover
,
4306 if (!lttng_live_url_parts
.proto
) {
4307 printf_err("Invalid LTTng live URL format: %s\n",
4312 if (!lttng_live_url_parts
.session_name
) {
4313 /* Print LTTng live sessions */
4314 cfg
= bt_config_print_lttng_live_sessions_create(
4320 cfg
->debug
= got_debug_opt
;
4321 cfg
->verbose
= got_verbose_opt
;
4322 g_string_assign(cfg
->cmd_data
.print_lttng_live_sessions
.url
,
4327 ret
= append_implicit_component_extra_arg(
4328 &implicit_lttng_live_args
, "url", leftover
);
4333 ret
= append_implicit_component_extra_arg(
4334 &implicit_ctf_args
, "path", leftover
);
4335 implicit_ctf_args
.exists
= true;
4343 * Ensure mutual exclusion between implicit `ctf.fs` and
4344 * `ctf.lttng-live` sources.
4346 if (implicit_ctf_args
.exists
&& implicit_lttng_live_args
.exists
) {
4347 printf_err("Cannot create both implicit `%s` and `%s` source components\n",
4348 implicit_ctf_args
.plugin_comp_cls_arg
->str
,
4349 implicit_lttng_live_args
.plugin_comp_cls_arg
->str
);
4354 * If the implicit `ctf.fs` or `ctf.lttng-live` source exists,
4355 * make sure there's a leftover (which is the path or URL).
4357 if (implicit_ctf_args
.exists
&& !leftover
) {
4358 printf_err("Missing path for implicit `%s` source component\n",
4359 implicit_ctf_args
.plugin_comp_cls_arg
->str
);
4363 if (implicit_lttng_live_args
.exists
&& !leftover
) {
4364 printf_err("Missing URL for implicit `%s` source component\n",
4365 implicit_lttng_live_args
.plugin_comp_cls_arg
->str
);
4369 /* Assign names to implicit components */
4370 ret
= assign_name_to_implicit_component(&implicit_ctf_args
,
4371 "ctf-fs", all_names
, &source_names
, true);
4376 ret
= assign_name_to_implicit_component(&implicit_lttng_live_args
,
4377 "lttng-live", all_names
, &source_names
, true);
4382 ret
= assign_name_to_implicit_component(&implicit_text_args
,
4383 "pretty", all_names
, &sink_names
, true);
4388 ret
= assign_name_to_implicit_component(&implicit_dummy_args
,
4389 "dummy", all_names
, &sink_names
, true);
4394 ret
= assign_name_to_implicit_component(&implicit_muxer_args
,
4395 "muxer", all_names
, NULL
, false);
4400 ret
= assign_name_to_implicit_component(&implicit_trimmer_args
,
4401 "trimmer", all_names
, NULL
, false);
4406 ret
= assign_name_to_implicit_component(&implicit_debug_info_args
,
4407 "debug-info", all_names
, NULL
, false);
4412 /* Make sure there's at least one source and one sink */
4413 if (!source_names
) {
4414 printf_err("No source component\n");
4419 printf_err("No sink component\n");
4424 * Prepend the muxer, the trimmer, and the debug info to the
4425 * filter chain so that we have:
4427 * sources -> muxer -> [trimmer] -> [debug info] ->
4428 * [user filters] -> sinks
4430 if (implicit_debug_info_args
.exists
) {
4431 if (g_list_prepend_gstring(&filter_names
,
4432 implicit_debug_info_args
.name_arg
->str
)) {
4437 if (implicit_trimmer_args
.exists
) {
4438 if (g_list_prepend_gstring(&filter_names
,
4439 implicit_trimmer_args
.name_arg
->str
)) {
4444 if (g_list_prepend_gstring(&filter_names
,
4445 implicit_muxer_args
.name_arg
->str
)) {
4450 * Append the equivalent run arguments for the implicit
4453 ret
= append_run_args_for_implicit_component(
4454 BT_COMPONENT_CLASS_TYPE_SOURCE
, &implicit_ctf_args
, run_args
);
4459 ret
= append_run_args_for_implicit_component(
4460 BT_COMPONENT_CLASS_TYPE_SOURCE
, &implicit_lttng_live_args
,
4466 ret
= append_run_args_for_implicit_component(
4467 BT_COMPONENT_CLASS_TYPE_SINK
, &implicit_text_args
, run_args
);
4472 ret
= append_run_args_for_implicit_component(
4473 BT_COMPONENT_CLASS_TYPE_SINK
, &implicit_dummy_args
, run_args
);
4478 ret
= append_run_args_for_implicit_component(
4479 BT_COMPONENT_CLASS_TYPE_FILTER
, &implicit_muxer_args
, run_args
);
4484 ret
= append_run_args_for_implicit_component(
4485 BT_COMPONENT_CLASS_TYPE_FILTER
, &implicit_trimmer_args
,
4491 ret
= append_run_args_for_implicit_component(
4492 BT_COMPONENT_CLASS_TYPE_FILTER
, &implicit_debug_info_args
,
4498 /* Auto-connect components */
4499 ret
= convert_auto_connect(run_args
, source_names
, filter_names
,
4502 printf_err("Cannot auto-connect components\n");
4507 * We have all the run command arguments now. Depending on
4508 * --run-args, we pass this to the run command or print them
4511 if (print_run_args
|| print_run_args_0
) {
4512 for (i
= 0; i
< bt_value_array_size(run_args
); i
++) {
4513 struct bt_value
*arg_value
=
4514 bt_value_array_get(run_args
, i
);
4516 GString
*quoted
= NULL
;
4517 const char *arg_to_print
;
4520 ret
= bt_value_string_get(arg_value
, &arg
);
4524 if (print_run_args
) {
4525 quoted
= bt_common_shell_quote(arg
, true);
4530 arg_to_print
= quoted
->str
;
4535 printf("%s", arg_to_print
);
4538 g_string_free(quoted
, TRUE
);
4541 if (i
< bt_value_array_size(run_args
) - 1) {
4542 if (print_run_args
) {
4555 cfg
= bt_config_run_from_args_array(run_args
, retcode
,
4556 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
4557 initial_plugin_paths
);
4566 poptFreeContext(pc
);
4572 g_string_free(cur_name
, TRUE
);
4575 if (cur_name_prefix
) {
4576 g_string_free(cur_name_prefix
, TRUE
);
4581 destroy_glist_of_gstring(source_names
);
4582 destroy_glist_of_gstring(filter_names
);
4583 destroy_glist_of_gstring(sink_names
);
4584 destroy_implicit_component_args(&implicit_ctf_args
);
4585 destroy_implicit_component_args(&implicit_lttng_live_args
);
4586 destroy_implicit_component_args(&implicit_dummy_args
);
4587 destroy_implicit_component_args(&implicit_text_args
);
4588 destroy_implicit_component_args(&implicit_debug_info_args
);
4589 destroy_implicit_component_args(&implicit_muxer_args
);
4590 destroy_implicit_component_args(&implicit_trimmer_args
);
4591 bt_put(plugin_paths
);
4592 bt_common_destroy_lttng_live_url_parts(<tng_live_url_parts
);
4597 * Prints the Babeltrace 2.x general usage.
4600 void print_gen_usage(FILE *fp
)
4602 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [COMMAND] [COMMAND ARGUMENTS]\n");
4604 fprintf(fp
, "General options:\n");
4606 fprintf(fp
, " -d, --debug Turn on debug mode\n");
4607 fprintf(fp
, " -h --help Show this help and quit\n");
4608 fprintf(fp
, " -v, --verbose Turn on verbose mode\n");
4609 fprintf(fp
, " -V, --version Show version and quit\n");
4611 fprintf(fp
, "Available commands:\n");
4613 fprintf(fp
, " convert Convert and trim traces (default)\n");
4614 fprintf(fp
, " help Get help for a plugin or a component class\n");
4615 fprintf(fp
, " list-plugins List available plugins and their content\n");
4616 fprintf(fp
, " query Query objects from a component class\n");
4617 fprintf(fp
, " run Build a processing graph and run it\n");
4619 fprintf(fp
, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
4622 struct bt_config
*bt_config_cli_args_create(int argc
, const char *argv
[],
4623 int *retcode
, bool force_omit_system_plugin_path
,
4624 bool force_omit_home_plugin_path
, bool force_no_debug_info
,
4625 struct bt_value
*initial_plugin_paths
)
4627 struct bt_config
*config
= NULL
;
4628 bool verbose
= false;
4631 const char **command_argv
= NULL
;
4632 int command_argc
= -1;
4633 const char *command_name
= NULL
;
4636 COMMAND_TYPE_NONE
= -1,
4637 COMMAND_TYPE_RUN
= 0,
4638 COMMAND_TYPE_CONVERT
,
4639 COMMAND_TYPE_LIST_PLUGINS
,
4642 } command_type
= COMMAND_TYPE_NONE
;
4646 if (!initial_plugin_paths
) {
4647 initial_plugin_paths
= bt_value_array_create();
4648 if (!initial_plugin_paths
) {
4653 bt_get(initial_plugin_paths
);
4657 print_gen_usage(stdout
);
4661 for (i
= 1; i
< argc
; i
++) {
4662 const char *cur_arg
= argv
[i
];
4664 if (strcmp(cur_arg
, "-d") == 0 ||
4665 strcmp(cur_arg
, "--debug") == 0) {
4667 } else if (strcmp(cur_arg
, "-v") == 0 ||
4668 strcmp(cur_arg
, "--verbose") == 0) {
4670 } else if (strcmp(cur_arg
, "-V") == 0 ||
4671 strcmp(cur_arg
, "--version") == 0) {
4674 } else if (strcmp(cur_arg
, "-h") == 0 ||
4675 strcmp(cur_arg
, "--help") == 0) {
4676 print_gen_usage(stdout
);
4679 bool has_command
= true;
4682 * First unknown argument: is it a known command
4685 if (strcmp(cur_arg
, "convert") == 0) {
4686 command_type
= COMMAND_TYPE_CONVERT
;
4687 } else if (strcmp(cur_arg
, "list-plugins") == 0) {
4688 command_type
= COMMAND_TYPE_LIST_PLUGINS
;
4689 } else if (strcmp(cur_arg
, "help") == 0) {
4690 command_type
= COMMAND_TYPE_HELP
;
4691 } else if (strcmp(cur_arg
, "query") == 0) {
4692 command_type
= COMMAND_TYPE_QUERY
;
4693 } else if (strcmp(cur_arg
, "run") == 0) {
4694 command_type
= COMMAND_TYPE_RUN
;
4697 * Unknown argument, but not a known
4698 * command name: assume the whole
4699 * arguments are for the default convert
4702 command_type
= COMMAND_TYPE_CONVERT
;
4703 command_argv
= argv
;
4704 command_argc
= argc
;
4705 has_command
= false;
4709 command_argv
= &argv
[i
];
4710 command_argc
= argc
- i
;
4711 command_name
= cur_arg
;
4717 if (command_type
== COMMAND_TYPE_NONE
) {
4719 * We only got non-help, non-version general options
4720 * like --verbose and --debug, without any other
4721 * arguments, so we can't do anything useful: print the
4724 print_gen_usage(stdout
);
4728 assert(command_argv
);
4729 assert(command_argc
>= 0);
4731 switch (command_type
) {
4732 case COMMAND_TYPE_RUN
:
4733 config
= bt_config_run_from_args(command_argc
, command_argv
,
4734 retcode
, force_omit_system_plugin_path
,
4735 force_omit_home_plugin_path
, initial_plugin_paths
);
4737 case COMMAND_TYPE_CONVERT
:
4738 config
= bt_config_convert_from_args(command_argc
, command_argv
,
4739 retcode
, force_omit_system_plugin_path
,
4740 force_omit_home_plugin_path
, force_no_debug_info
,
4741 initial_plugin_paths
);
4743 case COMMAND_TYPE_LIST_PLUGINS
:
4744 config
= bt_config_list_plugins_from_args(command_argc
,
4745 command_argv
, retcode
, force_omit_system_plugin_path
,
4746 force_omit_home_plugin_path
, initial_plugin_paths
);
4748 case COMMAND_TYPE_HELP
:
4749 config
= bt_config_help_from_args(command_argc
,
4750 command_argv
, retcode
, force_omit_system_plugin_path
,
4751 force_omit_home_plugin_path
, initial_plugin_paths
);
4753 case COMMAND_TYPE_QUERY
:
4754 config
= bt_config_query_from_args(command_argc
,
4755 command_argv
, retcode
, force_omit_system_plugin_path
,
4756 force_omit_home_plugin_path
, initial_plugin_paths
);
4764 config
->verbose
= true;
4768 config
->debug
= true;
4771 config
->command_name
= command_name
;
4775 bt_put(initial_plugin_paths
);