Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] initialize err variable in load_section_callback()
@ 2004-10-19 20:22 Theodore A. Roth
  2004-10-20 17:34 ` Andrew Cagney
  0 siblings, 1 reply; 10+ messages in thread
From: Theodore A. Roth @ 2004-10-19 20:22 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: TEXT/PLAIN, Size: 849 bytes --]

Hi,

I just encountered a problem with using the "load" command with a remote
avr target. The first packet would be sent to the remote target and then
gdb would just give up with this error message:

  (gdb) load
  Loading section .text, size 0x1f8 lma 0x0
  Sending packet: $M0,a:0c9446000c9463000c94#d7...Ack
  Packet received: OK
  Memory access error while loading section .text.

It looks like load_section_callback() in symfile.c is assuming that a
call to target_write_memory_partial() will set the err variable.
Unfortunately, that is not a valid assumption.

The attached patch got things working again, but this feels like a hack
to me since target_write_memory_partial() should really be setting err
to a sane value before returning.

Patch is against today's cvs mainline.

---
Ted Roth
PGP Key ID: 0x18F846E9
Jabber ID: troth@jabber.org

[-- Attachment #2: Type: TEXT/PLAIN, Size: 787 bytes --]

2004-10-19  Theodore A. Roth  <troth@openavr.org>

	* symfile.c (load_section_callback): Initialize err to zero since
	target_write_memory_partial() may not set it in all situations.

Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.143
diff -u -p -p -r1.143 symfile.c
--- symfile.c	1 Oct 2004 10:23:09 -0000	1.143
+++ symfile.c	19 Oct 2004 20:07:58 -0000
@@ -1405,7 +1405,7 @@ load_section_callback (bfd *abfd, asecti
 	  struct cleanup *old_chain;
 	  CORE_ADDR lma = bfd_section_lma (abfd, asec) + args->load_offset;
 	  bfd_size_type block_size;
-	  int err;
+	  int err = 0;
 	  const char *sect_name = bfd_get_section_name (abfd, asec);
 	  bfd_size_type sent;
 

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: [RFA] initialize err variable in load_section_callback()
@ 2004-12-02 14:45 Paul Schlie
  0 siblings, 0 replies; 10+ messages in thread
From: Paul Schlie @ 2004-12-02 14:45 UTC (permalink / raw)
  To: gdb-patches

Might it be possible to "OK" the check in of Theodore Roth's
load_section_callback() bug-fix patch into both 6.3 and head,
that he proposed earlier in October? (as otherwise GDB can't
write/update the memory contents of affected platforms/targets).

 http://sources.redhat.com/ml/gdb-patches/2004-10/msg00324.html

(This is likely the most reliable fix for this problem, as without
properly initializing the err variable introduced in this function,
it's initial value is indeterminate, and otherwise fragilely relies
on subsequent function calls signaling both success and failure,
although traditionally only errors are typically signaled though
this means.)



^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: [RFA] initialize err variable in load_section_callback()
@ 2005-01-04  7:31 Paul Schlie
  2005-01-14 23:29 ` Paul Schlie
  0 siblings, 1 reply; 10+ messages in thread
From: Paul Schlie @ 2005-01-04  7:31 UTC (permalink / raw)
  To: gdb-patches; +Cc: Theodore A. Roth, Andrew Cagney

Might Ted please be given authorization to check his October patch into
both the 6.3 and head branches, as it fixes an uninitialized variable
problem which has already been subsequently independently found with
identical fixes proposed at least a few times since:

 http://sources.redhat.com/ml/gdb-patches/2004-10/msg00324.html

(Although there appeared to be some discussion with Andrew on the subject,
 this fix should be considered the least fragile way to guarantee that
 the err variable declared within this function's scope is initialized,
 as it's likely too fragile to assume that all functions which may signal
 errors, explicitly also signal success [other than via the absents of an
 error, which typically necessitates the utilized shared signaling variable
 be initialized as being error-free]. Where then if there is a desire to
 check/refined all error signaling functions within GDB such that they both
 explicitly signal success and failure, and guarantee that at least one
 such function is always called to initialize otherwise un-initialized error
 variables prior to being tested, this may be done independently of this
 proposed simple less fragile quick fix.)




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2005-03-04 17:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-19 20:22 [RFA] initialize err variable in load_section_callback() Theodore A. Roth
2004-10-20 17:34 ` Andrew Cagney
2004-10-20 18:07   ` Theodore A. Roth
2004-10-26  0:04     ` Andrew Cagney
2004-10-26 18:19       ` Theodore A. Roth
2004-12-28  9:10         ` Theodore A. Roth
2005-03-04 17:51           ` Daniel Jacobowitz
2004-12-02 14:45 Paul Schlie
2005-01-04  7:31 Paul Schlie
2005-01-14 23:29 ` Paul Schlie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox