From: Tom Tromey Date: Thu, 30 Aug 2018 05:03:09 +0000 (-0600) Subject: Return std::string from gdb_bfd_errmsg X-Git-Tag: users/ARM/embedded-binutils-master-2018q4~777 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=803c08d083556154cd4d27368e58b359e9de8b93;p=platform%2Fupstream%2Fbinutils.git Return std::string from gdb_bfd_errmsg This changes gdb_bfd_errmsg to return a std::string, removing a cleanup. This approach may be slightly less efficient than the previous code, but I don't believe this is very important in this situation. gdb/ChangeLog 2018-09-13 Tom Tromey * utils.h (gdb_bfd_errmsg): Return std::string. * exec.c (exec_file_attach): Update. * compile/compile-object-load.c (compile_object_load): Update. * utils.c (gdb_bfd_errmsg): Return std::string. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 7351e5d..d087871 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2018-09-13 Tom Tromey + * utils.h (gdb_bfd_errmsg): Return std::string. + * exec.c (exec_file_attach): Update. + * compile/compile-object-load.c (compile_object_load): Update. + * utils.c (gdb_bfd_errmsg): Return std::string. + +2018-09-13 Tom Tromey + * procfs.c (struct procinfo_deleter): New. (procinfo_up): New typedef. (do_destroy_procinfo_cleanup): Remove. diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c index 873750b..40053d2 100644 --- a/gdb/compile/compile-object-load.c +++ b/gdb/compile/compile-object-load.c @@ -638,7 +638,8 @@ compile_object_load (const compile_file_names &file_names, if (!bfd_check_format_matches (abfd.get (), bfd_object, &matching)) error (_("\"%s\": not in loadable format: %s"), - filename.get (), gdb_bfd_errmsg (bfd_get_error (), matching)); + filename.get (), + gdb_bfd_errmsg (bfd_get_error (), matching).c_str ()); if ((bfd_get_file_flags (abfd.get ()) & (EXEC_P | DYNAMIC)) != 0) error (_("\"%s\": not in object format."), filename.get ()); diff --git a/gdb/exec.c b/gdb/exec.c index 3023ff7..6e44b0e 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -362,7 +362,7 @@ exec_file_attach (const char *filename, int from_tty) exec_close (); error (_("\"%s\": not in executable format: %s"), scratch_pathname, - gdb_bfd_errmsg (bfd_get_error (), matching)); + gdb_bfd_errmsg (bfd_get_error (), matching).c_str ()); } if (build_section_table (exec_bfd, §ions, §ions_end)) diff --git a/gdb/utils.c b/gdb/utils.c index 7a8c80c..d7980fe 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -2921,39 +2921,26 @@ compare_positive_ints (const void *ap, const void *bp) #define AMBIGUOUS_MESS2 \ ".\nUse \"set gnutarget format-name\" to specify the format." -const char * +std::string gdb_bfd_errmsg (bfd_error_type error_tag, char **matching) { - char *ret, *retp; - int ret_len; char **p; /* Check if errmsg just need simple return. */ if (error_tag != bfd_error_file_ambiguously_recognized || matching == NULL) return bfd_errmsg (error_tag); - ret_len = strlen (bfd_errmsg (error_tag)) + strlen (AMBIGUOUS_MESS1) - + strlen (AMBIGUOUS_MESS2); - for (p = matching; *p; p++) - ret_len += strlen (*p) + 1; - ret = (char *) xmalloc (ret_len + 1); - retp = ret; - make_cleanup (xfree, ret); - - strcpy (retp, bfd_errmsg (error_tag)); - retp += strlen (retp); - - strcpy (retp, AMBIGUOUS_MESS1); - retp += strlen (retp); + std::string ret (bfd_errmsg (error_tag)); + ret += AMBIGUOUS_MESS1; for (p = matching; *p; p++) { - sprintf (retp, " %s", *p); - retp += strlen (retp); + ret += " "; + ret += *p; } - xfree (matching); + ret += AMBIGUOUS_MESS2; - strcpy (retp, AMBIGUOUS_MESS2); + xfree (matching); return ret; } diff --git a/gdb/utils.h b/gdb/utils.h index 6852399..fa9a590 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -115,7 +115,7 @@ compare_cstrings (const char *str1, const char *str2) MATCHING, if non-NULL, is the corresponding argument to bfd_check_format_matches, and will be freed. */ -extern const char *gdb_bfd_errmsg (bfd_error_type error_tag, char **matching); +extern std::string gdb_bfd_errmsg (bfd_error_type error_tag, char **matching); /* Reset the prompt_for_continue clock. */ void reset_prompt_for_continue_wait_time (void);