Remove cleanups from find_frame_funname

This changes find_frame_funname to return a unique_xmalloc_ptr and
then fixes up the callers.  This removes several cleanups.

ChangeLog
2017-09-11  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (is_known_support_routine): Update.
	(ada_unhandled_exception_name_addr_from_raise): Update.
	* guile/scm-frame.c (gdbscm_frame_name): Update.
	* python/py-frame.c (frapy_name): Update.
	(frapy_function): Update.
	* stack.h (find_frame_funname): Update.
	* stack.c (find_frame_funname): Return unique_xmalloc_ptr.
	(print_frame): Update.
This commit is contained in:
Tom Tromey 2017-09-09 10:14:52 -06:00
parent d6b9b80f94
commit c6dc63a162
6 changed files with 49 additions and 55 deletions

View file

@ -1,3 +1,14 @@
2017-09-11 Tom Tromey <tom@tromey.com>
* ada-lang.c (is_known_support_routine): Update.
(ada_unhandled_exception_name_addr_from_raise): Update.
* guile/scm-frame.c (gdbscm_frame_name): Update.
* python/py-frame.c (frapy_name): Update.
(frapy_function): Update.
* stack.h (find_frame_funname): Update.
* stack.c (find_frame_funname): Return unique_xmalloc_ptr.
(print_frame): Update.
2017-09-11 Tom Tromey <tom@tromey.com> 2017-09-11 Tom Tromey <tom@tromey.com>
* findcmd.c (put_bits): Take a gdb::byte_vector. * findcmd.c (put_bits): Take a gdb::byte_vector.

View file

@ -11979,7 +11979,6 @@ ada_exception_support_info_sniffer (void)
static int static int
is_known_support_routine (struct frame_info *frame) is_known_support_routine (struct frame_info *frame)
{ {
char *func_name;
enum language func_lang; enum language func_lang;
int i; int i;
const char *fullname; const char *fullname;
@ -12018,21 +12017,18 @@ is_known_support_routine (struct frame_info *frame)
/* Check whether the function is a GNAT-generated entity. */ /* Check whether the function is a GNAT-generated entity. */
find_frame_funname (frame, &func_name, &func_lang, NULL); gdb::unique_xmalloc_ptr<char> func_name
= find_frame_funname (frame, &func_lang, NULL);
if (func_name == NULL) if (func_name == NULL)
return 1; return 1;
for (i = 0; known_auxiliary_function_name_patterns[i] != NULL; i += 1) for (i = 0; known_auxiliary_function_name_patterns[i] != NULL; i += 1)
{ {
re_comp (known_auxiliary_function_name_patterns[i]); re_comp (known_auxiliary_function_name_patterns[i]);
if (re_exec (func_name)) if (re_exec (func_name.get ()))
{ return 1;
xfree (func_name);
return 1;
}
} }
xfree (func_name);
return 0; return 0;
} }
@ -12076,7 +12072,6 @@ ada_unhandled_exception_name_addr_from_raise (void)
int frame_level; int frame_level;
struct frame_info *fi; struct frame_info *fi;
struct ada_inferior_data *data = get_ada_inferior_data (current_inferior ()); struct ada_inferior_data *data = get_ada_inferior_data (current_inferior ());
struct cleanup *old_chain;
/* To determine the name of this exception, we need to select /* To determine the name of this exception, we need to select
the frame corresponding to RAISE_SYM_NAME. This frame is the frame corresponding to RAISE_SYM_NAME. This frame is
@ -12087,24 +12082,20 @@ ada_unhandled_exception_name_addr_from_raise (void)
if (fi != NULL) if (fi != NULL)
fi = get_prev_frame (fi); fi = get_prev_frame (fi);
old_chain = make_cleanup (null_cleanup, NULL);
while (fi != NULL) while (fi != NULL)
{ {
char *func_name;
enum language func_lang; enum language func_lang;
find_frame_funname (fi, &func_name, &func_lang, NULL); gdb::unique_xmalloc_ptr<char> func_name
= find_frame_funname (fi, &func_lang, NULL);
if (func_name != NULL) if (func_name != NULL)
{ {
make_cleanup (xfree, func_name); if (strcmp (func_name.get (),
if (strcmp (func_name,
data->exception_info->catch_exception_sym) == 0) data->exception_info->catch_exception_sym) == 0)
break; /* We found the frame we were looking for... */ break; /* We found the frame we were looking for... */
fi = get_prev_frame (fi); fi = get_prev_frame (fi);
} }
} }
do_cleanups (old_chain);
if (fi == NULL) if (fi == NULL)
return 0; return 0;

