This is the mail archive of the gdb-patches@sources.redhat.com 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]

Re: [RFA] Handle win32 debugger file handles


On Mon, Sep 24, 2001 at 12:42:32PM +0200, Pierre Muller wrote:
>The following patch fixed a long stand problem with the win32 version
>of GDB when used as part of an editor.  This is the case for the FP IDE
>(a Free Pascal IDE that integrates GDB for internal debugging).  See
>http://sources.redhat.com/ml/cygwin/2001-08/msg00147.html
>
>That patch is still incomplete, in the sense that this does allow to
>change the executable after running it under the debugger, but we still
>leave open file handles for all used dlls.  The problem here is that
>the corresponding struct object are not freed when the program is
>exited or killed.  As I am unsure how to solve this secondary problem
>(less people use the IDE to debug DLLs) I send this patch with that
>problem pending.
>
>2001-09-22  Pierre Muller  <muller@ics.u-strasbg.fr>
>
>	* win32-nat.c: Handle hFile fields given by WaitForDebugEvent
>             when dwDebugEventCode is either CREATE_PROCESS_DEBUG_EVENT
>             or LOAD_DLL_DEBUG_EVENT.
>             (current_process_file_handle): New static variable.
>             (struct so_stuff): Add new field hFile.
>             (register_loaded_dll): Add new arg: hFile.
>             (handle_load_dll): Adapt to new register_loaded_dll function.
>             (handle_unload_dll): New function.
>             (child_clear_solibs):  Close hFile handles if valid.
>             (child_clear_solib_handles): New function that closes all open handles.
>             (get_child_debug_event): set or close the different file handles.
>	   (core_dll_symbols_add): adapt to modified register_loaded_dll function.

I'm sorry that it has taken me so long to respond to this email.

On analysis, I think you are taking the wrong tactic here.  You are
inventing structures to track open file handles that are never used.
The simple solution to this is to just close the file handles.  I've
done this in win32-nat.c and it seems to work.

I've actually been using a similar technique in another cygwin
application (strace) so I was pretty sure that it was safe to close
these handles.

So, I've checked in a patch to gdb.  Analyzing the open handles with the
utility handleex (from http://www.sysinternals.com/ ), I can see that
the number of open handles stays constant over several runs of an an
inferior process in one gdb session so I think that my changes had the
desired effect.

I do notice, as did you, that gdb keeps a handle to both the file being
debugged and any dlls that have been loaded.  These are apparently
closed and reopened on rerunning of the program but it would be nice if
this wasn't the case.  I'm not sure there is any way around this,
though.

Thanks for bringing this problem to my attention.

cgf


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