XML feature description support.

* NEWS: Mention target descriptions, "set tdesc filename",
	"unset tdesc filename", "show tdesc filename", and
	qXfer:features:read.
	* arch-utils.c (choose_architecture_for_target): New function.
	(gdbarch_info_fill): Call it.
	* target-descriptions.c (struct property): Make members non-const.
	(struct target_desc): Add arch member.
	(target_description_filename): New variable.
	(target_find_description): Try via XML first.
	(tdesc_architecture): New.
	(free_target_description, make_cleanup_free_target_description): New.
	(set_tdesc_property): Call xstrdup.
	(set_tdesc_architecture, tdesc_set_cmdlist, tdesc_show_cmdlist)
	(tdesc_unset_cmdlist, unset_tdesc_cmd, unset_tdesc_filename_cmd)
	(set_tdesc_cmd, show_tdesc_cmd, set_tdesc_filename_cmd)
	(show_tdesc_filename_cmd, _initialize_target_descriptions): New.
	* target-descriptions.h (tdesc_architecture)
	(make_cleanup_free_target_description, set_tdesc_architecture): New
	prototypes.
	* Makefile.in (SFILES): Add xml-tdesc.c.
	(COMMON_OBS): Add xml-tdesc.o.
	(target-descriptions.o): Update.
	(xml-tdesc.o): New rule.
	* xml-tdesc.c, xml-tdesc.h: New files.
	* remote.c (PACKET_qXfer_features): New enum.
	(remote_protocol_features): Add qXfer:features:read.
	(remote_xfer_partial): Handle TARGET_OBJECT_AVAILABLE_FEATURES.
	(_initialize_remote): Register qXfer:features:read.
	* target.h (enum target_object): Add TARGET_OBJECT_AVAILABLE_FEATURES.
	* features/gdb-target.dtd: New file.

	* linux-i386-low.c (the_low_target): Set arch_string.
	* linux-x86-64-low.c (the_low_target): Likewise.
	* linux-low.c (linux_arch_string): New.
	(linux_target_ops): Add it.
	* linux-low.h (struct linux_target_ops): Add arch_string.
	* server.c (write_qxfer_response): Use const void * for DATA.
	(get_features_xml): New.
	(handle_query): Handle qXfer:features:read.  Report it for qSupported.
	* target.h (struct target_ops): Add arch_string method.

	* gdb.texinfo (Target Descriptions): New section.
	(General Query Packets): Add QPassSignals anchor.  Mention
	qXfer:features:read under qSupported.  Expand mentions of
	qXfer:memory-map:read and QPassSignals.  Document
	qXfer:features:read.
This commit is contained in:
Daniel Jacobowitz
2007-01-09 22:55:10 +00:00
parent 3e9cb5f4b2
commit 23181151a2
19 changed files with 850 additions and 13 deletions

View File

