This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] PR python/18565 - make Frame.function work for inline frames


Yao> The reason I suggested that way is that the exception may be thrown
Yao> out in find_frame_funname after the memory is allocated for
Yao> funname, so we need xfree in CATCH, and also need xfree afterwards.

Pedro> I disagree.  In general, I think that up until the called function does a normal
Pedro> return, the memory for output parameters is owned by the called function.
Pedro> A normal return then transfers ownership of the output parameters' memory
Pedro> to the caller.

Pedro> So I think that it's find_frame_funname that should be responsible for making
Pedro> sure that memory for output parameters is cleaned up on exception, or be
Pedro> written in a way that never throws after the memory allocation, which it may be
Pedro> already, but I haven't checked in detail.

I agree with this.

I've just looked into the function and its callers.

Most cases in find_frame_funname clearly set *funname in a spot where an
exception cannot occur.  The one iffy case is:

	  *funname = xstrdup (SYMBOL_PRINT_NAME (func));
[...]
	  if (*funlang == language_cplus)
	    {
	      /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
		 to display the demangled name that we already have
		 stored in the symbol table, but we stored a version
		 with DMGL_PARAMS turned on, and here we don't want to
		 display parameters.  So remove the parameters.  */
	      char *func_only = cp_remove_params (*funname);

I'm not 100% sure that cp_remove_params cannot throw.  However, it's
simple to deal with this by adding a cleanup in find_frame_funname.  I'm
happy to do this if desired.

Another approach might be to have a free_current_contents cleanup at the
start of find_frame_funname and discard it at the exit.  This would
maybe make it a bit safer in the face of future changes.

Alternatively, if we need a try/catch in the caller to possibly free the
function name, then several other callers are incorrect (ada-lang.c and
stack.c).

Tom


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]