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]

[commit] fix gdb/1846 - include script line/file in error message


Catching the error, adding a file/line and rethrowing it fixes the problem.

committed,
Andrew

PS: This affords much cleanup, will follow up
2005-01-16  Andrew Cagney  <cagney@gnu.org>

	* cli/cli-script.c: Include "exceptions.h".
	(struct wrapped_read_command_file_args): Define.
	(wrapped_read_command_file): New function.
	(script_from_file): Replace direct call to read_command_file by
	one wrapped by an exception handler.
	* exceptions.c (throw_it): Free the old message after creating the
	new.
	* Makefile.in: Update dependencies.
	
Index: testsuite/ChangeLog
2005-01-16  Andrew Cagney  <cagney@gnu.org>

	* gdb.base/source.exp: Delete KFAIL gdb/1846, simplify.

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.690
diff -p -u -r1.690 Makefile.in
--- Makefile.in	16 Jan 2005 20:29:10 -0000	1.690
+++ Makefile.in	16 Jan 2005 21:17:34 -0000
@@ -2066,7 +2066,8 @@ i387-tdep.o: i387-tdep.c $(defs_h) $(dou
 	$(gdbcore_h) $(inferior_h) $(language_h) $(regcache_h) $(value_h) \
 	$(gdb_assert_h) $(gdb_string_h) $(i386_tdep_h) $(i387_tdep_h)
 ia64-linux-nat.o: ia64-linux-nat.c $(defs_h) $(gdb_string_h) $(inferior_h) \
-	$(target_h) $(gdbcore_h) $(regcache_h) $(gdb_wait_h) $(gregset_h)
+	$(target_h) $(gdbcore_h) $(regcache_h) $(ia64_tdep_h) $(gdb_wait_h) \
+	$(gregset_h)
 ia64-linux-tdep.o: ia64-linux-tdep.c $(defs_h) $(ia64_tdep_h) \
 	$(arch_utils_h) $(gdbcore_h) $(regcache_h) $(osabi_h)
 ia64-tdep.o: ia64-tdep.c $(defs_h) $(inferior_h) $(gdbcore_h) \
@@ -2140,7 +2141,7 @@ libunwind-frame.o: libunwind-frame.c $(d
 linespec.o: linespec.c $(defs_h) $(symtab_h) $(frame_h) $(command_h) \
 	$(symfile_h) $(objfiles_h) $(source_h) $(demangle_h) $(value_h) \
 	$(completer_h) $(cp_abi_h) $(parser_defs_h) $(block_h) \
-	$(objc_lang_h) $(linespec_h)
+	$(objc_lang_h) $(linespec_h) $(exceptions_h)
 linux-nat.o: linux-nat.c $(defs_h) $(inferior_h) $(target_h) $(gdb_string_h) \
 	$(gdb_wait_h) $(gdb_assert_h) $(linux_nat_h) $(gdbthread_h) \
 	$(gdbcmd_h) $(regcache_h) $(elf_bfd_h) $(gregset_h) $(gdbcore_h) \
@@ -2532,8 +2533,8 @@ source.o: source.c $(defs_h) $(symtab_h)
 	$(gdb_string_h) $(gdb_stat_h) $(gdbcore_h) $(gdb_regex_h) \
 	$(symfile_h) $(objfiles_h) $(annotate_h) $(gdbtypes_h) $(linespec_h) \
 	$(filenames_h) $(completer_h) $(ui_out_h) $(readline_h)
-sparc64fbsd-nat.o: sparc64fbsd-nat.c $(defs_h) $(target_h) \
-	$(fbsd_nat_h) $(sparc64_tdep_h) $(sparc_nat_h)
+sparc64fbsd-nat.o: sparc64fbsd-nat.c $(defs_h) $(target_h) $(fbsd_nat_h) \
+	$(sparc64_tdep_h) $(sparc_nat_h)
 sparc64fbsd-tdep.o: sparc64fbsd-tdep.c $(defs_h) $(frame_h) \
 	$(frame_unwind_h) $(gdbcore_h) $(osabi_h) $(regcache_h) $(regset_h) \
 	$(target_h) $(trad_frame_h) $(gdb_assert_h) $(gdb_string_h) \
@@ -2748,8 +2749,8 @@ cli-logging.o: $(srcdir)/cli/cli-logging
 	$(gdb_string_h)
 	$(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/cli/cli-logging.c
 cli-script.o: $(srcdir)/cli/cli-script.c $(defs_h) $(value_h) $(language_h) \
-	$(ui_out_h) $(gdb_string_h) $(top_h) $(cli_cmds_h) $(cli_decode_h) \
-	$(cli_script_h)
+	$(ui_out_h) $(gdb_string_h) $(exceptions_h) $(top_h) $(cli_cmds_h) \
+	$(cli_decode_h) $(cli_script_h)
 	$(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/cli/cli-script.c
 cli-setshow.o: $(srcdir)/cli/cli-setshow.c $(defs_h) $(readline_tilde_h) \
 	$(value_h) $(gdb_string_h) $(ui_out_h) $(cli_decode_h) $(cli_cmds_h) \
Index: exceptions.c
===================================================================
RCS file: /cvs/src/src/gdb/exceptions.c,v
retrieving revision 1.14
diff -p -u -r1.14 exceptions.c
--- exceptions.c	16 Jan 2005 19:51:51 -0000	1.14
+++ exceptions.c	16 Jan 2005 21:17:34 -0000
@@ -360,10 +360,13 @@ throw_it (enum return_reason reason, enu
 	  va_list ap)
 {
   struct exception e;
+  char *new_message;
 
-  /* Save the message.  */
+  /* Save the message.  Create the new message before deleting the
+     old, the new message may include the old message text.  */
+  new_message = xstrvprintf (fmt, ap);
   xfree (last_message);
-  last_message = xstrvprintf (fmt, ap);
+  last_message = new_message;
 
   /* Create the exception.  */
   e.reason = reason;
Index: cli/cli-script.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-script.c,v
retrieving revision 1.24
diff -p -u -r1.24 cli-script.c
--- cli/cli-script.c	10 Sep 2004 23:12:11 -0000	1.24
+++ cli/cli-script.c	16 Jan 2005 21:17:34 -0000
@@ -1,8 +1,8 @@
 /* GDB CLI command scripting.
 
    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
-   1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004 Free Software
-   Foundation, Inc.
+   1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005 Free
+   Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -28,7 +28,7 @@
 
 #include "ui-out.h"
 #include "gdb_string.h"
-
+#include "exceptions.h"
 #include "top.h"
 #include "cli/cli-cmds.h"
 #include "cli/cli-decode.h"
@@ -1251,6 +1251,18 @@ do_fclose_cleanup (void *stream)
   fclose (stream);
 }
 
+struct wrapped_read_command_file_args
+{
+  FILE *stream;
+};
+
+static void
+wrapped_read_command_file (struct ui_out *uiout, void *data)
+{
+  struct wrapped_read_command_file_args *args = data;
+  read_command_file (args->stream);
+}
+
 /* Used to implement source_command */
 
 void
@@ -1293,7 +1305,27 @@ script_from_file (FILE *stream, char *fi
 	source_error = xrealloc (source_error, source_error_allocated);
     }
 
-  read_command_file (stream);
+  {
+    struct exception e;
+    struct wrapped_read_command_file_args args;
+    args.stream = stream;
+    e = catch_exception (uiout, wrapped_read_command_file, &args,
+			 RETURN_MASK_ERROR);
+    switch (e.reason)
+      {
+      case 0:
+	break;
+      case RETURN_ERROR:
+	/* Re-throw the error, but with the file name information
+	   prepended.  */
+	throw_error (e.error, "%s%s:%d: Error in sourced command file:\n%s",
+		     source_pre_error, source_file_name,
+		     source_line_number,
+		     e.message);
+      default:
+	internal_error (__FILE__, __LINE__, "bad reason");
+      }
+  }
 
   do_cleanups (old_cleanups);
 }
Index: testsuite/gdb.base/source.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/source.exp,v
retrieving revision 1.1
diff -p -u -r1.1 source.exp
--- testsuite/gdb.base/source.exp	16 Jan 2005 20:30:18 -0000	1.1
+++ testsuite/gdb.base/source.exp	16 Jan 2005 21:17:37 -0000
@@ -35,14 +35,8 @@ set binfile ${objdir}/${subdir}/${testfi
 
 gdb_start
 
-set test "script contains error"
-gdb_test_multiple "source ${srcdir}/${subdir}/source-error.gdb" $test {
-    -re "source-error.gdb:22: Error in sourced command file:\[\r\n\]*Cannot access memory at address 0x0.*$gdb_prompt " {
-	pass $test
-    }
-    -re "0x0:\[ \t\]+Cannot access memory at address 0x0.*$gdb_prompt " {
-	kfail gdb/1846 $test
-    }
-}
+gdb_test "source ${srcdir}/${subdir}/source-error.gdb" \
+    "source-error.gdb:22: Error in sourced command file:\[\r\n\]*Cannot access memory at address 0x0.*" \
+    "script contains error"
     
 gdb_exit

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