From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6089 invoked by alias); 15 Jan 2004 23:42:44 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 6080 invoked from network); 15 Jan 2004 23:42:43 -0000 Received: from unknown (HELO touchme.toronto.redhat.com) (216.129.200.20) by sources.redhat.com with SMTP; 15 Jan 2004 23:42:43 -0000 Received: from redhat.com (toocool.toronto.redhat.com [172.16.14.72]) by touchme.toronto.redhat.com (Postfix) with ESMTP id 2CD7C800152; Thu, 15 Jan 2004 18:42:43 -0500 (EST) Message-ID: <40072573.8020807@redhat.com> Date: Thu, 15 Jan 2004 23:42:00 -0000 From: "J. Johnston" Organization: Red Hat Inc. User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 MIME-Version: 1.0 To: Andrew Cagney Cc: gdb-patches@sources.redhat.com, Elena Zannoni Subject: Re: [RFA]: error_silent for use in pending breakpoint support References: <3FE21F2B.3030104@redhat.com> <4001B608.2010607@gnu.org> In-Reply-To: <4001B608.2010607@gnu.org> Content-Type: multipart/mixed; boundary="------------010402060005060709060802" X-SW-Source: 2004-01/txt/msg00402.txt.bz2 This is a multi-part message in MIME format. --------------010402060005060709060802 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 2528 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 * 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. > > --------------010402060005060709060802 Content-Type: text/plain; name="error_silent.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="error_silent.patch" Content-length: 7446 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); --------------010402060005060709060802--