<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://sourceware.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="4.4+"
          urlbase="http://sourceware.org/bugzilla/"
          
          maintainer="overseers@sourceware.org"
>

    <bug>
          <bug_id>10966</bug_id>
          
          <creation_ts>2009-11-16 18:38:00 +0000</creation_ts>
          <short_desc>Something fishy with constructors</short_desc>
          <delta_ts>2010-03-15 17:33:48 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>gdb</product>
          <component>c++</component>
          <version>unknown</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>7.2</target_milestone>
          
          <blocked>11211</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Paul Pluzhnikov">ppluzhnikov</reporter>
          <assigned_to name="Paul Pluzhnikov">ppluzhnikov</assigned_to>
          <cc>gdb-prs</cc>
    
    <cc>tromey</cc>
          <cf_gcchost>x86_64-unknown-linux-gnu</cf_gcchost>
          <cf_gcctarget>x86_64-unknown-linux-gnu</cf_gcctarget>
          <cf_gccbuild>x86_64-unknown-linux-gnu</cf_gccbuild>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>39817</commentid>
    <comment_count>0</comment_count>
    <who name="Paul Pluzhnikov">ppluzhnikov</who>
    <bug_when>2009-11-16 18:38:40 +0000</bug_when>
    <thetext>There is something fishy going on with constructors.

--- cut ---
struct Foo {
#if DEFAULT_CONSTRUCTOR
  Foo() { x = 0; }
#endif
  Foo(const char *xx) : x(xx) { }
  const char *bar() { return x; }
  const char *x;
};

int main()
{
  Foo f(&quot;abc&quot;);
  const char *s = f.bar();
}
--- cut ---

g++ -g foo.cc -o foo1
g++ -g foo.cc -o foo2 -DDEFAULT_CONSTRUCTOR



gdb-cvs -nx ./foo1
GNU gdb (GDB) 7.0.50.20091116-cvs
...
This GDB was configured as &quot;x86_64-unknown-linux-gnu&quot;.
For bug reporting instructions, please see:
&lt;http://www.gnu.org/software/gdb/bugs/&gt;...
Reading symbols from /usr/local/google/tmp/b1844402/foo1...done.
(gdb) b Foo::bar
Breakpoint 1 at 0x400584: file foo.cc, line 6.
(gdb) b Foo::Foo
(gdb)                 ### problem 1: why didn&apos;t this set a breakpoint?



