gdb: remove two uses of obstack
Remove uses of obstack in the code generating the libraries XML for Windows and AIX. Use std::string instead. I'm not able to test this change, unfortunately. Change-Id: I28480913337e3fe8d6c31e551626931e6b1367ef Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
parent
0da4f405f8
commit
d6ac292e5f
4 changed files with 48 additions and 72 deletions
|
@ -1238,44 +1238,41 @@ rs6000_aix_extract_ld_info (struct gdbarch *gdbarch,
|
|||
return info;
|
||||
}
|
||||
|
||||
/* Append to OBJSTACK an XML string description of the shared library
|
||||
/* Append to XML an XML string description of the shared library
|
||||
corresponding to LDI, following the TARGET_OBJECT_LIBRARIES_AIX
|
||||
format. */
|
||||
|
||||
static void
|
||||
rs6000_aix_shared_library_to_xml (struct ld_info *ldi,
|
||||
struct obstack *obstack)
|
||||
rs6000_aix_shared_library_to_xml (struct ld_info *ldi, std::string &xml)
|
||||
{
|
||||
obstack_grow_str (obstack, "<library name=\"");
|
||||
std::string p = xml_escape_text (ldi->filename);
|
||||
obstack_grow_str (obstack, p.c_str ());
|
||||
obstack_grow_str (obstack, "\"");
|
||||
xml += "<library name=\"";
|
||||
xml_escape_text_append (xml, ldi->filename);
|
||||
xml += '"';
|
||||
|
||||
if (ldi->member_name[0] != '\0')
|
||||
{
|
||||
obstack_grow_str (obstack, " member=\"");
|
||||
p = xml_escape_text (ldi->member_name);
|
||||
obstack_grow_str (obstack, p.c_str ());
|
||||
obstack_grow_str (obstack, "\"");
|
||||
xml += " member=\"";
|
||||
xml_escape_text_append (xml, ldi->member_name);
|
||||
xml += '"';
|
||||
}
|
||||
|
||||
obstack_grow_str (obstack, " text_addr=\"");
|
||||
obstack_grow_str (obstack, core_addr_to_string (ldi->textorg));
|
||||
obstack_grow_str (obstack, "\"");
|
||||
xml += " text_addr=\"";
|
||||
xml += core_addr_to_string (ldi->textorg);
|
||||
xml += '"';
|
||||
|
||||
obstack_grow_str (obstack, " text_size=\"");
|
||||
obstack_grow_str (obstack, pulongest (ldi->textsize));
|
||||
obstack_grow_str (obstack, "\"");
|
||||
xml += " text_size=\"";
|
||||
xml += pulongest (ldi->textsize);
|
||||
xml += '"';
|
||||
|
||||
obstack_grow_str (obstack, " data_addr=\"");
|
||||
obstack_grow_str (obstack, core_addr_to_string (ldi->dataorg));
|
||||
obstack_grow_str (obstack, "\"");
|
||||
xml += " data_addr=\"";
|
||||
xml += core_addr_to_string (ldi->dataorg);
|
||||
xml += '"';
|
||||
|
||||
obstack_grow_str (obstack, " data_size=\"");
|
||||
obstack_grow_str (obstack, pulongest (ldi->datasize));
|
||||
obstack_grow_str (obstack, "\"");
|
||||
xml += " data_size=\"";
|
||||
xml += pulongest (ldi->datasize);
|
||||
xml += '"';
|
||||
|
||||
obstack_grow_str (obstack, "></library>");
|
||||
xml += "></library>";
|
||||
}
|
||||
|
||||
/* Convert the ld_info binary data provided by the AIX loader into
|
||||
|
@ -1298,18 +1295,13 @@ rs6000_aix_ld_info_to_xml (struct gdbarch *gdbarch, const gdb_byte *ldi_buf,
|
|||
gdb_byte *readbuf, ULONGEST offset, ULONGEST len,
|
||||
int close_ldinfo_fd)
|
||||
{
|
||||
struct obstack obstack;
|
||||
const char *buf;
|
||||
ULONGEST len_avail;
|
||||
|
||||
obstack_init (&obstack);
|
||||
obstack_grow_str (&obstack, "<library-list-aix version=\"1.0\">\n");
|
||||
std::string xml = "<library-list-aix version=\"1.0\">\n";
|
||||
|
||||
while (1)
|
||||
{
|
||||
struct ld_info ldi = rs6000_aix_extract_ld_info (gdbarch, ldi_buf);
|
||||
|
||||
rs6000_aix_shared_library_to_xml (&ldi, &obstack);
|
||||
rs6000_aix_shared_library_to_xml (&ldi, xml);
|
||||
if (close_ldinfo_fd)
|
||||
close (ldi.fd);
|
||||
|
||||
|
@ -1318,20 +1310,18 @@ rs6000_aix_ld_info_to_xml (struct gdbarch *gdbarch, const gdb_byte *ldi_buf,
|
|||
ldi_buf = ldi_buf + ldi.next;
|
||||
}
|
||||
|
||||
obstack_grow_str0 (&obstack, "</library-list-aix>\n");
|
||||
xml += "</library-list-aix>\n";
|
||||
|
||||
buf = (const char *) obstack_finish (&obstack);
|
||||
len_avail = strlen (buf);
|
||||
ULONGEST len_avail = xml.length ();
|
||||
if (offset >= len_avail)
|
||||
len= 0;
|
||||
else
|
||||
{
|
||||
if (len > len_avail - offset)
|
||||
len = len_avail - offset;
|
||||
memcpy (readbuf, buf + offset, len);
|
||||
memcpy (readbuf, xml.data () + offset, len);
|
||||
}
|
||||
|
||||
obstack_free (&obstack, NULL);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
|
|
@ -2908,30 +2908,25 @@ windows_xfer_shared_libraries (struct target_ops *ops,
|
|||
ULONGEST offset, ULONGEST len,
|
||||
ULONGEST *xfered_len)
|
||||
{
|
||||
auto_obstack obstack;
|
||||
const char *buf;
|
||||
LONGEST len_avail;
|
||||
|
||||
if (writebuf)
|
||||
return TARGET_XFER_E_IO;
|
||||
|
||||
obstack_grow_str (&obstack, "<library-list>\n");
|
||||
std::string xml = "<library-list>\n";
|
||||
for (windows_solib &so : windows_process.solibs)
|
||||
windows_xfer_shared_library (so.name.c_str (),
|
||||
(CORE_ADDR) (uintptr_t) so.load_addr,
|
||||
&so.text_offset,
|
||||
current_inferior ()->arch (), &obstack);
|
||||
obstack_grow_str0 (&obstack, "</library-list>\n");
|
||||
current_inferior ()->arch (), xml);
|
||||
xml += "</library-list>\n";
|
||||
|
||||
buf = (const char *) obstack_finish (&obstack);
|
||||
len_avail = strlen (buf);
|
||||
ULONGEST len_avail = xml.size ();
|
||||
if (offset >= len_avail)
|
||||
len= 0;
|
||||
len = 0;
|
||||
else
|
||||
{
|
||||
if (len > len_avail - offset)
|
||||
len = len_avail - offset;
|
||||
memcpy (readbuf, buf + offset, len);
|
||||
memcpy (readbuf, xml.data () + offset, len);
|
||||
}
|
||||
|
||||
*xfered_len = (ULONGEST) len;
|
||||
|
|
|
@ -527,14 +527,13 @@ display_tib (const char * args, int from_tty)
|
|||
void
|
||||
windows_xfer_shared_library (const char* so_name, CORE_ADDR load_addr,
|
||||
CORE_ADDR *text_offset_cached,
|
||||
struct gdbarch *gdbarch, struct obstack *obstack)
|
||||
struct gdbarch *gdbarch, std::string &xml)
|
||||
{
|
||||
CORE_ADDR text_offset = text_offset_cached ? *text_offset_cached : 0;
|
||||
|
||||
obstack_grow_str (obstack, "<library name=\"");
|
||||
std::string p = xml_escape_text (so_name);
|
||||
obstack_grow_str (obstack, p.c_str ());
|
||||
obstack_grow_str (obstack, "\"><segment address=\"");
|
||||
xml += "<library name=\"";
|
||||
xml_escape_text_append (xml, so_name);
|
||||
xml += "\"><segment address=\"";
|
||||
|
||||
if (!text_offset)
|
||||
{
|
||||
|
@ -547,8 +546,8 @@ windows_xfer_shared_library (const char* so_name, CORE_ADDR load_addr,
|
|||
*text_offset_cached = text_offset;
|
||||
}
|
||||
|
||||
obstack_grow_str (obstack, paddress (gdbarch, load_addr + text_offset));
|
||||
obstack_grow_str (obstack, "\"/></library>");
|
||||
xml += paddress (gdbarch, load_addr + text_offset);
|
||||
xml += "\"/></library>";
|
||||
}
|
||||
|
||||
/* Implement the "iterate_over_objfiles_in_search_order" gdbarch
|
||||
|
@ -1087,7 +1086,7 @@ range [%s, %s]."),
|
|||
struct cpms_data
|
||||
{
|
||||
struct gdbarch *gdbarch;
|
||||
struct obstack *obstack;
|
||||
std::string xml;
|
||||
int module_count;
|
||||
};
|
||||
|
||||
|
@ -1145,37 +1144,30 @@ core_process_module_section (bfd *abfd, asection *sect, void *obj)
|
|||
/* The first module is the .exe itself. */
|
||||
if (data->module_count != 0)
|
||||
windows_xfer_shared_library (module_name, base_addr,
|
||||
NULL, data->gdbarch, data->obstack);
|
||||
NULL, data->gdbarch, data->xml);
|
||||
data->module_count++;
|
||||
}
|
||||
|
||||
ULONGEST
|
||||
windows_core_xfer_shared_libraries (struct gdbarch *gdbarch,
|
||||
gdb_byte *readbuf,
|
||||
ULONGEST offset, ULONGEST len)
|
||||
gdb_byte *readbuf,
|
||||
ULONGEST offset, ULONGEST len)
|
||||
{
|
||||
struct obstack obstack;
|
||||
const char *buf;
|
||||
ULONGEST len_avail;
|
||||
struct cpms_data data = { gdbarch, &obstack, 0 };
|
||||
|
||||
obstack_init (&obstack);
|
||||
obstack_grow_str (&obstack, "<library-list>\n");
|
||||
cpms_data data { gdbarch, "<library-list>\n", 0 };
|
||||
bfd_map_over_sections (core_bfd,
|
||||
core_process_module_section,
|
||||
&data);
|
||||
obstack_grow_str0 (&obstack, "</library-list>\n");
|
||||
data.xml += "</library-list>\n";
|
||||
|
||||
buf = (const char *) obstack_finish (&obstack);
|
||||
len_avail = strlen (buf);
|
||||
ULONGEST len_avail = data.xml.length ();
|
||||
if (offset >= len_avail)
|
||||
return 0;
|
||||
|
||||
if (len > len_avail - offset)
|
||||
len = len_avail - offset;
|
||||
memcpy (readbuf, buf + offset, len);
|
||||
|
||||
obstack_free (&obstack, NULL);
|
||||
memcpy (readbuf, data.xml.data () + offset, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#ifndef WINDOWS_TDEP_H
|
||||
#define WINDOWS_TDEP_H
|
||||
|
||||
struct obstack;
|
||||
struct gdbarch;
|
||||
|
||||
extern struct cmd_list_element *info_w32_cmdlist;
|
||||
|
@ -29,7 +28,7 @@ extern void windows_xfer_shared_library (const char* so_name,
|
|||
CORE_ADDR load_addr,
|
||||
CORE_ADDR *text_offset_cached,
|
||||
struct gdbarch *gdbarch,
|
||||
struct obstack *obstack);
|
||||
std::string &xml);
|
||||
|
||||
extern ULONGEST windows_core_xfer_shared_libraries (struct gdbarch *gdbarch,
|
||||
gdb_byte *readbuf,
|
||||
|
|
Loading…
Add table
Reference in a new issue