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]

Patch: Don't crash on re-run (hack)


I've noticed, once again, a longstanding gdb crashing bug.  I've
reported it several times.

I'm running on x86 Red Hat Linux 6.2.  I'm using a trunk gdb checked
out and built last week (really the version doesn't matter, since I've
seen this bug for more than a year, maybe two).

It seems to happen if you put a breakpoint into a shared library and
re-run the inferior.  However, this doesn't really suffice; you must
also do something else.  I did manage to find a way to reproduce the
problem reliably; I've appended it.

Today I looked at it a little bit.  We crash here, in
symbol_add_stub():

      if (strcmp (so->objfile->name, so->so_name) == 0)

What happens is that so->objfile->name == NULL.  The appended hacky
patch lets things work well enough for me.  At least, so far I haven't
run into trouble.

I spent a little trying to find out why so->objfile->name==NULL.
However, I failed (debugging my test case cripples my machine, so it
is a very slow process.  And, I have other stuff I'm supposed to be
doing).  I did discover that an entry like this lurks at the end of
the `object_files' linked list even before I re-run the inferior.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* solib.c (symbol_add_stub): Check that objfile->name is not null
	before using it.

Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.49
diff -u -r1.49 solib.c
--- solib.c 6 Mar 2002 06:28:33 -0000 1.49
+++ solib.c 1 May 2002 19:08:02 -0000
@@ -331,7 +331,7 @@
   /* Have we already loaded this shared object?  */
   ALL_OBJFILES (so->objfile)
     {
-      if (strcmp (so->objfile->name, so->so_name) == 0)
+      if (so->objfile->name && strcmp (so->objfile->name, so->so_name) == 0)
 	return 1;
     }
 


Reproducing the Problem

Compile this Java program with gcj:

import java.io.*;

public class try2
{
  public static void main (String[] args) throws Throwable
  {
    FileInputStream fis = new FileInputStream ("/tmp/data");
    BufferedReader br = new BufferedReader (new InputStreamReader (fis),
					    5);

    String l1 = br.readLine ();
    System.out.println ("got 1 = " + l1);

    br.mark (1);
    char c = (char) br.read();
    System.out.println ("got c = " + c);

    br.reset();
    String l2 = br.readLine ();
    System.out.println ("got 2 = " + l2);
  }
}


Run gdb on this.  Set a breakpoint on the line `br.mark (1)'.
Run the program.

When the breakpoint is hit, type `p l1'.
Then `step' into BufferedReader.mark().
Set a breakpoint in that function (I set it on the first `if'
statement).
`fini'
`next' through the above program until the final println.
`p l2'

Now `r' will crash gdb.


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