@@ -23,9 +23,11 @@
#include "defs.h"
#include "arch-utils.h"
#include "gdbcmd.h"
#include "target.h"
#include "target-descriptions.h"
#include "vec.h"
#include "xml-tdesc.h"
#include "gdb_assert.h"
@@ -33,13 +35,16 @@
typedef struct property
{
const char *key;
const char *value;
char *key;
char *value;
} property_s;
DEF_VEC_O(property_s);
struct target_desc
{
/* The architecture reported by the target, if any. */
const struct bfd_arch_info *arch;
/* Any architecture-specific properties specified by the target. */
VEC(property_s) *properties;
};
@@ -61,6 +66,12 @@ static int target_desc_fetched;
static const struct target_desc *current_target_desc;
/* Other global variables. */
/* The filename to read a target description from. */
static char *target_description_filename;
/* Fetch the current target's description, and switch the current
architecture to one which incorporates that description. */
@@ -79,7 +90,22 @@ target_find_description (void)
disconnected from the previous target. */
gdb_assert (gdbarch_target_desc (current_gdbarch) == NULL);
current_target_desc = target_read_description (&current_target);
/* First try to fetch an XML description from the user-specified
file. */
current_target_desc = NULL;
if (target_description_filename != NULL
&& *target_description_filename != '\0')
current_target_desc
= file_read_description_xml (target_description_filename);
/* Next try to read the description from the current target using
target objects. */
if (current_target_desc == NULL)
current_target_desc = target_read_description_xml (&current_target);
/* If that failed try a target-specific hook. */
if (current_target_desc == NULL)
current_target_desc = target_read_description (&current_target);
/* If a non-NULL description was returned, then update the current
architecture. */
@@ -130,6 +156,9 @@ target_current_description (void)
return NULL;
}
/* Direct accessors for feature sets. */
/* Return the string value of a property named KEY, or NULL if the
property was not specified. */
@@ -148,6 +177,16 @@ tdesc_property (const struct target_desc *target_desc, const char *key)
return NULL;
}
/* Return the BFD architecture associated with this target
description, or NULL if no architecture was specified. */
const struct bfd_arch_info *
tdesc_architecture (const struct target_desc *target_desc)
{
return target_desc->arch;
}
/* Methods for constructing a target description. */
struct target_desc *
@@ -156,6 +195,31 @@ allocate_target_description (void)
return XZALLOC (struct target_desc);
}
static void
free_target_description (void *arg)
{
struct target_desc *target_desc = arg;
struct property *prop;
int ix;
for (ix = 0;
VEC_iterate (property_s, target_desc->properties, ix, prop);
ix++)
{
xfree (prop->key);
xfree (prop->value);
}
VEC_free (property_s, target_desc->properties);
xfree (target_desc);
}
struct cleanup *
make_cleanup_free_target_description (struct target_desc *target_desc)
{
return make_cleanup (free_target_description, target_desc);
}
void
set_tdesc_property (struct target_desc *target_desc,
const char *key, const char *value)
@@ -171,7 +235,102 @@ set_tdesc_property (struct target_desc *target_desc,
internal_error (__FILE__, __LINE__,
_("Attempted to add duplicate property \"%s\""), key);
new_prop.key = key;
new_prop.value = value;
new_prop.key = xstrdup (key);
new_prop.value = xstrdup (value);
VEC_safe_push (property_s, target_desc->properties, &new_prop);
}
void
set_tdesc_architecture (struct target_desc *target_desc,
const struct bfd_arch_info *arch)
{
target_desc->arch = arch;
}
static struct cmd_list_element *tdesc_set_cmdlist, *tdesc_show_cmdlist;
static struct cmd_list_element *tdesc_unset_cmdlist;
/* Helper functions for the CLI commands. */
static void
set_tdesc_cmd (char *args, int from_tty)
{
help_list (tdesc_set_cmdlist, "set tdesc ", -1, gdb_stdout);
}
static void
show_tdesc_cmd (char *args, int from_tty)
{
cmd_show_list (tdesc_show_cmdlist, from_tty, "");
}
static void
unset_tdesc_cmd (char *args, int from_tty)
{
help_list (tdesc_unset_cmdlist, "unset tdesc ", -1, gdb_stdout);
}
static void
set_tdesc_filename_cmd (char *args, int from_tty,
struct cmd_list_element *c)
{
target_clear_description ();
target_find_description ();
}
static void
show_tdesc_filename_cmd (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
const char *value)
{
if (value != NULL && *value != '\0')
printf_filtered (_("\
The target description will be read from \"%s\".\n"),
value);
else
printf_filtered (_("\
The target description will be read from the target.\n"));
}
static void
unset_tdesc_filename_cmd (char *args, int from_tty)
{
xfree (target_description_filename);
target_description_filename = NULL;
target_clear_description ();
target_find_description ();
}
void
_initialize_target_descriptions (void)
{
add_prefix_cmd ("tdesc", class_maintenance, set_tdesc_cmd, _("\
Set target description specific variables."),
&tdesc_set_cmdlist, "set tdesc ",
0 /* allow-unknown */, &setlist);
add_prefix_cmd ("tdesc", class_maintenance, show_tdesc_cmd, _("\
Show target description specific variables."),
&tdesc_show_cmdlist, "show tdesc ",
0 /* allow-unknown */, &showlist);
add_prefix_cmd ("tdesc", class_maintenance, unset_tdesc_cmd, _("\
Unset target description specific variables."),
&tdesc_unset_cmdlist, "unset tdesc ",
0 /* allow-unknown */, &unsetlist);
add_setshow_filename_cmd ("filename", class_obscure,
&target_description_filename,
_("\
Set the file to read for an XML target description"), _("\
Show the file to read for an XML target description"), _("\
When set, GDB will read the target description from a local\n\
file instead of querying the remote target."),
set_tdesc_filename_cmd,
show_tdesc_filename_cmd,
&tdesc_set_cmdlist, &tdesc_show_cmdlist);
add_cmd ("filename", class_obscure, unset_tdesc_filename_cmd, _("\
Unset the file to read for an XML target description. When unset,\n\
GDB will read the description from the target."),
&tdesc_unset_cmdlist);
}