aboutsummaryrefslogtreecommitdiff
path: root/gdb/target-descriptions.c
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2020-10-11 19:26:59 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2020-11-12 09:44:00 +0000
commitab33b15255460ac45a001c8ebf69ef73f6f1fba4 (patch)
treedba8d576f56297fe9a2c35ccedf7bf77c390bc35 /gdb/target-descriptions.c
parentb8b0c108c75bd957660b9cada31378d95de4ec5a (diff)
downloadgdb-ab33b15255460ac45a001c8ebf69ef73f6f1fba4.zip
gdb-ab33b15255460ac45a001c8ebf69ef73f6f1fba4.tar.gz
gdb-ab33b15255460ac45a001c8ebf69ef73f6f1fba4.tar.bz2
gdb: add an option flag to 'maint print c-tdesc'
GDB has two approaches to generating the target descriptions found in gdb/features/, the whole description approach, where the XML file contains a complete target description which is then used to generate a single C file that builds that target description. Or, the split feature approach, where the XML files contain a single target feature, each feature results in a single C file to create that one feature, and then a manually written C file is used to build a complete target description from individual features. There's a Makefile, gdb/features/Makefile, which is responsible for managing the regeneration of the C files from the XML files. However, some of the logic that selects between the whole description approach, or the split feature approach, is actually hard-coded into GDB, inside target-descriptions.c:maint_print_c_tdesc_cmd we check the path to the incoming XML file and use this to choose which type of C file we should generate. This commit removes this hard coding from GDB, and makes the Makefile entirely responsible for choosing the approach. This makes sense as the Makefile already has the XML files partitioned based on which approach they should use. In order to allow this change the 'maint print c-tdesc' command is given a new command option '-single-feature', which tells GDB which type of C file should be created. The makefile now supplies this flag to GDB. This did reveal a bug in features/Makefile, the rx.xml file was in the wrong list, this didn't matter previously as the actual choice of which approach to use was done in GDB. Now the Makefile decides, so placing each XML file in the correct list is critical. Tested this by doing 'make GDB=/path/to/gdb clean-cfiles cfiles' to regenerate all the C files from their XML source. There are no changes after this commit. gdb/ChangeLog: * features/Makefile (XMLTOC): Add rx.xml. (FEATURE_XMLFILES): Remove rx.xml. (FEATURE_CFILES rule): Pass '-single-feature' flag. * features/rx.c: Regenerate. * features/rx.xml: Wrap in `target` tags, and reindent. * target-descriptions.c (struct maint_print_c_tdesc_options): New structure. (maint_print_c_tdesc_opt_def): New typedef. (maint_print_c_tdesc_opt_defs): New static global. (make_maint_print_c_tdesc_options_def_group): New function. (maint_print_c_tdesc_cmd): Make use of command line flags, only print single feature C file for target descriptions containing a single feature. (maint_print_c_tdesc_cmd_completer): New function. (_initialize_target_descriptions): Update call to register command completer, and include command line flag in help text. gdb/doc/ChangeLog: * gdb.texinfo (Maintenance Commands): Update description of 'maint print c-tdesc'.
Diffstat (limited to 'gdb/target-descriptions.c')
-rw-r--r--gdb/target-descriptions.c85
1 files changed, 73 insertions, 12 deletions
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 6d0905b..d21f6fd 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -1731,12 +1731,45 @@ tdesc_get_features_xml (const target_desc *tdesc)
return tdesc->xmltarget;
}
+/* Data structures and functions to setup the option flags for 'maintenance
+ print c-tdesc command. */
+
+struct maint_print_c_tdesc_options
+{
+ /* True when the '-single-feature' flag was passed. */
+ bool single_feature = false;
+};
+
+using maint_print_c_tdesc_opt_def
+ = gdb::option::flag_option_def<maint_print_c_tdesc_options>;
+
+static const gdb::option::option_def maint_print_c_tdesc_opt_defs[] = {
+ maint_print_c_tdesc_opt_def {
+ "single-feature",
+ [] (maint_print_c_tdesc_options *opt) { return &opt->single_feature; },
+ N_("Print C description of just a single feature.")
+ },
+};
+
+static inline gdb::option::option_def_group
+make_maint_print_c_tdesc_options_def_group (maint_print_c_tdesc_options *opts)
+{
+ return {{maint_print_c_tdesc_opt_defs}, opts};
+}
+
+/* Implement 'maintenance print c-tdesc' command. */
+
static void
maint_print_c_tdesc_cmd (const char *args, int from_tty)
{
const struct target_desc *tdesc;
const char *filename;
+ maint_print_c_tdesc_options opts;
+ auto grp = make_maint_print_c_tdesc_options_def_group (&opts);
+ gdb::option::process_options
+ (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp);
+
if (args == NULL)
{
/* Use the global target-supplied description, not the current
@@ -1768,15 +1801,12 @@ maint_print_c_tdesc_cmd (const char *args, int from_tty)
/* Print c files for target features instead of target descriptions,
because c files got from target features are more flexible than the
counterparts. */
- if (startswith (filename_after_features.c_str (), "i386/32bit-")
- || startswith (filename_after_features.c_str (), "i386/64bit-")
- || startswith (filename_after_features.c_str (), "i386/x32-core.xml")
- || startswith (filename_after_features.c_str (), "riscv/")
- || startswith (filename_after_features.c_str (), "tic6x-")
- || startswith (filename_after_features.c_str (), "aarch64")
- || startswith (filename_after_features.c_str (), "arm/")
- || startswith (filename_after_features.c_str (), "arc/"))
+ if (opts.single_feature)
{
+ if (tdesc->features.size () != 1)
+ error (_("only target descriptions with 1 feature can be used "
+ "with -single-feature option"));
+
print_c_feature v (filename_after_features);
tdesc->accept (v);
@@ -1789,6 +1819,22 @@ maint_print_c_tdesc_cmd (const char *args, int from_tty)
}
}
+/* Completer for the "backtrace" command. */
+
+static void
+maint_print_c_tdesc_cmd_completer (struct cmd_list_element *ignore,
+ completion_tracker &tracker,
+ const char *text, const char *word)
+{
+ auto grp = make_maint_print_c_tdesc_options_def_group (nullptr);
+ if (gdb::option::complete_options
+ (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp))
+ return;
+
+ word = advance_to_filename_complete_word_point (tracker, text);
+ filename_completer (ignore, tracker, text, word);
+}
+
/* Implement the maintenance print xml-tdesc command. */
static void
@@ -1951,10 +1997,25 @@ Unset the file to read for an XML target description.\n\
When unset, GDB will read the description from the target."),
&tdesc_unset_cmdlist);
- cmd = add_cmd ("c-tdesc", class_maintenance, maint_print_c_tdesc_cmd, _("\
-Print the current target description as a C source file."),
- &maintenanceprintlist);
- set_cmd_completer (cmd, filename_completer);
+ auto grp = make_maint_print_c_tdesc_options_def_group (nullptr);
+ static std::string help_text
+ = gdb::option::build_help (_("\
+Print the current target description as a C source file.\n\
+Usage: maintenance print c-tdesc [OPTION] [FILENAME]\n\
+\n\
+Options:\n\
+%OPTIONS%\n\
+\n\
+When FILENAME is not provided then print the current target\n\
+description, otherwise an XML target description is read from\n\
+FILENAME and printed as a C function.\n\
+\n\
+When '-single-feature' is used then the target description should\n\
+contain a single feature and the generated C code will only create\n\
+that feature within an already existing target_desc object."), grp);
+ cmd = add_cmd ("c-tdesc", class_maintenance, maint_print_c_tdesc_cmd,
+ help_text.c_str (), &maintenanceprintlist);
+ set_cmd_completer_handle_brkchars (cmd, maint_print_c_tdesc_cmd_completer);
cmd = add_cmd ("xml-tdesc", class_maintenance, maint_print_xml_tdesc_cmd, _("\
Print the current target description as an XML file."),