+2018-08-07 Simon Marchi <simon.marchi@ericsson.com>
+
+ * common/filestuff.h (gdb_fopen_cloexec): New overload.
+ (gdb_open_cloexec): Likewise.
+ * nat/linux-osdata.c (command_from_pid): Use string_printf.
+ (commandline_from_pid): Likewise.
+ (linux_xfer_osdata_threads): Likewise.
+ (linux_xfer_osdata_fds): Likewise.
+ * ada-lang.c (is_package_name): Likewise.
+ * auxv.c (procfs_xfer_auxv): Likewise.
+ * breakpoint.c (print_one_breakpoint_location): Use
+ uiout::field_fmt.
+ (print_one_catch_solib): Use string_printf.
+ * coff-pe-read.c (add_pe_exported_sym): Likewise.
+ (add_pe_forwarded_sym): Likewise.
+ * dwarf2read.c (create_type_unit_group): Likewise.
+ (build_error_marker_type): Likewise.
+ * infcall.c (get_function_name): Likewise.
+ * valprint.c (print_converted_chars_to_obstack): Likewise.
+ * xtensa-tdep.c (xtensa_register_type): Likewise.
+
2018-08-06 Simon Marchi <simon.marchi@ericsson.com>
* remote.c (remote_target::download_tracepoint): Fix format
to NAME not existing in our list of symbols. There is only one
small complication with library-level functions (see below). */
- char *fun_name;
-
/* If it is a function that has not been defined at library level,
then we should be able to look it up in the symbols. */
if (standard_lookup (name, NULL, VAR_DOMAIN) != NULL)
if (strstr (name, "__") != NULL)
return 0;
- fun_name = xstrprintf ("_ada_%s", name);
+ std::string fun_name = string_printf ("_ada_%s", name);
- return (standard_lookup (fun_name, NULL, VAR_DOMAIN) == NULL);
+ return (standard_lookup (fun_name.c_str (), NULL, VAR_DOMAIN) == NULL);
}
/* Return nonzero if SYM corresponds to a renaming entity that is
ULONGEST len,
ULONGEST *xfered_len)
{
- char *pathname;
int fd;
ssize_t l;
- pathname = xstrprintf ("/proc/%d/auxv", inferior_ptid.pid ());
+ std::string pathname = string_printf ("/proc/%d/auxv", inferior_ptid.pid ());
fd = gdb_open_cloexec (pathname, writebuf != NULL ? O_WRONLY : O_RDONLY, 0);
- xfree (pathname);
if (fd < 0)
return TARGET_XFER_E_IO;
/* 1 */
annotate_field (0);
if (part_of_multiple)
- {
- char *formatted;
- formatted = xstrprintf ("%d.%d", b->number, loc_number);
- uiout->field_string ("number", formatted);
- xfree (formatted);
- }
+ uiout->field_fmt ("number", "%d.%d", b->number, loc_number);
else
- {
- uiout->field_int ("number", b->number);
- }
+ uiout->field_int ("number", b->number);
/* 2 */
annotate_field (1);
struct solib_catchpoint *self = (struct solib_catchpoint *) b;
struct value_print_options opts;
struct ui_out *uiout = current_uiout;
- char *msg;
get_user_print_options (&opts);
/* Field 4, the address, is omitted (which makes the columns not
uiout->field_skip ("addr");
}
+ std::string msg;
annotate_field (5);
if (self->is_load)
{
if (self->regex)
- msg = xstrprintf (_("load of library matching %s"), self->regex);
+ msg = string_printf (_("load of library matching %s"), self->regex);
else
- msg = xstrdup (_("load of library"));
+ msg = _("load of library");
}
else
{
if (self->regex)
- msg = xstrprintf (_("unload of library matching %s"), self->regex);
+ msg = string_printf (_("unload of library matching %s"), self->regex);
else
- msg = xstrdup (_("unload of library"));
+ msg = _("unload of library");
}
uiout->field_string ("what", msg);
- xfree (msg);
if (uiout->is_mi_like_p ())
uiout->field_string ("catch-type", self->is_load ? "load" : "unload");
const struct read_pe_section_data *section_data,
const char *dll_name, struct objfile *objfile)
{
- char *qualified_name, *bare_name;
/* Add the stored offset to get the loaded address of the symbol. */
CORE_ADDR vma = func_rva + section_data->vma_offset;
of the dll name, e.g. KERNEL32!AddAtomA. This matches the style
used by windbg from the "Microsoft Debugging Tools for Windows". */
+ std::string bare_name;
if (sym_name == NULL || *sym_name == '\0')
- bare_name = xstrprintf ("#%d", ordinal);
+ bare_name = string_printf ("#%d", ordinal);
else
- bare_name = xstrdup (sym_name);
+ bare_name = sym_name;
- qualified_name = xstrprintf ("%s!%s", dll_name, bare_name);
+ std::string qualified_name
+ = string_printf ("%s!%s", dll_name, bare_name.c_str ());
if ((section_data->ms_type == mst_unknown) && debug_coff_pe_read)
fprintf_unfiltered (gdb_stdlog , _("Unknown section type for \"%s\""
section_data->section_name.c_str (), sym_name,
dll_name);
- reader.record_with_info (qualified_name, vma, section_data->ms_type,
+ reader.record_with_info (qualified_name.c_str (), vma, section_data->ms_type,
section_data->index);
/* Enter the plain name as well, which might not be unique. */
- reader.record_with_info (bare_name, vma, section_data->ms_type,
+ reader.record_with_info (bare_name.c_str (), vma, section_data->ms_type,
section_data->index);
if (debug_coff_pe_read > 1)
fprintf_unfiltered (gdb_stdlog, _("Adding exported symbol \"%s\""
" in dll \"%s\"\n"), sym_name, dll_name);
- xfree (qualified_name);
- xfree (bare_name);
}
/* Create a minimal symbol entry for an exported forward symbol.
CORE_ADDR vma, baseaddr;
struct bound_minimal_symbol msymbol;
enum minimal_symbol_type msymtype;
- char *qualified_name, *bare_name;
int forward_dll_name_len = strlen (forward_dll_name);
int forward_func_name_len = strlen (forward_func_name);
int forward_len = forward_dll_name_len + forward_func_name_len + 2;
of the dll name, e.g. KERNEL32!AddAtomA. This matches the style
used by windbg from the "Microsoft Debugging Tools for Windows". */
+ std::string bare_name;
if (sym_name == NULL || *sym_name == '\0')
- bare_name = xstrprintf ("#%d", ordinal);
+ bare_name = string_printf ("#%d", ordinal);
else
- bare_name = xstrdup (sym_name);
+ bare_name = sym_name;
- qualified_name = xstrprintf ("%s!%s", dll_name, bare_name);
+ std::string qualified_name
+ = string_printf ("%s!%s", dll_name, bare_name.c_str ());
/* Note that this code makes a minimal symbol whose value may point
outside of any section in this objfile. These symbols can't
code. */
baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
- reader.record_with_info (qualified_name, vma - baseaddr, msymtype, section);
+ reader.record_with_info (qualified_name.c_str (), vma - baseaddr, msymtype,
+ section);
/* Enter the plain name as well, which might not be unique. */
- reader.record_with_info (bare_name, vma - baseaddr, msymtype, section);
- xfree (qualified_name);
- xfree (bare_name);
+ reader.record_with_info (bare_name.c_str(), vma - baseaddr, msymtype,
+ section);
return 1;
}
extern int gdb_open_cloexec (const char *filename, int flags,
/* mode_t */ unsigned long mode);
+/* Convenience wrapper for the above, which takes the filename as an
+ std::string. */
+
+static inline int
+gdb_open_cloexec (const std::string &filename, int flags,
+ /* mode_t */ unsigned long mode)
+{
+ return gdb_open_cloexec (filename.c_str (), flags, mode);
+}
+
struct gdb_file_deleter
{
void operator() (FILE *file) const
extern gdb_file_up gdb_fopen_cloexec (const char *filename,
const char *opentype);
+/* Convenience wrapper for the above, which takes the filename as an
+ std::string. */
+
+static inline gdb_file_up
+gdb_fopen_cloexec (const std::string &filename, const char *opentype)
+{
+ return gdb_fopen_cloexec (filename.c_str (), opentype);
+}
+
/* Like 'socketpair', but ensures that the returned file descriptors
have the close-on-exec flag set. */
{
unsigned int line_offset = to_underlying (line_offset_struct);
struct partial_symtab *pst;
- char *name;
+ std::string name;
/* Give the symtab a useful name for debug purposes. */
if ((line_offset & NO_STMT_LIST_TYPE_UNIT_PSYMTAB) != 0)
- name = xstrprintf ("<type_units_%d>",
- (line_offset & ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB));
+ name = string_printf ("<type_units_%d>",
+ (line_offset & ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB));
else
- name = xstrprintf ("<type_units_at_0x%x>", line_offset);
+ name = string_printf ("<type_units_at_0x%x>", line_offset);
- pst = create_partial_symtab (per_cu, name);
+ pst = create_partial_symtab (per_cu, name.c_str ());
pst->anonymous = 1;
-
- xfree (name);
}
tu_group->hash.dwo_unit = cu->dwo_unit;
struct dwarf2_per_objfile *dwarf2_per_objfile
= cu->per_cu->dwarf2_per_objfile;
struct objfile *objfile = dwarf2_per_objfile->objfile;
- char *message, *saved;
+ char *saved;
- message = xstrprintf (_("<unknown type in %s, CU %s, DIE %s>"),
- objfile_name (objfile),
- sect_offset_str (cu->header.sect_off),
- sect_offset_str (die->sect_off));
+ std::string message
+ = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
+ objfile_name (objfile),
+ sect_offset_str (cu->header.sect_off),
+ sect_offset_str (die->sect_off));
saved = (char *) obstack_copy0 (&objfile->objfile_obstack,
- message, strlen (message));
- xfree (message);
+ message.c_str (), message.length ());
return init_type (objfile, TYPE_CODE_ERROR, 0, saved);
}
}
{
- char *tmp = xstrprintf (_(RAW_FUNCTION_ADDRESS_FORMAT),
- hex_string (funaddr));
+ std::string tmp = string_printf (_(RAW_FUNCTION_ADDRESS_FORMAT),
+ hex_string (funaddr));
- gdb_assert (strlen (tmp) + 1 <= buf_size);
- strcpy (buf, tmp);
- xfree (tmp);
- return buf;
+ gdb_assert (tmp.length () + 1 <= buf_size);
+ return strcpy (buf, tmp.c_str ());
}
}
static void
command_from_pid (char *command, int maxlen, PID_T pid)
{
- char *stat_path = xstrprintf ("/proc/%lld/stat", pid);
+ std::string stat_path = string_printf ("/proc/%lld/stat", pid);
gdb_file_up fp = gdb_fopen_cloexec (stat_path, "r");
command[0] = '\0';
}
command[maxlen - 1] = '\0'; /* Ensure string is null-terminated. */
-
- xfree (stat_path);
}
/* Returns the command-line of the process with the given PID. The
static char *
commandline_from_pid (PID_T pid)
{
- char *pathname = xstrprintf ("/proc/%lld/cmdline", pid);
+ std::string pathname = xstrprintf ("/proc/%lld/cmdline", pid);
char *commandline = NULL;
gdb_file_up f = gdb_fopen_cloexec (pathname, "r");
}
}
- xfree (pathname);
-
return commandline;
}
&& S_ISDIR (statbuf.st_mode))
{
DIR *dirp2;
- char *pathname;
PID_T pid;
char command[32];
- pathname = xstrprintf ("/proc/%s/task", dp->d_name);
+ std::string pathname
+ = string_printf ("/proc/%s/task", dp->d_name);
pid = atoi (dp->d_name);
command_from_pid (command, sizeof (command), pid);
- dirp2 = opendir (pathname);
+ dirp2 = opendir (pathname.c_str ());
if (dirp2)
{
closedir (dirp2);
}
-
- xfree (pathname);
}
}
if (stat (procentry, &statbuf) == 0
&& S_ISDIR (statbuf.st_mode))
{
- char *pathname;
DIR *dirp2;
PID_T pid;
char command[32];
pid = atoi (dp->d_name);
command_from_pid (command, sizeof (command), pid);
- pathname = xstrprintf ("/proc/%s/fd", dp->d_name);
- dirp2 = opendir (pathname);
+ std::string pathname
+ = string_printf ("/proc/%s/fd", dp->d_name);
+ dirp2 = opendir (pathname.c_str ());
if (dirp2)
{
while ((dp2 = readdir (dirp2)) != NULL)
{
- char *fdname;
char buf[1000];
ssize_t rslt;
if (!isdigit (dp2->d_name[0]))
continue;
- fdname = xstrprintf ("%s/%s", pathname, dp2->d_name);
- rslt = readlink (fdname, buf, sizeof (buf) - 1);
+ std::string fdname
+ = string_printf ("%s/%s", pathname.c_str (),
+ dp2->d_name);
+ rslt = readlink (fdname.c_str (), buf,
+ sizeof (buf) - 1);
if (rslt >= 0)
buf[rslt] = '\0';
closedir (dirp2);
}
-
- xfree (pathname);
}
}
case REPEAT:
{
int j;
- char *s;
/* We are outputting a character with a repeat count
greater than options->repeat_count_threshold. */
print_wchar (gdb_WEOF, elem->buf, elem->buflen, width,
byte_order, obstack, quote_char, &need_escape);
obstack_grow_wstr (obstack, LCST ("'"));
- s = xstrprintf (_(" <repeats %u times>"), elem->repeat_count);
+ std::string s = string_printf (_(" <repeats %u times>"),
+ elem->repeat_count);
for (j = 0; s[j]; ++j)
{
gdb_wchar_t w = gdb_btowc (s[j]);
obstack_grow (obstack, &w, sizeof (gdb_wchar_t));
}
- xfree (s);
}
break;
if (tp == NULL)
{
- char *name = xstrprintf ("int%d", size * 8);
+ std::string name = string_printf ("int%d", size * 8);
tp = XNEW (struct ctype_cache);
tp->next = tdep->type_entries;
tdep->type_entries = tp;
tp->size = size;
tp->virtual_type
- = arch_integer_type (gdbarch, size * 8, 1, name);
- xfree (name);
+ = arch_integer_type (gdbarch, size * 8, 1, name.c_str ());
}
reg->ctype = tp->virtual_type;