]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: Allow target description to be dumped even when it is remote
authorAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 9 Jun 2020 18:00:55 +0000 (19:00 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 23 Jun 2020 21:17:18 +0000 (22:17 +0100)
The maintenance command 'maintenance print c-tdesc' can only print the
target description if it was loaded from a local file, or if the local
filename is passed to the maintenance command as an argument.

Sometimes it would be nice to know what target description GDB was
given by the remote, however, if I connect to a remote target and try
this command I see this:

  (gdb) maintenance print c-tdesc
  The current target description did not come from an XML file.
  (gdb)

Which is not very helpful.

This commit changes things so that if the description came from the
remote end then GDB will use a fake filename 'fetched from target' as
the filename for the description, GDB will then create the C
description of the target as though it came from this file.  Example
output would look like this (I snipped the feature creation from the
middle as that hasn't changed):

  (gdb) maintenance print c-tdesc
  /* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
    Original: fetched from target */

  #include "defs.h"
  #include "osabi.h"
  #include "target-descriptions.h"

  struct target_desc *tdesc_fetched_from_target;
  static void
  initialize_tdesc_fetched_from_target (void)
  {
    struct target_desc *result = allocate_target_description ();
    struct tdesc_feature *feature;

    /* ... features created here ... */

    tdesc_fetched_from_target = result;
  }
  (gdb)

In order to support using 'fetched from target' I had to update the
print_c_tdesc code to handle filenames that include a space.  This has
the benefit that we can now print out real files with spaces in the
name, for example the file 'with space.xml':

  (gdb) maint print c-tdesc with space.xml

I originally added this functionality so I could inspect the
description passed to GDB by the remote target.  After using this for
a while I realised that actually having GDB recreate the XML would be
even better, so a later commit will add that functionality too.

Still, given how small this patch is I thought it might be nice to
include this in GDB anyway.

While I was working on this anyway I've added filename command
completion to this command.

gdb/ChangeLog:

* target-descriptions.c (print_c_tdesc::print_c_tdesc): Change
whitespace to underscore.
(maint_print_c_tdesc_cmd): Use fake filename for target
descriptions that came from the target.
(_initialize_target_descriptions): Add filename command completion
for 'maint print c-tdesc'.

gdb/ChangeLog
gdb/target-descriptions.c

index 08e4d310e447b8e14e6159ead4d418d2dd23239e..3e914eb0d92180197c7524033d2223a3d98dde82 100644 (file)
@@ -1,3 +1,12 @@
+2020-06-23  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * target-descriptions.c (print_c_tdesc::print_c_tdesc): Change
+       whitespace to underscore.
+       (maint_print_c_tdesc_cmd): Use fake filename for target
+       descriptions that came from the target.
+       (_initialize_target_descriptions): Add filename command completion
+       for 'maint print c-tdesc'.
+
 2020-06-23  Simon Marchi  <simon.marchi@efficios.com>
 
        * dwarf2/loc.c (decode_debug_loclists_addresses): Add empty
index 20a3a640f4f8f0016ee57415c8c32289ecce1614..da6cb76404c50963a112d84ce74e8b32f88b7dc6 100644 (file)
@@ -1270,6 +1270,8 @@ public:
        break;
       else if (*inp == '-')
        *outp++ = '_';
+      else if (*inp == ' ')
+       *outp++ = '_';
       else
        *outp++ = *inp;
     *outp = '\0';
@@ -1680,7 +1682,7 @@ maint_print_c_tdesc_cmd (const char *args, int from_tty)
     error (_("There is no target description to print."));
 
   if (filename == NULL)
-    error (_("The current target description did not come from an XML file."));
+    filename = "fetched from target";
 
   std::string filename_after_features (filename);
   auto loc = filename_after_features.rfind ("/features/");
@@ -1811,6 +1813,8 @@ void _initialize_target_descriptions ();
 void
 _initialize_target_descriptions ()
 {
+  cmd_list_element *cmd;
+
   tdesc_data = gdbarch_data_register_pre_init (tdesc_data_init);
 
   add_basic_prefix_cmd ("tdesc", class_maintenance, _("\
@@ -1842,11 +1846,10 @@ Unset the file to read for an XML target description.\n\
 When unset, GDB will read the description from the target."),
           &tdesc_unset_cmdlist);
 
-  add_cmd ("c-tdesc", class_maintenance, maint_print_c_tdesc_cmd, _("\
+  cmd = add_cmd ("c-tdesc", class_maintenance, maint_print_c_tdesc_cmd, _("\
 Print the current target description as a C source file."),
           &maintenanceprintlist);
-
-  cmd_list_element *cmd;
+  set_cmd_completer (cmd, filename_completer);
 
   cmd = add_cmd ("xml-descriptions", class_maintenance,
                 maintenance_check_xml_descriptions, _("\