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_SOURCE
,
1313 BT_CONFIG_COMPONENT_DEST_FILTER
,
1314 BT_CONFIG_COMPONENT_DEST_SINK
,
1318 * Adds a configuration component to the appropriate configuration
1319 * array depending on the destination.
1322 void add_run_cfg_comp(struct bt_config
*cfg
,
1323 struct bt_config_component
*cfg_comp
,
1324 enum bt_config_component_dest dest
)
1329 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
1330 g_ptr_array_add(cfg
->cmd_data
.run
.sources
, cfg_comp
);
1332 case BT_CONFIG_COMPONENT_DEST_FILTER
:
1333 g_ptr_array_add(cfg
->cmd_data
.run
.filters
, cfg_comp
);
1335 case BT_CONFIG_COMPONENT_DEST_SINK
:
1336 g_ptr_array_add(cfg
->cmd_data
.run
.sinks
, cfg_comp
);
1344 int add_run_cfg_comp_check_name(struct bt_config
*cfg
,
1345 struct bt_config_component
*cfg_comp
,
1346 enum bt_config_component_dest dest
,
1347 struct bt_value
*instance_names
)
1351 if (cfg_comp
->instance_name
->len
== 0) {
1352 printf_err("Found an unnamed component\n");
1357 if (bt_value_map_has_key(instance_names
, cfg_comp
->instance_name
->str
)) {
1358 printf_err("Duplicate component instance name:\n %s\n",
1359 cfg_comp
->instance_name
->str
);
1364 if (bt_value_map_insert(instance_names
,
1365 cfg_comp
->instance_name
->str
, bt_value_null
)) {
1371 add_run_cfg_comp(cfg
, cfg_comp
, dest
);
1378 int append_env_var_plugin_paths(struct bt_value
*plugin_paths
)
1383 if (bt_common_is_setuid_setgid()) {
1384 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
1388 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
1393 ret
= bt_config_append_plugin_paths(plugin_paths
, envvar
);
1397 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
1404 int append_home_and_system_plugin_paths(struct bt_value
*plugin_paths
,
1405 bool omit_system_plugin_path
, bool omit_home_plugin_path
)
1409 if (!omit_home_plugin_path
) {
1410 if (bt_common_is_setuid_setgid()) {
1411 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
1413 char *home_plugin_dir
=
1414 bt_common_get_home_plugin_path();
1416 if (home_plugin_dir
) {
1417 ret
= bt_config_append_plugin_paths(
1418 plugin_paths
, home_plugin_dir
);
1419 free(home_plugin_dir
);
1422 printf_err("Invalid home plugin path\n");
1429 if (!omit_system_plugin_path
) {
1430 if (bt_config_append_plugin_paths(plugin_paths
,
1431 bt_common_get_system_plugin_path())) {
1432 printf_err("Invalid system plugin path\n");
1438 printf_err("Cannot append home and system plugin paths\n");
1443 int append_home_and_system_plugin_paths_cfg(struct bt_config
*cfg
)
1445 return append_home_and_system_plugin_paths(cfg
->plugin_paths
,
1446 cfg
->omit_system_plugin_path
, cfg
->omit_home_plugin_path
);
1450 struct bt_config
*bt_config_base_create(enum bt_config_command command
,
1451 struct bt_value
*initial_plugin_paths
, bool needs_plugins
)
1453 struct bt_config
*cfg
;
1456 cfg
= g_new0(struct bt_config
, 1);
1462 bt_object_init(cfg
, bt_config_destroy
);
1463 cfg
->command
= command
;
1464 cfg
->command_needs_plugins
= needs_plugins
;
1466 if (initial_plugin_paths
) {
1467 cfg
->plugin_paths
= bt_get(initial_plugin_paths
);
1469 cfg
->plugin_paths
= bt_value_array_create();
1470 if (!cfg
->plugin_paths
) {
1486 struct bt_config
*bt_config_run_create(
1487 struct bt_value
*initial_plugin_paths
)
1489 struct bt_config
*cfg
;
1492 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_RUN
,
1493 initial_plugin_paths
, true);
1498 cfg
->cmd_data
.run
.sources
= g_ptr_array_new_with_free_func(
1499 (GDestroyNotify
) bt_put
);
1500 if (!cfg
->cmd_data
.run
.sources
) {
1505 cfg
->cmd_data
.run
.filters
= g_ptr_array_new_with_free_func(
1506 (GDestroyNotify
) bt_put
);
1507 if (!cfg
->cmd_data
.run
.filters
) {
1512 cfg
->cmd_data
.run
.sinks
= g_ptr_array_new_with_free_func(
1513 (GDestroyNotify
) bt_put
);
1514 if (!cfg
->cmd_data
.run
.sinks
) {
1519 cfg
->cmd_data
.run
.connections
= g_ptr_array_new_with_free_func(
1520 (GDestroyNotify
) bt_config_connection_destroy
);
1521 if (!cfg
->cmd_data
.run
.connections
) {
1536 struct bt_config
*bt_config_list_plugins_create(
1537 struct bt_value
*initial_plugin_paths
)
1539 struct bt_config
*cfg
;
1542 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_LIST_PLUGINS
,
1543 initial_plugin_paths
, true);
1558 struct bt_config
*bt_config_help_create(
1559 struct bt_value
*initial_plugin_paths
)
1561 struct bt_config
*cfg
;
1564 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_HELP
,
1565 initial_plugin_paths
, true);
1570 cfg
->cmd_data
.help
.cfg_component
=
1571 bt_config_component_create(BT_COMPONENT_CLASS_TYPE_UNKNOWN
,
1573 if (!cfg
->cmd_data
.help
.cfg_component
) {
1587 struct bt_config
*bt_config_query_create(
1588 struct bt_value
*initial_plugin_paths
)
1590 struct bt_config
*cfg
;
1593 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_QUERY
,
1594 initial_plugin_paths
, true);
1599 cfg
->cmd_data
.query
.object
= g_string_new(NULL
);
1600 if (!cfg
->cmd_data
.query
.object
) {
1615 struct bt_config
*bt_config_print_ctf_metadata_create(
1616 struct bt_value
*initial_plugin_paths
)
1618 struct bt_config
*cfg
;
1621 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_CTF_METADATA
,
1622 initial_plugin_paths
, true);
1627 cfg
->cmd_data
.print_ctf_metadata
.path
= g_string_new(NULL
);
1628 if (!cfg
->cmd_data
.print_ctf_metadata
.path
) {
1643 struct bt_config
*bt_config_print_lttng_live_sessions_create(
1644 struct bt_value
*initial_plugin_paths
)
1646 struct bt_config
*cfg
;
1649 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
,
1650 initial_plugin_paths
, true);
1655 cfg
->cmd_data
.print_lttng_live_sessions
.url
= g_string_new(NULL
);
1656 if (!cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
1671 int bt_config_append_plugin_paths_check_setuid_setgid(
1672 struct bt_value
*plugin_paths
, const char *arg
)
1676 if (bt_common_is_setuid_setgid()) {
1677 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
1681 if (bt_config_append_plugin_paths(plugin_paths
, arg
)) {
1682 printf_err("Invalid --plugin-path option's argument:\n %s\n",
1693 * Prints the expected format for a --params option.
1696 void print_expected_params_format(FILE *fp
)
1698 fprintf(fp
, "Expected format of PARAMS\n");
1699 fprintf(fp
, "-------------------------\n");
1701 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
1703 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
1704 fprintf(fp
, "where PARAM is the parameter name (C identifier plus the [:.-] characters),\n");
1705 fprintf(fp
, "and VALUE can be one of:\n");
1707 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
1708 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
1709 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
1710 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
1711 fprintf(fp
, " (`0x` prefix) signed 64-bit integer.\n");
1712 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
1713 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
1714 fprintf(fp
, " the null and boolean value symbols above.\n");
1715 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
1717 fprintf(fp
, "You can put whitespaces allowed around individual `=` and `,` symbols.\n");
1719 fprintf(fp
, "Example:\n");
1721 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
1722 fprintf(fp
, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
1723 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
1725 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
1726 fprintf(fp
, "babeltrace from a shell.\n");
1731 * Prints the help command usage.
1734 void print_help_usage(FILE *fp
)
1736 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
1737 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --source=PLUGIN.CLS\n");
1738 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --filter=PLUGIN.CLS\n");
1739 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --sink=PLUGIN.CLS\n");
1741 fprintf(fp
, "Options:\n");
1743 fprintf(fp
, " -f, --filter=PLUGIN.CLS Get help for the filter component class\n");
1744 fprintf(fp
, " CLS found in the plugin PLUGIN\n");
1745 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1746 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1747 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1748 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1749 fprintf(fp
, " dynamic plugins can be loaded\n");
1750 fprintf(fp
, " -S, --sink=PLUGIN.CLS Get help for the sink component class\n");
1751 fprintf(fp
, " CLS found in the plugin PLUGIN\n");
1752 fprintf(fp
, " -s, --source=PLUGIN.CLS Get help for the source component class\n");
1753 fprintf(fp
, " CLS found in the plugin PLUGIN\n");
1754 fprintf(fp
, " -h --help Show this help and quit\n");
1756 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
1758 fprintf(fp
, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
1762 struct poptOption help_long_options
[] = {
1763 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1764 { "filter", 'f', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
1765 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1766 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1767 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1768 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1769 { "sink", 'S', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
1770 { "source", 's', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
1771 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1775 * Creates a Babeltrace config object from the arguments of a help
1778 * *retcode is set to the appropriate exit code to use.
1781 struct bt_config
*bt_config_help_from_args(int argc
, const char *argv
[],
1782 int *retcode
, bool force_omit_system_plugin_path
,
1783 bool force_omit_home_plugin_path
,
1784 struct bt_value
*initial_plugin_paths
)
1786 poptContext pc
= NULL
;
1790 struct bt_config
*cfg
= NULL
;
1791 const char *leftover
;
1792 char *plugin_name
= NULL
, *comp_cls_name
= NULL
;
1793 char *plug_comp_cls_names
= NULL
;
1796 cfg
= bt_config_help_create(initial_plugin_paths
);
1801 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
1802 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
1803 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
1809 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
1810 help_long_options
, 0);
1812 printf_err("Cannot get popt context\n");
1816 poptReadDefaultConfig(pc
, 0);
1818 while ((opt
= poptGetNextOpt(pc
)) > 0) {
1819 arg
= poptGetOptArg(pc
);
1822 case OPT_PLUGIN_PATH
:
1823 if (bt_config_append_plugin_paths_check_setuid_setgid(
1824 cfg
->plugin_paths
, arg
)) {
1828 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
1829 cfg
->omit_system_plugin_path
= true;
1831 case OPT_OMIT_HOME_PLUGIN_PATH
:
1832 cfg
->omit_home_plugin_path
= true;
1837 if (cfg
->cmd_data
.help
.cfg_component
->type
!=
1838 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
1839 printf_err("Cannot specify more than one plugin and component class:\n %s\n",
1846 cfg
->cmd_data
.help
.cfg_component
->type
=
1847 BT_COMPONENT_CLASS_TYPE_SOURCE
;
1850 cfg
->cmd_data
.help
.cfg_component
->type
=
1851 BT_COMPONENT_CLASS_TYPE_FILTER
;
1854 cfg
->cmd_data
.help
.cfg_component
->type
=
1855 BT_COMPONENT_CLASS_TYPE_SINK
;
1860 plug_comp_cls_names
= strdup(arg
);
1861 if (!plug_comp_cls_names
) {
1867 print_help_usage(stdout
);
1872 printf_err("Unknown command-line option specified (option code %d)\n",
1881 /* Check for option parsing error */
1883 printf_err("While parsing command-line options, at option %s: %s\n",
1884 poptBadOption(pc
, 0), poptStrerror(opt
));
1888 leftover
= poptGetArg(pc
);
1890 if (cfg
->cmd_data
.help
.cfg_component
->type
!=
1891 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
1892 printf_err("Cannot specify plugin name and --source/--filter/--sink component class:\n %s\n",
1897 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1900 if (cfg
->cmd_data
.help
.cfg_component
->type
==
1901 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
1902 print_help_usage(stdout
);
1908 plugin_comp_cls_names(plug_comp_cls_names
, NULL
,
1909 &plugin_name
, &comp_cls_name
);
1910 if (plugin_name
&& comp_cls_name
) {
1911 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1913 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
,
1916 printf_err("Invalid --source/--filter/--sink option's argument:\n %s\n",
1917 plug_comp_cls_names
);
1922 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
1933 free(plug_comp_cls_names
);
1934 g_free(plugin_name
);
1935 g_free(comp_cls_name
);
1938 poptFreeContext(pc
);
1946 * Prints the help command usage.
1949 void print_query_usage(FILE *fp
)
1951 fprintf(fp
, "Usage: babeltrace [GEN OPTS] query [OPTS] OBJECT --source=PLUGIN.CLS\n");
1952 fprintf(fp
, " babeltrace [GEN OPTS] query [OPTS] OBJECT --filter=PLUGIN.CLS\n");
1953 fprintf(fp
, " babeltrace [GEN OPTS] query [OPTS] OBJECT --sink=PLUGIN.CLS\n");
1955 fprintf(fp
, "Options:\n");
1957 fprintf(fp
, " -f. --filter=PLUGIN.CLS Query object from the filter component\n");
1958 fprintf(fp
, " class CLS found in the plugin PLUGIN\n");
1959 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1960 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1961 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1962 fprintf(fp
, " -p, --params=PARAMS Set the query parameters to PARAMS\n");
1963 fprintf(fp
, " (see the expected format of PARAMS below)\n");
1964 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1965 fprintf(fp
, " dynamic plugins can be loaded\n");
1966 fprintf(fp
, " -S, --sink=PLUGIN.CLS Query object from the sink component class\n");
1967 fprintf(fp
, " CLS found in the plugin PLUGIN\n");
1968 fprintf(fp
, " -s, --source=PLUGIN.CLS Query object from the source component\n");
1969 fprintf(fp
, " class CLS found in the plugin PLUGIN\n");
1970 fprintf(fp
, " -h --help Show this help and quit\n");
1971 fprintf(fp
, "\n\n");
1972 print_expected_params_format(fp
);
1976 struct poptOption query_long_options
[] = {
1977 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1978 { "filter", 'f', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
1979 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1980 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1981 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1982 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
1983 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1984 { "sink", 'S', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
1985 { "source", 's', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
1986 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1990 * Creates a Babeltrace config object from the arguments of a query
1993 * *retcode is set to the appropriate exit code to use.
1996 struct bt_config
*bt_config_query_from_args(int argc
, const char *argv
[],
1997 int *retcode
, bool force_omit_system_plugin_path
,
1998 bool force_omit_home_plugin_path
,
1999 struct bt_value
*initial_plugin_paths
)
2001 poptContext pc
= NULL
;
2005 struct bt_config
*cfg
= NULL
;
2006 const char *leftover
;
2007 struct bt_value
*params
= bt_value_null
;
2010 cfg
= bt_config_query_create(initial_plugin_paths
);
2015 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2016 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2017 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2023 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2024 query_long_options
, 0);
2026 printf_err("Cannot get popt context\n");
2030 poptReadDefaultConfig(pc
, 0);
2032 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2033 arg
= poptGetOptArg(pc
);
2036 case OPT_PLUGIN_PATH
:
2037 if (bt_config_append_plugin_paths_check_setuid_setgid(
2038 cfg
->plugin_paths
, arg
)) {
2042 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2043 cfg
->omit_system_plugin_path
= true;
2045 case OPT_OMIT_HOME_PLUGIN_PATH
:
2046 cfg
->omit_home_plugin_path
= true;
2052 enum bt_component_class_type type
;
2054 if (cfg
->cmd_data
.query
.cfg_component
) {
2055 printf_err("Cannot specify more than one plugin and component class:\n %s\n",
2062 type
= BT_COMPONENT_CLASS_TYPE_SOURCE
;
2065 type
= BT_COMPONENT_CLASS_TYPE_FILTER
;
2068 type
= BT_COMPONENT_CLASS_TYPE_SINK
;
2074 cfg
->cmd_data
.query
.cfg_component
=
2075 bt_config_component_from_arg(type
, arg
);
2076 if (!cfg
->cmd_data
.query
.cfg_component
) {
2077 printf_err("Invalid format for --source/--filter/--sink option's argument:\n %s\n",
2082 /* Default parameters: null */
2083 bt_put(cfg
->cmd_data
.query
.cfg_component
->params
);
2084 cfg
->cmd_data
.query
.cfg_component
->params
=
2090 params
= bt_value_from_arg(arg
);
2092 printf_err("Invalid format for --params option's argument:\n %s\n",
2099 print_query_usage(stdout
);
2104 printf_err("Unknown command-line option specified (option code %d)\n",
2113 if (!cfg
->cmd_data
.query
.cfg_component
) {
2114 printf_err("No target component class specified with --source/--filter/--sink option\n");
2119 BT_MOVE(cfg
->cmd_data
.query
.cfg_component
->params
, params
);
2121 /* Check for option parsing error */
2123 printf_err("While parsing command-line options, at option %s: %s\n",
2124 poptBadOption(pc
, 0), poptStrerror(opt
));
2129 * We need exactly one leftover argument which is the
2132 leftover
= poptGetArg(pc
);
2134 if (strlen(leftover
) == 0) {
2135 printf_err("Invalid empty object\n");
2139 g_string_assign(cfg
->cmd_data
.query
.object
, leftover
);
2141 print_query_usage(stdout
);
2147 leftover
= poptGetArg(pc
);
2149 printf_err("Unexpected argument: %s\n", leftover
);
2153 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2165 poptFreeContext(pc
);
2174 * Prints the list-plugins command usage.
2177 void print_list_plugins_usage(FILE *fp
)
2179 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
2181 fprintf(fp
, "Options:\n");
2183 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2184 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2185 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2186 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2187 fprintf(fp
, " dynamic plugins can be loaded\n");
2188 fprintf(fp
, " -h --help Show this help and quit\n");
2190 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2192 fprintf(fp
, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
2196 struct poptOption list_plugins_long_options
[] = {
2197 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2198 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2199 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2200 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2201 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2202 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2206 * Creates a Babeltrace config object from the arguments of a
2207 * list-plugins command.
2209 * *retcode is set to the appropriate exit code to use.
2212 struct bt_config
*bt_config_list_plugins_from_args(int argc
, const char *argv
[],
2213 int *retcode
, bool force_omit_system_plugin_path
,
2214 bool force_omit_home_plugin_path
,
2215 struct bt_value
*initial_plugin_paths
)
2217 poptContext pc
= NULL
;
2221 struct bt_config
*cfg
= NULL
;
2222 const char *leftover
;
2225 cfg
= bt_config_list_plugins_create(initial_plugin_paths
);
2230 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2231 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2232 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2238 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2239 list_plugins_long_options
, 0);
2241 printf_err("Cannot get popt context\n");
2245 poptReadDefaultConfig(pc
, 0);
2247 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2248 arg
= poptGetOptArg(pc
);
2251 case OPT_PLUGIN_PATH
:
2252 if (bt_config_append_plugin_paths_check_setuid_setgid(
2253 cfg
->plugin_paths
, arg
)) {
2257 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2258 cfg
->omit_system_plugin_path
= true;
2260 case OPT_OMIT_HOME_PLUGIN_PATH
:
2261 cfg
->omit_home_plugin_path
= true;
2264 print_list_plugins_usage(stdout
);
2269 printf_err("Unknown command-line option specified (option code %d)\n",
2278 /* Check for option parsing error */
2280 printf_err("While parsing command-line options, at option %s: %s\n",
2281 poptBadOption(pc
, 0), poptStrerror(opt
));
2285 leftover
= poptGetArg(pc
);
2287 printf_err("Unexpected argument: %s\n", leftover
);
2291 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2303 poptFreeContext(pc
);
2311 * Prints the run command usage.
2314 void print_run_usage(FILE *fp
)
2316 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] run [OPTIONS]\n");
2318 fprintf(fp
, "Options:\n");
2320 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
2321 fprintf(fp
, " for all the following components until\n");
2322 fprintf(fp
, " --reset-base-params is encountered\n");
2323 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2324 fprintf(fp
, " -c, --connect=CONNECTION Connect two created components (see the\n");
2325 fprintf(fp
, " expected format of CONNECTION below)\n");
2326 fprintf(fp
, " -f, --filter=[NAME:]PLUGIN.CLS Instantiate a filter component from plugin\n");
2327 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2328 fprintf(fp
, " the current component, and if NAME is\n");
2329 fprintf(fp
, " given, set its instance name to NAME\n");
2330 fprintf(fp
, " --key=KEY Set the current initialization string\n");
2331 fprintf(fp
, " parameter key to KEY (see --value)\n");
2332 fprintf(fp
, " -n, --name=NAME Set the name of the current component\n");
2333 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2334 fprintf(fp
, " names of the created components)\n");
2335 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2336 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2337 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2338 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2339 fprintf(fp
, " current component (see the expected format\n");
2340 fprintf(fp
, " of PARAMS below)\n");
2341 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2342 fprintf(fp
, " dynamic plugins can be loaded\n");
2343 fprintf(fp
, " -r, --reset-base-params Reset the current base parameters to an\n");
2344 fprintf(fp
, " empty map\n");
2345 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2346 fprintf(fp
, " the graph later, retry in DUR µs\n");
2347 fprintf(fp
, " (default: 100000)\n");
2348 fprintf(fp
, " -S, --sink=[NAME:]PLUGIN.CLS Instantiate a sink component from plugin\n");
2349 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2350 fprintf(fp
, " the current component, and if NAME is\n");
2351 fprintf(fp
, " given, set its instance name to NAME\n");
2352 fprintf(fp
, " -s, --source=[NAME:]PLUGIN.CLS Instantiate a source component from plugin\n");
2353 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2354 fprintf(fp
, " the current component, and if NAME is\n");
2355 fprintf(fp
, " given, set its instance name to NAME\n");
2356 fprintf(fp
, " --value=VAL Add a string initialization parameter to\n");
2357 fprintf(fp
, " the current component with a name given by\n");
2358 fprintf(fp
, " the last argument of the --key option and a\n");
2359 fprintf(fp
, " value set to VAL\n");
2360 fprintf(fp
, " -h --help Show this help and quit\n");
2362 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2363 fprintf(fp
, "\n\n");
2364 fprintf(fp
, "Expected format of CONNECTION\n");
2365 fprintf(fp
, "-----------------------------\n");
2367 fprintf(fp
, " UPSTREAM[.UPSTREAM-PORT]:DOWNSTREAM[.DOWNSTREAM-PORT]\n");
2369 fprintf(fp
, "UPSTREAM and DOWNSTREAM are names of the upstream and downstream\n");
2370 fprintf(fp
, "components to connect together. You must escape the following characters\n\n");
2371 fprintf(fp
, "with `\\`: `\\`, `.`, and `:`. You can set the name of the current\n");
2372 fprintf(fp
, "component with the --name option.\n");
2374 fprintf(fp
, "UPSTREAM-PORT and DOWNSTREAM-PORT are optional globbing patterns to\n");
2375 fprintf(fp
, "identify the upstream and downstream ports to use for the connection.\n");
2376 fprintf(fp
, "When the port is not specified, `*` is used.\n");
2378 fprintf(fp
, "When a component named UPSTREAM has an available port which matches the\n");
2379 fprintf(fp
, "UPSTREAM-PORT globbing pattern, it is connected to the first port which\n");
2380 fprintf(fp
, "matches the DOWNSTREAM-PORT globbing pattern of the component named\n");
2381 fprintf(fp
, "DOWNSTREAM.\n");
2383 fprintf(fp
, "The only special character in UPSTREAM-PORT and DOWNSTREAM-PORT is `*`\n");
2384 fprintf(fp
, "which matches anything. You must escape the following characters\n");
2385 fprintf(fp
, "with `\\`: `\\`, `*`, `?`, `[`, `.`, and `:`.\n");
2387 fprintf(fp
, "You can connect a source component to a filter or sink component. You\n");
2388 fprintf(fp
, "can connect a filter component to a sink component.\n");
2390 fprintf(fp
, "Examples:\n");
2392 fprintf(fp
, " my-src:my-sink\n");
2393 fprintf(fp
, " ctf-fs.*stream*:utils-muxer:*\n");
2395 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
2396 fprintf(fp
, "babeltrace from a shell.\n");
2397 fprintf(fp
, "\n\n");
2398 print_expected_params_format(fp
);
2402 * Creates a Babeltrace config object from the arguments of a run
2405 * *retcode is set to the appropriate exit code to use.
2408 struct bt_config
*bt_config_run_from_args(int argc
, const char *argv
[],
2409 int *retcode
, bool force_omit_system_plugin_path
,
2410 bool force_omit_home_plugin_path
,
2411 struct bt_value
*initial_plugin_paths
)
2413 poptContext pc
= NULL
;
2415 struct bt_config_component
*cur_cfg_comp
= NULL
;
2416 enum bt_config_component_dest cur_cfg_comp_dest
;
2417 struct bt_value
*cur_base_params
= NULL
;
2419 struct bt_config
*cfg
= NULL
;
2420 struct bt_value
*instance_names
= NULL
;
2421 struct bt_value
*connection_args
= NULL
;
2422 GString
*cur_param_key
= NULL
;
2423 char error_buf
[256] = { 0 };
2424 long long retry_duration
= -1;
2425 struct poptOption run_long_options
[] = {
2426 { "base-params", 'b', POPT_ARG_STRING
, NULL
, OPT_BASE_PARAMS
, NULL
, NULL
},
2427 { "connect", 'c', POPT_ARG_STRING
, NULL
, OPT_CONNECT
, NULL
, NULL
},
2428 { "filter", 'f', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
2429 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2430 { "key", '\0', POPT_ARG_STRING
, NULL
, OPT_KEY
, NULL
, NULL
},
2431 { "name", 'n', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2432 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2433 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2434 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2435 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2436 { "reset-base-params", 'r', POPT_ARG_NONE
, NULL
, OPT_RESET_BASE_PARAMS
, NULL
, NULL
},
2437 { "retry-duration", '\0', POPT_ARG_LONGLONG
, &retry_duration
, OPT_RETRY_DURATION
, NULL
, NULL
},
2438 { "sink", 'S', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
2439 { "source", 's', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
2440 { "value", '\0', POPT_ARG_STRING
, NULL
, OPT_VALUE
, NULL
, NULL
},
2441 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2445 cur_param_key
= g_string_new(NULL
);
2446 if (!cur_param_key
) {
2452 print_run_usage(stdout
);
2457 cfg
= bt_config_run_create(initial_plugin_paths
);
2462 cfg
->cmd_data
.run
.retry_duration_us
= 100000;
2463 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2464 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2465 cur_base_params
= bt_value_map_create();
2466 if (!cur_base_params
) {
2471 instance_names
= bt_value_map_create();
2472 if (!instance_names
) {
2477 connection_args
= bt_value_array_create();
2478 if (!connection_args
) {
2483 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2489 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2490 run_long_options
, 0);
2492 printf_err("Cannot get popt context\n");
2496 poptReadDefaultConfig(pc
, 0);
2498 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2499 arg
= poptGetOptArg(pc
);
2502 case OPT_PLUGIN_PATH
:
2503 if (bt_config_append_plugin_paths_check_setuid_setgid(
2504 cfg
->plugin_paths
, arg
)) {
2508 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2509 cfg
->omit_system_plugin_path
= true;
2511 case OPT_OMIT_HOME_PLUGIN_PATH
:
2512 cfg
->omit_home_plugin_path
= true;
2518 enum bt_component_class_type new_comp_type
;
2519 enum bt_config_component_dest new_dest
;
2520 const char *opt_name
;
2524 new_comp_type
= BT_COMPONENT_CLASS_TYPE_SOURCE
;
2525 new_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
2526 opt_name
= "--source";
2529 new_comp_type
= BT_COMPONENT_CLASS_TYPE_FILTER
;
2530 new_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
2531 opt_name
= "--filter";
2534 new_comp_type
= BT_COMPONENT_CLASS_TYPE_SINK
;
2535 new_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
2536 opt_name
= "--sink";
2543 ret
= add_run_cfg_comp_check_name(cfg
,
2544 cur_cfg_comp
, cur_cfg_comp_dest
,
2546 BT_PUT(cur_cfg_comp
);
2552 cur_cfg_comp
= bt_config_component_from_arg(
2553 new_comp_type
, arg
);
2554 if (!cur_cfg_comp
) {
2555 printf_err("Invalid format for %s option's argument:\n %s\n",
2560 assert(cur_base_params
);
2561 bt_put(cur_cfg_comp
->params
);
2562 cur_cfg_comp
->params
= bt_value_copy(cur_base_params
);
2563 if (!cur_cfg_comp
->params
) {
2568 cur_cfg_comp_dest
= new_dest
;
2573 struct bt_value
*params
;
2574 struct bt_value
*params_to_set
;
2576 if (!cur_cfg_comp
) {
2577 printf_err("Cannot add parameters to unavailable component:\n %s\n",
2582 params
= bt_value_from_arg(arg
);
2584 printf_err("Invalid format for --params option's argument:\n %s\n",
2589 params_to_set
= bt_value_map_extend(cur_cfg_comp
->params
,
2592 if (!params_to_set
) {
2593 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
2598 BT_MOVE(cur_cfg_comp
->params
, params_to_set
);
2602 if (strlen(arg
) == 0) {
2603 printf_err("Cannot set an empty string as the current parameter key\n");
2607 g_string_assign(cur_param_key
, arg
);
2610 if (!cur_cfg_comp
) {
2611 printf_err("Cannot set a parameter's value of unavailable component:\n %s\n",
2616 if (cur_param_key
->len
== 0) {
2617 printf_err("--value option specified without preceding --key option:\n %s\n",
2622 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
2623 cur_param_key
->str
, arg
)) {
2629 if (!cur_cfg_comp
) {
2630 printf_err("Cannot set the name of unavailable component:\n %s\n",
2635 g_string_assign(cur_cfg_comp
->instance_name
, arg
);
2637 case OPT_BASE_PARAMS
:
2639 struct bt_value
*params
= bt_value_from_arg(arg
);
2642 printf_err("Invalid format for --base-params option's argument:\n %s\n",
2647 BT_MOVE(cur_base_params
, params
);
2650 case OPT_RESET_BASE_PARAMS
:
2651 BT_PUT(cur_base_params
);
2652 cur_base_params
= bt_value_map_create();
2653 if (!cur_base_params
) {
2659 if (bt_value_array_append_string(connection_args
,
2665 case OPT_RETRY_DURATION
:
2666 if (retry_duration
< 0) {
2667 printf_err("--retry-duration option's argument must be positive or 0: %lld\n",
2672 cfg
->cmd_data
.run
.retry_duration_us
=
2673 (uint64_t) retry_duration
;
2676 print_run_usage(stdout
);
2681 printf_err("Unknown command-line option specified (option code %d)\n",
2690 /* Check for option parsing error */
2692 printf_err("While parsing command-line options, at option %s: %s\n",
2693 poptBadOption(pc
, 0), poptStrerror(opt
));
2697 /* This command does not accept leftover arguments */
2698 if (poptPeekArg(pc
)) {
2699 printf_err("Unexpected argument: %s\n", poptPeekArg(pc
));
2703 /* Add current component */
2705 ret
= add_run_cfg_comp_check_name(cfg
, cur_cfg_comp
,
2706 cur_cfg_comp_dest
, instance_names
);
2707 BT_PUT(cur_cfg_comp
);
2713 if (cfg
->cmd_data
.run
.sources
->len
== 0) {
2714 printf_err("Incomplete graph: no source component\n");
2718 if (cfg
->cmd_data
.run
.sinks
->len
== 0) {
2719 printf_err("Incomplete graph: no sink component\n");
2723 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2727 ret
= bt_config_cli_args_create_connections(cfg
, connection_args
,
2730 printf_err("Cannot creation connections:\n%s", error_buf
);
2742 poptFreeContext(pc
);
2745 if (cur_param_key
) {
2746 g_string_free(cur_param_key
, TRUE
);
2750 BT_PUT(cur_cfg_comp
);
2751 BT_PUT(cur_base_params
);
2752 BT_PUT(instance_names
);
2753 BT_PUT(connection_args
);
2758 struct bt_config
*bt_config_run_from_args_array(struct bt_value
*run_args
,
2759 int *retcode
, bool force_omit_system_plugin_path
,
2760 bool force_omit_home_plugin_path
,
2761 struct bt_value
*initial_plugin_paths
)
2763 struct bt_config
*cfg
= NULL
;
2766 const size_t argc
= bt_value_array_size(run_args
) + 1;
2768 argv
= calloc(argc
, sizeof(*argv
));
2776 for (i
= 0; i
< bt_value_array_size(run_args
); i
++) {
2778 struct bt_value
*arg_value
= bt_value_array_get(run_args
, i
);
2782 ret
= bt_value_string_get(arg_value
, &arg
);
2789 cfg
= bt_config_run_from_args(argc
, argv
, retcode
,
2790 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
2791 initial_plugin_paths
);
2799 * Prints the convert command usage.
2802 void print_convert_usage(FILE *fp
)
2804 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [convert] [OPTIONS] [PATH/URL]\n");
2806 fprintf(fp
, "Options:\n");
2808 fprintf(fp
, " --filter=[NAME:]PLUGIN.CLS Instantiate a filter component from plugin\n");
2809 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2810 fprintf(fp
, " the current component, and if NAME is\n");
2811 fprintf(fp
, " given, set its instance name to NAME\n");
2812 fprintf(fp
, " --name=NAME Set the name of the current component\n");
2813 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2814 fprintf(fp
, " names of the created components)\n");
2815 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2816 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2817 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2818 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2819 fprintf(fp
, " current component (see the expected format\n");
2820 fprintf(fp
, " of PARAMS below)\n");
2821 fprintf(fp
, " -P, --path=PATH Set the `path` string parameter of the\n");
2822 fprintf(fp
, " current component to PATH\n");
2823 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2824 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2825 fprintf(fp
, " the graph later, retry in DUR µs\n");
2826 fprintf(fp
, " (default: 100000)\n");
2827 fprintf(fp
, " dynamic plugins can be loaded\n");
2828 fprintf(fp
, " --run-args Print the equivalent arguments for the\n");
2829 fprintf(fp
, " `run` command to the standard output,\n");
2830 fprintf(fp
, " formatted for a shell, and quit\n");
2831 fprintf(fp
, " --run-args-0 Print the equivalent arguments for the\n");
2832 fprintf(fp
, " `run` command to the standard output,\n");
2833 fprintf(fp
, " formatted for `xargs -0`, and quit\n");
2834 fprintf(fp
, " --sink=[NAME:]PLUGIN.CLS Instantiate a sink component from plugin\n");
2835 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2836 fprintf(fp
, " the current component, and if NAME is\n");
2837 fprintf(fp
, " given, set its instance name to NAME\n");
2838 fprintf(fp
, " --source=[NAME:]PLUGIN.CLS Instantiate a source component from plugin\n");
2839 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2840 fprintf(fp
, " the current component, and if NAME is\n");
2841 fprintf(fp
, " given, set its instance name to NAME\n");
2842 fprintf(fp
, " -u, --url=URL Set the `url` string parameter of the\n");
2843 fprintf(fp
, " current component to URL\n");
2844 fprintf(fp
, " -h --help Show this help and quit\n");
2846 fprintf(fp
, "Implicit `ctf.fs` source component options:\n");
2848 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
2849 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS ns\n");
2850 fprintf(fp
, " --stream-intersection Only process events when all streams\n");
2851 fprintf(fp
, " are active\n");
2853 fprintf(fp
, "Implicit `text.text` sink component options:\n");
2855 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
2856 fprintf(fp
, " --clock-date Print timestamp dates\n");
2857 fprintf(fp
, " --clock-gmt Print and parse timestamps in the GMT\n");
2858 fprintf(fp
, " time zone instead of the local time zone\n");
2859 fprintf(fp
, " --clock-seconds Print the timestamps as `SEC.NS` instead\n");
2860 fprintf(fp
, " of `hh:mm:ss.nnnnnnnnn`\n");
2861 fprintf(fp
, " --color=(never | auto | always)\n");
2862 fprintf(fp
, " Never, automatically, or always emit\n");
2863 fprintf(fp
, " console color codes\n");
2864 fprintf(fp
, " -f, --fields=FIELD[,FIELD]... Print additional fields; FIELD can be:\n");
2865 fprintf(fp
, " `all`, `trace`, `trace:hostname`,\n");
2866 fprintf(fp
, " `trace:domain`, `trace:procname`,\n");
2867 fprintf(fp
, " `trace:vpid`, `loglevel`, `emf`\n");
2868 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names; NAME can be:\n");
2869 fprintf(fp
, " `payload` (or `arg` or `args`), `none`,\n");
2870 fprintf(fp
, " `all`, `scope`, `header`, `context`\n");
2871 fprintf(fp
, " (or `ctx`)\n");
2872 fprintf(fp
, " --no-delta Do not print time delta between\n");
2873 fprintf(fp
, " consecutive events\n");
2874 fprintf(fp
, " -w, --output=PATH Write output text to PATH instead of\n");
2875 fprintf(fp
, " the standard output\n");
2877 fprintf(fp
, "Implicit `utils.muxer` filter component options:\n");
2879 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently\n");
2880 fprintf(fp
, " correlated across traces\n");
2882 fprintf(fp
, "Implicit `utils.trimmer` filter component options:\n");
2884 fprintf(fp
, " -b, --begin=BEGIN Set the beginning time of the conversion\n");
2885 fprintf(fp
, " time range to BEGIN (see the format of\n");
2886 fprintf(fp
, " BEGIN below)\n");
2887 fprintf(fp
, " -e, --end=END Set the end time of the conversion time\n");
2888 fprintf(fp
, " range to END (see the format of END below)\n");
2889 fprintf(fp
, " -t, --timerange=TIMERANGE Set conversion time range to TIMERANGE:\n");
2890 fprintf(fp
, " BEGIN,END or [BEGIN,END] (literally `[` and\n");
2891 fprintf(fp
, " `]`) (see the format of BEGIN/END below)\n");
2893 fprintf(fp
, "Implicit `lttng-utils.debug-info` filter component options:\n");
2895 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
2896 fprintf(fp
, " instead of `/usr/lib/debug`\n");
2897 fprintf(fp
, " --debug-info-full-path Show full debug info source and\n");
2898 fprintf(fp
, " binary paths instead of just names\n");
2899 fprintf(fp
, " --debug-info-target-prefix=DIR\n");
2900 fprintf(fp
, " Use directory DIR as a prefix when\n");
2901 fprintf(fp
, " looking up executables during debug\n");
2902 fprintf(fp
, " info analysis\n");
2903 fprintf(fp
, " --no-debug-info Do not create an implicit\n");
2904 fprintf(fp
, " `lttng-utils.debug-info` filter component\n");
2906 fprintf(fp
, "Legacy options that still work:\n");
2908 fprintf(fp
, " -i, --input-format=(ctf | lttng-live)\n");
2909 fprintf(fp
, " `ctf`:\n");
2910 fprintf(fp
, " Create an implicit `ctf.fs` source\n");
2911 fprintf(fp
, " component\n");
2912 fprintf(fp
, " `lttng-live`:\n");
2913 fprintf(fp
, " Create an implicit `ctf.lttng-live`\n");
2914 fprintf(fp
, " source component\n");
2915 fprintf(fp
, " -o, --output-format=(text | dummy | ctf-metadata)\n");
2916 fprintf(fp
, " `text`:\n");
2917 fprintf(fp
, " Create an implicit `text.text` sink\n");
2918 fprintf(fp
, " component\n");
2919 fprintf(fp
, " `dummy`:\n");
2920 fprintf(fp
, " Create an implicit `utils.dummy` sink\n");
2921 fprintf(fp
, " component\n");
2922 fprintf(fp
, " `ctf-metadata`:\n");
2923 fprintf(fp
, " Query the `ctf.fs` component class for\n");
2924 fprintf(fp
, " metadata text and quit\n");
2926 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2927 fprintf(fp
, "\n\n");
2928 fprintf(fp
, "Format of BEGIN and END\n");
2929 fprintf(fp
, "-----------------------\n");
2931 fprintf(fp
, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
2932 fprintf(fp
, "\n\n");
2933 print_expected_params_format(fp
);
2937 struct poptOption convert_long_options
[] = {
2938 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2939 { "begin", 'b', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2940 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2941 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2942 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2943 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2944 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2945 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2946 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2947 { "color", '\0', POPT_ARG_STRING
, NULL
, OPT_COLOR
, NULL
, NULL
},
2948 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2949 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2950 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2951 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2952 { "end", 'e', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2953 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2954 { "filter", '\0', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
2955 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2956 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2957 { "name", '\0', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2958 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2959 { "no-debug-info", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DEBUG_INFO
, NULL
, NULL
},
2960 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2961 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2962 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2963 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT
, NULL
, NULL
},
2964 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2965 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2966 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2967 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2968 { "retry-duration", '\0', POPT_ARG_STRING
, NULL
, OPT_RETRY_DURATION
, NULL
, NULL
},
2969 { "run-args", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS
, NULL
, NULL
},
2970 { "run-args-0", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS_0
, NULL
, NULL
},
2971 { "sink", '\0', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
2972 { "source", '\0', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
2973 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2974 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2975 { "url", 'u', POPT_ARG_STRING
, NULL
, OPT_URL
, NULL
, NULL
},
2976 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2977 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2981 GString
*get_component_auto_name(const char *prefix
,
2982 struct bt_value
*existing_names
)
2985 GString
*auto_name
= g_string_new(NULL
);
2992 if (!bt_value_map_has_key(existing_names
, prefix
)) {
2993 g_string_assign(auto_name
, prefix
);
2998 g_string_printf(auto_name
, "%s-%d", prefix
, i
);
3000 } while (bt_value_map_has_key(existing_names
, auto_name
->str
));
3006 struct implicit_component_args
{
3008 GString
*plugin_comp_cls_arg
;
3010 GString
*params_arg
;
3011 struct bt_value
*extra_args
;
3015 int assign_name_to_implicit_component(struct implicit_component_args
*args
,
3016 const char *prefix
, struct bt_value
*existing_names
,
3017 GList
**comp_names
, bool append_to_comp_names
)
3020 GString
*name
= NULL
;
3022 if (!args
->exists
) {
3026 name
= get_component_auto_name(prefix
, existing_names
);
3033 g_string_assign(args
->name_arg
, name
->str
);
3035 if (bt_value_map_insert(existing_names
, name
->str
,
3042 if (append_to_comp_names
) {
3043 *comp_names
= g_list_append(*comp_names
, name
);
3049 g_string_free(name
, TRUE
);
3056 int append_run_args_for_implicit_component(
3057 enum bt_component_class_type type
,
3058 struct implicit_component_args
*impl_args
,
3059 struct bt_value
*run_args
)
3064 if (!impl_args
->exists
) {
3069 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
3070 if (bt_value_array_append_string(run_args
, "--source")) {
3075 case BT_COMPONENT_CLASS_TYPE_FILTER
:
3076 if (bt_value_array_append_string(run_args
, "--filter")) {
3081 case BT_COMPONENT_CLASS_TYPE_SINK
:
3082 if (bt_value_array_append_string(run_args
, "--sink")) {
3091 if (bt_value_array_append_string(run_args
,
3092 impl_args
->plugin_comp_cls_arg
->str
)) {
3097 if (bt_value_array_append_string(run_args
, "--name")) {
3102 if (bt_value_array_append_string(run_args
, impl_args
->name_arg
->str
)) {
3107 if (impl_args
->params_arg
->len
> 0) {
3108 if (bt_value_array_append_string(run_args
, "--params")) {
3113 if (bt_value_array_append_string(run_args
,
3114 impl_args
->params_arg
->str
)) {
3120 for (i
= 0; i
< bt_value_array_size(impl_args
->extra_args
); i
++) {
3121 struct bt_value
*elem
;
3124 elem
= bt_value_array_get(impl_args
->extra_args
, i
);
3129 assert(bt_value_is_string(elem
));
3130 if (bt_value_string_get(elem
, &arg
)) {
3134 ret
= bt_value_array_append_string(run_args
, arg
);
3152 void destroy_implicit_component_args(struct implicit_component_args
*args
)
3156 if (args
->plugin_comp_cls_arg
) {
3157 g_string_free(args
->plugin_comp_cls_arg
, TRUE
);
3160 if (args
->name_arg
) {
3161 g_string_free(args
->name_arg
, TRUE
);
3164 if (args
->params_arg
) {
3165 g_string_free(args
->params_arg
, TRUE
);
3168 bt_put(args
->extra_args
);
3172 int init_implicit_component_args(struct implicit_component_args
*args
,
3173 const char *plugin_comp_cls_arg
, bool exists
)
3177 args
->exists
= exists
;
3178 args
->plugin_comp_cls_arg
= g_string_new(plugin_comp_cls_arg
);
3179 args
->name_arg
= g_string_new(NULL
);
3180 args
->params_arg
= g_string_new(NULL
);
3181 args
->extra_args
= bt_value_array_create();
3183 if (!args
->plugin_comp_cls_arg
|| !args
->name_arg
||
3184 !args
->params_arg
|| !args
->extra_args
) {
3186 destroy_implicit_component_args(args
);
3196 void append_implicit_component_param(struct implicit_component_args
*args
,
3197 const char *key
, const char *value
)
3202 append_param_arg(args
->params_arg
, key
, value
);
3206 int append_implicit_component_extra_arg(struct implicit_component_args
*args
,
3207 const char *key
, const char *value
)
3215 if (bt_value_array_append_string(args
->extra_args
, "--key")) {
3221 if (bt_value_array_append_string(args
->extra_args
, key
)) {
3227 if (bt_value_array_append_string(args
->extra_args
, "--value")) {
3233 if (bt_value_array_append_string(args
->extra_args
, value
)) {
3244 int convert_append_name_param(enum bt_config_component_dest dest
,
3245 GString
*cur_name
, GString
*cur_name_prefix
,
3246 struct bt_value
*run_args
, struct bt_value
*all_names
,
3247 GList
**source_names
, GList
**filter_names
,
3252 if (cur_name_prefix
->len
> 0) {
3253 /* We're after a --source/--filter/--sink */
3254 GString
*name
= NULL
;
3255 bool append_name_opt
= false;
3257 if (cur_name
->len
== 0) {
3259 * No explicit name was provided for the user
3262 name
= get_component_auto_name(
3263 cur_name_prefix
->str
,
3265 append_name_opt
= true;
3268 * An explicit name was provided for the user
3271 if (bt_value_map_has_key(all_names
,
3273 printf_err("Duplicate component instance name:\n %s\n",
3278 name
= g_string_new(cur_name
->str
);
3287 * Remember this name globally, for the uniqueness of
3288 * all component names.
3290 if (bt_value_map_insert(all_names
, name
->str
, bt_value_null
)) {
3296 * Append the --name option if necessary.
3298 if (append_name_opt
) {
3299 if (bt_value_array_append_string(run_args
, "--name")) {
3304 if (bt_value_array_append_string(run_args
, name
->str
)) {
3311 * Remember this name specifically for the type of the
3312 * component. This is to create connection arguments.
3315 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
3316 *source_names
= g_list_append(*source_names
, name
);
3318 case BT_CONFIG_COMPONENT_DEST_FILTER
:
3319 *filter_names
= g_list_append(*filter_names
, name
);
3321 case BT_CONFIG_COMPONENT_DEST_SINK
:
3322 *sink_names
= g_list_append(*sink_names
, name
);
3328 g_string_assign(cur_name_prefix
, "");
3341 * Escapes `.`, `:`, and `\` of `input` with `\`.
3344 GString
*escape_dot_colon(const char *input
)
3346 GString
*output
= g_string_new(NULL
);
3354 for (ch
= input
; *ch
!= '\0'; ch
++) {
3355 if (*ch
== '\\' || *ch
== '.' || *ch
== ':') {
3356 g_string_append_c(output
, '\\');
3359 g_string_append_c(output
, *ch
);
3367 * Appends a --connect option to a list of arguments. `upstream_name`
3368 * and `downstream_name` are escaped with escape_dot_colon() in this
3372 int append_connect_arg(struct bt_value
*run_args
,
3373 const char *upstream_name
, const char *downstream_name
)
3376 GString
*e_upstream_name
= escape_dot_colon(upstream_name
);
3377 GString
*e_downstream_name
= escape_dot_colon(downstream_name
);
3378 GString
*arg
= g_string_new(NULL
);
3380 if (!e_upstream_name
|| !e_downstream_name
|| !arg
) {
3386 ret
= bt_value_array_append_string(run_args
, "--connect");
3393 g_string_append(arg
, e_upstream_name
->str
);
3394 g_string_append_c(arg
, ':');
3395 g_string_append(arg
, e_downstream_name
->str
);
3396 ret
= bt_value_array_append_string(run_args
, arg
->str
);
3405 g_string_free(arg
, TRUE
);
3408 if (e_upstream_name
) {
3409 g_string_free(e_upstream_name
, TRUE
);
3412 if (e_downstream_name
) {
3413 g_string_free(e_downstream_name
, TRUE
);
3420 * Appends the run command's --connect options for the convert command.
3423 int convert_auto_connect(struct bt_value
*run_args
,
3424 GList
*source_names
, GList
*filter_names
,
3428 GList
*source_at
= source_names
;
3429 GList
*filter_at
= filter_names
;
3431 GList
*sink_at
= sink_names
;
3433 assert(source_names
);
3434 assert(filter_names
);
3437 /* Connect all sources to the first filter */
3438 for (source_at
= source_names
; source_at
!= NULL
; source_at
= g_list_next(source_at
)) {
3439 GString
*source_name
= source_at
->data
;
3440 GString
*filter_name
= filter_at
->data
;
3442 ret
= append_connect_arg(run_args
, source_name
->str
,
3449 filter_prev
= filter_at
;
3450 filter_at
= g_list_next(filter_at
);
3452 /* Connect remaining filters */
3453 for (; filter_at
!= NULL
; filter_prev
= filter_at
, filter_at
= g_list_next(filter_at
)) {
3454 GString
*filter_name
= filter_at
->data
;
3455 GString
*filter_prev_name
= filter_prev
->data
;
3457 ret
= append_connect_arg(run_args
, filter_prev_name
->str
,
3464 /* Connect last filter to all sinks */
3465 for (sink_at
= sink_names
; sink_at
!= NULL
; sink_at
= g_list_next(sink_at
)) {
3466 GString
*filter_name
= filter_prev
->data
;
3467 GString
*sink_name
= sink_at
->data
;
3469 ret
= append_connect_arg(run_args
, filter_name
->str
,
3486 int split_timerange(const char *arg
, char **begin
, char **end
)
3489 const char *ch
= arg
;
3491 GString
*g_begin
= NULL
;
3492 GString
*g_end
= NULL
;
3500 g_begin
= bt_common_string_until(ch
, "", ",", &end_pos
);
3501 if (!g_begin
|| ch
[end_pos
] != ',' || g_begin
->len
== 0) {
3507 g_end
= bt_common_string_until(ch
, "", "]", &end_pos
);
3508 if (!g_end
|| g_end
->len
== 0) {
3514 *begin
= g_begin
->str
;
3516 g_string_free(g_begin
, FALSE
);
3517 g_string_free(g_end
, FALSE
);
3527 g_string_free(g_begin
, TRUE
);
3531 g_string_free(g_end
, TRUE
);
3538 int g_list_prepend_gstring(GList
**list
, const char *string
)
3541 GString
*gs
= g_string_new(string
);
3550 *list
= g_list_prepend(*list
, gs
);
3557 * Creates a Babeltrace config object from the arguments of a convert
3560 * *retcode is set to the appropriate exit code to use.
3563 struct bt_config
*bt_config_convert_from_args(int argc
, const char *argv
[],
3564 int *retcode
, bool force_omit_system_plugin_path
,
3565 bool force_omit_home_plugin_path
, bool force_no_debug_info
,
3566 struct bt_value
*initial_plugin_paths
)
3568 poptContext pc
= NULL
;
3570 enum bt_config_component_dest cur_comp_dest
;
3572 struct bt_config
*cfg
= NULL
;
3573 bool got_verbose_opt
= false;
3574 bool got_debug_opt
= false;
3575 bool got_input_format_opt
= false;
3576 bool got_output_format_opt
= false;
3577 bool trimmer_has_begin
= false;
3578 bool trimmer_has_end
= false;
3579 GString
*cur_name
= NULL
;
3580 GString
*cur_name_prefix
= NULL
;
3581 const char *leftover
= NULL
;
3582 bool print_run_args
= false;
3583 bool print_run_args_0
= false;
3584 bool print_ctf_metadata
= false;
3585 struct bt_value
*run_args
= NULL
;
3586 struct bt_value
*all_names
= NULL
;
3587 GList
*source_names
= NULL
;
3588 GList
*filter_names
= NULL
;
3589 GList
*sink_names
= NULL
;
3590 struct implicit_component_args implicit_ctf_args
= { 0 };
3591 struct implicit_component_args implicit_lttng_live_args
= { 0 };
3592 struct implicit_component_args implicit_dummy_args
= { 0 };
3593 struct implicit_component_args implicit_text_args
= { 0 };
3594 struct implicit_component_args implicit_debug_info_args
= { 0 };
3595 struct implicit_component_args implicit_muxer_args
= { 0 };
3596 struct implicit_component_args implicit_trimmer_args
= { 0 };
3597 struct bt_value
*plugin_paths
= bt_get(initial_plugin_paths
);
3598 char error_buf
[256] = { 0 };
3600 struct bt_common_lttng_live_url_parts lttng_live_url_parts
= { 0 };
3605 print_convert_usage(stdout
);
3610 if (init_implicit_component_args(&implicit_ctf_args
, "ctf.fs", false)) {
3614 if (init_implicit_component_args(&implicit_lttng_live_args
,
3615 "ctf.lttng-live", false)) {
3619 if (init_implicit_component_args(&implicit_text_args
, "text.pretty",
3624 if (init_implicit_component_args(&implicit_dummy_args
, "utils.dummy",
3629 if (init_implicit_component_args(&implicit_debug_info_args
,
3630 "lttng-utils.debug-info", !force_no_debug_info
)) {
3634 if (init_implicit_component_args(&implicit_muxer_args
, "utils.muxer",
3639 if (init_implicit_component_args(&implicit_trimmer_args
,
3640 "utils.trimmer", false)) {
3644 all_names
= bt_value_map_create();
3650 run_args
= bt_value_array_create();
3656 cur_name
= g_string_new(NULL
);
3662 cur_name_prefix
= g_string_new(NULL
);
3663 if (!cur_name_prefix
) {
3668 ret
= append_env_var_plugin_paths(plugin_paths
);
3674 * First pass: collect all arguments which need to be passed
3675 * as is to the run command. This pass can also add --name
3676 * arguments if needed to automatically name unnamed component
3677 * instances. Also it does the following transformations:
3679 * --path=PATH -> --key path --value PATH
3680 * --url=URL -> --key url --value URL
3682 * Also it appends the plugin paths of --plugin-path to
3685 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3686 convert_long_options
, 0);
3688 printf_err("Cannot get popt context\n");
3692 poptReadDefaultConfig(pc
, 0);
3694 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3696 char *plugin_name
= NULL
;
3697 char *comp_cls_name
= NULL
;
3699 arg
= poptGetOptArg(pc
);
3705 /* Append current component's name if needed */
3706 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3707 cur_name_prefix
, run_args
, all_names
,
3708 &source_names
, &filter_names
, &sink_names
);
3713 /* Parse the argument */
3714 plugin_comp_cls_names(arg
, &name
, &plugin_name
,
3716 if (!plugin_name
|| !comp_cls_name
) {
3717 printf_err("Invalid format for --source/--filter/--sink option's argument:\n %s\n",
3723 g_string_assign(cur_name
, name
);
3725 g_string_assign(cur_name
, "");
3731 BT_CONFIG_COMPONENT_DEST_SOURCE
;
3732 if (bt_value_array_append_string(run_args
,
3740 BT_CONFIG_COMPONENT_DEST_FILTER
;
3741 if (bt_value_array_append_string(run_args
,
3749 BT_CONFIG_COMPONENT_DEST_SINK
;
3750 if (bt_value_array_append_string(run_args
,
3760 if (bt_value_array_append_string(run_args
, arg
)) {
3765 g_string_assign(cur_name_prefix
, "");
3766 g_string_append(cur_name_prefix
, plugin_name
);
3767 g_string_append_c(cur_name_prefix
, '.');
3768 g_string_append(cur_name_prefix
, comp_cls_name
);
3771 free(comp_cls_name
);
3774 comp_cls_name
= NULL
;
3777 if (cur_name_prefix
->len
== 0) {
3778 printf_err("No current component of which to set parameters:\n %s\n",
3783 if (bt_value_array_append_string(run_args
,
3789 if (bt_value_array_append_string(run_args
, arg
)) {
3795 if (cur_name_prefix
->len
== 0) {
3796 printf_err("No current component of which to set `path` parameter:\n %s\n",
3801 if (bt_value_array_append_string(run_args
, "--key")) {
3806 if (bt_value_array_append_string(run_args
, "path")) {
3811 if (bt_value_array_append_string(run_args
, "--value")) {
3816 if (bt_value_array_append_string(run_args
, arg
)) {
3822 if (cur_name_prefix
->len
== 0) {
3823 printf_err("No current component of which to set `url` parameter:\n %s\n",
3828 if (bt_value_array_append_string(run_args
, "--key")) {
3833 if (bt_value_array_append_string(run_args
, "url")) {
3838 if (bt_value_array_append_string(run_args
, "--value")) {
3843 if (bt_value_array_append_string(run_args
, arg
)) {
3849 if (cur_name_prefix
->len
== 0) {
3850 printf_err("No current component to name:\n %s\n",
3855 if (bt_value_array_append_string(run_args
, "--name")) {
3860 if (bt_value_array_append_string(run_args
, arg
)) {
3865 g_string_assign(cur_name
, arg
);
3867 case OPT_OMIT_HOME_PLUGIN_PATH
:
3868 force_omit_home_plugin_path
= true;
3870 if (bt_value_array_append_string(run_args
,
3871 "--omit-home-plugin-path")) {
3876 case OPT_RETRY_DURATION
:
3877 if (bt_value_array_append_string(run_args
,
3878 "--retry-duration")) {
3883 if (bt_value_array_append_string(run_args
, arg
)) {
3888 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
3889 force_omit_system_plugin_path
= true;
3891 if (bt_value_array_append_string(run_args
,
3892 "--omit-system-plugin-path")) {
3897 case OPT_PLUGIN_PATH
:
3898 if (bt_config_append_plugin_paths_check_setuid_setgid(
3899 plugin_paths
, arg
)) {
3903 if (bt_value_array_append_string(run_args
,
3909 if (bt_value_array_append_string(run_args
, arg
)) {
3915 print_convert_usage(stdout
);
3920 case OPT_CLOCK_CYCLES
:
3921 case OPT_CLOCK_DATE
:
3922 case OPT_CLOCK_FORCE_CORRELATE
:
3924 case OPT_CLOCK_OFFSET
:
3925 case OPT_CLOCK_OFFSET_NS
:
3926 case OPT_CLOCK_SECONDS
:
3929 case OPT_DEBUG_INFO_DIR
:
3930 case OPT_DEBUG_INFO_FULL_PATH
:
3931 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3934 case OPT_INPUT_FORMAT
:
3936 case OPT_NO_DEBUG_INFO
:
3938 case OPT_OUTPUT_FORMAT
:
3941 case OPT_RUN_ARGS_0
:
3942 case OPT_STREAM_INTERSECTION
:
3945 /* Ignore in this pass */
3948 printf_err("Unknown command-line option specified (option code %d)\n",
3957 /* Append current component's name if needed */
3958 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3959 cur_name_prefix
, run_args
, all_names
, &source_names
,
3960 &filter_names
, &sink_names
);
3965 /* Check for option parsing error */
3967 printf_err("While parsing command-line options, at option %s: %s\n",
3968 poptBadOption(pc
, 0), poptStrerror(opt
));
3972 poptFreeContext(pc
);
3977 * Second pass: transform the convert-specific options and
3978 * arguments into implicit component instances for the run
3981 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3982 convert_long_options
, 0);
3984 printf_err("Cannot get popt context\n");
3988 poptReadDefaultConfig(pc
, 0);
3990 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3991 arg
= poptGetOptArg(pc
);
3995 if (trimmer_has_begin
) {
3996 printf("At --begin option: --begin or --timerange option already specified\n %s\n",
4001 trimmer_has_begin
= true;
4002 ret
= append_implicit_component_extra_arg(
4003 &implicit_trimmer_args
, "begin", arg
);
4004 implicit_trimmer_args
.exists
= true;
4010 if (trimmer_has_end
) {
4011 printf("At --end option: --end or --timerange option already specified\n %s\n",
4016 trimmer_has_end
= true;
4017 ret
= append_implicit_component_extra_arg(
4018 &implicit_trimmer_args
, "end", arg
);
4019 implicit_trimmer_args
.exists
= true;
4029 if (trimmer_has_begin
|| trimmer_has_end
) {
4030 printf("At --timerange option: --begin, --end, or --timerange option already specified\n %s\n",
4035 ret
= split_timerange(arg
, &begin
, &end
);
4037 printf_err("Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:\n %s\n",
4042 ret
= append_implicit_component_extra_arg(
4043 &implicit_trimmer_args
, "begin", begin
);
4044 ret
|= append_implicit_component_extra_arg(
4045 &implicit_trimmer_args
, "end", end
);
4046 implicit_trimmer_args
.exists
= true;
4054 case OPT_CLOCK_CYCLES
:
4055 append_implicit_component_param(
4056 &implicit_text_args
, "clock-cycles", "yes");
4057 implicit_text_args
.exists
= true;
4059 case OPT_CLOCK_DATE
:
4060 append_implicit_component_param(
4061 &implicit_text_args
, "clock-date", "yes");
4062 implicit_text_args
.exists
= true;
4064 case OPT_CLOCK_FORCE_CORRELATE
:
4065 append_implicit_component_param(
4066 &implicit_muxer_args
, "ignore-absolute", "yes");
4069 append_implicit_component_param(
4070 &implicit_text_args
, "clock-gmt", "yes");
4071 implicit_text_args
.exists
= true;
4073 case OPT_CLOCK_OFFSET
:
4074 ret
= append_implicit_component_extra_arg(
4075 &implicit_ctf_args
, "clock-offset-cycles", arg
);
4076 implicit_ctf_args
.exists
= true;
4081 case OPT_CLOCK_OFFSET_NS
:
4082 ret
= append_implicit_component_extra_arg(
4083 &implicit_ctf_args
, "clock-offset-ns", arg
);
4084 implicit_ctf_args
.exists
= true;
4089 case OPT_CLOCK_SECONDS
:
4090 append_implicit_component_param(
4091 &implicit_text_args
, "clock-seconds", "yes");
4092 implicit_text_args
.exists
= true;
4095 ret
= append_implicit_component_extra_arg(
4096 &implicit_text_args
, "color", arg
);
4097 implicit_text_args
.exists
= true;
4102 case OPT_NO_DEBUG_INFO
:
4103 implicit_debug_info_args
.exists
= false;
4105 case OPT_DEBUG_INFO_DIR
:
4106 ret
= append_implicit_component_extra_arg(
4107 &implicit_debug_info_args
, "dir", arg
);
4112 case OPT_DEBUG_INFO_FULL_PATH
:
4113 append_implicit_component_param(
4114 &implicit_debug_info_args
, "full-path", "yes");
4116 case OPT_DEBUG_INFO_TARGET_PREFIX
:
4117 ret
= append_implicit_component_extra_arg(
4118 &implicit_debug_info_args
,
4119 "target-prefix", arg
);
4126 struct bt_value
*fields
= fields_from_arg(arg
);
4132 ret
= insert_flat_params_from_array(
4133 implicit_text_args
.params_arg
,
4143 struct bt_value
*names
= names_from_arg(arg
);
4149 ret
= insert_flat_params_from_array(
4150 implicit_text_args
.params_arg
,
4159 append_implicit_component_param(
4160 &implicit_text_args
, "no-delta", "yes");
4161 implicit_text_args
.exists
= true;
4163 case OPT_INPUT_FORMAT
:
4164 if (got_input_format_opt
) {
4165 printf_err("Duplicate --input-format option\n");
4169 got_input_format_opt
= true;
4171 if (strcmp(arg
, "ctf") == 0) {
4172 implicit_ctf_args
.exists
= true;
4173 } else if (strcmp(arg
, "lttng-live") == 0) {
4174 implicit_lttng_live_args
.exists
= true;
4176 printf_err("Unknown legacy input format:\n %s\n",
4181 case OPT_OUTPUT_FORMAT
:
4182 if (got_output_format_opt
) {
4183 printf_err("Duplicate --output-format option\n");
4187 got_output_format_opt
= true;
4189 if (strcmp(arg
, "text") == 0) {
4190 implicit_text_args
.exists
= true;
4191 } else if (strcmp(arg
, "dummy") == 0) {
4192 implicit_dummy_args
.exists
= true;
4193 } else if (strcmp(arg
, "ctf-metadata") == 0) {
4194 print_ctf_metadata
= true;
4196 printf_err("Unknown legacy output format:\n %s\n",
4202 ret
= append_implicit_component_extra_arg(
4203 &implicit_text_args
, "path", arg
);
4204 implicit_text_args
.exists
= true;
4210 if (print_run_args_0
) {
4211 printf_err("Cannot specify --run-args and --run-args-0\n");
4215 print_run_args
= true;
4217 case OPT_RUN_ARGS_0
:
4218 if (print_run_args
) {
4219 printf_err("Cannot specify --run-args and --run-args-0\n");
4223 print_run_args_0
= true;
4225 case OPT_STREAM_INTERSECTION
:
4226 append_implicit_component_param(&implicit_ctf_args
,
4227 "stream-intersection", "yes");
4228 implicit_ctf_args
.exists
= true;
4231 if (got_verbose_opt
) {
4232 printf_err("Duplicate -v/--verbose option\n");
4236 append_implicit_component_param(&implicit_text_args
,
4238 implicit_text_args
.exists
= true;
4239 got_verbose_opt
= true;
4242 got_debug_opt
= true;
4250 /* Check for option parsing error */
4252 printf_err("While parsing command-line options, at option %s: %s\n",
4253 poptBadOption(pc
, 0), poptStrerror(opt
));
4258 * Append home and system plugin paths now that we possibly got
4261 if (append_home_and_system_plugin_paths(plugin_paths
,
4262 force_omit_system_plugin_path
,
4263 force_omit_home_plugin_path
)) {
4267 /* Consume leftover argument */
4268 leftover
= poptGetArg(pc
);
4270 if (poptPeekArg(pc
)) {
4271 printf_err("Unexpected argument:\n %s\n",
4276 /* Print CTF metadata or print LTTng live sessions */
4277 if (print_ctf_metadata
) {
4279 printf_err("--output-format=ctf-metadata specified without a path\n");
4283 cfg
= bt_config_print_ctf_metadata_create(plugin_paths
);
4288 cfg
->debug
= got_debug_opt
;
4289 cfg
->verbose
= got_verbose_opt
;
4290 g_string_assign(cfg
->cmd_data
.print_ctf_metadata
.path
,
4296 * If -o dummy was not specified, and if there are no explicit
4297 * sink components, then use an implicit `text.text` sink.
4299 if (!implicit_dummy_args
.exists
&& !sink_names
) {
4300 implicit_text_args
.exists
= true;
4303 /* Decide where the leftover argument goes */
4305 if (implicit_lttng_live_args
.exists
) {
4306 lttng_live_url_parts
=
4307 bt_common_parse_lttng_live_url(leftover
,
4308 error_buf
, sizeof(error_buf
));
4309 if (!lttng_live_url_parts
.proto
) {
4310 printf_err("Invalid LTTng live URL format: %s\n",
4315 if (!lttng_live_url_parts
.session_name
) {
4316 /* Print LTTng live sessions */
4317 cfg
= bt_config_print_lttng_live_sessions_create(
4323 cfg
->debug
= got_debug_opt
;
4324 cfg
->verbose
= got_verbose_opt
;
4325 g_string_assign(cfg
->cmd_data
.print_lttng_live_sessions
.url
,
4330 ret
= append_implicit_component_extra_arg(
4331 &implicit_lttng_live_args
, "url", leftover
);
4336 ret
= append_implicit_component_extra_arg(
4337 &implicit_ctf_args
, "path", leftover
);
4338 implicit_ctf_args
.exists
= true;
4346 * Ensure mutual exclusion between implicit `ctf.fs` and
4347 * `ctf.lttng-live` sources.
4349 if (implicit_ctf_args
.exists
&& implicit_lttng_live_args
.exists
) {
4350 printf_err("Cannot create both implicit `%s` and `%s` source components\n",
4351 implicit_ctf_args
.plugin_comp_cls_arg
->str
,
4352 implicit_lttng_live_args
.plugin_comp_cls_arg
->str
);
4357 * If the implicit `ctf.fs` or `ctf.lttng-live` source exists,
4358 * make sure there's a leftover (which is the path or URL).
4360 if (implicit_ctf_args
.exists
&& !leftover
) {
4361 printf_err("Missing path for implicit `%s` source component\n",
4362 implicit_ctf_args
.plugin_comp_cls_arg
->str
);
4366 if (implicit_lttng_live_args
.exists
&& !leftover
) {
4367 printf_err("Missing URL for implicit `%s` source component\n",
4368 implicit_lttng_live_args
.plugin_comp_cls_arg
->str
);
4372 /* Assign names to implicit components */
4373 ret
= assign_name_to_implicit_component(&implicit_ctf_args
,
4374 "ctf-fs", all_names
, &source_names
, true);
4379 ret
= assign_name_to_implicit_component(&implicit_lttng_live_args
,
4380 "lttng-live", all_names
, &source_names
, true);
4385 ret
= assign_name_to_implicit_component(&implicit_text_args
,
4386 "pretty", all_names
, &sink_names
, true);
4391 ret
= assign_name_to_implicit_component(&implicit_dummy_args
,
4392 "dummy", all_names
, &sink_names
, true);
4397 ret
= assign_name_to_implicit_component(&implicit_muxer_args
,
4398 "muxer", all_names
, NULL
, false);
4403 ret
= assign_name_to_implicit_component(&implicit_trimmer_args
,
4404 "trimmer", all_names
, NULL
, false);
4409 ret
= assign_name_to_implicit_component(&implicit_debug_info_args
,
4410 "debug-info", all_names
, NULL
, false);
4415 /* Make sure there's at least one source and one sink */
4416 if (!source_names
) {
4417 printf_err("No source component\n");
4422 printf_err("No sink component\n");
4427 * Prepend the muxer, the trimmer, and the debug info to the
4428 * filter chain so that we have:
4430 * sources -> muxer -> [trimmer] -> [debug info] ->
4431 * [user filters] -> sinks
4433 if (implicit_debug_info_args
.exists
) {
4434 if (g_list_prepend_gstring(&filter_names
,
4435 implicit_debug_info_args
.name_arg
->str
)) {
4440 if (implicit_trimmer_args
.exists
) {
4441 if (g_list_prepend_gstring(&filter_names
,
4442 implicit_trimmer_args
.name_arg
->str
)) {
4447 if (g_list_prepend_gstring(&filter_names
,
4448 implicit_muxer_args
.name_arg
->str
)) {
4453 * Append the equivalent run arguments for the implicit
4456 ret
= append_run_args_for_implicit_component(
4457 BT_COMPONENT_CLASS_TYPE_SOURCE
, &implicit_ctf_args
, run_args
);
4462 ret
= append_run_args_for_implicit_component(
4463 BT_COMPONENT_CLASS_TYPE_SOURCE
, &implicit_lttng_live_args
,
4469 ret
= append_run_args_for_implicit_component(
4470 BT_COMPONENT_CLASS_TYPE_SINK
, &implicit_text_args
, run_args
);
4475 ret
= append_run_args_for_implicit_component(
4476 BT_COMPONENT_CLASS_TYPE_SINK
, &implicit_dummy_args
, run_args
);
4481 ret
= append_run_args_for_implicit_component(
4482 BT_COMPONENT_CLASS_TYPE_FILTER
, &implicit_muxer_args
, run_args
);
4487 ret
= append_run_args_for_implicit_component(
4488 BT_COMPONENT_CLASS_TYPE_FILTER
, &implicit_trimmer_args
,
4494 ret
= append_run_args_for_implicit_component(
4495 BT_COMPONENT_CLASS_TYPE_FILTER
, &implicit_debug_info_args
,
4501 /* Auto-connect components */
4502 ret
= convert_auto_connect(run_args
, source_names
, filter_names
,
4505 printf_err("Cannot auto-connect components\n");
4510 * We have all the run command arguments now. Depending on
4511 * --run-args, we pass this to the run command or print them
4514 if (print_run_args
|| print_run_args_0
) {
4515 for (i
= 0; i
< bt_value_array_size(run_args
); i
++) {
4516 struct bt_value
*arg_value
=
4517 bt_value_array_get(run_args
, i
);
4519 GString
*quoted
= NULL
;
4520 const char *arg_to_print
;
4523 ret
= bt_value_string_get(arg_value
, &arg
);
4527 if (print_run_args
) {
4528 quoted
= bt_common_shell_quote(arg
, true);
4533 arg_to_print
= quoted
->str
;
4538 printf("%s", arg_to_print
);
4541 g_string_free(quoted
, TRUE
);
4544 if (i
< bt_value_array_size(run_args
) - 1) {
4545 if (print_run_args
) {
4558 cfg
= bt_config_run_from_args_array(run_args
, retcode
,
4559 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
4560 initial_plugin_paths
);
4569 poptFreeContext(pc
);
4575 g_string_free(cur_name
, TRUE
);
4578 if (cur_name_prefix
) {
4579 g_string_free(cur_name_prefix
, TRUE
);
4584 destroy_glist_of_gstring(source_names
);
4585 destroy_glist_of_gstring(filter_names
);
4586 destroy_glist_of_gstring(sink_names
);
4587 destroy_implicit_component_args(&implicit_ctf_args
);
4588 destroy_implicit_component_args(&implicit_lttng_live_args
);
4589 destroy_implicit_component_args(&implicit_dummy_args
);
4590 destroy_implicit_component_args(&implicit_text_args
);
4591 destroy_implicit_component_args(&implicit_debug_info_args
);
4592 destroy_implicit_component_args(&implicit_muxer_args
);
4593 destroy_implicit_component_args(&implicit_trimmer_args
);
4594 bt_put(plugin_paths
);
4595 bt_common_destroy_lttng_live_url_parts(<tng_live_url_parts
);
4600 * Prints the Babeltrace 2.x general usage.
4603 void print_gen_usage(FILE *fp
)
4605 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [COMMAND] [COMMAND ARGUMENTS]\n");
4607 fprintf(fp
, "General options:\n");
4609 fprintf(fp
, " -d, --debug Turn on debug mode\n");
4610 fprintf(fp
, " -h --help Show this help and quit\n");
4611 fprintf(fp
, " -v, --verbose Turn on verbose mode\n");
4612 fprintf(fp
, " -V, --version Show version and quit\n");
4614 fprintf(fp
, "Available commands:\n");
4616 fprintf(fp
, " convert Convert and trim traces (default)\n");
4617 fprintf(fp
, " help Get help for a plugin or a component class\n");
4618 fprintf(fp
, " list-plugins List available plugins and their content\n");
4619 fprintf(fp
, " query Query objects from a component class\n");
4620 fprintf(fp
, " run Build a processing graph and run it\n");
4622 fprintf(fp
, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
4625 struct bt_config
*bt_config_cli_args_create(int argc
, const char *argv
[],
4626 int *retcode
, bool force_omit_system_plugin_path
,
4627 bool force_omit_home_plugin_path
, bool force_no_debug_info
,
4628 struct bt_value
*initial_plugin_paths
)
4630 struct bt_config
*config
= NULL
;
4631 bool verbose
= false;
4634 const char **command_argv
= NULL
;
4635 int command_argc
= -1;
4636 const char *command_name
= NULL
;
4639 COMMAND_TYPE_NONE
= -1,
4640 COMMAND_TYPE_RUN
= 0,
4641 COMMAND_TYPE_CONVERT
,
4642 COMMAND_TYPE_LIST_PLUGINS
,
4645 } command_type
= COMMAND_TYPE_NONE
;
4649 if (!initial_plugin_paths
) {
4650 initial_plugin_paths
= bt_value_array_create();
4651 if (!initial_plugin_paths
) {
4656 bt_get(initial_plugin_paths
);
4660 print_gen_usage(stdout
);
4664 for (i
= 1; i
< argc
; i
++) {
4665 const char *cur_arg
= argv
[i
];
4667 if (strcmp(cur_arg
, "-d") == 0 ||
4668 strcmp(cur_arg
, "--debug") == 0) {
4670 } else if (strcmp(cur_arg
, "-v") == 0 ||
4671 strcmp(cur_arg
, "--verbose") == 0) {
4673 } else if (strcmp(cur_arg
, "-V") == 0 ||
4674 strcmp(cur_arg
, "--version") == 0) {
4677 } else if (strcmp(cur_arg
, "-h") == 0 ||
4678 strcmp(cur_arg
, "--help") == 0) {
4679 print_gen_usage(stdout
);
4682 bool has_command
= true;
4685 * First unknown argument: is it a known command
4688 if (strcmp(cur_arg
, "convert") == 0) {
4689 command_type
= COMMAND_TYPE_CONVERT
;
4690 } else if (strcmp(cur_arg
, "list-plugins") == 0) {
4691 command_type
= COMMAND_TYPE_LIST_PLUGINS
;
4692 } else if (strcmp(cur_arg
, "help") == 0) {
4693 command_type
= COMMAND_TYPE_HELP
;
4694 } else if (strcmp(cur_arg
, "query") == 0) {
4695 command_type
= COMMAND_TYPE_QUERY
;
4696 } else if (strcmp(cur_arg
, "run") == 0) {
4697 command_type
= COMMAND_TYPE_RUN
;
4700 * Unknown argument, but not a known
4701 * command name: assume the whole
4702 * arguments are for the default convert
4705 command_type
= COMMAND_TYPE_CONVERT
;
4706 command_argv
= argv
;
4707 command_argc
= argc
;
4708 has_command
= false;
4712 command_argv
= &argv
[i
];
4713 command_argc
= argc
- i
;
4714 command_name
= cur_arg
;
4720 if (command_type
== COMMAND_TYPE_NONE
) {
4722 * We only got non-help, non-version general options
4723 * like --verbose and --debug, without any other
4724 * arguments, so we can't do anything useful: print the
4727 print_gen_usage(stdout
);
4731 assert(command_argv
);
4732 assert(command_argc
>= 0);
4734 switch (command_type
) {
4735 case COMMAND_TYPE_RUN
:
4736 config
= bt_config_run_from_args(command_argc
, command_argv
,
4737 retcode
, force_omit_system_plugin_path
,
4738 force_omit_home_plugin_path
, initial_plugin_paths
);
4740 case COMMAND_TYPE_CONVERT
:
4741 config
= bt_config_convert_from_args(command_argc
, command_argv
,
4742 retcode
, force_omit_system_plugin_path
,
4743 force_omit_home_plugin_path
, force_no_debug_info
,
4744 initial_plugin_paths
);
4746 case COMMAND_TYPE_LIST_PLUGINS
:
4747 config
= bt_config_list_plugins_from_args(command_argc
,
4748 command_argv
, retcode
, force_omit_system_plugin_path
,
4749 force_omit_home_plugin_path
, initial_plugin_paths
);
4751 case COMMAND_TYPE_HELP
:
4752 config
= bt_config_help_from_args(command_argc
,
4753 command_argv
, retcode
, force_omit_system_plugin_path
,
4754 force_omit_home_plugin_path
, initial_plugin_paths
);
4756 case COMMAND_TYPE_QUERY
:
4757 config
= bt_config_query_from_args(command_argc
,
4758 command_argv
, retcode
, force_omit_system_plugin_path
,
4759 force_omit_home_plugin_path
, initial_plugin_paths
);
4767 config
->verbose
= true;
4771 config
->debug
= true;
4774 config
->command_name
= command_name
;
4778 bt_put(initial_plugin_paths
);