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]
Other format: [Raw text]

[RFA] infcmd.c: Fix UI problem in attach_command


Hi,

this is the infcmd.c fix which is necessary to run the to_pid_to_exec_file
functionality in win32-nat.c smoothly.  But I'm not sure if this patch is
the right way to solve the situation.  Sigh, so short a patch, so longish
to explain.

What happens is this:  Usually, when the user attaches to a running
process, the executable (determined by the to_pid_to_exec_file function)
is opened and the symbols are loaded.  Since the executable is the first
file opened, it's symbols are loaded first.

On Cygwin the situation is a bit different.  Attaching to a process
results in a bunch of debug messages from the Windows kernel.  One of
these messages is a LOAD_DLL_DEBUG_EVENT per DLL which is in use by the
attached process.  Each of these messages results in loading the symbol
table of the DLL into GDB.  This happens *before* the call to
to_pid_to_exec_file and so naturally also *before* the symbols from
the executable itself are loaded into GDB.

The result of this change in load order is, that GDB has already the
partial symbol table filled with symbols when it's asked to load the
executable's symbol table.  This in turn changes the UI behaviour.
Instead of just printing "Reading symbols from...", the function
symbol_file_add_with_addrs_or_offsets in symfile.c asks the user
"Load new symbol table from... (y or n)" using the query function.

That wouldn't be an actual problem if there wouldn't be this interesting
behaviour in the attach_command function.  Before trying to load the
executable's symbol table, attach_command calls target_terminal_inferior().
The effect is, that when the above query function is called, GDB is
not the foreground process.  When running under a shell with job control,
something funny happens.  After printing the "Load new..." message, fgetc
is called and at that point, the parent shell (here tcsh) takes over and
prints a message "[1]  +  3784 Suspended (tty input)         gdb"
Entering "fg" works, but it's not exactly helpful, right?

However, now I'm finally at the point where my patch kicks in.  When
attach_command loads the symbol table of the executable, my patch
temporarily returns the terminal to GDB.  After that, it returns terminal
ownership to the inferior process again.

I'm not sure if that's the right way to fix it for two reasons.  The
first is, it might be the same, just to move the original call to
target_terminal_inferior behinf the "if (!exec_file)" expression, this
way avoiding to bounce terminal ownership between GDB and the inferior.
The second reason is, if it might be better to avoid asking the user for
loading the symbol table at all, even on Cygwin.  In that case, I'm not
sure how to do it.

Anyway, below is my patch.


Corinna

	* infcmd.c (attach_command): Return terminal control to GDB
	before loading executable's file symbols.

Index: infcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/infcmd.c,v
retrieving revision 1.117
diff -u -p -r1.117 infcmd.c
--- infcmd.c	20 Jun 2004 18:10:14 -0000	1.117
+++ infcmd.c	26 Jun 2004 08:18:41 -0000
@@ -1829,8 +1829,10 @@ attach_command (char *args, int from_tty
 	  if (!source_full_path_of (exec_file, &full_exec_path))
 	    full_exec_path = savestring (exec_file, strlen (exec_file));
 
+	  target_terminal_ours ();
 	  exec_file_attach (full_exec_path, from_tty);
 	  symbol_file_add_main (full_exec_path, from_tty);
+	  target_terminal_inferior ();
 	}
     }
   else


-- 
Corinna Vinschen
Cygwin Co-Project Leader
Red Hat, Inc.


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