Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import header file when debug in lldb

Tags:

xcode

lldb

Now we can import module

(lldb) expr @import UIKit

What's the meaning of this import? What happen to debugger when we import a module.

Can we use this to import some private header file in a static lib, and how?

like image 312
Karl Avatar asked Jun 12 '16 03:06

Karl


2 Answers

The example code and commands below illustrate some of Jim's answer:

Framework

This framework is called rusty_nails. It is shipped inside of my iOS app.

class Hello{
    static func world() {
        print("hello from a static method")
    }
}

debugger commands

Connect to your iOS app with lldb.

(lldb) po Hello()
error: use of undeclared identifier 'Hello'

(lldb) exp import rusty_nails
error: unknown type name 'import'

(lldb) settings set target.language swift
(lldb) exp import rusty_nails
(lldb) po Hello()
<Hello: 0x60000001a630>

(lldb) po Hello.world()
hello from a static method

Import syntax for lldb

(lldb) expr @import <stdbool.h>  // C and Objective-C
(lldb) exp import UIKit          // Swift

Help LLDB ( when project has Swift, Obj-C and C )

(lldb) po bool $foo = true; 
error: <EXPR>:3:5: error: consecutive statements on a line must be separated by ';'

(lldb) settings set target.language objc
(lldb) expr @import <stdbool.h> 
(lldb) po bool $foo = true; 
(lldb) po $foo
true
like image 119
rustyMagnet Avatar answered Nov 02 '22 05:11

rustyMagnet


Running @import <Framework> in the debugger does pretty much what it does in your source code, makes the types & method signatures available to the compiler that implements the lldb expression parser.

It doesn't make the code from the framework available, just the types, and it doesn't work for a random set of headers, only for a clang module with a proper module map.

If you want to introduce a few internal types into the debugger's expression parser, you can use the expression prefix setting target.expr-prefix.

like image 23
Jim Ingham Avatar answered Nov 02 '22 04:11

Jim Ingham