[6/8] Replace hardwired error handler in go32_create_inferior

Message ID 1407319948-2264-7-git-send-email-gbenson@redhat.com
State Committed
Headers

Commit Message

Gary Benson Aug. 6, 2014, 10:12 a.m. UTC
  go32_create_inferior invokes a hardwired fprintf/exit error handler
if v2loadimage fails.  I could find no reason for this other than that
the block seems to have been copy-and-pasted from v2loadimage's
manpage.  This commit replaces the hardwired handler with a call to
error.

gdb/
2014-08-05  Gary Benson  <gbenson@redhat.com>

	* go32-nat.c (go32_create_inferior): Replace a fprintf/
	exit pair with a call to error.  Wrap the message with _().
---
 gdb/ChangeLog  |    5 +++++
 gdb/go32-nat.c |   12 ++++++------
 2 files changed, 11 insertions(+), 6 deletions(-)
  

Comments

Eli Zaretskii Aug. 6, 2014, 5 p.m. UTC | #1
> From: Gary Benson <gbenson@redhat.com>
> Date: Wed,  6 Aug 2014 11:12:26 +0100
> 
> go32_create_inferior invokes a hardwired fprintf/exit error handler
> if v2loadimage fails.  I could find no reason for this other than that
> the block seems to have been copy-and-pasted from v2loadimage's
> manpage.

AFAIR, it's actually the other way around: the example in the
documentation was copy-pasted from GDB, bit never mind.

> This commit replaces the hardwired handler with a call to error.

Thanks, but...

> -  if (v2loadimage (exec_file, cmdline, start_state))
> -    {
> -      environ = env_save;
> -      printf_unfiltered ("Load failed for image %s\n", exec_file);
> -      exit (1);
> -    }
> +  result = v2loadimage (exec_file, cmdline, start_state);
> +
>    environ = env_save;
>    xfree (cmdline);
>  
> +  if (!result)
> +    error (_("Load failed for image %s", exec_file);

...the last test is inverted: v2loadimage returns zero if it succeeds,
not if it fails (see also the old code).

OK with that change.
  
Gary Benson Aug. 8, 2014, 11:38 a.m. UTC | #2
Eli Zaretskii wrote:
> > From: Gary Benson <gbenson@redhat.com>
> > Date: Wed,  6 Aug 2014 11:12:26 +0100
> > 
> > go32_create_inferior invokes a hardwired fprintf/exit error
> > handler if v2loadimage fails.  I could find no reason for this
> > other than that the block seems to have been copy-and-pasted
> > from v2loadimage's manpage.
> 
> AFAIR, it's actually the other way around: the example in the
> documentation was copy-pasted from GDB, bit never mind.
> 
> > This commit replaces the hardwired handler with a call to error.
> 
> Thanks, but...
> 
> > -  if (v2loadimage (exec_file, cmdline, start_state))
> > -    {
> > -      environ = env_save;
> > -      printf_unfiltered ("Load failed for image %s\n", exec_file);
> > -      exit (1);
> > -    }
> > +  result = v2loadimage (exec_file, cmdline, start_state);
> > +
> >    environ = env_save;
> >    xfree (cmdline);
> >  
> > +  if (!result)
> > +    error (_("Load failed for image %s", exec_file);
> 
> ...the last test is inverted: v2loadimage returns zero if it
> succeeds, not if it fails (see also the old code).
> 
> OK with that change.

Thanks Eli.  I've updated my tree to "if (result != 0) error".
I won't mail an updated patch unless anyone wants one.

Cheers,
Gary
  

Patch

diff --git a/gdb/go32-nat.c b/gdb/go32-nat.c
index b2570e8..eb3cde9 100644
--- a/gdb/go32-nat.c
+++ b/gdb/go32-nat.c
@@ -642,6 +642,7 @@  go32_create_inferior (struct target_ops *ops, char *exec_file,
   char **env_save = environ;
   size_t cmdlen;
   struct inferior *inf;
+  int result;
 
   /* If no exec file handed to us, get it from the exec-file command -- with
      a good, common error message if none is specified.  */
@@ -693,15 +694,14 @@  go32_create_inferior (struct target_ops *ops, char *exec_file,
 
   environ = env;
 
-  if (v2loadimage (exec_file, cmdline, start_state))
-    {
-      environ = env_save;
-      printf_unfiltered ("Load failed for image %s\n", exec_file);
-      exit (1);
-    }
+  result = v2loadimage (exec_file, cmdline, start_state);
+
   environ = env_save;
   xfree (cmdline);
 
+  if (!result)
+    error (_("Load failed for image %s", exec_file);
+
   edi_init (start_state);
 #if __DJGPP_MINOR__ < 3
   save_npx ();