Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA]: error_silent for use in pending breakpoint support
@ 2003-12-18 21:42 Jeff Johnston
  2004-01-09 18:55 ` J. Johnston
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Jeff Johnston @ 2003-12-18 21:42 UTC (permalink / raw)
  To: gdb-patches; +Cc: Elena Zannoni

[-- Attachment #1: Type: text/plain, Size: 1149 bytes --]

To properly support pending breakpoints, gdb needs to be able to 
suppress the "not found" messages at will, but it also needs to 
sometimes issue these messages and determine the cause of the error was 
a "not found" event.

To handle the problem, I propose two new useful functions in utils.c.  
The first is error_silent() which works just like error(), only it does 
not issue the error message.  Like error(), it stores the error message 
in gdb_lasterr.  This leads to the other new function: 
error_last_output() which is used to output the last error message.

This allows the pending breakpoint support to issue the error message 
when the user is doing the initial break command and to suppress it when 
shared libraries are being loaded or a pending breakpoint is reenabled.

Ok to commit?

2003-12-18  Jeff Johnston  <jjohnstn@redhat.com>

        * linespec.c (decode_variable, symtab_from_filename):  Call
        error_silent with error message instead of throwing an exception
        directly.
        * defs.h (error_silent, error_last_output): Add prototypes.
        * utils.c (error_silent, error_last_output): New functions.



[-- Attachment #2: error_silent.patch --]
[-- Type: text/plain, Size: 3202 bytes --]

Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.135
diff -u -p -r1.135 defs.h
--- defs.h	7 Dec 2003 17:22:29 -0000	1.135
+++ defs.h	18 Dec 2003 21:25:08 -0000
@@ -912,6 +912,8 @@ extern NORETURN void verror (const char 
 
 extern NORETURN void error (const char *fmt, ...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
 
+extern NORETURN void error_silent (const char *fmt, ...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
+
 extern NORETURN void error_stream (struct ui_file *) ATTR_NORETURN;
 
 /* Initialize the error buffer.  */
@@ -920,6 +922,9 @@ extern void error_init (void);
 /* Returns a freshly allocate buffer containing the last error
    message.  */
 extern char *error_last_message (void);
+
+/* Output last error message.  */
+extern void error_last_output (void);
 
 extern NORETURN void internal_verror (const char *file, int line,
 				      const char *, va_list ap) ATTR_NORETURN;
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.110
diff -u -p -r1.110 utils.c
--- utils.c	21 Sep 2003 01:26:45 -0000	1.110
+++ utils.c	18 Dec 2003 21:25:08 -0000
@@ -626,6 +626,38 @@ do_write (void *data, const char *buffer
   ui_file_write (data, buffer, length_buffer);
 }
 
+/* Cause a silent error to occur.  Any error message is recorded
+   though it is not issued.  */
+NORETURN void
+error_silent (const char *string, ...)
+{
+  va_list args;
+  struct ui_file *tmp_stream = mem_fileopen ();
+  va_start (args, string);
+  make_cleanup_ui_file_delete (tmp_stream);
+  vfprintf_unfiltered (tmp_stream, string, args);
+  /* Copy the stream into the GDB_LASTERR buffer.  */
+  ui_file_rewind (gdb_lasterr);
+  ui_file_put (tmp_stream, do_write, gdb_lasterr);
+  va_end (args);
+
+  throw_exception (RETURN_ERROR);
+}
+
+/* Output the last error message plus any error_pre_print to gdb_stderr.  */
+void
+error_last_output (void)
+{
+  target_terminal_ours ();
+  wrap_here ("");		/* Force out any buffered output */
+  gdb_flush (gdb_stdout);
+  annotate_error_begin ();
+  if (error_pre_print)
+    fputs_filtered (error_pre_print, gdb_stderr);
+  ui_file_put (gdb_lasterr, do_write, gdb_stderr);
+  fprintf_filtered (gdb_stderr, "\n");
+}
+
 NORETURN void
 error_stream (struct ui_file *stream)
 {
Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.53
diff -u -p -r1.53 linespec.c
--- linespec.c	17 Dec 2003 21:47:47 -0000	1.53
+++ linespec.c	18 Dec 2003 21:25:08 -0000
@@ -1469,7 +1469,7 @@ symtab_from_filename (char **argptr, cha
       if (not_found_ptr)
 	{
 	  *not_found_ptr = 1;
-	  throw_exception (RETURN_ERROR);
+	  error_silent ("No source file named %s.", copy);
 	}
       error ("No source file named %s.", copy);
     }
@@ -1684,7 +1684,7 @@ decode_variable (char *copy, int funfirs
   if (not_found_ptr)
     {
       *not_found_ptr = 1;
-      throw_exception (RETURN_ERROR);
+      error_silent ("Function \"%s\" not defined.", copy);
     }
   
   error ("Function \"%s\" not defined.", copy);

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

* Re: [RFA]: error_silent for use in pending breakpoint support
  2003-12-18 21:42 [RFA]: error_silent for use in pending breakpoint support Jeff Johnston
@ 2004-01-09 18:55 ` J. Johnston
  2004-01-11 20:46 ` Andrew Cagney
  2004-01-12 15:27 ` Elena Zannoni
  2 siblings, 0 replies; 7+ messages in thread