View file

@ -418,7 +418,7 @@ static SCM
gdbscm_frame_name (SCM self) gdbscm_frame_name (SCM self)
{ {
frame_smob *f_smob; frame_smob *f_smob;
char *name = NULL; gdb::unique_xmalloc_ptr<char> name;
enum language lang = language_minimal; enum language lang = language_minimal;
struct frame_info *frame = NULL; struct frame_info *frame = NULL;
SCM result; SCM result;
@ -429,11 +429,10 @@ gdbscm_frame_name (SCM self)
{ {
frame = frscm_frame_smob_to_frame (f_smob); frame = frscm_frame_smob_to_frame (f_smob);
if (frame != NULL) if (frame != NULL)
find_frame_funname (frame, &name, &lang, NULL); name = find_frame_funname (frame, &lang, NULL);
} }
CATCH (except, RETURN_MASK_ALL) CATCH (except, RETURN_MASK_ALL)
{ {
xfree (name);
GDBSCM_HANDLE_GDB_EXCEPTION (except); GDBSCM_HANDLE_GDB_EXCEPTION (except);
} }
END_CATCH END_CATCH
@ -445,10 +444,7 @@ gdbscm_frame_name (SCM self)
} }
if (name != NULL) if (name != NULL)
{ result = gdbscm_scm_from_c_string (name.get ());
result = gdbscm_scm_from_c_string (name);
xfree (name);
}
else else
result = SCM_BOOL_F; result = SCM_BOOL_F;

View file

