lldb crash

I've got crash when was trying to call GetNumChildren of value which I got from EvaluateExpression method.

We have class:

@interface Item : NSObject {
    NSString *title;
    NSString *type;

@property(retain)NSString* title;
//... and some other stupid stuff

I'm trying to evaluate expression "[item title]"
Value is ok. But when GetNumChildren is invoked i've got crash:

static bool
GetCompleteQualType (clang::ASTContext *ast, clang::QualType qual_type) {

case clang::Type::ObjCInterface:
            const clang::ObjCObjectType *objc_class_type = dyn_cast<clang::ObjCObjectType>(qual_type);
            if (objc_class_type)
                clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
                // We currently can't complete objective C types through the newly added ASTContext
                // because it only supports TagDecl objects right now...
                bool is_forward_decl = class_interface_decl->isForwardDecl(); // !! <----- crashed here. class_interface_decl == NULL
Sorry for screenshot instead of normal crash dump. =( I just was not able to get it.

Screen shot 2011-07-14 at 15.55.09.png

You might be pleased to know that this bug is fixed in the latest LLDB.

What follows is an LLDB session printout, with the interesting lines bolded

da0603a-dhcp151:Debug egranata$ ./lldb andrey
Current executable set to ‘andrey’ (x86_64).
(lldb) b main
runbreakpoint set --name ‘main’
Breakpoint created: 1: name = ‘main’, locations = 1
(lldb) run
Process 71825 launched: ‘/Volumes/work/egranata/lldb/build/Debug/andrey’ (x86_64)
Process 71825 stopped

  • thread #1: tid = 0x2e03, 0x0000000100000d94 andreymain + 4 at andrey.m:18, stop reason = breakpoint 1.1 frame #0: 0x0000000100000d94 andreymain + 4 at andrey.m:18
    16 int main()
    17 {
    → 18 Item *itm = [[Item alloc] init];
    20 itm.title = @“Hello world”;
    (lldb) n
    Process 71825 stopped
  • thread #1: tid = 0x2e03, 0x0000000100000ddb andreymain + 75 at andrey.m:20, stop reason = step over frame #0: 0x0000000100000ddb andreymain + 75 at andrey.m:20
    17 {
    18 Item *itm = [[Item alloc] init];
    → 20 itm.title = @“Hello world”;
    22 itm.title = @“Try again”;
    (lldb) n
    Process 71825 stopped
  • thread #1: tid = 0x2e03, 0x0000000100000e00 andreymain + 112 at andrey.m:22, stop reason = step over frame #0: 0x0000000100000e00 andreymain + 112 at andrey.m:22
    20 itm.title = @“Hello world”;
    → 22 itm.title = @“Try again”;
    24 return 0;
    (lldb) expr (char*)[[itm title] UTF8String]
    (char *) $0 = 0x000000010010cdc0 "Hello world"

You can get the latest LLDB source from the project website and build it yourself. This should be enough to solve your crash

Thanks for your interest in LLDB :slight_smile:

Hi, Enrico!
Thank you for consideration of my problem.
But your listing doesn’t show described problem because “expr (char*)[[itm title] UTF8String]” doesn’t invoke GetNumChildren method of SBValue. But if you do it (e.g. from python script) you’ll get the crash.
It’s reproduced with latest sources. (tried right now)

Fixing this problem will make this feature work:

Xcode have the similar one in the variables view. But it doesn’t work. And if Xcode team will fix that issue with “Invalid expression” they will face the described one =(
Thank you for consideration.

It is quite strange that the problem is occurring to you even using the latest LLDB. I tried to stick exactly to what you had typed: “expr [item title]”, and still I do not get a crash:

(lldb) expr [item title]
(NSString *) $1 = 0x0000000100001238

Moreover, while I have not really had a chance to debug the debugger’s evaluation of your expression, the code snippet that you pinpoint as the culprit (dereferencing a NULL pointer in GetCompleteQualType()), is fixed now:

case clang::Type::ObjCObject:
case clang::Type::ObjCInterface:
const clang::ObjCObjectType *objc_class_type = dyn_castclang::ObjCObjectType(qual_type);
if (objc_class_type)
clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
// We currently can’t complete objective C types through the newly added ASTContext
// because it only supports TagDecl objects right now…
bool is_forward_decl = class_interface_decl->isForwardDecl(); ← only do it if class_interface_decl is not NULL

You might want to make sure you have grabbed the recent-most LLDB source code from the SVN repository. And, if this still not helps, probably sharing your source code so others can experiment with it and check exactly what is going wrong might be a good idea :).

Thanks again for your interest in LLDB.

Oh… Sorry. Now I see.
I had an issue with Xcode project layout so that build products was copied in bad place and I was linking against old framework.
Sorry for disturbing.
AppCode’s lldb front-end will be ready for try very soon =)
Thank you.