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"
43 #define BT_LOG_TAG "CLI-CFG-ARGS"
47 * Error printf() macro which prepends "Error: " the first time it's
48 * called. This gives a nicer feel than having a bunch of error prefixes
49 * (since the following lines usually describe the error and possible
50 * solutions), or the error prefix just at the end.
52 #define printf_err(fmt, args...) \
54 if (is_first_error) { \
55 fprintf(stderr, "Command line error: "); \
56 is_first_error = false; \
58 fprintf(stderr, fmt, ##args); \
61 static bool is_first_error
= true;
63 /* INI-style parsing FSM states */
64 enum ini_parsing_fsm_state
{
65 /* Expect a map key (identifier) */
68 /* Expect an equal character ('=') */
74 /* Expect a negative number value */
75 INI_EXPECT_VALUE_NUMBER_NEG
,
77 /* Expect a comma character (',') */
81 /* INI-style parsing state variables */
82 struct ini_parsing_state
{
83 /* Lexical scanner (owned by this) */
86 /* Output map value object being filled (owned by this) */
87 struct bt_value
*params
;
89 /* Next expected FSM state */
90 enum ini_parsing_fsm_state expecting
;
92 /* Last decoded map key (owned by this) */
95 /* Complete INI-style string to parse (not owned by this) */
98 /* Error buffer (not owned by this) */
102 /* Offset option with "is set" boolean */
108 /* Legacy "ctf"/"lttng-live" format options */
109 struct ctf_legacy_opts
{
110 struct offset_opt offset_s
;
111 struct offset_opt offset_ns
;
112 bool stream_intersection
;
115 /* Legacy "text" format options */
116 struct text_legacy_opts
{
118 * output, dbg_info_dir, dbg_info_target_prefix, names,
119 * and fields are owned by this.
122 GString
*dbg_info_dir
;
123 GString
*dbg_info_target_prefix
;
124 struct bt_value
*names
;
125 struct bt_value
*fields
;
133 bool dbg_info_full_path
;
137 /* Legacy input format format */
138 enum legacy_input_format
{
139 LEGACY_INPUT_FORMAT_NONE
= 0,
140 LEGACY_INPUT_FORMAT_CTF
,
141 LEGACY_INPUT_FORMAT_LTTNG_LIVE
,
144 /* Legacy output format format */
145 enum legacy_output_format
{
146 LEGACY_OUTPUT_FORMAT_NONE
= 0,
147 LEGACY_OUTPUT_FORMAT_TEXT
,
148 LEGACY_OUTPUT_FORMAT_DUMMY
,
152 * Prints the "out of memory" error.
155 void print_err_oom(void)
157 printf_err("Out of memory\n");
161 * Appends an "expecting token" error to the INI-style parsing state's
165 void ini_append_error_expecting(struct ini_parsing_state
*state
,
166 GScanner
*scanner
, const char *expecting
)
171 g_string_append_printf(state
->ini_error
, "Expecting %s:\n", expecting
);
173 /* Only print error if there's one line */
174 if (strchr(state
->arg
, '\n') != NULL
|| strlen(state
->arg
) == 0) {
178 g_string_append_printf(state
->ini_error
, "\n %s\n", state
->arg
);
179 pos
= g_scanner_cur_position(scanner
) + 4;
181 if (!g_scanner_eof(scanner
)) {
185 for (i
= 0; i
< pos
; ++i
) {
186 g_string_append_printf(state
->ini_error
, " ");
189 g_string_append_printf(state
->ini_error
, "^\n\n");
193 int ini_handle_state(struct ini_parsing_state
*state
)
196 GTokenType token_type
;
197 struct bt_value
*value
= NULL
;
199 token_type
= g_scanner_get_next_token(state
->scanner
);
200 if (token_type
== G_TOKEN_EOF
) {
201 if (state
->expecting
!= INI_EXPECT_COMMA
) {
202 switch (state
->expecting
) {
203 case INI_EXPECT_EQUAL
:
204 ini_append_error_expecting(state
,
205 state
->scanner
, "'='");
207 case INI_EXPECT_VALUE
:
208 case INI_EXPECT_VALUE_NUMBER_NEG
:
209 ini_append_error_expecting(state
,
210 state
->scanner
, "value");
212 case INI_EXPECT_MAP_KEY
:
213 ini_append_error_expecting(state
,
214 state
->scanner
, "unquoted map key");
227 switch (state
->expecting
) {
228 case INI_EXPECT_MAP_KEY
:
229 if (token_type
!= G_TOKEN_IDENTIFIER
) {
230 ini_append_error_expecting(state
, state
->scanner
,
235 free(state
->last_map_key
);
236 state
->last_map_key
=
237 strdup(state
->scanner
->value
.v_identifier
);
238 if (!state
->last_map_key
) {
239 g_string_append(state
->ini_error
,
244 if (bt_value_map_has_key(state
->params
, state
->last_map_key
)) {
245 g_string_append_printf(state
->ini_error
,
246 "Duplicate parameter key: `%s`\n",
247 state
->last_map_key
);
251 state
->expecting
= INI_EXPECT_EQUAL
;
253 case INI_EXPECT_EQUAL
:
254 if (token_type
!= G_TOKEN_CHAR
) {
255 ini_append_error_expecting(state
,
256 state
->scanner
, "'='");
260 if (state
->scanner
->value
.v_char
!= '=') {
261 ini_append_error_expecting(state
,
262 state
->scanner
, "'='");
266 state
->expecting
= INI_EXPECT_VALUE
;
268 case INI_EXPECT_VALUE
:
270 switch (token_type
) {
272 if (state
->scanner
->value
.v_char
== '-') {
273 /* Negative number */
275 INI_EXPECT_VALUE_NUMBER_NEG
;
278 ini_append_error_expecting(state
,
279 state
->scanner
, "value");
285 /* Positive integer */
286 uint64_t int_val
= state
->scanner
->value
.v_int64
;
288 if (int_val
> (1ULL << 63) - 1) {
289 g_string_append_printf(state
->ini_error
,
290 "Integer value %" PRIu64
" is outside the range of a 64-bit signed integer\n",
295 value
= bt_value_integer_create_init(
300 /* Positive floating point number */
301 value
= bt_value_float_create_init(
302 state
->scanner
->value
.v_float
);
306 value
= bt_value_string_create_init(
307 state
->scanner
->value
.v_string
);
309 case G_TOKEN_IDENTIFIER
:
312 * Using symbols would be appropriate here,
313 * but said symbols are allowed as map key,
314 * so it's easier to consider everything an
317 * If one of the known symbols is not
318 * recognized here, then fall back to creating
321 const char *id
= state
->scanner
->value
.v_identifier
;
323 if (!strcmp(id
, "null") || !strcmp(id
, "NULL") ||
324 !strcmp(id
, "nul")) {
325 value
= bt_value_null
;
326 } else if (!strcmp(id
, "true") || !strcmp(id
, "TRUE") ||
327 !strcmp(id
, "yes") ||
328 !strcmp(id
, "YES")) {
329 value
= bt_value_bool_create_init(true);
330 } else if (!strcmp(id
, "false") ||
331 !strcmp(id
, "FALSE") ||
334 value
= bt_value_bool_create_init(false);
336 value
= bt_value_string_create_init(id
);
341 /* Unset value variable will trigger the error */
346 ini_append_error_expecting(state
,
347 state
->scanner
, "value");
351 state
->expecting
= INI_EXPECT_COMMA
;
354 case INI_EXPECT_VALUE_NUMBER_NEG
:
356 switch (token_type
) {
359 /* Negative integer */
360 uint64_t int_val
= state
->scanner
->value
.v_int64
;
362 if (int_val
> (1ULL << 63) - 1) {
363 g_string_append_printf(state
->ini_error
,
364 "Integer value -%" PRIu64
" is outside the range of a 64-bit signed integer\n",
369 value
= bt_value_integer_create_init(
370 -((int64_t) int_val
));
374 /* Negative floating point number */
375 value
= bt_value_float_create_init(
376 -state
->scanner
->value
.v_float
);
379 /* Unset value variable will trigger the error */
384 ini_append_error_expecting(state
,
385 state
->scanner
, "value");
389 state
->expecting
= INI_EXPECT_COMMA
;
392 case INI_EXPECT_COMMA
:
393 if (token_type
!= G_TOKEN_CHAR
) {
394 ini_append_error_expecting(state
,
395 state
->scanner
, "','");
399 if (state
->scanner
->value
.v_char
!= ',') {
400 ini_append_error_expecting(state
,
401 state
->scanner
, "','");
405 state
->expecting
= INI_EXPECT_MAP_KEY
;
417 if (bt_value_map_insert(state
->params
,
418 state
->last_map_key
, value
)) {
419 /* Only override return value on error */
430 * Converts an INI-style argument to an equivalent map value object.
432 * Return value is owned by the caller.
435 struct bt_value
*bt_value_from_ini(const char *arg
, GString
*ini_error
)
437 /* Lexical scanner configuration */
438 GScannerConfig scanner_config
= {
439 /* Skip whitespaces */
440 .cset_skip_characters
= " \t\n",
442 /* Identifier syntax is: [a-zA-Z_][a-zA-Z0-9_.:-]* */
443 .cset_identifier_first
=
447 .cset_identifier_nth
=
452 /* "hello" and "Hello" two different keys */
453 .case_sensitive
= TRUE
,
456 .cpair_comment_single
= NULL
,
457 .skip_comment_multi
= TRUE
,
458 .skip_comment_single
= TRUE
,
459 .scan_comment_multi
= FALSE
,
462 * Do scan identifiers, including 1-char identifiers,
463 * but NULL is a normal identifier.
465 .scan_identifier
= TRUE
,
466 .scan_identifier_1char
= TRUE
,
467 .scan_identifier_NULL
= FALSE
,
470 * No specific symbols: null and boolean "symbols" are
471 * scanned as plain identifiers.
473 .scan_symbols
= FALSE
,
474 .symbol_2_token
= FALSE
,
475 .scope_0_fallback
= FALSE
,
478 * Scan "0b"-, "0"-, and "0x"-prefixed integers, but not
479 * integers prefixed with "$".
485 .scan_hex_dollar
= FALSE
,
487 /* Convert scanned numbers to integer tokens */
488 .numbers_2_int
= TRUE
,
490 /* Support both integers and floating-point numbers */
491 .int_2_float
= FALSE
,
493 /* Scan integers as 64-bit signed integers */
496 /* Only scan double-quoted strings */
497 .scan_string_sq
= FALSE
,
498 .scan_string_dq
= TRUE
,
500 /* Do not converter identifiers to string tokens */
501 .identifier_2_string
= FALSE
,
503 /* Scan characters as G_TOKEN_CHAR token */
504 .char_2_token
= FALSE
,
506 struct ini_parsing_state state
= {
509 .expecting
= INI_EXPECT_MAP_KEY
,
511 .ini_error
= ini_error
,
514 state
.params
= bt_value_map_create();
519 state
.scanner
= g_scanner_new(&scanner_config
);
520 if (!state
.scanner
) {
524 /* Let the scan begin */
525 g_scanner_input_text(state
.scanner
, arg
, strlen(arg
));
528 int ret
= ini_handle_state(&state
);
533 } else if (ret
> 0) {
542 BT_PUT(state
.params
);
546 g_scanner_destroy(state
.scanner
);
549 free(state
.last_map_key
);
554 * Returns the parameters map value object from a command-line
555 * parameter option's argument.
557 * Return value is owned by the caller.
560 struct bt_value
*bt_value_from_arg(const char *arg
)
562 struct bt_value
*params
= NULL
;
563 GString
*ini_error
= NULL
;
565 ini_error
= g_string_new(NULL
);
571 /* Try INI-style parsing */
572 params
= bt_value_from_ini(arg
, ini_error
);
574 printf_err("%s", ini_error
->str
);
580 g_string_free(ini_error
, TRUE
);
586 * Returns the plugin and component class names, and the instance name,
587 * from a command-line source/filter/sink option's argument. arg must
588 * have the following format:
592 * where NAME is the optional component name, PLUGIN is the plugin name,
593 * and CLS is the component class name.
595 * On success, both *plugin and *component are not NULL. *plugin
596 * and *component are owned by the caller. On success, *name can be NULL
597 * if no component name was found.
600 void plugin_comp_cls_names(const char *arg
, char **name
, char **plugin
,
603 const char *at
= arg
;
604 GString
*gs_name
= NULL
;
605 GString
*gs_plugin
= NULL
;
606 GString
*gs_comp_cls
= NULL
;
613 if (!bt_common_string_is_printable(arg
)) {
614 printf_err("Argument contains a non-printable character\n");
618 /* Parse the component name */
619 gs_name
= bt_common_string_until(at
, ".:\\", ":", &end_pos
);
624 if (arg
[end_pos
] == ':') {
628 g_string_assign(gs_name
, "");
631 /* Parse the plugin name */
632 gs_plugin
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
633 if (!gs_plugin
|| gs_plugin
->len
== 0 || at
[end_pos
] == '\0') {
639 /* Parse the component class name */
640 gs_comp_cls
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
641 if (!gs_comp_cls
|| gs_comp_cls
->len
== 0) {
645 if (at
[end_pos
] != '\0') {
646 /* Found a non-escaped `.` */
651 if (gs_name
->len
== 0) {
653 g_string_free(gs_name
, TRUE
);
655 *name
= gs_name
->str
;
656 g_string_free(gs_name
, FALSE
);
659 g_string_free(gs_name
, TRUE
);
662 *plugin
= gs_plugin
->str
;
663 *comp_cls
= gs_comp_cls
->str
;
664 g_string_free(gs_plugin
, FALSE
);
665 g_string_free(gs_comp_cls
, FALSE
);
673 g_string_free(gs_name
, TRUE
);
677 g_string_free(gs_plugin
, TRUE
);
681 g_string_free(gs_comp_cls
, TRUE
);
696 * Prints the Babeltrace version.
699 void print_version(void)
701 puts("Babeltrace " VERSION
);
705 * Destroys a component configuration.
708 void bt_config_component_destroy(struct bt_object
*obj
)
710 struct bt_config_component
*bt_config_component
=
711 container_of(obj
, struct bt_config_component
, base
);
717 if (bt_config_component
->plugin_name
) {
718 g_string_free(bt_config_component
->plugin_name
, TRUE
);
721 if (bt_config_component
->comp_cls_name
) {
722 g_string_free(bt_config_component
->comp_cls_name
, TRUE
);
725 if (bt_config_component
->instance_name
) {
726 g_string_free(bt_config_component
->instance_name
, TRUE
);
729 BT_PUT(bt_config_component
->params
);
730 g_free(bt_config_component
);
737 * Creates a component configuration using the given plugin name and
738 * component name. `plugin_name` and `comp_cls_name` are copied (belong
739 * to the return value).
741 * Return value is owned by the caller.
744 struct bt_config_component
*bt_config_component_create(
745 enum bt_component_class_type type
,
746 const char *plugin_name
, const char *comp_cls_name
)
748 struct bt_config_component
*cfg_component
= NULL
;
750 cfg_component
= g_new0(struct bt_config_component
, 1);
751 if (!cfg_component
) {
756 bt_object_init(cfg_component
, bt_config_component_destroy
);
757 cfg_component
->type
= type
;
758 cfg_component
->plugin_name
= g_string_new(plugin_name
);
759 if (!cfg_component
->plugin_name
) {
764 cfg_component
->comp_cls_name
= g_string_new(comp_cls_name
);
765 if (!cfg_component
->comp_cls_name
) {
770 cfg_component
->instance_name
= g_string_new(NULL
);
771 if (!cfg_component
->instance_name
) {
776 /* Start with empty parameters */
777 cfg_component
->params
= bt_value_map_create();
778 if (!cfg_component
->params
) {
786 BT_PUT(cfg_component
);
789 return cfg_component
;
793 * Creates a component configuration from a command-line source/sink
797 struct bt_config_component
*bt_config_component_from_arg(
798 enum bt_component_class_type type
, const char *arg
)
800 struct bt_config_component
*cfg_comp
= NULL
;
802 char *plugin_name
= NULL
;
803 char *comp_cls_name
= NULL
;
805 plugin_comp_cls_names(arg
, &name
, &plugin_name
, &comp_cls_name
);
806 if (!plugin_name
|| !comp_cls_name
) {
807 printf_err("Cannot get plugin or component class name\n");
811 cfg_comp
= bt_config_component_create(type
, plugin_name
, comp_cls_name
);
817 g_string_assign(cfg_comp
->instance_name
, name
);
828 g_free(comp_cls_name
);
833 * Destroys a configuration.
836 void bt_config_destroy(struct bt_object
*obj
)
838 struct bt_config
*cfg
=
839 container_of(obj
, struct bt_config
, base
);
845 BT_PUT(cfg
->plugin_paths
);
847 switch (cfg
->command
) {
848 case BT_CONFIG_COMMAND_RUN
:
849 if (cfg
->cmd_data
.run
.sources
) {
850 g_ptr_array_free(cfg
->cmd_data
.run
.sources
, TRUE
);
853 if (cfg
->cmd_data
.run
.filters
) {
854 g_ptr_array_free(cfg
->cmd_data
.run
.filters
, TRUE
);
857 if (cfg
->cmd_data
.run
.sinks
) {
858 g_ptr_array_free(cfg
->cmd_data
.run
.sinks
, TRUE
);
861 if (cfg
->cmd_data
.run
.connections
) {
862 g_ptr_array_free(cfg
->cmd_data
.run
.connections
,
866 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
868 case BT_CONFIG_COMMAND_HELP
:
869 BT_PUT(cfg
->cmd_data
.help
.cfg_component
);
871 case BT_CONFIG_COMMAND_QUERY
:
872 BT_PUT(cfg
->cmd_data
.query
.cfg_component
);
874 if (cfg
->cmd_data
.query
.object
) {
875 g_string_free(cfg
->cmd_data
.query
.object
, TRUE
);
878 case BT_CONFIG_COMMAND_PRINT_CTF_METADATA
:
879 if (cfg
->cmd_data
.print_ctf_metadata
.path
) {
880 g_string_free(cfg
->cmd_data
.print_ctf_metadata
.path
,
884 case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
:
885 if (cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
887 cfg
->cmd_data
.print_lttng_live_sessions
.url
,
902 void destroy_glist_of_gstring(GList
*list
)
910 for (at
= list
; at
!= NULL
; at
= g_list_next(at
)) {
911 g_string_free(at
->data
, TRUE
);
918 * Creates a simple lexical scanner for parsing comma-delimited names
921 * Return value is owned by the caller.
924 GScanner
*create_csv_identifiers_scanner(void)
927 GScannerConfig scanner_config
= {
928 .cset_skip_characters
= " \t\n",
929 .cset_identifier_first
= G_CSET_a_2_z G_CSET_A_2_Z
"_",
930 .cset_identifier_nth
= G_CSET_a_2_z G_CSET_A_2_Z
":_-",
931 .case_sensitive
= TRUE
,
932 .cpair_comment_single
= NULL
,
933 .skip_comment_multi
= TRUE
,
934 .skip_comment_single
= TRUE
,
935 .scan_comment_multi
= FALSE
,
936 .scan_identifier
= TRUE
,
937 .scan_identifier_1char
= TRUE
,
938 .scan_identifier_NULL
= FALSE
,
939 .scan_symbols
= FALSE
,
940 .symbol_2_token
= FALSE
,
941 .scope_0_fallback
= FALSE
,
942 .scan_binary
= FALSE
,
946 .scan_hex_dollar
= FALSE
,
947 .numbers_2_int
= FALSE
,
948 .int_2_float
= FALSE
,
949 .store_int64
= FALSE
,
950 .scan_string_sq
= FALSE
,
951 .scan_string_dq
= FALSE
,
952 .identifier_2_string
= FALSE
,
953 .char_2_token
= TRUE
,
956 scanner
= g_scanner_new(&scanner_config
);
965 * Converts a comma-delimited list of known names (--names option) to
966 * an array value object containing those names as string value objects.
968 * Return value is owned by the caller.
971 struct bt_value
*names_from_arg(const char *arg
)
973 GScanner
*scanner
= NULL
;
974 struct bt_value
*names
= NULL
;
975 bool found_all
= false, found_none
= false, found_item
= false;
977 names
= bt_value_array_create();
983 scanner
= create_csv_identifiers_scanner();
988 g_scanner_input_text(scanner
, arg
, strlen(arg
));
991 GTokenType token_type
= g_scanner_get_next_token(scanner
);
993 switch (token_type
) {
994 case G_TOKEN_IDENTIFIER
:
996 const char *identifier
= scanner
->value
.v_identifier
;
998 if (!strcmp(identifier
, "payload") ||
999 !strcmp(identifier
, "args") ||
1000 !strcmp(identifier
, "arg")) {
1002 if (bt_value_array_append_string(names
,
1006 } else if (!strcmp(identifier
, "context") ||
1007 !strcmp(identifier
, "ctx")) {
1009 if (bt_value_array_append_string(names
,
1013 } else if (!strcmp(identifier
, "scope") ||
1014 !strcmp(identifier
, "header")) {
1016 if (bt_value_array_append_string(names
,
1020 } else if (!strcmp(identifier
, "all")) {
1022 if (bt_value_array_append_string(names
,
1026 } else if (!strcmp(identifier
, "none")) {
1028 if (bt_value_array_append_string(names
,
1033 printf_err("Unknown name: `%s`\n",
1049 if (found_none
&& found_all
) {
1050 printf_err("Only either `all` or `none` can be specified in the list given to the --names option, but not both.\n");
1054 * Legacy behavior is to clear the defaults (show none) when at
1055 * least one item is specified.
1057 if (found_item
&& !found_none
&& !found_all
) {
1058 if (bt_value_array_append_string(names
, "none")) {
1063 g_scanner_destroy(scanner
);
1070 g_scanner_destroy(scanner
);
1076 * Converts a comma-delimited list of known fields (--fields option) to
1077 * an array value object containing those fields as string
1080 * Return value is owned by the caller.
1083 struct bt_value
*fields_from_arg(const char *arg
)
1085 GScanner
*scanner
= NULL
;
1086 struct bt_value
*fields
;
1088 fields
= bt_value_array_create();
1094 scanner
= create_csv_identifiers_scanner();
1099 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1102 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1104 switch (token_type
) {
1105 case G_TOKEN_IDENTIFIER
:
1107 const char *identifier
= scanner
->value
.v_identifier
;
1109 if (!strcmp(identifier
, "trace") ||
1110 !strcmp(identifier
, "trace:hostname") ||
1111 !strcmp(identifier
, "trace:domain") ||
1112 !strcmp(identifier
, "trace:procname") ||
1113 !strcmp(identifier
, "trace:vpid") ||
1114 !strcmp(identifier
, "loglevel") ||
1115 !strcmp(identifier
, "emf") ||
1116 !strcmp(identifier
, "callsite") ||
1117 !strcmp(identifier
, "all")) {
1118 if (bt_value_array_append_string(fields
,
1123 printf_err("Unknown field: `%s`\n",
1145 g_scanner_destroy(scanner
);
1151 void append_param_arg(GString
*params_arg
, const char *key
, const char *value
)
1157 if (params_arg
->len
!= 0) {
1158 g_string_append_c(params_arg
, ',');
1161 g_string_append(params_arg
, key
);
1162 g_string_append_c(params_arg
, '=');
1163 g_string_append(params_arg
, value
);
1167 * Inserts the equivalent "prefix-NAME=yes" strings into params_arg
1168 * where the names are in names_array.
1171 int insert_flat_params_from_array(GString
*params_arg
,
1172 struct bt_value
*names_array
, const char *prefix
)
1176 GString
*tmpstr
= NULL
, *default_value
= NULL
;
1177 bool default_set
= false, non_default_set
= false;
1180 * names_array may be NULL if no CLI options were specified to
1181 * trigger its creation.
1187 tmpstr
= g_string_new(NULL
);
1194 default_value
= g_string_new(NULL
);
1195 if (!default_value
) {
1201 for (i
= 0; i
< bt_value_array_size(names_array
); i
++) {
1202 struct bt_value
*str_obj
= bt_value_array_get(names_array
, i
);
1204 bool is_default
= false;
1207 printf_err("Unexpected error\n");
1212 ret
= bt_value_string_get(str_obj
, &suffix
);
1215 printf_err("Unexpected error\n");
1219 g_string_assign(tmpstr
, prefix
);
1220 g_string_append(tmpstr
, "-");
1222 /* Special-case for "all" and "none". */
1223 if (!strcmp(suffix
, "all")) {
1225 g_string_assign(default_value
, "show");
1226 } else if (!strcmp(suffix
, "none")) {
1228 g_string_assign(default_value
, "hide");
1232 g_string_append(tmpstr
, "default");
1233 append_param_arg(params_arg
, tmpstr
->str
,
1234 default_value
->str
);
1236 non_default_set
= true;
1237 g_string_append(tmpstr
, suffix
);
1238 append_param_arg(params_arg
, tmpstr
->str
, "yes");
1242 /* Implicit field-default=hide if any non-default option is set. */
1243 if (non_default_set
&& !default_set
) {
1244 g_string_assign(tmpstr
, prefix
);
1245 g_string_append(tmpstr
, "-default");
1246 g_string_assign(default_value
, "hide");
1247 append_param_arg(params_arg
, tmpstr
->str
, default_value
->str
);
1251 if (default_value
) {
1252 g_string_free(default_value
, TRUE
);
1256 g_string_free(tmpstr
, TRUE
);
1269 OPT_CLOCK_FORCE_CORRELATE
,
1272 OPT_CLOCK_OFFSET_NS
,
1278 OPT_DEBUG_INFO_FULL_PATH
,
1279 OPT_DEBUG_INFO_TARGET_PREFIX
,
1291 OPT_OMIT_HOME_PLUGIN_PATH
,
1292 OPT_OMIT_SYSTEM_PLUGIN_PATH
,
1298 OPT_RESET_BASE_PARAMS
,
1304 OPT_STREAM_INTERSECTION
,
1311 enum bt_config_component_dest
{
1312 BT_CONFIG_COMPONENT_DEST_UNKNOWN
= -1,
1313 BT_CONFIG_COMPONENT_DEST_SOURCE
,
1314 BT_CONFIG_COMPONENT_DEST_FILTER
,
1315 BT_CONFIG_COMPONENT_DEST_SINK
,
1319 * Adds a configuration component to the appropriate configuration
1320 * array depending on the destination.
1323 void add_run_cfg_comp(struct bt_config
*cfg
,
1324 struct bt_config_component
*cfg_comp
,
1325 enum bt_config_component_dest dest
)
1330 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
1331 g_ptr_array_add(cfg
->cmd_data
.run
.sources
, cfg_comp
);
1333 case BT_CONFIG_COMPONENT_DEST_FILTER
:
1334 g_ptr_array_add(cfg
->cmd_data
.run
.filters
, cfg_comp
);
1336 case BT_CONFIG_COMPONENT_DEST_SINK
:
1337 g_ptr_array_add(cfg
->cmd_data
.run
.sinks
, cfg_comp
);
1345 int add_run_cfg_comp_check_name(struct bt_config
*cfg
,
1346 struct bt_config_component
*cfg_comp
,
1347 enum bt_config_component_dest dest
,
1348 struct bt_value
*instance_names
)
1352 if (cfg_comp
->instance_name
->len
== 0) {
1353 printf_err("Found an unnamed component\n");
1358 if (bt_value_map_has_key(instance_names
, cfg_comp
->instance_name
->str
)) {
1359 printf_err("Duplicate component instance name:\n %s\n",
1360 cfg_comp
->instance_name
->str
);
1365 if (bt_value_map_insert(instance_names
,
1366 cfg_comp
->instance_name
->str
, bt_value_null
)) {
1372 add_run_cfg_comp(cfg
, cfg_comp
, dest
);
1379 int append_env_var_plugin_paths(struct bt_value
*plugin_paths
)
1384 if (bt_common_is_setuid_setgid()) {
1385 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
1389 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
1394 ret
= bt_config_append_plugin_paths(plugin_paths
, envvar
);
1398 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
1405 int append_home_and_system_plugin_paths(struct bt_value
*plugin_paths
,
1406 bool omit_system_plugin_path
, bool omit_home_plugin_path
)
1410 if (!omit_home_plugin_path
) {
1411 if (bt_common_is_setuid_setgid()) {
1412 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
1414 char *home_plugin_dir
=
1415 bt_common_get_home_plugin_path();
1417 if (home_plugin_dir
) {
1418 ret
= bt_config_append_plugin_paths(
1419 plugin_paths
, home_plugin_dir
);
1420 free(home_plugin_dir
);
1423 printf_err("Invalid home plugin path\n");
1430 if (!omit_system_plugin_path
) {
1431 if (bt_config_append_plugin_paths(plugin_paths
,
1432 bt_common_get_system_plugin_path())) {
1433 printf_err("Invalid system plugin path\n");
1439 printf_err("Cannot append home and system plugin paths\n");
1444 int append_home_and_system_plugin_paths_cfg(struct bt_config
*cfg
)
1446 return append_home_and_system_plugin_paths(cfg
->plugin_paths
,
1447 cfg
->omit_system_plugin_path
, cfg
->omit_home_plugin_path
);
1451 struct bt_config
*bt_config_base_create(enum bt_config_command command
,
1452 struct bt_value
*initial_plugin_paths
, bool needs_plugins
)
1454 struct bt_config
*cfg
;
1457 cfg
= g_new0(struct bt_config
, 1);
1463 bt_object_init(cfg
, bt_config_destroy
);
1464 cfg
->command
= command
;
1465 cfg
->command_needs_plugins
= needs_plugins
;
1467 if (initial_plugin_paths
) {
1468 cfg
->plugin_paths
= bt_get(initial_plugin_paths
);
1470 cfg
->plugin_paths
= bt_value_array_create();
1471 if (!cfg
->plugin_paths
) {
1487 struct bt_config
*bt_config_run_create(
1488 struct bt_value
*initial_plugin_paths
)
1490 struct bt_config
*cfg
;
1493 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_RUN
,
1494 initial_plugin_paths
, true);
1499 cfg
->cmd_data
.run
.sources
= g_ptr_array_new_with_free_func(
1500 (GDestroyNotify
) bt_put
);
1501 if (!cfg
->cmd_data
.run
.sources
) {
1506 cfg
->cmd_data
.run
.filters
= g_ptr_array_new_with_free_func(
1507 (GDestroyNotify
) bt_put
);
1508 if (!cfg
->cmd_data
.run
.filters
) {
1513 cfg
->cmd_data
.run
.sinks
= g_ptr_array_new_with_free_func(
1514 (GDestroyNotify
) bt_put
);
1515 if (!cfg
->cmd_data
.run
.sinks
) {
1520 cfg
->cmd_data
.run
.connections
= g_ptr_array_new_with_free_func(
1521 (GDestroyNotify
) bt_config_connection_destroy
);
1522 if (!cfg
->cmd_data
.run
.connections
) {
1537 struct bt_config
*bt_config_list_plugins_create(
1538 struct bt_value
*initial_plugin_paths
)
1540 struct bt_config
*cfg
;
1543 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_LIST_PLUGINS
,
1544 initial_plugin_paths
, true);
1559 struct bt_config
*bt_config_help_create(
1560 struct bt_value
*initial_plugin_paths
)
1562 struct bt_config
*cfg
;
1565 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_HELP
,
1566 initial_plugin_paths
, true);
1571 cfg
->cmd_data
.help
.cfg_component
=
1572 bt_config_component_create(BT_COMPONENT_CLASS_TYPE_UNKNOWN
,
1574 if (!cfg
->cmd_data
.help
.cfg_component
) {
1588 struct bt_config
*bt_config_query_create(
1589 struct bt_value
*initial_plugin_paths
)
1591 struct bt_config
*cfg
;
1594 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_QUERY
,
1595 initial_plugin_paths
, true);
1600 cfg
->cmd_data
.query
.object
= g_string_new(NULL
);
1601 if (!cfg
->cmd_data
.query
.object
) {
1616 struct bt_config
*bt_config_print_ctf_metadata_create(
1617 struct bt_value
*initial_plugin_paths
)
1619 struct bt_config
*cfg
;
1622 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_CTF_METADATA
,
1623 initial_plugin_paths
, true);
1628 cfg
->cmd_data
.print_ctf_metadata
.path
= g_string_new(NULL
);
1629 if (!cfg
->cmd_data
.print_ctf_metadata
.path
) {
1644 struct bt_config
*bt_config_print_lttng_live_sessions_create(
1645 struct bt_value
*initial_plugin_paths
)
1647 struct bt_config
*cfg
;
1650 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
,
1651 initial_plugin_paths
, true);
1656 cfg
->cmd_data
.print_lttng_live_sessions
.url
= g_string_new(NULL
);
1657 if (!cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
1672 int bt_config_append_plugin_paths_check_setuid_setgid(
1673 struct bt_value
*plugin_paths
, const char *arg
)
1677 if (bt_common_is_setuid_setgid()) {
1678 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
1682 if (bt_config_append_plugin_paths(plugin_paths
, arg
)) {
1683 printf_err("Invalid --plugin-path option's argument:\n %s\n",
1694 * Prints the expected format for a --params option.
1697 void print_expected_params_format(FILE *fp
)
1699 fprintf(fp
, "Expected format of PARAMS\n");
1700 fprintf(fp
, "-------------------------\n");
1702 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
1704 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
1705 fprintf(fp
, "where PARAM is the parameter name (C identifier plus the [:.-] characters),\n");
1706 fprintf(fp
, "and VALUE can be one of:\n");
1708 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
1709 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
1710 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
1711 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
1712 fprintf(fp
, " (`0x` prefix) signed 64-bit integer.\n");
1713 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
1714 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
1715 fprintf(fp
, " the null and boolean value symbols above.\n");
1716 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
1718 fprintf(fp
, "You can put whitespaces allowed around individual `=` and `,` symbols.\n");
1720 fprintf(fp
, "Example:\n");
1722 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
1723 fprintf(fp
, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
1724 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
1726 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
1727 fprintf(fp
, "babeltrace from a shell.\n");
1732 * Prints the help command usage.
1735 void print_help_usage(FILE *fp
)
1737 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
1738 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --source=PLUGIN.CLS\n");
1739 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --filter=PLUGIN.CLS\n");
1740 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --sink=PLUGIN.CLS\n");
1742 fprintf(fp
, "Options:\n");
1744 fprintf(fp
, " -f, --filter=PLUGIN.CLS Get help for the filter component class\n");
1745 fprintf(fp
, " CLS found in the plugin PLUGIN\n");
1746 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1747 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1748 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1749 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1750 fprintf(fp
, " dynamic plugins can be loaded\n");
1751 fprintf(fp
, " -S, --sink=PLUGIN.CLS Get help for the sink component class\n");
1752 fprintf(fp
, " CLS found in the plugin PLUGIN\n");
1753 fprintf(fp
, " -s, --source=PLUGIN.CLS Get help for the source component class\n");
1754 fprintf(fp
, " CLS found in the plugin PLUGIN\n");
1755 fprintf(fp
, " -h --help Show this help and quit\n");
1757 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
1759 fprintf(fp
, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
1763 struct poptOption help_long_options
[] = {
1764 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1765 { "filter", 'f', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
1766 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1767 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1768 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1769 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1770 { "sink", 'S', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
1771 { "source", 's', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
1772 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1776 * Creates a Babeltrace config object from the arguments of a help
1779 * *retcode is set to the appropriate exit code to use.
1782 struct bt_config
*bt_config_help_from_args(int argc
, const char *argv
[],
1783 int *retcode
, bool force_omit_system_plugin_path
,
1784 bool force_omit_home_plugin_path
,
1785 struct bt_value
*initial_plugin_paths
)
1787 poptContext pc
= NULL
;
1791 struct bt_config
*cfg
= NULL
;
1792 const char *leftover
;
1793 char *plugin_name
= NULL
, *comp_cls_name
= NULL
;
1794 char *plug_comp_cls_names
= NULL
;
1797 cfg
= bt_config_help_create(initial_plugin_paths
);
1802 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
1803 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
1804 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
1810 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
1811 help_long_options
, 0);
1813 printf_err("Cannot get popt context\n");
1817 poptReadDefaultConfig(pc
, 0);
1819 while ((opt
= poptGetNextOpt(pc
)) > 0) {
1820 arg
= poptGetOptArg(pc
);
1823 case OPT_PLUGIN_PATH
:
1824 if (bt_config_append_plugin_paths_check_setuid_setgid(
1825 cfg
->plugin_paths
, arg
)) {
1829 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
1830 cfg
->omit_system_plugin_path
= true;
1832 case OPT_OMIT_HOME_PLUGIN_PATH
:
1833 cfg
->omit_home_plugin_path
= true;
1838 if (cfg
->cmd_data
.help
.cfg_component
->type
!=
1839 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
1840 printf_err("Cannot specify more than one plugin and component class:\n %s\n",
1847 cfg
->cmd_data
.help
.cfg_component
->type
=
1848 BT_COMPONENT_CLASS_TYPE_SOURCE
;
1851 cfg
->cmd_data
.help
.cfg_component
->type
=
1852 BT_COMPONENT_CLASS_TYPE_FILTER
;
1855 cfg
->cmd_data
.help
.cfg_component
->type
=
1856 BT_COMPONENT_CLASS_TYPE_SINK
;
1861 plug_comp_cls_names
= strdup(arg
);
1862 if (!plug_comp_cls_names
) {
1868 print_help_usage(stdout
);
1873 printf_err("Unknown command-line option specified (option code %d)\n",
1882 /* Check for option parsing error */
1884 printf_err("While parsing command-line options, at option %s: %s\n",
1885 poptBadOption(pc
, 0), poptStrerror(opt
));
1889 leftover
= poptGetArg(pc
);
1891 if (cfg
->cmd_data
.help
.cfg_component
->type
!=
1892 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
1893 printf_err("Cannot specify plugin name and --source/--filter/--sink component class:\n %s\n",
1898 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1901 if (cfg
->cmd_data
.help
.cfg_component
->type
==
1902 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
1903 print_help_usage(stdout
);
1909 plugin_comp_cls_names(plug_comp_cls_names
, NULL
,
1910 &plugin_name
, &comp_cls_name
);
1911 if (plugin_name
&& comp_cls_name
) {
1912 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1914 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
,
1917 printf_err("Invalid --source/--filter/--sink option's argument:\n %s\n",
1918 plug_comp_cls_names
);
1923 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
1934 free(plug_comp_cls_names
);
1935 g_free(plugin_name
);
1936 g_free(comp_cls_name
);
1939 poptFreeContext(pc
);
1947 * Prints the help command usage.
1950 void print_query_usage(FILE *fp
)
1952 fprintf(fp
, "Usage: babeltrace [GEN OPTS] query [OPTS] OBJECT --source=PLUGIN.CLS\n");
1953 fprintf(fp
, " babeltrace [GEN OPTS] query [OPTS] OBJECT --filter=PLUGIN.CLS\n");
1954 fprintf(fp
, " babeltrace [GEN OPTS] query [OPTS] OBJECT --sink=PLUGIN.CLS\n");
1956 fprintf(fp
, "Options:\n");
1958 fprintf(fp
, " -f. --filter=PLUGIN.CLS Query object from the filter component\n");
1959 fprintf(fp
, " class CLS found in the plugin PLUGIN\n");
1960 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1961 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1962 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1963 fprintf(fp
, " -p, --params=PARAMS Set the query parameters to PARAMS\n");
1964 fprintf(fp
, " (see the expected format of PARAMS below)\n");
1965 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1966 fprintf(fp
, " dynamic plugins can be loaded\n");
1967 fprintf(fp
, " -S, --sink=PLUGIN.CLS Query object from the sink component class\n");
1968 fprintf(fp
, " CLS found in the plugin PLUGIN\n");
1969 fprintf(fp
, " -s, --source=PLUGIN.CLS Query object from the source component\n");
1970 fprintf(fp
, " class CLS found in the plugin PLUGIN\n");
1971 fprintf(fp
, " -h --help Show this help and quit\n");
1972 fprintf(fp
, "\n\n");
1973 print_expected_params_format(fp
);
1977 struct poptOption query_long_options
[] = {
1978 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1979 { "filter", 'f', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
1980 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1981 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1982 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1983 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
1984 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1985 { "sink", 'S', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
1986 { "source", 's', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
1987 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1991 * Creates a Babeltrace config object from the arguments of a query
1994 * *retcode is set to the appropriate exit code to use.
1997 struct bt_config
*bt_config_query_from_args(int argc
, const char *argv
[],
1998 int *retcode
, bool force_omit_system_plugin_path
,
1999 bool force_omit_home_plugin_path
,
2000 struct bt_value
*initial_plugin_paths
)
2002 poptContext pc
= NULL
;
2006 struct bt_config
*cfg
= NULL
;
2007 const char *leftover
;
2008 struct bt_value
*params
= bt_value_null
;
2011 cfg
= bt_config_query_create(initial_plugin_paths
);
2016 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2017 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2018 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2024 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2025 query_long_options
, 0);
2027 printf_err("Cannot get popt context\n");
2031 poptReadDefaultConfig(pc
, 0);
2033 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2034 arg
= poptGetOptArg(pc
);
2037 case OPT_PLUGIN_PATH
:
2038 if (bt_config_append_plugin_paths_check_setuid_setgid(
2039 cfg
->plugin_paths
, arg
)) {
2043 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2044 cfg
->omit_system_plugin_path
= true;
2046 case OPT_OMIT_HOME_PLUGIN_PATH
:
2047 cfg
->omit_home_plugin_path
= true;
2053 enum bt_component_class_type type
;
2055 if (cfg
->cmd_data
.query
.cfg_component
) {
2056 printf_err("Cannot specify more than one plugin and component class:\n %s\n",
2063 type
= BT_COMPONENT_CLASS_TYPE_SOURCE
;
2066 type
= BT_COMPONENT_CLASS_TYPE_FILTER
;
2069 type
= BT_COMPONENT_CLASS_TYPE_SINK
;
2075 cfg
->cmd_data
.query
.cfg_component
=
2076 bt_config_component_from_arg(type
, arg
);
2077 if (!cfg
->cmd_data
.query
.cfg_component
) {
2078 printf_err("Invalid format for --source/--filter/--sink option's argument:\n %s\n",
2083 /* Default parameters: null */
2084 bt_put(cfg
->cmd_data
.query
.cfg_component
->params
);
2085 cfg
->cmd_data
.query
.cfg_component
->params
=
2091 params
= bt_value_from_arg(arg
);
2093 printf_err("Invalid format for --params option's argument:\n %s\n",
2100 print_query_usage(stdout
);
2105 printf_err("Unknown command-line option specified (option code %d)\n",
2114 if (!cfg
->cmd_data
.query
.cfg_component
) {
2115 printf_err("No target component class specified with --source/--filter/--sink option\n");
2120 BT_MOVE(cfg
->cmd_data
.query
.cfg_component
->params
, params
);
2122 /* Check for option parsing error */
2124 printf_err("While parsing command-line options, at option %s: %s\n",
2125 poptBadOption(pc
, 0), poptStrerror(opt
));
2130 * We need exactly one leftover argument which is the
2133 leftover
= poptGetArg(pc
);
2135 if (strlen(leftover
) == 0) {
2136 printf_err("Invalid empty object\n");
2140 g_string_assign(cfg
->cmd_data
.query
.object
, leftover
);
2142 print_query_usage(stdout
);
2148 leftover
= poptGetArg(pc
);
2150 printf_err("Unexpected argument: %s\n", leftover
);
2154 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2166 poptFreeContext(pc
);
2175 * Prints the list-plugins command usage.
2178 void print_list_plugins_usage(FILE *fp
)
2180 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
2182 fprintf(fp
, "Options:\n");
2184 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2185 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2186 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2187 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2188 fprintf(fp
, " dynamic plugins can be loaded\n");
2189 fprintf(fp
, " -h --help Show this help and quit\n");
2191 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2193 fprintf(fp
, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
2197 struct poptOption list_plugins_long_options
[] = {
2198 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2199 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2200 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2201 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2202 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2203 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2207 * Creates a Babeltrace config object from the arguments of a
2208 * list-plugins command.
2210 * *retcode is set to the appropriate exit code to use.
2213 struct bt_config
*bt_config_list_plugins_from_args(int argc
, const char *argv
[],
2214 int *retcode
, bool force_omit_system_plugin_path
,
2215 bool force_omit_home_plugin_path
,
2216 struct bt_value
*initial_plugin_paths
)
2218 poptContext pc
= NULL
;
2222 struct bt_config
*cfg
= NULL
;
2223 const char *leftover
;
2226 cfg
= bt_config_list_plugins_create(initial_plugin_paths
);
2231 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2232 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2233 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2239 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2240 list_plugins_long_options
, 0);
2242 printf_err("Cannot get popt context\n");
2246 poptReadDefaultConfig(pc
, 0);
2248 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2249 arg
= poptGetOptArg(pc
);
2252 case OPT_PLUGIN_PATH
:
2253 if (bt_config_append_plugin_paths_check_setuid_setgid(
2254 cfg
->plugin_paths
, arg
)) {
2258 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2259 cfg
->omit_system_plugin_path
= true;
2261 case OPT_OMIT_HOME_PLUGIN_PATH
:
2262 cfg
->omit_home_plugin_path
= true;
2265 print_list_plugins_usage(stdout
);
2270 printf_err("Unknown command-line option specified (option code %d)\n",
2279 /* Check for option parsing error */
2281 printf_err("While parsing command-line options, at option %s: %s\n",
2282 poptBadOption(pc
, 0), poptStrerror(opt
));
2286 leftover
= poptGetArg(pc
);
2288 printf_err("Unexpected argument: %s\n", leftover
);
2292 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2304 poptFreeContext(pc
);
2312 * Prints the run command usage.
2315 void print_run_usage(FILE *fp
)
2317 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] run [OPTIONS]\n");
2319 fprintf(fp
, "Options:\n");
2321 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
2322 fprintf(fp
, " for all the following components until\n");
2323 fprintf(fp
, " --reset-base-params is encountered\n");
2324 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2325 fprintf(fp
, " -c, --connect=CONNECTION Connect two created components (see the\n");
2326 fprintf(fp
, " expected format of CONNECTION below)\n");
2327 fprintf(fp
, " -f, --filter=[NAME:]PLUGIN.CLS Instantiate a filter component from plugin\n");
2328 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2329 fprintf(fp
, " the current component, and if NAME is\n");
2330 fprintf(fp
, " given, set its instance name to NAME\n");
2331 fprintf(fp
, " --key=KEY Set the current initialization string\n");
2332 fprintf(fp
, " parameter key to KEY (see --value)\n");
2333 fprintf(fp
, " -n, --name=NAME Set the name of the current component\n");
2334 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2335 fprintf(fp
, " names of the created components)\n");
2336 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2337 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2338 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2339 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2340 fprintf(fp
, " current component (see the expected format\n");
2341 fprintf(fp
, " of PARAMS below)\n");
2342 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2343 fprintf(fp
, " dynamic plugins can be loaded\n");
2344 fprintf(fp
, " -r, --reset-base-params Reset the current base parameters to an\n");
2345 fprintf(fp
, " empty map\n");
2346 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2347 fprintf(fp
, " the graph later, retry in DUR µs\n");
2348 fprintf(fp
, " (default: 100000)\n");
2349 fprintf(fp
, " -S, --sink=[NAME:]PLUGIN.CLS Instantiate a sink 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
, " -s, --source=[NAME:]PLUGIN.CLS Instantiate a source component from plugin\n");
2354 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2355 fprintf(fp
, " the current component, and if NAME is\n");
2356 fprintf(fp
, " given, set its instance name to NAME\n");
2357 fprintf(fp
, " --value=VAL Add a string initialization parameter to\n");
2358 fprintf(fp
, " the current component with a name given by\n");
2359 fprintf(fp
, " the last argument of the --key option and a\n");
2360 fprintf(fp
, " value set to VAL\n");
2361 fprintf(fp
, " -h --help Show this help and quit\n");
2363 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2364 fprintf(fp
, "\n\n");
2365 fprintf(fp
, "Expected format of CONNECTION\n");
2366 fprintf(fp
, "-----------------------------\n");
2368 fprintf(fp
, " UPSTREAM[.UPSTREAM-PORT]:DOWNSTREAM[.DOWNSTREAM-PORT]\n");
2370 fprintf(fp
, "UPSTREAM and DOWNSTREAM are names of the upstream and downstream\n");
2371 fprintf(fp
, "components to connect together. You must escape the following characters\n\n");
2372 fprintf(fp
, "with `\\`: `\\`, `.`, and `:`. You can set the name of the current\n");
2373 fprintf(fp
, "component with the --name option.\n");
2375 fprintf(fp
, "UPSTREAM-PORT and DOWNSTREAM-PORT are optional globbing patterns to\n");
2376 fprintf(fp
, "identify the upstream and downstream ports to use for the connection.\n");
2377 fprintf(fp
, "When the port is not specified, `*` is used.\n");
2379 fprintf(fp
, "When a component named UPSTREAM has an available port which matches the\n");
2380 fprintf(fp
, "UPSTREAM-PORT globbing pattern, it is connected to the first port which\n");
2381 fprintf(fp
, "matches the DOWNSTREAM-PORT globbing pattern of the component named\n");
2382 fprintf(fp
, "DOWNSTREAM.\n");
2384 fprintf(fp
, "The only special character in UPSTREAM-PORT and DOWNSTREAM-PORT is `*`\n");
2385 fprintf(fp
, "which matches anything. You must escape the following characters\n");
2386 fprintf(fp
, "with `\\`: `\\`, `*`, `?`, `[`, `.`, and `:`.\n");
2388 fprintf(fp
, "You can connect a source component to a filter or sink component. You\n");
2389 fprintf(fp
, "can connect a filter component to a sink component.\n");
2391 fprintf(fp
, "Examples:\n");
2393 fprintf(fp
, " my-src:my-sink\n");
2394 fprintf(fp
, " ctf-fs.*stream*:utils-muxer:*\n");
2396 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
2397 fprintf(fp
, "babeltrace from a shell.\n");
2398 fprintf(fp
, "\n\n");
2399 print_expected_params_format(fp
);
2403 * Creates a Babeltrace config object from the arguments of a run
2406 * *retcode is set to the appropriate exit code to use.
2409 struct bt_config
*bt_config_run_from_args(int argc
, const char *argv
[],
2410 int *retcode
, bool force_omit_system_plugin_path
,
2411 bool force_omit_home_plugin_path
,
2412 struct bt_value
*initial_plugin_paths
)
2414 poptContext pc
= NULL
;
2416 struct bt_config_component
*cur_cfg_comp
= NULL
;
2417 enum bt_config_component_dest cur_cfg_comp_dest
=
2418 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
2419 struct bt_value
*cur_base_params
= NULL
;
2421 struct bt_config
*cfg
= NULL
;
2422 struct bt_value
*instance_names
= NULL
;
2423 struct bt_value
*connection_args
= NULL
;
2424 GString
*cur_param_key
= NULL
;
2425 char error_buf
[256] = { 0 };
2426 long long retry_duration
= -1;
2427 struct poptOption run_long_options
[] = {
2428 { "base-params", 'b', POPT_ARG_STRING
, NULL
, OPT_BASE_PARAMS
, NULL
, NULL
},
2429 { "connect", 'c', POPT_ARG_STRING
, NULL
, OPT_CONNECT
, NULL
, NULL
},
2430 { "filter", 'f', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
2431 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2432 { "key", '\0', POPT_ARG_STRING
, NULL
, OPT_KEY
, NULL
, NULL
},
2433 { "name", 'n', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2434 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2435 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2436 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2437 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2438 { "reset-base-params", 'r', POPT_ARG_NONE
, NULL
, OPT_RESET_BASE_PARAMS
, NULL
, NULL
},
2439 { "retry-duration", '\0', POPT_ARG_LONGLONG
, &retry_duration
, OPT_RETRY_DURATION
, NULL
, NULL
},
2440 { "sink", 'S', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
2441 { "source", 's', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
2442 { "value", '\0', POPT_ARG_STRING
, NULL
, OPT_VALUE
, NULL
, NULL
},
2443 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2447 cur_param_key
= g_string_new(NULL
);
2448 if (!cur_param_key
) {
2454 print_run_usage(stdout
);
2459 cfg
= bt_config_run_create(initial_plugin_paths
);
2464 cfg
->cmd_data
.run
.retry_duration_us
= 100000;
2465 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2466 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2467 cur_base_params
= bt_value_map_create();
2468 if (!cur_base_params
) {
2473 instance_names
= bt_value_map_create();
2474 if (!instance_names
) {
2479 connection_args
= bt_value_array_create();
2480 if (!connection_args
) {
2485 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2491 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2492 run_long_options
, 0);
2494 printf_err("Cannot get popt context\n");
2498 poptReadDefaultConfig(pc
, 0);
2500 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2501 arg
= poptGetOptArg(pc
);
2504 case OPT_PLUGIN_PATH
:
2505 if (bt_config_append_plugin_paths_check_setuid_setgid(
2506 cfg
->plugin_paths
, arg
)) {
2510 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2511 cfg
->omit_system_plugin_path
= true;
2513 case OPT_OMIT_HOME_PLUGIN_PATH
:
2514 cfg
->omit_home_plugin_path
= true;
2520 enum bt_component_class_type new_comp_type
;
2521 enum bt_config_component_dest new_dest
;
2522 const char *opt_name
;
2526 new_comp_type
= BT_COMPONENT_CLASS_TYPE_SOURCE
;
2527 new_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
2528 opt_name
= "--source";
2531 new_comp_type
= BT_COMPONENT_CLASS_TYPE_FILTER
;
2532 new_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
2533 opt_name
= "--filter";
2536 new_comp_type
= BT_COMPONENT_CLASS_TYPE_SINK
;
2537 new_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
2538 opt_name
= "--sink";
2545 ret
= add_run_cfg_comp_check_name(cfg
,
2546 cur_cfg_comp
, cur_cfg_comp_dest
,
2548 BT_PUT(cur_cfg_comp
);
2554 cur_cfg_comp
= bt_config_component_from_arg(
2555 new_comp_type
, arg
);
2556 if (!cur_cfg_comp
) {
2557 printf_err("Invalid format for %s option's argument:\n %s\n",
2562 assert(cur_base_params
);
2563 bt_put(cur_cfg_comp
->params
);
2564 cur_cfg_comp
->params
= bt_value_copy(cur_base_params
);
2565 if (!cur_cfg_comp
->params
) {
2570 cur_cfg_comp_dest
= new_dest
;
2575 struct bt_value
*params
;
2576 struct bt_value
*params_to_set
;
2578 if (!cur_cfg_comp
) {
2579 printf_err("Cannot add parameters to unavailable component:\n %s\n",
2584 params
= bt_value_from_arg(arg
);
2586 printf_err("Invalid format for --params option's argument:\n %s\n",
2591 params_to_set
= bt_value_map_extend(cur_cfg_comp
->params
,
2594 if (!params_to_set
) {
2595 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
2600 BT_MOVE(cur_cfg_comp
->params
, params_to_set
);
2604 if (strlen(arg
) == 0) {
2605 printf_err("Cannot set an empty string as the current parameter key\n");
2609 g_string_assign(cur_param_key
, arg
);
2612 if (!cur_cfg_comp
) {
2613 printf_err("Cannot set a parameter's value of unavailable component:\n %s\n",
2618 if (cur_param_key
->len
== 0) {
2619 printf_err("--value option specified without preceding --key option:\n %s\n",
2624 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
2625 cur_param_key
->str
, arg
)) {
2631 if (!cur_cfg_comp
) {
2632 printf_err("Cannot set the name of unavailable component:\n %s\n",
2637 g_string_assign(cur_cfg_comp
->instance_name
, arg
);
2639 case OPT_BASE_PARAMS
:
2641 struct bt_value
*params
= bt_value_from_arg(arg
);
2644 printf_err("Invalid format for --base-params option's argument:\n %s\n",
2649 BT_MOVE(cur_base_params
, params
);
2652 case OPT_RESET_BASE_PARAMS
:
2653 BT_PUT(cur_base_params
);
2654 cur_base_params
= bt_value_map_create();
2655 if (!cur_base_params
) {
2661 if (bt_value_array_append_string(connection_args
,
2667 case OPT_RETRY_DURATION
:
2668 if (retry_duration
< 0) {
2669 printf_err("--retry-duration option's argument must be positive or 0: %lld\n",
2674 cfg
->cmd_data
.run
.retry_duration_us
=
2675 (uint64_t) retry_duration
;
2678 print_run_usage(stdout
);
2683 printf_err("Unknown command-line option specified (option code %d)\n",
2692 /* Check for option parsing error */
2694 printf_err("While parsing command-line options, at option %s: %s\n",
2695 poptBadOption(pc
, 0), poptStrerror(opt
));
2699 /* This command does not accept leftover arguments */
2700 if (poptPeekArg(pc
)) {
2701 printf_err("Unexpected argument: %s\n", poptPeekArg(pc
));
2705 /* Add current component */
2707 ret
= add_run_cfg_comp_check_name(cfg
, cur_cfg_comp
,
2708 cur_cfg_comp_dest
, instance_names
);
2709 BT_PUT(cur_cfg_comp
);
2715 if (cfg
->cmd_data
.run
.sources
->len
== 0) {
2716 printf_err("Incomplete graph: no source component\n");
2720 if (cfg
->cmd_data
.run
.sinks
->len
== 0) {
2721 printf_err("Incomplete graph: no sink component\n");
2725 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2729 ret
= bt_config_cli_args_create_connections(cfg
, connection_args
,
2732 printf_err("Cannot creation connections:\n%s", error_buf
);
2744 poptFreeContext(pc
);
2747 if (cur_param_key
) {
2748 g_string_free(cur_param_key
, TRUE
);
2752 BT_PUT(cur_cfg_comp
);
2753 BT_PUT(cur_base_params
);
2754 BT_PUT(instance_names
);
2755 BT_PUT(connection_args
);
2760 struct bt_config
*bt_config_run_from_args_array(struct bt_value
*run_args
,
2761 int *retcode
, bool force_omit_system_plugin_path
,
2762 bool force_omit_home_plugin_path
,
2763 struct bt_value
*initial_plugin_paths
)
2765 struct bt_config
*cfg
= NULL
;
2768 const size_t argc
= bt_value_array_size(run_args
) + 1;
2770 argv
= calloc(argc
, sizeof(*argv
));
2778 for (i
= 0; i
< bt_value_array_size(run_args
); i
++) {
2780 struct bt_value
*arg_value
= bt_value_array_get(run_args
, i
);
2784 ret
= bt_value_string_get(arg_value
, &arg
);
2791 cfg
= bt_config_run_from_args(argc
, argv
, retcode
,
2792 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
2793 initial_plugin_paths
);
2801 * Prints the convert command usage.
2804 void print_convert_usage(FILE *fp
)
2806 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [convert] [OPTIONS] [PATH/URL]\n");
2808 fprintf(fp
, "Options:\n");
2810 fprintf(fp
, " --filter=[NAME:]PLUGIN.CLS Instantiate a filter component from plugin\n");
2811 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2812 fprintf(fp
, " the current component, and if NAME is\n");
2813 fprintf(fp
, " given, set its instance name to NAME\n");
2814 fprintf(fp
, " --name=NAME Set the name of the current component\n");
2815 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2816 fprintf(fp
, " names of the created components)\n");
2817 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2818 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2819 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2820 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2821 fprintf(fp
, " current component (see the expected format\n");
2822 fprintf(fp
, " of PARAMS below)\n");
2823 fprintf(fp
, " -P, --path=PATH Set the `path` string parameter of the\n");
2824 fprintf(fp
, " current component to PATH\n");
2825 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2826 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2827 fprintf(fp
, " the graph later, retry in DUR µs\n");
2828 fprintf(fp
, " (default: 100000)\n");
2829 fprintf(fp
, " dynamic plugins can be loaded\n");
2830 fprintf(fp
, " --run-args Print the equivalent arguments for the\n");
2831 fprintf(fp
, " `run` command to the standard output,\n");
2832 fprintf(fp
, " formatted for a shell, and quit\n");
2833 fprintf(fp
, " --run-args-0 Print the equivalent arguments for the\n");
2834 fprintf(fp
, " `run` command to the standard output,\n");
2835 fprintf(fp
, " formatted for `xargs -0`, and quit\n");
2836 fprintf(fp
, " --sink=[NAME:]PLUGIN.CLS Instantiate a sink component from plugin\n");
2837 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2838 fprintf(fp
, " the current component, and if NAME is\n");
2839 fprintf(fp
, " given, set its instance name to NAME\n");
2840 fprintf(fp
, " --source=[NAME:]PLUGIN.CLS Instantiate a source component from plugin\n");
2841 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2842 fprintf(fp
, " the current component, and if NAME is\n");
2843 fprintf(fp
, " given, set its instance name to NAME\n");
2844 fprintf(fp
, " -u, --url=URL Set the `url` string parameter of the\n");
2845 fprintf(fp
, " current component to URL\n");
2846 fprintf(fp
, " -h --help Show this help and quit\n");
2848 fprintf(fp
, "Implicit `ctf.fs` source component options:\n");
2850 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
2851 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS ns\n");
2852 fprintf(fp
, " --stream-intersection Only process events when all streams\n");
2853 fprintf(fp
, " are active\n");
2855 fprintf(fp
, "Implicit `text.text` sink component options:\n");
2857 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
2858 fprintf(fp
, " --clock-date Print timestamp dates\n");
2859 fprintf(fp
, " --clock-gmt Print and parse timestamps in the GMT\n");
2860 fprintf(fp
, " time zone instead of the local time zone\n");
2861 fprintf(fp
, " --clock-seconds Print the timestamps as `SEC.NS` instead\n");
2862 fprintf(fp
, " of `hh:mm:ss.nnnnnnnnn`\n");
2863 fprintf(fp
, " --color=(never | auto | always)\n");
2864 fprintf(fp
, " Never, automatically, or always emit\n");
2865 fprintf(fp
, " console color codes\n");
2866 fprintf(fp
, " -f, --fields=FIELD[,FIELD]... Print additional fields; FIELD can be:\n");
2867 fprintf(fp
, " `all`, `trace`, `trace:hostname`,\n");
2868 fprintf(fp
, " `trace:domain`, `trace:procname`,\n");
2869 fprintf(fp
, " `trace:vpid`, `loglevel`, `emf`\n");
2870 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names; NAME can be:\n");
2871 fprintf(fp
, " `payload` (or `arg` or `args`), `none`,\n");
2872 fprintf(fp
, " `all`, `scope`, `header`, `context`\n");
2873 fprintf(fp
, " (or `ctx`)\n");
2874 fprintf(fp
, " --no-delta Do not print time delta between\n");
2875 fprintf(fp
, " consecutive events\n");
2876 fprintf(fp
, " -w, --output=PATH Write output text to PATH instead of\n");
2877 fprintf(fp
, " the standard output\n");
2879 fprintf(fp
, "Implicit `utils.muxer` filter component options:\n");
2881 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently\n");
2882 fprintf(fp
, " correlated across traces\n");
2884 fprintf(fp
, "Implicit `utils.trimmer` filter component options:\n");
2886 fprintf(fp
, " -b, --begin=BEGIN Set the beginning time of the conversion\n");
2887 fprintf(fp
, " time range to BEGIN (see the format of\n");
2888 fprintf(fp
, " BEGIN below)\n");
2889 fprintf(fp
, " -e, --end=END Set the end time of the conversion time\n");
2890 fprintf(fp
, " range to END (see the format of END below)\n");
2891 fprintf(fp
, " -t, --timerange=TIMERANGE Set conversion time range to TIMERANGE:\n");
2892 fprintf(fp
, " BEGIN,END or [BEGIN,END] (literally `[` and\n");
2893 fprintf(fp
, " `]`) (see the format of BEGIN/END below)\n");
2895 fprintf(fp
, "Implicit `lttng-utils.debug-info` filter component options:\n");
2897 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
2898 fprintf(fp
, " instead of `/usr/lib/debug`\n");
2899 fprintf(fp
, " --debug-info-full-path Show full debug info source and\n");
2900 fprintf(fp
, " binary paths instead of just names\n");
2901 fprintf(fp
, " --debug-info-target-prefix=DIR\n");
2902 fprintf(fp
, " Use directory DIR as a prefix when\n");
2903 fprintf(fp
, " looking up executables during debug\n");
2904 fprintf(fp
, " info analysis\n");
2905 fprintf(fp
, " --no-debug-info Do not create an implicit\n");
2906 fprintf(fp
, " `lttng-utils.debug-info` filter component\n");
2908 fprintf(fp
, "Legacy options that still work:\n");
2910 fprintf(fp
, " -i, --input-format=(ctf | lttng-live)\n");
2911 fprintf(fp
, " `ctf`:\n");
2912 fprintf(fp
, " Create an implicit `ctf.fs` source\n");
2913 fprintf(fp
, " component\n");
2914 fprintf(fp
, " `lttng-live`:\n");
2915 fprintf(fp
, " Create an implicit `ctf.lttng-live`\n");
2916 fprintf(fp
, " source component\n");
2917 fprintf(fp
, " -o, --output-format=(text | dummy | ctf-metadata)\n");
2918 fprintf(fp
, " `text`:\n");
2919 fprintf(fp
, " Create an implicit `text.text` sink\n");
2920 fprintf(fp
, " component\n");
2921 fprintf(fp
, " `dummy`:\n");
2922 fprintf(fp
, " Create an implicit `utils.dummy` sink\n");
2923 fprintf(fp
, " component\n");
2924 fprintf(fp
, " `ctf-metadata`:\n");
2925 fprintf(fp
, " Query the `ctf.fs` component class for\n");
2926 fprintf(fp
, " metadata text and quit\n");
2928 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2929 fprintf(fp
, "\n\n");
2930 fprintf(fp
, "Format of BEGIN and END\n");
2931 fprintf(fp
, "-----------------------\n");
2933 fprintf(fp
, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
2934 fprintf(fp
, "\n\n");
2935 print_expected_params_format(fp
);
2939 struct poptOption convert_long_options
[] = {
2940 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2941 { "begin", 'b', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2942 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2943 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2944 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2945 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2946 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2947 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2948 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2949 { "color", '\0', POPT_ARG_STRING
, NULL
, OPT_COLOR
, NULL
, NULL
},
2950 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2951 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2952 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2953 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2954 { "end", 'e', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2955 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2956 { "filter", '\0', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
2957 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2958 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2959 { "name", '\0', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2960 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2961 { "no-debug-info", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DEBUG_INFO
, NULL
, NULL
},
2962 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2963 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2964 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2965 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT
, NULL
, NULL
},
2966 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2967 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2968 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2969 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2970 { "retry-duration", '\0', POPT_ARG_STRING
, NULL
, OPT_RETRY_DURATION
, NULL
, NULL
},
2971 { "run-args", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS
, NULL
, NULL
},
2972 { "run-args-0", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS_0
, NULL
, NULL
},
2973 { "sink", '\0', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
2974 { "source", '\0', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
2975 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2976 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2977 { "url", 'u', POPT_ARG_STRING
, NULL
, OPT_URL
, NULL
, NULL
},
2978 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2979 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2983 GString
*get_component_auto_name(const char *prefix
,
2984 struct bt_value
*existing_names
)
2987 GString
*auto_name
= g_string_new(NULL
);
2994 if (!bt_value_map_has_key(existing_names
, prefix
)) {
2995 g_string_assign(auto_name
, prefix
);
3000 g_string_printf(auto_name
, "%s-%d", prefix
, i
);
3002 } while (bt_value_map_has_key(existing_names
, auto_name
->str
));
3008 struct implicit_component_args
{
3010 GString
*plugin_comp_cls_arg
;
3012 GString
*params_arg
;
3013 struct bt_value
*extra_args
;
3017 int assign_name_to_implicit_component(struct implicit_component_args
*args
,
3018 const char *prefix
, struct bt_value
*existing_names
,
3019 GList
**comp_names
, bool append_to_comp_names
)
3022 GString
*name
= NULL
;
3024 if (!args
->exists
) {
3028 name
= get_component_auto_name(prefix
, existing_names
);
3035 g_string_assign(args
->name_arg
, name
->str
);
3037 if (bt_value_map_insert(existing_names
, name
->str
,
3044 if (append_to_comp_names
) {
3045 *comp_names
= g_list_append(*comp_names
, name
);
3051 g_string_free(name
, TRUE
);
3058 int append_run_args_for_implicit_component(
3059 enum bt_component_class_type type
,
3060 struct implicit_component_args
*impl_args
,
3061 struct bt_value
*run_args
)
3066 if (!impl_args
->exists
) {
3071 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
3072 if (bt_value_array_append_string(run_args
, "--source")) {
3077 case BT_COMPONENT_CLASS_TYPE_FILTER
:
3078 if (bt_value_array_append_string(run_args
, "--filter")) {
3083 case BT_COMPONENT_CLASS_TYPE_SINK
:
3084 if (bt_value_array_append_string(run_args
, "--sink")) {
3093 if (bt_value_array_append_string(run_args
,
3094 impl_args
->plugin_comp_cls_arg
->str
)) {
3099 if (bt_value_array_append_string(run_args
, "--name")) {
3104 if (bt_value_array_append_string(run_args
, impl_args
->name_arg
->str
)) {
3109 if (impl_args
->params_arg
->len
> 0) {
3110 if (bt_value_array_append_string(run_args
, "--params")) {
3115 if (bt_value_array_append_string(run_args
,
3116 impl_args
->params_arg
->str
)) {
3122 for (i
= 0; i
< bt_value_array_size(impl_args
->extra_args
); i
++) {
3123 struct bt_value
*elem
;
3126 elem
= bt_value_array_get(impl_args
->extra_args
, i
);
3131 assert(bt_value_is_string(elem
));
3132 if (bt_value_string_get(elem
, &arg
)) {
3136 ret
= bt_value_array_append_string(run_args
, arg
);
3154 void destroy_implicit_component_args(struct implicit_component_args
*args
)
3158 if (args
->plugin_comp_cls_arg
) {
3159 g_string_free(args
->plugin_comp_cls_arg
, TRUE
);
3162 if (args
->name_arg
) {
3163 g_string_free(args
->name_arg
, TRUE
);
3166 if (args
->params_arg
) {
3167 g_string_free(args
->params_arg
, TRUE
);
3170 bt_put(args
->extra_args
);
3174 int init_implicit_component_args(struct implicit_component_args
*args
,
3175 const char *plugin_comp_cls_arg
, bool exists
)
3179 args
->exists
= exists
;
3180 args
->plugin_comp_cls_arg
= g_string_new(plugin_comp_cls_arg
);
3181 args
->name_arg
= g_string_new(NULL
);
3182 args
->params_arg
= g_string_new(NULL
);
3183 args
->extra_args
= bt_value_array_create();
3185 if (!args
->plugin_comp_cls_arg
|| !args
->name_arg
||
3186 !args
->params_arg
|| !args
->extra_args
) {
3188 destroy_implicit_component_args(args
);
3198 void append_implicit_component_param(struct implicit_component_args
*args
,
3199 const char *key
, const char *value
)
3204 append_param_arg(args
->params_arg
, key
, value
);
3208 int append_implicit_component_extra_arg(struct implicit_component_args
*args
,
3209 const char *key
, const char *value
)
3217 if (bt_value_array_append_string(args
->extra_args
, "--key")) {
3223 if (bt_value_array_append_string(args
->extra_args
, key
)) {
3229 if (bt_value_array_append_string(args
->extra_args
, "--value")) {
3235 if (bt_value_array_append_string(args
->extra_args
, value
)) {
3246 int convert_append_name_param(enum bt_config_component_dest dest
,
3247 GString
*cur_name
, GString
*cur_name_prefix
,
3248 struct bt_value
*run_args
, struct bt_value
*all_names
,
3249 GList
**source_names
, GList
**filter_names
,
3254 if (cur_name_prefix
->len
> 0) {
3255 /* We're after a --source/--filter/--sink */
3256 GString
*name
= NULL
;
3257 bool append_name_opt
= false;
3259 if (cur_name
->len
== 0) {
3261 * No explicit name was provided for the user
3264 name
= get_component_auto_name(
3265 cur_name_prefix
->str
,
3267 append_name_opt
= true;
3270 * An explicit name was provided for the user
3273 if (bt_value_map_has_key(all_names
,
3275 printf_err("Duplicate component instance name:\n %s\n",
3280 name
= g_string_new(cur_name
->str
);
3289 * Remember this name globally, for the uniqueness of
3290 * all component names.
3292 if (bt_value_map_insert(all_names
, name
->str
, bt_value_null
)) {
3298 * Append the --name option if necessary.
3300 if (append_name_opt
) {
3301 if (bt_value_array_append_string(run_args
, "--name")) {
3306 if (bt_value_array_append_string(run_args
, name
->str
)) {
3313 * Remember this name specifically for the type of the
3314 * component. This is to create connection arguments.
3317 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
3318 *source_names
= g_list_append(*source_names
, name
);
3320 case BT_CONFIG_COMPONENT_DEST_FILTER
:
3321 *filter_names
= g_list_append(*filter_names
, name
);
3323 case BT_CONFIG_COMPONENT_DEST_SINK
:
3324 *sink_names
= g_list_append(*sink_names
, name
);
3330 g_string_assign(cur_name_prefix
, "");
3343 * Escapes `.`, `:`, and `\` of `input` with `\`.
3346 GString
*escape_dot_colon(const char *input
)
3348 GString
*output
= g_string_new(NULL
);
3356 for (ch
= input
; *ch
!= '\0'; ch
++) {
3357 if (*ch
== '\\' || *ch
== '.' || *ch
== ':') {
3358 g_string_append_c(output
, '\\');
3361 g_string_append_c(output
, *ch
);
3369 * Appends a --connect option to a list of arguments. `upstream_name`
3370 * and `downstream_name` are escaped with escape_dot_colon() in this
3374 int append_connect_arg(struct bt_value
*run_args
,
3375 const char *upstream_name
, const char *downstream_name
)
3378 GString
*e_upstream_name
= escape_dot_colon(upstream_name
);
3379 GString
*e_downstream_name
= escape_dot_colon(downstream_name
);
3380 GString
*arg
= g_string_new(NULL
);
3382 if (!e_upstream_name
|| !e_downstream_name
|| !arg
) {
3388 ret
= bt_value_array_append_string(run_args
, "--connect");
3395 g_string_append(arg
, e_upstream_name
->str
);
3396 g_string_append_c(arg
, ':');
3397 g_string_append(arg
, e_downstream_name
->str
);
3398 ret
= bt_value_array_append_string(run_args
, arg
->str
);
3407 g_string_free(arg
, TRUE
);
3410 if (e_upstream_name
) {
3411 g_string_free(e_upstream_name
, TRUE
);
3414 if (e_downstream_name
) {
3415 g_string_free(e_downstream_name
, TRUE
);
3422 * Appends the run command's --connect options for the convert command.
3425 int convert_auto_connect(struct bt_value
*run_args
,
3426 GList
*source_names
, GList
*filter_names
,
3430 GList
*source_at
= source_names
;
3431 GList
*filter_at
= filter_names
;
3433 GList
*sink_at
= sink_names
;
3435 assert(source_names
);
3436 assert(filter_names
);
3439 /* Connect all sources to the first filter */
3440 for (source_at
= source_names
; source_at
!= NULL
; source_at
= g_list_next(source_at
)) {
3441 GString
*source_name
= source_at
->data
;
3442 GString
*filter_name
= filter_at
->data
;
3444 ret
= append_connect_arg(run_args
, source_name
->str
,
3451 filter_prev
= filter_at
;
3452 filter_at
= g_list_next(filter_at
);
3454 /* Connect remaining filters */
3455 for (; filter_at
!= NULL
; filter_prev
= filter_at
, filter_at
= g_list_next(filter_at
)) {
3456 GString
*filter_name
= filter_at
->data
;
3457 GString
*filter_prev_name
= filter_prev
->data
;
3459 ret
= append_connect_arg(run_args
, filter_prev_name
->str
,
3466 /* Connect last filter to all sinks */
3467 for (sink_at
= sink_names
; sink_at
!= NULL
; sink_at
= g_list_next(sink_at
)) {
3468 GString
*filter_name
= filter_prev
->data
;
3469 GString
*sink_name
= sink_at
->data
;
3471 ret
= append_connect_arg(run_args
, filter_name
->str
,
3488 int split_timerange(const char *arg
, char **begin
, char **end
)
3491 const char *ch
= arg
;
3493 GString
*g_begin
= NULL
;
3494 GString
*g_end
= NULL
;
3502 g_begin
= bt_common_string_until(ch
, "", ",", &end_pos
);
3503 if (!g_begin
|| ch
[end_pos
] != ',' || g_begin
->len
== 0) {
3509 g_end
= bt_common_string_until(ch
, "", "]", &end_pos
);
3510 if (!g_end
|| g_end
->len
== 0) {
3516 *begin
= g_begin
->str
;
3518 g_string_free(g_begin
, FALSE
);
3519 g_string_free(g_end
, FALSE
);
3529 g_string_free(g_begin
, TRUE
);
3533 g_string_free(g_end
, TRUE
);
3540 int g_list_prepend_gstring(GList
**list
, const char *string
)
3543 GString
*gs
= g_string_new(string
);
3552 *list
= g_list_prepend(*list
, gs
);
3559 * Creates a Babeltrace config object from the arguments of a convert
3562 * *retcode is set to the appropriate exit code to use.
3565 struct bt_config
*bt_config_convert_from_args(int argc
, const char *argv
[],
3566 int *retcode
, bool force_omit_system_plugin_path
,
3567 bool force_omit_home_plugin_path
, bool force_no_debug_info
,
3568 struct bt_value
*initial_plugin_paths
)
3570 poptContext pc
= NULL
;
3572 enum bt_config_component_dest cur_comp_dest
=
3573 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
3575 struct bt_config
*cfg
= NULL
;
3576 bool got_verbose_opt
= false;
3577 bool got_debug_opt
= false;
3578 bool got_input_format_opt
= false;
3579 bool got_output_format_opt
= false;
3580 bool trimmer_has_begin
= false;
3581 bool trimmer_has_end
= false;
3582 GString
*cur_name
= NULL
;
3583 GString
*cur_name_prefix
= NULL
;
3584 const char *leftover
= NULL
;
3585 bool print_run_args
= false;
3586 bool print_run_args_0
= false;
3587 bool print_ctf_metadata
= false;
3588 struct bt_value
*run_args
= NULL
;
3589 struct bt_value
*all_names
= NULL
;
3590 GList
*source_names
= NULL
;
3591 GList
*filter_names
= NULL
;
3592 GList
*sink_names
= NULL
;
3593 struct implicit_component_args implicit_ctf_args
= { 0 };
3594 struct implicit_component_args implicit_lttng_live_args
= { 0 };
3595 struct implicit_component_args implicit_dummy_args
= { 0 };
3596 struct implicit_component_args implicit_text_args
= { 0 };
3597 struct implicit_component_args implicit_debug_info_args
= { 0 };
3598 struct implicit_component_args implicit_muxer_args
= { 0 };
3599 struct implicit_component_args implicit_trimmer_args
= { 0 };
3600 struct bt_value
*plugin_paths
= bt_get(initial_plugin_paths
);
3601 char error_buf
[256] = { 0 };
3603 struct bt_common_lttng_live_url_parts lttng_live_url_parts
= { 0 };
3608 print_convert_usage(stdout
);
3613 if (init_implicit_component_args(&implicit_ctf_args
, "ctf.fs", false)) {
3617 if (init_implicit_component_args(&implicit_lttng_live_args
,
3618 "ctf.lttng-live", false)) {
3622 if (init_implicit_component_args(&implicit_text_args
, "text.pretty",
3627 if (init_implicit_component_args(&implicit_dummy_args
, "utils.dummy",
3632 if (init_implicit_component_args(&implicit_debug_info_args
,
3633 "lttng-utils.debug-info", !force_no_debug_info
)) {
3637 if (init_implicit_component_args(&implicit_muxer_args
, "utils.muxer",
3642 if (init_implicit_component_args(&implicit_trimmer_args
,
3643 "utils.trimmer", false)) {
3647 all_names
= bt_value_map_create();
3653 run_args
= bt_value_array_create();
3659 cur_name
= g_string_new(NULL
);
3665 cur_name_prefix
= g_string_new(NULL
);
3666 if (!cur_name_prefix
) {
3671 ret
= append_env_var_plugin_paths(plugin_paths
);
3677 * First pass: collect all arguments which need to be passed
3678 * as is to the run command. This pass can also add --name
3679 * arguments if needed to automatically name unnamed component
3680 * instances. Also it does the following transformations:
3682 * --path=PATH -> --key path --value PATH
3683 * --url=URL -> --key url --value URL
3685 * Also it appends the plugin paths of --plugin-path to
3688 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3689 convert_long_options
, 0);
3691 printf_err("Cannot get popt context\n");
3695 poptReadDefaultConfig(pc
, 0);
3697 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3699 char *plugin_name
= NULL
;
3700 char *comp_cls_name
= NULL
;
3702 arg
= poptGetOptArg(pc
);
3708 /* Append current component's name if needed */
3709 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3710 cur_name_prefix
, run_args
, all_names
,
3711 &source_names
, &filter_names
, &sink_names
);
3716 /* Parse the argument */
3717 plugin_comp_cls_names(arg
, &name
, &plugin_name
,
3719 if (!plugin_name
|| !comp_cls_name
) {
3720 printf_err("Invalid format for --source/--filter/--sink option's argument:\n %s\n",
3726 g_string_assign(cur_name
, name
);
3728 g_string_assign(cur_name
, "");
3734 BT_CONFIG_COMPONENT_DEST_SOURCE
;
3735 if (bt_value_array_append_string(run_args
,
3743 BT_CONFIG_COMPONENT_DEST_FILTER
;
3744 if (bt_value_array_append_string(run_args
,
3752 BT_CONFIG_COMPONENT_DEST_SINK
;
3753 if (bt_value_array_append_string(run_args
,
3763 if (bt_value_array_append_string(run_args
, arg
)) {
3768 g_string_assign(cur_name_prefix
, "");
3769 g_string_append(cur_name_prefix
, plugin_name
);
3770 g_string_append_c(cur_name_prefix
, '.');
3771 g_string_append(cur_name_prefix
, comp_cls_name
);
3774 free(comp_cls_name
);
3777 comp_cls_name
= NULL
;
3780 if (cur_name_prefix
->len
== 0) {
3781 printf_err("No current component of which to set parameters:\n %s\n",
3786 if (bt_value_array_append_string(run_args
,
3792 if (bt_value_array_append_string(run_args
, arg
)) {
3798 if (cur_name_prefix
->len
== 0) {
3799 printf_err("No current component of which to set `path` parameter:\n %s\n",
3804 if (bt_value_array_append_string(run_args
, "--key")) {
3809 if (bt_value_array_append_string(run_args
, "path")) {
3814 if (bt_value_array_append_string(run_args
, "--value")) {
3819 if (bt_value_array_append_string(run_args
, arg
)) {
3825 if (cur_name_prefix
->len
== 0) {
3826 printf_err("No current component of which to set `url` parameter:\n %s\n",
3831 if (bt_value_array_append_string(run_args
, "--key")) {
3836 if (bt_value_array_append_string(run_args
, "url")) {
3841 if (bt_value_array_append_string(run_args
, "--value")) {
3846 if (bt_value_array_append_string(run_args
, arg
)) {
3852 if (cur_name_prefix
->len
== 0) {
3853 printf_err("No current component to name:\n %s\n",
3858 if (bt_value_array_append_string(run_args
, "--name")) {
3863 if (bt_value_array_append_string(run_args
, arg
)) {
3868 g_string_assign(cur_name
, arg
);
3870 case OPT_OMIT_HOME_PLUGIN_PATH
:
3871 force_omit_home_plugin_path
= true;
3873 if (bt_value_array_append_string(run_args
,
3874 "--omit-home-plugin-path")) {
3879 case OPT_RETRY_DURATION
:
3880 if (bt_value_array_append_string(run_args
,
3881 "--retry-duration")) {
3886 if (bt_value_array_append_string(run_args
, arg
)) {
3891 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
3892 force_omit_system_plugin_path
= true;
3894 if (bt_value_array_append_string(run_args
,
3895 "--omit-system-plugin-path")) {
3900 case OPT_PLUGIN_PATH
:
3901 if (bt_config_append_plugin_paths_check_setuid_setgid(
3902 plugin_paths
, arg
)) {
3906 if (bt_value_array_append_string(run_args
,
3912 if (bt_value_array_append_string(run_args
, arg
)) {
3918 print_convert_usage(stdout
);
3923 case OPT_CLOCK_CYCLES
:
3924 case OPT_CLOCK_DATE
:
3925 case OPT_CLOCK_FORCE_CORRELATE
:
3927 case OPT_CLOCK_OFFSET
:
3928 case OPT_CLOCK_OFFSET_NS
:
3929 case OPT_CLOCK_SECONDS
:
3932 case OPT_DEBUG_INFO_DIR
:
3933 case OPT_DEBUG_INFO_FULL_PATH
:
3934 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3937 case OPT_INPUT_FORMAT
:
3939 case OPT_NO_DEBUG_INFO
:
3941 case OPT_OUTPUT_FORMAT
:
3944 case OPT_RUN_ARGS_0
:
3945 case OPT_STREAM_INTERSECTION
:
3948 /* Ignore in this pass */
3951 printf_err("Unknown command-line option specified (option code %d)\n",
3960 /* Append current component's name if needed */
3961 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3962 cur_name_prefix
, run_args
, all_names
, &source_names
,
3963 &filter_names
, &sink_names
);
3968 /* Check for option parsing error */
3970 printf_err("While parsing command-line options, at option %s: %s\n",
3971 poptBadOption(pc
, 0), poptStrerror(opt
));
3975 poptFreeContext(pc
);
3980 * Second pass: transform the convert-specific options and
3981 * arguments into implicit component instances for the run
3984 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3985 convert_long_options
, 0);
3987 printf_err("Cannot get popt context\n");
3991 poptReadDefaultConfig(pc
, 0);
3993 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3994 arg
= poptGetOptArg(pc
);
3998 if (trimmer_has_begin
) {
3999 printf("At --begin option: --begin or --timerange option already specified\n %s\n",
4004 trimmer_has_begin
= true;
4005 ret
= append_implicit_component_extra_arg(
4006 &implicit_trimmer_args
, "begin", arg
);
4007 implicit_trimmer_args
.exists
= true;
4013 if (trimmer_has_end
) {
4014 printf("At --end option: --end or --timerange option already specified\n %s\n",
4019 trimmer_has_end
= true;
4020 ret
= append_implicit_component_extra_arg(
4021 &implicit_trimmer_args
, "end", arg
);
4022 implicit_trimmer_args
.exists
= true;
4032 if (trimmer_has_begin
|| trimmer_has_end
) {
4033 printf("At --timerange option: --begin, --end, or --timerange option already specified\n %s\n",
4038 ret
= split_timerange(arg
, &begin
, &end
);
4040 printf_err("Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:\n %s\n",
4045 ret
= append_implicit_component_extra_arg(
4046 &implicit_trimmer_args
, "begin", begin
);
4047 ret
|= append_implicit_component_extra_arg(
4048 &implicit_trimmer_args
, "end", end
);
4049 implicit_trimmer_args
.exists
= true;
4057 case OPT_CLOCK_CYCLES
:
4058 append_implicit_component_param(
4059 &implicit_text_args
, "clock-cycles", "yes");
4060 implicit_text_args
.exists
= true;
4062 case OPT_CLOCK_DATE
:
4063 append_implicit_component_param(
4064 &implicit_text_args
, "clock-date", "yes");
4065 implicit_text_args
.exists
= true;
4067 case OPT_CLOCK_FORCE_CORRELATE
:
4068 append_implicit_component_param(
4069 &implicit_muxer_args
, "assume-absolute-clock-classes", "yes");
4072 append_implicit_component_param(
4073 &implicit_text_args
, "clock-gmt", "yes");
4074 implicit_text_args
.exists
= true;
4076 case OPT_CLOCK_OFFSET
:
4077 ret
= append_implicit_component_extra_arg(
4078 &implicit_ctf_args
, "clock-offset-cycles", arg
);
4079 implicit_ctf_args
.exists
= true;
4084 case OPT_CLOCK_OFFSET_NS
:
4085 ret
= append_implicit_component_extra_arg(
4086 &implicit_ctf_args
, "clock-offset-ns", arg
);
4087 implicit_ctf_args
.exists
= true;
4092 case OPT_CLOCK_SECONDS
:
4093 append_implicit_component_param(
4094 &implicit_text_args
, "clock-seconds", "yes");
4095 implicit_text_args
.exists
= true;
4098 ret
= append_implicit_component_extra_arg(
4099 &implicit_text_args
, "color", arg
);
4100 implicit_text_args
.exists
= true;
4105 case OPT_NO_DEBUG_INFO
:
4106 implicit_debug_info_args
.exists
= false;
4108 case OPT_DEBUG_INFO_DIR
:
4109 ret
= append_implicit_component_extra_arg(
4110 &implicit_debug_info_args
, "dir", arg
);
4115 case OPT_DEBUG_INFO_FULL_PATH
:
4116 append_implicit_component_param(
4117 &implicit_debug_info_args
, "full-path", "yes");
4119 case OPT_DEBUG_INFO_TARGET_PREFIX
:
4120 ret
= append_implicit_component_extra_arg(
4121 &implicit_debug_info_args
,
4122 "target-prefix", arg
);
4129 struct bt_value
*fields
= fields_from_arg(arg
);
4135 ret
= insert_flat_params_from_array(
4136 implicit_text_args
.params_arg
,
4146 struct bt_value
*names
= names_from_arg(arg
);
4152 ret
= insert_flat_params_from_array(
4153 implicit_text_args
.params_arg
,
4162 append_implicit_component_param(
4163 &implicit_text_args
, "no-delta", "yes");
4164 implicit_text_args
.exists
= true;
4166 case OPT_INPUT_FORMAT
:
4167 if (got_input_format_opt
) {
4168 printf_err("Duplicate --input-format option\n");
4172 got_input_format_opt
= true;
4174 if (strcmp(arg
, "ctf") == 0) {
4175 implicit_ctf_args
.exists
= true;
4176 } else if (strcmp(arg
, "lttng-live") == 0) {
4177 implicit_lttng_live_args
.exists
= true;
4179 printf_err("Unknown legacy input format:\n %s\n",
4184 case OPT_OUTPUT_FORMAT
:
4185 if (got_output_format_opt
) {
4186 printf_err("Duplicate --output-format option\n");
4190 got_output_format_opt
= true;
4192 if (strcmp(arg
, "text") == 0) {
4193 implicit_text_args
.exists
= true;
4194 } else if (strcmp(arg
, "dummy") == 0) {
4195 implicit_dummy_args
.exists
= true;
4196 } else if (strcmp(arg
, "ctf-metadata") == 0) {
4197 print_ctf_metadata
= true;
4199 printf_err("Unknown legacy output format:\n %s\n",
4205 ret
= append_implicit_component_extra_arg(
4206 &implicit_text_args
, "path", arg
);
4207 implicit_text_args
.exists
= true;
4213 if (print_run_args_0
) {
4214 printf_err("Cannot specify --run-args and --run-args-0\n");
4218 print_run_args
= true;
4220 case OPT_RUN_ARGS_0
:
4221 if (print_run_args
) {
4222 printf_err("Cannot specify --run-args and --run-args-0\n");
4226 print_run_args_0
= true;
4228 case OPT_STREAM_INTERSECTION
:
4229 append_implicit_component_param(&implicit_ctf_args
,
4230 "stream-intersection", "yes");
4231 implicit_ctf_args
.exists
= true;
4234 if (got_verbose_opt
) {
4235 printf_err("Duplicate -v/--verbose option\n");
4239 append_implicit_component_param(&implicit_text_args
,
4241 implicit_text_args
.exists
= true;
4242 got_verbose_opt
= true;
4245 got_debug_opt
= true;
4253 /* Check for option parsing error */
4255 printf_err("While parsing command-line options, at option %s: %s\n",
4256 poptBadOption(pc
, 0), poptStrerror(opt
));
4261 * Append home and system plugin paths now that we possibly got
4264 if (append_home_and_system_plugin_paths(plugin_paths
,
4265 force_omit_system_plugin_path
,
4266 force_omit_home_plugin_path
)) {
4270 /* Consume leftover argument */
4271 leftover
= poptGetArg(pc
);
4273 if (poptPeekArg(pc
)) {
4274 printf_err("Unexpected argument:\n %s\n",
4279 /* Print CTF metadata or print LTTng live sessions */
4280 if (print_ctf_metadata
) {
4282 printf_err("--output-format=ctf-metadata specified without a path\n");
4286 cfg
= bt_config_print_ctf_metadata_create(plugin_paths
);
4291 cfg
->debug
= got_debug_opt
;
4292 cfg
->verbose
= got_verbose_opt
;
4293 g_string_assign(cfg
->cmd_data
.print_ctf_metadata
.path
,
4299 * If -o dummy was not specified, and if there are no explicit
4300 * sink components, then use an implicit `text.text` sink.
4302 if (!implicit_dummy_args
.exists
&& !sink_names
) {
4303 implicit_text_args
.exists
= true;
4306 /* Decide where the leftover argument goes */
4308 if (implicit_lttng_live_args
.exists
) {
4309 lttng_live_url_parts
=
4310 bt_common_parse_lttng_live_url(leftover
,
4311 error_buf
, sizeof(error_buf
));
4312 if (!lttng_live_url_parts
.proto
) {
4313 printf_err("Invalid LTTng live URL format: %s\n",
4318 if (!lttng_live_url_parts
.session_name
) {
4319 /* Print LTTng live sessions */
4320 cfg
= bt_config_print_lttng_live_sessions_create(
4326 cfg
->debug
= got_debug_opt
;
4327 cfg
->verbose
= got_verbose_opt
;
4328 g_string_assign(cfg
->cmd_data
.print_lttng_live_sessions
.url
,
4333 ret
= append_implicit_component_extra_arg(
4334 &implicit_lttng_live_args
, "url", leftover
);
4339 ret
= append_implicit_component_extra_arg(
4340 &implicit_ctf_args
, "path", leftover
);
4341 implicit_ctf_args
.exists
= true;
4349 * Ensure mutual exclusion between implicit `ctf.fs` and
4350 * `ctf.lttng-live` sources.
4352 if (implicit_ctf_args
.exists
&& implicit_lttng_live_args
.exists
) {
4353 printf_err("Cannot create both implicit `%s` and `%s` source components\n",
4354 implicit_ctf_args
.plugin_comp_cls_arg
->str
,
4355 implicit_lttng_live_args
.plugin_comp_cls_arg
->str
);
4360 * If the implicit `ctf.fs` or `ctf.lttng-live` source exists,
4361 * make sure there's a leftover (which is the path or URL).
4363 if (implicit_ctf_args
.exists
&& !leftover
) {
4364 printf_err("Missing path for implicit `%s` source component\n",
4365 implicit_ctf_args
.plugin_comp_cls_arg
->str
);
4369 if (implicit_lttng_live_args
.exists
&& !leftover
) {
4370 printf_err("Missing URL for implicit `%s` source component\n",
4371 implicit_lttng_live_args
.plugin_comp_cls_arg
->str
);
4375 /* Assign names to implicit components */
4376 ret
= assign_name_to_implicit_component(&implicit_ctf_args
,
4377 "ctf-fs", all_names
, &source_names
, true);
4382 ret
= assign_name_to_implicit_component(&implicit_lttng_live_args
,
4383 "lttng-live", all_names
, &source_names
, true);
4388 ret
= assign_name_to_implicit_component(&implicit_text_args
,
4389 "pretty", all_names
, &sink_names
, true);
4394 ret
= assign_name_to_implicit_component(&implicit_dummy_args
,
4395 "dummy", all_names
, &sink_names
, true);
4400 ret
= assign_name_to_implicit_component(&implicit_muxer_args
,
4401 "muxer", all_names
, NULL
, false);
4406 ret
= assign_name_to_implicit_component(&implicit_trimmer_args
,
4407 "trimmer", all_names
, NULL
, false);
4412 ret
= assign_name_to_implicit_component(&implicit_debug_info_args
,
4413 "debug-info", all_names
, NULL
, false);
4418 /* Make sure there's at least one source and one sink */
4419 if (!source_names
) {
4420 printf_err("No source component\n");
4425 printf_err("No sink component\n");
4430 * Prepend the muxer, the trimmer, and the debug info to the
4431 * filter chain so that we have:
4433 * sources -> muxer -> [trimmer] -> [debug info] ->
4434 * [user filters] -> sinks
4436 if (implicit_debug_info_args
.exists
) {
4437 if (g_list_prepend_gstring(&filter_names
,
4438 implicit_debug_info_args
.name_arg
->str
)) {
4443 if (implicit_trimmer_args
.exists
) {
4444 if (g_list_prepend_gstring(&filter_names
,
4445 implicit_trimmer_args
.name_arg
->str
)) {
4450 if (g_list_prepend_gstring(&filter_names
,
4451 implicit_muxer_args
.name_arg
->str
)) {
4456 * Append the equivalent run arguments for the implicit
4459 ret
= append_run_args_for_implicit_component(
4460 BT_COMPONENT_CLASS_TYPE_SOURCE
, &implicit_ctf_args
, run_args
);
4465 ret
= append_run_args_for_implicit_component(
4466 BT_COMPONENT_CLASS_TYPE_SOURCE
, &implicit_lttng_live_args
,
4472 ret
= append_run_args_for_implicit_component(
4473 BT_COMPONENT_CLASS_TYPE_SINK
, &implicit_text_args
, run_args
);
4478 ret
= append_run_args_for_implicit_component(
4479 BT_COMPONENT_CLASS_TYPE_SINK
, &implicit_dummy_args
, run_args
);
4484 ret
= append_run_args_for_implicit_component(
4485 BT_COMPONENT_CLASS_TYPE_FILTER
, &implicit_muxer_args
, run_args
);
4490 ret
= append_run_args_for_implicit_component(
4491 BT_COMPONENT_CLASS_TYPE_FILTER
, &implicit_trimmer_args
,
4497 ret
= append_run_args_for_implicit_component(
4498 BT_COMPONENT_CLASS_TYPE_FILTER
, &implicit_debug_info_args
,
4504 /* Auto-connect components */
4505 ret
= convert_auto_connect(run_args
, source_names
, filter_names
,
4508 printf_err("Cannot auto-connect components\n");
4513 * We have all the run command arguments now. Depending on
4514 * --run-args, we pass this to the run command or print them
4517 if (print_run_args
|| print_run_args_0
) {
4518 for (i
= 0; i
< bt_value_array_size(run_args
); i
++) {
4519 struct bt_value
*arg_value
=
4520 bt_value_array_get(run_args
, i
);
4522 GString
*quoted
= NULL
;
4523 const char *arg_to_print
;
4526 ret
= bt_value_string_get(arg_value
, &arg
);
4530 if (print_run_args
) {
4531 quoted
= bt_common_shell_quote(arg
, true);
4536 arg_to_print
= quoted
->str
;
4541 printf("%s", arg_to_print
);
4544 g_string_free(quoted
, TRUE
);
4547 if (i
< bt_value_array_size(run_args
) - 1) {
4548 if (print_run_args
) {
4561 cfg
= bt_config_run_from_args_array(run_args
, retcode
,
4562 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
4563 initial_plugin_paths
);
4572 poptFreeContext(pc
);
4578 g_string_free(cur_name
, TRUE
);
4581 if (cur_name_prefix
) {
4582 g_string_free(cur_name_prefix
, TRUE
);
4587 destroy_glist_of_gstring(source_names
);
4588 destroy_glist_of_gstring(filter_names
);
4589 destroy_glist_of_gstring(sink_names
);
4590 destroy_implicit_component_args(&implicit_ctf_args
);
4591 destroy_implicit_component_args(&implicit_lttng_live_args
);
4592 destroy_implicit_component_args(&implicit_dummy_args
);
4593 destroy_implicit_component_args(&implicit_text_args
);
4594 destroy_implicit_component_args(&implicit_debug_info_args
);
4595 destroy_implicit_component_args(&implicit_muxer_args
);
4596 destroy_implicit_component_args(&implicit_trimmer_args
);
4597 bt_put(plugin_paths
);
4598 bt_common_destroy_lttng_live_url_parts(<tng_live_url_parts
);
4603 * Prints the Babeltrace 2.x general usage.
4606 void print_gen_usage(FILE *fp
)
4608 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [COMMAND] [COMMAND ARGUMENTS]\n");
4610 fprintf(fp
, "General options:\n");
4612 fprintf(fp
, " -d, --debug Turn on debug mode\n");
4613 fprintf(fp
, " -h --help Show this help and quit\n");
4614 fprintf(fp
, " -v, --verbose Turn on verbose mode\n");
4615 fprintf(fp
, " -V, --version Show version and quit\n");
4617 fprintf(fp
, "Available commands:\n");
4619 fprintf(fp
, " convert Convert and trim traces (default)\n");
4620 fprintf(fp
, " help Get help for a plugin or a component class\n");
4621 fprintf(fp
, " list-plugins List available plugins and their content\n");
4622 fprintf(fp
, " query Query objects from a component class\n");
4623 fprintf(fp
, " run Build a processing graph and run it\n");
4625 fprintf(fp
, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
4628 struct bt_config
*bt_config_cli_args_create(int argc
, const char *argv
[],
4629 int *retcode
, bool force_omit_system_plugin_path
,
4630 bool force_omit_home_plugin_path
, bool force_no_debug_info
,
4631 struct bt_value
*initial_plugin_paths
)
4633 struct bt_config
*config
= NULL
;
4634 bool verbose
= false;
4637 const char **command_argv
= NULL
;
4638 int command_argc
= -1;
4639 const char *command_name
= NULL
;
4642 COMMAND_TYPE_NONE
= -1,
4643 COMMAND_TYPE_RUN
= 0,
4644 COMMAND_TYPE_CONVERT
,
4645 COMMAND_TYPE_LIST_PLUGINS
,
4648 } command_type
= COMMAND_TYPE_NONE
;
4652 if (!initial_plugin_paths
) {
4653 initial_plugin_paths
= bt_value_array_create();
4654 if (!initial_plugin_paths
) {
4659 bt_get(initial_plugin_paths
);
4663 print_gen_usage(stdout
);
4667 for (i
= 1; i
< argc
; i
++) {
4668 const char *cur_arg
= argv
[i
];
4670 if (strcmp(cur_arg
, "-d") == 0 ||
4671 strcmp(cur_arg
, "--debug") == 0) {
4673 } else if (strcmp(cur_arg
, "-v") == 0 ||
4674 strcmp(cur_arg
, "--verbose") == 0) {
4676 } else if (strcmp(cur_arg
, "-V") == 0 ||
4677 strcmp(cur_arg
, "--version") == 0) {
4680 } else if (strcmp(cur_arg
, "-h") == 0 ||
4681 strcmp(cur_arg
, "--help") == 0) {
4682 print_gen_usage(stdout
);
4685 bool has_command
= true;
4688 * First unknown argument: is it a known command
4691 if (strcmp(cur_arg
, "convert") == 0) {
4692 command_type
= COMMAND_TYPE_CONVERT
;
4693 } else if (strcmp(cur_arg
, "list-plugins") == 0) {
4694 command_type
= COMMAND_TYPE_LIST_PLUGINS
;
4695 } else if (strcmp(cur_arg
, "help") == 0) {
4696 command_type
= COMMAND_TYPE_HELP
;
4697 } else if (strcmp(cur_arg
, "query") == 0) {
4698 command_type
= COMMAND_TYPE_QUERY
;
4699 } else if (strcmp(cur_arg
, "run") == 0) {
4700 command_type
= COMMAND_TYPE_RUN
;
4703 * Unknown argument, but not a known
4704 * command name: assume the whole
4705 * arguments are for the default convert
4708 command_type
= COMMAND_TYPE_CONVERT
;
4709 command_argv
= argv
;
4710 command_argc
= argc
;
4711 has_command
= false;
4715 command_argv
= &argv
[i
];
4716 command_argc
= argc
- i
;
4717 command_name
= cur_arg
;
4723 if (command_type
== COMMAND_TYPE_NONE
) {
4725 * We only got non-help, non-version general options
4726 * like --verbose and --debug, without any other
4727 * arguments, so we can't do anything useful: print the
4730 print_gen_usage(stdout
);
4734 assert(command_argv
);
4735 assert(command_argc
>= 0);
4737 switch (command_type
) {
4738 case COMMAND_TYPE_RUN
:
4739 config
= bt_config_run_from_args(command_argc
, command_argv
,
4740 retcode
, force_omit_system_plugin_path
,
4741 force_omit_home_plugin_path
, initial_plugin_paths
);
4743 case COMMAND_TYPE_CONVERT
:
4744 config
= bt_config_convert_from_args(command_argc
, command_argv
,
4745 retcode
, force_omit_system_plugin_path
,
4746 force_omit_home_plugin_path
, force_no_debug_info
,
4747 initial_plugin_paths
);
4749 case COMMAND_TYPE_LIST_PLUGINS
:
4750 config
= bt_config_list_plugins_from_args(command_argc
,
4751 command_argv
, retcode
, force_omit_system_plugin_path
,
4752 force_omit_home_plugin_path
, initial_plugin_paths
);
4754 case COMMAND_TYPE_HELP
:
4755 config
= bt_config_help_from_args(command_argc
,
4756 command_argv
, retcode
, force_omit_system_plugin_path
,
4757 force_omit_home_plugin_path
, initial_plugin_paths
);
4759 case COMMAND_TYPE_QUERY
:
4760 config
= bt_config_query_from_args(command_argc
,
4761 command_argv
, retcode
, force_omit_system_plugin_path
,
4762 force_omit_home_plugin_path
, initial_plugin_paths
);
4770 config
->verbose
= true;
4774 config
->debug
= true;
4777 config
->command_name
= command_name
;
4781 bt_put(initial_plugin_paths
);