0

I run a new project. The project maybe downloads from the GitHub.

When I running the project. I want to log at the viewDidload function to help me see which controller is showing at the current time.

By the log, I can see the order of the different controllers loaded.

NSLog((@"%s [Line %d] "), __PRETTY_FUNCTION__, __LINE__);
I type this code in the viewDidLoad function, it works well.

@implementation STListController

- (void)viewDidLoad {
    [super viewDidLoad];        

    NSLog((@"%s [Line %d] " ), __PRETTY_FUNCTION__, __LINE__);

In the console:

2018-06-14 12:03:09.740756+0800 SwipeTableView[10634:1105858] -[STListController viewDidLoad] [Line 23]

Then I set a Symbolic Breakpoint

enter image description here

To my surprise, the log is wrong. The log by the breakpoint doesn't show as the log code.

2018-06-14 12:05:58.427936+0800 SwipeTableView[10789:1113954] void $__lldb_expr(void *) [Line 45] 0x73ef013aaa6a000d

2018-06-14 12:06:00.168679+0800 SwipeTableView[10789:1113954] void $__lldb_expr(void *) [Line 45] 0x73ef013aaa6a000d

2018-06-14 12:06:01.858458+0800 SwipeTableView[10789:1113954] -[STListController viewDidLoad] [Line 23]

As you see the third log is right.

In the Edit Breakpoints action, NSLog((@"%s [Line %d] "), __PRETTY_FUNCTION__, __LINE__); can't show the same log. The good log is NSLog((@"%s [Line %d] "), __PRETTY_FUNCTION__, __LINE__); in the code.

I hunt this question. Logging the class name of all UIViewControllers in a project The top answer is perfect to me. I don't find the lldb answer.

jiexishede
  • 2,473
  • 6
  • 38
  • 54

1 Answers1

2

I'm not sure why you say the third log is right, or exactly what you were expecting to see.

You set a breakpoint to stop the program in the method -[UIViewController viewDidLoad] and so it stopped there. Now, when lldb runs expressions, its job is to run them "as if they had been inserted in the code at the point where you are currently stopped" which is -[UIViewController viewDidLoad]... So the right answer for __PRETTY_FUNCTION__ should have been -[UIViewController viewDidLoad].

However, lldb's emulation of the current frame for expressions doesn't go so far as to get these tokens to report the values they would have had had the expression been compiled in the code that generated the instruction you're currently stopped at. So these tokens are just getting some random values.

Getting them right might be possible, but seems like way more trouble than it's worth, since you are already stopped in the debugger in that frame. The lldb command

(lldb) f 0

will tell you where you are much more straightforwardly.

BTW, one of the tricks lldb plays to emulate the current frame is to make a category on the class of the current frame, insert a new method for that class, insert your expression in that method, and call it passing in the stop frame's self. That way lldb gets references to ivars & methods to work as expected. NSLog always prepends the log by a time stamp and the most specific class for self. That's why you consistently see a sensible class name after the timestamp.

If you tell us more about what information you were actually trying to record, perhaps we can be of more help with that.

Jim Ingham
  • 25,260
  • 2
  • 55
  • 63
  • lngham Only the third log shows "viewDidlod" and line number. – jiexishede Jun 14 '18 at 03:57
  • lngham Your idea is using the runtime to change the implementation to change the system "viewDidLoad". It's cool. I run a new project. The project maybe downloads from the GitHub. I want to log the viewDidload order to help me read the project. – jiexishede Jun 14 '18 at 06:03