From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31711 invoked by alias); 26 Nov 2001 17:47:46 -0000 Mailing-List: contact gdb-patches-help@sourceware.cygnus.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 31690 invoked from network); 26 Nov 2001 17:47:43 -0000 Received: from unknown (HELO cygnus.com) (205.180.230.5) by sourceware.cygnus.com with SMTP; 26 Nov 2001 17:47:43 -0000 Received: from rtl.cygnus.com (cse.cygnus.com [205.180.230.236]) by runyon.cygnus.com (8.8.7-cygnus/8.8.7) with ESMTP id JAA14598; Mon, 26 Nov 2001 09:47:40 -0800 (PST) Received: (from ezannoni@localhost) by rtl.cygnus.com (8.11.2/8.11.0) id fAQHriT01775; Mon, 26 Nov 2001 12:53:44 -0500 X-Authentication-Warning: krustylu.cygnus.com: ezannoni set sender to ezannoni@cygnus.com using -f From: Elena Zannoni MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15362.33192.680997.976657@krustylu.cygnus.com> Date: Mon, 12 Nov 2001 11:34:00 -0000 To: fnf@ninemoons.com Cc: gdb-patches@sources.redhat.com Subject: Re: [PATCH] temporary fix for bogus language check In-Reply-To: <200111251921.fAPJLP323371@fishpond.ninemoons.com> References: <200111251921.fAPJLP323371@fishpond.ninemoons.com> X-Mailer: VM 6.97 under Emacs 20.7.1 X-SW-Source: 2001-11/txt/msg00231.txt.bz2 Fred Fish writes: > In lookup_symbol(), gdb checks the current language and if it is C++, > trys to demangle the symbol name before looking it up. This works > fine if we are both looking up a C++ symbol and the current language > is C++. However it breaks down if we are trying to lookup a C++ > symbol and the current language is not C++, such as when stopped > inside a C function (perhaps a C library call for example). > > Consider decode_line_1 in linespec.c, which is called when you do > something like "br PCReader::work". This function calls > find_methods(), which later calls lookup_symbol() with the mangled > name "work__8PCReader". If the current language is C++, > lookup_symbol() demangles it to "PCReader::work(void)" and calls > lookup_symbol_aux with the demangled name, which succeeds. If however > you try to set the same breakpoint when stopped at a C function > setting the breakpoint fails. > > The following patch works around the problem by always attempting to > demangle the symbol to be looked up. We could fix this problem by > eliminating the test of the current language, but then every gdb > session would incur the additional overhead of attempting to demangle > every symbol regardless of whether or not any C++ symbols were > present. Another option is to set some global flag whenever symbols > for a C++ function are read in, and then do the current language test > unconditionally once we know that there might be C++ symbols > somewhere. Yet another option is to add a parameter to lookup_symbol > that says whether to consider the possibility that the symbol to be > looked up is a C++ symbol, set that appropriately when calling > lookup_symbol, and use that value to decide whether or not to try > demangling the symbol. Hmm, I can see the problem. We have the language information stored in the symtabs, but we don't know where the symbol is yet, so that's useless. I am not sure that the idea of saving somewhere the language information as you read symbols in would work here. It may be that you are setting your very first breakpoint in a c++ function, and you haven't read the symbols in yet. Is psymtab_to_symtab called before lookup_symbol or not? Actually I start to like the idea that the caller of lookup_symbol should know whether or not the name should be demangled. After all decode_line_1 has already figured out it is dealing with a c++ name, why throw that info away? Or (thinking out loud) would it make sense to never pass a mangled symbol to lookup_symbol (can the caller take care of demangling it?). Elena > > Suggestions? > > -Fred > > Index: symtab.c > =================================================================== > RCS file: /cvs/src/src/gdb/symtab.c,v > retrieving revision 1.48 > diff -u -r1.48 symtab.c > --- symtab.c 2001/11/13 16:42:50 1.48 > +++ symtab.c 2001/11/25 18:49:46 > @@ -528,8 +528,11 @@ > modified_name = (char *) name; > > /* If we are using C++ language, demangle the name before doing a lookup, so > - we can always binary search. */ > - if (current_language->la_language == language_cplus) > + we can always binary search. > + NOTE: We need to always try to demangle since the current_language might > + be something other than C++ at the point when we are trying to set a > + breakpoint in C++ code. -fnf */ > + if (1 || (current_language->la_language == language_cplus)) > { > modified_name2 = cplus_demangle (modified_name, DMGL_ANSI | DMGL_PARAMS); > if (modified_name2) From mboxrd@z Thu Jan 1 00:00:00 1970 From: Elena Zannoni To: fnf@ninemoons.com Cc: gdb-patches@sources.redhat.com Subject: Re: [PATCH] temporary fix for bogus language check Date: Mon, 26 Nov 2001 09:47:00 -0000 Message-ID: <15362.33192.680997.976657@krustylu.cygnus.com> References: <200111251921.fAPJLP323371@fishpond.ninemoons.com> X-SW-Source: 2001-11/msg00446.html Message-ID: <20011126094700.tX2x4TcJ3QvrmFouFQgYbijns7Ad_weSsn0kci7blJA@z> Fred Fish writes: > In lookup_symbol(), gdb checks the current language and if it is C++, > trys to demangle the symbol name before looking it up. This works > fine if we are both looking up a C++ symbol and the current language > is C++. However it breaks down if we are trying to lookup a C++ > symbol and the current language is not C++, such as when stopped > inside a C function (perhaps a C library call for example). > > Consider decode_line_1 in linespec.c, which is called when you do > something like "br PCReader::work". This function calls > find_methods(), which later calls lookup_symbol() with the mangled > name "work__8PCReader". If the current language is C++, > lookup_symbol() demangles it to "PCReader::work(void)" and calls > lookup_symbol_aux with the demangled name, which succeeds. If however > you try to set the same breakpoint when stopped at a C function > setting the breakpoint fails. > > The following patch works around the problem by always attempting to > demangle the symbol to be looked up. We could fix this problem by > eliminating the test of the current language, but then every gdb > session would incur the additional overhead of attempting to demangle > every symbol regardless of whether or not any C++ symbols were > present. Another option is to set some global flag whenever symbols > for a C++ function are read in, and then do the current language test > unconditionally once we know that there might be C++ symbols > somewhere. Yet another option is to add a parameter to lookup_symbol > that says whether to consider the possibility that the symbol to be > looked up is a C++ symbol, set that appropriately when calling > lookup_symbol, and use that value to decide whether or not to try > demangling the symbol. Hmm, I can see the problem. We have the language information stored in the symtabs, but we don't know where the symbol is yet, so that's useless. I am not sure that the idea of saving somewhere the language information as you read symbols in would work here. It may be that you are setting your very first breakpoint in a c++ function, and you haven't read the symbols in yet. Is psymtab_to_symtab called before lookup_symbol or not? Actually I start to like the idea that the caller of lookup_symbol should know whether or not the name should be demangled. After all decode_line_1 has already figured out it is dealing with a c++ name, why throw that info away? Or (thinking out loud) would it make sense to never pass a mangled symbol to lookup_symbol (can the caller take care of demangling it?). Elena > > Suggestions? > > -Fred > > Index: symtab.c > =================================================================== > RCS file: /cvs/src/src/gdb/symtab.c,v > retrieving revision 1.48 > diff -u -r1.48 symtab.c > --- symtab.c 2001/11/13 16:42:50 1.48 > +++ symtab.c 2001/11/25 18:49:46 > @@ -528,8 +528,11 @@ > modified_name = (char *) name; > > /* If we are using C++ language, demangle the name before doing a lookup, so > - we can always binary search. */ > - if (current_language->la_language == language_cplus) > + we can always binary search. > + NOTE: We need to always try to demangle since the current_language might > + be something other than C++ at the point when we are trying to set a > + breakpoint in C++ code. -fnf */ > + if (1 || (current_language->la_language == language_cplus)) > { > modified_name2 = cplus_demangle (modified_name, DMGL_ANSI | DMGL_PARAMS); > if (modified_name2)