[gdbserver] Automatically add an ".exe" suffix on failure.

Pedro Alves pedro_alves@portugalmail.pt
Sun Aug 12 16:15:00 GMT 2007


Pedro Alves wrote:
> Hi,
> 
> I was running the testsuite against a local gdbserver on Cygwin, and 
> noticed
> that gdbserver as opposed to a native gdb, doesn't append the ".exe" 
> suffix to
> the executable name and retry if creating the inferior process failed.  
> When
> building natively, an .exe suffix is appended to the executable filename if
> there isn't one already.  Most the testcases don't specify it.  This
> results in gdbserver trying to look for an executable called break for 
> instance,
> while there is only a break.exe.  This isn't noticeable when cross testing,
> since (I think) that on that case the suffix isn't appended automatically.
> 
> (Gdb does the retrying in exec.c:exec_file_attach.)
> 
> Tested on a local gdbserver which doesn't look that bad compared to a 
> native
> test run.  Unfortunately the test results aren't 100% consistent across 
> runs,
> on both native and remote, to have a good comparison...
> 
> I had to hack win32-nat.c to be able to test against a local gdbserver 
> on native
> Cygwin, because currently, a Cygwin hosted gdb will isn't able to use 
> the new
> gdbserver dll support.  This happens because a Cygwin hosted gdb will 
> always use
> the current_target_so_ops set in win32-nat.c:init_win32_ops, even when 
> remote
> debugging.
> 
> The patch to use solib-target.c on native Cygwin would fix this too.  
> Daniel,
> I'm going to work on rewriting it to not be so aggressive fetching the 
> list of
> sos from the target, by keeping a list of dlls on win32-nat.c like it is
> currently.  The patch should turn up much smaller and safer.  Maybe it 
> can then
> go into 6.7 (?),  but I wouldn't mind if it didn't either.
> 


Here is an updated patch.
We should only retry with ".exe" if the CreateProcess call fails because the
file doesn't exist.  I then noticed that the setenv call (Cygwin only) between
the create_process call and the error call always sets the last error as
ERROR_FILE_NOT_FOUND, thus masking the real error (eg: ERROR_BAD_EXE_FORMAT)...

     if (!ret && err == ERROR_FILE_NOT_FOUND)
       {
         char *exename = alloca (strlen (program) + 5);
         strcat (strcpy (exename, program), ".exe");
         ret = create_process (exename, args, flags, &pi);
         /* GetLastError() here returns lets say, 193 (ERROR_BAD_EXE_FORMAT)... */
       }

     if (orig_path)
       {
         setenv ("PATH", orig_path, 1);

         /* ... and here GetLastError() here always returns 2
	(ERROR_FILE_NOT_FOUND). */
       }

     if (!ret)
       {
        /* which means we now print a confusing error message. */
         DWORD err = GetLastError ();
         error ("Error creating process \"%s%s\", (error %d): %s\n",
	     program, args, (int) err, strwinerror (err));
       }

Cheers,
Pedro Alves


-------------- next part --------------
A non-text attachment was scrubbed...
Name: gdbserver_exe_suffix.diff
Type: text/x-diff
Size: 4804 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20070812/023693f9/attachment.bin>


More information about the Gdb-patches mailing list