Re: [RFA]: error_silent for use in pending breakpoint support

J. Johnston
2004-01-20T02:05:12Z

[-- 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);