From: J. Johnston @ 2004-01-09 18:55 UTC (permalink / raw)
  To: Jeff Johnston; +Cc: gdb-patches, Elena Zannoni

Ping.

Jeff Johnston wrote:
> To properly support pending breakpoints, gdb needs to be able to 
> suppress the "not found" messages at will, but it also needs to 
> sometimes issue these messages and determine the cause of the error was 
> a "not found" event.
> 
> To handle the problem, I propose two new useful functions in utils.c.  
> The first is error_silent() which works just like error(), only it does 
> not issue the error message.  Like error(), it stores the error message 
> in gdb_lasterr.  This leads to the other new function: 
> error_last_output() which is used to output the last error message.
> 
> This allows the pending breakpoint support to issue the error message 
> when the user is doing the initial break command and to suppress it when 
> shared libraries are being loaded or a pending breakpoint is reenabled.
> 
> Ok to commit?
> 
> 2003-12-18  Jeff Johnston  <jjohnstn@redhat.com>
> 
>        * linespec.c (decode_variable, symtab_from_filename):  Call
>        error_silent with error message instead of throwing an exception
>        directly.
>        * defs.h (error_silent, error_last_output): Add prototypes.
>        * utils.c (error_silent, error_last_output): New functions.
> 
> 


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

* Re: [RFA]: error_silent for use in pending breakpoint support
  2003-12-18 21:42 [RFA]: error_silent for use in pending breakpoint support Jeff Johnston
  2004-01-09 18:55 ` J. Johnston
@ 2004-01-11 20:46 ` Andrew Cagney
  2004-01-15 23:42   ` J. Johnston
  2004-01-12 15:27 ` Elena Zannoni
  2 siblings, 1 reply; 7+ messages in thread
From: Andrew Cagney @ 2004-01-11 20:46 UTC (permalink / raw)
  To: Jeff Johnston; +Cc: gdb-patches, Elena Zannoni

> To properly support pending breakpoints, gdb needs to be able to suppress the "not found" messages at will, but it also needs to sometimes issue these messages and determine the cause of the error was a "not found" event.
> 
> To handle the problem, I propose two new useful functions in utils.c.  The first is error_silent() which works just like error(), only it does not issue the error message.  Like error(), it stores the error message in gdb_lasterr.  This leads to the other new function: error_last_output() which is used to output the last error message.
> 
> This allows the pending breakpoint support to issue the error message when the user is doing the initial break command and to suppress it when shared libraries are being loaded or a pending breakpoint is reenabled.

(I noticed this mentioned linespec so left it, it's really more of a 
change to utils though).

What does the stack look like at the point where error_silent is being 
called?

I'm thinking that something more like:

	catch_exception_error (....., &error_mesg);
with
	throw_error (message, ...) // silent

or
	catch_exception_silently (..., &error_mesg);
with
	error (message, ...)

would be better.  With that it should be possible to avoid the stateful 
error_last_output interface.   I think this would also be better long 
term as it should lend itself to the recursive case (where an error is 
being propogated up the stack).


