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"
41 #define DEFAULT_SOURCE_COMPONENT_NAME "ctf.fs"
42 #define DEFAULT_SINK_COMPONENT_NAME "text.text"
45 * Error printf() macro which prepends "Error: " the first time it's
46 * called. This gives a nicer feel than having a bunch of error prefixes
47 * (since the following lines usually describe the error and possible
48 * solutions), or the error prefix just at the end.
50 #define printf_err(fmt, args...) \
52 if (is_first_error) { \
53 fprintf(stderr, "Error: "); \
54 is_first_error = false; \
56 fprintf(stderr, fmt, ##args); \
59 static bool is_first_error
= true;
61 /* INI-style parsing FSM states */
62 enum ini_parsing_fsm_state
{
63 /* Expect a map key (identifier) */
66 /* Expect an equal character ('=') */
72 /* Expect a negative number value */
73 INI_EXPECT_VALUE_NUMBER_NEG
,
75 /* Expect a comma character (',') */
79 /* INI-style parsing state variables */
80 struct ini_parsing_state
{
81 /* Lexical scanner (owned by this) */
84 /* Output map value object being filled (owned by this) */
85 struct bt_value
*params
;
87 /* Next expected FSM state */
88 enum ini_parsing_fsm_state expecting
;
90 /* Last decoded map key (owned by this) */
93 /* Complete INI-style string to parse (not owned by this) */
96 /* Error buffer (not owned by this) */
100 /* Offset option with "is set" boolean */
106 /* Legacy "ctf"/"lttng-live" format options */
107 struct ctf_legacy_opts
{
108 struct offset_opt offset_s
;
109 struct offset_opt offset_ns
;
110 bool stream_intersection
;
113 /* Legacy "text" format options */
114 struct text_legacy_opts
{
116 * output, dbg_info_dir, dbg_info_target_prefix, names,
117 * and fields are owned by this.
120 GString
*dbg_info_dir
;
121 GString
*dbg_info_target_prefix
;
122 struct bt_value
*names
;
123 struct bt_value
*fields
;
131 bool dbg_info_full_path
;
134 /* Legacy input format format */
135 enum legacy_input_format
{
136 LEGACY_INPUT_FORMAT_NONE
= 0,
137 LEGACY_INPUT_FORMAT_CTF
,
138 LEGACY_INPUT_FORMAT_LTTNG_LIVE
,
141 /* Legacy output format format */
142 enum legacy_output_format
{
143 LEGACY_OUTPUT_FORMAT_NONE
= 0,
144 LEGACY_OUTPUT_FORMAT_TEXT
,
145 LEGACY_OUTPUT_FORMAT_CTF_METADATA
,
146 LEGACY_OUTPUT_FORMAT_DUMMY
,
150 * Prints the "out of memory" error.
153 void print_err_oom(void)
155 printf_err("Out of memory\n");
159 * Prints duplicate legacy output format error.
162 void print_err_dup_legacy_output(void)
164 printf_err("More than one legacy output format specified\n");
168 * Prints duplicate legacy input format error.
171 void print_err_dup_legacy_input(void)
173 printf_err("More than one legacy input format specified\n");
177 * Checks if any of the "text" legacy options is set.
180 bool text_legacy_opts_is_any_set(struct text_legacy_opts
*opts
)
182 return (opts
->output
&& opts
->output
->len
> 0) ||
183 (opts
->dbg_info_dir
&& opts
->dbg_info_dir
->len
> 0) ||
184 (opts
->dbg_info_target_prefix
&&
185 opts
->dbg_info_target_prefix
->len
> 0) ||
186 bt_value_array_size(opts
->names
) > 0 ||
187 bt_value_array_size(opts
->fields
) > 0 ||
188 opts
->no_delta
|| opts
->clock_cycles
|| opts
->clock_seconds
||
189 opts
->clock_date
|| opts
->clock_gmt
||
190 opts
->dbg_info_full_path
;
194 * Checks if any of the "ctf" legacy options is set.
197 bool ctf_legacy_opts_is_any_set(struct ctf_legacy_opts
*opts
)
199 return opts
->offset_s
.is_set
|| opts
->offset_ns
.is_set
||
200 opts
->stream_intersection
;
204 * Appends an "expecting token" error to the INI-style parsing state's
208 void ini_append_error_expecting(struct ini_parsing_state
*state
,
209 GScanner
*scanner
, const char *expecting
)
214 g_string_append_printf(state
->ini_error
, "Expecting %s:\n", expecting
);
216 /* Only print error if there's one line */
217 if (strchr(state
->arg
, '\n') != NULL
|| strlen(state
->arg
) == 0) {
221 g_string_append_printf(state
->ini_error
, "\n %s\n", state
->arg
);
222 pos
= g_scanner_cur_position(scanner
) + 4;
224 if (!g_scanner_eof(scanner
)) {
228 for (i
= 0; i
< pos
; ++i
) {
229 g_string_append_printf(state
->ini_error
, " ");
232 g_string_append_printf(state
->ini_error
, "^\n\n");
236 int ini_handle_state(struct ini_parsing_state
*state
)
239 GTokenType token_type
;
240 struct bt_value
*value
= NULL
;
242 token_type
= g_scanner_get_next_token(state
->scanner
);
243 if (token_type
== G_TOKEN_EOF
) {
244 if (state
->expecting
!= INI_EXPECT_COMMA
) {
245 switch (state
->expecting
) {
246 case INI_EXPECT_EQUAL
:
247 ini_append_error_expecting(state
,
248 state
->scanner
, "'='");
250 case INI_EXPECT_VALUE
:
251 case INI_EXPECT_VALUE_NUMBER_NEG
:
252 ini_append_error_expecting(state
,
253 state
->scanner
, "value");
255 case INI_EXPECT_MAP_KEY
:
256 ini_append_error_expecting(state
,
257 state
->scanner
, "unquoted map key");
270 switch (state
->expecting
) {
271 case INI_EXPECT_MAP_KEY
:
272 if (token_type
!= G_TOKEN_IDENTIFIER
) {
273 ini_append_error_expecting(state
, state
->scanner
,
278 free(state
->last_map_key
);
279 state
->last_map_key
=
280 strdup(state
->scanner
->value
.v_identifier
);
281 if (!state
->last_map_key
) {
282 g_string_append(state
->ini_error
,
287 if (bt_value_map_has_key(state
->params
, state
->last_map_key
)) {
288 g_string_append_printf(state
->ini_error
,
289 "Duplicate parameter key: `%s`\n",
290 state
->last_map_key
);
294 state
->expecting
= INI_EXPECT_EQUAL
;
296 case INI_EXPECT_EQUAL
:
297 if (token_type
!= G_TOKEN_CHAR
) {
298 ini_append_error_expecting(state
,
299 state
->scanner
, "'='");
303 if (state
->scanner
->value
.v_char
!= '=') {
304 ini_append_error_expecting(state
,
305 state
->scanner
, "'='");
309 state
->expecting
= INI_EXPECT_VALUE
;
311 case INI_EXPECT_VALUE
:
313 switch (token_type
) {
315 if (state
->scanner
->value
.v_char
== '-') {
316 /* Negative number */
318 INI_EXPECT_VALUE_NUMBER_NEG
;
321 ini_append_error_expecting(state
,
322 state
->scanner
, "value");
328 /* Positive integer */
329 uint64_t int_val
= state
->scanner
->value
.v_int64
;
331 if (int_val
> (1ULL << 63) - 1) {
332 g_string_append_printf(state
->ini_error
,
333 "Integer value %" PRIu64
" is outside the range of a 64-bit signed integer\n",
338 value
= bt_value_integer_create_init(
343 /* Positive floating point number */
344 value
= bt_value_float_create_init(
345 state
->scanner
->value
.v_float
);
349 value
= bt_value_string_create_init(
350 state
->scanner
->value
.v_string
);
352 case G_TOKEN_IDENTIFIER
:
355 * Using symbols would be appropriate here,
356 * but said symbols are allowed as map key,
357 * so it's easier to consider everything an
360 * If one of the known symbols is not
361 * recognized here, then fall back to creating
364 const char *id
= state
->scanner
->value
.v_identifier
;
366 if (!strcmp(id
, "null") || !strcmp(id
, "NULL") ||
367 !strcmp(id
, "nul")) {
368 value
= bt_value_null
;
369 } else if (!strcmp(id
, "true") || !strcmp(id
, "TRUE") ||
370 !strcmp(id
, "yes") ||
371 !strcmp(id
, "YES")) {
372 value
= bt_value_bool_create_init(true);
373 } else if (!strcmp(id
, "false") ||
374 !strcmp(id
, "FALSE") ||
377 value
= bt_value_bool_create_init(false);
379 value
= bt_value_string_create_init(id
);
384 /* Unset value variable will trigger the error */
389 ini_append_error_expecting(state
,
390 state
->scanner
, "value");
394 state
->expecting
= INI_EXPECT_COMMA
;
397 case INI_EXPECT_VALUE_NUMBER_NEG
:
399 switch (token_type
) {
402 /* Negative integer */
403 uint64_t int_val
= state
->scanner
->value
.v_int64
;
405 if (int_val
> (1ULL << 63) - 1) {
406 g_string_append_printf(state
->ini_error
,
407 "Integer value -%" PRIu64
" is outside the range of a 64-bit signed integer\n",
412 value
= bt_value_integer_create_init(
413 -((int64_t) int_val
));
417 /* Negative floating point number */
418 value
= bt_value_float_create_init(
419 -state
->scanner
->value
.v_float
);
422 /* Unset value variable will trigger the error */
427 ini_append_error_expecting(state
,
428 state
->scanner
, "value");
432 state
->expecting
= INI_EXPECT_COMMA
;
435 case INI_EXPECT_COMMA
:
436 if (token_type
!= G_TOKEN_CHAR
) {
437 ini_append_error_expecting(state
,
438 state
->scanner
, "','");
442 if (state
->scanner
->value
.v_char
!= ',') {
443 ini_append_error_expecting(state
,
444 state
->scanner
, "','");
448 state
->expecting
= INI_EXPECT_MAP_KEY
;
460 if (bt_value_map_insert(state
->params
,
461 state
->last_map_key
, value
)) {
462 /* Only override return value on error */
473 * Converts an INI-style argument to an equivalent map value object.
475 * Return value is owned by the caller.
478 struct bt_value
*bt_value_from_ini(const char *arg
, GString
*ini_error
)
480 /* Lexical scanner configuration */
481 GScannerConfig scanner_config
= {
482 /* Skip whitespaces */
483 .cset_skip_characters
= " \t\n",
485 /* Identifier syntax is: [a-zA-Z_][a-zA-Z0-9_.:-]* */
486 .cset_identifier_first
=
490 .cset_identifier_nth
=
495 /* "hello" and "Hello" two different keys */
496 .case_sensitive
= TRUE
,
499 .cpair_comment_single
= NULL
,
500 .skip_comment_multi
= TRUE
,
501 .skip_comment_single
= TRUE
,
502 .scan_comment_multi
= FALSE
,
505 * Do scan identifiers, including 1-char identifiers,
506 * but NULL is a normal identifier.
508 .scan_identifier
= TRUE
,
509 .scan_identifier_1char
= TRUE
,
510 .scan_identifier_NULL
= FALSE
,
513 * No specific symbols: null and boolean "symbols" are
514 * scanned as plain identifiers.
516 .scan_symbols
= FALSE
,
517 .symbol_2_token
= FALSE
,
518 .scope_0_fallback
= FALSE
,
521 * Scan "0b"-, "0"-, and "0x"-prefixed integers, but not
522 * integers prefixed with "$".
528 .scan_hex_dollar
= FALSE
,
530 /* Convert scanned numbers to integer tokens */
531 .numbers_2_int
= TRUE
,
533 /* Support both integers and floating-point numbers */
534 .int_2_float
= FALSE
,
536 /* Scan integers as 64-bit signed integers */
539 /* Only scan double-quoted strings */
540 .scan_string_sq
= FALSE
,
541 .scan_string_dq
= TRUE
,
543 /* Do not converter identifiers to string tokens */
544 .identifier_2_string
= FALSE
,
546 /* Scan characters as G_TOKEN_CHAR token */
547 .char_2_token
= FALSE
,
549 struct ini_parsing_state state
= {
552 .expecting
= INI_EXPECT_MAP_KEY
,
554 .ini_error
= ini_error
,
557 state
.params
= bt_value_map_create();
562 state
.scanner
= g_scanner_new(&scanner_config
);
563 if (!state
.scanner
) {
567 /* Let the scan begin */
568 g_scanner_input_text(state
.scanner
, arg
, strlen(arg
));
571 int ret
= ini_handle_state(&state
);
576 } else if (ret
> 0) {
585 BT_PUT(state
.params
);
589 g_scanner_destroy(state
.scanner
);
592 free(state
.last_map_key
);
597 * Returns the parameters map value object from a command-line
598 * parameter option's argument.
600 * Return value is owned by the caller.
603 struct bt_value
*bt_value_from_arg(const char *arg
)
605 struct bt_value
*params
= NULL
;
606 GString
*ini_error
= NULL
;
608 ini_error
= g_string_new(NULL
);
614 /* Try INI-style parsing */
615 params
= bt_value_from_ini(arg
, ini_error
);
617 printf_err("%s", ini_error
->str
);
623 g_string_free(ini_error
, TRUE
);
629 * Returns the plugin and component names from a command-line
630 * source/sink option's argument. arg must have the following format:
634 * where PLUGIN is the plugin name, and COMPONENT is the component
637 * On success, both *plugin and *component are not NULL. *plugin
638 * and *component are owned by the caller.
641 void plugin_component_names_from_arg(const char *arg
, char **plugin
,
647 size_t component_len
;
649 /* Initialize both return values to NULL: not found */
653 dot
= strchr(arg
, '.');
659 end
= arg
+ strlen(arg
);
660 plugin_len
= dot
- arg
;
661 component_len
= end
- dot
- 1;
662 if (plugin_len
== 0 || component_len
== 0) {
666 *plugin
= g_malloc0(plugin_len
+ 1);
672 g_strlcpy(*plugin
, arg
, plugin_len
+ 1);
673 *component
= g_malloc0(component_len
+ 1);
679 g_strlcpy(*component
, dot
+ 1, component_len
+ 1);
686 * Prints the Babeltrace version.
689 void print_version(void)
691 puts("Babeltrace " VERSION
);
695 * Destroys a component configuration.
698 void bt_config_component_destroy(struct bt_object
*obj
)
700 struct bt_config_component
*bt_config_component
=
701 container_of(obj
, struct bt_config_component
, base
);
707 if (bt_config_component
->plugin_name
) {
708 g_string_free(bt_config_component
->plugin_name
, TRUE
);
711 if (bt_config_component
->component_name
) {
712 g_string_free(bt_config_component
->component_name
, TRUE
);
715 BT_PUT(bt_config_component
->params
);
716 g_free(bt_config_component
);
723 * Creates a component configuration using the given plugin name and
724 * component name. plugin_name and component_name are copied (belong to
727 * Return value is owned by the caller.
730 struct bt_config_component
*bt_config_component_create(const char *plugin_name
,
731 const char *component_name
)
733 struct bt_config_component
*cfg_component
= NULL
;
735 cfg_component
= g_new0(struct bt_config_component
, 1);
736 if (!cfg_component
) {
741 bt_object_init(cfg_component
, bt_config_component_destroy
);
742 cfg_component
->plugin_name
= g_string_new(plugin_name
);
743 if (!cfg_component
->plugin_name
) {
748 cfg_component
->component_name
= g_string_new(component_name
);
749 if (!cfg_component
->component_name
) {
754 /* Start with empty parameters */
755 cfg_component
->params
= bt_value_map_create();
756 if (!cfg_component
->params
) {
764 BT_PUT(cfg_component
);
767 return cfg_component
;
771 * Creates a component configuration from a command-line source/sink
775 struct bt_config_component
*bt_config_component_from_arg(const char *arg
)
777 struct bt_config_component
*bt_config_component
= NULL
;
779 char *component_name
;
781 plugin_component_names_from_arg(arg
, &plugin_name
, &component_name
);
782 if (!plugin_name
|| !component_name
) {
783 printf_err("Cannot get plugin or component class name\n");
787 bt_config_component
= bt_config_component_create(plugin_name
,
789 if (!bt_config_component
) {
796 BT_PUT(bt_config_component
);
800 g_free(component_name
);
801 return bt_config_component
;
805 * Destroys a configuration.
808 void bt_config_destroy(struct bt_object
*obj
)
810 struct bt_config
*cfg
=
811 container_of(obj
, struct bt_config
, base
);
817 switch (cfg
->command
) {
818 case BT_CONFIG_COMMAND_CONVERT
:
819 if (cfg
->cmd_data
.convert
.sources
) {
820 g_ptr_array_free(cfg
->cmd_data
.convert
.sources
, TRUE
);
823 if (cfg
->cmd_data
.convert
.sinks
) {
824 g_ptr_array_free(cfg
->cmd_data
.convert
.sinks
, TRUE
);
827 BT_PUT(cfg
->cmd_data
.convert
.plugin_paths
);
829 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
830 BT_PUT(cfg
->cmd_data
.list_plugins
.plugin_paths
);
832 case BT_CONFIG_COMMAND_HELP
:
833 BT_PUT(cfg
->cmd_data
.help
.plugin_paths
);
835 if (cfg
->cmd_data
.help
.plugin_name
) {
836 g_string_free(cfg
->cmd_data
.help
.plugin_name
, TRUE
);
839 if (cfg
->cmd_data
.help
.component_name
) {
840 g_string_free(cfg
->cmd_data
.help
.component_name
, TRUE
);
853 static void destroy_gstring(void *data
)
855 g_string_free(data
, TRUE
);
859 * Extracts the various paths from the string arg, delimited by ':',
860 * and appends them to the array value object plugin_paths.
862 enum bt_value_status
bt_config_append_plugin_paths(
863 struct bt_value
*plugin_paths
, const char *arg
)
865 enum bt_value_status status
= BT_VALUE_STATUS_OK
;
866 GPtrArray
*dirs
= g_ptr_array_new_with_free_func(destroy_gstring
);
871 status
= BT_VALUE_STATUS_ERROR
;
875 ret
= bt_common_append_plugin_path_dirs(arg
, dirs
);
877 status
= BT_VALUE_STATUS_ERROR
;
881 for (i
= 0; i
< dirs
->len
; i
++) {
882 GString
*dir
= g_ptr_array_index(dirs
, i
);
884 bt_value_array_append_string(plugin_paths
, dir
->str
);
888 g_ptr_array_free(dirs
, TRUE
);
893 * Creates a simple lexical scanner for parsing comma-delimited names
896 * Return value is owned by the caller.
899 GScanner
*create_csv_identifiers_scanner(void)
901 GScannerConfig scanner_config
= {
902 .cset_skip_characters
= " \t\n",
903 .cset_identifier_first
= G_CSET_a_2_z G_CSET_A_2_Z
"_",
904 .cset_identifier_nth
= G_CSET_a_2_z G_CSET_A_2_Z
":_-",
905 .case_sensitive
= TRUE
,
906 .cpair_comment_single
= NULL
,
907 .skip_comment_multi
= TRUE
,
908 .skip_comment_single
= TRUE
,
909 .scan_comment_multi
= FALSE
,
910 .scan_identifier
= TRUE
,
911 .scan_identifier_1char
= TRUE
,
912 .scan_identifier_NULL
= FALSE
,
913 .scan_symbols
= FALSE
,
914 .symbol_2_token
= FALSE
,
915 .scope_0_fallback
= FALSE
,
916 .scan_binary
= FALSE
,
920 .scan_hex_dollar
= FALSE
,
921 .numbers_2_int
= FALSE
,
922 .int_2_float
= FALSE
,
923 .store_int64
= FALSE
,
924 .scan_string_sq
= FALSE
,
925 .scan_string_dq
= FALSE
,
926 .identifier_2_string
= FALSE
,
927 .char_2_token
= TRUE
,
930 return g_scanner_new(&scanner_config
);
934 * Inserts a string (if exists and not empty) or null to a map value
938 enum bt_value_status
map_insert_string_or_null(struct bt_value
*map
,
939 const char *key
, GString
*string
)
941 enum bt_value_status ret
;
943 if (string
&& string
->len
> 0) {
944 ret
= bt_value_map_insert_string(map
, key
, string
->str
);
946 ret
= bt_value_map_insert(map
, key
, bt_value_null
);
952 * Converts a comma-delimited list of known names (--names option) to
953 * an array value object containing those names as string value objects.
955 * Return value is owned by the caller.
958 struct bt_value
*names_from_arg(const char *arg
)
960 GScanner
*scanner
= NULL
;
961 struct bt_value
*names
= NULL
;
962 bool found_all
= false, found_none
= false, found_item
= false;
964 names
= bt_value_array_create();
970 scanner
= create_csv_identifiers_scanner();
976 g_scanner_input_text(scanner
, arg
, strlen(arg
));
979 GTokenType token_type
= g_scanner_get_next_token(scanner
);
981 switch (token_type
) {
982 case G_TOKEN_IDENTIFIER
:
984 const char *identifier
= scanner
->value
.v_identifier
;
986 if (!strcmp(identifier
, "payload") ||
987 !strcmp(identifier
, "args") ||
988 !strcmp(identifier
, "arg")) {
990 if (bt_value_array_append_string(names
,
994 } else if (!strcmp(identifier
, "context") ||
995 !strcmp(identifier
, "ctx")) {
997 if (bt_value_array_append_string(names
,
1001 } else if (!strcmp(identifier
, "scope") ||
1002 !strcmp(identifier
, "header")) {
1004 if (bt_value_array_append_string(names
,
1008 } else if (!strcmp(identifier
, "all")) {
1010 if (bt_value_array_append_string(names
,
1014 } else if (!strcmp(identifier
, "none")) {
1016 if (bt_value_array_append_string(names
,
1021 printf_err("Unknown field name: `%s`\n",
1037 if (found_none
&& found_all
) {
1038 printf_err("Only either `all` or `none` can be specified in the list given to the --names option, but not both.\n");
1042 * Legacy behavior is to clear the defaults (show none) when at
1043 * least one item is specified.
1045 if (found_item
&& !found_none
&& !found_all
) {
1046 if (bt_value_array_append_string(names
, "none")) {
1051 g_scanner_destroy(scanner
);
1058 g_scanner_destroy(scanner
);
1065 * Converts a comma-delimited list of known fields (--fields option) to
1066 * an array value object containing those fields as string
1069 * Return value is owned by the caller.
1072 struct bt_value
*fields_from_arg(const char *arg
)
1074 GScanner
*scanner
= NULL
;
1075 struct bt_value
*fields
;
1077 fields
= bt_value_array_create();
1083 scanner
= create_csv_identifiers_scanner();
1089 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1092 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1094 switch (token_type
) {
1095 case G_TOKEN_IDENTIFIER
:
1097 const char *identifier
= scanner
->value
.v_identifier
;
1099 if (!strcmp(identifier
, "trace") ||
1100 !strcmp(identifier
, "trace:hostname") ||
1101 !strcmp(identifier
, "trace:domain") ||
1102 !strcmp(identifier
, "trace:procname") ||
1103 !strcmp(identifier
, "trace:vpid") ||
1104 !strcmp(identifier
, "loglevel") ||
1105 !strcmp(identifier
, "emf") ||
1106 !strcmp(identifier
, "callsite") ||
1107 !strcmp(identifier
, "all")) {
1108 if (bt_value_array_append_string(fields
,
1113 printf_err("Unknown field name: `%s`\n",
1135 g_scanner_destroy(scanner
);
1141 * Inserts the equivalent "prefix-name" true boolean value objects into
1142 * map_obj where the names are in array_obj.
1145 int insert_flat_names_fields_from_array(struct bt_value
*map_obj
,
1146 struct bt_value
*array_obj
, const char *prefix
)
1150 GString
*tmpstr
= NULL
, *default_value
= NULL
;
1153 * array_obj may be NULL if no CLI options were specified to
1154 * trigger its creation.
1160 tmpstr
= g_string_new(NULL
);
1167 default_value
= g_string_new(NULL
);
1168 if (!default_value
) {
1174 for (i
= 0; i
< bt_value_array_size(array_obj
); i
++) {
1175 struct bt_value
*str_obj
= bt_value_array_get(array_obj
, i
);
1177 bool is_default
= false;
1180 printf_err("Unexpected error\n");
1185 ret
= bt_value_string_get(str_obj
, &suffix
);
1188 printf_err("Unexpected error\n");
1192 g_string_assign(tmpstr
, prefix
);
1193 g_string_append(tmpstr
, "-");
1195 /* Special-case for "all" and "none". */
1196 if (!strcmp(suffix
, "all")) {
1198 g_string_assign(default_value
, "show");
1199 } else if (!strcmp(suffix
, "none")) {
1201 g_string_assign(default_value
, "hide");
1204 g_string_append(tmpstr
, "default");
1205 ret
= map_insert_string_or_null(map_obj
,
1213 g_string_append(tmpstr
, suffix
);
1214 ret
= bt_value_map_insert_bool(map_obj
, tmpstr
->str
,
1224 if (default_value
) {
1225 g_string_free(default_value
, TRUE
);
1228 g_string_free(tmpstr
, TRUE
);
1235 * Returns the parameters (map value object) corresponding to the
1236 * legacy text format options.
1238 * Return value is owned by the caller.
1241 struct bt_value
*params_from_text_legacy_opts(
1242 struct text_legacy_opts
*text_legacy_opts
)
1244 struct bt_value
*params
;
1246 params
= bt_value_map_create();
1252 if (map_insert_string_or_null(params
, "output-path",
1253 text_legacy_opts
->output
)) {
1258 if (map_insert_string_or_null(params
, "debug-info-dir",
1259 text_legacy_opts
->dbg_info_dir
)) {
1264 if (map_insert_string_or_null(params
, "debug-info-target-prefix",
1265 text_legacy_opts
->dbg_info_target_prefix
)) {
1270 if (bt_value_map_insert_bool(params
, "debug-info-full-path",
1271 text_legacy_opts
->dbg_info_full_path
)) {
1276 if (bt_value_map_insert_bool(params
, "no-delta",
1277 text_legacy_opts
->no_delta
)) {
1282 if (bt_value_map_insert_bool(params
, "clock-cycles",
1283 text_legacy_opts
->clock_cycles
)) {
1288 if (bt_value_map_insert_bool(params
, "clock-seconds",
1289 text_legacy_opts
->clock_seconds
)) {
1294 if (bt_value_map_insert_bool(params
, "clock-date",
1295 text_legacy_opts
->clock_date
)) {
1300 if (bt_value_map_insert_bool(params
, "clock-gmt",
1301 text_legacy_opts
->clock_gmt
)) {
1306 if (insert_flat_names_fields_from_array(params
,
1307 text_legacy_opts
->names
, "name")) {
1311 if (insert_flat_names_fields_from_array(params
,
1312 text_legacy_opts
->fields
, "field")) {
1326 int append_sinks_from_legacy_opts(GPtrArray
*sinks
,
1327 enum legacy_output_format legacy_output_format
,
1328 struct text_legacy_opts
*text_legacy_opts
)
1331 struct bt_value
*params
= NULL
;
1332 const char *plugin_name
;
1333 const char *component_name
;
1334 struct bt_config_component
*bt_config_component
= NULL
;
1336 switch (legacy_output_format
) {
1337 case LEGACY_OUTPUT_FORMAT_TEXT
:
1338 plugin_name
= "text";
1339 component_name
= "text";
1341 case LEGACY_OUTPUT_FORMAT_CTF_METADATA
:
1342 plugin_name
= "ctf";
1343 component_name
= "metadata-text";
1345 case LEGACY_OUTPUT_FORMAT_DUMMY
:
1346 plugin_name
= "dummy";
1347 component_name
= "dummy";
1354 if (legacy_output_format
== LEGACY_OUTPUT_FORMAT_TEXT
) {
1355 /* Legacy "text" output format has parameters */
1356 params
= params_from_text_legacy_opts(text_legacy_opts
);
1362 * Legacy "dummy" and "ctf-metadata" output formats do
1363 * not have parameters.
1365 params
= bt_value_map_create();
1372 /* Create a component configuration */
1373 bt_config_component
= bt_config_component_create(plugin_name
,
1375 if (!bt_config_component
) {
1379 BT_MOVE(bt_config_component
->params
, params
);
1381 /* Move created component configuration to the array */
1382 g_ptr_array_add(sinks
, bt_config_component
);
1396 * Returns the parameters (map value object) corresponding to the
1397 * given legacy CTF format options.
1399 * Return value is owned by the caller.
1402 struct bt_value
*params_from_ctf_legacy_opts(
1403 struct ctf_legacy_opts
*ctf_legacy_opts
)
1405 struct bt_value
*params
;
1407 params
= bt_value_map_create();
1413 if (bt_value_map_insert_integer(params
, "offset-s",
1414 ctf_legacy_opts
->offset_s
.value
)) {
1419 if (bt_value_map_insert_integer(params
, "offset-ns",
1420 ctf_legacy_opts
->offset_ns
.value
)) {
1425 if (bt_value_map_insert_bool(params
, "stream-intersection",
1426 ctf_legacy_opts
->stream_intersection
)) {
1441 int append_sources_from_legacy_opts(GPtrArray
*sources
,
1442 enum legacy_input_format legacy_input_format
,
1443 struct ctf_legacy_opts
*ctf_legacy_opts
,
1444 struct bt_value
*legacy_input_paths
)
1448 struct bt_value
*base_params
;
1449 struct bt_value
*params
= NULL
;
1450 struct bt_value
*input_path
= NULL
;
1451 struct bt_value
*input_path_copy
= NULL
;
1452 const char *input_key
;
1453 const char *component_name
;
1455 switch (legacy_input_format
) {
1456 case LEGACY_INPUT_FORMAT_CTF
:
1458 component_name
= "fs";
1460 case LEGACY_INPUT_FORMAT_LTTNG_LIVE
:
1462 component_name
= "lttng-live";
1469 base_params
= params_from_ctf_legacy_opts(ctf_legacy_opts
);
1474 for (i
= 0; i
< bt_value_array_size(legacy_input_paths
); i
++) {
1475 struct bt_config_component
*bt_config_component
= NULL
;
1477 /* Copy base parameters as current parameters */
1478 params
= bt_value_copy(base_params
);
1483 /* Get current input path string value object */
1484 input_path
= bt_value_array_get(legacy_input_paths
, i
);
1489 /* Copy current input path value object */
1490 input_path_copy
= bt_value_copy(input_path
);
1491 if (!input_path_copy
) {
1495 /* Insert input path value object into current parameters */
1496 ret
= bt_value_map_insert(params
, input_key
, input_path_copy
);
1501 /* Create a component configuration */
1502 bt_config_component
= bt_config_component_create("ctf",
1504 if (!bt_config_component
) {
1508 BT_MOVE(bt_config_component
->params
, params
);
1510 /* Move created component configuration to the array */
1511 g_ptr_array_add(sources
, bt_config_component
);
1513 /* Put current stuff */
1515 BT_PUT(input_path_copy
);
1524 BT_PUT(base_params
);
1527 BT_PUT(input_path_copy
);
1532 * Escapes a string for the shell. The string is escaped knowing that
1533 * it's a parameter string value (double-quoted), and that it will be
1534 * entered between single quotes in the shell.
1536 * Return value is owned by the caller.
1539 char *str_shell_escape(const char *input
)
1542 const char *at
= input
;
1543 GString
*str
= g_string_new(NULL
);
1549 while (*at
!= '\0') {
1552 g_string_append(str
, "\\\\");
1555 g_string_append(str
, "\\\"");
1558 g_string_append(str
, "'\"'\"'");
1561 g_string_append(str
, "\\n");
1564 g_string_append(str
, "\\t");
1567 g_string_append_c(str
, *at
);
1577 g_string_free(str
, FALSE
);
1584 int append_prefixed_flag_params(GString
*str
, struct bt_value
*flags
,
1594 for (i
= 0; i
< bt_value_array_size(flags
); i
++) {
1595 struct bt_value
*value
= bt_value_array_get(flags
, i
);
1603 if (bt_value_string_get(value
, &flag
)) {
1609 g_string_append_printf(str
, ",%s-%s=true", prefix
, flag
);
1618 * Appends a boolean parameter string.
1621 void g_string_append_bool_param(GString
*str
, const char *name
, bool value
)
1623 g_string_append_printf(str
, ",%s=%s", name
, value
? "true" : "false");
1627 * Appends a path parameter string, or null if it's empty.
1630 int g_string_append_string_path_param(GString
*str
, const char *name
,
1635 if (path
->len
> 0) {
1636 char *escaped_path
= str_shell_escape(path
->str
);
1638 if (!escaped_path
) {
1643 g_string_append_printf(str
, "%s=\"%s\"", name
, escaped_path
);
1646 g_string_append_printf(str
, "%s=null", name
);
1659 * Prints the non-legacy sink options equivalent to the specified
1660 * legacy output format options.
1663 void print_output_legacy_to_sinks(
1664 enum legacy_output_format legacy_output_format
,
1665 struct text_legacy_opts
*text_legacy_opts
)
1667 const char *input_format
;
1668 GString
*str
= NULL
;
1670 str
= g_string_new(" ");
1676 switch (legacy_output_format
) {
1677 case LEGACY_OUTPUT_FORMAT_TEXT
:
1678 input_format
= "text";
1680 case LEGACY_OUTPUT_FORMAT_CTF_METADATA
:
1681 input_format
= "ctf-metadata";
1683 case LEGACY_OUTPUT_FORMAT_DUMMY
:
1684 input_format
= "dummy";
1690 printf_err("Both `%s` legacy output format and non-legacy sink component\ninstances(s) specified.\n\n",
1692 printf_err("Specify the following non-legacy sink component instance instead of the\nlegacy `%s` output format options:\n\n",
1694 g_string_append(str
, "-o ");
1696 switch (legacy_output_format
) {
1697 case LEGACY_OUTPUT_FORMAT_TEXT
:
1698 g_string_append(str
, "text.text");
1700 case LEGACY_OUTPUT_FORMAT_CTF_METADATA
:
1701 g_string_append(str
, "ctf.metadata-text");
1703 case LEGACY_OUTPUT_FORMAT_DUMMY
:
1704 g_string_append(str
, "dummy.dummy");
1710 if (legacy_output_format
== LEGACY_OUTPUT_FORMAT_TEXT
&&
1711 text_legacy_opts_is_any_set(text_legacy_opts
)) {
1714 g_string_append(str
, " -p '");
1716 if (g_string_append_string_path_param(str
, "output-path",
1717 text_legacy_opts
->output
)) {
1721 g_string_append(str
, ",");
1723 if (g_string_append_string_path_param(str
, "debug-info-dir",
1724 text_legacy_opts
->dbg_info_dir
)) {
1728 g_string_append(str
, ",");
1730 if (g_string_append_string_path_param(str
,
1731 "debug-info-target-prefix",
1732 text_legacy_opts
->dbg_info_target_prefix
)) {
1736 g_string_append_bool_param(str
, "no-delta",
1737 text_legacy_opts
->no_delta
);
1738 g_string_append_bool_param(str
, "clock-cycles",
1739 text_legacy_opts
->clock_cycles
);
1740 g_string_append_bool_param(str
, "clock-seconds",
1741 text_legacy_opts
->clock_seconds
);
1742 g_string_append_bool_param(str
, "clock-date",
1743 text_legacy_opts
->clock_date
);
1744 g_string_append_bool_param(str
, "clock-gmt",
1745 text_legacy_opts
->clock_gmt
);
1746 ret
= append_prefixed_flag_params(str
, text_legacy_opts
->names
,
1752 ret
= append_prefixed_flag_params(str
, text_legacy_opts
->fields
,
1758 /* Remove last comma and close single quote */
1759 g_string_append(str
, "'");
1762 printf_err("%s\n\n", str
->str
);
1766 g_string_free(str
, TRUE
);
1772 * Prints the non-legacy source options equivalent to the specified
1773 * legacy input format options.
1776 void print_input_legacy_to_sources(enum legacy_input_format legacy_input_format
,
1777 struct bt_value
*legacy_input_paths
,
1778 struct ctf_legacy_opts
*ctf_legacy_opts
)
1780 const char *input_format
;
1781 GString
*str
= NULL
;
1784 str
= g_string_new(" ");
1790 switch (legacy_input_format
) {
1791 case LEGACY_INPUT_FORMAT_CTF
:
1792 input_format
= "ctf";
1794 case LEGACY_INPUT_FORMAT_LTTNG_LIVE
:
1795 input_format
= "lttng-live";
1801 printf_err("Both `%s` legacy input format and non-legacy source component\ninstance(s) specified.\n\n",
1803 printf_err("Specify the following non-legacy source component instance(s) instead of the\nlegacy `%s` input format options and positional arguments:\n\n",
1806 for (i
= 0; i
< bt_value_array_size(legacy_input_paths
); i
++) {
1807 struct bt_value
*input_value
=
1808 bt_value_array_get(legacy_input_paths
, i
);
1809 const char *input
= NULL
;
1810 char *escaped_input
;
1813 assert(input_value
);
1814 ret
= bt_value_string_get(input_value
, &input
);
1815 BT_PUT(input_value
);
1816 assert(!ret
&& input
);
1817 escaped_input
= str_shell_escape(input
);
1818 if (!escaped_input
) {
1823 g_string_append(str
, "-i ctf.");
1825 switch (legacy_input_format
) {
1826 case LEGACY_INPUT_FORMAT_CTF
:
1827 g_string_append(str
, "fs -p 'path=\"");
1829 case LEGACY_INPUT_FORMAT_LTTNG_LIVE
:
1830 g_string_append(str
, "lttng-live -p 'url=\"");
1836 g_string_append(str
, escaped_input
);
1837 g_string_append(str
, "\"");
1838 g_string_append_printf(str
, ",offset-s=%" PRId64
,
1839 ctf_legacy_opts
->offset_s
.value
);
1840 g_string_append_printf(str
, ",offset-ns=%" PRId64
,
1841 ctf_legacy_opts
->offset_ns
.value
);
1842 g_string_append_bool_param(str
, "stream-intersection",
1843 ctf_legacy_opts
->stream_intersection
);
1844 g_string_append(str
, "' ");
1845 g_free(escaped_input
);
1848 printf_err("%s\n\n", str
->str
);
1852 g_string_free(str
, TRUE
);
1858 * Validates a given configuration, with optional legacy input and
1859 * output formats options. Prints useful error messages if anything
1862 * Returns true when the configuration is valid.
1865 bool validate_cfg(struct bt_config
*cfg
,
1866 enum legacy_input_format
*legacy_input_format
,
1867 enum legacy_output_format
*legacy_output_format
,
1868 struct bt_value
*legacy_input_paths
,
1869 struct ctf_legacy_opts
*ctf_legacy_opts
,
1870 struct text_legacy_opts
*text_legacy_opts
)
1872 bool legacy_input
= false;
1873 bool legacy_output
= false;
1875 /* Determine if the input and output should be legacy-style */
1876 if (*legacy_input_format
!= LEGACY_INPUT_FORMAT_NONE
||
1877 !bt_value_array_is_empty(legacy_input_paths
) ||
1878 ctf_legacy_opts_is_any_set(ctf_legacy_opts
)) {
1879 legacy_input
= true;
1882 if (*legacy_output_format
!= LEGACY_OUTPUT_FORMAT_NONE
||
1883 text_legacy_opts_is_any_set(text_legacy_opts
)) {
1884 legacy_output
= true;
1888 /* If no legacy input format was specified, default to CTF */
1889 if (*legacy_input_format
== LEGACY_INPUT_FORMAT_NONE
) {
1890 *legacy_input_format
= LEGACY_INPUT_FORMAT_CTF
;
1893 /* Make sure at least one input path exists */
1894 if (bt_value_array_is_empty(legacy_input_paths
)) {
1895 switch (*legacy_input_format
) {
1896 case LEGACY_INPUT_FORMAT_CTF
:
1897 printf_err("No input path specified for legacy `ctf` input format\n");
1899 case LEGACY_INPUT_FORMAT_LTTNG_LIVE
:
1900 printf_err("No URL specified for legacy `lttng-live` input format\n");
1908 /* Make sure no non-legacy sources are specified */
1909 if (cfg
->cmd_data
.convert
.sources
->len
!= 0) {
1910 print_input_legacy_to_sources(*legacy_input_format
,
1911 legacy_input_paths
, ctf_legacy_opts
);
1916 if (legacy_output
) {
1918 * If no legacy output format was specified, default to
1921 if (*legacy_output_format
== LEGACY_OUTPUT_FORMAT_NONE
) {
1922 *legacy_output_format
= LEGACY_OUTPUT_FORMAT_TEXT
;
1926 * If any "text" option was specified, the output must be
1929 if (text_legacy_opts_is_any_set(text_legacy_opts
) &&
1930 *legacy_output_format
!=
1931 LEGACY_OUTPUT_FORMAT_TEXT
) {
1932 printf_err("Options for legacy `text` output format specified with a different legacy output format\n");
1936 /* Make sure no non-legacy sinks are specified */
1937 if (cfg
->cmd_data
.convert
.sinks
->len
!= 0) {
1938 print_output_legacy_to_sinks(*legacy_output_format
,
1945 * If the output is the legacy "ctf-metadata" format, then the
1946 * input should be the legacy "ctf" input format.
1948 if (*legacy_output_format
== LEGACY_OUTPUT_FORMAT_CTF_METADATA
&&
1949 *legacy_input_format
!= LEGACY_INPUT_FORMAT_CTF
) {
1950 printf_err("Legacy `ctf-metadata` output format requires using legacy `ctf` input format\n");
1961 * Parses a 64-bit signed integer.
1963 * Returns a negative value if anything goes wrong.
1966 int parse_int64(const char *arg
, int64_t *val
)
1971 *val
= strtoll(arg
, &endptr
, 0);
1972 if (*endptr
!= '\0' || arg
== endptr
|| errno
!= 0) {
1986 OPT_CLOCK_FORCE_CORRELATE
,
1989 OPT_CLOCK_OFFSET_NS
,
1993 OPT_DEBUG_INFO_FULL_PATH
,
1994 OPT_DEBUG_INFO_TARGET_PREFIX
,
2003 OPT_OMIT_HOME_PLUGIN_PATH
,
2004 OPT_OMIT_SYSTEM_PLUGIN_PATH
,
2010 OPT_RESET_BASE_PARAMS
,
2013 OPT_STREAM_INTERSECTION
,
2019 * Sets the value of a given legacy offset option and marks it as set.
2021 static void set_offset_value(struct offset_opt
*offset_opt
, int64_t value
)
2023 offset_opt
->value
= value
;
2024 offset_opt
->is_set
= true;
2027 enum bt_config_component_dest
{
2028 BT_CONFIG_COMPONENT_DEST_SOURCE
,
2029 BT_CONFIG_COMPONENT_DEST_SINK
,
2033 * Adds a configuration component to the appropriate configuration
2034 * array depending on the destination.
2036 static void add_cfg_comp(struct bt_config
*cfg
,
2037 struct bt_config_component
*cfg_comp
,
2038 enum bt_config_component_dest dest
)
2040 if (dest
== BT_CONFIG_COMPONENT_DEST_SOURCE
) {
2041 g_ptr_array_add(cfg
->cmd_data
.convert
.sources
, cfg_comp
);
2043 g_ptr_array_add(cfg
->cmd_data
.convert
.sinks
, cfg_comp
);
2047 static int split_timerange(const char *arg
, const char **begin
, const char **end
)
2051 /* Try to match [begin,end] */
2052 c
= strchr(arg
, '[');
2066 /* Try to match begin,end */
2080 static int append_env_var_plugin_paths(struct bt_value
*plugin_paths
)
2085 if (bt_common_is_setuid_setgid()) {
2086 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
2090 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
2095 ret
= bt_config_append_plugin_paths(plugin_paths
, envvar
);
2101 static int append_home_and_system_plugin_paths(struct bt_value
*plugin_paths
,
2102 bool omit_system_plugin_path
, bool omit_home_plugin_path
)
2106 if (!omit_home_plugin_path
) {
2107 if (bt_common_is_setuid_setgid()) {
2108 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
2110 char *home_plugin_dir
=
2111 bt_common_get_home_plugin_path();
2113 if (home_plugin_dir
) {
2114 ret
= bt_config_append_plugin_paths(
2117 free(home_plugin_dir
);
2120 printf_err("Invalid home plugin path\n");
2127 if (!omit_system_plugin_path
) {
2128 if (bt_config_append_plugin_paths(plugin_paths
,
2129 bt_common_get_system_plugin_path())) {
2130 printf_err("Invalid system plugin path\n");
2139 static int append_sources_from_implicit_params(GPtrArray
*sources
,
2140 struct bt_config_component
*implicit_source_comp
)
2143 size_t len
= sources
->len
;
2145 for (i
= 0; i
< len
; i
++) {
2146 struct bt_config_component
*comp
;
2147 struct bt_value
*params_to_set
;
2149 comp
= g_ptr_array_index(sources
, i
);
2150 params_to_set
= bt_value_map_extend(comp
->params
,
2151 implicit_source_comp
->params
);
2152 if (!params_to_set
) {
2153 printf_err("Cannot extend legacy component parameters with non-legacy parameters\n");
2156 BT_MOVE(comp
->params
, params_to_set
);
2163 static struct bt_config
*bt_config_base_create(enum bt_config_command command
)
2165 struct bt_config
*cfg
;
2168 cfg
= g_new0(struct bt_config
, 1);
2174 bt_object_init(cfg
, bt_config_destroy
);
2175 cfg
->command
= command
;
2185 static struct bt_config
*bt_config_convert_create(
2186 struct bt_value
*initial_plugin_paths
)
2188 struct bt_config
*cfg
;
2191 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_CONVERT
);
2197 cfg
->cmd_data
.convert
.sources
= g_ptr_array_new_with_free_func(
2198 (GDestroyNotify
) bt_put
);
2199 if (!cfg
->cmd_data
.convert
.sources
) {
2204 cfg
->cmd_data
.convert
.sinks
= g_ptr_array_new_with_free_func(
2205 (GDestroyNotify
) bt_put
);
2206 if (!cfg
->cmd_data
.convert
.sinks
) {
2211 if (initial_plugin_paths
) {
2212 cfg
->cmd_data
.convert
.plugin_paths
=
2213 bt_get(initial_plugin_paths
);
2215 cfg
->cmd_data
.convert
.plugin_paths
= bt_value_array_create();
2216 if (!cfg
->cmd_data
.convert
.plugin_paths
) {
2231 static struct bt_config
*bt_config_list_plugins_create(
2232 struct bt_value
*initial_plugin_paths
)
2234 struct bt_config
*cfg
;
2237 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_LIST_PLUGINS
);
2243 if (initial_plugin_paths
) {
2244 cfg
->cmd_data
.list_plugins
.plugin_paths
=
2245 bt_get(initial_plugin_paths
);
2247 cfg
->cmd_data
.list_plugins
.plugin_paths
=
2248 bt_value_array_create();
2249 if (!cfg
->cmd_data
.list_plugins
.plugin_paths
) {
2264 static struct bt_config
*bt_config_help_create(
2265 struct bt_value
*initial_plugin_paths
)
2267 struct bt_config
*cfg
;
2270 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_HELP
);
2276 if (initial_plugin_paths
) {
2277 cfg
->cmd_data
.help
.plugin_paths
=
2278 bt_get(initial_plugin_paths
);
2280 cfg
->cmd_data
.help
.plugin_paths
=
2281 bt_value_array_create();
2282 if (!cfg
->cmd_data
.help
.plugin_paths
) {
2288 cfg
->cmd_data
.help
.plugin_name
= g_string_new(NULL
);
2289 if (!cfg
->cmd_data
.help
.plugin_name
) {
2294 cfg
->cmd_data
.help
.component_name
= g_string_new(NULL
);
2295 if (!cfg
->cmd_data
.help
.component_name
) {
2310 * Prints the help command usage.
2313 void print_help_usage(FILE *fp
)
2315 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
2316 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --source PLUGIN.COMPCLS\n");
2317 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --filter PLUGIN.COMPCLS\n");
2318 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --sink PLUGIN.COMPCLS\n");
2320 fprintf(fp
, "Options:\n");
2322 fprintf(fp
, " --filter=PLUGIN.COMPCLS Get help for the filter component class\n");
2323 fprintf(fp
, " COMPCLS found in the plugin PLUGIN\n");
2324 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2325 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2326 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2327 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2328 fprintf(fp
, " dynamic plugins can be loaded\n");
2329 fprintf(fp
, " --sink=PLUGIN.COMPCLS Get help for the sink component class\n");
2330 fprintf(fp
, " COMPCLS found in the plugin PLUGIN\n");
2331 fprintf(fp
, " --source=PLUGIN.COMPCLS Get help for the source component class\n");
2332 fprintf(fp
, " COMPCLS found in the plugin PLUGIN\n");
2333 fprintf(fp
, " -h --help Show this help and quit\n");
2335 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2337 fprintf(fp
, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
2340 static struct poptOption help_long_options
[] = {
2341 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2342 { "filter", '\0', POPT_ARG_STRING
, NULL
, OPT_FILTER
, NULL
, NULL
},
2343 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2344 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2345 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2346 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2347 { "sink", '\0', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
2348 { "source", '\0', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
2349 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
2353 * Creates a Babeltrace config object from the arguments of a help
2356 * *retcode is set to the appropriate exit code to use.
2358 struct bt_config
*bt_config_help_from_args(int argc
, const char *argv
[],
2359 int *retcode
, bool omit_system_plugin_path
,
2360 bool omit_home_plugin_path
,
2361 struct bt_value
*initial_plugin_paths
)
2363 poptContext pc
= NULL
;
2367 struct bt_config
*cfg
= NULL
;
2368 const char *leftover
;
2369 char *plugin_name
= NULL
, *component_name
= NULL
;
2370 char *plugin_comp_cls_names
= NULL
;
2373 cfg
= bt_config_help_create(initial_plugin_paths
);
2379 cfg
->cmd_data
.help
.comp_cls_type
= BT_COMPONENT_CLASS_TYPE_UNKNOWN
;
2380 cfg
->cmd_data
.help
.omit_system_plugin_path
= omit_system_plugin_path
;
2381 cfg
->cmd_data
.help
.omit_home_plugin_path
= omit_home_plugin_path
;
2382 ret
= append_env_var_plugin_paths(cfg
->cmd_data
.help
.plugin_paths
);
2384 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
2389 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2390 help_long_options
, 0);
2392 printf_err("Cannot get popt context\n");
2396 poptReadDefaultConfig(pc
, 0);
2398 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2399 arg
= poptGetOptArg(pc
);
2402 case OPT_PLUGIN_PATH
:
2403 if (bt_common_is_setuid_setgid()) {
2404 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
2406 if (bt_config_append_plugin_paths(
2407 cfg
->cmd_data
.help
.plugin_paths
,
2409 printf_err("Invalid --plugin-path option's argument:\n %s\n",
2415 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2416 cfg
->cmd_data
.help
.omit_system_plugin_path
= true;
2418 case OPT_OMIT_HOME_PLUGIN_PATH
:
2419 cfg
->cmd_data
.help
.omit_home_plugin_path
= true;
2424 if (cfg
->cmd_data
.help
.comp_cls_type
!=
2425 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
2426 printf_err("Cannot specify more than one plugin and component class:\n %s\n",
2433 cfg
->cmd_data
.help
.comp_cls_type
=
2434 BT_COMPONENT_CLASS_TYPE_SOURCE
;
2437 cfg
->cmd_data
.help
.comp_cls_type
=
2438 BT_COMPONENT_CLASS_TYPE_FILTER
;
2441 cfg
->cmd_data
.help
.comp_cls_type
=
2442 BT_COMPONENT_CLASS_TYPE_SINK
;
2447 plugin_comp_cls_names
= strdup(arg
);
2448 if (!plugin_comp_cls_names
) {
2454 print_help_usage(stdout
);
2459 printf_err("Unknown command-line option specified (option code %d)\n",
2468 /* Check for option parsing error */
2470 printf_err("While parsing command-line options, at option %s: %s\n",
2471 poptBadOption(pc
, 0), poptStrerror(opt
));
2475 leftover
= poptGetArg(pc
);
2477 if (cfg
->cmd_data
.help
.comp_cls_type
!=
2478 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
2479 printf_err("Cannot specify plugin name and --source/--filter/--sink component class:\n %s\n",
2484 g_string_assign(cfg
->cmd_data
.help
.plugin_name
, leftover
);
2486 if (cfg
->cmd_data
.help
.comp_cls_type
==
2487 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
2488 print_help_usage(stdout
);
2494 plugin_component_names_from_arg(plugin_comp_cls_names
,
2495 &plugin_name
, &component_name
);
2496 if (plugin_name
&& component_name
) {
2497 g_string_assign(cfg
->cmd_data
.help
.plugin_name
, plugin_name
);
2498 g_string_assign(cfg
->cmd_data
.help
.component_name
,
2501 printf_err("Invalid --source/--filter/--sink option's argument:\n %s\n",
2502 plugin_comp_cls_names
);
2507 if (append_home_and_system_plugin_paths(
2508 cfg
->cmd_data
.help
.plugin_paths
,
2509 cfg
->cmd_data
.help
.omit_system_plugin_path
,
2510 cfg
->cmd_data
.help
.omit_home_plugin_path
)) {
2511 printf_err("Cannot append home and system plugin paths\n");
2522 free(plugin_comp_cls_names
);
2523 g_free(plugin_name
);
2524 g_free(component_name
);
2527 poptFreeContext(pc
);
2535 * Prints the list-plugins command usage.
2538 void print_list_plugins_usage(FILE *fp
)
2540 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
2542 fprintf(fp
, "Options:\n");
2544 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2545 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2546 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2547 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2548 fprintf(fp
, " dynamic plugins can be loaded\n");
2549 fprintf(fp
, " -h --help Show this help and quit\n");
2551 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2553 fprintf(fp
, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
2556 static struct poptOption list_plugins_long_options
[] = {
2557 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2558 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2559 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2560 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2561 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2562 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
2566 * Creates a Babeltrace config object from the arguments of a
2567 * list-plugins command.
2569 * *retcode is set to the appropriate exit code to use.
2571 struct bt_config
*bt_config_list_plugins_from_args(int argc
, const char *argv
[],
2572 int *retcode
, bool omit_system_plugin_path
,
2573 bool omit_home_plugin_path
,
2574 struct bt_value
*initial_plugin_paths
)
2576 poptContext pc
= NULL
;
2580 struct bt_config
*cfg
= NULL
;
2581 const char *leftover
;
2584 cfg
= bt_config_list_plugins_create(initial_plugin_paths
);
2590 cfg
->cmd_data
.list_plugins
.omit_system_plugin_path
= omit_system_plugin_path
;
2591 cfg
->cmd_data
.list_plugins
.omit_home_plugin_path
= omit_home_plugin_path
;
2592 ret
= append_env_var_plugin_paths(
2593 cfg
->cmd_data
.list_plugins
.plugin_paths
);
2595 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
2600 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2601 list_plugins_long_options
, 0);
2603 printf_err("Cannot get popt context\n");
2607 poptReadDefaultConfig(pc
, 0);
2609 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2610 arg
= poptGetOptArg(pc
);
2613 case OPT_PLUGIN_PATH
:
2614 if (bt_common_is_setuid_setgid()) {
2615 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
2617 if (bt_config_append_plugin_paths(
2618 cfg
->cmd_data
.list_plugins
.plugin_paths
,
2620 printf_err("Invalid --plugin-path option's argument:\n %s\n",
2626 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2627 cfg
->cmd_data
.list_plugins
.omit_system_plugin_path
= true;
2629 case OPT_OMIT_HOME_PLUGIN_PATH
:
2630 cfg
->cmd_data
.list_plugins
.omit_home_plugin_path
= true;
2633 print_list_plugins_usage(stdout
);
2638 printf_err("Unknown command-line option specified (option code %d)\n",
2647 /* Check for option parsing error */
2649 printf_err("While parsing command-line options, at option %s: %s\n",
2650 poptBadOption(pc
, 0), poptStrerror(opt
));
2654 leftover
= poptGetArg(pc
);
2656 printf_err("Invalid argument: %s\n", leftover
);
2660 if (append_home_and_system_plugin_paths(
2661 cfg
->cmd_data
.list_plugins
.plugin_paths
,
2662 cfg
->cmd_data
.list_plugins
.omit_system_plugin_path
,
2663 cfg
->cmd_data
.list_plugins
.omit_home_plugin_path
)) {
2664 printf_err("Cannot append home and system plugin paths\n");
2676 poptFreeContext(pc
);
2684 * Prints the legacy, Babeltrace 1.x command usage. Those options are
2685 * still compatible in Babeltrace 2.x, but it is recommended to use
2686 * the more generic plugin/component parameters instead of those
2687 * hard-coded option names.
2690 void print_legacy_usage(FILE *fp
)
2692 fprintf(fp
, "Usage: babeltrace [OPTIONS] INPUT...\n");
2694 fprintf(fp
, "The following options are compatible with the Babeltrace 1.x options:\n");
2696 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently correlated\n");
2697 fprintf(fp
, " across traces\n");
2698 fprintf(fp
, " -d, --debug Enable debug mode\n");
2699 fprintf(fp
, " -i, --input-format=FORMAT Input trace format (default: ctf)\n");
2700 fprintf(fp
, " -l, --list List available formats\n");
2701 fprintf(fp
, " -o, --output-format=FORMAT Output trace format (default: text)\n");
2702 fprintf(fp
, " -v, --verbose Enable verbose output\n");
2703 fprintf(fp
, " --help-legacy Show this help and quit\n");
2704 fprintf(fp
, " -V, --version Show version and quit\n");
2706 fprintf(fp
, " Available input formats: ctf, lttng-live, ctf-metadata\n");
2707 fprintf(fp
, " Available output formats: text, dummy\n");
2709 fprintf(fp
, "Input formats specific options:\n");
2711 fprintf(fp
, " INPUT... Input trace file(s), directory(ies), or URLs\n");
2712 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
2713 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS nanoseconds\n");
2714 fprintf(fp
, " --stream-intersection Only process events when all streams are active\n");
2716 fprintf(fp
, "text output format specific options:\n");
2718 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
2719 fprintf(fp
, " --clock-date Print timestamp dates\n");
2720 fprintf(fp
, " --clock-gmt Print and parse timestamps in GMT time zone\n");
2721 fprintf(fp
, " (default: local time zone)\n");
2722 fprintf(fp
, " --clock-seconds Print the timestamps as [SEC.NS]\n");
2723 fprintf(fp
, " (default format: [HH:MM:SS.NS])\n");
2724 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
2725 fprintf(fp
, " (default: `/usr/lib/debug`)\n");
2726 fprintf(fp
, " --debug-info-full-path Show full debug info source and binary paths\n");
2727 fprintf(fp
, " --debug-info-target-prefix=DIR Use directory DIR as a prefix when looking\n");
2728 fprintf(fp
, " up executables during debug info analysis\n");
2729 fprintf(fp
, " (default: `/usr/lib/debug`)\n");
2730 fprintf(fp
, " -f, --fields=NAME[,NAME]... Print additional fields:\n");
2731 fprintf(fp
, " all, trace, trace:hostname, trace:domain,\n");
2732 fprintf(fp
, " trace:procname, trace:vpid, loglevel, emf\n");
2733 fprintf(fp
, " (default: trace:hostname, trace:procname,\n");
2734 fprintf(fp
, " trace:vpid)\n");
2735 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names:\n");
2736 fprintf(fp
, " payload (or arg or args)\n");
2737 fprintf(fp
, " none, all, scope, header, context (or ctx)\n");
2738 fprintf(fp
, " (default: payload, context)\n");
2739 fprintf(fp
, " --no-delta Do not print time delta between consecutive\n");
2740 fprintf(fp
, " events\n");
2741 fprintf(fp
, " -w, --output=PATH Write output to PATH (default: standard output)\n");
2745 * Prints the convert command usage.
2748 void print_convert_usage(FILE *fp
)
2750 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] convert [OPTIONS]\n");
2752 fprintf(fp
, "Options:\n");
2754 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
2755 fprintf(fp
, " for the following component instances\n");
2756 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2757 fprintf(fp
, " --begin=BEGIN Set the `begin` parameter of the latest\n");
2758 fprintf(fp
, " source component instance to BEGIN\n");
2759 fprintf(fp
, " (see the suggested format of BEGIN below)\n");
2760 fprintf(fp
, " -d, --debug Enable debug mode\n");
2761 fprintf(fp
, " --end=END Set the `end` parameter of the latest\n");
2762 fprintf(fp
, " source component instance to END\n");
2763 fprintf(fp
, " (see the suggested format of BEGIN below)\n");
2764 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2765 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2766 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2767 fprintf(fp
, " -p, --params=PARAMS Set the parameters of the latest component\n");
2768 fprintf(fp
, " instance (in command-line order) to PARAMS\n");
2769 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2770 fprintf(fp
, " -P, --path=PATH Set the `path` parameter of the latest\n");
2771 fprintf(fp
, " component instance to PATH\n");
2772 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2773 fprintf(fp
, " dynamic plugins can be loaded\n");
2774 fprintf(fp
, " -r, --reset-base-params Reset the current base parameters of the\n");
2775 fprintf(fp
, " following source and sink component\n");
2776 fprintf(fp
, " instances to an empty map\n");
2777 fprintf(fp
, " -o, --sink=PLUGIN.COMPCLS Instantiate a sink component from plugin\n");
2778 fprintf(fp
, " PLUGIN and component class COMPCLS (may be\n");
2779 fprintf(fp
, " repeated)\n");
2780 fprintf(fp
, " -i, --source=PLUGIN.COMPCLS Instantiate a source component from plugin\n");
2781 fprintf(fp
, " PLUGIN and component class COMPCLS (may be\n");
2782 fprintf(fp
, " repeated)\n");
2783 fprintf(fp
, " --timerange=TIMERANGE Set time range to TIMERANGE: BEGIN,END or\n");
2784 fprintf(fp
, " [BEGIN,END] (literally `[` and `]`)\n");
2785 fprintf(fp
, " (suggested format of BEGIN/END below)\n");
2786 fprintf(fp
, " -v, --verbose Enable verbose output\n");
2787 fprintf(fp
, " -h --help Show this help and quit\n");
2789 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2790 fprintf(fp
, "\n\n");
2791 fprintf(fp
, "Suggested format of BEGIN and END\n");
2792 fprintf(fp
, "---------------------------------\n");
2794 fprintf(fp
, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
2795 fprintf(fp
, "\n\n");
2796 fprintf(fp
, "Expected format of PARAMS\n");
2797 fprintf(fp
, "-------------------------\n");
2799 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
2801 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
2802 fprintf(fp
, "where PARAM is the parameter name (C identifier plus [:.-] characters), and\n");
2803 fprintf(fp
, "VALUE can be one of:\n");
2805 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
2806 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
2807 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
2808 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
2809 fprintf(fp
, " (`0x` prefix) signed 64-bit integer.\n");
2810 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
2811 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
2812 fprintf(fp
, " the null and boolean value symbols above.\n");
2813 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
2815 fprintf(fp
, "Whitespaces are allowed around individual `=` and `,` tokens.\n");
2817 fprintf(fp
, "Example:\n");
2819 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
2820 fprintf(fp
, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
2821 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
2823 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run babeltrace\n");
2824 fprintf(fp
, "from a shell.\n");
2827 static struct poptOption convert_long_options
[] = {
2828 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2829 { "base-params", 'b', POPT_ARG_STRING
, NULL
, OPT_BASE_PARAMS
, NULL
, NULL
},
2830 { "begin", '\0', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2831 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2832 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2833 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2834 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2835 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2836 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2837 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2838 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2839 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2840 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2841 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2842 { "end", '\0', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2843 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2844 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2845 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2846 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2847 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2848 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2849 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2850 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_PATH
, NULL
, NULL
},
2851 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2852 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2853 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2854 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2855 { "reset-base-params", 'r', POPT_ARG_NONE
, NULL
, OPT_RESET_BASE_PARAMS
, NULL
, NULL
},
2856 { "sink", '\0', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
2857 { "source", '\0', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
2858 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2859 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2860 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2861 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
2865 * Creates a Babeltrace config object from the arguments of a convert
2868 * *retcode is set to the appropriate exit code to use.
2870 struct bt_config
*bt_config_convert_from_args(int argc
, const char *argv
[],
2871 int *retcode
, bool omit_system_plugin_path
,
2872 bool omit_home_plugin_path
,
2873 struct bt_value
*initial_plugin_paths
)
2875 poptContext pc
= NULL
;
2877 struct ctf_legacy_opts ctf_legacy_opts
;
2878 struct text_legacy_opts text_legacy_opts
;
2879 enum legacy_input_format legacy_input_format
= LEGACY_INPUT_FORMAT_NONE
;
2880 enum legacy_output_format legacy_output_format
=
2881 LEGACY_OUTPUT_FORMAT_NONE
;
2882 struct bt_value
*legacy_input_paths
= NULL
;
2883 struct bt_config_component
*implicit_source_comp
= NULL
;
2884 struct bt_config_component
*cur_cfg_comp
= NULL
;
2885 bool cur_is_implicit_source
= false;
2886 bool use_implicit_source
= false;
2887 enum bt_config_component_dest cur_cfg_comp_dest
=
2888 BT_CONFIG_COMPONENT_DEST_SOURCE
;
2889 struct bt_value
*cur_base_params
= NULL
;
2891 struct bt_config
*cfg
= NULL
;
2894 memset(&ctf_legacy_opts
, 0, sizeof(ctf_legacy_opts
));
2895 memset(&text_legacy_opts
, 0, sizeof(text_legacy_opts
));
2898 print_convert_usage(stdout
);
2903 cfg
= bt_config_convert_create(initial_plugin_paths
);
2909 cfg
->cmd_data
.convert
.omit_system_plugin_path
= omit_system_plugin_path
;
2910 cfg
->cmd_data
.convert
.omit_home_plugin_path
= omit_home_plugin_path
;
2911 text_legacy_opts
.output
= g_string_new(NULL
);
2912 if (!text_legacy_opts
.output
) {
2917 text_legacy_opts
.dbg_info_dir
= g_string_new(NULL
);
2918 if (!text_legacy_opts
.dbg_info_dir
) {
2923 text_legacy_opts
.dbg_info_target_prefix
= g_string_new(NULL
);
2924 if (!text_legacy_opts
.dbg_info_target_prefix
) {
2929 cur_base_params
= bt_value_map_create();
2930 if (!cur_base_params
) {
2935 legacy_input_paths
= bt_value_array_create();
2936 if (!legacy_input_paths
) {
2941 ret
= append_env_var_plugin_paths(cfg
->cmd_data
.convert
.plugin_paths
);
2943 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
2947 /* Note: implicit source never gets positional base params. */
2948 implicit_source_comp
= bt_config_component_from_arg(DEFAULT_SOURCE_COMPONENT_NAME
);
2949 if (!implicit_source_comp
) {
2954 cur_cfg_comp
= implicit_source_comp
;
2955 cur_is_implicit_source
= true;
2956 use_implicit_source
= true;
2959 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2960 convert_long_options
, 0);
2962 printf_err("Cannot get popt context\n");
2966 poptReadDefaultConfig(pc
, 0);
2968 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2969 arg
= poptGetOptArg(pc
);
2972 case OPT_PLUGIN_PATH
:
2973 if (bt_common_is_setuid_setgid()) {
2974 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
2976 if (bt_config_append_plugin_paths(
2977 cfg
->cmd_data
.convert
.plugin_paths
,
2979 printf_err("Invalid --plugin-path option's argument:\n %s\n",
2985 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2986 cfg
->cmd_data
.convert
.omit_system_plugin_path
= true;
2988 case OPT_OMIT_HOME_PLUGIN_PATH
:
2989 cfg
->cmd_data
.convert
.omit_home_plugin_path
= true;
2991 case OPT_OUTPUT_PATH
:
2992 if (text_legacy_opts
.output
->len
> 0) {
2993 printf_err("Duplicate --output option\n");
2997 g_string_assign(text_legacy_opts
.output
, arg
);
2999 case OPT_DEBUG_INFO_DIR
:
3000 if (text_legacy_opts
.dbg_info_dir
->len
> 0) {
3001 printf_err("Duplicate --debug-info-dir option\n");
3005 g_string_assign(text_legacy_opts
.dbg_info_dir
, arg
);
3007 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3008 if (text_legacy_opts
.dbg_info_target_prefix
->len
> 0) {
3009 printf_err("Duplicate --debug-info-target-prefix option\n");
3013 g_string_assign(text_legacy_opts
.dbg_info_target_prefix
, arg
);
3015 case OPT_INPUT_FORMAT
:
3018 if (opt
== OPT_INPUT_FORMAT
) {
3019 if (!strcmp(arg
, "ctf")) {
3020 /* Legacy CTF input format */
3021 if (legacy_input_format
) {
3022 print_err_dup_legacy_input();
3026 legacy_input_format
=
3027 LEGACY_INPUT_FORMAT_CTF
;
3029 } else if (!strcmp(arg
, "lttng-live")) {
3030 /* Legacy LTTng-live input format */
3031 if (legacy_input_format
) {
3032 print_err_dup_legacy_input();
3036 legacy_input_format
=
3037 LEGACY_INPUT_FORMAT_LTTNG_LIVE
;
3042 use_implicit_source
= false;
3044 /* Non-legacy: try to create a component config */
3045 if (cur_cfg_comp
&& !cur_is_implicit_source
) {
3046 add_cfg_comp(cfg
, cur_cfg_comp
,
3050 cur_cfg_comp
= bt_config_component_from_arg(arg
);
3051 if (!cur_cfg_comp
) {
3052 printf_err("Invalid format for --source option's argument:\n %s\n",
3056 cur_is_implicit_source
= false;
3058 assert(cur_base_params
);
3059 bt_put(cur_cfg_comp
->params
);
3060 cur_cfg_comp
->params
= bt_value_copy(cur_base_params
);
3061 if (!cur_cfg_comp
->params
) {
3066 cur_cfg_comp_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
3069 case OPT_OUTPUT_FORMAT
:
3072 if (opt
== OPT_OUTPUT_FORMAT
) {
3073 if (!strcmp(arg
, "text")) {
3074 /* Legacy CTF-text output format */
3075 if (legacy_output_format
) {
3076 print_err_dup_legacy_output();
3080 legacy_output_format
=
3081 LEGACY_OUTPUT_FORMAT_TEXT
;
3083 } else if (!strcmp(arg
, "dummy")) {
3084 /* Legacy dummy output format */
3085 if (legacy_output_format
) {
3086 print_err_dup_legacy_output();
3090 legacy_output_format
=
3091 LEGACY_OUTPUT_FORMAT_DUMMY
;
3093 } else if (!strcmp(arg
, "ctf-metadata")) {
3094 /* Legacy CTF-metadata output format */
3095 if (legacy_output_format
) {
3096 print_err_dup_legacy_output();
3100 legacy_output_format
=
3101 LEGACY_OUTPUT_FORMAT_CTF_METADATA
;
3106 /* Non-legacy: try to create a component config */
3107 if (cur_cfg_comp
&& !cur_is_implicit_source
) {
3108 add_cfg_comp(cfg
, cur_cfg_comp
,
3112 cur_cfg_comp
= bt_config_component_from_arg(arg
);
3113 if (!cur_cfg_comp
) {
3114 printf_err("Invalid format for --sink option's argument:\n %s\n",
3118 cur_is_implicit_source
= false;
3120 assert(cur_base_params
);
3121 bt_put(cur_cfg_comp
->params
);
3122 cur_cfg_comp
->params
= bt_value_copy(cur_base_params
);
3123 if (!cur_cfg_comp
->params
) {
3128 cur_cfg_comp_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
3133 struct bt_value
*params
;
3134 struct bt_value
*params_to_set
;
3136 if (!cur_cfg_comp
) {
3137 printf_err("Cannot add parameters to unavailable default source component `%s`:\n %s\n",
3138 DEFAULT_SOURCE_COMPONENT_NAME
, arg
);
3142 params
= bt_value_from_arg(arg
);
3144 printf_err("Invalid format for --params option's argument:\n %s\n",
3149 params_to_set
= bt_value_map_extend(cur_cfg_comp
->params
,
3152 if (!params_to_set
) {
3153 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
3158 BT_MOVE(cur_cfg_comp
->params
, params_to_set
);
3162 if (!cur_cfg_comp
) {
3163 printf_err("Cannot add `path` parameter to unavailable default source component `%s`:\n %s\n",
3164 DEFAULT_SOURCE_COMPONENT_NAME
, arg
);
3168 assert(cur_cfg_comp
->params
);
3170 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
3176 case OPT_BASE_PARAMS
:
3178 struct bt_value
*params
= bt_value_from_arg(arg
);
3181 printf_err("Invalid format for --base-params option's argument:\n %s\n",
3186 BT_MOVE(cur_base_params
, params
);
3189 case OPT_RESET_BASE_PARAMS
:
3190 BT_PUT(cur_base_params
);
3191 cur_base_params
= bt_value_map_create();
3192 if (!cur_base_params
) {
3198 if (text_legacy_opts
.names
) {
3199 printf_err("Duplicate --names option\n");
3203 text_legacy_opts
.names
= names_from_arg(arg
);
3204 if (!text_legacy_opts
.names
) {
3205 printf_err("Invalid --names option's argument:\n %s\n",
3211 if (text_legacy_opts
.fields
) {
3212 printf_err("Duplicate --fields option\n");
3216 text_legacy_opts
.fields
= fields_from_arg(arg
);
3217 if (!text_legacy_opts
.fields
) {
3218 printf_err("Invalid --fields option's argument:\n %s\n",
3224 text_legacy_opts
.no_delta
= true;
3226 case OPT_CLOCK_CYCLES
:
3227 text_legacy_opts
.clock_cycles
= true;
3229 case OPT_CLOCK_SECONDS
:
3230 text_legacy_opts
.clock_seconds
= true;
3232 case OPT_CLOCK_DATE
:
3233 text_legacy_opts
.clock_date
= true;
3236 text_legacy_opts
.clock_gmt
= true;
3238 case OPT_DEBUG_INFO_FULL_PATH
:
3239 text_legacy_opts
.dbg_info_full_path
= true;
3241 case OPT_CLOCK_OFFSET
:
3245 if (ctf_legacy_opts
.offset_s
.is_set
) {
3246 printf_err("Duplicate --clock-offset option\n");
3250 if (parse_int64(arg
, &val
)) {
3251 printf_err("Invalid --clock-offset option's argument:\n %s\n",
3256 set_offset_value(&ctf_legacy_opts
.offset_s
, val
);
3259 case OPT_CLOCK_OFFSET_NS
:
3263 if (ctf_legacy_opts
.offset_ns
.is_set
) {
3264 printf_err("Duplicate --clock-offset-ns option\n");
3268 if (parse_int64(arg
, &val
)) {
3269 printf_err("Invalid --clock-offset-ns option's argument:\n %s\n",
3274 set_offset_value(&ctf_legacy_opts
.offset_ns
, val
);
3277 case OPT_STREAM_INTERSECTION
:
3278 ctf_legacy_opts
.stream_intersection
= true;
3280 case OPT_CLOCK_FORCE_CORRELATE
:
3281 cfg
->cmd_data
.convert
.force_correlate
= true;
3284 if (!cur_cfg_comp
) {
3285 printf_err("Cannot add `begin` parameter to unavailable default source component `%s`:\n %s\n",
3286 DEFAULT_SOURCE_COMPONENT_NAME
, arg
);
3289 if (cur_cfg_comp_dest
!= BT_CONFIG_COMPONENT_DEST_SOURCE
) {
3290 printf_err("--begin option must follow a --source option:\n %s\n",
3294 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
3301 if (!cur_cfg_comp
) {
3302 printf_err("Cannot add `end` parameter to unavailable default source component `%s`:\n %s\n",
3303 DEFAULT_SOURCE_COMPONENT_NAME
, arg
);
3306 if (cur_cfg_comp_dest
!= BT_CONFIG_COMPONENT_DEST_SOURCE
) {
3307 printf_err("--end option must follow a --source option:\n %s\n",
3311 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
3319 const char *begin
, *end
;
3321 if (!cur_cfg_comp
) {
3322 printf_err("Cannot add `begin` and `end` parameters to unavailable default source component `%s`:\n %s\n",
3323 DEFAULT_SOURCE_COMPONENT_NAME
, arg
);
3326 if (cur_cfg_comp_dest
!= BT_CONFIG_COMPONENT_DEST_SOURCE
) {
3327 printf_err("--timerange option must follow a --source option:\n %s\n",
3331 if (split_timerange(arg
, &begin
, &end
)) {
3332 printf_err("Invalid --timerange format: expecting BEGIN,END or [BEGIN,END]:\n %s\n",
3336 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
3341 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
3349 print_convert_usage(stdout
);
3354 cfg
->verbose
= true;
3360 printf_err("Unknown command-line option specified (option code %d)\n",
3369 /* Check for option parsing error */
3371 printf_err("While parsing command-line options, at option %s: %s\n",
3372 poptBadOption(pc
, 0), poptStrerror(opt
));
3376 /* Consume leftover arguments as legacy input paths */
3378 const char *input_path
= poptGetArg(pc
);
3384 if (bt_value_array_append_string(legacy_input_paths
,
3391 if (append_home_and_system_plugin_paths(
3392 cfg
->cmd_data
.convert
.plugin_paths
,
3393 cfg
->cmd_data
.convert
.omit_system_plugin_path
,
3394 cfg
->cmd_data
.convert
.omit_home_plugin_path
)) {
3395 printf_err("Cannot append home and system plugin paths\n");
3399 /* Append current component configuration, if any */
3400 if (cur_cfg_comp
&& !cur_is_implicit_source
) {
3401 add_cfg_comp(cfg
, cur_cfg_comp
, cur_cfg_comp_dest
);
3403 cur_cfg_comp
= NULL
;
3405 /* Validate legacy/non-legacy options */
3406 if (!validate_cfg(cfg
, &legacy_input_format
, &legacy_output_format
,
3407 legacy_input_paths
, &ctf_legacy_opts
,
3408 &text_legacy_opts
)) {
3409 printf_err("Command-line options form an invalid configuration\n");
3414 * If there's a legacy input format, convert it to source
3415 * component configurations.
3417 if (legacy_input_format
) {
3418 if (append_sources_from_legacy_opts(
3419 cfg
->cmd_data
.convert
.sources
,
3420 legacy_input_format
, &ctf_legacy_opts
,
3421 legacy_input_paths
)) {
3422 printf_err("Cannot convert legacy input format options to source component instance(s)\n");
3425 if (append_sources_from_implicit_params(
3426 cfg
->cmd_data
.convert
.sources
,
3427 implicit_source_comp
)) {
3428 printf_err("Cannot initialize legacy component parameters\n");
3431 use_implicit_source
= false;
3433 if (use_implicit_source
) {
3434 add_cfg_comp(cfg
, implicit_source_comp
,
3435 BT_CONFIG_COMPONENT_DEST_SOURCE
);
3436 implicit_source_comp
= NULL
;
3438 if (implicit_source_comp
3439 && !bt_value_map_is_empty(implicit_source_comp
->params
)) {
3440 printf_err("Arguments specified for implicit source, but an explicit source has been specified, overriding it\n");
3447 * If there's a legacy output format, convert it to sink
3448 * component configurations.
3450 if (legacy_output_format
) {
3451 if (append_sinks_from_legacy_opts(cfg
->cmd_data
.convert
.sinks
,
3452 legacy_output_format
, &text_legacy_opts
)) {
3453 printf_err("Cannot convert legacy output format options to sink component instance(s)\n");
3458 if (cfg
->cmd_data
.convert
.sinks
->len
== 0) {
3459 /* Use implicit sink as default. */
3460 cur_cfg_comp
= bt_config_component_from_arg(DEFAULT_SINK_COMPONENT_NAME
);
3461 if (!cur_cfg_comp
) {
3462 printf_error("Cannot find implicit sink plugin `%s`\n",
3463 DEFAULT_SINK_COMPONENT_NAME
);
3465 add_cfg_comp(cfg
, cur_cfg_comp
,
3466 BT_CONFIG_COMPONENT_DEST_SINK
);
3467 cur_cfg_comp
= NULL
;
3478 poptFreeContext(pc
);
3481 if (text_legacy_opts
.output
) {
3482 g_string_free(text_legacy_opts
.output
, TRUE
);
3485 if (text_legacy_opts
.dbg_info_dir
) {
3486 g_string_free(text_legacy_opts
.dbg_info_dir
, TRUE
);
3489 if (text_legacy_opts
.dbg_info_target_prefix
) {
3490 g_string_free(text_legacy_opts
.dbg_info_target_prefix
, TRUE
);
3494 BT_PUT(implicit_source_comp
);
3495 BT_PUT(cur_cfg_comp
);
3496 BT_PUT(cur_base_params
);
3497 BT_PUT(text_legacy_opts
.names
);
3498 BT_PUT(text_legacy_opts
.fields
);
3499 BT_PUT(legacy_input_paths
);
3504 * Prints the Babeltrace 2.x general usage.
3507 void print_gen_usage(FILE *fp
)
3509 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [COMMAND] [COMMAND OPTIONS]\n");
3511 fprintf(fp
, "General options:\n");
3513 fprintf(fp
, " -d, --debug Enable debug mode\n");
3514 fprintf(fp
, " -h --help Show this help and quit\n");
3515 fprintf(fp
, " --help-legacy Show Babeltrace 1.x legacy help and quit\n");
3516 fprintf(fp
, " -v, --verbose Enable verbose output\n");
3517 fprintf(fp
, " -V, --version Show version and quit\n");
3519 fprintf(fp
, "Available commands:\n");
3521 fprintf(fp
, " convert Build a trace conversion graph and run it (default)\n");
3522 fprintf(fp
, " help Get help for a plugin or a component class\n");
3523 fprintf(fp
, " list-plugins List available plugins and their content\n");
3525 fprintf(fp
, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
3528 struct bt_config
*bt_config_from_args(int argc
, const char *argv
[],
3529 int *retcode
, bool omit_system_plugin_path
,
3530 bool omit_home_plugin_path
,
3531 struct bt_value
*initial_plugin_paths
)
3533 struct bt_config
*config
= NULL
;
3534 bool verbose
= false;
3537 enum bt_config_command command
= -1;
3538 const char **command_argv
= NULL
;
3539 int command_argc
= -1;
3540 const char *command_name
= NULL
;
3545 print_gen_usage(stdout
);
3549 for (i
= 1; i
< argc
; i
++) {
3550 const char *cur_arg
= argv
[i
];
3552 if (strcmp(cur_arg
, "-d") == 0 ||
3553 strcmp(cur_arg
, "--debug") == 0) {
3555 } else if (strcmp(cur_arg
, "-v") == 0 ||
3556 strcmp(cur_arg
, "--verbose") == 0) {
3558 } else if (strcmp(cur_arg
, "-V") == 0 ||
3559 strcmp(cur_arg
, "--version") == 0) {
3562 } else if (strcmp(cur_arg
, "-h") == 0 ||
3563 strcmp(cur_arg
, "--help") == 0) {
3564 print_gen_usage(stdout
);
3566 } else if (strcmp(cur_arg
, "--help-legacy") == 0) {
3567 print_legacy_usage(stdout
);
3570 bool has_command
= true;
3573 * First unknown argument: is it a known command
3576 if (strcmp(cur_arg
, "convert") == 0) {
3577 command
= BT_CONFIG_COMMAND_CONVERT
;
3578 } else if (strcmp(cur_arg
, "list-plugins") == 0) {
3579 command
= BT_CONFIG_COMMAND_LIST_PLUGINS
;
3580 } else if (strcmp(cur_arg
, "help") == 0) {
3581 command
= BT_CONFIG_COMMAND_HELP
;
3584 * Unknown argument, but not a known
3585 * command name: assume the whole
3586 * arguments are for the default convert
3589 command
= BT_CONFIG_COMMAND_CONVERT
;
3590 command_argv
= argv
;
3591 command_argc
= argc
;
3592 has_command
= false;
3596 command_argv
= &argv
[i
];
3597 command_argc
= argc
- i
;
3598 command_name
= cur_arg
;
3604 if ((int) command
< 0) {
3606 * We only got non-help, non-version general options
3607 * like --verbose and --debug, without any other
3608 * arguments, so we can't do anything useful: print the
3611 print_gen_usage(stdout
);
3615 assert(command_argv
);
3616 assert(command_argc
>= 0);
3619 case BT_CONFIG_COMMAND_CONVERT
:
3620 config
= bt_config_convert_from_args(command_argc
, command_argv
,
3621 retcode
, omit_system_plugin_path
,
3622 omit_home_plugin_path
, initial_plugin_paths
);
3624 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
3625 config
= bt_config_list_plugins_from_args(command_argc
,
3626 command_argv
, retcode
, omit_system_plugin_path
,
3627 omit_home_plugin_path
, initial_plugin_paths
);
3629 case BT_CONFIG_COMMAND_HELP
:
3630 config
= bt_config_help_from_args(command_argc
,
3631 command_argv
, retcode
, omit_system_plugin_path
,
3632 omit_home_plugin_path
, initial_plugin_paths
);
3640 config
->verbose
= true;
3644 config
->debug
= true;
3647 config
->command_name
= command_name
;