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(const char *plugin_name
,
736 const char *component_name
)
738 struct bt_config_component
*cfg_component
= NULL
;
740 cfg_component
= g_new0(struct bt_config_component
, 1);
741 if (!cfg_component
) {
746 bt_object_init(cfg_component
, bt_config_component_destroy
);
747 cfg_component
->plugin_name
= g_string_new(plugin_name
);
748 if (!cfg_component
->plugin_name
) {
753 cfg_component
->component_name
= g_string_new(component_name
);
754 if (!cfg_component
->component_name
) {
759 cfg_component
->instance_name
= g_string_new(NULL
);
760 if (!cfg_component
->instance_name
) {
765 /* Start with empty parameters */
766 cfg_component
->params
= bt_value_map_create();
767 if (!cfg_component
->params
) {
775 BT_PUT(cfg_component
);
778 return cfg_component
;
782 * Creates a component configuration from a command-line source/sink
785 struct bt_config_component
*bt_config_component_from_arg(const char *arg
)
787 struct bt_config_component
*bt_config_component
= NULL
;
789 char *component_name
;
791 plugin_component_names_from_arg(arg
, &plugin_name
, &component_name
);
792 if (!plugin_name
|| !component_name
) {
793 printf_err("Cannot get plugin or component class name\n");
797 bt_config_component
= bt_config_component_create(plugin_name
,
799 if (!bt_config_component
) {
806 BT_PUT(bt_config_component
);
810 g_free(component_name
);
811 return bt_config_component
;
815 * Destroys a configuration.
818 void bt_config_destroy(struct bt_object
*obj
)
820 struct bt_config
*cfg
=
821 container_of(obj
, struct bt_config
, base
);
827 switch (cfg
->command
) {
828 case BT_CONFIG_COMMAND_CONVERT
:
829 if (cfg
->cmd_data
.convert
.sources
) {
830 g_ptr_array_free(cfg
->cmd_data
.convert
.sources
, TRUE
);
833 if (cfg
->cmd_data
.convert
.filters
) {
834 g_ptr_array_free(cfg
->cmd_data
.convert
.filters
, TRUE
);
837 if (cfg
->cmd_data
.convert
.sinks
) {
838 g_ptr_array_free(cfg
->cmd_data
.convert
.sinks
, TRUE
);
841 if (cfg
->cmd_data
.convert
.connections
) {
842 g_ptr_array_free(cfg
->cmd_data
.convert
.connections
,
846 BT_PUT(cfg
->cmd_data
.convert
.plugin_paths
);
848 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
849 BT_PUT(cfg
->cmd_data
.list_plugins
.plugin_paths
);
851 case BT_CONFIG_COMMAND_HELP
:
852 BT_PUT(cfg
->cmd_data
.help
.plugin_paths
);
854 if (cfg
->cmd_data
.help
.plugin_name
) {
855 g_string_free(cfg
->cmd_data
.help
.plugin_name
, TRUE
);
858 if (cfg
->cmd_data
.help
.component_name
) {
859 g_string_free(cfg
->cmd_data
.help
.component_name
, TRUE
);
872 static void destroy_gstring(void *data
)
874 g_string_free(data
, TRUE
);
878 * Extracts the various paths from the string arg, delimited by ':',
879 * and appends them to the array value object plugin_paths.
881 enum bt_value_status
bt_config_append_plugin_paths(
882 struct bt_value
*plugin_paths
, const char *arg
)
884 enum bt_value_status status
= BT_VALUE_STATUS_OK
;
885 GPtrArray
*dirs
= g_ptr_array_new_with_free_func(destroy_gstring
);
890 status
= BT_VALUE_STATUS_ERROR
;
894 ret
= bt_common_append_plugin_path_dirs(arg
, dirs
);
896 status
= BT_VALUE_STATUS_ERROR
;
900 for (i
= 0; i
< dirs
->len
; i
++) {
901 GString
*dir
= g_ptr_array_index(dirs
, i
);
903 bt_value_array_append_string(plugin_paths
, dir
->str
);
907 g_ptr_array_free(dirs
, TRUE
);
912 * Creates a simple lexical scanner for parsing comma-delimited names
915 * Return value is owned by the caller.
918 GScanner
*create_csv_identifiers_scanner(void)
920 GScannerConfig scanner_config
= {
921 .cset_skip_characters
= " \t\n",
922 .cset_identifier_first
= G_CSET_a_2_z G_CSET_A_2_Z
"_",
923 .cset_identifier_nth
= G_CSET_a_2_z G_CSET_A_2_Z
":_-",
924 .case_sensitive
= TRUE
,
925 .cpair_comment_single
= NULL
,
926 .skip_comment_multi
= TRUE
,
927 .skip_comment_single
= TRUE
,
928 .scan_comment_multi
= FALSE
,
929 .scan_identifier
= TRUE
,
930 .scan_identifier_1char
= TRUE
,
931 .scan_identifier_NULL
= FALSE
,
932 .scan_symbols
= FALSE
,
933 .symbol_2_token
= FALSE
,
934 .scope_0_fallback
= FALSE
,
935 .scan_binary
= FALSE
,
939 .scan_hex_dollar
= FALSE
,
940 .numbers_2_int
= FALSE
,
941 .int_2_float
= FALSE
,
942 .store_int64
= FALSE
,
943 .scan_string_sq
= FALSE
,
944 .scan_string_dq
= FALSE
,
945 .identifier_2_string
= FALSE
,
946 .char_2_token
= TRUE
,
949 return g_scanner_new(&scanner_config
);
953 * Inserts a string (if exists and not empty) or null to a map value
957 enum bt_value_status
map_insert_string_or_null(struct bt_value
*map
,
958 const char *key
, GString
*string
)
960 enum bt_value_status ret
;
962 if (string
&& string
->len
> 0) {
963 ret
= bt_value_map_insert_string(map
, key
, string
->str
);
965 ret
= bt_value_map_insert(map
, key
, bt_value_null
);
971 * Converts a comma-delimited list of known names (--names option) to
972 * an array value object containing those names as string value objects.
974 * Return value is owned by the caller.
977 struct bt_value
*names_from_arg(const char *arg
)
979 GScanner
*scanner
= NULL
;
980 struct bt_value
*names
= NULL
;
981 bool found_all
= false, found_none
= false, found_item
= false;
983 names
= bt_value_array_create();
989 scanner
= create_csv_identifiers_scanner();
995 g_scanner_input_text(scanner
, arg
, strlen(arg
));
998 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1000 switch (token_type
) {
1001 case G_TOKEN_IDENTIFIER
:
1003 const char *identifier
= scanner
->value
.v_identifier
;
1005 if (!strcmp(identifier
, "payload") ||
1006 !strcmp(identifier
, "args") ||
1007 !strcmp(identifier
, "arg")) {
1009 if (bt_value_array_append_string(names
,
1013 } else if (!strcmp(identifier
, "context") ||
1014 !strcmp(identifier
, "ctx")) {
1016 if (bt_value_array_append_string(names
,
1020 } else if (!strcmp(identifier
, "scope") ||
1021 !strcmp(identifier
, "header")) {
1023 if (bt_value_array_append_string(names
,
1027 } else if (!strcmp(identifier
, "all")) {
1029 if (bt_value_array_append_string(names
,
1033 } else if (!strcmp(identifier
, "none")) {
1035 if (bt_value_array_append_string(names
,
1040 printf_err("Unknown field name: `%s`\n",
1056 if (found_none
&& found_all
) {
1057 printf_err("Only either `all` or `none` can be specified in the list given to the --names option, but not both.\n");
1061 * Legacy behavior is to clear the defaults (show none) when at
1062 * least one item is specified.
1064 if (found_item
&& !found_none
&& !found_all
) {
1065 if (bt_value_array_append_string(names
, "none")) {
1070 g_scanner_destroy(scanner
);
1077 g_scanner_destroy(scanner
);
1084 * Converts a comma-delimited list of known fields (--fields option) to
1085 * an array value object containing those fields as string
1088 * Return value is owned by the caller.
1091 struct bt_value
*fields_from_arg(const char *arg
)
1093 GScanner
*scanner
= NULL
;
1094 struct bt_value
*fields
;
1096 fields
= bt_value_array_create();
1102 scanner
= create_csv_identifiers_scanner();
1108 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1111 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1113 switch (token_type
) {
1114 case G_TOKEN_IDENTIFIER
:
1116 const char *identifier
= scanner
->value
.v_identifier
;
1118 if (!strcmp(identifier
, "trace") ||
1119 !strcmp(identifier
, "trace:hostname") ||
1120 !strcmp(identifier
, "trace:domain") ||
1121 !strcmp(identifier
, "trace:procname") ||
1122 !strcmp(identifier
, "trace:vpid") ||
1123 !strcmp(identifier
, "loglevel") ||
1124 !strcmp(identifier
, "emf") ||
1125 !strcmp(identifier
, "callsite") ||
1126 !strcmp(identifier
, "all")) {
1127 if (bt_value_array_append_string(fields
,
1132 printf_err("Unknown field name: `%s`\n",
1154 g_scanner_destroy(scanner
);
1160 * Inserts the equivalent "prefix-name" true boolean value objects into
1161 * map_obj where the names are in array_obj.
1164 int insert_flat_names_fields_from_array(struct bt_value
*map_obj
,
1165 struct bt_value
*array_obj
, const char *prefix
)
1169 GString
*tmpstr
= NULL
, *default_value
= NULL
;
1172 * array_obj may be NULL if no CLI options were specified to
1173 * trigger its creation.
1179 tmpstr
= g_string_new(NULL
);
1186 default_value
= g_string_new(NULL
);
1187 if (!default_value
) {
1193 for (i
= 0; i
< bt_value_array_size(array_obj
); i
++) {
1194 struct bt_value
*str_obj
= bt_value_array_get(array_obj
, i
);
1196 bool is_default
= false;
1199 printf_err("Unexpected error\n");
1204 ret
= bt_value_string_get(str_obj
, &suffix
);
1207 printf_err("Unexpected error\n");
1211 g_string_assign(tmpstr
, prefix
);
1212 g_string_append(tmpstr
, "-");
1214 /* Special-case for "all" and "none". */
1215 if (!strcmp(suffix
, "all")) {
1217 g_string_assign(default_value
, "show");
1218 } else if (!strcmp(suffix
, "none")) {
1220 g_string_assign(default_value
, "hide");
1223 g_string_append(tmpstr
, "default");
1224 ret
= map_insert_string_or_null(map_obj
,
1232 g_string_append(tmpstr
, suffix
);
1233 ret
= bt_value_map_insert_bool(map_obj
, tmpstr
->str
,
1243 if (default_value
) {
1244 g_string_free(default_value
, TRUE
);
1247 g_string_free(tmpstr
, TRUE
);
1254 * Returns the parameters (map value object) corresponding to the
1255 * legacy text format options.
1257 * Return value is owned by the caller.
1260 struct bt_value
*params_from_text_legacy_opts(
1261 struct text_legacy_opts
*text_legacy_opts
)
1263 struct bt_value
*params
;
1265 params
= bt_value_map_create();
1271 if (map_insert_string_or_null(params
, "output-path",
1272 text_legacy_opts
->output
)) {
1277 if (map_insert_string_or_null(params
, "debug-info-dir",
1278 text_legacy_opts
->dbg_info_dir
)) {
1283 if (map_insert_string_or_null(params
, "debug-info-target-prefix",
1284 text_legacy_opts
->dbg_info_target_prefix
)) {
1289 if (bt_value_map_insert_bool(params
, "debug-info-full-path",
1290 text_legacy_opts
->dbg_info_full_path
)) {
1295 if (bt_value_map_insert_bool(params
, "no-delta",
1296 text_legacy_opts
->no_delta
)) {
1301 if (bt_value_map_insert_bool(params
, "clock-cycles",
1302 text_legacy_opts
->clock_cycles
)) {
1307 if (bt_value_map_insert_bool(params
, "clock-seconds",
1308 text_legacy_opts
->clock_seconds
)) {
1313 if (bt_value_map_insert_bool(params
, "clock-date",
1314 text_legacy_opts
->clock_date
)) {
1319 if (bt_value_map_insert_bool(params
, "clock-gmt",
1320 text_legacy_opts
->clock_gmt
)) {
1325 if (insert_flat_names_fields_from_array(params
,
1326 text_legacy_opts
->names
, "name")) {
1330 if (insert_flat_names_fields_from_array(params
,
1331 text_legacy_opts
->fields
, "field")) {
1345 int append_sinks_from_legacy_opts(GPtrArray
*sinks
,
1346 enum legacy_output_format legacy_output_format
,
1347 struct text_legacy_opts
*text_legacy_opts
)
1350 struct bt_value
*params
= NULL
;
1351 const char *plugin_name
;
1352 const char *component_name
;
1353 struct bt_config_component
*bt_config_component
= NULL
;
1355 switch (legacy_output_format
) {
1356 case LEGACY_OUTPUT_FORMAT_TEXT
:
1357 plugin_name
= "text";
1358 component_name
= "text";
1360 case LEGACY_OUTPUT_FORMAT_CTF_METADATA
:
1361 plugin_name
= "ctf";
1362 component_name
= "metadata-text";
1364 case LEGACY_OUTPUT_FORMAT_DUMMY
:
1365 plugin_name
= "utils";
1366 component_name
= "dummy";
1373 if (legacy_output_format
== LEGACY_OUTPUT_FORMAT_TEXT
) {
1374 /* Legacy "text" output format has parameters */
1375 params
= params_from_text_legacy_opts(text_legacy_opts
);
1381 * Legacy "dummy" and "ctf-metadata" output formats do
1382 * not have parameters.
1384 params
= bt_value_map_create();
1391 /* Create a component configuration */
1392 bt_config_component
= bt_config_component_create(plugin_name
,
1394 if (!bt_config_component
) {
1398 BT_MOVE(bt_config_component
->params
, params
);
1400 /* Move created component configuration to the array */
1401 g_ptr_array_add(sinks
, bt_config_component
);
1415 * Returns the parameters (map value object) corresponding to the
1416 * given legacy CTF format options.
1418 * Return value is owned by the caller.
1421 struct bt_value
*params_from_ctf_legacy_opts(
1422 struct ctf_legacy_opts
*ctf_legacy_opts
)
1424 struct bt_value
*params
;
1426 params
= bt_value_map_create();
1432 if (bt_value_map_insert_integer(params
, "offset-s",
1433 ctf_legacy_opts
->offset_s
.value
)) {
1438 if (bt_value_map_insert_integer(params
, "offset-ns",
1439 ctf_legacy_opts
->offset_ns
.value
)) {
1444 if (bt_value_map_insert_bool(params
, "stream-intersection",
1445 ctf_legacy_opts
->stream_intersection
)) {
1460 int append_sources_from_legacy_opts(GPtrArray
*sources
,
1461 enum legacy_input_format legacy_input_format
,
1462 struct ctf_legacy_opts
*ctf_legacy_opts
,
1463 struct bt_value
*legacy_input_paths
)
1467 struct bt_value
*base_params
;
1468 struct bt_value
*params
= NULL
;
1469 struct bt_value
*input_path
= NULL
;
1470 struct bt_value
*input_path_copy
= NULL
;
1471 const char *input_key
;
1472 const char *component_name
;
1474 switch (legacy_input_format
) {
1475 case LEGACY_INPUT_FORMAT_CTF
:
1477 component_name
= "fs";
1479 case LEGACY_INPUT_FORMAT_LTTNG_LIVE
:
1481 component_name
= "lttng-live";
1488 base_params
= params_from_ctf_legacy_opts(ctf_legacy_opts
);
1493 for (i
= 0; i
< bt_value_array_size(legacy_input_paths
); i
++) {
1494 struct bt_config_component
*bt_config_component
= NULL
;
1496 /* Copy base parameters as current parameters */
1497 params
= bt_value_copy(base_params
);
1502 /* Get current input path string value object */
1503 input_path
= bt_value_array_get(legacy_input_paths
, i
);
1508 /* Copy current input path value object */
1509 input_path_copy
= bt_value_copy(input_path
);
1510 if (!input_path_copy
) {
1514 /* Insert input path value object into current parameters */
1515 ret
= bt_value_map_insert(params
, input_key
, input_path_copy
);
1520 /* Create a component configuration */
1521 bt_config_component
= bt_config_component_create("ctf",
1523 if (!bt_config_component
) {
1527 BT_MOVE(bt_config_component
->params
, params
);
1529 /* Move created component configuration to the array */
1530 g_ptr_array_add(sources
, bt_config_component
);
1532 /* Put current stuff */
1534 BT_PUT(input_path_copy
);
1543 BT_PUT(base_params
);
1546 BT_PUT(input_path_copy
);
1551 * Escapes a string for the shell. The string is escaped knowing that
1552 * it's a parameter string value (double-quoted), and that it will be
1553 * entered between single quotes in the shell.
1555 * Return value is owned by the caller.
1558 char *str_shell_escape(const char *input
)
1561 const char *at
= input
;
1562 GString
*str
= g_string_new(NULL
);
1568 while (*at
!= '\0') {
1571 g_string_append(str
, "\\\\");
1574 g_string_append(str
, "\\\"");
1577 g_string_append(str
, "'\"'\"'");
1580 g_string_append(str
, "\\n");
1583 g_string_append(str
, "\\t");
1586 g_string_append_c(str
, *at
);
1596 g_string_free(str
, FALSE
);
1603 int append_prefixed_flag_params(GString
*str
, struct bt_value
*flags
,
1613 for (i
= 0; i
< bt_value_array_size(flags
); i
++) {
1614 struct bt_value
*value
= bt_value_array_get(flags
, i
);
1622 if (bt_value_string_get(value
, &flag
)) {
1628 g_string_append_printf(str
, ",%s-%s=true", prefix
, flag
);
1637 * Appends a boolean parameter string.
1640 void g_string_append_bool_param(GString
*str
, const char *name
, bool value
)
1642 g_string_append_printf(str
, ",%s=%s", name
, value
? "true" : "false");
1646 * Appends a path parameter string, or null if it's empty.
1649 int g_string_append_string_path_param(GString
*str
, const char *name
,
1654 if (path
->len
> 0) {
1655 char *escaped_path
= str_shell_escape(path
->str
);
1657 if (!escaped_path
) {
1662 g_string_append_printf(str
, "%s=\"%s\"", name
, escaped_path
);
1665 g_string_append_printf(str
, "%s=null", name
);
1678 * Prints the non-legacy sink options equivalent to the specified
1679 * legacy output format options.
1682 void print_output_legacy_to_sinks(
1683 enum legacy_output_format legacy_output_format
,
1684 struct text_legacy_opts
*text_legacy_opts
)
1686 const char *output_format
;
1687 GString
*str
= NULL
;
1689 str
= g_string_new(" ");
1695 switch (legacy_output_format
) {
1696 case LEGACY_OUTPUT_FORMAT_TEXT
:
1697 output_format
= "text";
1699 case LEGACY_OUTPUT_FORMAT_CTF_METADATA
:
1700 output_format
= "ctf-metadata";
1702 case LEGACY_OUTPUT_FORMAT_DUMMY
:
1703 output_format
= "dummy";
1709 printf_err("Both `%s` legacy output format and non-legacy sink component\ninstances(s) specified.\n\n",
1711 printf_err("Specify the following non-legacy sink component instance instead of the\nlegacy `%s` output format options:\n\n",
1713 g_string_append(str
, "-o ");
1715 switch (legacy_output_format
) {
1716 case LEGACY_OUTPUT_FORMAT_TEXT
:
1717 g_string_append(str
, "text.text");
1719 case LEGACY_OUTPUT_FORMAT_CTF_METADATA
:
1720 g_string_append(str
, "ctf.metadata-text");
1722 case LEGACY_OUTPUT_FORMAT_DUMMY
:
1723 g_string_append(str
, "utils.dummy");
1729 if (legacy_output_format
== LEGACY_OUTPUT_FORMAT_TEXT
&&
1730 text_legacy_opts_is_any_set(text_legacy_opts
)) {
1733 g_string_append(str
, " -p '");
1735 if (g_string_append_string_path_param(str
, "output-path",
1736 text_legacy_opts
->output
)) {
1740 g_string_append(str
, ",");
1742 if (g_string_append_string_path_param(str
, "debug-info-dir",
1743 text_legacy_opts
->dbg_info_dir
)) {
1747 g_string_append(str
, ",");
1749 if (g_string_append_string_path_param(str
,
1750 "debug-info-target-prefix",
1751 text_legacy_opts
->dbg_info_target_prefix
)) {
1755 g_string_append_bool_param(str
, "no-delta",
1756 text_legacy_opts
->no_delta
);
1757 g_string_append_bool_param(str
, "clock-cycles",
1758 text_legacy_opts
->clock_cycles
);
1759 g_string_append_bool_param(str
, "clock-seconds",
1760 text_legacy_opts
->clock_seconds
);
1761 g_string_append_bool_param(str
, "clock-date",
1762 text_legacy_opts
->clock_date
);
1763 g_string_append_bool_param(str
, "clock-gmt",
1764 text_legacy_opts
->clock_gmt
);
1765 ret
= append_prefixed_flag_params(str
, text_legacy_opts
->names
,
1771 ret
= append_prefixed_flag_params(str
, text_legacy_opts
->fields
,
1777 /* Remove last comma and close single quote */
1778 g_string_append(str
, "'");
1781 printf_err("%s\n\n", str
->str
);
1785 g_string_free(str
, TRUE
);
1791 * Prints the non-legacy source options equivalent to the specified
1792 * legacy input format options.
1795 void print_input_legacy_to_sources(enum legacy_input_format legacy_input_format
,
1796 struct bt_value
*legacy_input_paths
,
1797 struct ctf_legacy_opts
*ctf_legacy_opts
)
1799 const char *input_format
;
1800 GString
*str
= NULL
;
1803 str
= g_string_new(" ");
1809 switch (legacy_input_format
) {
1810 case LEGACY_INPUT_FORMAT_CTF
:
1811 input_format
= "ctf";
1813 case LEGACY_INPUT_FORMAT_LTTNG_LIVE
:
1814 input_format
= "lttng-live";
1820 printf_err("Both `%s` legacy input format and non-legacy source component\ninstance(s) specified.\n\n",
1822 printf_err("Specify the following non-legacy source component instance(s) instead of the\nlegacy `%s` input format options and positional arguments:\n\n",
1825 for (i
= 0; i
< bt_value_array_size(legacy_input_paths
); i
++) {
1826 struct bt_value
*input_value
=
1827 bt_value_array_get(legacy_input_paths
, i
);
1828 const char *input
= NULL
;
1829 char *escaped_input
;
1832 assert(input_value
);
1833 ret
= bt_value_string_get(input_value
, &input
);
1834 BT_PUT(input_value
);
1835 assert(!ret
&& input
);
1836 escaped_input
= str_shell_escape(input
);
1837 if (!escaped_input
) {
1842 g_string_append(str
, "-i ctf.");
1844 switch (legacy_input_format
) {
1845 case LEGACY_INPUT_FORMAT_CTF
:
1846 g_string_append(str
, "fs -p 'path=\"");
1848 case LEGACY_INPUT_FORMAT_LTTNG_LIVE
:
1849 g_string_append(str
, "lttng-live -p 'url=\"");
1855 g_string_append(str
, escaped_input
);
1856 g_string_append(str
, "\"");
1857 g_string_append_printf(str
, ",offset-s=%" PRId64
,
1858 ctf_legacy_opts
->offset_s
.value
);
1859 g_string_append_printf(str
, ",offset-ns=%" PRId64
,
1860 ctf_legacy_opts
->offset_ns
.value
);
1861 g_string_append_bool_param(str
, "stream-intersection",
1862 ctf_legacy_opts
->stream_intersection
);
1863 g_string_append(str
, "' ");
1864 g_free(escaped_input
);
1867 printf_err("%s\n\n", str
->str
);
1871 g_string_free(str
, TRUE
);
1877 * Validates a given configuration, with optional legacy input and
1878 * output formats options. Prints useful error messages if anything
1881 * Returns true when the configuration is valid.
1884 bool validate_cfg(struct bt_config
*cfg
,
1885 enum legacy_input_format
*legacy_input_format
,
1886 enum legacy_output_format
*legacy_output_format
,
1887 struct bt_value
*legacy_input_paths
,
1888 struct ctf_legacy_opts
*ctf_legacy_opts
,
1889 struct text_legacy_opts
*text_legacy_opts
)
1891 bool legacy_input
= false;
1892 bool legacy_output
= false;
1894 /* Determine if the input and output should be legacy-style */
1895 if (*legacy_input_format
!= LEGACY_INPUT_FORMAT_NONE
||
1896 !bt_value_array_is_empty(legacy_input_paths
) ||
1897 ctf_legacy_opts_is_any_set(ctf_legacy_opts
)) {
1898 legacy_input
= true;
1901 if (*legacy_output_format
!= LEGACY_OUTPUT_FORMAT_NONE
||
1902 text_legacy_opts_is_any_set(text_legacy_opts
)) {
1903 legacy_output
= true;
1907 /* If no legacy input format was specified, default to CTF */
1908 if (*legacy_input_format
== LEGACY_INPUT_FORMAT_NONE
) {
1909 *legacy_input_format
= LEGACY_INPUT_FORMAT_CTF
;
1912 /* Make sure at least one input path exists */
1913 if (bt_value_array_is_empty(legacy_input_paths
)) {
1914 switch (*legacy_input_format
) {
1915 case LEGACY_INPUT_FORMAT_CTF
:
1916 printf_err("No input path specified for legacy `ctf` input format\n");
1918 case LEGACY_INPUT_FORMAT_LTTNG_LIVE
:
1919 printf_err("No URL specified for legacy `lttng-live` input format\n");
1927 /* Make sure no non-legacy sources are specified */
1928 if (cfg
->cmd_data
.convert
.sources
->len
!= 0) {
1929 print_input_legacy_to_sources(*legacy_input_format
,
1930 legacy_input_paths
, ctf_legacy_opts
);
1935 if (legacy_output
) {
1937 * If no legacy output format was specified, default to
1940 if (*legacy_output_format
== LEGACY_OUTPUT_FORMAT_NONE
) {
1941 *legacy_output_format
= LEGACY_OUTPUT_FORMAT_TEXT
;
1945 * If any "text" option was specified, the output must be
1948 if (text_legacy_opts_is_any_set(text_legacy_opts
) &&
1949 *legacy_output_format
!=
1950 LEGACY_OUTPUT_FORMAT_TEXT
) {
1951 printf_err("Options for legacy `text` output format specified with a different legacy output format\n");
1955 /* Make sure no non-legacy sinks are specified */
1956 if (cfg
->cmd_data
.convert
.sinks
->len
!= 0) {
1957 print_output_legacy_to_sinks(*legacy_output_format
,
1964 * If the output is the legacy "ctf-metadata" format, then the
1965 * input should be the legacy "ctf" input format.
1967 if (*legacy_output_format
== LEGACY_OUTPUT_FORMAT_CTF_METADATA
&&
1968 *legacy_input_format
!= LEGACY_INPUT_FORMAT_CTF
) {
1969 printf_err("Legacy `ctf-metadata` output format requires using legacy `ctf` input format\n");
1980 * Parses a 64-bit signed integer.
1982 * Returns a negative value if anything goes wrong.
1985 int parse_int64(const char *arg
, int64_t *val
)
1990 *val
= strtoll(arg
, &endptr
, 0);
1991 if (*endptr
!= '\0' || arg
== endptr
|| errno
!= 0) {
2005 OPT_CLOCK_FORCE_CORRELATE
,
2008 OPT_CLOCK_OFFSET_NS
,
2013 OPT_DEBUG_INFO_FULL_PATH
,
2014 OPT_DEBUG_INFO_TARGET_PREFIX
,
2024 OPT_OMIT_HOME_PLUGIN_PATH
,
2025 OPT_OMIT_SYSTEM_PLUGIN_PATH
,
2031 OPT_RESET_BASE_PARAMS
,
2034 OPT_STREAM_INTERSECTION
,
2040 * Sets the value of a given legacy offset option and marks it as set.
2042 static void set_offset_value(struct offset_opt
*offset_opt
, int64_t value
)
2044 offset_opt
->value
= value
;
2045 offset_opt
->is_set
= true;
2048 enum bt_config_component_dest
{
2049 BT_CONFIG_COMPONENT_DEST_SOURCE
,
2050 BT_CONFIG_COMPONENT_DEST_SINK
,
2054 * Adds a configuration component to the appropriate configuration
2055 * array depending on the destination.
2057 static void add_cfg_comp(struct bt_config
*cfg
,
2058 struct bt_config_component
*cfg_comp
,
2059 enum bt_config_component_dest dest
)
2061 if (dest
== BT_CONFIG_COMPONENT_DEST_SOURCE
) {
2062 g_ptr_array_add(cfg
->cmd_data
.convert
.sources
, cfg_comp
);
2064 g_ptr_array_add(cfg
->cmd_data
.convert
.sinks
, cfg_comp
);
2068 static int split_timerange(const char *arg
, const char **begin
, const char **end
)
2072 /* Try to match [begin,end] */
2073 c
= strchr(arg
, '[');
2087 /* Try to match begin,end */
2101 static int append_env_var_plugin_paths(struct bt_value
*plugin_paths
)
2106 if (bt_common_is_setuid_setgid()) {
2107 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
2111 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
2116 ret
= bt_config_append_plugin_paths(plugin_paths
, envvar
);
2122 static int append_home_and_system_plugin_paths(struct bt_value
*plugin_paths
,
2123 bool omit_system_plugin_path
, bool omit_home_plugin_path
)
2127 if (!omit_home_plugin_path
) {
2128 if (bt_common_is_setuid_setgid()) {
2129 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
2131 char *home_plugin_dir
=
2132 bt_common_get_home_plugin_path();
2134 if (home_plugin_dir
) {
2135 ret
= bt_config_append_plugin_paths(
2138 free(home_plugin_dir
);
2141 printf_err("Invalid home plugin path\n");
2148 if (!omit_system_plugin_path
) {
2149 if (bt_config_append_plugin_paths(plugin_paths
,
2150 bt_common_get_system_plugin_path())) {
2151 printf_err("Invalid system plugin path\n");
2160 static int append_sources_from_implicit_params(GPtrArray
*sources
,
2161 struct bt_config_component
*implicit_source_comp
)
2164 size_t len
= sources
->len
;
2166 for (i
= 0; i
< len
; i
++) {
2167 struct bt_config_component
*comp
;
2168 struct bt_value
*params_to_set
;
2170 comp
= g_ptr_array_index(sources
, i
);
2171 params_to_set
= bt_value_map_extend(comp
->params
,
2172 implicit_source_comp
->params
);
2173 if (!params_to_set
) {
2174 printf_err("Cannot extend legacy component parameters with non-legacy parameters\n");
2177 BT_MOVE(comp
->params
, params_to_set
);
2184 static struct bt_config
*bt_config_base_create(enum bt_config_command command
)
2186 struct bt_config
*cfg
;
2189 cfg
= g_new0(struct bt_config
, 1);
2195 bt_object_init(cfg
, bt_config_destroy
);
2196 cfg
->command
= command
;
2206 static struct bt_config
*bt_config_convert_create(
2207 struct bt_value
*initial_plugin_paths
)
2209 struct bt_config
*cfg
;
2212 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_CONVERT
);
2218 cfg
->cmd_data
.convert
.sources
= g_ptr_array_new_with_free_func(
2219 (GDestroyNotify
) bt_put
);
2220 if (!cfg
->cmd_data
.convert
.sources
) {
2225 cfg
->cmd_data
.convert
.filters
= g_ptr_array_new_with_free_func(
2226 (GDestroyNotify
) bt_put
);
2227 if (!cfg
->cmd_data
.convert
.filters
) {
2232 cfg
->cmd_data
.convert
.sinks
= g_ptr_array_new_with_free_func(
2233 (GDestroyNotify
) bt_put
);
2234 if (!cfg
->cmd_data
.convert
.sinks
) {
2239 cfg
->cmd_data
.convert
.connections
= g_ptr_array_new_with_free_func(
2240 (GDestroyNotify
) bt_config_connection_destroy
);
2241 if (!cfg
->cmd_data
.convert
.connections
) {
2246 if (initial_plugin_paths
) {
2247 cfg
->cmd_data
.convert
.plugin_paths
=
2248 bt_get(initial_plugin_paths
);
2250 cfg
->cmd_data
.convert
.plugin_paths
= bt_value_array_create();
2251 if (!cfg
->cmd_data
.convert
.plugin_paths
) {
2266 static struct bt_config
*bt_config_list_plugins_create(
2267 struct bt_value
*initial_plugin_paths
)
2269 struct bt_config
*cfg
;
2272 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_LIST_PLUGINS
);
2278 if (initial_plugin_paths
) {
2279 cfg
->cmd_data
.list_plugins
.plugin_paths
=
2280 bt_get(initial_plugin_paths
);
2282 cfg
->cmd_data
.list_plugins
.plugin_paths
=
2283 bt_value_array_create();
2284 if (!cfg
->cmd_data
.list_plugins
.plugin_paths
) {
2299 static struct bt_config
*bt_config_help_create(
2300 struct bt_value
*initial_plugin_paths
)
2302 struct bt_config
*cfg
;
2305 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_HELP
);
2311 if (initial_plugin_paths
) {
2312 cfg
->cmd_data
.help
.plugin_paths
=
2313 bt_get(initial_plugin_paths
);
2315 cfg
->cmd_data
.help
.plugin_paths
=
2316 bt_value_array_create();
2317 if (!cfg
->cmd_data
.help
.plugin_paths
) {
2323 cfg
->cmd_data
.help
.plugin_name
= g_string_new(NULL
);
2324 if (!cfg
->cmd_data
.help
.plugin_name
) {
2329 cfg
->cmd_data
.help
.component_name
= g_string_new(NULL
);
2330 if (!cfg
->cmd_data
.help
.component_name
) {
2345 * Prints the help command usage.
2348 void print_help_usage(FILE *fp
)
2350 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
2351 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --source PLUGIN.COMPCLS\n");
2352 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --filter PLUGIN.COMPCLS\n");
2353 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --sink PLUGIN.COMPCLS\n");
2355 fprintf(fp
, "Options:\n");
2357 fprintf(fp
, " --filter=PLUGIN.COMPCLS Get help for the filter component class\n");
2358 fprintf(fp
, " COMPCLS found in the plugin PLUGIN\n");
2359 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2360 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2361 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2362 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2363 fprintf(fp
, " dynamic plugins can be loaded\n");
2364 fprintf(fp
, " --sink=PLUGIN.COMPCLS Get help for the sink component class\n");
2365 fprintf(fp
, " COMPCLS found in the plugin PLUGIN\n");
2366 fprintf(fp
, " --source=PLUGIN.COMPCLS Get help for the source component class\n");
2367 fprintf(fp
, " COMPCLS found in the plugin PLUGIN\n");
2368 fprintf(fp
, " -h --help Show this help and quit\n");
2370 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2372 fprintf(fp
, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
2375 static struct poptOption help_long_options
[] = {
2376 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2377 { "filter", '\0', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
2378 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2379 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2380 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2381 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2382 { "sink", '\0', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
2383 { "source", '\0', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
2384 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
2388 * Creates a Babeltrace config object from the arguments of a help
2391 * *retcode is set to the appropriate exit code to use.
2393 struct bt_config
*bt_config_help_from_args(int argc
, const char *argv
[],
2394 int *retcode
, bool omit_system_plugin_path
,
2395 bool omit_home_plugin_path
,
2396 struct bt_value
*initial_plugin_paths
)
2398 poptContext pc
= NULL
;
2402 struct bt_config
*cfg
= NULL
;
2403 const char *leftover
;
2404 char *plugin_name
= NULL
, *component_name
= NULL
;
2405 char *plugin_comp_cls_names
= NULL
;
2408 cfg
= bt_config_help_create(initial_plugin_paths
);
2414 cfg
->cmd_data
.help
.comp_cls_type
= BT_COMPONENT_CLASS_TYPE_UNKNOWN
;
2415 cfg
->cmd_data
.help
.omit_system_plugin_path
= omit_system_plugin_path
;
2416 cfg
->cmd_data
.help
.omit_home_plugin_path
= omit_home_plugin_path
;
2417 ret
= append_env_var_plugin_paths(cfg
->cmd_data
.help
.plugin_paths
);
2419 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
2424 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2425 help_long_options
, 0);
2427 printf_err("Cannot get popt context\n");
2431 poptReadDefaultConfig(pc
, 0);
2433 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2434 arg
= poptGetOptArg(pc
);
2437 case OPT_PLUGIN_PATH
:
2438 if (bt_common_is_setuid_setgid()) {
2439 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
2441 if (bt_config_append_plugin_paths(
2442 cfg
->cmd_data
.help
.plugin_paths
,
2444 printf_err("Invalid --plugin-path option's argument:\n %s\n",
2450 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2451 cfg
->cmd_data
.help
.omit_system_plugin_path
= true;
2453 case OPT_OMIT_HOME_PLUGIN_PATH
:
2454 cfg
->cmd_data
.help
.omit_home_plugin_path
= true;
2459 if (cfg
->cmd_data
.help
.comp_cls_type
!=
2460 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
2461 printf_err("Cannot specify more than one plugin and component class:\n %s\n",
2468 cfg
->cmd_data
.help
.comp_cls_type
=
2469 BT_COMPONENT_CLASS_TYPE_SOURCE
;
2472 cfg
->cmd_data
.help
.comp_cls_type
=
2473 BT_COMPONENT_CLASS_TYPE_FILTER
;
2476 cfg
->cmd_data
.help
.comp_cls_type
=
2477 BT_COMPONENT_CLASS_TYPE_SINK
;
2482 plugin_comp_cls_names
= strdup(arg
);
2483 if (!plugin_comp_cls_names
) {
2489 print_help_usage(stdout
);
2494 printf_err("Unknown command-line option specified (option code %d)\n",
2503 /* Check for option parsing error */
2505 printf_err("While parsing command-line options, at option %s: %s\n",
2506 poptBadOption(pc
, 0), poptStrerror(opt
));
2510 leftover
= poptGetArg(pc
);
2512 if (cfg
->cmd_data
.help
.comp_cls_type
!=
2513 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
2514 printf_err("Cannot specify plugin name and --source/--filter/--sink component class:\n %s\n",
2519 g_string_assign(cfg
->cmd_data
.help
.plugin_name
, leftover
);
2521 if (cfg
->cmd_data
.help
.comp_cls_type
==
2522 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
2523 print_help_usage(stdout
);
2529 plugin_component_names_from_arg(plugin_comp_cls_names
,
2530 &plugin_name
, &component_name
);
2531 if (plugin_name
&& component_name
) {
2532 g_string_assign(cfg
->cmd_data
.help
.plugin_name
, plugin_name
);
2533 g_string_assign(cfg
->cmd_data
.help
.component_name
,
2536 printf_err("Invalid --source/--filter/--sink option's argument:\n %s\n",
2537 plugin_comp_cls_names
);
2542 if (append_home_and_system_plugin_paths(
2543 cfg
->cmd_data
.help
.plugin_paths
,
2544 cfg
->cmd_data
.help
.omit_system_plugin_path
,
2545 cfg
->cmd_data
.help
.omit_home_plugin_path
)) {
2546 printf_err("Cannot append home and system plugin paths\n");
2557 free(plugin_comp_cls_names
);
2558 g_free(plugin_name
);
2559 g_free(component_name
);
2562 poptFreeContext(pc
);
2570 * Prints the list-plugins command usage.
2573 void print_list_plugins_usage(FILE *fp
)
2575 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
2577 fprintf(fp
, "Options:\n");
2579 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2580 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2581 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2582 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2583 fprintf(fp
, " dynamic plugins can be loaded\n");
2584 fprintf(fp
, " -h --help Show this help and quit\n");
2586 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2588 fprintf(fp
, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
2591 static struct poptOption list_plugins_long_options
[] = {
2592 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2593 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2594 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2595 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2596 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2597 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
2601 * Creates a Babeltrace config object from the arguments of a
2602 * list-plugins command.
2604 * *retcode is set to the appropriate exit code to use.
2606 struct bt_config
*bt_config_list_plugins_from_args(int argc
, const char *argv
[],
2607 int *retcode
, bool omit_system_plugin_path
,
2608 bool omit_home_plugin_path
,
2609 struct bt_value
*initial_plugin_paths
)
2611 poptContext pc
= NULL
;
2615 struct bt_config
*cfg
= NULL
;
2616 const char *leftover
;
2619 cfg
= bt_config_list_plugins_create(initial_plugin_paths
);
2625 cfg
->cmd_data
.list_plugins
.omit_system_plugin_path
= omit_system_plugin_path
;
2626 cfg
->cmd_data
.list_plugins
.omit_home_plugin_path
= omit_home_plugin_path
;
2627 ret
= append_env_var_plugin_paths(
2628 cfg
->cmd_data
.list_plugins
.plugin_paths
);
2630 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
2635 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2636 list_plugins_long_options
, 0);
2638 printf_err("Cannot get popt context\n");
2642 poptReadDefaultConfig(pc
, 0);
2644 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2645 arg
= poptGetOptArg(pc
);
2648 case OPT_PLUGIN_PATH
:
2649 if (bt_common_is_setuid_setgid()) {
2650 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
2652 if (bt_config_append_plugin_paths(
2653 cfg
->cmd_data
.list_plugins
.plugin_paths
,
2655 printf_err("Invalid --plugin-path option's argument:\n %s\n",
2661 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2662 cfg
->cmd_data
.list_plugins
.omit_system_plugin_path
= true;
2664 case OPT_OMIT_HOME_PLUGIN_PATH
:
2665 cfg
->cmd_data
.list_plugins
.omit_home_plugin_path
= true;
2668 print_list_plugins_usage(stdout
);
2673 printf_err("Unknown command-line option specified (option code %d)\n",
2682 /* Check for option parsing error */
2684 printf_err("While parsing command-line options, at option %s: %s\n",
2685 poptBadOption(pc
, 0), poptStrerror(opt
));
2689 leftover
= poptGetArg(pc
);
2691 printf_err("Invalid argument: %s\n", leftover
);
2695 if (append_home_and_system_plugin_paths(
2696 cfg
->cmd_data
.list_plugins
.plugin_paths
,
2697 cfg
->cmd_data
.list_plugins
.omit_system_plugin_path
,
2698 cfg
->cmd_data
.list_plugins
.omit_home_plugin_path
)) {
2699 printf_err("Cannot append home and system plugin paths\n");
2711 poptFreeContext(pc
);
2719 * Prints the legacy, Babeltrace 1.x command usage. Those options are
2720 * still compatible in Babeltrace 2.x, but it is recommended to use
2721 * the more generic plugin/component parameters instead of those
2722 * hard-coded option names.
2725 void print_legacy_usage(FILE *fp
)
2727 fprintf(fp
, "Usage: babeltrace [OPTIONS] INPUT...\n");
2729 fprintf(fp
, "The following options are compatible with the Babeltrace 1.x options:\n");
2731 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently correlated\n");
2732 fprintf(fp
, " across traces\n");
2733 fprintf(fp
, " -d, --debug Enable debug mode\n");
2734 fprintf(fp
, " -i, --input-format=FORMAT Input trace format (default: ctf)\n");
2735 fprintf(fp
, " -l, --list List available formats\n");
2736 fprintf(fp
, " -o, --output-format=FORMAT Output trace format (default: text)\n");
2737 fprintf(fp
, " -v, --verbose Enable verbose output\n");
2738 fprintf(fp
, " --help-legacy Show this help and quit\n");
2739 fprintf(fp
, " -V, --version Show version and quit\n");
2741 fprintf(fp
, " Available input formats: ctf, lttng-live, ctf-metadata\n");
2742 fprintf(fp
, " Available output formats: text, dummy\n");
2744 fprintf(fp
, "Input formats specific options:\n");
2746 fprintf(fp
, " INPUT... Input trace file(s), directory(ies), or URLs\n");
2747 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
2748 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS nanoseconds\n");
2749 fprintf(fp
, " --stream-intersection Only process events when all streams are active\n");
2751 fprintf(fp
, "text output format specific options:\n");
2753 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
2754 fprintf(fp
, " --clock-date Print timestamp dates\n");
2755 fprintf(fp
, " --clock-gmt Print and parse timestamps in GMT time zone\n");
2756 fprintf(fp
, " (default: local time zone)\n");
2757 fprintf(fp
, " --clock-seconds Print the timestamps as [SEC.NS]\n");
2758 fprintf(fp
, " (default format: [HH:MM:SS.NS])\n");
2759 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
2760 fprintf(fp
, " (default: `/usr/lib/debug`)\n");
2761 fprintf(fp
, " --debug-info-full-path Show full debug info source and binary paths\n");
2762 fprintf(fp
, " --debug-info-target-prefix=DIR Use directory DIR as a prefix when looking\n");
2763 fprintf(fp
, " up executables during debug info analysis\n");
2764 fprintf(fp
, " (default: `/usr/lib/debug`)\n");
2765 fprintf(fp
, " -f, --fields=NAME[,NAME]... Print additional fields:\n");
2766 fprintf(fp
, " all, trace, trace:hostname, trace:domain,\n");
2767 fprintf(fp
, " trace:procname, trace:vpid, loglevel, emf\n");
2768 fprintf(fp
, " (default: trace:hostname, trace:procname,\n");
2769 fprintf(fp
, " trace:vpid)\n");
2770 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names:\n");
2771 fprintf(fp
, " payload (or arg or args)\n");
2772 fprintf(fp
, " none, all, scope, header, context (or ctx)\n");
2773 fprintf(fp
, " (default: payload, context)\n");
2774 fprintf(fp
, " --no-delta Do not print time delta between consecutive\n");
2775 fprintf(fp
, " events\n");
2776 fprintf(fp
, " -w, --output=PATH Write output to PATH (default: standard output)\n");
2780 * Prints the convert command usage.
2783 void print_convert_usage(FILE *fp
)
2785 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] convert [OPTIONS]\n");
2787 fprintf(fp
, "Options:\n");
2789 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
2790 fprintf(fp
, " for the following component instances\n");
2791 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2792 fprintf(fp
, " --begin=BEGIN Set the `begin` parameter of the latest\n");
2793 fprintf(fp
, " source component instance to BEGIN\n");
2794 fprintf(fp
, " (see the suggested format of BEGIN below)\n");
2795 fprintf(fp
, " -c, --connect=CONNECTION Connect two component instances (see the\n");
2796 fprintf(fp
, " expected format of CONNECTION below)\n");
2797 fprintf(fp
, " -d, --debug Enable debug mode\n");
2798 fprintf(fp
, " --end=END Set the `end` parameter of the latest\n");
2799 fprintf(fp
, " source component instance to END\n");
2800 fprintf(fp
, " (see the suggested format of BEGIN below)\n");
2801 fprintf(fp
, " --name=NAME Set the name of the latest component\n");
2802 fprintf(fp
, " instance to NAME (must be unique amongst\n");
2803 fprintf(fp
, " all the names of the component instances)\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 Set the parameters of the latest component\n");
2808 fprintf(fp
, " instance (in command-line order) to PARAMS\n");
2809 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2810 fprintf(fp
, " -P, --path=PATH Set the `path` parameter of the latest\n");
2811 fprintf(fp
, " component instance 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
, " -r, --reset-base-params Reset the current base parameters of the\n");
2815 fprintf(fp
, " following source and sink component\n");
2816 fprintf(fp
, " instances to an empty map\n");
2817 fprintf(fp
, " -o, --sink=PLUGIN.COMPCLS Instantiate a sink component from plugin\n");
2818 fprintf(fp
, " PLUGIN and component class COMPCLS (may be\n");
2819 fprintf(fp
, " repeated)\n");
2820 fprintf(fp
, " -i, --source=PLUGIN.COMPCLS Instantiate a source component from plugin\n");
2821 fprintf(fp
, " PLUGIN and component class COMPCLS (may be\n");
2822 fprintf(fp
, " repeated)\n");
2823 fprintf(fp
, " --timerange=TIMERANGE Set time range to TIMERANGE: BEGIN,END or\n");
2824 fprintf(fp
, " [BEGIN,END] (literally `[` and `]`)\n");
2825 fprintf(fp
, " (suggested format of BEGIN/END below)\n");
2826 fprintf(fp
, " -v, --verbose Enable verbose output\n");
2827 fprintf(fp
, " -h --help Show this help and quit\n");
2829 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2830 fprintf(fp
, "\n\n");
2831 fprintf(fp
, "Suggested format of BEGIN and END\n");
2832 fprintf(fp
, "---------------------------------\n");
2834 fprintf(fp
, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
2835 fprintf(fp
, "\n\n");
2836 fprintf(fp
, "Expected format of CONNECTION\n");
2837 fprintf(fp
, "-----------------------------\n");
2839 fprintf(fp
, " SRC[.SRCPORT]:DST[.DSTPORT]\n");
2841 fprintf(fp
, "SRC and DST are the names of the source and destination component\n");
2842 fprintf(fp
, "instances to connect together. You can set the name of a component\n");
2843 fprintf(fp
, "instance with the --name option.\n");
2845 fprintf(fp
, "SRCPORT and DSTPORT are the optional source and destination ports to use\n");
2846 fprintf(fp
, "for the connection. When the port is not specified, the default port is\n");
2847 fprintf(fp
, "used.\n");
2849 fprintf(fp
, "You can connect a source component to a filter or sink component. You\n");
2850 fprintf(fp
, "can connect a filter component to a sink component.\n");
2852 fprintf(fp
, "Example:\n");
2854 fprintf(fp
, " my-filter.top10:json-out\n");
2855 fprintf(fp
, "\n\n");
2856 fprintf(fp
, "Expected format of PARAMS\n");
2857 fprintf(fp
, "-------------------------\n");
2859 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
2861 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
2862 fprintf(fp
, "where PARAM is the parameter name (C identifier plus [:.-] characters), and\n");
2863 fprintf(fp
, "VALUE can be one of:\n");
2865 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
2866 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
2867 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
2868 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
2869 fprintf(fp
, " (`0x` prefix) signed 64-bit integer.\n");
2870 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
2871 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
2872 fprintf(fp
, " the null and boolean value symbols above.\n");
2873 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
2875 fprintf(fp
, "Whitespaces are allowed around individual `=` and `,` tokens.\n");
2877 fprintf(fp
, "Example:\n");
2879 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
2880 fprintf(fp
, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
2881 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
2883 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run babeltrace\n");
2884 fprintf(fp
, "from a shell.\n");
2887 static struct poptOption convert_long_options
[] = {
2888 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2889 { "base-params", 'b', POPT_ARG_STRING
, NULL
, OPT_BASE_PARAMS
, NULL
, NULL
},
2890 { "begin", '\0', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2891 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2892 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2893 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2894 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2895 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2896 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2897 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2898 { "connect", 'c', POPT_ARG_STRING
, NULL
, OPT_CONNECT
, NULL
, NULL
},
2899 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2900 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2901 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2902 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2903 { "end", '\0', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2904 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2905 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2906 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2907 { "name", '\0', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2908 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2909 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2910 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2911 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2912 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_PATH
, NULL
, NULL
},
2913 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2914 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2915 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2916 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2917 { "reset-base-params", 'r', POPT_ARG_NONE
, NULL
, OPT_RESET_BASE_PARAMS
, NULL
, NULL
},
2918 { "sink", '\0', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
2919 { "source", '\0', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
2920 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2921 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2922 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2923 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
2927 * Creates a Babeltrace config object from the arguments of a convert
2930 * *retcode is set to the appropriate exit code to use.
2932 struct bt_config
*bt_config_convert_from_args(int argc
, const char *argv
[],
2933 int *retcode
, bool omit_system_plugin_path
,
2934 bool omit_home_plugin_path
,
2935 struct bt_value
*initial_plugin_paths
)
2937 poptContext pc
= NULL
;
2939 struct ctf_legacy_opts ctf_legacy_opts
;
2940 struct text_legacy_opts text_legacy_opts
;
2941 enum legacy_input_format legacy_input_format
= LEGACY_INPUT_FORMAT_NONE
;
2942 enum legacy_output_format legacy_output_format
=
2943 LEGACY_OUTPUT_FORMAT_NONE
;
2944 struct bt_value
*legacy_input_paths
= NULL
;
2945 struct bt_config_component
*implicit_source_comp
= NULL
;
2946 struct bt_config_component
*cur_cfg_comp
= NULL
;
2947 bool cur_is_implicit_source
= false;
2948 bool use_implicit_source
= false;
2949 enum bt_config_component_dest cur_cfg_comp_dest
=
2950 BT_CONFIG_COMPONENT_DEST_SOURCE
;
2951 struct bt_value
*cur_base_params
= NULL
;
2953 struct bt_config
*cfg
= NULL
;
2954 struct bt_value
*instance_names
= NULL
;
2955 struct bt_value
*connection_args
= NULL
;
2956 char error_buf
[256] = { 0 };
2959 memset(&ctf_legacy_opts
, 0, sizeof(ctf_legacy_opts
));
2960 memset(&text_legacy_opts
, 0, sizeof(text_legacy_opts
));
2963 print_convert_usage(stdout
);
2968 cfg
= bt_config_convert_create(initial_plugin_paths
);
2974 cfg
->cmd_data
.convert
.omit_system_plugin_path
= omit_system_plugin_path
;
2975 cfg
->cmd_data
.convert
.omit_home_plugin_path
= omit_home_plugin_path
;
2976 text_legacy_opts
.output
= g_string_new(NULL
);
2977 if (!text_legacy_opts
.output
) {
2982 text_legacy_opts
.dbg_info_dir
= g_string_new(NULL
);
2983 if (!text_legacy_opts
.dbg_info_dir
) {
2988 text_legacy_opts
.dbg_info_target_prefix
= g_string_new(NULL
);
2989 if (!text_legacy_opts
.dbg_info_target_prefix
) {
2994 cur_base_params
= bt_value_map_create();
2995 if (!cur_base_params
) {
3000 legacy_input_paths
= bt_value_array_create();
3001 if (!legacy_input_paths
) {
3006 instance_names
= bt_value_map_create();
3007 if (!instance_names
) {
3012 connection_args
= bt_value_array_create();
3013 if (!connection_args
) {
3018 ret
= append_env_var_plugin_paths(cfg
->cmd_data
.convert
.plugin_paths
);
3020 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
3024 /* Note: implicit source never gets positional base params. */
3025 implicit_source_comp
= bt_config_component_from_arg(DEFAULT_SOURCE_COMPONENT_NAME
);
3026 if (!implicit_source_comp
) {
3031 cur_cfg_comp
= implicit_source_comp
;
3032 cur_is_implicit_source
= true;
3033 use_implicit_source
= true;
3036 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3037 convert_long_options
, 0);
3039 printf_err("Cannot get popt context\n");
3043 poptReadDefaultConfig(pc
, 0);
3045 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3046 arg
= poptGetOptArg(pc
);
3049 case OPT_PLUGIN_PATH
:
3050 if (bt_common_is_setuid_setgid()) {
3051 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
3053 if (bt_config_append_plugin_paths(
3054 cfg
->cmd_data
.convert
.plugin_paths
,
3056 printf_err("Invalid --plugin-path option's argument:\n %s\n",
3062 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
3063 cfg
->cmd_data
.convert
.omit_system_plugin_path
= true;
3065 case OPT_OMIT_HOME_PLUGIN_PATH
:
3066 cfg
->cmd_data
.convert
.omit_home_plugin_path
= true;
3068 case OPT_OUTPUT_PATH
:
3069 if (text_legacy_opts
.output
->len
> 0) {
3070 printf_err("Duplicate --output option\n");
3074 g_string_assign(text_legacy_opts
.output
, arg
);
3076 case OPT_DEBUG_INFO_DIR
:
3077 if (text_legacy_opts
.dbg_info_dir
->len
> 0) {
3078 printf_err("Duplicate --debug-info-dir option\n");
3082 g_string_assign(text_legacy_opts
.dbg_info_dir
, arg
);
3084 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3085 if (text_legacy_opts
.dbg_info_target_prefix
->len
> 0) {
3086 printf_err("Duplicate --debug-info-target-prefix option\n");
3090 g_string_assign(text_legacy_opts
.dbg_info_target_prefix
, arg
);
3092 case OPT_INPUT_FORMAT
:
3095 if (opt
== OPT_INPUT_FORMAT
) {
3096 if (!strcmp(arg
, "ctf")) {
3097 /* Legacy CTF input format */
3098 if (legacy_input_format
) {
3099 print_err_dup_legacy_input();
3103 legacy_input_format
=
3104 LEGACY_INPUT_FORMAT_CTF
;
3106 } else if (!strcmp(arg
, "lttng-live")) {
3107 /* Legacy LTTng-live input format */
3108 if (legacy_input_format
) {
3109 print_err_dup_legacy_input();
3113 legacy_input_format
=
3114 LEGACY_INPUT_FORMAT_LTTNG_LIVE
;
3119 use_implicit_source
= false;
3121 /* Non-legacy: try to create a component config */
3122 if (cur_cfg_comp
&& !cur_is_implicit_source
) {
3123 add_cfg_comp(cfg
, cur_cfg_comp
,
3127 cur_cfg_comp
= bt_config_component_from_arg(arg
);
3128 if (!cur_cfg_comp
) {
3129 printf_err("Invalid format for --source option's argument:\n %s\n",
3133 cur_is_implicit_source
= false;
3135 assert(cur_base_params
);
3136 bt_put(cur_cfg_comp
->params
);
3137 cur_cfg_comp
->params
= bt_value_copy(cur_base_params
);
3138 if (!cur_cfg_comp
->params
) {
3143 cur_cfg_comp_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
3146 case OPT_OUTPUT_FORMAT
:
3149 if (opt
== OPT_OUTPUT_FORMAT
) {
3150 if (!strcmp(arg
, "text")) {
3151 /* Legacy CTF-text output format */
3152 if (legacy_output_format
) {
3153 print_err_dup_legacy_output();
3157 legacy_output_format
=
3158 LEGACY_OUTPUT_FORMAT_TEXT
;
3160 } else if (!strcmp(arg
, "dummy")) {
3161 /* Legacy dummy output format */
3162 if (legacy_output_format
) {
3163 print_err_dup_legacy_output();
3167 legacy_output_format
=
3168 LEGACY_OUTPUT_FORMAT_DUMMY
;
3170 } else if (!strcmp(arg
, "ctf-metadata")) {
3171 /* Legacy CTF-metadata output format */
3172 if (legacy_output_format
) {
3173 print_err_dup_legacy_output();
3177 legacy_output_format
=
3178 LEGACY_OUTPUT_FORMAT_CTF_METADATA
;
3183 /* Non-legacy: try to create a component config */
3184 if (cur_cfg_comp
&& !cur_is_implicit_source
) {
3185 add_cfg_comp(cfg
, cur_cfg_comp
,
3189 cur_cfg_comp
= bt_config_component_from_arg(arg
);
3190 if (!cur_cfg_comp
) {
3191 printf_err("Invalid format for --sink option's argument:\n %s\n",
3195 cur_is_implicit_source
= false;
3197 assert(cur_base_params
);
3198 bt_put(cur_cfg_comp
->params
);
3199 cur_cfg_comp
->params
= bt_value_copy(cur_base_params
);
3200 if (!cur_cfg_comp
->params
) {
3205 cur_cfg_comp_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
3210 struct bt_value
*params
;
3211 struct bt_value
*params_to_set
;
3213 if (!cur_cfg_comp
) {
3214 printf_err("Cannot add parameters to unavailable default source component `%s`:\n %s\n",
3215 DEFAULT_SOURCE_COMPONENT_NAME
, arg
);
3219 params
= bt_value_from_arg(arg
);
3221 printf_err("Invalid format for --params option's argument:\n %s\n",
3226 params_to_set
= bt_value_map_extend(cur_cfg_comp
->params
,
3229 if (!params_to_set
) {
3230 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
3235 BT_MOVE(cur_cfg_comp
->params
, params_to_set
);
3239 if (!cur_cfg_comp
) {
3240 printf_err("Cannot add `path` parameter to unavailable default source component `%s`:\n %s\n",
3241 DEFAULT_SOURCE_COMPONENT_NAME
, arg
);
3245 assert(cur_cfg_comp
->params
);
3247 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
3254 if (!cur_cfg_comp
) {
3255 printf_err("Cannot set the name of unavailable default source component `%s`:\n %s\n",
3256 DEFAULT_SOURCE_COMPONENT_NAME
, arg
);
3260 if (bt_value_map_has_key(instance_names
, arg
)) {
3261 printf_err("Duplicate component instance name:\n %s\n",
3266 g_string_assign(cur_cfg_comp
->instance_name
, arg
);
3268 if (bt_value_map_insert(instance_names
,
3269 arg
, bt_value_null
)) {
3274 case OPT_BASE_PARAMS
:
3276 struct bt_value
*params
= bt_value_from_arg(arg
);
3279 printf_err("Invalid format for --base-params option's argument:\n %s\n",
3284 BT_MOVE(cur_base_params
, params
);
3287 case OPT_RESET_BASE_PARAMS
:
3288 BT_PUT(cur_base_params
);
3289 cur_base_params
= bt_value_map_create();
3290 if (!cur_base_params
) {
3296 if (text_legacy_opts
.names
) {
3297 printf_err("Duplicate --names option\n");
3301 text_legacy_opts
.names
= names_from_arg(arg
);
3302 if (!text_legacy_opts
.names
) {
3303 printf_err("Invalid --names option's argument:\n %s\n",
3309 if (text_legacy_opts
.fields
) {
3310 printf_err("Duplicate --fields option\n");
3314 text_legacy_opts
.fields
= fields_from_arg(arg
);
3315 if (!text_legacy_opts
.fields
) {
3316 printf_err("Invalid --fields option's argument:\n %s\n",
3322 text_legacy_opts
.no_delta
= true;
3324 case OPT_CLOCK_CYCLES
:
3325 text_legacy_opts
.clock_cycles
= true;
3327 case OPT_CLOCK_SECONDS
:
3328 text_legacy_opts
.clock_seconds
= true;
3330 case OPT_CLOCK_DATE
:
3331 text_legacy_opts
.clock_date
= true;
3334 text_legacy_opts
.clock_gmt
= true;
3336 case OPT_DEBUG_INFO_FULL_PATH
:
3337 text_legacy_opts
.dbg_info_full_path
= true;
3339 case OPT_CLOCK_OFFSET
:
3343 if (ctf_legacy_opts
.offset_s
.is_set
) {
3344 printf_err("Duplicate --clock-offset option\n");
3348 if (parse_int64(arg
, &val
)) {
3349 printf_err("Invalid --clock-offset option's argument:\n %s\n",
3354 set_offset_value(&ctf_legacy_opts
.offset_s
, val
);
3357 case OPT_CLOCK_OFFSET_NS
:
3361 if (ctf_legacy_opts
.offset_ns
.is_set
) {
3362 printf_err("Duplicate --clock-offset-ns option\n");
3366 if (parse_int64(arg
, &val
)) {
3367 printf_err("Invalid --clock-offset-ns option's argument:\n %s\n",
3372 set_offset_value(&ctf_legacy_opts
.offset_ns
, val
);
3375 case OPT_STREAM_INTERSECTION
:
3376 ctf_legacy_opts
.stream_intersection
= true;
3378 case OPT_CLOCK_FORCE_CORRELATE
:
3379 cfg
->cmd_data
.convert
.force_correlate
= true;
3382 if (!cur_cfg_comp
) {
3383 printf_err("Cannot add `begin` parameter to unavailable default source component `%s`:\n %s\n",
3384 DEFAULT_SOURCE_COMPONENT_NAME
, arg
);
3387 if (cur_cfg_comp_dest
!= BT_CONFIG_COMPONENT_DEST_SOURCE
) {
3388 printf_err("--begin option must follow a --source option:\n %s\n",
3392 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
3399 if (!cur_cfg_comp
) {
3400 printf_err("Cannot add `end` parameter to unavailable default source component `%s`:\n %s\n",
3401 DEFAULT_SOURCE_COMPONENT_NAME
, arg
);
3404 if (cur_cfg_comp_dest
!= BT_CONFIG_COMPONENT_DEST_SOURCE
) {
3405 printf_err("--end option must follow a --source option:\n %s\n",
3409 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
3417 const char *begin
, *end
;
3419 if (!cur_cfg_comp
) {
3420 printf_err("Cannot add `begin` and `end` parameters to unavailable default source component `%s`:\n %s\n",
3421 DEFAULT_SOURCE_COMPONENT_NAME
, arg
);
3424 if (cur_cfg_comp_dest
!= BT_CONFIG_COMPONENT_DEST_SOURCE
) {
3425 printf_err("--timerange option must follow a --source option:\n %s\n",
3429 if (split_timerange(arg
, &begin
, &end
)) {
3430 printf_err("Invalid --timerange format: expecting BEGIN,END or [BEGIN,END]:\n %s\n",
3434 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
3439 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
3447 if (bt_value_array_append_string(connection_args
,
3454 print_convert_usage(stdout
);
3459 cfg
->verbose
= true;
3465 printf_err("Unknown command-line option specified (option code %d)\n",
3474 /* Check for option parsing error */
3476 printf_err("While parsing command-line options, at option %s: %s\n",
3477 poptBadOption(pc
, 0), poptStrerror(opt
));
3481 /* Consume leftover arguments as legacy input paths */
3483 const char *input_path
= poptGetArg(pc
);
3489 if (bt_value_array_append_string(legacy_input_paths
,
3496 if (append_home_and_system_plugin_paths(
3497 cfg
->cmd_data
.convert
.plugin_paths
,
3498 cfg
->cmd_data
.convert
.omit_system_plugin_path
,
3499 cfg
->cmd_data
.convert
.omit_home_plugin_path
)) {
3500 printf_err("Cannot append home and system plugin paths\n");
3504 /* Append current component configuration, if any */
3505 if (cur_cfg_comp
&& !cur_is_implicit_source
) {
3506 add_cfg_comp(cfg
, cur_cfg_comp
, cur_cfg_comp_dest
);
3508 cur_cfg_comp
= NULL
;
3510 /* Validate legacy/non-legacy options */
3511 if (!validate_cfg(cfg
, &legacy_input_format
, &legacy_output_format
,
3512 legacy_input_paths
, &ctf_legacy_opts
,
3513 &text_legacy_opts
)) {
3514 printf_err("Command-line options form an invalid configuration\n");
3519 * If there's a legacy input format, convert it to source
3520 * component configurations.
3522 if (legacy_input_format
) {
3523 if (append_sources_from_legacy_opts(
3524 cfg
->cmd_data
.convert
.sources
,
3525 legacy_input_format
, &ctf_legacy_opts
,
3526 legacy_input_paths
)) {
3527 printf_err("Cannot convert legacy input format options to source component instance(s)\n");
3530 if (append_sources_from_implicit_params(
3531 cfg
->cmd_data
.convert
.sources
,
3532 implicit_source_comp
)) {
3533 printf_err("Cannot initialize legacy component parameters\n");
3536 use_implicit_source
= false;
3538 if (use_implicit_source
) {
3539 add_cfg_comp(cfg
, implicit_source_comp
,
3540 BT_CONFIG_COMPONENT_DEST_SOURCE
);
3541 implicit_source_comp
= NULL
;
3543 if (implicit_source_comp
3544 && !bt_value_map_is_empty(implicit_source_comp
->params
)) {
3545 printf_err("Arguments specified for implicit source, but an explicit source has been specified, overriding it\n");
3552 * If there's a legacy output format, convert it to sink
3553 * component configurations.
3555 if (legacy_output_format
) {
3556 if (append_sinks_from_legacy_opts(cfg
->cmd_data
.convert
.sinks
,
3557 legacy_output_format
, &text_legacy_opts
)) {
3558 printf_err("Cannot convert legacy output format options to sink component instance(s)\n");
3563 if (cfg
->cmd_data
.convert
.sinks
->len
== 0) {
3564 /* Use implicit sink as default. */
3565 cur_cfg_comp
= bt_config_component_from_arg(DEFAULT_SINK_COMPONENT_NAME
);
3566 if (!cur_cfg_comp
) {
3567 printf_error("Cannot find implicit sink plugin `%s`\n",
3568 DEFAULT_SINK_COMPONENT_NAME
);
3570 add_cfg_comp(cfg
, cur_cfg_comp
,
3571 BT_CONFIG_COMPONENT_DEST_SINK
);
3572 cur_cfg_comp
= NULL
;
3575 ret
= bt_config_create_connections(cfg
, connection_args
,
3578 printf_err("Cannot creation connections:\n%s", error_buf
);
3590 poptFreeContext(pc
);
3593 if (text_legacy_opts
.output
) {
3594 g_string_free(text_legacy_opts
.output
, TRUE
);
3597 if (text_legacy_opts
.dbg_info_dir
) {
3598 g_string_free(text_legacy_opts
.dbg_info_dir
, TRUE
);
3601 if (text_legacy_opts
.dbg_info_target_prefix
) {
3602 g_string_free(text_legacy_opts
.dbg_info_target_prefix
, TRUE
);
3606 BT_PUT(implicit_source_comp
);
3607 BT_PUT(cur_cfg_comp
);
3608 BT_PUT(cur_base_params
);
3609 BT_PUT(text_legacy_opts
.names
);
3610 BT_PUT(text_legacy_opts
.fields
);
3611 BT_PUT(legacy_input_paths
);
3612 BT_PUT(instance_names
);
3613 BT_PUT(connection_args
);
3618 * Prints the Babeltrace 2.x general usage.
3621 void print_gen_usage(FILE *fp
)
3623 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [COMMAND] [COMMAND OPTIONS]\n");
3625 fprintf(fp
, "General options:\n");
3627 fprintf(fp
, " -d, --debug Enable debug mode\n");
3628 fprintf(fp
, " -h --help Show this help and quit\n");
3629 fprintf(fp
, " --help-legacy Show Babeltrace 1.x legacy help and quit\n");
3630 fprintf(fp
, " -v, --verbose Enable verbose output\n");
3631 fprintf(fp
, " -V, --version Show version and quit\n");
3633 fprintf(fp
, "Available commands:\n");
3635 fprintf(fp
, " convert Build a trace conversion graph and run it (default)\n");
3636 fprintf(fp
, " help Get help for a plugin or a component class\n");
3637 fprintf(fp
, " list-plugins List available plugins and their content\n");
3639 fprintf(fp
, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
3642 struct bt_config
*bt_config_from_args(int argc
, const char *argv
[],
3643 int *retcode
, bool omit_system_plugin_path
,
3644 bool omit_home_plugin_path
,
3645 struct bt_value
*initial_plugin_paths
)
3647 struct bt_config
*config
= NULL
;
3648 bool verbose
= false;
3651 enum bt_config_command command
= -1;
3652 const char **command_argv
= NULL
;
3653 int command_argc
= -1;
3654 const char *command_name
= NULL
;
3659 print_gen_usage(stdout
);
3663 for (i
= 1; i
< argc
; i
++) {
3664 const char *cur_arg
= argv
[i
];
3666 if (strcmp(cur_arg
, "-d") == 0 ||
3667 strcmp(cur_arg
, "--debug") == 0) {
3669 } else if (strcmp(cur_arg
, "-v") == 0 ||
3670 strcmp(cur_arg
, "--verbose") == 0) {
3672 } else if (strcmp(cur_arg
, "-V") == 0 ||
3673 strcmp(cur_arg
, "--version") == 0) {
3676 } else if (strcmp(cur_arg
, "-h") == 0 ||
3677 strcmp(cur_arg
, "--help") == 0) {
3678 print_gen_usage(stdout
);
3680 } else if (strcmp(cur_arg
, "--help-legacy") == 0) {
3681 print_legacy_usage(stdout
);
3684 bool has_command
= true;
3687 * First unknown argument: is it a known command
3690 if (strcmp(cur_arg
, "convert") == 0) {
3691 command
= BT_CONFIG_COMMAND_CONVERT
;
3692 } else if (strcmp(cur_arg
, "list-plugins") == 0) {
3693 command
= BT_CONFIG_COMMAND_LIST_PLUGINS
;
3694 } else if (strcmp(cur_arg
, "help") == 0) {
3695 command
= BT_CONFIG_COMMAND_HELP
;
3698 * Unknown argument, but not a known
3699 * command name: assume the whole
3700 * arguments are for the default convert
3703 command
= BT_CONFIG_COMMAND_CONVERT
;
3704 command_argv
= argv
;
3705 command_argc
= argc
;
3706 has_command
= false;
3710 command_argv
= &argv
[i
];
3711 command_argc
= argc
- i
;
3712 command_name
= cur_arg
;
3718 if ((int) command
< 0) {
3720 * We only got non-help, non-version general options
3721 * like --verbose and --debug, without any other
3722 * arguments, so we can't do anything useful: print the
3725 print_gen_usage(stdout
);
3729 assert(command_argv
);
3730 assert(command_argc
>= 0);
3733 case BT_CONFIG_COMMAND_CONVERT
:
3734 config
= bt_config_convert_from_args(command_argc
, command_argv
,
3735 retcode
, omit_system_plugin_path
,
3736 omit_home_plugin_path
, initial_plugin_paths
);
3738 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
3739 config
= bt_config_list_plugins_from_args(command_argc
,
3740 command_argv
, retcode
, omit_system_plugin_path
,
3741 omit_home_plugin_path
, initial_plugin_paths
);
3743 case BT_CONFIG_COMMAND_HELP
:
3744 config
= bt_config_help_from_args(command_argc
,
3745 command_argv
, retcode
, omit_system_plugin_path
,
3746 omit_home_plugin_path
, initial_plugin_paths
);
3754 config
->verbose
= true;
3758 config
->debug
= true;
3761 config
->command_name
= command_name
;