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-connect.h"
43 * Error printf() macro which prepends "Error: " the first time it's
44 * called. This gives a nicer feel than having a bunch of error prefixes
45 * (since the following lines usually describe the error and possible
46 * solutions), or the error prefix just at the end.
48 #define printf_err(fmt, args...) \
50 if (is_first_error) { \
51 fprintf(stderr, "Command line error: "); \
52 is_first_error = false; \
54 fprintf(stderr, fmt, ##args); \
57 static bool is_first_error
= true;
59 /* INI-style parsing FSM states */
60 enum ini_parsing_fsm_state
{
61 /* Expect a map key (identifier) */
64 /* Expect an equal character ('=') */
70 /* Expect a negative number value */
71 INI_EXPECT_VALUE_NUMBER_NEG
,
73 /* Expect a comma character (',') */
77 /* INI-style parsing state variables */
78 struct ini_parsing_state
{
79 /* Lexical scanner (owned by this) */
82 /* Output map value object being filled (owned by this) */
83 struct bt_value
*params
;
85 /* Next expected FSM state */
86 enum ini_parsing_fsm_state expecting
;
88 /* Last decoded map key (owned by this) */
91 /* Complete INI-style string to parse (not owned by this) */
94 /* Error buffer (not owned by this) */
98 /* Offset option with "is set" boolean */
104 /* Legacy "ctf"/"lttng-live" format options */
105 struct ctf_legacy_opts
{
106 struct offset_opt offset_s
;
107 struct offset_opt offset_ns
;
108 bool stream_intersection
;
111 /* Legacy "text" format options */
112 struct text_legacy_opts
{
114 * output, dbg_info_dir, dbg_info_target_prefix, names,
115 * and fields are owned by this.
118 GString
*dbg_info_dir
;
119 GString
*dbg_info_target_prefix
;
120 struct bt_value
*names
;
121 struct bt_value
*fields
;
129 bool dbg_info_full_path
;
133 /* Legacy input format format */
134 enum legacy_input_format
{
135 LEGACY_INPUT_FORMAT_NONE
= 0,
136 LEGACY_INPUT_FORMAT_CTF
,
137 LEGACY_INPUT_FORMAT_LTTNG_LIVE
,
140 /* Legacy output format format */
141 enum legacy_output_format
{
142 LEGACY_OUTPUT_FORMAT_NONE
= 0,
143 LEGACY_OUTPUT_FORMAT_TEXT
,
144 LEGACY_OUTPUT_FORMAT_DUMMY
,
148 * Prints the "out of memory" error.
151 void print_err_oom(void)
153 printf_err("Out of memory\n");
157 * Appends an "expecting token" error to the INI-style parsing state's
161 void ini_append_error_expecting(struct ini_parsing_state
*state
,
162 GScanner
*scanner
, const char *expecting
)
167 g_string_append_printf(state
->ini_error
, "Expecting %s:\n", expecting
);
169 /* Only print error if there's one line */
170 if (strchr(state
->arg
, '\n') != NULL
|| strlen(state
->arg
) == 0) {
174 g_string_append_printf(state
->ini_error
, "\n %s\n", state
->arg
);
175 pos
= g_scanner_cur_position(scanner
) + 4;
177 if (!g_scanner_eof(scanner
)) {
181 for (i
= 0; i
< pos
; ++i
) {
182 g_string_append_printf(state
->ini_error
, " ");
185 g_string_append_printf(state
->ini_error
, "^\n\n");
189 int ini_handle_state(struct ini_parsing_state
*state
)
192 GTokenType token_type
;
193 struct bt_value
*value
= NULL
;
195 token_type
= g_scanner_get_next_token(state
->scanner
);
196 if (token_type
== G_TOKEN_EOF
) {
197 if (state
->expecting
!= INI_EXPECT_COMMA
) {
198 switch (state
->expecting
) {
199 case INI_EXPECT_EQUAL
:
200 ini_append_error_expecting(state
,
201 state
->scanner
, "'='");
203 case INI_EXPECT_VALUE
:
204 case INI_EXPECT_VALUE_NUMBER_NEG
:
205 ini_append_error_expecting(state
,
206 state
->scanner
, "value");
208 case INI_EXPECT_MAP_KEY
:
209 ini_append_error_expecting(state
,
210 state
->scanner
, "unquoted map key");
223 switch (state
->expecting
) {
224 case INI_EXPECT_MAP_KEY
:
225 if (token_type
!= G_TOKEN_IDENTIFIER
) {
226 ini_append_error_expecting(state
, state
->scanner
,
231 free(state
->last_map_key
);
232 state
->last_map_key
=
233 strdup(state
->scanner
->value
.v_identifier
);
234 if (!state
->last_map_key
) {
235 g_string_append(state
->ini_error
,
240 if (bt_value_map_has_key(state
->params
, state
->last_map_key
)) {
241 g_string_append_printf(state
->ini_error
,
242 "Duplicate parameter key: `%s`\n",
243 state
->last_map_key
);
247 state
->expecting
= INI_EXPECT_EQUAL
;
249 case INI_EXPECT_EQUAL
:
250 if (token_type
!= G_TOKEN_CHAR
) {
251 ini_append_error_expecting(state
,
252 state
->scanner
, "'='");
256 if (state
->scanner
->value
.v_char
!= '=') {
257 ini_append_error_expecting(state
,
258 state
->scanner
, "'='");
262 state
->expecting
= INI_EXPECT_VALUE
;
264 case INI_EXPECT_VALUE
:
266 switch (token_type
) {
268 if (state
->scanner
->value
.v_char
== '-') {
269 /* Negative number */
271 INI_EXPECT_VALUE_NUMBER_NEG
;
274 ini_append_error_expecting(state
,
275 state
->scanner
, "value");
281 /* Positive integer */
282 uint64_t int_val
= state
->scanner
->value
.v_int64
;
284 if (int_val
> (1ULL << 63) - 1) {
285 g_string_append_printf(state
->ini_error
,
286 "Integer value %" PRIu64
" is outside the range of a 64-bit signed integer\n",
291 value
= bt_value_integer_create_init(
296 /* Positive floating point number */
297 value
= bt_value_float_create_init(
298 state
->scanner
->value
.v_float
);
302 value
= bt_value_string_create_init(
303 state
->scanner
->value
.v_string
);
305 case G_TOKEN_IDENTIFIER
:
308 * Using symbols would be appropriate here,
309 * but said symbols are allowed as map key,
310 * so it's easier to consider everything an
313 * If one of the known symbols is not
314 * recognized here, then fall back to creating
317 const char *id
= state
->scanner
->value
.v_identifier
;
319 if (!strcmp(id
, "null") || !strcmp(id
, "NULL") ||
320 !strcmp(id
, "nul")) {
321 value
= bt_value_null
;
322 } else if (!strcmp(id
, "true") || !strcmp(id
, "TRUE") ||
323 !strcmp(id
, "yes") ||
324 !strcmp(id
, "YES")) {
325 value
= bt_value_bool_create_init(true);
326 } else if (!strcmp(id
, "false") ||
327 !strcmp(id
, "FALSE") ||
330 value
= bt_value_bool_create_init(false);
332 value
= bt_value_string_create_init(id
);
337 /* Unset value variable will trigger the error */
342 ini_append_error_expecting(state
,
343 state
->scanner
, "value");
347 state
->expecting
= INI_EXPECT_COMMA
;
350 case INI_EXPECT_VALUE_NUMBER_NEG
:
352 switch (token_type
) {
355 /* Negative integer */
356 uint64_t int_val
= state
->scanner
->value
.v_int64
;
358 if (int_val
> (1ULL << 63) - 1) {
359 g_string_append_printf(state
->ini_error
,
360 "Integer value -%" PRIu64
" is outside the range of a 64-bit signed integer\n",
365 value
= bt_value_integer_create_init(
366 -((int64_t) int_val
));
370 /* Negative floating point number */
371 value
= bt_value_float_create_init(
372 -state
->scanner
->value
.v_float
);
375 /* Unset value variable will trigger the error */
380 ini_append_error_expecting(state
,
381 state
->scanner
, "value");
385 state
->expecting
= INI_EXPECT_COMMA
;
388 case INI_EXPECT_COMMA
:
389 if (token_type
!= G_TOKEN_CHAR
) {
390 ini_append_error_expecting(state
,
391 state
->scanner
, "','");
395 if (state
->scanner
->value
.v_char
!= ',') {
396 ini_append_error_expecting(state
,
397 state
->scanner
, "','");
401 state
->expecting
= INI_EXPECT_MAP_KEY
;
413 if (bt_value_map_insert(state
->params
,
414 state
->last_map_key
, value
)) {
415 /* Only override return value on error */
426 * Converts an INI-style argument to an equivalent map value object.
428 * Return value is owned by the caller.
431 struct bt_value
*bt_value_from_ini(const char *arg
, GString
*ini_error
)
433 /* Lexical scanner configuration */
434 GScannerConfig scanner_config
= {
435 /* Skip whitespaces */
436 .cset_skip_characters
= " \t\n",
438 /* Identifier syntax is: [a-zA-Z_][a-zA-Z0-9_.:-]* */
439 .cset_identifier_first
=
443 .cset_identifier_nth
=
448 /* "hello" and "Hello" two different keys */
449 .case_sensitive
= TRUE
,
452 .cpair_comment_single
= NULL
,
453 .skip_comment_multi
= TRUE
,
454 .skip_comment_single
= TRUE
,
455 .scan_comment_multi
= FALSE
,
458 * Do scan identifiers, including 1-char identifiers,
459 * but NULL is a normal identifier.
461 .scan_identifier
= TRUE
,
462 .scan_identifier_1char
= TRUE
,
463 .scan_identifier_NULL
= FALSE
,
466 * No specific symbols: null and boolean "symbols" are
467 * scanned as plain identifiers.
469 .scan_symbols
= FALSE
,
470 .symbol_2_token
= FALSE
,
471 .scope_0_fallback
= FALSE
,
474 * Scan "0b"-, "0"-, and "0x"-prefixed integers, but not
475 * integers prefixed with "$".
481 .scan_hex_dollar
= FALSE
,
483 /* Convert scanned numbers to integer tokens */
484 .numbers_2_int
= TRUE
,
486 /* Support both integers and floating-point numbers */
487 .int_2_float
= FALSE
,
489 /* Scan integers as 64-bit signed integers */
492 /* Only scan double-quoted strings */
493 .scan_string_sq
= FALSE
,
494 .scan_string_dq
= TRUE
,
496 /* Do not converter identifiers to string tokens */
497 .identifier_2_string
= FALSE
,
499 /* Scan characters as G_TOKEN_CHAR token */
500 .char_2_token
= FALSE
,
502 struct ini_parsing_state state
= {
505 .expecting
= INI_EXPECT_MAP_KEY
,
507 .ini_error
= ini_error
,
510 state
.params
= bt_value_map_create();
515 state
.scanner
= g_scanner_new(&scanner_config
);
516 if (!state
.scanner
) {
520 /* Let the scan begin */
521 g_scanner_input_text(state
.scanner
, arg
, strlen(arg
));
524 int ret
= ini_handle_state(&state
);
529 } else if (ret
> 0) {
538 BT_PUT(state
.params
);
542 g_scanner_destroy(state
.scanner
);
545 free(state
.last_map_key
);
550 * Returns the parameters map value object from a command-line
551 * parameter option's argument.
553 * Return value is owned by the caller.
556 struct bt_value
*bt_value_from_arg(const char *arg
)
558 struct bt_value
*params
= NULL
;
559 GString
*ini_error
= NULL
;
561 ini_error
= g_string_new(NULL
);
567 /* Try INI-style parsing */
568 params
= bt_value_from_ini(arg
, ini_error
);
570 printf_err("%s", ini_error
->str
);
576 g_string_free(ini_error
, TRUE
);
582 * Returns the plugin and component class names, and the instance name,
583 * from a command-line source/filter/sink option's argument. arg must
584 * have the following format:
588 * where NAME is the optional component name, PLUGIN is the plugin name,
589 * and CLS is the component class name.
591 * On success, both *plugin and *component are not NULL. *plugin
592 * and *component are owned by the caller. On success, *name can be NULL
593 * if no component name was found.
596 void plugin_comp_cls_names(const char *arg
, char **name
, char **plugin
,
599 const char *at
= arg
;
600 GString
*gs_name
= NULL
;
601 GString
*gs_plugin
= NULL
;
602 GString
*gs_comp_cls
= NULL
;
609 if (!bt_common_string_is_printable(arg
)) {
610 printf_err("Argument contains a non-printable character\n");
614 /* Parse the component name */
615 gs_name
= bt_common_string_until(at
, ".:\\", ":", &end_pos
);
620 if (arg
[end_pos
] == ':') {
624 g_string_assign(gs_name
, "");
627 /* Parse the plugin name */
628 gs_plugin
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
629 if (!gs_plugin
|| gs_plugin
->len
== 0 || at
[end_pos
] == '\0') {
635 /* Parse the component class name */
636 gs_comp_cls
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
637 if (!gs_comp_cls
|| gs_comp_cls
->len
== 0) {
641 if (at
[end_pos
] != '\0') {
642 /* Found a non-escaped `.` */
647 if (gs_name
->len
== 0) {
649 g_string_free(gs_name
, TRUE
);
651 *name
= gs_name
->str
;
652 g_string_free(gs_name
, FALSE
);
655 g_string_free(gs_name
, TRUE
);
658 *plugin
= gs_plugin
->str
;
659 *comp_cls
= gs_comp_cls
->str
;
660 g_string_free(gs_plugin
, FALSE
);
661 g_string_free(gs_comp_cls
, FALSE
);
669 g_string_free(gs_name
, TRUE
);
673 g_string_free(gs_plugin
, TRUE
);
677 g_string_free(gs_comp_cls
, TRUE
);
692 * Prints the Babeltrace version.
695 void print_version(void)
697 puts("Babeltrace " VERSION
);
701 * Destroys a component configuration.
704 void bt_config_component_destroy(struct bt_object
*obj
)
706 struct bt_config_component
*bt_config_component
=
707 container_of(obj
, struct bt_config_component
, base
);
713 if (bt_config_component
->plugin_name
) {
714 g_string_free(bt_config_component
->plugin_name
, TRUE
);
717 if (bt_config_component
->comp_cls_name
) {
718 g_string_free(bt_config_component
->comp_cls_name
, TRUE
);
721 if (bt_config_component
->instance_name
) {
722 g_string_free(bt_config_component
->instance_name
, TRUE
);
725 BT_PUT(bt_config_component
->params
);
726 g_free(bt_config_component
);
733 * Creates a component configuration using the given plugin name and
734 * component name. `plugin_name` and `comp_cls_name` are copied (belong
735 * to the return value).
737 * Return value is owned by the caller.
740 struct bt_config_component
*bt_config_component_create(
741 enum bt_component_class_type type
,
742 const char *plugin_name
, const char *comp_cls_name
)
744 struct bt_config_component
*cfg_component
= NULL
;
746 cfg_component
= g_new0(struct bt_config_component
, 1);
747 if (!cfg_component
) {
752 bt_object_init(cfg_component
, bt_config_component_destroy
);
753 cfg_component
->type
= type
;
754 cfg_component
->plugin_name
= g_string_new(plugin_name
);
755 if (!cfg_component
->plugin_name
) {
760 cfg_component
->comp_cls_name
= g_string_new(comp_cls_name
);
761 if (!cfg_component
->comp_cls_name
) {
766 cfg_component
->instance_name
= g_string_new(NULL
);
767 if (!cfg_component
->instance_name
) {
772 /* Start with empty parameters */
773 cfg_component
->params
= bt_value_map_create();
774 if (!cfg_component
->params
) {
782 BT_PUT(cfg_component
);
785 return cfg_component
;
789 * Creates a component configuration from a command-line source/sink
792 struct bt_config_component
*bt_config_component_from_arg(
793 enum bt_component_class_type type
, const char *arg
)
795 struct bt_config_component
*cfg_comp
= NULL
;
797 char *plugin_name
= NULL
;
798 char *comp_cls_name
= NULL
;
800 plugin_comp_cls_names(arg
, &name
, &plugin_name
, &comp_cls_name
);
801 if (!plugin_name
|| !comp_cls_name
) {
802 printf_err("Cannot get plugin or component class name\n");
806 cfg_comp
= bt_config_component_create(type
, plugin_name
, comp_cls_name
);
812 g_string_assign(cfg_comp
->instance_name
, name
);
823 g_free(comp_cls_name
);
828 * Destroys a configuration.
831 void bt_config_destroy(struct bt_object
*obj
)
833 struct bt_config
*cfg
=
834 container_of(obj
, struct bt_config
, base
);
840 BT_PUT(cfg
->plugin_paths
);
842 switch (cfg
->command
) {
843 case BT_CONFIG_COMMAND_RUN
:
844 if (cfg
->cmd_data
.run
.sources
) {
845 g_ptr_array_free(cfg
->cmd_data
.run
.sources
, TRUE
);
848 if (cfg
->cmd_data
.run
.filters
) {
849 g_ptr_array_free(cfg
->cmd_data
.run
.filters
, TRUE
);
852 if (cfg
->cmd_data
.run
.sinks
) {
853 g_ptr_array_free(cfg
->cmd_data
.run
.sinks
, TRUE
);
856 if (cfg
->cmd_data
.run
.connections
) {
857 g_ptr_array_free(cfg
->cmd_data
.run
.connections
,
861 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
863 case BT_CONFIG_COMMAND_HELP
:
864 BT_PUT(cfg
->cmd_data
.help
.cfg_component
);
866 case BT_CONFIG_COMMAND_QUERY
:
867 BT_PUT(cfg
->cmd_data
.query
.cfg_component
);
869 if (cfg
->cmd_data
.query
.object
) {
870 g_string_free(cfg
->cmd_data
.query
.object
, TRUE
);
873 case BT_CONFIG_COMMAND_PRINT_CTF_METADATA
:
874 if (cfg
->cmd_data
.print_ctf_metadata
.path
) {
875 g_string_free(cfg
->cmd_data
.print_ctf_metadata
.path
,
879 case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
:
880 if (cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
882 cfg
->cmd_data
.print_lttng_live_sessions
.url
,
896 static void destroy_gstring(void *data
)
898 g_string_free(data
, TRUE
);
901 static void destroy_glist_of_gstring(GList
*list
)
909 for (at
= list
; at
!= NULL
; at
= g_list_next(at
)) {
910 g_string_free(at
->data
, TRUE
);
917 * Extracts the various paths from the string arg, delimited by ':',
918 * and appends them to the array value object plugin_paths.
920 enum bt_value_status
bt_config_append_plugin_paths(
921 struct bt_value
*plugin_paths
, const char *arg
)
923 enum bt_value_status status
= BT_VALUE_STATUS_OK
;
924 GPtrArray
*dirs
= g_ptr_array_new_with_free_func(destroy_gstring
);
929 status
= BT_VALUE_STATUS_ERROR
;
933 ret
= bt_common_append_plugin_path_dirs(arg
, dirs
);
935 status
= BT_VALUE_STATUS_ERROR
;
939 for (i
= 0; i
< dirs
->len
; i
++) {
940 GString
*dir
= g_ptr_array_index(dirs
, i
);
942 bt_value_array_append_string(plugin_paths
, dir
->str
);
946 g_ptr_array_free(dirs
, TRUE
);
951 * Creates a simple lexical scanner for parsing comma-delimited names
954 * Return value is owned by the caller.
957 GScanner
*create_csv_identifiers_scanner(void)
960 GScannerConfig scanner_config
= {
961 .cset_skip_characters
= " \t\n",
962 .cset_identifier_first
= G_CSET_a_2_z G_CSET_A_2_Z
"_",
963 .cset_identifier_nth
= G_CSET_a_2_z G_CSET_A_2_Z
":_-",
964 .case_sensitive
= TRUE
,
965 .cpair_comment_single
= NULL
,
966 .skip_comment_multi
= TRUE
,
967 .skip_comment_single
= TRUE
,
968 .scan_comment_multi
= FALSE
,
969 .scan_identifier
= TRUE
,
970 .scan_identifier_1char
= TRUE
,
971 .scan_identifier_NULL
= FALSE
,
972 .scan_symbols
= FALSE
,
973 .symbol_2_token
= FALSE
,
974 .scope_0_fallback
= FALSE
,
975 .scan_binary
= FALSE
,
979 .scan_hex_dollar
= FALSE
,
980 .numbers_2_int
= FALSE
,
981 .int_2_float
= FALSE
,
982 .store_int64
= FALSE
,
983 .scan_string_sq
= FALSE
,
984 .scan_string_dq
= FALSE
,
985 .identifier_2_string
= FALSE
,
986 .char_2_token
= TRUE
,
989 scanner
= g_scanner_new(&scanner_config
);
998 * Converts a comma-delimited list of known names (--names option) to
999 * an array value object containing those names as string value objects.
1001 * Return value is owned by the caller.
1004 struct bt_value
*names_from_arg(const char *arg
)
1006 GScanner
*scanner
= NULL
;
1007 struct bt_value
*names
= NULL
;
1008 bool found_all
= false, found_none
= false, found_item
= false;
1010 names
= bt_value_array_create();
1016 scanner
= create_csv_identifiers_scanner();
1021 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1024 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1026 switch (token_type
) {
1027 case G_TOKEN_IDENTIFIER
:
1029 const char *identifier
= scanner
->value
.v_identifier
;
1031 if (!strcmp(identifier
, "payload") ||
1032 !strcmp(identifier
, "args") ||
1033 !strcmp(identifier
, "arg")) {
1035 if (bt_value_array_append_string(names
,
1039 } else if (!strcmp(identifier
, "context") ||
1040 !strcmp(identifier
, "ctx")) {
1042 if (bt_value_array_append_string(names
,
1046 } else if (!strcmp(identifier
, "scope") ||
1047 !strcmp(identifier
, "header")) {
1049 if (bt_value_array_append_string(names
,
1053 } else if (!strcmp(identifier
, "all")) {
1055 if (bt_value_array_append_string(names
,
1059 } else if (!strcmp(identifier
, "none")) {
1061 if (bt_value_array_append_string(names
,
1066 printf_err("Unknown name: `%s`\n",
1082 if (found_none
&& found_all
) {
1083 printf_err("Only either `all` or `none` can be specified in the list given to the --names option, but not both.\n");
1087 * Legacy behavior is to clear the defaults (show none) when at
1088 * least one item is specified.
1090 if (found_item
&& !found_none
&& !found_all
) {
1091 if (bt_value_array_append_string(names
, "none")) {
1096 g_scanner_destroy(scanner
);
1103 g_scanner_destroy(scanner
);
1109 * Converts a comma-delimited list of known fields (--fields option) to
1110 * an array value object containing those fields as string
1113 * Return value is owned by the caller.
1116 struct bt_value
*fields_from_arg(const char *arg
)
1118 GScanner
*scanner
= NULL
;
1119 struct bt_value
*fields
;
1121 fields
= bt_value_array_create();
1127 scanner
= create_csv_identifiers_scanner();
1132 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1135 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1137 switch (token_type
) {
1138 case G_TOKEN_IDENTIFIER
:
1140 const char *identifier
= scanner
->value
.v_identifier
;
1142 if (!strcmp(identifier
, "trace") ||
1143 !strcmp(identifier
, "trace:hostname") ||
1144 !strcmp(identifier
, "trace:domain") ||
1145 !strcmp(identifier
, "trace:procname") ||
1146 !strcmp(identifier
, "trace:vpid") ||
1147 !strcmp(identifier
, "loglevel") ||
1148 !strcmp(identifier
, "emf") ||
1149 !strcmp(identifier
, "callsite") ||
1150 !strcmp(identifier
, "all")) {
1151 if (bt_value_array_append_string(fields
,
1156 printf_err("Unknown field: `%s`\n",
1178 g_scanner_destroy(scanner
);
1184 void append_param_arg(GString
*params_arg
, const char *key
, const char *value
)
1190 if (params_arg
->len
!= 0) {
1191 g_string_append_c(params_arg
, ',');
1194 g_string_append(params_arg
, key
);
1195 g_string_append_c(params_arg
, '=');
1196 g_string_append(params_arg
, value
);
1200 * Inserts the equivalent "prefix-NAME=yes" strings into params_arg
1201 * where the names are in names_array.
1204 int insert_flat_params_from_array(GString
*params_arg
,
1205 struct bt_value
*names_array
, const char *prefix
)
1209 GString
*tmpstr
= NULL
, *default_value
= NULL
;
1210 bool default_set
= false, non_default_set
= false;
1213 * names_array may be NULL if no CLI options were specified to
1214 * trigger its creation.
1220 tmpstr
= g_string_new(NULL
);
1227 default_value
= g_string_new(NULL
);
1228 if (!default_value
) {
1234 for (i
= 0; i
< bt_value_array_size(names_array
); i
++) {
1235 struct bt_value
*str_obj
= bt_value_array_get(names_array
, i
);
1237 bool is_default
= false;
1240 printf_err("Unexpected error\n");
1245 ret
= bt_value_string_get(str_obj
, &suffix
);
1248 printf_err("Unexpected error\n");
1252 g_string_assign(tmpstr
, prefix
);
1253 g_string_append(tmpstr
, "-");
1255 /* Special-case for "all" and "none". */
1256 if (!strcmp(suffix
, "all")) {
1258 g_string_assign(default_value
, "show");
1259 } else if (!strcmp(suffix
, "none")) {
1261 g_string_assign(default_value
, "hide");
1265 g_string_append(tmpstr
, "default");
1266 append_param_arg(params_arg
, tmpstr
->str
,
1267 default_value
->str
);
1269 non_default_set
= true;
1270 g_string_append(tmpstr
, suffix
);
1271 append_param_arg(params_arg
, tmpstr
->str
, "yes");
1275 /* Implicit field-default=hide if any non-default option is set. */
1276 if (non_default_set
&& !default_set
) {
1277 g_string_assign(tmpstr
, prefix
);
1278 g_string_append(tmpstr
, "-default");
1279 g_string_assign(default_value
, "hide");
1280 append_param_arg(params_arg
, tmpstr
->str
, default_value
->str
);
1284 if (default_value
) {
1285 g_string_free(default_value
, TRUE
);
1289 g_string_free(tmpstr
, TRUE
);
1302 OPT_CLOCK_FORCE_CORRELATE
,
1305 OPT_CLOCK_OFFSET_NS
,
1311 OPT_DEBUG_INFO_FULL_PATH
,
1312 OPT_DEBUG_INFO_TARGET_PREFIX
,
1324 OPT_OMIT_HOME_PLUGIN_PATH
,
1325 OPT_OMIT_SYSTEM_PLUGIN_PATH
,
1331 OPT_RESET_BASE_PARAMS
,
1336 OPT_STREAM_INTERSECTION
,
1343 enum bt_config_component_dest
{
1344 BT_CONFIG_COMPONENT_DEST_SOURCE
,
1345 BT_CONFIG_COMPONENT_DEST_FILTER
,
1346 BT_CONFIG_COMPONENT_DEST_SINK
,
1350 * Adds a configuration component to the appropriate configuration
1351 * array depending on the destination.
1353 static void add_run_cfg_comp(struct bt_config
*cfg
,
1354 struct bt_config_component
*cfg_comp
,
1355 enum bt_config_component_dest dest
)
1360 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
1361 g_ptr_array_add(cfg
->cmd_data
.run
.sources
, cfg_comp
);
1363 case BT_CONFIG_COMPONENT_DEST_FILTER
:
1364 g_ptr_array_add(cfg
->cmd_data
.run
.filters
, cfg_comp
);
1366 case BT_CONFIG_COMPONENT_DEST_SINK
:
1367 g_ptr_array_add(cfg
->cmd_data
.run
.sinks
, cfg_comp
);
1374 static int add_run_cfg_comp_check_name(struct bt_config
*cfg
,
1375 struct bt_config_component
*cfg_comp
,
1376 enum bt_config_component_dest dest
,
1377 struct bt_value
*instance_names
)
1381 if (cfg_comp
->instance_name
->len
== 0) {
1382 printf_err("Found an unnamed component\n");
1387 if (bt_value_map_has_key(instance_names
, cfg_comp
->instance_name
->str
)) {
1388 printf_err("Duplicate component instance name:\n %s\n",
1389 cfg_comp
->instance_name
->str
);
1394 if (bt_value_map_insert(instance_names
,
1395 cfg_comp
->instance_name
->str
, bt_value_null
)) {
1401 add_run_cfg_comp(cfg
, cfg_comp
, dest
);
1407 static int append_env_var_plugin_paths(struct bt_value
*plugin_paths
)
1412 if (bt_common_is_setuid_setgid()) {
1413 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
1417 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
1422 ret
= bt_config_append_plugin_paths(plugin_paths
, envvar
);
1426 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
1432 static int append_home_and_system_plugin_paths(struct bt_value
*plugin_paths
,
1433 bool omit_system_plugin_path
, bool omit_home_plugin_path
)
1437 if (!omit_home_plugin_path
) {
1438 if (bt_common_is_setuid_setgid()) {
1439 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
1441 char *home_plugin_dir
=
1442 bt_common_get_home_plugin_path();
1444 if (home_plugin_dir
) {
1445 ret
= bt_config_append_plugin_paths(
1446 plugin_paths
, home_plugin_dir
);
1447 free(home_plugin_dir
);
1450 printf_err("Invalid home plugin path\n");
1457 if (!omit_system_plugin_path
) {
1458 if (bt_config_append_plugin_paths(plugin_paths
,
1459 bt_common_get_system_plugin_path())) {
1460 printf_err("Invalid system plugin path\n");
1466 printf_err("Cannot append home and system plugin paths\n");
1470 static int append_home_and_system_plugin_paths_cfg(struct bt_config
*cfg
)
1472 return append_home_and_system_plugin_paths(cfg
->plugin_paths
,
1473 cfg
->omit_system_plugin_path
, cfg
->omit_home_plugin_path
);
1476 static struct bt_config
*bt_config_base_create(enum bt_config_command command
,
1477 struct bt_value
*initial_plugin_paths
, bool needs_plugins
)
1479 struct bt_config
*cfg
;
1482 cfg
= g_new0(struct bt_config
, 1);
1488 bt_object_init(cfg
, bt_config_destroy
);
1489 cfg
->command
= command
;
1490 cfg
->command_needs_plugins
= needs_plugins
;
1492 if (initial_plugin_paths
) {
1493 cfg
->plugin_paths
= bt_get(initial_plugin_paths
);
1495 cfg
->plugin_paths
= bt_value_array_create();
1496 if (!cfg
->plugin_paths
) {
1511 static struct bt_config
*bt_config_run_create(
1512 struct bt_value
*initial_plugin_paths
)
1514 struct bt_config
*cfg
;
1517 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_RUN
,
1518 initial_plugin_paths
, true);
1523 cfg
->cmd_data
.run
.sources
= g_ptr_array_new_with_free_func(
1524 (GDestroyNotify
) bt_put
);
1525 if (!cfg
->cmd_data
.run
.sources
) {
1530 cfg
->cmd_data
.run
.filters
= g_ptr_array_new_with_free_func(
1531 (GDestroyNotify
) bt_put
);
1532 if (!cfg
->cmd_data
.run
.filters
) {
1537 cfg
->cmd_data
.run
.sinks
= g_ptr_array_new_with_free_func(
1538 (GDestroyNotify
) bt_put
);
1539 if (!cfg
->cmd_data
.run
.sinks
) {
1544 cfg
->cmd_data
.run
.connections
= g_ptr_array_new_with_free_func(
1545 (GDestroyNotify
) bt_config_connection_destroy
);
1546 if (!cfg
->cmd_data
.run
.connections
) {
1560 static struct bt_config
*bt_config_list_plugins_create(
1561 struct bt_value
*initial_plugin_paths
)
1563 struct bt_config
*cfg
;
1566 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_LIST_PLUGINS
,
1567 initial_plugin_paths
, true);
1581 static struct bt_config
*bt_config_help_create(
1582 struct bt_value
*initial_plugin_paths
)
1584 struct bt_config
*cfg
;
1587 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_HELP
,
1588 initial_plugin_paths
, true);
1593 cfg
->cmd_data
.help
.cfg_component
=
1594 bt_config_component_create(BT_COMPONENT_CLASS_TYPE_UNKNOWN
,
1596 if (!cfg
->cmd_data
.help
.cfg_component
) {
1609 static struct bt_config
*bt_config_query_create(
1610 struct bt_value
*initial_plugin_paths
)
1612 struct bt_config
*cfg
;
1615 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_QUERY
,
1616 initial_plugin_paths
, true);
1621 cfg
->cmd_data
.query
.object
= g_string_new(NULL
);
1622 if (!cfg
->cmd_data
.query
.object
) {
1636 static struct bt_config
*bt_config_print_ctf_metadata_create(
1637 struct bt_value
*initial_plugin_paths
)
1639 struct bt_config
*cfg
;
1642 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_CTF_METADATA
,
1643 initial_plugin_paths
, true);
1648 cfg
->cmd_data
.print_ctf_metadata
.path
= g_string_new(NULL
);
1649 if (!cfg
->cmd_data
.print_ctf_metadata
.path
) {
1663 static struct bt_config
*bt_config_print_lttng_live_sessions_create(
1664 struct bt_value
*initial_plugin_paths
)
1666 struct bt_config
*cfg
;
1669 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
,
1670 initial_plugin_paths
, true);
1675 cfg
->cmd_data
.print_lttng_live_sessions
.url
= g_string_new(NULL
);
1676 if (!cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
1690 int bt_config_append_plugin_paths_check_setuid_setgid(
1691 struct bt_value
*plugin_paths
, const char *arg
)
1695 if (bt_common_is_setuid_setgid()) {
1696 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
1700 if (bt_config_append_plugin_paths(plugin_paths
, arg
)) {
1701 printf_err("Invalid --plugin-path option's argument:\n %s\n",
1712 * Prints the expected format for a --params option.
1715 void print_expected_params_format(FILE *fp
)
1717 fprintf(fp
, "Expected format of PARAMS\n");
1718 fprintf(fp
, "-------------------------\n");
1720 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
1722 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
1723 fprintf(fp
, "where PARAM is the parameter name (C identifier plus the [:.-] characters),\n");
1724 fprintf(fp
, "and VALUE can be one of:\n");
1726 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
1727 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
1728 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
1729 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
1730 fprintf(fp
, " (`0x` prefix) signed 64-bit integer.\n");
1731 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
1732 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
1733 fprintf(fp
, " the null and boolean value symbols above.\n");
1734 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
1736 fprintf(fp
, "You can put whitespaces allowed around individual `=` and `,` symbols.\n");
1738 fprintf(fp
, "Example:\n");
1740 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
1741 fprintf(fp
, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
1742 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
1744 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run babeltrace\n");
1745 fprintf(fp
, "from a shell.\n");
1750 * Prints the help command usage.
1753 void print_help_usage(FILE *fp
)
1755 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
1756 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --source=PLUGIN.CLS\n");
1757 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --filter=PLUGIN.CLS\n");
1758 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --sink=PLUGIN.CLS\n");
1760 fprintf(fp
, "Options:\n");
1762 fprintf(fp
, " -f, --filter=PLUGIN.CLS Get help for the filter component class\n");
1763 fprintf(fp
, " CLS found in the plugin PLUGIN\n");
1764 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1765 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1766 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1767 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1768 fprintf(fp
, " dynamic plugins can be loaded\n");
1769 fprintf(fp
, " -S, --sink=PLUGIN.CLS Get help for the sink component class\n");
1770 fprintf(fp
, " CLS found in the plugin PLUGIN\n");
1771 fprintf(fp
, " -s, --source=PLUGIN.CLS Get help for the source component class\n");
1772 fprintf(fp
, " CLS found in the plugin PLUGIN\n");
1773 fprintf(fp
, " -h --help Show this help and quit\n");
1775 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
1777 fprintf(fp
, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
1780 static struct poptOption help_long_options
[] = {
1781 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1782 { "filter", 'f', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
1783 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1784 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1785 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1786 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1787 { "sink", 'S', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
1788 { "source", 's', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
1789 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
1793 * Creates a Babeltrace config object from the arguments of a help
1796 * *retcode is set to the appropriate exit code to use.
1799 struct bt_config
*bt_config_help_from_args(int argc
, const char *argv
[],
1800 int *retcode
, bool omit_system_plugin_path
,
1801 bool omit_home_plugin_path
,
1802 struct bt_value
*initial_plugin_paths
)
1804 poptContext pc
= NULL
;
1808 struct bt_config
*cfg
= NULL
;
1809 const char *leftover
;
1810 char *plugin_name
= NULL
, *comp_cls_name
= NULL
;
1811 char *plug_comp_cls_names
= NULL
;
1814 cfg
= bt_config_help_create(initial_plugin_paths
);
1819 cfg
->omit_system_plugin_path
= omit_system_plugin_path
;
1820 cfg
->omit_home_plugin_path
= omit_home_plugin_path
;
1821 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
1827 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
1828 help_long_options
, 0);
1830 printf_err("Cannot get popt context\n");
1834 poptReadDefaultConfig(pc
, 0);
1836 while ((opt
= poptGetNextOpt(pc
)) > 0) {
1837 arg
= poptGetOptArg(pc
);
1840 case OPT_PLUGIN_PATH
:
1841 if (bt_config_append_plugin_paths_check_setuid_setgid(
1842 cfg
->plugin_paths
, arg
)) {
1846 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
1847 cfg
->omit_system_plugin_path
= true;
1849 case OPT_OMIT_HOME_PLUGIN_PATH
:
1850 cfg
->omit_home_plugin_path
= true;
1855 if (cfg
->cmd_data
.help
.cfg_component
->type
!=
1856 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
1857 printf_err("Cannot specify more than one plugin and component class:\n %s\n",
1864 cfg
->cmd_data
.help
.cfg_component
->type
=
1865 BT_COMPONENT_CLASS_TYPE_SOURCE
;
1868 cfg
->cmd_data
.help
.cfg_component
->type
=
1869 BT_COMPONENT_CLASS_TYPE_FILTER
;
1872 cfg
->cmd_data
.help
.cfg_component
->type
=
1873 BT_COMPONENT_CLASS_TYPE_SINK
;
1878 plug_comp_cls_names
= strdup(arg
);
1879 if (!plug_comp_cls_names
) {
1885 print_help_usage(stdout
);
1890 printf_err("Unknown command-line option specified (option code %d)\n",
1899 /* Check for option parsing error */
1901 printf_err("While parsing command-line options, at option %s: %s\n",
1902 poptBadOption(pc
, 0), poptStrerror(opt
));
1906 leftover
= poptGetArg(pc
);
1908 if (cfg
->cmd_data
.help
.cfg_component
->type
!=
1909 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
1910 printf_err("Cannot specify plugin name and --source/--filter/--sink component class:\n %s\n",
1915 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1918 if (cfg
->cmd_data
.help
.cfg_component
->type
==
1919 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
1920 print_help_usage(stdout
);
1926 plugin_comp_cls_names(plug_comp_cls_names
, NULL
,
1927 &plugin_name
, &comp_cls_name
);
1928 if (plugin_name
&& comp_cls_name
) {
1929 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1931 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
,
1934 printf_err("Invalid --source/--filter/--sink option's argument:\n %s\n",
1935 plug_comp_cls_names
);
1940 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
1951 free(plug_comp_cls_names
);
1952 g_free(plugin_name
);
1953 g_free(comp_cls_name
);
1956 poptFreeContext(pc
);
1964 * Prints the help command usage.
1967 void print_query_usage(FILE *fp
)
1969 fprintf(fp
, "Usage: babeltrace [GEN OPTS] query [OPTS] OBJECT --source=PLUGIN.CLS\n");
1970 fprintf(fp
, " babeltrace [GEN OPTS] query [OPTS] OBJECT --filter=PLUGIN.CLS\n");
1971 fprintf(fp
, " babeltrace [GEN OPTS] query [OPTS] OBJECT --sink=PLUGIN.CLS\n");
1973 fprintf(fp
, "Options:\n");
1975 fprintf(fp
, " -f. --filter=PLUGIN.CLS Query object from the filter component\n");
1976 fprintf(fp
, " class CLS found in the plugin PLUGIN\n");
1977 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1978 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1979 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1980 fprintf(fp
, " -p, --params=PARAMS Set the query parameters to PARAMS\n");
1981 fprintf(fp
, " (see the expected format of PARAMS below)\n");
1982 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1983 fprintf(fp
, " dynamic plugins can be loaded\n");
1984 fprintf(fp
, " -S, --sink=PLUGIN.CLS Query object from the sink component class\n");
1985 fprintf(fp
, " CLS found in the plugin PLUGIN\n");
1986 fprintf(fp
, " -s, --source=PLUGIN.CLS Query object from the source component\n");
1987 fprintf(fp
, " class CLS found in the plugin PLUGIN\n");
1988 fprintf(fp
, " -h --help Show this help and quit\n");
1989 fprintf(fp
, "\n\n");
1990 print_expected_params_format(fp
);
1993 static struct poptOption query_long_options
[] = {
1994 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1995 { "filter", 'f', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
1996 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1997 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1998 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1999 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2000 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2001 { "sink", 'S', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
2002 { "source", 's', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
2003 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
2007 * Creates a Babeltrace config object from the arguments of a query
2010 * *retcode is set to the appropriate exit code to use.
2013 struct bt_config
*bt_config_query_from_args(int argc
, const char *argv
[],
2014 int *retcode
, bool omit_system_plugin_path
,
2015 bool omit_home_plugin_path
,
2016 struct bt_value
*initial_plugin_paths
)
2018 poptContext pc
= NULL
;
2022 struct bt_config
*cfg
= NULL
;
2023 const char *leftover
;
2024 struct bt_value
*params
= bt_value_null
;
2027 cfg
= bt_config_query_create(initial_plugin_paths
);
2032 cfg
->omit_system_plugin_path
=
2033 omit_system_plugin_path
;
2034 cfg
->omit_home_plugin_path
= omit_home_plugin_path
;
2035 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2041 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2042 query_long_options
, 0);
2044 printf_err("Cannot get popt context\n");
2048 poptReadDefaultConfig(pc
, 0);
2050 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2051 arg
= poptGetOptArg(pc
);
2054 case OPT_PLUGIN_PATH
:
2055 if (bt_config_append_plugin_paths_check_setuid_setgid(
2056 cfg
->plugin_paths
, arg
)) {
2060 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2061 cfg
->omit_system_plugin_path
= true;
2063 case OPT_OMIT_HOME_PLUGIN_PATH
:
2064 cfg
->omit_home_plugin_path
= true;
2070 enum bt_component_class_type type
;
2072 if (cfg
->cmd_data
.query
.cfg_component
) {
2073 printf_err("Cannot specify more than one plugin and component class:\n %s\n",
2080 type
= BT_COMPONENT_CLASS_TYPE_SOURCE
;
2083 type
= BT_COMPONENT_CLASS_TYPE_FILTER
;
2086 type
= BT_COMPONENT_CLASS_TYPE_SINK
;
2092 cfg
->cmd_data
.query
.cfg_component
=
2093 bt_config_component_from_arg(type
, arg
);
2094 if (!cfg
->cmd_data
.query
.cfg_component
) {
2095 printf_err("Invalid format for --source/--filter/--sink option's argument:\n %s\n",
2100 /* Default parameters: null */
2101 bt_put(cfg
->cmd_data
.query
.cfg_component
->params
);
2102 cfg
->cmd_data
.query
.cfg_component
->params
=
2108 params
= bt_value_from_arg(arg
);
2110 printf_err("Invalid format for --params option's argument:\n %s\n",
2117 print_query_usage(stdout
);
2122 printf_err("Unknown command-line option specified (option code %d)\n",
2131 if (!cfg
->cmd_data
.query
.cfg_component
) {
2132 printf_err("No target component class specified with --source/--filter/--sink option\n");
2137 BT_MOVE(cfg
->cmd_data
.query
.cfg_component
->params
, params
);
2139 /* Check for option parsing error */
2141 printf_err("While parsing command-line options, at option %s: %s\n",
2142 poptBadOption(pc
, 0), poptStrerror(opt
));
2147 * We need exactly one leftover argument which is the
2150 leftover
= poptGetArg(pc
);
2152 if (strlen(leftover
) == 0) {
2153 printf_err("Invalid empty object\n");
2157 g_string_assign(cfg
->cmd_data
.query
.object
, leftover
);
2159 print_query_usage(stdout
);
2165 leftover
= poptGetArg(pc
);
2167 printf_err("Unexpected argument: %s\n", leftover
);
2171 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2183 poptFreeContext(pc
);
2192 * Prints the list-plugins command usage.
2195 void print_list_plugins_usage(FILE *fp
)
2197 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
2199 fprintf(fp
, "Options:\n");
2201 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2202 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2203 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2204 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2205 fprintf(fp
, " dynamic plugins can be loaded\n");
2206 fprintf(fp
, " -h --help Show this help and quit\n");
2208 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2210 fprintf(fp
, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
2213 static struct poptOption list_plugins_long_options
[] = {
2214 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2215 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2216 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2217 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2218 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2219 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
2223 * Creates a Babeltrace config object from the arguments of a
2224 * list-plugins command.
2226 * *retcode is set to the appropriate exit code to use.
2229 struct bt_config
*bt_config_list_plugins_from_args(int argc
, const char *argv
[],
2230 int *retcode
, bool omit_system_plugin_path
,
2231 bool omit_home_plugin_path
,
2232 struct bt_value
*initial_plugin_paths
)
2234 poptContext pc
= NULL
;
2238 struct bt_config
*cfg
= NULL
;
2239 const char *leftover
;
2242 cfg
= bt_config_list_plugins_create(initial_plugin_paths
);
2247 cfg
->omit_system_plugin_path
= omit_system_plugin_path
;
2248 cfg
->omit_home_plugin_path
= omit_home_plugin_path
;
2249 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2255 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2256 list_plugins_long_options
, 0);
2258 printf_err("Cannot get popt context\n");
2262 poptReadDefaultConfig(pc
, 0);
2264 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2265 arg
= poptGetOptArg(pc
);
2268 case OPT_PLUGIN_PATH
:
2269 if (bt_config_append_plugin_paths_check_setuid_setgid(
2270 cfg
->plugin_paths
, arg
)) {
2274 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2275 cfg
->omit_system_plugin_path
= true;
2277 case OPT_OMIT_HOME_PLUGIN_PATH
:
2278 cfg
->omit_home_plugin_path
= true;
2281 print_list_plugins_usage(stdout
);
2286 printf_err("Unknown command-line option specified (option code %d)\n",
2295 /* Check for option parsing error */
2297 printf_err("While parsing command-line options, at option %s: %s\n",
2298 poptBadOption(pc
, 0), poptStrerror(opt
));
2302 leftover
= poptGetArg(pc
);
2304 printf_err("Unexpected argument: %s\n", leftover
);
2308 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2320 poptFreeContext(pc
);
2328 * Prints the run command usage.
2331 void print_run_usage(FILE *fp
)
2333 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] run [OPTIONS]\n");
2335 fprintf(fp
, "Options:\n");
2337 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
2338 fprintf(fp
, " for all the following components until\n");
2339 fprintf(fp
, " --reset-base-params is encountered\n");
2340 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2341 fprintf(fp
, " -c, --connect=CONNECTION Connect two created components (see the\n");
2342 fprintf(fp
, " expected format of CONNECTION below)\n");
2343 fprintf(fp
, " -f, --filter=[NAME:]PLUGIN.CLS Instantiate a filter component from plugin\n");
2344 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2345 fprintf(fp
, " the current component, and if NAME is\n");
2346 fprintf(fp
, " given, set its instance name to NAME\n");
2347 fprintf(fp
, " --key=KEY Set the current initialization string\n");
2348 fprintf(fp
, " parameter key to KEY (see --value)\n");
2349 fprintf(fp
, " -n, --name=NAME Set the name of the current component\n");
2350 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2351 fprintf(fp
, " names of the created components)\n");
2352 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2353 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2354 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2355 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2356 fprintf(fp
, " current component (see the expected format\n");
2357 fprintf(fp
, " of PARAMS below)\n");
2358 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2359 fprintf(fp
, " dynamic plugins can be loaded\n");
2360 fprintf(fp
, " -r, --reset-base-params Reset the current base parameters to an\n");
2361 fprintf(fp
, " empty map\n");
2362 fprintf(fp
, " -S, --sink=[NAME:]PLUGIN.CLS Instantiate a sink component from plugin\n");
2363 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2364 fprintf(fp
, " the current component, and if NAME is\n");
2365 fprintf(fp
, " given, set its instance name to NAME\n");
2366 fprintf(fp
, " -s, --source=[NAME:]PLUGIN.CLS Instantiate a source component from plugin\n");
2367 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2368 fprintf(fp
, " the current component, and if NAME is\n");
2369 fprintf(fp
, " given, set its instance name to NAME\n");
2370 fprintf(fp
, " --value=VAL Add a string initialization parameter to\n");
2371 fprintf(fp
, " the current component with a name given by\n");
2372 fprintf(fp
, " the last argument of the --key option and a\n");
2373 fprintf(fp
, " value set to VAL\n");
2374 fprintf(fp
, " -h --help Show this help and quit\n");
2376 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2377 fprintf(fp
, "\n\n");
2378 fprintf(fp
, "Expected format of CONNECTION\n");
2379 fprintf(fp
, "-----------------------------\n");
2381 fprintf(fp
, " UPSTREAM[.UPSTREAM-PORT]:DOWNSTREAM[.DOWNSTREAM-PORT]\n");
2383 fprintf(fp
, "UPSTREAM and DOWNSTREAM are the names of the upstream and downstream components\n");
2384 fprintf(fp
, "to connect together. You can set the name of the current component with the\n");
2385 fprintf(fp
, "--name option.\n");
2387 fprintf(fp
, "UPSTREAM-PORT and DOWNSTREAM-PORT are the optional upstream and downstream\n");
2388 fprintf(fp
, "ports to use for the connection. When the port is not specified, the default\n");
2389 fprintf(fp
, "port is used.\n");
2391 fprintf(fp
, "You can connect a source component to a filter or sink component. You\n");
2392 fprintf(fp
, "can connect a filter component to a sink component.\n");
2394 fprintf(fp
, "Example:\n");
2396 fprintf(fp
, " my-filter.top10:json-out\n");
2397 fprintf(fp
, "\n\n");
2398 print_expected_params_format(fp
);
2401 static struct poptOption run_long_options
[] = {
2402 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2403 { "base-params", 'b', POPT_ARG_STRING
, NULL
, OPT_BASE_PARAMS
, NULL
, NULL
},
2404 { "connect", 'c', POPT_ARG_STRING
, NULL
, OPT_CONNECT
, NULL
, NULL
},
2405 { "filter", 'f', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
2406 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2407 { "key", '\0', POPT_ARG_STRING
, NULL
, OPT_KEY
, NULL
, NULL
},
2408 { "name", 'n', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2409 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2410 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2411 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2412 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2413 { "reset-base-params", 'r', POPT_ARG_NONE
, NULL
, OPT_RESET_BASE_PARAMS
, NULL
, NULL
},
2414 { "sink", 'S', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
2415 { "source", 's', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
2416 { "value", '\0', POPT_ARG_STRING
, NULL
, OPT_VALUE
, NULL
, NULL
},
2417 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
2421 * Creates a Babeltrace config object from the arguments of a run
2424 * *retcode is set to the appropriate exit code to use.
2427 struct bt_config
*bt_config_run_from_args(int argc
, const char *argv
[],
2428 int *retcode
, bool omit_system_plugin_path
,
2429 bool omit_home_plugin_path
,
2430 struct bt_value
*initial_plugin_paths
)
2432 poptContext pc
= NULL
;
2434 struct bt_config_component
*cur_cfg_comp
= NULL
;
2435 enum bt_config_component_dest cur_cfg_comp_dest
;
2436 struct bt_value
*cur_base_params
= NULL
;
2438 struct bt_config
*cfg
= NULL
;
2439 struct bt_value
*instance_names
= NULL
;
2440 struct bt_value
*connection_args
= NULL
;
2441 GString
*cur_param_key
= NULL
;
2442 char error_buf
[256] = { 0 };
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
->omit_system_plugin_path
= omit_system_plugin_path
;
2463 cfg
->omit_home_plugin_path
= omit_home_plugin_path
;
2464 cur_base_params
= bt_value_map_create();
2465 if (!cur_base_params
) {
2470 instance_names
= bt_value_map_create();
2471 if (!instance_names
) {
2476 connection_args
= bt_value_array_create();
2477 if (!connection_args
) {
2482 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2488 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2489 run_long_options
, 0);
2491 printf_err("Cannot get popt context\n");
2495 poptReadDefaultConfig(pc
, 0);
2497 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2498 arg
= poptGetOptArg(pc
);
2501 case OPT_PLUGIN_PATH
:
2502 if (bt_config_append_plugin_paths_check_setuid_setgid(
2503 cfg
->plugin_paths
, arg
)) {
2507 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2508 cfg
->omit_system_plugin_path
= true;
2510 case OPT_OMIT_HOME_PLUGIN_PATH
:
2511 cfg
->omit_home_plugin_path
= true;
2517 enum bt_component_class_type new_comp_type
;
2518 enum bt_config_component_dest new_dest
;
2519 const char *opt_name
;
2523 new_comp_type
= BT_COMPONENT_CLASS_TYPE_SOURCE
;
2524 new_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
2525 opt_name
= "--source";
2528 new_comp_type
= BT_COMPONENT_CLASS_TYPE_FILTER
;
2529 new_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
2530 opt_name
= "--filter";
2533 new_comp_type
= BT_COMPONENT_CLASS_TYPE_SINK
;
2534 new_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
2535 opt_name
= "--sink";
2542 ret
= add_run_cfg_comp_check_name(cfg
,
2543 cur_cfg_comp
, cur_cfg_comp_dest
,
2545 BT_PUT(cur_cfg_comp
);
2551 cur_cfg_comp
= bt_config_component_from_arg(
2552 new_comp_type
, arg
);
2553 if (!cur_cfg_comp
) {
2554 printf_err("Invalid format for %s option's argument:\n %s\n",
2559 assert(cur_base_params
);
2560 bt_put(cur_cfg_comp
->params
);
2561 cur_cfg_comp
->params
= bt_value_copy(cur_base_params
);
2562 if (!cur_cfg_comp
->params
) {
2567 cur_cfg_comp_dest
= new_dest
;
2572 struct bt_value
*params
;
2573 struct bt_value
*params_to_set
;
2575 if (!cur_cfg_comp
) {
2576 printf_err("Cannot add parameters to unavailable component:\n %s\n",
2581 params
= bt_value_from_arg(arg
);
2583 printf_err("Invalid format for --params option's argument:\n %s\n",
2588 params_to_set
= bt_value_map_extend(cur_cfg_comp
->params
,
2591 if (!params_to_set
) {
2592 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
2597 BT_MOVE(cur_cfg_comp
->params
, params_to_set
);
2601 if (strlen(arg
) == 0) {
2602 printf_err("Cannot set an empty string as the current parameter key\n");
2606 g_string_assign(cur_param_key
, arg
);
2609 if (!cur_cfg_comp
) {
2610 printf_err("Cannot set a parameter's value of unavailable component:\n %s\n",
2615 if (cur_param_key
->len
== 0) {
2616 printf_err("--value option specified without preceding --key option:\n %s\n",
2621 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
2622 cur_param_key
->str
, arg
)) {
2628 if (!cur_cfg_comp
) {
2629 printf_err("Cannot set the name of unavailable component:\n %s\n",
2634 g_string_assign(cur_cfg_comp
->instance_name
, arg
);
2636 case OPT_BASE_PARAMS
:
2638 struct bt_value
*params
= bt_value_from_arg(arg
);
2641 printf_err("Invalid format for --base-params option's argument:\n %s\n",
2646 BT_MOVE(cur_base_params
, params
);
2649 case OPT_RESET_BASE_PARAMS
:
2650 BT_PUT(cur_base_params
);
2651 cur_base_params
= bt_value_map_create();
2652 if (!cur_base_params
) {
2658 if (bt_value_array_append_string(connection_args
,
2665 print_run_usage(stdout
);
2670 printf_err("Unknown command-line option specified (option code %d)\n",
2679 /* Check for option parsing error */
2681 printf_err("While parsing command-line options, at option %s: %s\n",
2682 poptBadOption(pc
, 0), poptStrerror(opt
));
2686 /* This command does not accept leftover arguments */
2687 if (poptPeekArg(pc
)) {
2688 printf_err("Unexpected argument: %s\n", poptPeekArg(pc
));
2692 /* Add current component */
2694 ret
= add_run_cfg_comp_check_name(cfg
, cur_cfg_comp
,
2695 cur_cfg_comp_dest
, instance_names
);
2696 BT_PUT(cur_cfg_comp
);
2702 if (cfg
->cmd_data
.run
.sources
->len
== 0) {
2703 printf_err("Incomplete graph: no source component\n");
2707 if (cfg
->cmd_data
.run
.sinks
->len
== 0) {
2708 printf_err("Incomplete graph: no sink component\n");
2712 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2716 ret
= bt_config_create_connections(cfg
, connection_args
,
2719 printf_err("Cannot creation connections:\n%s", error_buf
);
2731 poptFreeContext(pc
);
2734 if (cur_param_key
) {
2735 g_string_free(cur_param_key
, TRUE
);
2739 BT_PUT(cur_cfg_comp
);
2740 BT_PUT(cur_base_params
);
2741 BT_PUT(instance_names
);
2742 BT_PUT(connection_args
);
2747 struct bt_config
*bt_config_run_from_args_array(struct bt_value
*run_args
,
2748 int *retcode
, bool omit_system_plugin_path
,
2749 bool omit_home_plugin_path
,
2750 struct bt_value
*initial_plugin_paths
)
2752 struct bt_config
*cfg
= NULL
;
2755 const size_t argc
= bt_value_array_size(run_args
) + 1;
2757 argv
= calloc(argc
, sizeof(*argv
));
2765 for (i
= 0; i
< bt_value_array_size(run_args
); i
++) {
2767 struct bt_value
*arg_value
= bt_value_array_get(run_args
, i
);
2771 ret
= bt_value_string_get(arg_value
, &arg
);
2778 cfg
= bt_config_run_from_args(argc
, argv
, retcode
,
2779 omit_system_plugin_path
, omit_home_plugin_path
,
2780 initial_plugin_paths
);
2788 * Prints the convert command usage.
2791 void print_convert_usage(FILE *fp
)
2793 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [convert] [OPTIONS] [PATH/URL]\n");
2795 fprintf(fp
, "Options:\n");
2797 fprintf(fp
, " --filter=[NAME:]PLUGIN.CLS Instantiate a filter component from plugin\n");
2798 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2799 fprintf(fp
, " the current component, and if NAME is\n");
2800 fprintf(fp
, " given, set its instance name to NAME\n");
2801 fprintf(fp
, " --name=NAME Set the name of the current component\n");
2802 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2803 fprintf(fp
, " names of the created components)\n");
2804 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2805 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2806 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2807 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2808 fprintf(fp
, " current component (see the expected format\n");
2809 fprintf(fp
, " of PARAMS below)\n");
2810 fprintf(fp
, " -P, --path=PATH Set the `path` string parameter of the\n");
2811 fprintf(fp
, " current component to PATH\n");
2812 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2813 fprintf(fp
, " dynamic plugins can be loaded\n");
2814 fprintf(fp
, " --run-args Print the equivalent arguments for the\n");
2815 fprintf(fp
, " `run` command to the standard output,\n");
2816 fprintf(fp
, " formatted for a shell, and quit\n");
2817 fprintf(fp
, " --run-args-0 Print the equivalent arguments for the\n");
2818 fprintf(fp
, " `run` command to the standard output,\n");
2819 fprintf(fp
, " formatted for `xargs -0`, and quit\n");
2820 fprintf(fp
, " --sink=[NAME:]PLUGIN.CLS Instantiate a sink component from plugin\n");
2821 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2822 fprintf(fp
, " the current component, and if NAME is\n");
2823 fprintf(fp
, " given, set its instance name to NAME\n");
2824 fprintf(fp
, " --source=[NAME:]PLUGIN.CLS Instantiate a source component from plugin\n");
2825 fprintf(fp
, " PLUGIN and component class CLS, set it as\n");
2826 fprintf(fp
, " the current component, and if NAME is\n");
2827 fprintf(fp
, " given, set its instance name to NAME\n");
2828 fprintf(fp
, " -u, --url=URL Set the `url` string parameter of the\n");
2829 fprintf(fp
, " current component to URL\n");
2830 fprintf(fp
, " -h --help Show this help and quit\n");
2832 fprintf(fp
, "Implicit `ctf.fs` source component options:\n");
2834 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
2835 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS ns\n");
2836 fprintf(fp
, " --stream-intersection Only process events when all streams\n");
2837 fprintf(fp
, " are active\n");
2839 fprintf(fp
, "Implicit `text.text` sink component options:\n");
2841 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
2842 fprintf(fp
, " --clock-date Print timestamp dates\n");
2843 fprintf(fp
, " --clock-gmt Print and parse timestamps in the GMT\n");
2844 fprintf(fp
, " time zone instead of the local time zone\n");
2845 fprintf(fp
, " --clock-seconds Print the timestamps as `SEC.NS` instead\n");
2846 fprintf(fp
, " of `hh:mm:ss.nnnnnnnnn`\n");
2847 fprintf(fp
, " --color=(never | auto | always)\n");
2848 fprintf(fp
, " Never, automatically, or always emit\n");
2849 fprintf(fp
, " console color codes\n");
2850 fprintf(fp
, " -f, --fields=FIELD[,FIELD]... Print additional fields; FIELD can be:\n");
2851 fprintf(fp
, " `all`, `trace`, `trace:hostname`,\n");
2852 fprintf(fp
, " `trace:domain`, `trace:procname`,\n");
2853 fprintf(fp
, " `trace:vpid`, `loglevel`, `emf`\n");
2854 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names; NAME can be:\n");
2855 fprintf(fp
, " `payload` (or `arg` or `args`), `none`,\n");
2856 fprintf(fp
, " `all`, `scope`, `header`, `context`\n");
2857 fprintf(fp
, " (or `ctx`)\n");
2858 fprintf(fp
, " --no-delta Do not print time delta between\n");
2859 fprintf(fp
, " consecutive events\n");
2860 fprintf(fp
, " -w, --output=PATH Write output text to PATH instead of\n");
2861 fprintf(fp
, " the standard output\n");
2863 fprintf(fp
, "Implicit `utils.muxer` filter component options:\n");
2865 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently\n");
2866 fprintf(fp
, " correlated across traces\n");
2868 fprintf(fp
, "Implicit `utils.trimmer` filter component options:\n");
2870 fprintf(fp
, " -b, --begin=BEGIN Set the beginning time of the conversion\n");
2871 fprintf(fp
, " time range to BEGIN (see the format of\n");
2872 fprintf(fp
, " BEGIN below)\n");
2873 fprintf(fp
, " -e, --end=END Set the end time of the conversion time\n");
2874 fprintf(fp
, " range to END (see the format of END below)\n");
2875 fprintf(fp
, " -t, --timerange=TIMERANGE Set conversion time range to TIMERANGE:\n");
2876 fprintf(fp
, " BEGIN,END or [BEGIN,END] (literally `[` and\n");
2877 fprintf(fp
, " `]`) (see the format of BEGIN/END below)\n");
2879 fprintf(fp
, "Implicit `lttng-utils.debug-info` filter component options:\n");
2881 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
2882 fprintf(fp
, " instead of `/usr/lib/debug`\n");
2883 fprintf(fp
, " --debug-info-full-path Show full debug info source and\n");
2884 fprintf(fp
, " binary paths instead of just names\n");
2885 fprintf(fp
, " --debug-info-target-prefix=DIR\n");
2886 fprintf(fp
, " Use directory DIR as a prefix when\n");
2887 fprintf(fp
, " looking up executables during debug\n");
2888 fprintf(fp
, " info analysis\n");
2889 fprintf(fp
, " --no-debug-info Do not create an implicit\n");
2890 fprintf(fp
, " `lttng-utils.debug-info` filter component\n");
2892 fprintf(fp
, "Legacy options that still work:\n");
2894 fprintf(fp
, " -i, --input-format=(ctf | lttng-live)\n");
2895 fprintf(fp
, " `ctf`:\n");
2896 fprintf(fp
, " Create an implicit `ctf.fs` source\n");
2897 fprintf(fp
, " component\n");
2898 fprintf(fp
, " `lttng-live`:\n");
2899 fprintf(fp
, " Create an implicit `ctf.lttng-live`\n");
2900 fprintf(fp
, " source component\n");
2901 fprintf(fp
, " -o, --output-format=(text | dummy | ctf-metadata)\n");
2902 fprintf(fp
, " `text`:\n");
2903 fprintf(fp
, " Create an implicit `text.text` sink\n");
2904 fprintf(fp
, " component\n");
2905 fprintf(fp
, " `dummy`:\n");
2906 fprintf(fp
, " Create an implicit `utils.dummy` sink\n");
2907 fprintf(fp
, " component\n");
2908 fprintf(fp
, " `ctf-metadata`:\n");
2909 fprintf(fp
, " Query the `ctf.fs` component class for\n");
2910 fprintf(fp
, " metadata text and quit\n");
2912 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2913 fprintf(fp
, "\n\n");
2914 fprintf(fp
, "Format of BEGIN and END\n");
2915 fprintf(fp
, "-----------------------\n");
2917 fprintf(fp
, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
2918 fprintf(fp
, "\n\n");
2919 print_expected_params_format(fp
);
2922 static struct poptOption convert_long_options
[] = {
2923 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2924 { "begin", 'b', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2925 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2926 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2927 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2928 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2929 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2930 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2931 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2932 { "color", '\0', POPT_ARG_STRING
, NULL
, OPT_COLOR
, NULL
, NULL
},
2933 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2934 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2935 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2936 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2937 { "end", 'e', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2938 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2939 { "filter", '\0', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
2940 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2941 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2942 { "name", '\0', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2943 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2944 { "no-debug-info", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DEBUG_INFO
, NULL
, NULL
},
2945 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2946 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2947 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2948 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT
, NULL
, NULL
},
2949 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2950 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2951 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2952 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2953 { "run-args", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS
, NULL
, NULL
},
2954 { "run-args-0", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS_0
, NULL
, NULL
},
2955 { "sink", '\0', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
2956 { "source", '\0', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
2957 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2958 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2959 { "url", 'u', POPT_ARG_STRING
, NULL
, OPT_URL
, NULL
, NULL
},
2960 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2961 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
2965 GString
*get_component_auto_name(const char *prefix
,
2966 struct bt_value
*existing_names
)
2969 GString
*auto_name
= g_string_new(NULL
);
2976 if (!bt_value_map_has_key(existing_names
, prefix
)) {
2977 g_string_assign(auto_name
, prefix
);
2982 g_string_printf(auto_name
, "%s-%d", prefix
, i
);
2984 } while (bt_value_map_has_key(existing_names
, auto_name
->str
));
2990 struct implicit_component_args
{
2992 GString
*plugin_comp_cls_arg
;
2994 GString
*params_arg
;
2995 struct bt_value
*extra_args
;
2999 int assign_name_to_implicit_component(struct implicit_component_args
*args
,
3000 const char *prefix
, struct bt_value
*existing_names
,
3001 GList
**comp_names
, bool append_to_comp_names
)
3004 GString
*name
= NULL
;
3006 if (!args
->exists
) {
3010 name
= get_component_auto_name(prefix
, existing_names
);
3017 g_string_assign(args
->name_arg
, name
->str
);
3019 if (bt_value_map_insert(existing_names
, name
->str
,
3026 if (append_to_comp_names
) {
3027 *comp_names
= g_list_append(*comp_names
, name
);
3033 g_string_free(name
, TRUE
);
3040 int append_run_args_for_implicit_component(
3041 enum bt_component_class_type type
,
3042 struct implicit_component_args
*impl_args
,
3043 struct bt_value
*run_args
)
3048 if (!impl_args
->exists
) {
3053 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
3054 if (bt_value_array_append_string(run_args
, "--source")) {
3059 case BT_COMPONENT_CLASS_TYPE_FILTER
:
3060 if (bt_value_array_append_string(run_args
, "--filter")) {
3065 case BT_COMPONENT_CLASS_TYPE_SINK
:
3066 if (bt_value_array_append_string(run_args
, "--sink")) {
3075 if (bt_value_array_append_string(run_args
,
3076 impl_args
->plugin_comp_cls_arg
->str
)) {
3081 if (bt_value_array_append_string(run_args
, "--name")) {
3086 if (bt_value_array_append_string(run_args
, impl_args
->name_arg
->str
)) {
3091 if (impl_args
->params_arg
->len
> 0) {
3092 if (bt_value_array_append_string(run_args
, "--params")) {
3097 if (bt_value_array_append_string(run_args
,
3098 impl_args
->params_arg
->str
)) {
3104 for (i
= 0; i
< bt_value_array_size(impl_args
->extra_args
); i
++) {
3105 struct bt_value
*elem
;
3108 elem
= bt_value_array_get(impl_args
->extra_args
, i
);
3113 assert(bt_value_is_string(elem
));
3114 if (bt_value_string_get(elem
, &arg
)) {
3118 ret
= bt_value_array_append_string(run_args
, arg
);
3136 void destroy_implicit_component_args(struct implicit_component_args
*args
)
3140 if (args
->plugin_comp_cls_arg
) {
3141 g_string_free(args
->plugin_comp_cls_arg
, TRUE
);
3144 if (args
->name_arg
) {
3145 g_string_free(args
->name_arg
, TRUE
);
3148 if (args
->params_arg
) {
3149 g_string_free(args
->params_arg
, TRUE
);
3152 bt_put(args
->extra_args
);
3156 int init_implicit_component_args(struct implicit_component_args
*args
,
3157 const char *plugin_comp_cls_arg
, bool exists
)
3161 args
->exists
= exists
;
3162 args
->plugin_comp_cls_arg
= g_string_new(plugin_comp_cls_arg
);
3163 args
->name_arg
= g_string_new(NULL
);
3164 args
->params_arg
= g_string_new(NULL
);
3165 args
->extra_args
= bt_value_array_create();
3167 if (!args
->plugin_comp_cls_arg
|| !args
->name_arg
||
3168 !args
->params_arg
|| !args
->extra_args
) {
3170 destroy_implicit_component_args(args
);
3180 void append_implicit_component_param(struct implicit_component_args
*args
,
3181 const char *key
, const char *value
)
3186 append_param_arg(args
->params_arg
, key
, value
);
3190 int append_implicit_component_extra_arg(struct implicit_component_args
*args
,
3191 const char *key
, const char *value
)
3199 if (bt_value_array_append_string(args
->extra_args
, "--key")) {
3205 if (bt_value_array_append_string(args
->extra_args
, key
)) {
3211 if (bt_value_array_append_string(args
->extra_args
, "--value")) {
3217 if (bt_value_array_append_string(args
->extra_args
, value
)) {
3228 int convert_append_name_param(enum bt_config_component_dest dest
,
3229 GString
*cur_name
, GString
*cur_name_prefix
,
3230 struct bt_value
*run_args
, struct bt_value
*all_names
,
3231 GList
**source_names
, GList
**filter_names
,
3236 if (cur_name_prefix
->len
> 0) {
3237 /* We're after a --source/--filter/--sink */
3238 GString
*name
= NULL
;
3239 bool append_name_opt
= false;
3241 if (cur_name
->len
== 0) {
3243 * No explicit name was provided for the user
3246 name
= get_component_auto_name(
3247 cur_name_prefix
->str
,
3249 append_name_opt
= true;
3252 * An explicit name was provided for the user
3255 if (bt_value_map_has_key(all_names
,
3257 printf_err("Duplicate component instance name:\n %s\n",
3262 name
= g_string_new(cur_name
->str
);
3271 * Remember this name globally, for the uniqueness of
3272 * all component names.
3274 if (bt_value_map_insert(all_names
, name
->str
, bt_value_null
)) {
3280 * Append the --name option if necessary.
3282 if (append_name_opt
) {
3283 if (bt_value_array_append_string(run_args
, "--name")) {
3288 if (bt_value_array_append_string(run_args
, name
->str
)) {
3295 * Remember this name specifically for the type of the
3296 * component. This is to create connection arguments.
3299 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
3300 *source_names
= g_list_append(*source_names
, name
);
3302 case BT_CONFIG_COMPONENT_DEST_FILTER
:
3303 *filter_names
= g_list_append(*filter_names
, name
);
3305 case BT_CONFIG_COMPONENT_DEST_SINK
:
3306 *sink_names
= g_list_append(*sink_names
, name
);
3312 g_string_assign(cur_name_prefix
, "");
3325 * Escapes `.`, `:`, and `\` of `input` with `\`.
3327 GString
*escape_dot_colon(const char *input
)
3329 GString
*output
= g_string_new(NULL
);
3337 for (ch
= input
; *ch
!= '\0'; ch
++) {
3338 if (*ch
== '\\' || *ch
== '.' || *ch
== ':') {
3339 g_string_append_c(output
, '\\');
3342 g_string_append_c(output
, *ch
);
3350 * Appends a --connect option to a list of arguments. `upstream_name`
3351 * and `downstream_name` are escaped with escape_dot_colon() in this
3354 int append_connect_arg(struct bt_value
*run_args
,
3355 const char *upstream_name
, const char *downstream_name
)
3358 GString
*e_upstream_name
= escape_dot_colon(upstream_name
);
3359 GString
*e_downstream_name
= escape_dot_colon(downstream_name
);
3360 GString
*arg
= g_string_new(NULL
);
3362 if (!e_upstream_name
|| !e_downstream_name
|| !arg
) {
3368 ret
= bt_value_array_append_string(run_args
, "--connect");
3375 g_string_append(arg
, e_upstream_name
->str
);
3376 g_string_append_c(arg
, ':');
3377 g_string_append(arg
, e_downstream_name
->str
);
3378 ret
= bt_value_array_append_string(run_args
, arg
->str
);
3387 g_string_free(arg
, TRUE
);
3390 if (e_upstream_name
) {
3391 g_string_free(e_upstream_name
, TRUE
);
3394 if (e_downstream_name
) {
3395 g_string_free(e_downstream_name
, TRUE
);
3402 * Appends the run command's --connect options for the convert command.
3404 int convert_auto_connect(struct bt_value
*run_args
,
3405 GList
*source_names
, GList
*filter_names
,
3409 GList
*source_at
= source_names
;
3410 GList
*filter_at
= filter_names
;
3412 GList
*sink_at
= sink_names
;
3414 assert(source_names
);
3415 assert(filter_names
);
3418 /* Connect all sources to the first filter */
3419 for (source_at
= source_names
; source_at
!= NULL
; source_at
= g_list_next(source_at
)) {
3420 GString
*source_name
= source_at
->data
;
3421 GString
*filter_name
= filter_at
->data
;
3423 ret
= append_connect_arg(run_args
, source_name
->str
,
3430 filter_prev
= filter_at
;
3431 filter_at
= g_list_next(filter_at
);
3433 /* Connect remaining filters */
3434 for (; filter_at
!= NULL
; filter_prev
= filter_at
, filter_at
= g_list_next(filter_at
)) {
3435 GString
*filter_name
= filter_at
->data
;
3436 GString
*filter_prev_name
= filter_prev
->data
;
3438 ret
= append_connect_arg(run_args
, filter_prev_name
->str
,
3445 /* Connect last filter to all sinks */
3446 for (sink_at
= sink_names
; sink_at
!= NULL
; sink_at
= g_list_next(sink_at
)) {
3447 GString
*filter_name
= filter_prev
->data
;
3448 GString
*sink_name
= sink_at
->data
;
3450 ret
= append_connect_arg(run_args
, filter_name
->str
,
3466 static int split_timerange(const char *arg
, char **begin
, char **end
)
3469 const char *ch
= arg
;
3471 GString
*g_begin
= NULL
;
3472 GString
*g_end
= NULL
;
3480 g_begin
= bt_common_string_until(ch
, "", ",", &end_pos
);
3481 if (!g_begin
|| ch
[end_pos
] != ',' || g_begin
->len
== 0) {
3487 g_end
= bt_common_string_until(ch
, "", "]", &end_pos
);
3488 if (!g_end
|| g_end
->len
== 0) {
3494 *begin
= g_begin
->str
;
3496 g_string_free(g_begin
, FALSE
);
3497 g_string_free(g_end
, FALSE
);
3507 g_string_free(g_begin
, TRUE
);
3511 g_string_free(g_end
, TRUE
);
3518 int g_list_prepend_gstring(GList
**list
, const char *string
)
3521 GString
*gs
= g_string_new(string
);
3530 *list
= g_list_prepend(*list
, gs
);
3537 * Creates a Babeltrace config object from the arguments of a convert
3540 * *retcode is set to the appropriate exit code to use.
3543 struct bt_config
*bt_config_convert_from_args(int argc
, const char *argv
[],
3544 int *retcode
, bool omit_system_plugin_path
,
3545 bool omit_home_plugin_path
,
3546 struct bt_value
*initial_plugin_paths
)
3548 poptContext pc
= NULL
;
3550 enum bt_config_component_dest cur_comp_dest
;
3552 struct bt_config
*cfg
= NULL
;
3553 bool got_verbose_opt
= false;
3554 bool got_debug_opt
= false;
3555 bool got_input_format_opt
= false;
3556 bool got_output_format_opt
= false;
3557 bool trimmer_has_begin
= false;
3558 bool trimmer_has_end
= false;
3559 GString
*cur_name
= NULL
;
3560 GString
*cur_name_prefix
= NULL
;
3561 const char *leftover
= NULL
;
3562 bool print_run_args
= false;
3563 bool print_run_args_0
= false;
3564 bool print_ctf_metadata
= false;
3565 struct bt_value
*run_args
= NULL
;
3566 struct bt_value
*all_names
= NULL
;
3567 GList
*source_names
= NULL
;
3568 GList
*filter_names
= NULL
;
3569 GList
*sink_names
= NULL
;
3570 struct implicit_component_args implicit_ctf_args
= { 0 };
3571 struct implicit_component_args implicit_lttng_live_args
= { 0 };
3572 struct implicit_component_args implicit_dummy_args
= { 0 };
3573 struct implicit_component_args implicit_text_args
= { 0 };
3574 struct implicit_component_args implicit_debug_info_args
= { 0 };
3575 struct implicit_component_args implicit_muxer_args
= { 0 };
3576 struct implicit_component_args implicit_trimmer_args
= { 0 };
3577 struct bt_value
*plugin_paths
= bt_get(initial_plugin_paths
);
3578 char error_buf
[256] = { 0 };
3580 struct bt_common_lttng_live_url_parts lttng_live_url_parts
= { 0 };
3585 print_convert_usage(stdout
);
3590 if (init_implicit_component_args(&implicit_ctf_args
, "ctf.fs", false)) {
3594 if (init_implicit_component_args(&implicit_lttng_live_args
,
3595 "ctf.lttng-live", false)) {
3599 if (init_implicit_component_args(&implicit_text_args
, "text.text",
3604 if (init_implicit_component_args(&implicit_dummy_args
, "utils.dummy",
3609 if (init_implicit_component_args(&implicit_debug_info_args
,
3610 "lttng-utils.debug-info", true)) {
3614 if (init_implicit_component_args(&implicit_muxer_args
, "utils.muxer",
3619 if (init_implicit_component_args(&implicit_trimmer_args
,
3620 "utils.trimmer", false)) {
3624 all_names
= bt_value_map_create();
3630 run_args
= bt_value_array_create();
3636 cur_name
= g_string_new(NULL
);
3642 cur_name_prefix
= g_string_new(NULL
);
3643 if (!cur_name_prefix
) {
3648 ret
= append_env_var_plugin_paths(plugin_paths
);
3654 * First pass: collect all arguments which need to be passed
3655 * as is to the run command. This pass can also add --name
3656 * arguments if needed to automatically name unnamed component
3657 * instances. Also it does the following transformations:
3659 * --path=PATH -> --key path --value PATH
3660 * --url=URL -> --key url --value URL
3662 * Also it appends the plugin paths of --plugin-path to
3665 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3666 convert_long_options
, 0);
3668 printf_err("Cannot get popt context\n");
3672 poptReadDefaultConfig(pc
, 0);
3674 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3676 char *plugin_name
= NULL
;
3677 char *comp_cls_name
= NULL
;
3679 arg
= poptGetOptArg(pc
);
3685 /* Append current component's name if needed */
3686 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3687 cur_name_prefix
, run_args
, all_names
,
3688 &source_names
, &filter_names
, &sink_names
);
3693 /* Parse the argument */
3694 plugin_comp_cls_names(arg
, &name
, &plugin_name
,
3696 if (!plugin_name
|| !comp_cls_name
) {
3697 printf_err("Invalid format for --source/--filter/--sink option's argument:\n %s\n",
3703 g_string_assign(cur_name
, name
);
3705 g_string_assign(cur_name
, "");
3711 BT_CONFIG_COMPONENT_DEST_SOURCE
;
3712 if (bt_value_array_append_string(run_args
,
3720 BT_CONFIG_COMPONENT_DEST_FILTER
;
3721 if (bt_value_array_append_string(run_args
,
3729 BT_CONFIG_COMPONENT_DEST_SINK
;
3730 if (bt_value_array_append_string(run_args
,
3740 if (bt_value_array_append_string(run_args
, arg
)) {
3745 g_string_assign(cur_name_prefix
, "");
3746 g_string_append(cur_name_prefix
, plugin_name
);
3747 g_string_append_c(cur_name_prefix
, '.');
3748 g_string_append(cur_name_prefix
, comp_cls_name
);
3751 free(comp_cls_name
);
3754 comp_cls_name
= NULL
;
3757 if (cur_name_prefix
->len
== 0) {
3758 printf_err("No current component of which to set parameters:\n %s\n",
3763 if (bt_value_array_append_string(run_args
,
3769 if (bt_value_array_append_string(run_args
, arg
)) {
3775 if (cur_name_prefix
->len
== 0) {
3776 printf_err("No current component of which to set `path` parameter:\n %s\n",
3781 if (bt_value_array_append_string(run_args
, "--key")) {
3786 if (bt_value_array_append_string(run_args
, "path")) {
3791 if (bt_value_array_append_string(run_args
, "--value")) {
3796 if (bt_value_array_append_string(run_args
, arg
)) {
3802 if (cur_name_prefix
->len
== 0) {
3803 printf_err("No current component of which to set `url` parameter:\n %s\n",
3808 if (bt_value_array_append_string(run_args
, "--key")) {
3813 if (bt_value_array_append_string(run_args
, "url")) {
3818 if (bt_value_array_append_string(run_args
, "--value")) {
3823 if (bt_value_array_append_string(run_args
, arg
)) {
3829 if (cur_name_prefix
->len
== 0) {
3830 printf_err("No current component to name:\n %s\n",
3835 if (bt_value_array_append_string(run_args
, "--name")) {
3840 if (bt_value_array_append_string(run_args
, arg
)) {
3845 g_string_assign(cur_name
, arg
);
3847 case OPT_OMIT_HOME_PLUGIN_PATH
:
3848 if (bt_value_array_append_string(run_args
,
3849 "--omit-home-plugin-path")) {
3854 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
3855 if (bt_value_array_append_string(run_args
,
3856 "--omit-system-plugin-path")) {
3861 case OPT_PLUGIN_PATH
:
3862 if (bt_config_append_plugin_paths_check_setuid_setgid(
3863 plugin_paths
, arg
)) {
3867 if (bt_value_array_append_string(run_args
,
3873 if (bt_value_array_append_string(run_args
, arg
)) {
3879 print_convert_usage(stdout
);
3884 case OPT_CLOCK_CYCLES
:
3885 case OPT_CLOCK_DATE
:
3886 case OPT_CLOCK_FORCE_CORRELATE
:
3888 case OPT_CLOCK_OFFSET
:
3889 case OPT_CLOCK_OFFSET_NS
:
3890 case OPT_CLOCK_SECONDS
:
3893 case OPT_DEBUG_INFO_DIR
:
3894 case OPT_DEBUG_INFO_FULL_PATH
:
3895 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3898 case OPT_INPUT_FORMAT
:
3900 case OPT_NO_DEBUG_INFO
:
3902 case OPT_OUTPUT_FORMAT
:
3905 case OPT_RUN_ARGS_0
:
3906 case OPT_STREAM_INTERSECTION
:
3909 /* Ignore in this pass */
3912 printf_err("Unknown command-line option specified (option code %d)\n",
3921 /* Append current component's name if needed */
3922 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3923 cur_name_prefix
, run_args
, all_names
, &source_names
,
3924 &filter_names
, &sink_names
);
3929 /* Check for option parsing error */
3931 printf_err("While parsing command-line options, at option %s: %s\n",
3932 poptBadOption(pc
, 0), poptStrerror(opt
));
3936 poptFreeContext(pc
);
3941 * Second pass: transform the convert-specific options and
3942 * arguments into implicit component instances for the run
3945 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3946 convert_long_options
, 0);
3948 printf_err("Cannot get popt context\n");
3952 poptReadDefaultConfig(pc
, 0);
3954 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3955 arg
= poptGetOptArg(pc
);
3959 if (trimmer_has_begin
) {
3960 printf("At --begin option: --begin or --timerange option already specified\n %s\n",
3965 trimmer_has_begin
= true;
3966 ret
= append_implicit_component_extra_arg(
3967 &implicit_trimmer_args
, "begin", arg
);
3968 implicit_trimmer_args
.exists
= true;
3974 if (trimmer_has_end
) {
3975 printf("At --end option: --end or --timerange option already specified\n %s\n",
3980 trimmer_has_end
= true;
3981 ret
= append_implicit_component_extra_arg(
3982 &implicit_trimmer_args
, "end", arg
);
3983 implicit_trimmer_args
.exists
= true;
3993 if (trimmer_has_begin
|| trimmer_has_end
) {
3994 printf("At --timerange option: --begin, --end, or --timerange option already specified\n %s\n",
3999 ret
= split_timerange(arg
, &begin
, &end
);
4001 printf_err("Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:\n %s\n",
4006 ret
= append_implicit_component_extra_arg(
4007 &implicit_trimmer_args
, "begin", begin
);
4008 ret
|= append_implicit_component_extra_arg(
4009 &implicit_trimmer_args
, "end", end
);
4010 implicit_trimmer_args
.exists
= true;
4018 case OPT_CLOCK_CYCLES
:
4019 append_implicit_component_param(
4020 &implicit_text_args
, "clock-cycles", "yes");
4021 implicit_text_args
.exists
= true;
4023 case OPT_CLOCK_DATE
:
4024 append_implicit_component_param(
4025 &implicit_text_args
, "clock-date", "yes");
4026 implicit_text_args
.exists
= true;
4028 case OPT_CLOCK_FORCE_CORRELATE
:
4029 append_implicit_component_param(
4030 &implicit_muxer_args
, "force-correlate", "yes");
4033 append_implicit_component_param(
4034 &implicit_text_args
, "clock-gmt", "yes");
4035 implicit_text_args
.exists
= true;
4037 case OPT_CLOCK_OFFSET
:
4038 ret
= append_implicit_component_extra_arg(
4039 &implicit_ctf_args
, "clock-offset-cycles", arg
);
4040 implicit_ctf_args
.exists
= true;
4045 case OPT_CLOCK_OFFSET_NS
:
4046 ret
= append_implicit_component_extra_arg(
4047 &implicit_ctf_args
, "clock-offset-ns", arg
);
4048 implicit_ctf_args
.exists
= true;
4053 case OPT_CLOCK_SECONDS
:
4054 append_implicit_component_param(
4055 &implicit_text_args
, "clock-seconds", "yes");
4056 implicit_text_args
.exists
= true;
4059 ret
= append_implicit_component_extra_arg(
4060 &implicit_text_args
, "color", arg
);
4061 implicit_text_args
.exists
= true;
4066 case OPT_NO_DEBUG_INFO
:
4067 implicit_debug_info_args
.exists
= false;
4069 case OPT_DEBUG_INFO_DIR
:
4070 ret
= append_implicit_component_extra_arg(
4071 &implicit_debug_info_args
, "dir", arg
);
4076 case OPT_DEBUG_INFO_FULL_PATH
:
4077 append_implicit_component_param(
4078 &implicit_debug_info_args
, "full-path", "yes");
4080 case OPT_DEBUG_INFO_TARGET_PREFIX
:
4081 ret
= append_implicit_component_extra_arg(
4082 &implicit_debug_info_args
,
4083 "target-prefix", arg
);
4090 struct bt_value
*fields
= fields_from_arg(arg
);
4096 ret
= insert_flat_params_from_array(
4097 implicit_text_args
.params_arg
,
4107 struct bt_value
*names
= names_from_arg(arg
);
4113 ret
= insert_flat_params_from_array(
4114 implicit_text_args
.params_arg
,
4123 append_implicit_component_param(
4124 &implicit_text_args
, "no-delta", "yes");
4125 implicit_text_args
.exists
= true;
4127 case OPT_INPUT_FORMAT
:
4128 if (got_input_format_opt
) {
4129 printf_err("Duplicate --input-format option\n");
4133 got_input_format_opt
= true;
4135 if (strcmp(arg
, "ctf") == 0) {
4136 implicit_ctf_args
.exists
= true;
4137 } else if (strcmp(arg
, "lttng-live") == 0) {
4138 implicit_lttng_live_args
.exists
= true;
4140 printf_err("Unknown legacy input format:\n %s\n",
4145 case OPT_OUTPUT_FORMAT
:
4146 if (got_output_format_opt
) {
4147 printf_err("Duplicate --output-format option\n");
4151 got_output_format_opt
= true;
4153 if (strcmp(arg
, "text") == 0) {
4154 implicit_text_args
.exists
= true;
4155 } else if (strcmp(arg
, "dummy") == 0) {
4156 implicit_dummy_args
.exists
= true;
4157 } else if (strcmp(arg
, "ctf-metadata") == 0) {
4158 print_ctf_metadata
= true;
4160 printf_err("Unknown legacy output format:\n %s\n",
4166 ret
= append_implicit_component_extra_arg(
4167 &implicit_text_args
, "path", arg
);
4168 implicit_text_args
.exists
= true;
4174 if (print_run_args_0
) {
4175 printf_err("Cannot specify --run-args and --run-args-0\n");
4179 print_run_args
= true;
4181 case OPT_RUN_ARGS_0
:
4182 if (print_run_args
) {
4183 printf_err("Cannot specify --run-args and --run-args-0\n");
4187 print_run_args_0
= true;
4189 case OPT_STREAM_INTERSECTION
:
4190 append_implicit_component_param(&implicit_ctf_args
,
4191 "stream-intersection", "yes");
4192 implicit_ctf_args
.exists
= true;
4195 if (got_verbose_opt
) {
4196 printf_err("Duplicate -v/--verbose option\n");
4200 append_implicit_component_param(&implicit_text_args
,
4202 implicit_text_args
.exists
= true;
4203 got_verbose_opt
= true;
4206 got_debug_opt
= true;
4214 /* Check for option parsing error */
4216 printf_err("While parsing command-line options, at option %s: %s\n",
4217 poptBadOption(pc
, 0), poptStrerror(opt
));
4222 * Append home and system plugin paths now that we possibly got
4225 if (append_home_and_system_plugin_paths(plugin_paths
,
4226 omit_system_plugin_path
, omit_home_plugin_path
)) {
4230 /* Consume leftover argument */
4231 leftover
= poptGetArg(pc
);
4233 if (poptPeekArg(pc
)) {
4234 printf_err("Unexpected argument:\n %s\n",
4239 /* Print CTF metadata or print LTTng-live sessions */
4240 if (print_ctf_metadata
) {
4242 printf_err("--output-format=ctf-metadata specified without a path\n");
4246 cfg
= bt_config_print_ctf_metadata_create(plugin_paths
);
4251 cfg
->debug
= got_debug_opt
;
4252 cfg
->verbose
= got_verbose_opt
;
4253 g_string_assign(cfg
->cmd_data
.print_ctf_metadata
.path
,
4259 * If -o dummy was not specified, and if there are no explicit
4260 * sink components, then use an implicit `text.text` sink.
4262 if (!implicit_dummy_args
.exists
&& !sink_names
) {
4263 implicit_text_args
.exists
= true;
4266 /* Decide where the leftover argument goes */
4268 if (implicit_lttng_live_args
.exists
) {
4269 lttng_live_url_parts
=
4270 bt_common_parse_lttng_live_url(leftover
,
4272 if (!lttng_live_url_parts
.proto
) {
4273 printf_err("Invalid LTTng-live URL format: %s\n",
4278 if (!lttng_live_url_parts
.session_name
) {
4279 /* Print LTTng-live sessions */
4280 cfg
= bt_config_print_lttng_live_sessions_create(
4286 cfg
->debug
= got_debug_opt
;
4287 cfg
->verbose
= got_verbose_opt
;
4288 g_string_assign(cfg
->cmd_data
.print_lttng_live_sessions
.url
,
4293 ret
= append_implicit_component_extra_arg(
4294 &implicit_lttng_live_args
, "url", leftover
);
4299 ret
= append_implicit_component_extra_arg(
4300 &implicit_ctf_args
, "path", leftover
);
4301 implicit_ctf_args
.exists
= true;
4309 * Ensure mutual exclusion between implicit `ctf.fs` and
4310 * `ctf.lttng-live` sources.
4312 if (implicit_ctf_args
.exists
&& implicit_lttng_live_args
.exists
) {
4313 printf_err("Cannot create both implicit `ctf.fs` and `ctf.lttng-live` source components\n");
4318 * If the implicit `ctf.fs` or `ctf.lttng-live` source exists,
4319 * make sure there's a leftover (which is the path or URL).
4321 if (implicit_ctf_args
.exists
&& !leftover
) {
4322 printf_err("Missing path for implicit `ctf.fs` source component\n");
4326 if (implicit_lttng_live_args
.exists
&& !leftover
) {
4327 printf_err("Missing URL for implicit `ctf.lttng-live` source component\n");
4331 /* Assign names to implicit components */
4332 ret
= assign_name_to_implicit_component(&implicit_ctf_args
,
4333 "ctf", all_names
, &source_names
, true);
4338 ret
= assign_name_to_implicit_component(&implicit_lttng_live_args
,
4339 "lttng-live", all_names
, &source_names
, true);
4344 ret
= assign_name_to_implicit_component(&implicit_text_args
,
4345 "text", all_names
, &sink_names
, true);
4350 ret
= assign_name_to_implicit_component(&implicit_dummy_args
,
4351 "dummy", all_names
, &sink_names
, true);
4356 ret
= assign_name_to_implicit_component(&implicit_muxer_args
,
4357 "mux", all_names
, NULL
, false);
4362 ret
= assign_name_to_implicit_component(&implicit_trimmer_args
,
4363 "trim", all_names
, NULL
, false);
4368 ret
= assign_name_to_implicit_component(&implicit_debug_info_args
,
4369 "debug-info", all_names
, NULL
, false);
4374 /* Make sure there's at least one source and one sink */
4375 if (!source_names
) {
4376 printf_err("No source component\n");
4381 printf_err("No sink component\n");
4386 * Prepend the muxer, the trimmer, and the debug info to the
4387 * filter chain so that we have:
4389 * sources -> muxer -> [trimmer] -> [debug info] ->
4390 * [user filters] -> sinks
4392 if (implicit_debug_info_args
.exists
) {
4393 if (g_list_prepend_gstring(&filter_names
,
4394 implicit_debug_info_args
.name_arg
->str
)) {
4399 if (implicit_trimmer_args
.exists
) {
4400 if (g_list_prepend_gstring(&filter_names
,
4401 implicit_trimmer_args
.name_arg
->str
)) {
4406 if (g_list_prepend_gstring(&filter_names
,
4407 implicit_muxer_args
.name_arg
->str
)) {
4412 * Append the equivalent run arguments for the implicit
4415 ret
= append_run_args_for_implicit_component(
4416 BT_COMPONENT_CLASS_TYPE_SOURCE
, &implicit_ctf_args
, run_args
);
4421 ret
= append_run_args_for_implicit_component(
4422 BT_COMPONENT_CLASS_TYPE_SOURCE
, &implicit_lttng_live_args
,
4428 ret
= append_run_args_for_implicit_component(
4429 BT_COMPONENT_CLASS_TYPE_SINK
, &implicit_text_args
, run_args
);
4434 ret
= append_run_args_for_implicit_component(
4435 BT_COMPONENT_CLASS_TYPE_SINK
, &implicit_dummy_args
, run_args
);
4440 ret
= append_run_args_for_implicit_component(
4441 BT_COMPONENT_CLASS_TYPE_FILTER
, &implicit_muxer_args
, run_args
);
4446 ret
= append_run_args_for_implicit_component(
4447 BT_COMPONENT_CLASS_TYPE_FILTER
, &implicit_trimmer_args
,
4453 ret
= append_run_args_for_implicit_component(
4454 BT_COMPONENT_CLASS_TYPE_FILTER
, &implicit_debug_info_args
,
4460 /* Auto-connect components */
4461 ret
= convert_auto_connect(run_args
, source_names
, filter_names
,
4464 printf_err("Cannot auto-connect components\n");
4469 * We have all the run command arguments now. Depending on
4470 * --run-args, we pass this to the run command or print them
4473 if (print_run_args
|| print_run_args_0
) {
4474 for (i
= 0; i
< bt_value_array_size(run_args
); i
++) {
4475 struct bt_value
*arg_value
=
4476 bt_value_array_get(run_args
, i
);
4478 GString
*quoted
= NULL
;
4479 const char *arg_to_print
;
4482 ret
= bt_value_string_get(arg_value
, &arg
);
4486 if (print_run_args
) {
4487 quoted
= bt_common_shell_quote(arg
);
4492 arg_to_print
= quoted
->str
;
4497 printf("%s", arg_to_print
);
4500 g_string_free(quoted
, TRUE
);
4503 if (i
< bt_value_array_size(run_args
) - 1) {
4504 if (print_run_args
) {
4517 cfg
= bt_config_run_from_args_array(run_args
, retcode
,
4518 omit_system_plugin_path
, omit_home_plugin_path
,
4519 initial_plugin_paths
);
4528 poptFreeContext(pc
);
4534 g_string_free(cur_name
, TRUE
);
4537 if (cur_name_prefix
) {
4538 g_string_free(cur_name_prefix
, TRUE
);
4543 destroy_glist_of_gstring(source_names
);
4544 destroy_glist_of_gstring(filter_names
);
4545 destroy_glist_of_gstring(sink_names
);
4546 destroy_implicit_component_args(&implicit_ctf_args
);
4547 destroy_implicit_component_args(&implicit_lttng_live_args
);
4548 destroy_implicit_component_args(&implicit_dummy_args
);
4549 destroy_implicit_component_args(&implicit_text_args
);
4550 destroy_implicit_component_args(&implicit_debug_info_args
);
4551 destroy_implicit_component_args(&implicit_muxer_args
);
4552 destroy_implicit_component_args(&implicit_trimmer_args
);
4553 bt_put(plugin_paths
);
4554 bt_common_destroy_lttng_live_url_parts(<tng_live_url_parts
);
4559 * Prints the Babeltrace 2.x general usage.
4562 void print_gen_usage(FILE *fp
)
4564 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [COMMAND] [COMMAND ARGUMENTS]\n");
4566 fprintf(fp
, "General options:\n");
4568 fprintf(fp
, " -d, --debug Turn on debug mode\n");
4569 fprintf(fp
, " -h --help Show this help and quit\n");
4570 fprintf(fp
, " -v, --verbose Turn on verbose mode\n");
4571 fprintf(fp
, " -V, --version Show version and quit\n");
4573 fprintf(fp
, "Available commands:\n");
4575 fprintf(fp
, " convert Convert and trim traces (default)\n");
4576 fprintf(fp
, " help Get help for a plugin or a component class\n");
4577 fprintf(fp
, " list-plugins List available plugins and their content\n");
4578 fprintf(fp
, " query Query objects from a component class\n");
4579 fprintf(fp
, " run Build a processing graph and run it\n");
4581 fprintf(fp
, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
4584 struct bt_config
*bt_config_from_args(int argc
, const char *argv
[],
4585 int *retcode
, bool omit_system_plugin_path
,
4586 bool omit_home_plugin_path
,
4587 struct bt_value
*initial_plugin_paths
)
4589 struct bt_config
*config
= NULL
;
4590 bool verbose
= false;
4593 const char **command_argv
= NULL
;
4594 int command_argc
= -1;
4595 const char *command_name
= NULL
;
4598 COMMAND_TYPE_NONE
= -1,
4599 COMMAND_TYPE_RUN
= 0,
4600 COMMAND_TYPE_CONVERT
,
4601 COMMAND_TYPE_LIST_PLUGINS
,
4604 } command_type
= COMMAND_TYPE_NONE
;
4608 if (!initial_plugin_paths
) {
4609 initial_plugin_paths
= bt_value_array_create();
4610 if (!initial_plugin_paths
) {
4615 bt_get(initial_plugin_paths
);
4619 print_gen_usage(stdout
);
4623 for (i
= 1; i
< argc
; i
++) {
4624 const char *cur_arg
= argv
[i
];
4626 if (strcmp(cur_arg
, "-d") == 0 ||
4627 strcmp(cur_arg
, "--debug") == 0) {
4629 } else if (strcmp(cur_arg
, "-v") == 0 ||
4630 strcmp(cur_arg
, "--verbose") == 0) {
4632 } else if (strcmp(cur_arg
, "-V") == 0 ||
4633 strcmp(cur_arg
, "--version") == 0) {
4636 } else if (strcmp(cur_arg
, "-h") == 0 ||
4637 strcmp(cur_arg
, "--help") == 0) {
4638 print_gen_usage(stdout
);
4641 bool has_command
= true;
4644 * First unknown argument: is it a known command
4647 if (strcmp(cur_arg
, "convert") == 0) {
4648 command_type
= COMMAND_TYPE_CONVERT
;
4649 } else if (strcmp(cur_arg
, "list-plugins") == 0) {
4650 command_type
= COMMAND_TYPE_LIST_PLUGINS
;
4651 } else if (strcmp(cur_arg
, "help") == 0) {
4652 command_type
= COMMAND_TYPE_HELP
;
4653 } else if (strcmp(cur_arg
, "query") == 0) {
4654 command_type
= COMMAND_TYPE_QUERY
;
4655 } else if (strcmp(cur_arg
, "run") == 0) {
4656 command_type
= COMMAND_TYPE_RUN
;
4659 * Unknown argument, but not a known
4660 * command name: assume the whole
4661 * arguments are for the default convert
4664 command_type
= COMMAND_TYPE_CONVERT
;
4665 command_argv
= argv
;
4666 command_argc
= argc
;
4667 has_command
= false;
4671 command_argv
= &argv
[i
];
4672 command_argc
= argc
- i
;
4673 command_name
= cur_arg
;
4679 if (command_type
== COMMAND_TYPE_NONE
) {
4681 * We only got non-help, non-version general options
4682 * like --verbose and --debug, without any other
4683 * arguments, so we can't do anything useful: print the
4686 print_gen_usage(stdout
);
4690 assert(command_argv
);
4691 assert(command_argc
>= 0);
4693 switch (command_type
) {
4694 case COMMAND_TYPE_RUN
:
4695 config
= bt_config_run_from_args(command_argc
, command_argv
,
4696 retcode
, omit_system_plugin_path
,
4697 omit_home_plugin_path
, initial_plugin_paths
);
4699 case COMMAND_TYPE_CONVERT
:
4700 config
= bt_config_convert_from_args(command_argc
, command_argv
,
4701 retcode
, omit_system_plugin_path
,
4702 omit_home_plugin_path
, initial_plugin_paths
);
4704 case COMMAND_TYPE_LIST_PLUGINS
:
4705 config
= bt_config_list_plugins_from_args(command_argc
,
4706 command_argv
, retcode
, omit_system_plugin_path
,
4707 omit_home_plugin_path
, initial_plugin_paths
);
4709 case COMMAND_TYPE_HELP
:
4710 config
= bt_config_help_from_args(command_argc
,
4711 command_argv
, retcode
, omit_system_plugin_path
,
4712 omit_home_plugin_path
, initial_plugin_paths
);
4714 case COMMAND_TYPE_QUERY
:
4715 config
= bt_config_query_from_args(command_argc
,
4716 command_argv
, retcode
, omit_system_plugin_path
,
4717 omit_home_plugin_path
, initial_plugin_paths
);
4725 config
->verbose
= true;
4729 config
->debug
= true;
4732 config
->command_name
= command_name
;
4736 bt_put(initial_plugin_paths
);