[RFA]: error_silent for use in pending breakpoint support

Jeff Johnston
2003-12-18T21:42:04Z

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