So what is wrong with v3 C++

Daniel Berlin
Fri Jun 29 08:59:00 GMT 2001

Michael Elizabeth Chastain <> writes:

> Dan Berlin writes:
>> 1. Template functions (names or types) have return types encoded,
>>    with the exceptions listed below.
> Okay, we must comply with the ABI, then.
>> You seem to want to get rid of return types from mangled names for
>> templates. This ain't gonna ever happen. It's done on purpose, it's
>> not an accident.
> No, first I want to know what the spec requires.  The ABI spec wants the
> information to be present in the mangled name.  Now follow the information
> flow:
>   mangled name -> demangled name (demangler)
>   demangled name -> user visible and user matchable names (gdb)
> I accept the ABI spec, and I'm comfortable with the demangler preserving
> all the information including the return type.
> We still have to figure out what to do if the user types:
>   (gdb) break add_two_values
> ... when add_two_values is a template.

What we really should be doing is something like find_methods, except
including templates.
That way, we could present a list like:

add_two_values<int, int>
add_two_values<float, int>

And let the user decide which ones they wanted breakpointed.

> One option is to propagate this "return type in the name" all the way
> through to the user, and mention it in the documentation.  So the
> user really would have to type:
>   (gdb) break 'int add_two_values<int,int>TAB
Oh, I see what you mean.

However, note, the new dwarf2 reader should fix this problem as well.

It was the reliance on mangled names that gave the return type.

Ah, yes.
Hand verified to be mostly fixed in the new d2 reader.

(gdb) b 'add_two_values<int>'
Breakpoint 1 at 0x10000830: file, line 3.

There is a mismatch in the new d2 reader between psymbol names and
symbol names, because i haven't quite gotten scoping into the
psymbols.  So if you did "info func add", it would show
"int add_two_values<int> (int, int)".

However, this bug also causes b 'int add_two_values<int> (int, int)'
to work, just like it used to.

STABS isn't possible to fix without generating it's own qualified
names, which won't work with namespaces.

So we'll probably need to document the difference anyway.

>> LD, c++filt, nm, objdump, etc all use it.
>> GDB seems to *depend* on it more, but this is not a good thing. We
>> depend on mangled names too much.
> nm, objdump, and c++filt just use demangling in their output.
> As far as I know, ld operates the same way.  Does it ever demangle a name
> and use the result for anything except error printing?

I have no idea. I'll check.
> gdb is the only tool I know where people type in names and the tool
> has to match against demangled forms.

The thing is, it shouldn't match against demangled forms, it should
match against *fully qualified* forms.

When talking about symbols in C++, do you say "Yeah, look at the int
a::b(int a, int b) function." or "Yeah, look at the a::b function".

The whole reason we do demangled forms is because of limitations of
STABS (lack of namespace support, etc) that don't allow us to do full
qualified names.

However, using demangled forms gives us an interface that isn't quite
what the user expects, and causes us problems elsewhere.

It's okay to use the internally, but we really shouldn't expose them
to the user.

Think of it as if you had to write code like this:

int main(void)
        Aclass a;
        int c;
        c = int a::george(int, int)(5, 6);
That's what we've got now.

Of course, because STABS *won't* (IIRC, thinks like Third Eye do
support it) allow us to handle namespaces properly, I don't expect to
see this changed, and would fight it, for a few more years, until
STABS is much less prevalent.

> If you are suggesting that the demangler should return a nice tree
> of information, instead of gdb doing its own re-parsing, I'm in favor
> of that.
>> I've already rewritten the dwarf2 reader, including the scope work.
>> There would be little point in JimB rewriting it again.
> I saw the patch.
> Do you have any test results, or plans for getting it tested?

After I fix the known bugs, i'm going to start running the regression
tests and fixing those bugs.

Once we either end up with no regressions, or doing better than we
used to, i'll submit it for approval.

> Michael

"I owed my friend George $25.  For about three weeks I owed it to
him.  The whole time I had the money on me -- he didn't know it.
Walking through New York City, 2:30 in the morning and got held
up.  He said, "Gimme all your money."  I said, "Wait a minute."
I said, "George, here's the 25 dollars I owe you."  The the
thief took a thousand dollars out of his own money and he gave
it to George.  At gunpoint made me borrow a thousand dollars
from George.
"-Steven Wright

More information about the Gdb mailing list