This is the mail archive of the gdb-patches@sourceware.org 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] fix symbol-file crash


Hi,

The attached patch fixes a bug which causes a crash clearing the symbol tables.

The problem occurs as follows:

(gdb) add-symbol-file ~/hello
add symbol table from file "/home/afra/users/stubbsa/hello" at
(y or n) y
Reading symbols from /home/afra/users/stubbsa/hello...done.
Using host libthread_db library "/lib/tls/libthread_db.so.1".
(gdb) symbol-file
Segmentation fault

The problem does not occur when the commands are executed from a script.

The cause is symbol-file asking permission to clear the symbol tables using the name of the object file without first checking there is an object file. If symbol-file was used to load the symbols then all is well. If add-symbol-file was used (which seems to work equally well in all other ways) then there is no main object file and it all goes horribly wrong.

Note that this is the second problem mentioned in bug #858 and also in bug #878, which appears to be a duplicate.

I have fixed this by testing the pointer before dereferencing it and using '<unknown>' if there is no object file name. Perhaps there is something more intelligent that could be done here, but this fixes the problem at hand.

I have also added a missing _() to the query string.

Andrew Stubbs
2005-12-01  Andrew Stubbs  <andrew.stubbs@st.com>

	* symfile.c (symbol_file_clear): Test symfile_objfile is not NULL
	before dereferencing it.
	Gettextize the query.

Index: src/gdb/symfile.c
===================================================================
--- src.orig/gdb/symfile.c	2005-12-01 12:05:58.000000000 +0000
+++ src/gdb/symfile.c	2005-12-01 15:21:17.000000000 +0000
@@ -1085,8 +1085,8 @@ symbol_file_clear (int from_tty)
 {
   if ((have_full_symbols () || have_partial_symbols ())
       && from_tty
-      && !query ("Discard symbol table from `%s'? ",
-		 symfile_objfile->name))
+      && !query (_("Discard symbol table from `%s'? "),
+		 symfile_objfile ? symfile_objfile->name : _("<unknown>")))
     error (_("Not confirmed."));
     free_all_objfiles ();
 

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