* [patch] check return value of do_write in sim_load_file()
@ 2010-02-04 7:07 Mike Frysinger
2010-02-04 21:58 ` Doug Evans
0 siblings, 1 reply; 3+ messages in thread
From: Mike Frysinger @ 2010-02-04 7:07 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: Text/Plain, Size: 979 bytes --]
if the do_write function (which is the real meat of sim_load_file()) fails,
nothing is displayed in the load output to indicate a problem. so check the
return value before declaring everything peachy.
2010-02-04 Mike Frysinger <vapier@gentoo.org>
* sim-load.c (sim_load_file): Check do_write() return value.
RCS file: /cvs/src/src/sim/common/sim-load.c,v
retrieving revision 1.14
diff -u -p -r1.14 sim-load.c
--- sim/common/sim-load.c 1 Jan 2010 10:03:27 -0000 1.14
+++ sim/common/sim-load.c 4 Feb 2010 07:02:42 -0000
@@ -140,8 +140,10 @@ sim_load_file (sd, myname, callback, pro
}
data_count += size;
bfd_get_section_contents (result_bfd, s, buffer, 0, size);
- do_write (sd, lma, buffer, size);
- found_loadable_section = 1;
+ if (do_write (sd, lma, buffer, size) != size)
+ eprintf (callback, "\tloading section failed\n");
+ else
+ found_loadable_section = 1;
free (buffer);
}
}
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch] check return value of do_write in sim_load_file()
2010-02-04 7:07 [patch] check return value of do_write in sim_load_file() Mike Frysinger
@ 2010-02-04 21:58 ` Doug Evans
2010-02-05 0:18 ` Mike Frysinger
0 siblings, 1 reply; 3+ messages in thread
From: Doug Evans @ 2010-02-04 21:58 UTC (permalink / raw)
To: Mike Frysinger; +Cc: gdb-patches
On Wed, Feb 3, 2010 at 11:07 PM, Mike Frysinger <vapier@gentoo.org> wrote:
> if the do_write function (which is the real meat of sim_load_file()) fails,
> nothing is displayed in the load output to indicate a problem. so check the
> return value before declaring everything peachy.
>
> 2010-02-04 Mike Frysinger <vapier@gentoo.org>
>
> * sim-load.c (sim_load_file): Check do_write() return value.
>
> RCS file: /cvs/src/src/sim/common/sim-load.c,v
> retrieving revision 1.14
> diff -u -p -r1.14 sim-load.c
> --- sim/common/sim-load.c 1 Jan 2010 10:03:27 -0000 1.14
> +++ sim/common/sim-load.c 4 Feb 2010 07:02:42 -0000
> @@ -140,8 +140,10 @@ sim_load_file (sd, myname, callback, pro
> }
> data_count += size;
> bfd_get_section_contents (result_bfd, s, buffer, 0, size);
> - do_write (sd, lma, buffer, size);
> - found_loadable_section = 1;
> + if (do_write (sd, lma, buffer, size) != size)
> + eprintf (callback, "\tloading section failed\n");
> + else
> + found_loadable_section = 1;
> free (buffer);
> }
> }
>
If there's an error loading a section I think it would be better to
fail the entire call. How about something like
if (do_write (sd, lma, buffer, size) != size)
{
eprintf (callback, "%s: error loading section %s\n",
myname, bfd_get_section_name (result_bfd, s));
/* Only close if we opened it. */
if (prog_bfd == NULL)
bfd_close (result_bfd);
free (buffer);
return NULL;
}
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [patch] check return value of do_write in sim_load_file()
2010-02-04 21:58 ` Doug Evans
@ 2010-02-05 0:18 ` Mike Frysinger
0 siblings, 0 replies; 3+ messages in thread
From: Mike Frysinger @ 2010-02-05 0:18 UTC (permalink / raw)
To: Doug Evans; +Cc: gdb-patches
[-- Attachment #1: Type: Text/Plain, Size: 1820 bytes --]
On Thursday 04 February 2010 16:58:18 Doug Evans wrote:
> On Wed, Feb 3, 2010 at 11:07 PM, Mike Frysinger <vapier@gentoo.org> wrote:
> > if the do_write function (which is the real meat of sim_load_file())
> > fails, nothing is displayed in the load output to indicate a problem. so
> > check the return value before declaring everything peachy.
> >
> > 2010-02-04 Mike Frysinger <vapier@gentoo.org>
> >
> > * sim-load.c (sim_load_file): Check do_write() return value.
> >
> > RCS file: /cvs/src/src/sim/common/sim-load.c,v
> > retrieving revision 1.14
> > diff -u -p -r1.14 sim-load.c
> > --- sim/common/sim-load.c 1 Jan 2010 10:03:27 -0000 1.14
> > +++ sim/common/sim-load.c 4 Feb 2010 07:02:42 -0000
> > @@ -140,8 +140,10 @@ sim_load_file (sd, myname, callback, pro
> > }
> > data_count += size;
> > bfd_get_section_contents (result_bfd, s, buffer, 0, size);
> > - do_write (sd, lma, buffer, size);
> > - found_loadable_section = 1;
> > + if (do_write (sd, lma, buffer, size) != size)
> > + eprintf (callback, "\tloading section failed\n");
> > + else
> > + found_loadable_section = 1;
> > free (buffer);
> > }
> > }
>
> If there's an error loading a section I think it would be better to
> fail the entire call. How about something like
>
> if (do_write (sd, lma, buffer, size) != size)
> {
> eprintf (callback, "%s: error loading section %s\n",
> myname, bfd_get_section_name (result_bfd, s));
> /* Only close if we opened it. */
> if (prog_bfd == NULL)
> bfd_close (result_bfd);
> free (buffer);
> return NULL;
> }
that works for me too
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-02-05 0:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-04 7:07 [patch] check return value of do_write in sim_load_file() Mike Frysinger
2010-02-04 21:58 ` Doug Evans
2010-02-05 0:18 ` Mike Frysinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox