Re: [rfc] Be in language c more c++ compatible

Matt Rice
2011-07-23T21:17:59Z

[-- Attachment #1: Type: text/plain, Size: 1529 bytes --]

On Fri, Jul 15, 2011 at 12:19 PM, Jan Kratochvil
<jan.kratochvil@redhat.com> wrote:
> Hi,
>
> I always see some terrible C++ GDB bug so I fix in some hours and then find out
> it works in GDB when one has `set language c++'.  This usually happens with
> artificial testcases like the one today:
>        http://sourceware.org/ml/gdb-patches/2011-07/msg00387.html

was curious what it did with the attached objc++ version.

which isn't really a supported language by any means.
gdb considers it to be 'minimal'/doesn't recognize the CU language in
the debuginfo. and it is difficult to say how meaningful it would be
if it did.
I imagine gdb wants DW_TAG_partial_unit/DW_AT_language when
switching between c++/objective-c functions, I hadn't been able to
coax this out of gcc

anyhow the last line was a bit suprising.

gcc -g -o objcxx objc++.mm -lobjc

GNU gdb (GDB) Fedora (7.2-51.fc14)
(gdb) set language c++
(gdb) whatis C::t
No symbol "C" in current context.
(gdb) set language objective-c
(gdb) whatis C::t
No symbol "C" in current context.
(gdb) break main
Breakpoint 1 at 0x400808: file objc++.mm, line 47.
(gdb) r
Breakpoint 1, main () at objc++.mm:47
47 Foo *foo = [[Foo alloc] init];
Warning: the current language does not match this frame.
(gdb) whatis C::t
type = t
(gdb) show language
The current source language is "objective-c".
Warning: the current language does not match this frame.
(gdb) set language c++
(gdb) whatis C::t
A syntax error in expression, near `'.

[-- Attachment #2: objc++.mm --]
[-- Type: text/plain, Size: 441 bytes --]

#include <objc/Object.h>

class C {
public:
typedef int t;
C();
C(t);
t i;
} c;

C::C()
{
i = 9;
}

C::C(t x)
{
i = x;
}

@interface Foo : Object
{
@public
C::t i;
}
- (C::t) bar;
@end

@implementation Foo
- (id) init
{
if ((self = [super init]))
i = 5;

return self;
}

- (C::t) bar
{
return i;
}

@end

int main()
{
Foo *foo = [[Foo alloc] init];
C c = C([foo bar]);
printf("%i %i\n", foo->i, c.i);
}