Andrew



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

* Re: [RFA]: error_silent for use in pending breakpoint support
  2003-12-18 21:42 [RFA]: error_silent for use in pending breakpoint support Jeff Johnston
  2004-01-09 18:55 ` J. Johnston
  2004-01-11 20:46 ` Andrew Cagney
@ 2004-01-12 15:27 ` Elena Zannoni
  2 siblings, 0 replies; 7+ messages in thread
From: Elena Zannoni @ 2004-01-12 15:27 UTC (permalink / raw)
  To: Jeff Johnston; +Cc: gdb-patches, Elena Zannoni

Jeff Johnston writes:
 > To properly support pending breakpoints, gdb needs to be able to 
 > suppress the "not found" messages at will, but it also needs to 
 > sometimes issue these messages and determine the cause of the error was 
 > a "not found" event.
 > 
 > To handle the problem, I propose two new useful functions in utils.c.  
 > The first is error_silent() which works just like error(), only it does 
 > not issue the error message.  Like error(), it stores the error message 
 > in gdb_lasterr.  This leads to the other new function: 
 > error_last_output() which is used to output the last error message.
 > 
 > This allows the pending breakpoint support to issue the error message 
 > when the user is doing the initial break command and to suppress it when 
 > shared libraries are being loaded or a pending breakpoint is reenabled.
 > 
 > Ok to commit?
 > 
 > 2003-12-18  Jeff Johnston  <jjohnstn@redhat.com>
 > 
 >         * linespec.c (decode_variable, symtab_from_filename):  Call
 >         error_silent with error message instead of throwing an exception
 >         directly.
 >         * defs.h (error_silent, error_last_output): Add prototypes.
 >         * utils.c (error_silent, error_last_output): New functions.
 > 
 > 

The linespec.c change depends on the rest being approved. If that
happens, this would be ok.

elena

 > Index: linespec.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/linespec.c,v
 > retrieving revision 1.53
 > diff -u -p -r1.53 linespec.c
 > --- linespec.c	17 Dec 2003 21:47:47 -0000	1.53
 > +++ linespec.c	18 Dec 2003 21:25:08 -0000
 > @@ -1469,7 +1469,7 @@ symtab_from_filename (char **argptr, cha
 >        if (not_found_ptr)
 >  	{
 >  	  *not_found_ptr = 1;
 > -	  throw_exception (RETURN_ERROR);
 > +	  error_silent ("No source file named %s.", copy);
 >  	}
 >        error ("No source file named %s.", copy);
 >      }
 > @@ -1684,7 +1684,7 @@ decode_variable (char *copy, int funfirs
 >    if (not_found_ptr)
 >      {
 >        *not_found_ptr = 1;
 > -      throw_exception (RETURN_ERROR);
 > +      error_silent ("Function \"%s\" not defined.", copy);
 >      }
 >    
 >    error ("Function \"%s\" not defined.", copy);


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

* Re: [RFA]: error_silent for use in pending breakpoint support
  2004-01-11 20:46 ` Andrew Cagney
@ 2004-01-15 23:42   ` J. Johnston
  2004-01-19 23:10     ` Andrew Cagney
  0 siblings, 1 reply; 7+ messages in thread
From: J. Johnston @ 2004-01-15 23:42 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb-patches, Elena Zannoni