@ -119,7 +119,7 @@ static PyObject *
frapy_name (PyObject *self, PyObject *args) frapy_name (PyObject *self, PyObject *args)
{ {
struct frame_info *frame; struct frame_info *frame;
char *name = NULL; gdb::unique_xmalloc_ptr<char> name;
enum language lang; enum language lang;
PyObject *result; PyObject *result;
@ -127,19 +127,18 @@ frapy_name (PyObject *self, PyObject *args)
{ {
FRAPY_REQUIRE_VALID (self, frame); FRAPY_REQUIRE_VALID (self, frame);
find_frame_funname (frame, &name, &lang, NULL); name = find_frame_funname (frame, &lang, NULL);
} }
CATCH (except, RETURN_MASK_ALL) CATCH (except, RETURN_MASK_ALL)
{ {
xfree (name);
GDB_PY_HANDLE_EXCEPTION (except); GDB_PY_HANDLE_EXCEPTION (except);
} }
END_CATCH END_CATCH
if (name) if (name)
{ {
result = PyUnicode_Decode (name, strlen (name), host_charset (), NULL); result = PyUnicode_Decode (name.get (), strlen (name.get ()),
xfree (name); host_charset (), NULL);
} }
else else
{ {
@ -334,13 +333,12 @@ frapy_function (PyObject *self, PyObject *args)
TRY TRY
{ {
char *funname;
enum language funlang; enum language funlang;
FRAPY_REQUIRE_VALID (self, frame); FRAPY_REQUIRE_VALID (self, frame);
find_frame_funname (frame, &funname, &funlang, &sym); gdb::unique_xmalloc_ptr<char> funname
xfree (funname); = find_frame_funname (frame, &funlang, &sym);
} }
CATCH (except, RETURN_MASK_ALL) CATCH (except, RETURN_MASK_ALL)
{ {

View file

@ -1032,16 +1032,16 @@ get_last_displayed_sal ()
} }
/* Attempt to obtain the FUNNAME, FUNLANG and optionally FUNCP of the function /* Attempt to obtain the name, FUNLANG and optionally FUNCP of the function
corresponding to FRAME. FUNNAME needs to be freed by the caller. */ corresponding to FRAME. */
void gdb::unique_xmalloc_ptr<char>
find_frame_funname (struct frame_info *frame, char **funname, find_frame_funname (struct frame_info *frame, enum language *funlang,
enum language *funlang, struct symbol **funcp) struct symbol **funcp)
{ {
struct symbol *func; struct symbol *func;
gdb::unique_xmalloc_ptr<char> funname;
*funname = NULL;
*funlang = language_unknown; *funlang = language_unknown;
if (funcp) if (funcp)
*funcp = NULL; *funcp = NULL;
@ -1084,7 +1084,7 @@ find_frame_funname (struct frame_info *frame, char **funname,
/* We also don't know anything about the function besides /* We also don't know anything about the function besides
its address and name. */ its address and name. */
func = 0; func = 0;
*funname = xstrdup (MSYMBOL_PRINT_NAME (msymbol.minsym)); funname.reset (xstrdup (MSYMBOL_PRINT_NAME (msymbol.minsym)));
*funlang = MSYMBOL_LANGUAGE (msymbol.minsym); *funlang = MSYMBOL_LANGUAGE (msymbol.minsym);
} }
else else
@ -1104,14 +1104,13 @@ find_frame_funname (struct frame_info *frame, char **funname,
char *func_only = cp_remove_params (print_name); char *func_only = cp_remove_params (print_name);
if (func_only) if (func_only)
*funname = func_only; funname.reset (func_only);
} }
/* If we didn't hit the C++ case above, set *funname here. /* If we didn't hit the C++ case above, set *funname
This approach is taken to avoid having to install a here. */
cleanup in case cp_remove_params can throw. */ if (funname == NULL)
if (*funname == NULL) funname.reset (xstrdup (print_name));
*funname = xstrdup (print_name);
} }
} }
else else
@ -1120,15 +1119,17 @@ find_frame_funname (struct frame_info *frame, char **funname,
CORE_ADDR pc; CORE_ADDR pc;
if (!get_frame_address_in_block_if_available (frame, &pc)) if (!get_frame_address_in_block_if_available (frame, &pc))
return; return funname;
msymbol = lookup_minimal_symbol_by_pc (pc); msymbol = lookup_minimal_symbol_by_pc (pc);
if (msymbol.minsym != NULL) if (msymbol.minsym != NULL)
{ {
*funname = xstrdup (MSYMBOL_PRINT_NAME (msymbol.minsym)); funname.reset (xstrdup (MSYMBOL_PRINT_NAME (msymbol.minsym)));
*funlang = MSYMBOL_LANGUAGE (msymbol.minsym); *funlang = MSYMBOL_LANGUAGE (msymbol.minsym);
} }
} }
return funname;
} }
static void static void
@ -1138,9 +1139,7 @@ print_frame (struct frame_info *frame, int print_level,
{ {
struct gdbarch *gdbarch = get_frame_arch (frame); struct gdbarch *gdbarch = get_frame_arch (frame);
struct ui_out *uiout = current_uiout; struct ui_out *uiout = current_uiout;
char *funname = NULL;
enum language funlang = language_unknown; enum language funlang = language_unknown;
struct cleanup *old_chain;
struct value_print_options opts; struct value_print_options opts;
struct symbol *func; struct symbol *func;
CORE_ADDR pc = 0; CORE_ADDR pc = 0;
@ -1148,9 +1147,8 @@ print_frame (struct frame_info *frame, int print_level,
pc_p = get_frame_pc_if_available (frame, &pc); pc_p = get_frame_pc_if_available (frame, &pc);
gdb::unique_xmalloc_ptr<char> funname
find_frame_funname (frame, &funname, &funlang, &func); = find_frame_funname (frame, &funlang, &func);
old_chain = make_cleanup (xfree, funname);
annotate_frame_begin (print_level ? frame_relative_level (frame) : 0, annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
gdbarch, pc); gdbarch, pc);
@ -1181,7 +1179,7 @@ print_frame (struct frame_info *frame, int print_level,
annotate_frame_function_name (); annotate_frame_function_name ();
string_file stb; string_file stb;
fprintf_symbol_filtered (&stb, funname ? funname : "??", fprintf_symbol_filtered (&stb, funname ? funname.get () : "??",
funlang, DMGL_ANSI); funlang, DMGL_ANSI);
uiout->field_stream ("func", stb); uiout->field_stream ("func", stb);
uiout->wrap_hint (" "); uiout->wrap_hint (" ");
@ -1257,7 +1255,6 @@ print_frame (struct frame_info *frame, int print_level,
} }
uiout->text ("\n"); uiout->text ("\n");
do_cleanups (old_chain);
} }

View file

@ -22,8 +22,9 @@
void select_frame_command (char *level_exp, int from_tty); void select_frame_command (char *level_exp, int from_tty);
void find_frame_funname (struct frame_info *frame, char **funname, gdb::unique_xmalloc_ptr<char> find_frame_funname (struct frame_info *frame,
enum language *funlang, struct symbol **funcp); enum language *funlang,
struct symbol **funcp);
typedef void (*iterate_over_block_arg_local_vars_cb) (const char *print_name, typedef void (*iterate_over_block_arg_local_vars_cb) (const char *print_name,
struct symbol *sym, struct symbol *sym,