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"
42 #define DEFAULT_SOURCE_COMPONENT_NAME "ctf.fs"
43 #define DEFAULT_SINK_COMPONENT_NAME "text.text"
46 * Error printf() macro which prepends "Error: " the first time it's
47 * called. This gives a nicer feel than having a bunch of error prefixes
48 * (since the following lines usually describe the error and possible
49 * solutions), or the error prefix just at the end.
51 #define printf_err(fmt, args...) \
53 if (is_first_error) { \
54 fprintf(stderr, "Error: "); \
55 is_first_error = false; \
57 fprintf(stderr, fmt, ##args); \
60 static bool is_first_error
= true;
62 /* INI-style parsing FSM states */
63 enum ini_parsing_fsm_state
{
64 /* Expect a map key (identifier) */
67 /* Expect an equal character ('=') */
73 /* Expect a negative number value */
74 INI_EXPECT_VALUE_NUMBER_NEG
,
76 /* Expect a comma character (',') */
80 /* INI-style parsing state variables */
81 struct ini_parsing_state
{
82 /* Lexical scanner (owned by this) */
85 /* Output map value object being filled (owned by this) */
86 struct bt_value
*params
;
88 /* Next expected FSM state */
89 enum ini_parsing_fsm_state expecting
;
91 /* Last decoded map key (owned by this) */
94 /* Complete INI-style string to parse (not owned by this) */
97 /* Error buffer (not owned by this) */
101 /* Offset option with "is set" boolean */
107 /* Legacy "ctf"/"lttng-live" format options */
108 struct ctf_legacy_opts
{
109 struct offset_opt offset_s
;
110 struct offset_opt offset_ns
;
111 bool stream_intersection
;
114 /* Legacy "text" format options */
115 struct text_legacy_opts
{
117 * output, dbg_info_dir, dbg_info_target_prefix, names,
118 * and fields are owned by this.
121 GString
*dbg_info_dir
;
122 GString
*dbg_info_target_prefix
;
123 struct bt_value
*names
;
124 struct bt_value
*fields
;
132 bool dbg_info_full_path
;
135 /* Legacy input format format */
136 enum legacy_input_format
{
137 LEGACY_INPUT_FORMAT_NONE
= 0,
138 LEGACY_INPUT_FORMAT_CTF
,
139 LEGACY_INPUT_FORMAT_LTTNG_LIVE
,
142 /* Legacy output format format */
143 enum legacy_output_format
{
144 LEGACY_OUTPUT_FORMAT_NONE
= 0,
145 LEGACY_OUTPUT_FORMAT_TEXT
,
146 LEGACY_OUTPUT_FORMAT_CTF_METADATA
,
147 LEGACY_OUTPUT_FORMAT_DUMMY
,
151 * Prints the "out of memory" error.
154 void print_err_oom(void)
156 printf_err("Out of memory\n");
160 * Prints duplicate legacy output format error.
163 void print_err_dup_legacy_output(void)
165 printf_err("More than one legacy output format specified\n");
169 * Prints duplicate legacy input format error.
172 void print_err_dup_legacy_input(void)
174 printf_err("More than one legacy input format specified\n");
178 * Checks if any of the "text" legacy options is set.
181 bool text_legacy_opts_is_any_set(struct text_legacy_opts
*opts
)
183 return (opts
->output
&& opts
->output
->len
> 0) ||
184 (opts
->dbg_info_dir
&& opts
->dbg_info_dir
->len
> 0) ||
185 (opts
->dbg_info_target_prefix
&&
186 opts
->dbg_info_target_prefix
->len
> 0) ||
187 bt_value_array_size(opts
->names
) > 0 ||
188 bt_value_array_size(opts
->fields
) > 0 ||
189 opts
->no_delta
|| opts
->clock_cycles
|| opts
->clock_seconds
||
190 opts
->clock_date
|| opts
->clock_gmt
||
191 opts
->dbg_info_full_path
;
195 * Checks if any of the "ctf" legacy options is set.
198 bool ctf_legacy_opts_is_any_set(struct ctf_legacy_opts
*opts
)
200 return opts
->offset_s
.is_set
|| opts
->offset_ns
.is_set
||
201 opts
->stream_intersection
;
205 * Appends an "expecting token" error to the INI-style parsing state's
209 void ini_append_error_expecting(struct ini_parsing_state
*state
,
210 GScanner
*scanner
, const char *expecting
)
215 g_string_append_printf(state
->ini_error
, "Expecting %s:\n", expecting
);
217 /* Only print error if there's one line */
218 if (strchr(state
->arg
, '\n') != NULL
|| strlen(state
->arg
) == 0) {
222 g_string_append_printf(state
->ini_error
, "\n %s\n", state
->arg
);
223 pos
= g_scanner_cur_position(scanner
) + 4;
225 if (!g_scanner_eof(scanner
)) {
229 for (i
= 0; i
< pos
; ++i
) {
230 g_string_append_printf(state
->ini_error
, " ");
233 g_string_append_printf(state
->ini_error
, "^\n\n");
237 int ini_handle_state(struct ini_parsing_state
*state
)
240 GTokenType token_type
;
241 struct bt_value
*value
= NULL
;
243 token_type
= g_scanner_get_next_token(state
->scanner
);
244 if (token_type
== G_TOKEN_EOF
) {
245 if (state
->expecting
!= INI_EXPECT_COMMA
) {
246 switch (state
->expecting
) {
247 case INI_EXPECT_EQUAL
:
248 ini_append_error_expecting(state
,
249 state
->scanner
, "'='");
251 case INI_EXPECT_VALUE
:
252 case INI_EXPECT_VALUE_NUMBER_NEG
:
253 ini_append_error_expecting(state
,
254 state
->scanner
, "value");
256 case INI_EXPECT_MAP_KEY
:
257 ini_append_error_expecting(state
,
258 state
->scanner
, "unquoted map key");
271 switch (state
->expecting
) {
272 case INI_EXPECT_MAP_KEY
:
273 if (token_type
!= G_TOKEN_IDENTIFIER
) {
274 ini_append_error_expecting(state
, state
->scanner
,
279 free(state
->last_map_key
);
280 state
->last_map_key
=
281 strdup(state
->scanner
->value
.v_identifier
);
282 if (!state
->last_map_key
) {
283 g_string_append(state
->ini_error
,
288 if (bt_value_map_has_key(state
->params
, state
->last_map_key
)) {
289 g_string_append_printf(state
->ini_error
,
290 "Duplicate parameter key: `%s`\n",
291 state
->last_map_key
);
295 state
->expecting
= INI_EXPECT_EQUAL
;
297 case INI_EXPECT_EQUAL
:
298 if (token_type
!= G_TOKEN_CHAR
) {
299 ini_append_error_expecting(state
,
300 state
->scanner
, "'='");
304 if (state
->scanner
->value
.v_char
!= '=') {
305 ini_append_error_expecting(state
,
306 state
->scanner
, "'='");
310 state
->expecting
= INI_EXPECT_VALUE
;
312 case INI_EXPECT_VALUE
:
314 switch (token_type
) {
316 if (state
->scanner
->value
.v_char
== '-') {
317 /* Negative number */
319 INI_EXPECT_VALUE_NUMBER_NEG
;
322 ini_append_error_expecting(state
,
323 state
->scanner
, "value");
329 /* Positive integer */
330 uint64_t int_val
= state
->scanner
->value
.v_int64
;
332 if (int_val
> (1ULL << 63) - 1) {
333 g_string_append_printf(state
->ini_error
,
334 "Integer value %" PRIu64
" is outside the range of a 64-bit signed integer\n",
339 value
= bt_value_integer_create_init(
344 /* Positive floating point number */
345 value
= bt_value_float_create_init(
346 state
->scanner
->value
.v_float
);
350 value
= bt_value_string_create_init(
351 state
->scanner
->value
.v_string
);
353 case G_TOKEN_IDENTIFIER
:
356 * Using symbols would be appropriate here,
357 * but said symbols are allowed as map key,
358 * so it's easier to consider everything an
361 * If one of the known symbols is not
362 * recognized here, then fall back to creating
365 const char *id
= state
->scanner
->value
.v_identifier
;
367 if (!strcmp(id
, "null") || !strcmp(id
, "NULL") ||
368 !strcmp(id
, "nul")) {
369 value
= bt_value_null
;
370 } else if (!strcmp(id
, "true") || !strcmp(id
, "TRUE") ||
371 !strcmp(id
, "yes") ||
372 !strcmp(id
, "YES")) {
373 value
= bt_value_bool_create_init(true);
374 } else if (!strcmp(id
, "false") ||
375 !strcmp(id
, "FALSE") ||
378 value
= bt_value_bool_create_init(false);
380 value
= bt_value_string_create_init(id
);
385 /* Unset value variable will trigger the error */
390 ini_append_error_expecting(state
,
391 state
->scanner
, "value");
395 state
->expecting
= INI_EXPECT_COMMA
;
398 case INI_EXPECT_VALUE_NUMBER_NEG
:
400 switch (token_type
) {
403 /* Negative integer */
404 uint64_t int_val
= state
->scanner
->value
.v_int64
;
406 if (int_val
> (1ULL << 63) - 1) {
407 g_string_append_printf(state
->ini_error
,
408 "Integer value -%" PRIu64
" is outside the range of a 64-bit signed integer\n",
413 value
= bt_value_integer_create_init(
414 -((int64_t) int_val
));
418 /* Negative floating point number */
419 value
= bt_value_float_create_init(
420 -state
->scanner
->value
.v_float
);
423 /* Unset value variable will trigger the error */
428 ini_append_error_expecting(state
,
429 state
->scanner
, "value");
433 state
->expecting
= INI_EXPECT_COMMA
;
436 case INI_EXPECT_COMMA
:
437 if (token_type
!= G_TOKEN_CHAR
) {
438 ini_append_error_expecting(state
,
439 state
->scanner
, "','");
443 if (state
->scanner
->value
.v_char
!= ',') {
444 ini_append_error_expecting(state
,
445 state
->scanner
, "','");
449 state
->expecting
= INI_EXPECT_MAP_KEY
;
461 if (bt_value_map_insert(state
->params
,
462 state
->last_map_key
, value
)) {
463 /* Only override return value on error */
474 * Converts an INI-style argument to an equivalent map value object.
476 * Return value is owned by the caller.
479 struct bt_value
*bt_value_from_ini(const char *arg
, GString
*ini_error
)
481 /* Lexical scanner configuration */
482 GScannerConfig scanner_config
= {
483 /* Skip whitespaces */
484 .cset_skip_characters
= " \t\n",
486 /* Identifier syntax is: [a-zA-Z_][a-zA-Z0-9_.:-]* */
487 .cset_identifier_first
=
491 .cset_identifier_nth
=
496 /* "hello" and "Hello" two different keys */
497 .case_sensitive
= TRUE
,
500 .cpair_comment_single
= NULL
,
501 .skip_comment_multi
= TRUE
,
502 .skip_comment_single
= TRUE
,
503 .scan_comment_multi
= FALSE
,
506 * Do scan identifiers, including 1-char identifiers,
507 * but NULL is a normal identifier.
509 .scan_identifier
= TRUE
,
510 .scan_identifier_1char
= TRUE
,
511 .scan_identifier_NULL
= FALSE
,
514 * No specific symbols: null and boolean "symbols" are
515 * scanned as plain identifiers.
517 .scan_symbols
= FALSE
,
518 .symbol_2_token
= FALSE
,
519 .scope_0_fallback
= FALSE
,
522 * Scan "0b"-, "0"-, and "0x"-prefixed integers, but not
523 * integers prefixed with "$".
529 .scan_hex_dollar
= FALSE
,
531 /* Convert scanned numbers to integer tokens */
532 .numbers_2_int
= TRUE
,
534 /* Support both integers and floating-point numbers */
535 .int_2_float
= FALSE
,
537 /* Scan integers as 64-bit signed integers */
540 /* Only scan double-quoted strings */
541 .scan_string_sq
= FALSE
,
542 .scan_string_dq
= TRUE
,
544 /* Do not converter identifiers to string tokens */
545 .identifier_2_string
= FALSE
,
547 /* Scan characters as G_TOKEN_CHAR token */
548 .char_2_token
= FALSE
,
550 struct ini_parsing_state state
= {
553 .expecting
= INI_EXPECT_MAP_KEY
,
555 .ini_error
= ini_error
,
558 state
.params
= bt_value_map_create();
563 state
.scanner
= g_scanner_new(&scanner_config
);
564 if (!state
.scanner
) {
568 /* Let the scan begin */
569 g_scanner_input_text(state
.scanner
, arg
, strlen(arg
));
572 int ret
= ini_handle_state(&state
);
577 } else if (ret
> 0) {
586 BT_PUT(state
.params
);
590 g_scanner_destroy(state
.scanner
);
593 free(state
.last_map_key
);
598 * Returns the parameters map value object from a command-line
599 * parameter option's argument.
601 * Return value is owned by the caller.
604 struct bt_value
*bt_value_from_arg(const char *arg
)
606 struct bt_value
*params
= NULL
;
607 GString
*ini_error
= NULL
;
609 ini_error
= g_string_new(NULL
);
615 /* Try INI-style parsing */
616 params
= bt_value_from_ini(arg
, ini_error
);
618 printf_err("%s", ini_error
->str
);
624 g_string_free(ini_error
, TRUE
);
630 * Returns the plugin and component names from a command-line
631 * source/sink option's argument. arg must have the following format:
635 * where PLUGIN is the plugin name, and COMPONENT is the component
638 * On success, both *plugin and *component are not NULL. *plugin
639 * and *component are owned by the caller.
642 void plugin_component_names_from_arg(const char *arg
, char **plugin
,
648 size_t component_len
;
650 /* Initialize both return values to NULL: not found */
654 dot
= strchr(arg
, '.');
660 end
= arg
+ strlen(arg
);
661 plugin_len
= dot
- arg
;
662 component_len
= end
- dot
- 1;
663 if (plugin_len
== 0 || component_len
== 0) {
667 *plugin
= g_malloc0(plugin_len
+ 1);
673 g_strlcpy(*plugin
, arg
, plugin_len
+ 1);
674 *component
= g_malloc0(component_len
+ 1);
680 g_strlcpy(*component
, dot
+ 1, component_len
+ 1);
687 * Prints the Babeltrace version.
690 void print_version(void)
692 puts("Babeltrace " VERSION
);
696 * Destroys a component configuration.
699 void bt_config_component_destroy(struct bt_object
*obj
)
701 struct bt_config_component
*bt_config_component
=
702 container_of(obj
, struct bt_config_component
, base
);
708 if (bt_config_component
->plugin_name
) {
709 g_string_free(bt_config_component
->plugin_name
, TRUE
);
712 if (bt_config_component
->component_name
) {
713 g_string_free(bt_config_component
->component_name
, TRUE
);
716 if (bt_config_component
->instance_name
) {
717 g_string_free(bt_config_component
->instance_name
, TRUE
);
720 BT_PUT(bt_config_component
->params
);
721 g_free(bt_config_component
);
728 * Creates a component configuration using the given plugin name and
729 * component name. plugin_name and component_name are copied (belong to
732 * Return value is owned by the caller.
735 struct bt_config_component
*bt_config_component_create(
736 enum bt_component_class_type type
,
737 const char *plugin_name
, const char *component_name
)
739 struct bt_config_component
*cfg_component
= NULL
;
741 cfg_component
= g_new0(struct bt_config_component
, 1);
742 if (!cfg_component
) {
747 bt_object_init(cfg_component
, bt_config_component_destroy
);
748 cfg_component
->type
= type
;
749 cfg_component
->plugin_name
= g_string_new(plugin_name
);
750 if (!cfg_component
->plugin_name
) {
755 cfg_component
->component_name
= g_string_new(component_name
);
756 if (!cfg_component
->component_name
) {
761 cfg_component
->instance_name
= g_string_new(NULL
);
762 if (!cfg_component
->instance_name
) {
767 /* Start with empty parameters */
768 cfg_component
->params
= bt_value_map_create();
769 if (!cfg_component
->params
) {
777 BT_PUT(cfg_component
);
780 return cfg_component
;
784 * Creates a component configuration from a command-line source/sink
787 struct bt_config_component
*bt_config_component_from_arg(
788 enum bt_component_class_type type
, const char *arg
)
790 struct bt_config_component
*bt_config_component
= NULL
;
792 char *component_name
;
794 plugin_component_names_from_arg(arg
, &plugin_name
, &component_name
);
795 if (!plugin_name
|| !component_name
) {
796 printf_err("Cannot get plugin or component class name\n");
800 bt_config_component
= bt_config_component_create(type
, plugin_name
,
802 if (!bt_config_component
) {
809 BT_PUT(bt_config_component
);
813 g_free(component_name
);
814 return bt_config_component
;
818 * Destroys a configuration.
821 void bt_config_destroy(struct bt_object
*obj
)
823 struct bt_config
*cfg
=
824 container_of(obj
, struct bt_config
, base
);
830 switch (cfg
->command
) {
831 case BT_CONFIG_COMMAND_CONVERT
:
832 if (cfg
->cmd_data
.convert
.sources
) {
833 g_ptr_array_free(cfg
->cmd_data
.convert
.sources
, TRUE
);
836 if (cfg
->cmd_data
.convert
.filters
) {
837 g_ptr_array_free(cfg
->cmd_data
.convert
.filters
, TRUE
);
840 if (cfg
->cmd_data
.convert
.sinks
) {
841 g_ptr_array_free(cfg
->cmd_data
.convert
.sinks
, TRUE
);
844 if (cfg
->cmd_data
.convert
.connections
) {
845 g_ptr_array_free(cfg
->cmd_data
.convert
.connections
,
849 BT_PUT(cfg
->cmd_data
.convert
.plugin_paths
);
851 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
852 BT_PUT(cfg
->cmd_data
.list_plugins
.plugin_paths
);
854 case BT_CONFIG_COMMAND_HELP
:
855 BT_PUT(cfg
->cmd_data
.help
.plugin_paths
);
856 BT_PUT(cfg
->cmd_data
.help
.cfg_component
);
868 static void destroy_gstring(void *data
)
870 g_string_free(data
, TRUE
);
874 * Extracts the various paths from the string arg, delimited by ':',
875 * and appends them to the array value object plugin_paths.
877 enum bt_value_status
bt_config_append_plugin_paths(
878 struct bt_value
*plugin_paths
, const char *arg
)
880 enum bt_value_status status
= BT_VALUE_STATUS_OK
;
881 GPtrArray
*dirs
= g_ptr_array_new_with_free_func(destroy_gstring
);
886 status
= BT_VALUE_STATUS_ERROR
;
890 ret
= bt_common_append_plugin_path_dirs(arg
, dirs
);
892 status
= BT_VALUE_STATUS_ERROR
;
896 for (i
= 0; i
< dirs
->len
; i
++) {
897 GString
*dir
= g_ptr_array_index(dirs
, i
);
899 bt_value_array_append_string(plugin_paths
, dir
->str
);
903 g_ptr_array_free(dirs
, TRUE
);
908 * Creates a simple lexical scanner for parsing comma-delimited names
911 * Return value is owned by the caller.
914 GScanner
*create_csv_identifiers_scanner(void)
916 GScannerConfig scanner_config
= {
917 .cset_skip_characters
= " \t\n",
918 .cset_identifier_first
= G_CSET_a_2_z G_CSET_A_2_Z
"_",
919 .cset_identifier_nth
= G_CSET_a_2_z G_CSET_A_2_Z
":_-",
920 .case_sensitive
= TRUE
,
921 .cpair_comment_single
= NULL
,
922 .skip_comment_multi
= TRUE
,
923 .skip_comment_single
= TRUE
,
924 .scan_comment_multi
= FALSE
,
925 .scan_identifier
= TRUE
,
926 .scan_identifier_1char
= TRUE
,
927 .scan_identifier_NULL
= FALSE
,
928 .scan_symbols
= FALSE
,
929 .symbol_2_token
= FALSE
,
930 .scope_0_fallback
= FALSE
,
931 .scan_binary
= FALSE
,
935 .scan_hex_dollar
= FALSE
,
936 .numbers_2_int
= FALSE
,
937 .int_2_float
= FALSE
,
938 .store_int64
= FALSE
,
939 .scan_string_sq
= FALSE
,
940 .scan_string_dq
= FALSE
,
941 .identifier_2_string
= FALSE
,
942 .char_2_token
= TRUE
,
945 return g_scanner_new(&scanner_config
);
949 * Inserts a string (if exists and not empty) or null to a map value
953 enum bt_value_status
map_insert_string_or_null(struct bt_value
*map
,
954 const char *key
, GString
*string
)
956 enum bt_value_status ret
;
958 if (string
&& string
->len
> 0) {
959 ret
= bt_value_map_insert_string(map
, key
, string
->str
);
961 ret
= bt_value_map_insert(map
, key
, bt_value_null
);
967 * Converts a comma-delimited list of known names (--names option) to
968 * an array value object containing those names as string value objects.
970 * Return value is owned by the caller.
973 struct bt_value
*names_from_arg(const char *arg
)
975 GScanner
*scanner
= NULL
;
976 struct bt_value
*names
= NULL
;
977 bool found_all
= false, found_none
= false, found_item
= false;
979 names
= bt_value_array_create();
985 scanner
= create_csv_identifiers_scanner();
991 g_scanner_input_text(scanner
, arg
, strlen(arg
));
994 GTokenType token_type
= g_scanner_get_next_token(scanner
);
996 switch (token_type
) {
997 case G_TOKEN_IDENTIFIER
:
999 const char *identifier
= scanner
->value
.v_identifier
;
1001 if (!strcmp(identifier
, "payload") ||
1002 !strcmp(identifier
, "args") ||
1003 !strcmp(identifier
, "arg")) {
1005 if (bt_value_array_append_string(names
,
1009 } else if (!strcmp(identifier
, "context") ||
1010 !strcmp(identifier
, "ctx")) {
1012 if (bt_value_array_append_string(names
,
1016 } else if (!strcmp(identifier
, "scope") ||
1017 !strcmp(identifier
, "header")) {
1019 if (bt_value_array_append_string(names
,
1023 } else if (!strcmp(identifier
, "all")) {
1025 if (bt_value_array_append_string(names
,
1029 } else if (!strcmp(identifier
, "none")) {
1031 if (bt_value_array_append_string(names
,
1036 printf_err("Unknown field name: `%s`\n",
1052 if (found_none
&& found_all
) {
1053 printf_err("Only either `all` or `none` can be specified in the list given to the --names option, but not both.\n");
1057 * Legacy behavior is to clear the defaults (show none) when at
1058 * least one item is specified.
1060 if (found_item
&& !found_none
&& !found_all
) {
1061 if (bt_value_array_append_string(names
, "none")) {
1066 g_scanner_destroy(scanner
);
1073 g_scanner_destroy(scanner
);
1080 * Converts a comma-delimited list of known fields (--fields option) to
1081 * an array value object containing those fields as string
1084 * Return value is owned by the caller.
1087 struct bt_value
*fields_from_arg(const char *arg
)
1089 GScanner
*scanner
= NULL
;
1090 struct bt_value
*fields
;
1092 fields
= bt_value_array_create();
1098 scanner
= create_csv_identifiers_scanner();
1104 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1107 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1109 switch (token_type
) {
1110 case G_TOKEN_IDENTIFIER
:
1112 const char *identifier
= scanner
->value
.v_identifier
;
1114 if (!strcmp(identifier
, "trace") ||
1115 !strcmp(identifier
, "trace:hostname") ||
1116 !strcmp(identifier
, "trace:domain") ||
1117 !strcmp(identifier
, "trace:procname") ||
1118 !strcmp(identifier
, "trace:vpid") ||
1119 !strcmp(identifier
, "loglevel") ||
1120 !strcmp(identifier
, "emf") ||
1121 !strcmp(identifier
, "callsite") ||
1122 !strcmp(identifier
, "all")) {
1123 if (bt_value_array_append_string(fields
,
1128 printf_err("Unknown field name: `%s`\n",
1150 g_scanner_destroy(scanner
);
1156 * Inserts the equivalent "prefix-name" true boolean value objects into
1157 * map_obj where the names are in array_obj.
1160 int insert_flat_names_fields_from_array(struct bt_value
*map_obj
,
1161 struct bt_value
*array_obj
, const char *prefix
)
1165 GString
*tmpstr
= NULL
, *default_value
= NULL
;
1168 * array_obj may be NULL if no CLI options were specified to
1169 * trigger its creation.
1175 tmpstr
= g_string_new(NULL
);
1182 default_value
= g_string_new(NULL
);
1183 if (!default_value
) {
1189 for (i
= 0; i
< bt_value_array_size(array_obj
); i
++) {
1190 struct bt_value
*str_obj
= bt_value_array_get(array_obj
, i
);
1192 bool is_default
= false;
1195 printf_err("Unexpected error\n");
1200 ret
= bt_value_string_get(str_obj
, &suffix
);
1203 printf_err("Unexpected error\n");
1207 g_string_assign(tmpstr
, prefix
);
1208 g_string_append(tmpstr
, "-");
1210 /* Special-case for "all" and "none". */
1211 if (!strcmp(suffix
, "all")) {
1213 g_string_assign(default_value
, "show");
1214 } else if (!strcmp(suffix
, "none")) {
1216 g_string_assign(default_value
, "hide");
1219 g_string_append(tmpstr
, "default");
1220 ret
= map_insert_string_or_null(map_obj
,
1228 g_string_append(tmpstr
, suffix
);
1229 ret
= bt_value_map_insert_bool(map_obj
, tmpstr
->str
,
1239 if (default_value
) {
1240 g_string_free(default_value
, TRUE
);
1243 g_string_free(tmpstr
, TRUE
);
1250 * Returns the parameters (map value object) corresponding to the
1251 * legacy text format options.
1253 * Return value is owned by the caller.
1256 struct bt_value
*params_from_text_legacy_opts(
1257 struct text_legacy_opts
*text_legacy_opts
)
1259 struct bt_value
*params
;
1261 params
= bt_value_map_create();
1267 if (map_insert_string_or_null(params
, "output-path",
1268 text_legacy_opts
->output
)) {
1273 if (map_insert_string_or_null(params
, "debug-info-dir",
1274 text_legacy_opts
->dbg_info_dir
)) {
1279 if (map_insert_string_or_null(params
, "debug-info-target-prefix",
1280 text_legacy_opts
->dbg_info_target_prefix
)) {
1285 if (bt_value_map_insert_bool(params
, "debug-info-full-path",
1286 text_legacy_opts
->dbg_info_full_path
)) {
1291 if (bt_value_map_insert_bool(params
, "no-delta",
1292 text_legacy_opts
->no_delta
)) {
1297 if (bt_value_map_insert_bool(params
, "clock-cycles",
1298 text_legacy_opts
->clock_cycles
)) {
1303 if (bt_value_map_insert_bool(params
, "clock-seconds",
1304 text_legacy_opts
->clock_seconds
)) {
1309 if (bt_value_map_insert_bool(params
, "clock-date",
1310 text_legacy_opts
->clock_date
)) {
1315 if (bt_value_map_insert_bool(params
, "clock-gmt",
1316 text_legacy_opts
->clock_gmt
)) {
1321 if (insert_flat_names_fields_from_array(params
,
1322 text_legacy_opts
->names
, "name")) {
1326 if (insert_flat_names_fields_from_array(params
,
1327 text_legacy_opts
->fields
, "field")) {
1341 int append_sinks_from_legacy_opts(GPtrArray
*sinks
,
1342 enum legacy_output_format legacy_output_format
,
1343 struct text_legacy_opts
*text_legacy_opts
)
1346 struct bt_value
*params
= NULL
;
1347 const char *plugin_name
;
1348 const char *component_name
;
1349 struct bt_config_component
*bt_config_component
= NULL
;
1351 switch (legacy_output_format
) {
1352 case LEGACY_OUTPUT_FORMAT_TEXT
:
1353 plugin_name
= "text";
1354 component_name
= "text";
1356 case LEGACY_OUTPUT_FORMAT_CTF_METADATA
:
1357 plugin_name
= "ctf";
1358 component_name
= "metadata-text";
1360 case LEGACY_OUTPUT_FORMAT_DUMMY
:
1361 plugin_name
= "utils";
1362 component_name
= "dummy";
1369 if (legacy_output_format
== LEGACY_OUTPUT_FORMAT_TEXT
) {
1370 /* Legacy "text" output format has parameters */
1371 params
= params_from_text_legacy_opts(text_legacy_opts
);
1377 * Legacy "dummy" and "ctf-metadata" output formats do
1378 * not have parameters.
1380 params
= bt_value_map_create();
1387 /* Create a component configuration */
1388 bt_config_component
= bt_config_component_create(
1389 BT_COMPONENT_CLASS_TYPE_SINK
, plugin_name
, component_name
);
1390 if (!bt_config_component
) {
1394 BT_MOVE(bt_config_component
->params
, params
);
1396 /* Move created component configuration to the array */
1397 g_ptr_array_add(sinks
, bt_config_component
);
1411 * Returns the parameters (map value object) corresponding to the
1412 * given legacy CTF format options.
1414 * Return value is owned by the caller.
1417 struct bt_value
*params_from_ctf_legacy_opts(
1418 struct ctf_legacy_opts
*ctf_legacy_opts
)
1420 struct bt_value
*params
;
1422 params
= bt_value_map_create();
1428 if (bt_value_map_insert_integer(params
, "offset-s",
1429 ctf_legacy_opts
->offset_s
.value
)) {
1434 if (bt_value_map_insert_integer(params
, "offset-ns",
1435 ctf_legacy_opts
->offset_ns
.value
)) {
1440 if (bt_value_map_insert_bool(params
, "stream-intersection",
1441 ctf_legacy_opts
->stream_intersection
)) {
1456 int append_sources_from_legacy_opts(GPtrArray
*sources
,
1457 enum legacy_input_format legacy_input_format
,
1458 struct ctf_legacy_opts
*ctf_legacy_opts
,
1459 struct bt_value
*legacy_input_paths
)
1463 struct bt_value
*base_params
;
1464 struct bt_value
*params
= NULL
;
1465 struct bt_value
*input_path
= NULL
;
1466 struct bt_value
*input_path_copy
= NULL
;
1467 const char *input_key
;
1468 const char *component_name
;
1470 switch (legacy_input_format
) {
1471 case LEGACY_INPUT_FORMAT_CTF
:
1473 component_name
= "fs";
1475 case LEGACY_INPUT_FORMAT_LTTNG_LIVE
:
1477 component_name
= "lttng-live";
1484 base_params
= params_from_ctf_legacy_opts(ctf_legacy_opts
);
1489 for (i
= 0; i
< bt_value_array_size(legacy_input_paths
); i
++) {
1490 struct bt_config_component
*bt_config_component
= NULL
;
1492 /* Copy base parameters as current parameters */
1493 params
= bt_value_copy(base_params
);
1498 /* Get current input path string value object */
1499 input_path
= bt_value_array_get(legacy_input_paths
, i
);
1504 /* Copy current input path value object */
1505 input_path_copy
= bt_value_copy(input_path
);
1506 if (!input_path_copy
) {
1510 /* Insert input path value object into current parameters */
1511 ret
= bt_value_map_insert(params
, input_key
, input_path_copy
);
1516 /* Create a component configuration */
1517 bt_config_component
= bt_config_component_create(
1518 BT_COMPONENT_CLASS_TYPE_SOURCE
, "ctf", component_name
);
1519 if (!bt_config_component
) {
1523 BT_MOVE(bt_config_component
->params
, params
);
1525 /* Move created component configuration to the array */
1526 g_ptr_array_add(sources
, bt_config_component
);
1528 /* Put current stuff */
1530 BT_PUT(input_path_copy
);
1539 BT_PUT(base_params
);
1542 BT_PUT(input_path_copy
);
1547 * Escapes a string for the shell. The string is escaped knowing that
1548 * it's a parameter string value (double-quoted), and that it will be
1549 * entered between single quotes in the shell.
1551 * Return value is owned by the caller.
1554 char *str_shell_escape(const char *input
)
1557 const char *at
= input
;
1558 GString
*str
= g_string_new(NULL
);
1564 while (*at
!= '\0') {
1567 g_string_append(str
, "\\\\");
1570 g_string_append(str
, "\\\"");
1573 g_string_append(str
, "'\"'\"'");
1576 g_string_append(str
, "\\n");
1579 g_string_append(str
, "\\t");
1582 g_string_append_c(str
, *at
);
1592 g_string_free(str
, FALSE
);
1599 int append_prefixed_flag_params(GString
*str
, struct bt_value
*flags
,
1609 for (i
= 0; i
< bt_value_array_size(flags
); i
++) {
1610 struct bt_value
*value
= bt_value_array_get(flags
, i
);
1618 if (bt_value_string_get(value
, &flag
)) {
1624 g_string_append_printf(str
, ",%s-%s=true", prefix
, flag
);
1633 * Appends a boolean parameter string.
1636 void g_string_append_bool_param(GString
*str
, const char *name
, bool value
)
1638 g_string_append_printf(str
, ",%s=%s", name
, value
? "true" : "false");
1642 * Appends a path parameter string, or null if it's empty.
1645 int g_string_append_string_path_param(GString
*str
, const char *name
,
1650 if (path
->len
> 0) {
1651 char *escaped_path
= str_shell_escape(path
->str
);
1653 if (!escaped_path
) {
1658 g_string_append_printf(str
, "%s=\"%s\"", name
, escaped_path
);
1661 g_string_append_printf(str
, "%s=null", name
);
1674 * Prints the non-legacy sink options equivalent to the specified
1675 * legacy output format options.
1678 void print_output_legacy_to_sinks(
1679 enum legacy_output_format legacy_output_format
,
1680 struct text_legacy_opts
*text_legacy_opts
)
1682 const char *output_format
;
1683 GString
*str
= NULL
;
1685 str
= g_string_new(" ");
1691 switch (legacy_output_format
) {
1692 case LEGACY_OUTPUT_FORMAT_TEXT
:
1693 output_format
= "text";
1695 case LEGACY_OUTPUT_FORMAT_CTF_METADATA
:
1696 output_format
= "ctf-metadata";
1698 case LEGACY_OUTPUT_FORMAT_DUMMY
:
1699 output_format
= "dummy";
1705 printf_err("Both `%s` legacy output format and non-legacy sink component\ninstances(s) specified.\n\n",
1707 printf_err("Specify the following non-legacy sink component instance instead of the\nlegacy `%s` output format options:\n\n",
1709 g_string_append(str
, "-o ");
1711 switch (legacy_output_format
) {
1712 case LEGACY_OUTPUT_FORMAT_TEXT
:
1713 g_string_append(str
, "text.text");
1715 case LEGACY_OUTPUT_FORMAT_CTF_METADATA
:
1716 g_string_append(str
, "ctf.metadata-text");
1718 case LEGACY_OUTPUT_FORMAT_DUMMY
:
1719 g_string_append(str
, "utils.dummy");
1725 if (legacy_output_format
== LEGACY_OUTPUT_FORMAT_TEXT
&&
1726 text_legacy_opts_is_any_set(text_legacy_opts
)) {
1729 g_string_append(str
, " -p '");
1731 if (g_string_append_string_path_param(str
, "output-path",
1732 text_legacy_opts
->output
)) {
1736 g_string_append(str
, ",");
1738 if (g_string_append_string_path_param(str
, "debug-info-dir",
1739 text_legacy_opts
->dbg_info_dir
)) {
1743 g_string_append(str
, ",");
1745 if (g_string_append_string_path_param(str
,
1746 "debug-info-target-prefix",
1747 text_legacy_opts
->dbg_info_target_prefix
)) {
1751 g_string_append_bool_param(str
, "no-delta",
1752 text_legacy_opts
->no_delta
);
1753 g_string_append_bool_param(str
, "clock-cycles",
1754 text_legacy_opts
->clock_cycles
);
1755 g_string_append_bool_param(str
, "clock-seconds",
1756 text_legacy_opts
->clock_seconds
);
1757 g_string_append_bool_param(str
, "clock-date",
1758 text_legacy_opts
->clock_date
);
1759 g_string_append_bool_param(str
, "clock-gmt",
1760 text_legacy_opts
->clock_gmt
);
1761 ret
= append_prefixed_flag_params(str
, text_legacy_opts
->names
,
1767 ret
= append_prefixed_flag_params(str
, text_legacy_opts
->fields
,
1773 /* Remove last comma and close single quote */
1774 g_string_append(str
, "'");
1777 printf_err("%s\n\n", str
->str
);
1781 g_string_free(str
, TRUE
);
1787 * Prints the non-legacy source options equivalent to the specified
1788 * legacy input format options.
1791 void print_input_legacy_to_sources(enum legacy_input_format legacy_input_format
,
1792 struct bt_value
*legacy_input_paths
,
1793 struct ctf_legacy_opts
*ctf_legacy_opts
)
1795 const char *input_format
;
1796 GString
*str
= NULL
;
1799 str
= g_string_new(" ");
1805 switch (legacy_input_format
) {
1806 case LEGACY_INPUT_FORMAT_CTF
:
1807 input_format
= "ctf";
1809 case LEGACY_INPUT_FORMAT_LTTNG_LIVE
:
1810 input_format
= "lttng-live";
1816 printf_err("Both `%s` legacy input format and non-legacy source component\ninstance(s) specified.\n\n",
1818 printf_err("Specify the following non-legacy source component instance(s) instead of the\nlegacy `%s` input format options and positional arguments:\n\n",
1821 for (i
= 0; i
< bt_value_array_size(legacy_input_paths
); i
++) {
1822 struct bt_value
*input_value
=
1823 bt_value_array_get(legacy_input_paths
, i
);
1824 const char *input
= NULL
;
1825 char *escaped_input
;
1828 assert(input_value
);
1829 ret
= bt_value_string_get(input_value
, &input
);
1830 BT_PUT(input_value
);
1831 assert(!ret
&& input
);
1832 escaped_input
= str_shell_escape(input
);
1833 if (!escaped_input
) {
1838 g_string_append(str
, "-i ctf.");
1840 switch (legacy_input_format
) {
1841 case LEGACY_INPUT_FORMAT_CTF
:
1842 g_string_append(str
, "fs -p 'path=\"");
1844 case LEGACY_INPUT_FORMAT_LTTNG_LIVE
:
1845 g_string_append(str
, "lttng-live -p 'url=\"");
1851 g_string_append(str
, escaped_input
);
1852 g_string_append(str
, "\"");
1853 g_string_append_printf(str
, ",offset-s=%" PRId64
,
1854 ctf_legacy_opts
->offset_s
.value
);
1855 g_string_append_printf(str
, ",offset-ns=%" PRId64
,
1856 ctf_legacy_opts
->offset_ns
.value
);
1857 g_string_append_bool_param(str
, "stream-intersection",
1858 ctf_legacy_opts
->stream_intersection
);
1859 g_string_append(str
, "' ");
1860 g_free(escaped_input
);
1863 printf_err("%s\n\n", str
->str
);
1867 g_string_free(str
, TRUE
);
1873 * Validates a given configuration, with optional legacy input and
1874 * output formats options. Prints useful error messages if anything
1877 * Returns true when the configuration is valid.
1880 bool validate_cfg(struct bt_config
*cfg
,
1881 enum legacy_input_format
*legacy_input_format
,
1882 enum legacy_output_format
*legacy_output_format
,
1883 struct bt_value
*legacy_input_paths
,
1884 struct ctf_legacy_opts
*ctf_legacy_opts
,
1885 struct text_legacy_opts
*text_legacy_opts
)
1887 bool legacy_input
= false;
1888 bool legacy_output
= false;
1890 /* Determine if the input and output should be legacy-style */
1891 if (*legacy_input_format
!= LEGACY_INPUT_FORMAT_NONE
||
1892 !bt_value_array_is_empty(legacy_input_paths
) ||
1893 ctf_legacy_opts_is_any_set(ctf_legacy_opts
)) {
1894 legacy_input
= true;
1897 if (*legacy_output_format
!= LEGACY_OUTPUT_FORMAT_NONE
||
1898 text_legacy_opts_is_any_set(text_legacy_opts
)) {
1899 legacy_output
= true;
1903 /* If no legacy input format was specified, default to CTF */
1904 if (*legacy_input_format
== LEGACY_INPUT_FORMAT_NONE
) {
1905 *legacy_input_format
= LEGACY_INPUT_FORMAT_CTF
;
1908 /* Make sure at least one input path exists */
1909 if (bt_value_array_is_empty(legacy_input_paths
)) {
1910 switch (*legacy_input_format
) {
1911 case LEGACY_INPUT_FORMAT_CTF
:
1912 printf_err("No input path specified for legacy `ctf` input format\n");
1914 case LEGACY_INPUT_FORMAT_LTTNG_LIVE
:
1915 printf_err("No URL specified for legacy `lttng-live` input format\n");
1923 /* Make sure no non-legacy sources are specified */
1924 if (cfg
->cmd_data
.convert
.sources
->len
!= 0) {
1925 print_input_legacy_to_sources(*legacy_input_format
,
1926 legacy_input_paths
, ctf_legacy_opts
);
1931 if (legacy_output
) {
1933 * If no legacy output format was specified, default to
1936 if (*legacy_output_format
== LEGACY_OUTPUT_FORMAT_NONE
) {
1937 *legacy_output_format
= LEGACY_OUTPUT_FORMAT_TEXT
;
1941 * If any "text" option was specified, the output must be
1944 if (text_legacy_opts_is_any_set(text_legacy_opts
) &&
1945 *legacy_output_format
!=
1946 LEGACY_OUTPUT_FORMAT_TEXT
) {
1947 printf_err("Options for legacy `text` output format specified with a different legacy output format\n");
1951 /* Make sure no non-legacy sinks are specified */
1952 if (cfg
->cmd_data
.convert
.sinks
->len
!= 0) {
1953 print_output_legacy_to_sinks(*legacy_output_format
,
1960 * If the output is the legacy "ctf-metadata" format, then the
1961 * input should be the legacy "ctf" input format.
1963 if (*legacy_output_format
== LEGACY_OUTPUT_FORMAT_CTF_METADATA
&&
1964 *legacy_input_format
!= LEGACY_INPUT_FORMAT_CTF
) {
1965 printf_err("Legacy `ctf-metadata` output format requires using legacy `ctf` input format\n");
1976 * Parses a 64-bit signed integer.
1978 * Returns a negative value if anything goes wrong.
1981 int parse_int64(const char *arg
, int64_t *val
)
1986 *val
= strtoll(arg
, &endptr
, 0);
1987 if (*endptr
!= '\0' || arg
== endptr
|| errno
!= 0) {
2001 OPT_CLOCK_FORCE_CORRELATE
,
2004 OPT_CLOCK_OFFSET_NS
,
2009 OPT_DEBUG_INFO_FULL_PATH
,
2010 OPT_DEBUG_INFO_TARGET_PREFIX
,
2020 OPT_OMIT_HOME_PLUGIN_PATH
,
2021 OPT_OMIT_SYSTEM_PLUGIN_PATH
,
2027 OPT_RESET_BASE_PARAMS
,
2030 OPT_STREAM_INTERSECTION
,
2036 * Sets the value of a given legacy offset option and marks it as set.
2038 static void set_offset_value(struct offset_opt
*offset_opt
, int64_t value
)
2040 offset_opt
->value
= value
;
2041 offset_opt
->is_set
= true;
2044 enum bt_config_component_dest
{
2045 BT_CONFIG_COMPONENT_DEST_SOURCE
,
2046 BT_CONFIG_COMPONENT_DEST_SINK
,
2050 * Adds a configuration component to the appropriate configuration
2051 * array depending on the destination.
2053 static void add_cfg_comp(struct bt_config
*cfg
,
2054 struct bt_config_component
*cfg_comp
,
2055 enum bt_config_component_dest dest
)
2057 if (dest
== BT_CONFIG_COMPONENT_DEST_SOURCE
) {
2058 g_ptr_array_add(cfg
->cmd_data
.convert
.sources
, cfg_comp
);
2060 g_ptr_array_add(cfg
->cmd_data
.convert
.sinks
, cfg_comp
);
2064 static int split_timerange(const char *arg
, const char **begin
, const char **end
)
2068 /* Try to match [begin,end] */
2069 c
= strchr(arg
, '[');
2083 /* Try to match begin,end */
2097 static int append_env_var_plugin_paths(struct bt_value
*plugin_paths
)
2102 if (bt_common_is_setuid_setgid()) {
2103 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
2107 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
2112 ret
= bt_config_append_plugin_paths(plugin_paths
, envvar
);
2118 static int append_home_and_system_plugin_paths(struct bt_value
*plugin_paths
,
2119 bool omit_system_plugin_path
, bool omit_home_plugin_path
)
2123 if (!omit_home_plugin_path
) {
2124 if (bt_common_is_setuid_setgid()) {
2125 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
2127 char *home_plugin_dir
=
2128 bt_common_get_home_plugin_path();
2130 if (home_plugin_dir
) {
2131 ret
= bt_config_append_plugin_paths(
2134 free(home_plugin_dir
);
2137 printf_err("Invalid home plugin path\n");
2144 if (!omit_system_plugin_path
) {
2145 if (bt_config_append_plugin_paths(plugin_paths
,
2146 bt_common_get_system_plugin_path())) {
2147 printf_err("Invalid system plugin path\n");
2156 static int append_sources_from_implicit_params(GPtrArray
*sources
,
2157 struct bt_config_component
*implicit_source_comp
)
2160 size_t len
= sources
->len
;
2162 for (i
= 0; i
< len
; i
++) {
2163 struct bt_config_component
*comp
;
2164 struct bt_value
*params_to_set
;
2166 comp
= g_ptr_array_index(sources
, i
);
2167 params_to_set
= bt_value_map_extend(comp
->params
,
2168 implicit_source_comp
->params
);
2169 if (!params_to_set
) {
2170 printf_err("Cannot extend legacy component parameters with non-legacy parameters\n");
2173 BT_MOVE(comp
->params
, params_to_set
);
2180 static struct bt_config
*bt_config_base_create(enum bt_config_command command
)
2182 struct bt_config
*cfg
;
2185 cfg
= g_new0(struct bt_config
, 1);
2191 bt_object_init(cfg
, bt_config_destroy
);
2192 cfg
->command
= command
;
2202 static struct bt_config
*bt_config_convert_create(
2203 struct bt_value
*initial_plugin_paths
)
2205 struct bt_config
*cfg
;
2208 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_CONVERT
);
2214 cfg
->cmd_data
.convert
.sources
= g_ptr_array_new_with_free_func(
2215 (GDestroyNotify
) bt_put
);
2216 if (!cfg
->cmd_data
.convert
.sources
) {
2221 cfg
->cmd_data
.convert
.filters
= g_ptr_array_new_with_free_func(
2222 (GDestroyNotify
) bt_put
);
2223 if (!cfg
->cmd_data
.convert
.filters
) {
2228 cfg
->cmd_data
.convert
.sinks
= g_ptr_array_new_with_free_func(
2229 (GDestroyNotify
) bt_put
);
2230 if (!cfg
->cmd_data
.convert
.sinks
) {
2235 cfg
->cmd_data
.convert
.connections
= g_ptr_array_new_with_free_func(
2236 (GDestroyNotify
) bt_config_connection_destroy
);
2237 if (!cfg
->cmd_data
.convert
.connections
) {
2242 if (initial_plugin_paths
) {
2243 cfg
->cmd_data
.convert
.plugin_paths
=
2244 bt_get(initial_plugin_paths
);
2246 cfg
->cmd_data
.convert
.plugin_paths
= bt_value_array_create();
2247 if (!cfg
->cmd_data
.convert
.plugin_paths
) {
2262 static struct bt_config
*bt_config_list_plugins_create(
2263 struct bt_value
*initial_plugin_paths
)
2265 struct bt_config
*cfg
;
2268 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_LIST_PLUGINS
);
2274 if (initial_plugin_paths
) {
2275 cfg
->cmd_data
.list_plugins
.plugin_paths
=
2276 bt_get(initial_plugin_paths
);
2278 cfg
->cmd_data
.list_plugins
.plugin_paths
=
2279 bt_value_array_create();
2280 if (!cfg
->cmd_data
.list_plugins
.plugin_paths
) {
2295 static struct bt_config
*bt_config_help_create(
2296 struct bt_value
*initial_plugin_paths
)
2298 struct bt_config
*cfg
;
2301 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_HELP
);
2307 if (initial_plugin_paths
) {
2308 cfg
->cmd_data
.help
.plugin_paths
=
2309 bt_get(initial_plugin_paths
);
2311 cfg
->cmd_data
.help
.plugin_paths
=
2312 bt_value_array_create();
2313 if (!cfg
->cmd_data
.help
.plugin_paths
) {
2319 cfg
->cmd_data
.help
.cfg_component
=
2320 bt_config_component_create(BT_COMPONENT_CLASS_TYPE_UNKNOWN
,
2322 if (!cfg
->cmd_data
.help
.cfg_component
) {
2337 * Prints the help command usage.
2340 void print_help_usage(FILE *fp
)
2342 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
2343 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --source PLUGIN.COMPCLS\n");
2344 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --filter PLUGIN.COMPCLS\n");
2345 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --sink PLUGIN.COMPCLS\n");
2347 fprintf(fp
, "Options:\n");
2349 fprintf(fp
, " --filter=PLUGIN.COMPCLS Get help for the filter component class\n");
2350 fprintf(fp
, " COMPCLS found in the plugin PLUGIN\n");
2351 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2352 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2353 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2354 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2355 fprintf(fp
, " dynamic plugins can be loaded\n");
2356 fprintf(fp
, " --sink=PLUGIN.COMPCLS Get help for the sink component class\n");
2357 fprintf(fp
, " COMPCLS found in the plugin PLUGIN\n");
2358 fprintf(fp
, " --source=PLUGIN.COMPCLS Get help for the source component class\n");
2359 fprintf(fp
, " COMPCLS found in the plugin PLUGIN\n");
2360 fprintf(fp
, " -h --help Show this help and quit\n");
2362 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2364 fprintf(fp
, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
2367 static struct poptOption help_long_options
[] = {
2368 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2369 { "filter", '\0', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
2370 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2371 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2372 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2373 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2374 { "sink", '\0', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
2375 { "source", '\0', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
2376 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
2380 * Creates a Babeltrace config object from the arguments of a help
2383 * *retcode is set to the appropriate exit code to use.
2385 struct bt_config
*bt_config_help_from_args(int argc
, const char *argv
[],
2386 int *retcode
, bool omit_system_plugin_path
,
2387 bool omit_home_plugin_path
,
2388 struct bt_value
*initial_plugin_paths
)
2390 poptContext pc
= NULL
;
2394 struct bt_config
*cfg
= NULL
;
2395 const char *leftover
;
2396 char *plugin_name
= NULL
, *component_name
= NULL
;
2397 char *plugin_comp_cls_names
= NULL
;
2400 cfg
= bt_config_help_create(initial_plugin_paths
);
2406 cfg
->cmd_data
.help
.omit_system_plugin_path
= omit_system_plugin_path
;
2407 cfg
->cmd_data
.help
.omit_home_plugin_path
= omit_home_plugin_path
;
2408 ret
= append_env_var_plugin_paths(cfg
->cmd_data
.help
.plugin_paths
);
2410 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
2415 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2416 help_long_options
, 0);
2418 printf_err("Cannot get popt context\n");
2422 poptReadDefaultConfig(pc
, 0);
2424 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2425 arg
= poptGetOptArg(pc
);
2428 case OPT_PLUGIN_PATH
:
2429 if (bt_common_is_setuid_setgid()) {
2430 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
2432 if (bt_config_append_plugin_paths(
2433 cfg
->cmd_data
.help
.plugin_paths
,
2435 printf_err("Invalid --plugin-path option's argument:\n %s\n",
2441 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2442 cfg
->cmd_data
.help
.omit_system_plugin_path
= true;
2444 case OPT_OMIT_HOME_PLUGIN_PATH
:
2445 cfg
->cmd_data
.help
.omit_home_plugin_path
= true;
2450 if (cfg
->cmd_data
.help
.cfg_component
->type
!=
2451 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
2452 printf_err("Cannot specify more than one plugin and component class:\n %s\n",
2459 cfg
->cmd_data
.help
.cfg_component
->type
=
2460 BT_COMPONENT_CLASS_TYPE_SOURCE
;
2463 cfg
->cmd_data
.help
.cfg_component
->type
=
2464 BT_COMPONENT_CLASS_TYPE_FILTER
;
2467 cfg
->cmd_data
.help
.cfg_component
->type
=
2468 BT_COMPONENT_CLASS_TYPE_SINK
;
2473 plugin_comp_cls_names
= strdup(arg
);
2474 if (!plugin_comp_cls_names
) {
2480 print_help_usage(stdout
);
2485 printf_err("Unknown command-line option specified (option code %d)\n",
2494 /* Check for option parsing error */
2496 printf_err("While parsing command-line options, at option %s: %s\n",
2497 poptBadOption(pc
, 0), poptStrerror(opt
));
2501 leftover
= poptGetArg(pc
);
2503 if (cfg
->cmd_data
.help
.cfg_component
->type
!=
2504 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
2505 printf_err("Cannot specify plugin name and --source/--filter/--sink component class:\n %s\n",
2510 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
2513 if (cfg
->cmd_data
.help
.cfg_component
->type
==
2514 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
2515 print_help_usage(stdout
);
2521 plugin_component_names_from_arg(plugin_comp_cls_names
,
2522 &plugin_name
, &component_name
);
2523 if (plugin_name
&& component_name
) {
2524 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
2526 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->component_name
,
2529 printf_err("Invalid --source/--filter/--sink option's argument:\n %s\n",
2530 plugin_comp_cls_names
);
2535 if (append_home_and_system_plugin_paths(
2536 cfg
->cmd_data
.help
.plugin_paths
,
2537 cfg
->cmd_data
.help
.omit_system_plugin_path
,
2538 cfg
->cmd_data
.help
.omit_home_plugin_path
)) {
2539 printf_err("Cannot append home and system plugin paths\n");
2550 free(plugin_comp_cls_names
);
2551 g_free(plugin_name
);
2552 g_free(component_name
);
2555 poptFreeContext(pc
);
2563 * Prints the list-plugins command usage.
2566 void print_list_plugins_usage(FILE *fp
)
2568 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
2570 fprintf(fp
, "Options:\n");
2572 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2573 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2574 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2575 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2576 fprintf(fp
, " dynamic plugins can be loaded\n");
2577 fprintf(fp
, " -h --help Show this help and quit\n");
2579 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2581 fprintf(fp
, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
2584 static struct poptOption list_plugins_long_options
[] = {
2585 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2586 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2587 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2588 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2589 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2590 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
2594 * Creates a Babeltrace config object from the arguments of a
2595 * list-plugins command.
2597 * *retcode is set to the appropriate exit code to use.
2599 struct bt_config
*bt_config_list_plugins_from_args(int argc
, const char *argv
[],
2600 int *retcode
, bool omit_system_plugin_path
,
2601 bool omit_home_plugin_path
,
2602 struct bt_value
*initial_plugin_paths
)
2604 poptContext pc
= NULL
;
2608 struct bt_config
*cfg
= NULL
;
2609 const char *leftover
;
2612 cfg
= bt_config_list_plugins_create(initial_plugin_paths
);
2618 cfg
->cmd_data
.list_plugins
.omit_system_plugin_path
= omit_system_plugin_path
;
2619 cfg
->cmd_data
.list_plugins
.omit_home_plugin_path
= omit_home_plugin_path
;
2620 ret
= append_env_var_plugin_paths(
2621 cfg
->cmd_data
.list_plugins
.plugin_paths
);
2623 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
2628 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2629 list_plugins_long_options
, 0);
2631 printf_err("Cannot get popt context\n");
2635 poptReadDefaultConfig(pc
, 0);
2637 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2638 arg
= poptGetOptArg(pc
);
2641 case OPT_PLUGIN_PATH
:
2642 if (bt_common_is_setuid_setgid()) {
2643 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
2645 if (bt_config_append_plugin_paths(
2646 cfg
->cmd_data
.list_plugins
.plugin_paths
,
2648 printf_err("Invalid --plugin-path option's argument:\n %s\n",
2654 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2655 cfg
->cmd_data
.list_plugins
.omit_system_plugin_path
= true;
2657 case OPT_OMIT_HOME_PLUGIN_PATH
:
2658 cfg
->cmd_data
.list_plugins
.omit_home_plugin_path
= true;
2661 print_list_plugins_usage(stdout
);
2666 printf_err("Unknown command-line option specified (option code %d)\n",
2675 /* Check for option parsing error */
2677 printf_err("While parsing command-line options, at option %s: %s\n",
2678 poptBadOption(pc
, 0), poptStrerror(opt
));
2682 leftover
= poptGetArg(pc
);
2684 printf_err("Invalid argument: %s\n", leftover
);
2688 if (append_home_and_system_plugin_paths(
2689 cfg
->cmd_data
.list_plugins
.plugin_paths
,
2690 cfg
->cmd_data
.list_plugins
.omit_system_plugin_path
,
2691 cfg
->cmd_data
.list_plugins
.omit_home_plugin_path
)) {
2692 printf_err("Cannot append home and system plugin paths\n");
2704 poptFreeContext(pc
);
2712 * Prints the legacy, Babeltrace 1.x command usage. Those options are
2713 * still compatible in Babeltrace 2.x, but it is recommended to use
2714 * the more generic plugin/component parameters instead of those
2715 * hard-coded option names.
2718 void print_legacy_usage(FILE *fp
)
2720 fprintf(fp
, "Usage: babeltrace [OPTIONS] INPUT...\n");
2722 fprintf(fp
, "The following options are compatible with the Babeltrace 1.x options:\n");
2724 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently correlated\n");
2725 fprintf(fp
, " across traces\n");
2726 fprintf(fp
, " -d, --debug Enable debug mode\n");
2727 fprintf(fp
, " -i, --input-format=FORMAT Input trace format (default: ctf)\n");
2728 fprintf(fp
, " -l, --list List available formats\n");
2729 fprintf(fp
, " -o, --output-format=FORMAT Output trace format (default: text)\n");
2730 fprintf(fp
, " -v, --verbose Enable verbose output\n");
2731 fprintf(fp
, " --help-legacy Show this help and quit\n");
2732 fprintf(fp
, " -V, --version Show version and quit\n");
2734 fprintf(fp
, " Available input formats: ctf, lttng-live, ctf-metadata\n");
2735 fprintf(fp
, " Available output formats: text, dummy\n");
2737 fprintf(fp
, "Input formats specific options:\n");
2739 fprintf(fp
, " INPUT... Input trace file(s), directory(ies), or URLs\n");
2740 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
2741 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS nanoseconds\n");
2742 fprintf(fp
, " --stream-intersection Only process events when all streams are active\n");
2744 fprintf(fp
, "text output format specific options:\n");
2746 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
2747 fprintf(fp
, " --clock-date Print timestamp dates\n");
2748 fprintf(fp
, " --clock-gmt Print and parse timestamps in GMT time zone\n");
2749 fprintf(fp
, " (default: local time zone)\n");
2750 fprintf(fp
, " --clock-seconds Print the timestamps as [SEC.NS]\n");
2751 fprintf(fp
, " (default format: [HH:MM:SS.NS])\n");
2752 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
2753 fprintf(fp
, " (default: `/usr/lib/debug`)\n");
2754 fprintf(fp
, " --debug-info-full-path Show full debug info source and binary paths\n");
2755 fprintf(fp
, " --debug-info-target-prefix=DIR Use directory DIR as a prefix when looking\n");
2756 fprintf(fp
, " up executables during debug info analysis\n");
2757 fprintf(fp
, " (default: `/usr/lib/debug`)\n");
2758 fprintf(fp
, " -f, --fields=NAME[,NAME]... Print additional fields:\n");
2759 fprintf(fp
, " all, trace, trace:hostname, trace:domain,\n");
2760 fprintf(fp
, " trace:procname, trace:vpid, loglevel, emf\n");
2761 fprintf(fp
, " (default: trace:hostname, trace:procname,\n");
2762 fprintf(fp
, " trace:vpid)\n");
2763 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names:\n");
2764 fprintf(fp
, " payload (or arg or args)\n");
2765 fprintf(fp
, " none, all, scope, header, context (or ctx)\n");
2766 fprintf(fp
, " (default: payload, context)\n");
2767 fprintf(fp
, " --no-delta Do not print time delta between consecutive\n");
2768 fprintf(fp
, " events\n");
2769 fprintf(fp
, " -w, --output=PATH Write output to PATH (default: standard output)\n");
2773 * Prints the convert command usage.
2776 void print_convert_usage(FILE *fp
)
2778 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] convert [OPTIONS]\n");
2780 fprintf(fp
, "Options:\n");
2782 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
2783 fprintf(fp
, " for the following component instances\n");
2784 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2785 fprintf(fp
, " --begin=BEGIN Set the `begin` parameter of the latest\n");
2786 fprintf(fp
, " source component instance to BEGIN\n");
2787 fprintf(fp
, " (see the suggested format of BEGIN below)\n");
2788 fprintf(fp
, " -c, --connect=CONNECTION Connect two component instances (see the\n");
2789 fprintf(fp
, " expected format of CONNECTION below)\n");
2790 fprintf(fp
, " -d, --debug Enable debug mode\n");
2791 fprintf(fp
, " --end=END Set the `end` parameter of the latest\n");
2792 fprintf(fp
, " source component instance to END\n");
2793 fprintf(fp
, " (see the suggested format of BEGIN below)\n");
2794 fprintf(fp
, " --name=NAME Set the name of the latest component\n");
2795 fprintf(fp
, " instance to NAME (must be unique amongst\n");
2796 fprintf(fp
, " all the names of the component instances)\n");
2797 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2798 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2799 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2800 fprintf(fp
, " -p, --params=PARAMS Set the parameters of the latest component\n");
2801 fprintf(fp
, " instance (in command-line order) to PARAMS\n");
2802 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2803 fprintf(fp
, " -P, --path=PATH Set the `path` parameter of the latest\n");
2804 fprintf(fp
, " component instance to PATH\n");
2805 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2806 fprintf(fp
, " dynamic plugins can be loaded\n");
2807 fprintf(fp
, " -r, --reset-base-params Reset the current base parameters of the\n");
2808 fprintf(fp
, " following source and sink component\n");
2809 fprintf(fp
, " instances to an empty map\n");
2810 fprintf(fp
, " -o, --sink=PLUGIN.COMPCLS Instantiate a sink component from plugin\n");
2811 fprintf(fp
, " PLUGIN and component class COMPCLS (may be\n");
2812 fprintf(fp
, " repeated)\n");
2813 fprintf(fp
, " -i, --source=PLUGIN.COMPCLS Instantiate a source component from plugin\n");
2814 fprintf(fp
, " PLUGIN and component class COMPCLS (may be\n");
2815 fprintf(fp
, " repeated)\n");
2816 fprintf(fp
, " --timerange=TIMERANGE Set time range to TIMERANGE: BEGIN,END or\n");
2817 fprintf(fp
, " [BEGIN,END] (literally `[` and `]`)\n");
2818 fprintf(fp
, " (suggested format of BEGIN/END below)\n");
2819 fprintf(fp
, " -v, --verbose Enable verbose output\n");
2820 fprintf(fp
, " -h --help Show this help and quit\n");
2822 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2823 fprintf(fp
, "\n\n");
2824 fprintf(fp
, "Suggested format of BEGIN and END\n");
2825 fprintf(fp
, "---------------------------------\n");
2827 fprintf(fp
, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
2828 fprintf(fp
, "\n\n");
2829 fprintf(fp
, "Expected format of CONNECTION\n");
2830 fprintf(fp
, "-----------------------------\n");
2832 fprintf(fp
, " SRC[.SRCPORT]:DST[.DSTPORT]\n");
2834 fprintf(fp
, "SRC and DST are the names of the source and destination component\n");
2835 fprintf(fp
, "instances to connect together. You can set the name of a component\n");
2836 fprintf(fp
, "instance with the --name option.\n");
2838 fprintf(fp
, "SRCPORT and DSTPORT are the optional source and destination ports to use\n");
2839 fprintf(fp
, "for the connection. When the port is not specified, the default port is\n");
2840 fprintf(fp
, "used.\n");
2842 fprintf(fp
, "You can connect a source component to a filter or sink component. You\n");
2843 fprintf(fp
, "can connect a filter component to a sink component.\n");
2845 fprintf(fp
, "Example:\n");
2847 fprintf(fp
, " my-filter.top10:json-out\n");
2848 fprintf(fp
, "\n\n");
2849 fprintf(fp
, "Expected format of PARAMS\n");
2850 fprintf(fp
, "-------------------------\n");
2852 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
2854 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
2855 fprintf(fp
, "where PARAM is the parameter name (C identifier plus [:.-] characters), and\n");
2856 fprintf(fp
, "VALUE can be one of:\n");
2858 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
2859 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
2860 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
2861 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
2862 fprintf(fp
, " (`0x` prefix) signed 64-bit integer.\n");
2863 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
2864 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
2865 fprintf(fp
, " the null and boolean value symbols above.\n");
2866 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
2868 fprintf(fp
, "Whitespaces are allowed around individual `=` and `,` tokens.\n");
2870 fprintf(fp
, "Example:\n");
2872 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
2873 fprintf(fp
, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
2874 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
2876 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run babeltrace\n");
2877 fprintf(fp
, "from a shell.\n");
2880 static struct poptOption convert_long_options
[] = {
2881 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2882 { "base-params", 'b', POPT_ARG_STRING
, NULL
, OPT_BASE_PARAMS
, NULL
, NULL
},
2883 { "begin", '\0', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2884 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2885 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2886 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2887 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2888 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2889 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2890 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2891 { "connect", 'c', POPT_ARG_STRING
, NULL
, OPT_CONNECT
, NULL
, NULL
},
2892 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2893 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2894 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2895 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2896 { "end", '\0', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2897 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2898 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2899 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2900 { "name", '\0', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2901 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2902 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2903 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2904 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2905 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_PATH
, NULL
, NULL
},
2906 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2907 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2908 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2909 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2910 { "reset-base-params", 'r', POPT_ARG_NONE
, NULL
, OPT_RESET_BASE_PARAMS
, NULL
, NULL
},
2911 { "sink", '\0', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
2912 { "source", '\0', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
2913 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2914 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2915 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2916 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
2920 * Creates a Babeltrace config object from the arguments of a convert
2923 * *retcode is set to the appropriate exit code to use.
2925 struct bt_config
*bt_config_convert_from_args(int argc
, const char *argv
[],
2926 int *retcode
, bool omit_system_plugin_path
,
2927 bool omit_home_plugin_path
,
2928 struct bt_value
*initial_plugin_paths
)
2930 poptContext pc
= NULL
;
2932 struct ctf_legacy_opts ctf_legacy_opts
;
2933 struct text_legacy_opts text_legacy_opts
;
2934 enum legacy_input_format legacy_input_format
= LEGACY_INPUT_FORMAT_NONE
;
2935 enum legacy_output_format legacy_output_format
=
2936 LEGACY_OUTPUT_FORMAT_NONE
;
2937 struct bt_value
*legacy_input_paths
= NULL
;
2938 struct bt_config_component
*implicit_source_comp
= NULL
;
2939 struct bt_config_component
*cur_cfg_comp
= NULL
;
2940 bool cur_is_implicit_source
= false;
2941 bool use_implicit_source
= false;
2942 enum bt_config_component_dest cur_cfg_comp_dest
=
2943 BT_CONFIG_COMPONENT_DEST_SOURCE
;
2944 struct bt_value
*cur_base_params
= NULL
;
2946 struct bt_config
*cfg
= NULL
;
2947 struct bt_value
*instance_names
= NULL
;
2948 struct bt_value
*connection_args
= NULL
;
2949 char error_buf
[256] = { 0 };
2952 memset(&ctf_legacy_opts
, 0, sizeof(ctf_legacy_opts
));
2953 memset(&text_legacy_opts
, 0, sizeof(text_legacy_opts
));
2956 print_convert_usage(stdout
);
2961 cfg
= bt_config_convert_create(initial_plugin_paths
);
2967 cfg
->cmd_data
.convert
.omit_system_plugin_path
= omit_system_plugin_path
;
2968 cfg
->cmd_data
.convert
.omit_home_plugin_path
= omit_home_plugin_path
;
2969 text_legacy_opts
.output
= g_string_new(NULL
);
2970 if (!text_legacy_opts
.output
) {
2975 text_legacy_opts
.dbg_info_dir
= g_string_new(NULL
);
2976 if (!text_legacy_opts
.dbg_info_dir
) {
2981 text_legacy_opts
.dbg_info_target_prefix
= g_string_new(NULL
);
2982 if (!text_legacy_opts
.dbg_info_target_prefix
) {
2987 cur_base_params
= bt_value_map_create();
2988 if (!cur_base_params
) {
2993 legacy_input_paths
= bt_value_array_create();
2994 if (!legacy_input_paths
) {
2999 instance_names
= bt_value_map_create();
3000 if (!instance_names
) {
3005 connection_args
= bt_value_array_create();
3006 if (!connection_args
) {
3011 ret
= append_env_var_plugin_paths(cfg
->cmd_data
.convert
.plugin_paths
);
3013 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
3017 /* Note: implicit source never gets positional base params. */
3018 implicit_source_comp
= bt_config_component_from_arg(
3019 BT_COMPONENT_CLASS_TYPE_SOURCE
, DEFAULT_SOURCE_COMPONENT_NAME
);
3020 if (!implicit_source_comp
) {
3025 cur_cfg_comp
= implicit_source_comp
;
3026 cur_is_implicit_source
= true;
3027 use_implicit_source
= true;
3030 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3031 convert_long_options
, 0);
3033 printf_err("Cannot get popt context\n");
3037 poptReadDefaultConfig(pc
, 0);
3039 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3040 arg
= poptGetOptArg(pc
);
3043 case OPT_PLUGIN_PATH
:
3044 if (bt_common_is_setuid_setgid()) {
3045 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
3047 if (bt_config_append_plugin_paths(
3048 cfg
->cmd_data
.convert
.plugin_paths
,
3050 printf_err("Invalid --plugin-path option's argument:\n %s\n",
3056 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
3057 cfg
->cmd_data
.convert
.omit_system_plugin_path
= true;
3059 case OPT_OMIT_HOME_PLUGIN_PATH
:
3060 cfg
->cmd_data
.convert
.omit_home_plugin_path
= true;
3062 case OPT_OUTPUT_PATH
:
3063 if (text_legacy_opts
.output
->len
> 0) {
3064 printf_err("Duplicate --output option\n");
3068 g_string_assign(text_legacy_opts
.output
, arg
);
3070 case OPT_DEBUG_INFO_DIR
:
3071 if (text_legacy_opts
.dbg_info_dir
->len
> 0) {
3072 printf_err("Duplicate --debug-info-dir option\n");
3076 g_string_assign(text_legacy_opts
.dbg_info_dir
, arg
);
3078 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3079 if (text_legacy_opts
.dbg_info_target_prefix
->len
> 0) {
3080 printf_err("Duplicate --debug-info-target-prefix option\n");
3084 g_string_assign(text_legacy_opts
.dbg_info_target_prefix
, arg
);
3086 case OPT_INPUT_FORMAT
:
3089 if (opt
== OPT_INPUT_FORMAT
) {
3090 if (!strcmp(arg
, "ctf")) {
3091 /* Legacy CTF input format */
3092 if (legacy_input_format
) {
3093 print_err_dup_legacy_input();
3097 legacy_input_format
=
3098 LEGACY_INPUT_FORMAT_CTF
;
3100 } else if (!strcmp(arg
, "lttng-live")) {
3101 /* Legacy LTTng-live input format */
3102 if (legacy_input_format
) {
3103 print_err_dup_legacy_input();
3107 legacy_input_format
=
3108 LEGACY_INPUT_FORMAT_LTTNG_LIVE
;
3113 use_implicit_source
= false;
3115 /* Non-legacy: try to create a component config */
3116 if (cur_cfg_comp
&& !cur_is_implicit_source
) {
3117 add_cfg_comp(cfg
, cur_cfg_comp
,
3121 cur_cfg_comp
= bt_config_component_from_arg(
3122 BT_COMPONENT_CLASS_TYPE_SOURCE
, arg
);
3123 if (!cur_cfg_comp
) {
3124 printf_err("Invalid format for --source option's argument:\n %s\n",
3128 cur_is_implicit_source
= false;
3130 assert(cur_base_params
);
3131 bt_put(cur_cfg_comp
->params
);
3132 cur_cfg_comp
->params
= bt_value_copy(cur_base_params
);
3133 if (!cur_cfg_comp
->params
) {
3138 cur_cfg_comp_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
3141 case OPT_OUTPUT_FORMAT
:
3144 if (opt
== OPT_OUTPUT_FORMAT
) {
3145 if (!strcmp(arg
, "text")) {
3146 /* Legacy CTF-text output format */
3147 if (legacy_output_format
) {
3148 print_err_dup_legacy_output();
3152 legacy_output_format
=
3153 LEGACY_OUTPUT_FORMAT_TEXT
;
3155 } else if (!strcmp(arg
, "dummy")) {
3156 /* Legacy dummy output format */
3157 if (legacy_output_format
) {
3158 print_err_dup_legacy_output();
3162 legacy_output_format
=
3163 LEGACY_OUTPUT_FORMAT_DUMMY
;
3165 } else if (!strcmp(arg
, "ctf-metadata")) {
3166 /* Legacy CTF-metadata output format */
3167 if (legacy_output_format
) {
3168 print_err_dup_legacy_output();
3172 legacy_output_format
=
3173 LEGACY_OUTPUT_FORMAT_CTF_METADATA
;
3178 /* Non-legacy: try to create a component config */
3179 if (cur_cfg_comp
&& !cur_is_implicit_source
) {
3180 add_cfg_comp(cfg
, cur_cfg_comp
,
3184 cur_cfg_comp
= bt_config_component_from_arg(
3185 BT_COMPONENT_CLASS_TYPE_SINK
, arg
);
3186 if (!cur_cfg_comp
) {
3187 printf_err("Invalid format for --sink option's argument:\n %s\n",
3191 cur_is_implicit_source
= false;
3193 assert(cur_base_params
);
3194 bt_put(cur_cfg_comp
->params
);
3195 cur_cfg_comp
->params
= bt_value_copy(cur_base_params
);
3196 if (!cur_cfg_comp
->params
) {
3201 cur_cfg_comp_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
3206 struct bt_value
*params
;
3207 struct bt_value
*params_to_set
;
3209 if (!cur_cfg_comp
) {
3210 printf_err("Cannot add parameters to unavailable default source component `%s`:\n %s\n",
3211 DEFAULT_SOURCE_COMPONENT_NAME
, arg
);
3215 params
= bt_value_from_arg(arg
);
3217 printf_err("Invalid format for --params option's argument:\n %s\n",
3222 params_to_set
= bt_value_map_extend(cur_cfg_comp
->params
,
3225 if (!params_to_set
) {
3226 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
3231 BT_MOVE(cur_cfg_comp
->params
, params_to_set
);
3235 if (!cur_cfg_comp
) {
3236 printf_err("Cannot add `path` parameter to unavailable default source component `%s`:\n %s\n",
3237 DEFAULT_SOURCE_COMPONENT_NAME
, arg
);
3241 assert(cur_cfg_comp
->params
);
3243 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
3250 if (!cur_cfg_comp
) {
3251 printf_err("Cannot set the name of unavailable default source component `%s`:\n %s\n",
3252 DEFAULT_SOURCE_COMPONENT_NAME
, arg
);
3256 if (bt_value_map_has_key(instance_names
, arg
)) {
3257 printf_err("Duplicate component instance name:\n %s\n",
3262 g_string_assign(cur_cfg_comp
->instance_name
, arg
);
3264 if (bt_value_map_insert(instance_names
,
3265 arg
, bt_value_null
)) {
3270 case OPT_BASE_PARAMS
:
3272 struct bt_value
*params
= bt_value_from_arg(arg
);
3275 printf_err("Invalid format for --base-params option's argument:\n %s\n",
3280 BT_MOVE(cur_base_params
, params
);
3283 case OPT_RESET_BASE_PARAMS
:
3284 BT_PUT(cur_base_params
);
3285 cur_base_params
= bt_value_map_create();
3286 if (!cur_base_params
) {
3292 if (text_legacy_opts
.names
) {
3293 printf_err("Duplicate --names option\n");
3297 text_legacy_opts
.names
= names_from_arg(arg
);
3298 if (!text_legacy_opts
.names
) {
3299 printf_err("Invalid --names option's argument:\n %s\n",
3305 if (text_legacy_opts
.fields
) {
3306 printf_err("Duplicate --fields option\n");
3310 text_legacy_opts
.fields
= fields_from_arg(arg
);
3311 if (!text_legacy_opts
.fields
) {
3312 printf_err("Invalid --fields option's argument:\n %s\n",
3318 text_legacy_opts
.no_delta
= true;
3320 case OPT_CLOCK_CYCLES
:
3321 text_legacy_opts
.clock_cycles
= true;
3323 case OPT_CLOCK_SECONDS
:
3324 text_legacy_opts
.clock_seconds
= true;
3326 case OPT_CLOCK_DATE
:
3327 text_legacy_opts
.clock_date
= true;
3330 text_legacy_opts
.clock_gmt
= true;
3332 case OPT_DEBUG_INFO_FULL_PATH
:
3333 text_legacy_opts
.dbg_info_full_path
= true;
3335 case OPT_CLOCK_OFFSET
:
3339 if (ctf_legacy_opts
.offset_s
.is_set
) {
3340 printf_err("Duplicate --clock-offset option\n");
3344 if (parse_int64(arg
, &val
)) {
3345 printf_err("Invalid --clock-offset option's argument:\n %s\n",
3350 set_offset_value(&ctf_legacy_opts
.offset_s
, val
);
3353 case OPT_CLOCK_OFFSET_NS
:
3357 if (ctf_legacy_opts
.offset_ns
.is_set
) {
3358 printf_err("Duplicate --clock-offset-ns option\n");
3362 if (parse_int64(arg
, &val
)) {
3363 printf_err("Invalid --clock-offset-ns option's argument:\n %s\n",
3368 set_offset_value(&ctf_legacy_opts
.offset_ns
, val
);
3371 case OPT_STREAM_INTERSECTION
:
3372 ctf_legacy_opts
.stream_intersection
= true;
3374 case OPT_CLOCK_FORCE_CORRELATE
:
3375 cfg
->cmd_data
.convert
.force_correlate
= true;
3378 if (!cur_cfg_comp
) {
3379 printf_err("Cannot add `begin` parameter to unavailable default source component `%s`:\n %s\n",
3380 DEFAULT_SOURCE_COMPONENT_NAME
, arg
);
3383 if (cur_cfg_comp_dest
!= BT_CONFIG_COMPONENT_DEST_SOURCE
) {
3384 printf_err("--begin option must follow a --source option:\n %s\n",
3388 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
3395 if (!cur_cfg_comp
) {
3396 printf_err("Cannot add `end` parameter to unavailable default source component `%s`:\n %s\n",
3397 DEFAULT_SOURCE_COMPONENT_NAME
, arg
);
3400 if (cur_cfg_comp_dest
!= BT_CONFIG_COMPONENT_DEST_SOURCE
) {
3401 printf_err("--end option must follow a --source option:\n %s\n",
3405 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
3413 const char *begin
, *end
;
3415 if (!cur_cfg_comp
) {
3416 printf_err("Cannot add `begin` and `end` parameters to unavailable default source component `%s`:\n %s\n",
3417 DEFAULT_SOURCE_COMPONENT_NAME
, arg
);
3420 if (cur_cfg_comp_dest
!= BT_CONFIG_COMPONENT_DEST_SOURCE
) {
3421 printf_err("--timerange option must follow a --source option:\n %s\n",
3425 if (split_timerange(arg
, &begin
, &end
)) {
3426 printf_err("Invalid --timerange format: expecting BEGIN,END or [BEGIN,END]:\n %s\n",
3430 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
3435 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
3443 if (bt_value_array_append_string(connection_args
,
3450 print_convert_usage(stdout
);
3455 cfg
->verbose
= true;
3461 printf_err("Unknown command-line option specified (option code %d)\n",
3470 /* Check for option parsing error */
3472 printf_err("While parsing command-line options, at option %s: %s\n",
3473 poptBadOption(pc
, 0), poptStrerror(opt
));
3477 /* Consume leftover arguments as legacy input paths */
3479 const char *input_path
= poptGetArg(pc
);
3485 if (bt_value_array_append_string(legacy_input_paths
,
3492 if (append_home_and_system_plugin_paths(
3493 cfg
->cmd_data
.convert
.plugin_paths
,
3494 cfg
->cmd_data
.convert
.omit_system_plugin_path
,
3495 cfg
->cmd_data
.convert
.omit_home_plugin_path
)) {
3496 printf_err("Cannot append home and system plugin paths\n");
3500 /* Append current component configuration, if any */
3501 if (cur_cfg_comp
&& !cur_is_implicit_source
) {
3502 add_cfg_comp(cfg
, cur_cfg_comp
, cur_cfg_comp_dest
);
3504 cur_cfg_comp
= NULL
;
3506 /* Validate legacy/non-legacy options */
3507 if (!validate_cfg(cfg
, &legacy_input_format
, &legacy_output_format
,
3508 legacy_input_paths
, &ctf_legacy_opts
,
3509 &text_legacy_opts
)) {
3510 printf_err("Command-line options form an invalid configuration\n");
3515 * If there's a legacy input format, convert it to source
3516 * component configurations.
3518 if (legacy_input_format
) {
3519 if (append_sources_from_legacy_opts(
3520 cfg
->cmd_data
.convert
.sources
,
3521 legacy_input_format
, &ctf_legacy_opts
,
3522 legacy_input_paths
)) {
3523 printf_err("Cannot convert legacy input format options to source component instance(s)\n");
3526 if (append_sources_from_implicit_params(
3527 cfg
->cmd_data
.convert
.sources
,
3528 implicit_source_comp
)) {
3529 printf_err("Cannot initialize legacy component parameters\n");
3532 use_implicit_source
= false;
3534 if (use_implicit_source
) {
3535 add_cfg_comp(cfg
, implicit_source_comp
,
3536 BT_CONFIG_COMPONENT_DEST_SOURCE
);
3537 implicit_source_comp
= NULL
;
3539 if (implicit_source_comp
3540 && !bt_value_map_is_empty(implicit_source_comp
->params
)) {
3541 printf_err("Arguments specified for implicit source, but an explicit source has been specified, overriding it\n");
3548 * If there's a legacy output format, convert it to sink
3549 * component configurations.
3551 if (legacy_output_format
) {
3552 if (append_sinks_from_legacy_opts(cfg
->cmd_data
.convert
.sinks
,
3553 legacy_output_format
, &text_legacy_opts
)) {
3554 printf_err("Cannot convert legacy output format options to sink component instance(s)\n");
3559 if (cfg
->cmd_data
.convert
.sinks
->len
== 0) {
3560 /* Use implicit sink as default. */
3561 cur_cfg_comp
= bt_config_component_from_arg(
3562 BT_COMPONENT_CLASS_TYPE_SINK
,
3563 DEFAULT_SINK_COMPONENT_NAME
);
3564 if (!cur_cfg_comp
) {
3565 printf_error("Cannot find implicit sink plugin `%s`\n",
3566 DEFAULT_SINK_COMPONENT_NAME
);
3568 add_cfg_comp(cfg
, cur_cfg_comp
,
3569 BT_CONFIG_COMPONENT_DEST_SINK
);
3570 cur_cfg_comp
= NULL
;
3573 ret
= bt_config_create_connections(cfg
, connection_args
,
3576 printf_err("Cannot creation connections:\n%s", error_buf
);
3588 poptFreeContext(pc
);
3591 if (text_legacy_opts
.output
) {
3592 g_string_free(text_legacy_opts
.output
, TRUE
);
3595 if (text_legacy_opts
.dbg_info_dir
) {
3596 g_string_free(text_legacy_opts
.dbg_info_dir
, TRUE
);
3599 if (text_legacy_opts
.dbg_info_target_prefix
) {
3600 g_string_free(text_legacy_opts
.dbg_info_target_prefix
, TRUE
);
3604 BT_PUT(implicit_source_comp
);
3605 BT_PUT(cur_cfg_comp
);
3606 BT_PUT(cur_base_params
);
3607 BT_PUT(text_legacy_opts
.names
);
3608 BT_PUT(text_legacy_opts
.fields
);
3609 BT_PUT(legacy_input_paths
);
3610 BT_PUT(instance_names
);
3611 BT_PUT(connection_args
);
3616 * Prints the Babeltrace 2.x general usage.
3619 void print_gen_usage(FILE *fp
)
3621 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [COMMAND] [COMMAND OPTIONS]\n");
3623 fprintf(fp
, "General options:\n");
3625 fprintf(fp
, " -d, --debug Enable debug mode\n");
3626 fprintf(fp
, " -h --help Show this help and quit\n");
3627 fprintf(fp
, " --help-legacy Show Babeltrace 1.x legacy help and quit\n");
3628 fprintf(fp
, " -v, --verbose Enable verbose output\n");
3629 fprintf(fp
, " -V, --version Show version and quit\n");
3631 fprintf(fp
, "Available commands:\n");
3633 fprintf(fp
, " convert Build a trace conversion graph and run it (default)\n");
3634 fprintf(fp
, " help Get help for a plugin or a component class\n");
3635 fprintf(fp
, " list-plugins List available plugins and their content\n");
3637 fprintf(fp
, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
3640 struct bt_config
*bt_config_from_args(int argc
, const char *argv
[],
3641 int *retcode
, bool omit_system_plugin_path
,
3642 bool omit_home_plugin_path
,
3643 struct bt_value
*initial_plugin_paths
)
3645 struct bt_config
*config
= NULL
;
3646 bool verbose
= false;
3649 enum bt_config_command command
= -1;
3650 const char **command_argv
= NULL
;
3651 int command_argc
= -1;
3652 const char *command_name
= NULL
;
3657 print_gen_usage(stdout
);
3661 for (i
= 1; i
< argc
; i
++) {
3662 const char *cur_arg
= argv
[i
];
3664 if (strcmp(cur_arg
, "-d") == 0 ||
3665 strcmp(cur_arg
, "--debug") == 0) {
3667 } else if (strcmp(cur_arg
, "-v") == 0 ||
3668 strcmp(cur_arg
, "--verbose") == 0) {
3670 } else if (strcmp(cur_arg
, "-V") == 0 ||
3671 strcmp(cur_arg
, "--version") == 0) {
3674 } else if (strcmp(cur_arg
, "-h") == 0 ||
3675 strcmp(cur_arg
, "--help") == 0) {
3676 print_gen_usage(stdout
);
3678 } else if (strcmp(cur_arg
, "--help-legacy") == 0) {
3679 print_legacy_usage(stdout
);
3682 bool has_command
= true;
3685 * First unknown argument: is it a known command
3688 if (strcmp(cur_arg
, "convert") == 0) {
3689 command
= BT_CONFIG_COMMAND_CONVERT
;
3690 } else if (strcmp(cur_arg
, "list-plugins") == 0) {
3691 command
= BT_CONFIG_COMMAND_LIST_PLUGINS
;
3692 } else if (strcmp(cur_arg
, "help") == 0) {
3693 command
= BT_CONFIG_COMMAND_HELP
;
3696 * Unknown argument, but not a known
3697 * command name: assume the whole
3698 * arguments are for the default convert
3701 command
= BT_CONFIG_COMMAND_CONVERT
;
3702 command_argv
= argv
;
3703 command_argc
= argc
;
3704 has_command
= false;
3708 command_argv
= &argv
[i
];
3709 command_argc
= argc
- i
;
3710 command_name
= cur_arg
;
3716 if ((int) command
< 0) {
3718 * We only got non-help, non-version general options
3719 * like --verbose and --debug, without any other
3720 * arguments, so we can't do anything useful: print the
3723 print_gen_usage(stdout
);
3727 assert(command_argv
);
3728 assert(command_argc
>= 0);
3731 case BT_CONFIG_COMMAND_CONVERT
:
3732 config
= bt_config_convert_from_args(command_argc
, command_argv
,
3733 retcode
, omit_system_plugin_path
,
3734 omit_home_plugin_path
, initial_plugin_paths
);
3736 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
3737 config
= bt_config_list_plugins_from_args(command_argc
,
3738 command_argv
, retcode
, omit_system_plugin_path
,
3739 omit_home_plugin_path
, initial_plugin_paths
);
3741 case BT_CONFIG_COMMAND_HELP
:
3742 config
= bt_config_help_from_args(command_argc
,
3743 command_argv
, retcode
, omit_system_plugin_path
,
3744 omit_home_plugin_path
, initial_plugin_paths
);
3752 config
->verbose
= true;
3756 config
->debug
= true;
3759 config
->command_name
= command_name
;