[-- Attachment #1: Type: text/plain, Size: 2528 bytes --]

Andrew Cagney wrote:
>> To properly support pending breakpoints, gdb needs to be able to 
>> suppress the "not found" messages at will, but it also needs to 
>> sometimes issue these messages and determine the cause of the error 
>> was a "not found" event.
>>
>> To handle the problem, I propose two new useful functions in utils.c.  
>> The first is error_silent() which works just like error(), only it 
>> does not issue the error message.  Like error(), it stores the error 
>> message in gdb_lasterr.  This leads to the other new function: 
>> error_last_output() which is used to output the last error message.
>>
>> This allows the pending breakpoint support to issue the error message 
>> when the user is doing the initial break command and to suppress it 
>> when shared libraries are being loaded or a pending breakpoint is 
>> reenabled.
> 
> 
> (I noticed this mentioned linespec so left it, it's really more of a 
> change to utils though).
> 
> What does the stack look like at the point where error_silent is being 
> called?
> 
> I'm thinking that something more like:
> 
>     catch_exception_error (....., &error_mesg);
> with
>     throw_error (message, ...) // silent
> 
> or
>     catch_exception_silently (..., &error_mesg);
> with
>     error (message, ...)
> 
> would be better.  With that it should be possible to avoid the stateful 
> error_last_output interface.   I think this would also be better long 
> term as it should lend itself to the recursive case (where an error is 
> being propogated up the stack).
> 
> 
> Andrew
> 

Ok, patch revised.

I chose to add a new version of catch_exceptions() called 
catch_exceptions_with_msg() which saves a copy of the error message (if an error 
occurs) for the caller to manually output if desired.  The copy needs to be 
freed by the caller once the message is no longer needed.

I removed error_last_output() and created a new function error_output_message() 
which takes pre_print text plus a message and outputs to gdb_stderr.

Any other problems or ok to commit?

-- Jeff J.

2004-01-15  Jeff Johnston  <jjohnstn@redhat.com>

         * linespec.c (decode_variable, symtab_from_filename):  Call
         error_silent with error message instead of throwing an exception
         directly.
         * defs.h (error_silent, error_output_message): Add prototypes.
         (catch_exceptions_with_msg): Ditto.
         * utils.c (error_silent, error_output_message): New functions.
         * top.c (catch_exceptions_with_msg): New function.



> 
> 

[-- Attachment #2: error_silent.patch --]
[-- Type: text/plain, Size: 7446 bytes --]

Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.136
diff -u -p -r1.136 defs.h
--- defs.h	2 Jan 2004 17:35:00 -0000	1.136
+++ defs.h	15 Jan 2004 23:39:19 -0000
@@ -1,7 +1,7 @@
 /* *INDENT-OFF* */ /* ATTR_FORMAT confuses indent, avoid running it for now */
 /* Basic, host-specific, and target-specific definitions for GDB.
    Copyright 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
-   1997, 1998, 1999, 2000, 2001, 2002, 2003
+   1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -911,6 +911,8 @@ extern NORETURN void verror (const char 
 
 extern NORETURN void error (const char *fmt, ...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
 
+extern NORETURN void error_silent (const char *fmt, ...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
+
 extern NORETURN void error_stream (struct ui_file *) ATTR_NORETURN;
 
 /* Initialize the error buffer.  */
@@ -920,6 +922,9 @@ extern void error_init (void);
    message.  */
 extern char *error_last_message (void);
 
+/* Output arbitrary error message.  */
+extern void error_output_message (char *pre_print, char *msg);
+
 extern NORETURN void internal_verror (const char *file, int line,
 				      const char *, va_list ap) ATTR_NORETURN;
 
@@ -982,6 +987,11 @@ extern NORETURN void throw_exception (en
    new cleanup_chain is established.  The old values are restored
    before catch_exceptions() returns.
 
+   The variant catch_exceptions_with_msg() is the same as
+   catch_exceptions() but adds the ability to return an allocated
+   copy of the gdb error message.  This is used when a silent error is 
+   issued and the caller wants to manually issue the error message.
+
    FIXME; cagney/2001-08-13: The need to override the global UIOUT
    builder variable should just go away.
 
@@ -994,6 +1004,11 @@ typedef int (catch_exceptions_ftype) (st
 extern int catch_exceptions (struct ui_out *uiout,
 			     catch_exceptions_ftype *func, void *func_args,
 			     char *errstring, return_mask mask);
+extern int catch_exceptions_with_msg (struct ui_out *uiout,
+			     	      catch_exceptions_ftype *func, 
+			     	      void *func_args,
+			     	      char *errstring, char **gdberrmsg,
+				      return_mask mask);
 
 /* If CATCH_ERRORS_FTYPE throws an error, catch_errors() returns zero
    otherwize the result from CATCH_ERRORS_FTYPE is returned. It is
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.111
diff -u -p -r1.111 utils.c
--- utils.c	2 Jan 2004 17:35:01 -0000	1.111
+++ utils.c	15 Jan 2004 23:39:19 -0000
@@ -1,7 +1,7 @@
 /* General utility routines for GDB, the GNU debugger.
 
    Copyright 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
+   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
    Foundation, Inc.
 
    This file is part of GDB.
@@ -626,6 +626,38 @@ static void
 do_write (void *data, const char *buffer, long length_buffer)
 {
   ui_file_write (data, buffer, length_buffer);
+}
+
+/* Cause a silent error to occur.  Any error message is recorded
+   though it is not issued.  */
+NORETURN void
+error_silent (const char *string, ...)
+{
+  va_list args;
+  struct ui_file *tmp_stream = mem_fileopen ();
+  va_start (args, string);
+  make_cleanup_ui_file_delete (tmp_stream);
+  vfprintf_unfiltered (tmp_stream, string, args);
+  /* Copy the stream into the GDB_LASTERR buffer.  */
+  ui_file_rewind (gdb_lasterr);
+  ui_file_put (tmp_stream, do_write, gdb_lasterr);
+  va_end (args);
+
+  throw_exception (RETURN_ERROR);
+}
+
+/* Output an error message including any pre-print text to gdb_stderr.  */
+void
+error_output_message (char *pre_print, char *msg)
+{
+  target_terminal_ours ();
+  wrap_here ("");		/* Force out any buffered output */
+  gdb_flush (gdb_stdout);
+  annotate_error_begin ();
+  if (pre_print)
+    fputs_filtered (pre_print, gdb_stderr);
+  fputs_filtered (msg, gdb_stderr);
+  fprintf_filtered (gdb_stderr, "\n");
 }
 
 NORETURN void
Index: top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.86
diff -u -p -r1.86 top.c
--- top.c	2 Jan 2004 20:53:11 -0000	1.86
+++ top.c	15 Jan 2004 23:39:19 -0000
@@ -383,6 +383,7 @@ catcher (catch_exceptions_ftype *func,
 	 int *func_val,
 	 enum return_reason *func_caught,
 	 char *errstring,
+	 char **gdberrmsg,
 	 return_mask mask)
 {
   SIGJMP_BUF *saved_catch;
@@ -428,7 +429,14 @@ catcher (catch_exceptions_ftype *func,
   if (!caught)
     val = (*func) (func_uiout, func_args);
   else
-    val = 0;
+    {
+      val = 0;
+      /* If caller wants a copy of the low-level error message, make one.  
+         This is used in the case of a silent error whereby the caller
+         may optionally want to issue the message.  */
+      if (gdberrmsg)
+	*gdberrmsg = error_last_message ();
+    }
   catch_return = saved_catch;
 
   /* FIXME: cagney/1999-11-05: A correct FUNC implementation will
@@ -476,7 +484,25 @@ catch_exceptions (struct ui_out *uiout,
 {
   int val;
   enum return_reason caught;
-  catcher (func, uiout, func_args, &val, &caught, errstring, mask);
+  catcher (func, uiout, func_args, &val, &caught, errstring, NULL, mask);
+  gdb_assert (val >= 0);
+  gdb_assert (caught <= 0);
+  if (caught < 0)
+    return caught;
+  return val;
+}
+
+int
+catch_exceptions_with_msg (struct ui_out *uiout,
+		  	   catch_exceptions_ftype *func,
+		  	   void *func_args,
+		  	   char *errstring,
+			   char **gdberrmsg,
+		  	   return_mask mask)
+{
+  int val;
+  enum return_reason caught;
+  catcher (func, uiout, func_args, &val, &caught, errstring, gdberrmsg, mask);
   gdb_assert (val >= 0);
   gdb_assert (caught <= 0);
   if (caught < 0)
@@ -506,7 +532,8 @@ catch_errors (catch_errors_ftype *func, 
   struct catch_errors_args args;
   args.func = func;
   args.func_args = func_args;
-  catcher (do_catch_errors, uiout, &args, &val, &caught, errstring, mask);
+  catcher (do_catch_errors, uiout, &args, &val, &caught, errstring, 
+	   NULL, mask);
   if (caught != 0)
     return 0;
   return val;
Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.53
diff -u -p -r1.53 linespec.c
--- linespec.c	17 Dec 2003 21:47:47 -0000	1.53
+++ linespec.c	15 Jan 2004 23:39:19 -0000
@@ -1,6 +1,6 @@
 /* Parser for linespec for the GNU debugger, GDB.
    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
+   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -1469,7 +1469,7 @@ symtab_from_filename (char **argptr, cha
       if (not_found_ptr)
 	{
 	  *not_found_ptr = 1;
-	  throw_exception (RETURN_ERROR);
+	  error_silent ("No source file named %s.", copy);
 	}
       error ("No source file named %s.", copy);
     }
@@ -1684,7 +1684,7 @@ decode_variable (char *copy, int funfirs
   if (not_found_ptr)
     {
       *not_found_ptr = 1;
-      throw_exception (RETURN_ERROR);
+      error_silent ("Function \"%s\" not defined.", copy);
     }
   
   error ("Function \"%s\" not defined.", copy);

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

* Re: [RFA]: error_silent for use in pending breakpoint support
  2004-01-15 23:42   ` J. Johnston
@ 2004-01-19 23:10     ` Andrew Cagney
  2004-01-20  2:05       ` J. Johnston
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Cagney @ 2004-01-19 23:10 UTC (permalink / raw)
  To: J. Johnston; +Cc: gdb-patches, Elena Zannoni


> 
> Ok, patch revised.
> 
> I chose to add a new version of catch_exceptions() called catch_exceptions_with_msg() which saves a copy of the error message (if an error occurs) for the caller to manually output if desired.  The copy needs to be freed by the caller once the message is no longer needed.
> 
> I removed error_last_output() and created a new function error_output_message() which takes pre_print text plus a message and outputs to gdb_stderr.
> 
> Any other problems or ok to commit? 

Much nicer - that nasty message buffer is better confied to top.c - 
thank.  Just suggest more commentary here:
> -	  throw_exception (RETURN_ERROR);
> +	  error_silent ("No source file named %s.", copy);
before committing (elena's already oked it from memory).

tks.
Andrew



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

* Re: [RFA]: error_silent for use in pending breakpoint support
  2004-01-19 23:10     ` Andrew Cagney
@ 2004-01-20  2:05       ` J. Johnston
  0 siblings, 0 replies; 7+ messages in thread
From: J. Johnston @ 2004-01-20  2:05 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb-patches, Elena Zannoni

[-- Attachment #1: Type: text/plain, Size: 957 bytes --]

Thanks.  I updated comments as asked.  The revised patch has been checked in.

-- Jeff J.

Andrew Cagney wrote:
> 
>>
>> Ok, patch revised.
>>
>> I chose to add a new version of catch_exceptions() called 
>> catch_exceptions_with_msg() which saves a copy of the error message 
>> (if an error occurs) for the caller to manually output if desired.  
>> The copy needs to be freed by the caller once the message is no longer 
>> needed.
>>
>> I removed error_last_output() and created a new function 
>> error_output_message() which takes pre_print text plus a message and 
>> outputs to gdb_stderr.
>>
>> Any other problems or ok to commit? 
> 
> 
> Much nicer - that nasty message buffer is better confied to top.c - 
> thank.  Just suggest more commentary here:
> 
>> -      throw_exception (RETURN_ERROR);
>> +      error_silent ("No source file named %s.", copy);
> 
> before committing (elena's already oked it from memory).
> 
> tks.
> Andrew
> 
> 
> 

[-- Attachment #2: error_silent.patch --]
[-- Type: text/plain, Size: 8338 bytes --]

Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.137
diff -u -p -r1.137 defs.h
--- defs.h	17 Jan 2004 00:13:46 -0000	1.137
+++ defs.h	20 Jan 2004 02:03:33 -0000
@@ -1,7 +1,7 @@
 /* *INDENT-OFF* */ /* ATTR_FORMAT confuses indent, avoid running it for now */
 /* Basic, host-specific, and target-specific definitions for GDB.
    Copyright 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
-   1997, 1998, 1999, 2000, 2001, 2002, 2003
+   1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -911,6 +911,8 @@ extern NORETURN void verror (const char 
 
 extern NORETURN void error (const char *fmt, ...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
 
+extern NORETURN void error_silent (const char *fmt, ...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
+
 extern NORETURN void error_stream (struct ui_file *) ATTR_NORETURN;
 
 /* Initialize the error buffer.  */
@@ -920,6 +922,9 @@ extern void error_init (void);
    message.  */
 extern char *error_last_message (void);
 
+/* Output arbitrary error message.  */
+extern void error_output_message (char *pre_print, char *msg);
+
 extern NORETURN void internal_verror (const char *file, int line,
 				      const char *, va_list ap) ATTR_NORETURN;
 
@@ -982,6 +987,11 @@ extern NORETURN void throw_exception (en
    new cleanup_chain is established.  The old values are restored
    before catch_exceptions() returns.
 
+   The variant catch_exceptions_with_msg() is the same as
+   catch_exceptions() but adds the ability to return an allocated
+   copy of the gdb error message.  This is used when a silent error is 
+   issued and the caller wants to manually issue the error message.
+
    FIXME; cagney/2001-08-13: The need to override the global UIOUT
    builder variable should just go away.
 
@@ -994,6 +1004,11 @@ typedef int (catch_exceptions_ftype) (st
 extern int catch_exceptions (struct ui_out *uiout,
 			     catch_exceptions_ftype *func, void *func_args,
 			     char *errstring, return_mask mask);
+extern int catch_exceptions_with_msg (struct ui_out *uiout,
+			     	      catch_exceptions_ftype *func, 
+			     	      void *func_args,
+			     	      char *errstring, char **gdberrmsg,
+				      return_mask mask);
 
 /* If CATCH_ERRORS_FTYPE throws an error, catch_errors() returns zero
    otherwize the result from CATCH_ERRORS_FTYPE is returned. It is
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.111
diff -u -p -r1.111 utils.c
--- utils.c	2 Jan 2004 17:35:01 -0000	1.111
+++ utils.c	20 Jan 2004 02:03:33 -0000
@@ -1,7 +1,7 @@
 /* General utility routines for GDB, the GNU debugger.
 
    Copyright 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
+   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
    Foundation, Inc.
 
    This file is part of GDB.
@@ -626,6 +626,38 @@ static void
 do_write (void *data, const char *buffer, long length_buffer)
 {
   ui_file_write (data, buffer, length_buffer);
+}
+
+/* Cause a silent error to occur.  Any error message is recorded
+   though it is not issued.  */
+NORETURN void
+error_silent (const char *string, ...)
+{
+  va_list args;
+  struct ui_file *tmp_stream = mem_fileopen ();
+  va_start (args, string);
+  make_cleanup_ui_file_delete (tmp_stream);
+  vfprintf_unfiltered (tmp_stream, string, args);
+  /* Copy the stream into the GDB_LASTERR buffer.  */
+  ui_file_rewind (gdb_lasterr);
+  ui_file_put (tmp_stream, do_write, gdb_lasterr);
+  va_end (args);
+
+  throw_exception (RETURN_ERROR);
+}
+
+/* Output an error message including any pre-print text to gdb_stderr.  */
+void
+error_output_message (char *pre_print, char *msg)
+{
+  target_terminal_ours ();
+  wrap_here ("");		/* Force out any buffered output */
+  gdb_flush (gdb_stdout);
+  annotate_error_begin ();
+  if (pre_print)
+    fputs_filtered (pre_print, gdb_stderr);
+  fputs_filtered (msg, gdb_stderr);
+  fprintf_filtered (gdb_stderr, "\n");
 }
 
 NORETURN void
Index: top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.86
diff -u -p -r1.86 top.c
--- top.c	2 Jan 2004 20:53:11 -0000	1.86
+++ top.c	20 Jan 2004 02:03:33 -0000
@@ -383,6 +383,7 @@ catcher (catch_exceptions_ftype *func,
 	 int *func_val,
 	 enum return_reason *func_caught,
 	 char *errstring,
+	 char **gdberrmsg,
 	 return_mask mask)
 {
   SIGJMP_BUF *saved_catch;
@@ -428,7 +429,14 @@ catcher (catch_exceptions_ftype *func,
   if (!caught)
     val = (*func) (func_uiout, func_args);
   else
-    val = 0;
+    {
+      val = 0;
+      /* If caller wants a copy of the low-level error message, make one.  
+         This is used in the case of a silent error whereby the caller
+         may optionally want to issue the message.  */
+      if (gdberrmsg)
+	*gdberrmsg = error_last_message ();
+    }
   catch_return = saved_catch;
 
   /* FIXME: cagney/1999-11-05: A correct FUNC implementation will
@@ -476,7 +484,25 @@ catch_exceptions (struct ui_out *uiout,
 {
   int val;
   enum return_reason caught;
-  catcher (func, uiout, func_args, &val, &caught, errstring, mask);
+  catcher (func, uiout, func_args, &val, &caught, errstring, NULL, mask);
+  gdb_assert (val >= 0);
+  gdb_assert (caught <= 0);
+  if (caught < 0)
+    return caught;
+  return val;
+}
+
+int
+catch_exceptions_with_msg (struct ui_out *uiout,
+		  	   catch_exceptions_ftype *func,
+		  	   void *func_args,
+		  	   char *errstring,
+			   char **gdberrmsg,
+		  	   return_mask mask)
+{
+  int val;
+  enum return_reason caught;
+  catcher (func, uiout, func_args, &val, &caught, errstring, gdberrmsg, mask);
   gdb_assert (val >= 0);
   gdb_assert (caught <= 0);
   if (caught < 0)
@@ -506,7 +532,8 @@ catch_errors (catch_errors_ftype *func, 
   struct catch_errors_args args;
   args.func = func;
   args.func_args = func_args;
-  catcher (do_catch_errors, uiout, &args, &val, &caught, errstring, mask);
+  catcher (do_catch_errors, uiout, &args, &val, &caught, errstring, 
+	   NULL, mask);
   if (caught != 0)
     return 0;
   return val;
Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.53
diff -u -p -r1.53 linespec.c
--- linespec.c	17 Dec 2003 21:47:47 -0000	1.53
+++ linespec.c	20 Jan 2004 02:03:33 -0000
@@ -1,6 +1,6 @@
 /* Parser for linespec for the GNU debugger, GDB.
    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
+   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -1469,7 +1469,14 @@ symtab_from_filename (char **argptr, cha
       if (not_found_ptr)
 	{
 	  *not_found_ptr = 1;
-	  throw_exception (RETURN_ERROR);
+	  /* The caller has indicated that it wishes quiet notification of any
+	     error where the function or file is not found.  A call to 
+	     error_silent causes an error to occur, but it does not issue 
+	     the supplied message.  The message can be manually output by
+	     the caller, if desired.  This is used, for example, when 
+	     attempting to set breakpoints for functions in shared libraries 
+	     that have not yet been loaded.  */
+	  error_silent ("No source file named %s.", copy);
 	}
       error ("No source file named %s.", copy);
     }
@@ -1684,7 +1691,14 @@ decode_variable (char *copy, int funfirs
   if (not_found_ptr)
     {
       *not_found_ptr = 1;
-      throw_exception (RETURN_ERROR);
+      /* The caller has indicated that it wishes quiet notification of any
+	 error where the function or file is not found.  A call to 
+	 error_silent causes an error to occur, but it does not issue 
+	 the supplied message.  The message can be manually output by
+	 the caller, if desired.  This is used, for example, when 
+	 attempting to set breakpoints for functions in shared libraries 
+	 that have not yet been loaded.  */
+      error_silent ("Function \"%s\" not defined.", copy);
     }
   
   error ("Function \"%s\" not defined.", copy);

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

end of thread, other threads:[~2004-01-20  2:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-18 21:42 [RFA]: error_silent for use in pending breakpoint support Jeff Johnston
2004-01-09 18:55 ` J. Johnston
2004-01-11 20:46 ` Andrew Cagney
2004-01-15 23:42   ` J. Johnston
2004-01-19 23:10     ` Andrew Cagney
2004-01-20  2:05       ` J. Johnston
2004-01-12 15:27 ` Elena Zannoni

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