aboutsummaryrefslogtreecommitdiff
path: root/gdb/xml-support.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2020-09-14 11:12:55 -0400
committerSimon Marchi <simon.marchi@efficios.com>2020-09-14 11:30:58 -0400
commit8400a90d19c5c53f7100421c688fb896789048b9 (patch)
treedbf3aff829ab551c14a040ac7717e187d7417300 /gdb/xml-support.c
parentb1766e7ce88647c8002928aeb8a9f04048c494ae (diff)
downloadgdb-8400a90d19c5c53f7100421c688fb896789048b9.zip
gdb-8400a90d19c5c53f7100421c688fb896789048b9.tar.gz
gdb-8400a90d19c5c53f7100421c688fb896789048b9.tar.bz2
gdb: change xml_fetch_another a function_view
The xml_fetch_another is currently a plain function pointer type, with a `void *` baton parameter. To improve type-safety, change this to a function_view. Any required data is captured by a lambda at the call site. gdb/ChangeLog: * xml-support.h (xml_fetch_another): Change type to be a function_view. (xml_process_xincludes): Remove baton parameter. (xml_fetch_content_from_file): Change baton parameter to dirname. * xml-support.c (struct xinclude_parsing_data) <xinclude_parsing_data>: Remove baton parameter. <fetcher_baton>: Remove. (xinclude_start_include): Adjust. (xml_process_xincludes): Adjust. (xml_fetch_content_from_file): Replace baton parameter with dirname. * xml-syscall.c (syscall_parse_xml): Remove baton parameter. (xml_init_syscalls_info): Use a lambda. * xml-tdesc.c (tdesc_parse_xml): Remove baton parameter. (file_read_description_xml): Use a lambda. (fetch_available_features_from_target): Change baton parameter to target_ops. (target_read_description_xml): Use a lambda. (target_fetch_description_xml): Use a lambda. (string_read_description_xml): Update. Change-Id: I7ba4b8f5e97fc6a952c6c20ccc3be92a06cc2bd2
Diffstat (limited to 'gdb/xml-support.c')
-rw-r--r--gdb/xml-support.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/gdb/xml-support.c b/gdb/xml-support.c
index c906b69..8b698e5 100644
--- a/gdb/xml-support.c
+++ b/gdb/xml-support.c
@@ -745,13 +745,12 @@ gdb_xml_parse_attr_enum (struct gdb_xml_parser *parser,
struct xinclude_parsing_data
{
xinclude_parsing_data (std::string &output_,
- xml_fetch_another fetcher_, void *fetcher_baton_,
+ xml_fetch_another fetcher_,
int include_depth_)
: output (output_),
skip_depth (0),
include_depth (include_depth_),
- fetcher (fetcher_),
- fetcher_baton (fetcher_baton_)
+ fetcher (fetcher_)
{}
/* Where the output goes. */
@@ -770,7 +769,6 @@ struct xinclude_parsing_data
/* A function to call to obtain additional features, and its
baton. */
xml_fetch_another fetcher;
- void *fetcher_baton;
};
static void
@@ -789,14 +787,12 @@ xinclude_start_include (struct gdb_xml_parser *parser,
gdb_xml_error (parser, _("Maximum XInclude depth (%d) exceeded"),
MAX_XINCLUDE_DEPTH);
- gdb::optional<gdb::char_vector> text
- = data->fetcher (href, data->fetcher_baton);
+ gdb::optional<gdb::char_vector> text = data->fetcher (href);
if (!text)
gdb_xml_error (parser, _("Could not load XML document \"%s\""), href);
if (!xml_process_xincludes (data->output, parser->name (),
text->data (), data->fetcher,
- data->fetcher_baton,
data->include_depth + 1))
gdb_xml_error (parser, _("Parsing \"%s\" failed"), href);
@@ -878,10 +874,9 @@ const struct gdb_xml_element xinclude_elements[] = {
bool
xml_process_xincludes (std::string &result,
const char *name, const char *text,
- xml_fetch_another fetcher, void *fetcher_baton,
- int depth)
+ xml_fetch_another fetcher, int depth)
{
- xinclude_parsing_data data (result, fetcher, fetcher_baton, depth);
+ xinclude_parsing_data data (result, fetcher, depth);
gdb_xml_parser parser (name, xinclude_elements, &data);
parser.set_is_xinclude (true);
@@ -968,12 +963,11 @@ show_debug_xml (struct ui_file *file, int from_tty,
}
gdb::optional<gdb::char_vector>
-xml_fetch_content_from_file (const char *filename, void *baton)
+xml_fetch_content_from_file (const char *filename, const char *dirname)
{
- const char *dirname = (const char *) baton;
gdb_file_up file;
- if (dirname && *dirname)
+ if (dirname != nullptr && *dirname != '\0')
{
char *fullname = concat (dirname, "/", filename, (char *) NULL);