gdb64-cvs -q -nx ./foo2
Reading symbols from /usr/local/google/tmp/b1844402/foo2...done.
(gdb) b Foo::Foo
../../src/gdb/breakpoint.c:4797: internal-error: set_raw_breakpoint: Assertion
`sal.pspace != NULL&apos; failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.


Both problems also exist in 6.8 and official 7.0 release, though the second
problem does not result in a crash, merely in bogus breakpoints being
inserted:

GNU gdb (GDB) 7.0
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type &quot;show copying&quot;
and &quot;show warranty&quot; for details.
This GDB was configured as &quot;x86_64-unknown-linux-gnu&quot;.
For bug reporting instructions, please see:
&lt;http://www.gnu.org/software/gdb/bugs/&gt;...
Reading symbols from /usr/local/google/tmp/b1844402/foo2...done.
(gdb) b Foo::Foo
Breakpoint 1 at 0x0
Note: breakpoint 1 also set at pc 0x0.
Breakpoint 2 at 0x0
warning: Multiple breakpoints were set.
Use the &quot;delete&quot; command to delete unwanted breakpoints.
(gdb)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>39818</commentid>
    <comment_count>1</comment_count>
    <who name="Pedro Alves">palves</who>
    <bug_when>2009-11-16 18:53:42 +0000</bug_when>
    <thetext>Subject: Re:  New: Something fishy with constructors

&gt; (gdb) b Foo::Foo
&gt; Breakpoint 1 at 0x0
&gt; Note: breakpoint 1 also set at pc 0x0.
&gt; Breakpoint 2 at 0x0
&gt; warning: Multiple breakpoints were set.
&gt; Use the &quot;delete&quot; command to delete unwanted breakpoints.
&gt; (gdb)
&gt; 

Ah!  This is actually PR8166, in desguise.  &apos;show multiple-symbols&apos; was
added in gdb 7.0, and the default changed to &quot;all&quot;:

On head:

(gdb) show multiple-symbols
How the debugger handles ambiguities in expressions is &quot;all&quot;.

(gdb) b Foo::Foo
[0] cancel
[1] all
?HERE
?HERE
&gt; 
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>39820</commentid>
    <comment_count>2</comment_count>
    <who name="Pedro Alves">palves</who>
    <bug_when>2009-11-16 19:14:06 +0000</bug_when>
    <thetext>Subject: Re:  Something fishy with constructors

Here&apos;s the problem:

(top-gdb) bt
#0  add_matching_methods (method_counter=0, t=0xc73930, language=language_cplus, sym_arr=0x7fff4c0b26e0)
    at ../../src/gdb/linespec.c:316
#1  0x0000000000536b72 in find_methods (t=0xc73930, name=0x7fff4c0b2830 &quot;Foo&quot;, language=language_cplus,
    sym_arr=0x7fff4c0b26e0) at ../../src/gdb/linespec.c:249
#2  0x00000000005392cb in find_method (funfirstline=1, canonical=0x7fff4c0b2ce8, saved_arg=0xb1e1c2 &quot;Foo::Foo&quot;,
    copy=0x7fff4c0b2830 &quot;Foo&quot;, t=0xc73930, sym_class=0xc8b840, not_found_ptr=0x7fff4c0b2d14)
    at ../../src/gdb/linespec.c:1488
#3  0x0000000000538e99 in decode_compound (argptr=0x7fff4c0b2c00, funfirstline=1, canonical=0x7fff4c0b2ce8,
    saved_arg=0xb1e1c2 &quot;Foo::Foo&quot;, p=0xb1e1ca &quot;&quot;, not_found_ptr=0x7fff4c0b2d14) at ../../src/gdb/linespec.c:1386


linespec.c:

312           sym_arr[i1] = lookup_symbol_in_language (phys_name,
313                                        NULL, VAR_DOMAIN,
314                                        language,
315                                        (int *) NULL);
316           if (sym_arr[i1])    &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
317             i1++;
318           else

(top-gdb) p *sym_arr[i1]
$2 = {ginfo = {name = 0xc739a0 &quot;Foo&quot;, value = {ivalue = 0, block = 0x0, bytes = 0x0, address = 0, chain = 0x0},
    language_specific = {cplus_specific = {demangled_name = 0x0}}, language = language_cplus, section = 0,
    obj_section = 0x0}, type = 0xc73930, symtab = 0xc954e0, domain = STRUCT_DOMAIN, aclass = LOC_TYPEDEF,
  is_argument = 0, is_inlined = 0, line = 1, ops = {ops_computed = 0x0, ops_register = 0x0}, aux_value = 0x0,
  hash_next = 0xc8ba00}

(top-gdb) p phys_name
$3 = 0xc6f0de &quot;Foo&quot;

&apos;phys_name&apos; isn&apos;t the link name of neither &apos;Foo::Foo()&apos; nor
&apos;Foo::Foo(const char *)&apos;, (those would be _ZN3FooC1Ev and _ZN3FooC2Ev) so
looking up on VAR_DOMAIN for &quot;Foo&quot; happens to find the typedef for
struct FOO instead of a FOO&apos;s methods (those have VAR_DOMAIN;LOC_BLOCK)...

To see what&apos;s going on with non-constructors, I&apos;ve added these to
struct Foo in the test case:

  void Bar();
  void Bar(const char *);

and here&apos;s what you get at the same place in the code:

(gdb) b Foo::Bar
(top-gdb) p phys_name
$4 = 0xc6f11f &quot;_ZN3Foo3BarEPKc&quot;
(top-gdb) p *sym_arr[i1]
$5 = {ginfo = {name = 0xc536f0 &quot;_ZN3Foo3BarEPKc&quot;, value = {ivalue = 13161920, block = 0xc8d5c0,
      bytes = 0xc8d5c0 &quot;\230\005@&quot;, address = 13161920, chain = 0xc8d5c0}, language_specific = {cplus_specific = {
        demangled_name = 0xc53700 &quot;Foo::Bar(char const*)&quot;}}, language = language_cplus, section = 12,
    obj_section = 0xc53280}, type = 0xc8d380, symtab = 0xc954e0, domain = VAR_DOMAIN, aclass = LOC_BLOCK,
  is_argument = 0, is_inlined = 0, line = 24, ops = {ops_computed = 0x7a1ce0, ops_register = 0x7a1ce0},
  aux_value = 0xc8d4a0, hash_next = 0xc8d6f0}

I&apos;d guess that at least, something would have to be done
so that &apos;phys_name&apos; on Foo&apos;s constructors is the proper
mangled name.

I wonder if archer-keiths-expr-cumulative archer branch has
a not-too-big-and-invasive fix for this.  I think that they
don&apos;t use mangled names anymore on that branch, so if fixed,
it may not be a small change though.
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>39822</commentid>
    <comment_count>3</comment_count>
    <who name="Keith Seitz">keiths</who>
    <bug_when>2009-11-16 19:38:18 +0000</bug_when>
    <thetext>Subject: Re:  Something fishy with constructors

On 11/16/2009 11:14 AM, pedro at codesourcery dot com wrote:
&gt; I wonder if archer-keiths-expr-cumulative archer branch has
&gt; a not-too-big-and-invasive fix for this.  I think that they
&gt; don&apos;t use mangled names anymore on that branch, so if fixed,
&gt; it may not be a small change though.

expr-cumulative should fix (some/all of?) these problems. Running the 
provided examples, I get:

$ ./gdb -nx -q ~/tmp/foo1
Reading symbols from /home/keiths/tmp/foo1...done.
(gdb) b Foo::Foo
Breakpoint 1 at 0x804847b: file foo.cc, line 5.

and

$ ./gdb -nx -q ~/tmp/foo2
Reading symbols from /home/keiths/tmp/foo2...done.
(gdb) b Foo::Foo
Breakpoint 1 at 0x804847b: file foo.cc, line 5.


I am working to get all these patches submitted upstream right now. I 
have, I think, one miscellaneous patch (which is actually Daniel&apos;s 
patch), and some ADA failures to investigate. When that&apos;s done, I will 
be ready to submit my &quot;mega-patch&quot; from expr-cumulative to get rid of 
linkage_name.

Keith
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>39825</commentid>
    <comment_count>4</comment_count>
    <who name="Pedro Alves">palves</who>
    <bug_when>2009-11-16 20:07:04 +0000</bug_when>
    <thetext>Subject: Re:  Something fishy with constructors

On Monday 16 November 2009 19:38:18, keiths at redhat dot com wrote:

&gt; expr-cumulative should fix (some/all of?) these problems.

Great!

&gt; I am working to get all these patches submitted upstream right now. I 
&gt; have, I think, one miscellaneous patch (which is actually Daniel&apos;s 
&gt; patch), and some ADA failures to investigate. When that&apos;s done, I will 
&gt; be ready to submit my &quot;mega-patch&quot; from expr-cumulative to get rid of 
&gt; linkage_name.

Looking forward for that!

If the new crash bothers people meanwhile, I suppose we could do
a quick bandaid like:

 - Have add_matching_methods call lookup_symbol_in_language
   with FUNCTIONS_DOMAIN (and make that work) instead of
   VAR_DOMAIN.  That still looks up for &quot;Foo&quot; multiple
   times, so &apos;b Foo::Foo&apos; would still display multiple entries
   for the same constructor...

 - Alternatively, do something like:

add_matching_methods:

      sym_arr[i1] = lookup_symbol_in_language (phys_name,
				   NULL, FUNCTIONS_DOMAIN,
				   language,
				   (int *) NULL);
-      if (sym_arr[i1])
+      /* See PR10966.  Remove check on symbol domain and class when
+         we stop using (bad) linkage names on constructors.  */
+      if (sym_arr[i1] &amp;&amp; (SYMBOL_DOMAIN (sym_arr[i1]) == VAR_DOMAIN
+                          &amp;&amp; SYMBOL_CLASS (sym_arr[i1]) == LOC_BLOCK))
	i1++;

   That is, simply ignore bad lookups...

Or just wait --- I&apos;m fine with that.  :-)
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>39827</commentid>
    <comment_count>5</comment_count>
    <who name="Pedro Alves">palves</who>
    <bug_when>2009-11-16 20:13:31 +0000</bug_when>
    <thetext>Subject: Re:  Something fishy with constructors

On Monday 16 November 2009 18:53:42, pedro at codesourcery dot com wrote:
&gt; On head:
&gt; 
&gt; (gdb) show multiple-symbols
&gt; How the debugger handles ambiguities in expressions is &quot;all&quot;.
&gt; 
&gt; (gdb) b Foo::Foo
&gt; [0] cancel
&gt; [1] all
&gt; ?HERE
&gt; ?HERE
&gt; &gt; 

For completeness: I forgot to paste the &apos;(gdb) set multiple-symbols ask&apos;
right before &apos;b Foo::Foo&apos; that I had typed in the console, so
that head does ask...
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>42024</commentid>
    <comment_count>6</comment_count>
    <who name="Tom Tromey">tromey</who>
    <bug_when>2010-03-15 17:33:48 +0000</bug_when>
    <thetext>This was fixed by the expr-cumulative/&quot;physname&quot; merge.
I tried both scenarios with cvs head and they seem to work for me.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>