-
Notifications
You must be signed in to change notification settings - Fork 21
/
409 Introduction to LLDB and the Swift Repl [English].srt
3571 lines (2811 loc) · 66.4 KB
/
409 Introduction to LLDB and the Swift Repl [English].srt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1
00:00:14,000 --> 00:00:16,001
good morning I'm
2
00:00:16,001 --> 00:00:17,098
on countdown
3
00:00:17,098 --> 00:00:21,105
you thank you arm I work on the debugger
team
4
00:00:22,005 --> 00:00:25,080
at Apple and I'm really excited to show
you this
5
00:00:25,008 --> 00:00:29,021
stuff today now a funny thing before
6
00:00:29,093 --> 00:00:33,098
when I was preparing the slides I
thought by the time I'm giving this talk
7
00:00:33,098 --> 00:00:36,165
maybe some people have looked at the
language manual for swift maybe some
8
00:00:37,065 --> 00:00:38,107
people have tried a playground
9
00:00:39,007 --> 00:00:45,029
it's gone a little faster than that I am
really impressed
10
00:00:45,029 --> 00:00:48,042
you guys I look on the lobs I look on
Twitter
11
00:00:48,042 --> 00:00:51,137
you guys have ap started already entire
ops running in swift
12
00:00:52,037 --> 00:00:56,103
I saw somebody with a rate racer it's
crazy I'm
13
00:00:57,003 --> 00:01:00,059
this is the sort of thing that makes me
happy to be working at Apple
14
00:01:00,059 --> 00:01:03,059
you guys are such awesome developers
it's really just an
15
00:01:03,059 --> 00:01:10,059
honor to write the tools you use thank
you very much
16
00:01:11,081 --> 00:01:13,113
cell I'm gonna tell you
17
00:01:14,013 --> 00:01:18,034
about using lol TB and a swift rebel now
18
00:01:18,034 --> 00:01:22,523
as you're writing a swift top you're
probably gonna write one or two lines up
19
00:01:22,829 --> 00:01:23,560
by key code
20
00:01:23,056 --> 00:01:26,132
and that's where I want to be fit and
now
21
00:01:27,032 --> 00:01:30,089
the good news is lol GB is better than
it's ever been
22
00:01:30,089 --> 00:01:35,106
were swept I'm gonna tell you about some
of the basic features that all to be
23
00:01:36,006 --> 00:01:38,010
house to help you find bugs in your
program
24
00:01:38,046 --> 00:01:41,053
I want to be as its core
25
00:01:41,053 --> 00:01:45,124
is a tool to help you fix problems in
your code it's got
26
00:01:46,024 --> 00:01:49,723
a great set of basic features for
tracking down
27
00:01:49,939 --> 00:01:53,018
where your bugs are ok the first wall
28
00:01:53,729 --> 00:01:56,793
as the stock the stock
29
00:01:57,369 --> 00:02:00,530
is a for is a tool that lets you look
30
00:02:00,053 --> 00:02:04,084
at why the your program is stopped
downed
31
00:02:04,084 --> 00:02:07,120
what functions got called to get you to
the point
32
00:02:08,002 --> 00:02:11,041
where your program stopped now
33
00:02:11,059 --> 00:02:14,788
your program doesn't always obediently
stop where you want it to
34
00:02:15,319 --> 00:02:21,440
in that case you need break points break
points or another great tool LTB
35
00:02:21,044 --> 00:02:24,122
provides that much you stop whenever you
want to
36
00:02:25,022 --> 00:02:30,026
finally no matter how you stop your
program
37
00:02:30,026 --> 00:02:34,595
we have a great expression command that
lets you inspector data
38
00:02:34,829 --> 00:02:39,880
right at the point where your program
stopped and today's presentation
39
00:02:39,088 --> 00:02:43,175
I'm gonna show you these tools working
with swift the good news is
40
00:02:44,075 --> 00:02:47,654
the compounds are basically the same as
they used to be
41
00:02:48,329 --> 00:02:52,100
but I'm gonna show you how to find some
familiar box
42
00:02:52,001 --> 00:02:56,034
but you may have seen before and also a
couple of new ones
43
00:02:56,043 --> 00:03:01,066
that are introduced when you're working
with swept now
44
00:03:01,066 --> 00:03:06,015
the cool thing is this is an all I have
to talk about
45
00:03:06,609 --> 00:03:11,170
we now have a rebel to the swift rebel
46
00:03:11,017 --> 00:03:18,017
is built on topic lol to be you can
access it just
47
00:03:18,006 --> 00:03:22,089
at the old to be command prompt and you
time
48
00:03:23,043 --> 00:03:27,872
that you're debugging a program that's
not although
49
00:03:28,259 --> 00:03:32,266
you can also access the swift trouble
when you don't have a program running
50
00:03:32,329 --> 00:03:37,100
you can access it directly off at the
shell prompt for a clean slate
51
00:03:37,001 --> 00:03:40,360
I'm gonna tell you lots more about
interacting with the
52
00:03:40,459 --> 00:03:44,474
rebel later but there are two basic ways
that we want you to use
53
00:03:44,609 --> 00:03:49,090
the rebel the first is when you've got a
program
54
00:03:49,009 --> 00:03:52,618
with some code and would like to find
out
55
00:03:52,699 --> 00:03:55,740
if it works if it's doing what you
expected to
56
00:03:56,109 --> 00:03:59,470
you can use this ltp rebel
57
00:03:59,047 --> 00:04:03,806
to test your app interactively another
great use for those
58
00:04:04,229 --> 00:04:07,242
LTB rebel is to add new code
59
00:04:07,359 --> 00:04:10,444
you can call right new functions new
classes
60
00:04:11,209 --> 00:04:15,680
in an existing LDP session and they get
put into your code and they can interact
61
00:04:15,068 --> 00:04:17,367
with your code just as if you threaten
them
62
00:04:17,979 --> 00:04:22,970
in your source files now
63
00:04:22,097 --> 00:04:26,166
if you've noticed one theme this year
64
00:04:27,039 --> 00:04:30,114
one thing but kind of over and over
we're seeing
65
00:04:30,789 --> 00:04:34,610
and all the presentation starting right
at the keynote is how everything seems a
66
00:04:34,061 --> 00:04:35,096
little bit more alive
67
00:04:35,096 --> 00:04:38,097
everything's a little bit more
interactive stops coming in Christ
68
00:04:39,006 --> 00:04:40,019
telling you about his hair
69
00:04:40,019 --> 00:04:43,053
its everything's everything's much more
70
00:04:43,053 --> 00:04:46,150
immediate and I want to be as the same
way
71
00:04:47,005 --> 00:04:50,021
now we have a couple of tools that
72
00:04:50,066 --> 00:04:54,110
art that already existed that are very
interactive and we're adding more this
73
00:04:55,001 --> 00:04:55,054
year
74
00:04:55,063 --> 00:04:58,162
first of all you happy expression
command
75
00:04:59,062 --> 00:05:02,158
as I alluded to earlier that's a great
way for when you're stopped
76
00:05:03,058 --> 00:05:06,237
to poke at your variables to call a
couple of local functions
77
00:05:06,759 --> 00:05:10,550
we also have if you're
78
00:05:10,055 --> 00:05:13,088
a little bit more experienced old to be
users may be watch them some of our
79
00:05:13,088 --> 00:05:14,377
previous session videos
80
00:05:15,169 --> 00:05:19,600
lol to be Python scripting I'm not gonna
tell you too much about that
81
00:05:19,006 --> 00:05:23,071
in this session but it's a great way to
create new debugger features
82
00:05:24,025 --> 00:05:27,664
and automate your debugging processes
83
00:05:27,889 --> 00:05:32,260
this year we've added playgrounds which
allow you to prototype
84
00:05:32,026 --> 00:05:36,041
entire new algorithms from scratch and
learn API's
85
00:05:36,041 --> 00:05:39,049
and we've also added the Lobb rebel
86
00:05:39,049 --> 00:05:43,147
now what's the difference between the
LDP rebel and playgrounds
87
00:05:44,047 --> 00:05:48,084
playgrounds as I told you and as you saw
in Wednesday's demo which
88
00:05:48,084 --> 00:05:52,142
reckon Connor showed you all the
fantastic ways you can use playgrounds
89
00:05:53,042 --> 00:05:56,141
playgrounds works from a blank slate
you've got a text editor
90
00:05:57,041 --> 00:06:00,074
you import the stuff you want to import
when you write some code
91
00:06:00,074 --> 00:06:03,128
and you see how it works on the other
hand
92
00:06:04,028 --> 00:06:08,035
the point that the LTB rebel is to let
you
93
00:06:08,035 --> 00:06:15,035
investigate how code would work if it
were inside your pre-existing program
94
00:06:16,072 --> 00:06:19,107
now in today's session I'm gonna give
you
95
00:06:20,007 --> 00:06:23,012
to basic things first
96
00:06:23,012 --> 00:06:26,103
an overview are the kind of beat skills
that you're going to want to apply just
97
00:06:27,003 --> 00:06:32,008
working with lol to be in your regular
debugging
98
00:06:32,008 --> 00:06:35,101
and then I'm gonna tell you about some
new debugging workflows
99
00:06:36,001 --> 00:06:39,880
the torch swift rebel enables
100
00:06:39,889 --> 00:06:46,889
finally I'm gonna sum up and tell you
where you can go for more information
101
00:06:48,006 --> 00:06:52,585
sup lots jump right into basic debugging
102
00:06:52,639 --> 00:06:55,680
now in this slides I'm going to show you
103
00:06:55,068 --> 00:06:58,074
interactions with lol TB but really
104
00:06:58,074 --> 00:07:01,173
there's two basic ways of talking to Ala
to be
105
00:07:02,073 --> 00:07:05,088
the one is if you're inside Xcode
106
00:07:05,088 --> 00:07:09,116
in Xcode you have the debugger console
which is usually at the bottom of your
107
00:07:10,016 --> 00:07:13,055
window when you're debugging
108
00:07:13,055 --> 00:07:16,106
you can work with the debugger console
an answer compounds
109
00:07:17,006 --> 00:07:20,075
and also Xcode provides you with a bunch
of you why features
110
00:07:20,075 --> 00:07:25,128
that but you automatic but but you
automate certain things like stopping
111
00:07:26,028 --> 00:07:29,035
there's another way of working with LTP
112
00:07:29,035 --> 00:07:32,126
but some %uh view more experienced users
may use from time to time
113
00:07:33,026 --> 00:07:37,078
and that's the terminal the RTB command
line interface
114
00:07:37,078 --> 00:07:41,078
uses the exact same commands that you're
familiar with with typing and commands
115
00:07:41,078 --> 00:07:42,173
in Xcode
116
00:07:43,073 --> 00:07:46,074
I'm going to show you the command line
interface
117
00:07:46,074 --> 00:07:50,082
but there's great sessions I'll tell you
why later the tell you more about how to
118
00:07:50,082 --> 00:07:54,088
use that through Xcode
119
00:07:54,088 --> 00:07:57,132
now this is up situation
120
00:07:58,032 --> 00:08:02,411
but probably all all if you have run
into at one time or another
121
00:08:02,699 --> 00:08:07,530
you're debugging along in your program
and your program crashes
122
00:08:07,053 --> 00:08:10,118
it stopped and now the question is well
what do i do there's all this
123
00:08:11,018 --> 00:08:13,079
information here
124
00:08:13,079 --> 00:08:16,156
there are couple basic questions but you
should be asking
125
00:08:17,056 --> 00:08:20,150
that will help you find your back as
quickly as possible
126
00:08:21,005 --> 00:08:26,032
the first is what is the stop a reason
wire we stopped
127
00:08:26,077 --> 00:08:30,136
the stop reason is a facility that Ltd
provides
128
00:08:31,036 --> 00:08:35,125
the tells you why are your program its
was told to stop
129
00:08:36,025 --> 00:08:39,544
something makes it stop
130
00:08:39,769 --> 00:08:42,820
the next question is alright well I know
wop
131
00:08:43,279 --> 00:08:47,285
mmm dot the program was told to stop how
to get there
132
00:08:47,339 --> 00:08:50,420
what code around to get us to this bad
point
133
00:08:51,149 --> 00:08:55,180
this is where you use the stock as I
alluded to earlier
134
00:08:55,018 --> 00:08:58,061
you want to look up the stock and find
your own code
135
00:08:58,061 --> 00:09:02,069
so look for all the framework code look
through all the standard library code
136
00:09:02,069 --> 00:09:06,518
and find frames in your own code that
are responsible for this
137
00:09:07,139 --> 00:09:10,500
once you have located the place where
things might have gone wrong
138
00:09:10,005 --> 00:09:13,027
than you can start investigating the
failure conditions looking at your
139
00:09:13,072 --> 00:09:13,147
variables
140
00:09:14,047 --> 00:09:20,085
and seeing what variable values might
have gotten you into a bad state
141
00:09:20,085 --> 00:09:23,157
so let's get started and look at
applying these basic techniques
142
00:09:24,057 --> 00:09:30,079
to some crap to some crashes you might
see out in the world
143
00:09:30,079 --> 00:09:35,118
now but their programs crashed the first
question as I told you what you want to
144
00:09:35,829 --> 00:09:36,350
know
145
00:09:36,035 --> 00:09:40,080
the stock reason why did it crash
146
00:09:40,008 --> 00:09:43,020
but command that helps you find this
information is called
147
00:09:43,092 --> 00:09:48,129
thread intro now I'm showing you two
versions of the command here
148
00:09:49,029 --> 00:09:52,068
they both do the exact same thing
149
00:09:52,068 --> 00:09:55,135
it's just that the short version TI
150
00:09:56,035 --> 00:10:00,070
is very quick to type and if you're
doing repeated stops and you're trying
151
00:10:00,007 --> 00:10:01,059
to get their work done quickly
152
00:10:02,022 --> 00:10:06,081
know probably use short versions the
commands there's also a long long
153
00:10:06,279 --> 00:10:07,720
version of the command
154
00:10:07,072 --> 00:10:10,075
now there are two reasons why this might
be helpful
155
00:10:10,075 --> 00:10:14,108
the first is it's more explicit about
what you're doing
156
00:10:15,008 --> 00:10:18,517
and the second thing is you can find it
in the help
157
00:10:18,589 --> 00:10:22,300
so if you use the Help commander the
Opera poke a mountain lol DB
158
00:10:22,003 --> 00:10:25,005
you can find this command very easily
159
00:10:25,005 --> 00:10:28,012
now let's say you type thread and for
what the hell to be prompt
160
00:10:28,057 --> 00:10:32,149
you're gonna got some information about
the thread that's currently stopped
161
00:10:33,049 --> 00:10:37,056
there's two pieces of information but
you want to know when you're crashed
162
00:10:38,019 --> 00:10:41,047
the first is what piece of code crashed
163
00:10:41,047 --> 00:10:44,068
in this case were stopped in a function
called swift
164
00:10:44,068 --> 00:10:47,070
top underscore get optional value
165
00:10:47,088 --> 00:10:50,105
now the swift underscore pop as a swift
top part
166
00:10:51,005 --> 00:10:54,234
is very important here because it tells
you
167
00:10:54,279 --> 00:10:57,680
but you're inside the key swift module
168
00:10:57,068 --> 00:11:00,156
the swift module is the swift standard
library so we are you know
169
00:11:01,056 --> 00:11:04,081
but standard library code crashed
170
00:11:04,081 --> 00:11:07,142
now what was the reason that it did for
crushing
171
00:11:08,042 --> 00:11:11,057
the reason is a bad instruction
172
00:11:11,057 --> 00:11:15,516
now some of you may cutscene this
message before
173
00:11:16,029 --> 00:11:19,630
about instruction is when the CPU
doesn't understand the instruction
174
00:11:19,063 --> 00:11:20,144
that's being given
175
00:11:21,044 --> 00:11:24,083
but wait a second we've got a compiler
error that's
176
00:11:24,083 --> 00:11:29,086
being pretty smart about and issuing the
right instructions what's going on here
177
00:11:30,013 --> 00:11:34,062
well it turns out but much ninety-nine
percent of the time despite instructions
178
00:11:34,062 --> 00:11:36,099
are used in assertions
179
00:11:36,099 --> 00:11:39,197
soil the code says if something is bad
180
00:11:40,097 --> 00:11:43,163
if something unexpected is happening I'm
going to issue about instruction to the
181
00:11:44,063 --> 00:11:46,142
CPU in the program will stop
182
00:11:47,042 --> 00:11:50,057
so when you see your ex about
instruction what you should be thinking
183
00:11:50,057 --> 00:11:50,064
as
184
00:11:51,027 --> 00:11:56,036
assertion failure now
185
00:11:56,279 --> 00:11:59,740
what we can see from the stop reason
without even looking at the stocker and
186
00:11:59,074 --> 00:12:00,080
if the stock frames
187
00:12:00,008 --> 00:12:03,417
is that we failed an assertion in the
standard library
188
00:12:04,209 --> 00:12:09,520
know what might cause that to happen
okay let's move on and have a lock
189
00:12:09,052 --> 00:12:13,060
the next commander gonna wanna use is
the back trace command
190
00:12:13,006 --> 00:12:16,031
the thread back trace command Prince
191
00:12:16,085 --> 00:12:19,136
all the frames on the car stock up the
current thread
192
00:12:20,036 --> 00:12:23,123
that is it tells you what functions
called each other
193
00:12:24,023 --> 00:12:28,041
on the current thread to get you to the
point where you've stopped
194
00:12:28,041 --> 00:12:32,045
in this case we see but just below the
195
00:12:32,045 --> 00:12:35,137
the the function but was actually crop
stopped
196
00:12:36,037 --> 00:12:40,126
you see your own code now this top-level
code function
197
00:12:41,026 --> 00:12:45,058
may be familiar to you if you played
around with with command-line tools
198
00:12:45,058 --> 00:12:49,687
that's the code but outside any function
in your main source file
199
00:12:50,209 --> 00:12:55,278
other command line tool so you recognize
this top-level Cody you say aha
200
00:12:55,899 --> 00:13:01,240
this is my code but Apple ok top-level
code is frame number one
201
00:13:01,024 --> 00:13:05,026
cell that means we called directly into
the standard library and an assertion
202
00:13:05,026 --> 00:13:07,061
failed:
203
00:13:07,061 --> 00:13:10,085
let's have a look at why that happened
well
204
00:13:10,085 --> 00:13:15,090
we select the first frame and now we
have information about the source code
205
00:13:16,035 --> 00:13:19,114
because it's your own code and we have
to
206
00:13:20,014 --> 00:13:24,050
here we see that we've got on optional
and the object
207
00:13:24,005 --> 00:13:27,077
that we got from a source that looks a
little shady
208
00:13:28,022 --> 00:13:32,099
and then we unwrapped not optional
without checking well
209
00:13:32,099 --> 00:13:36,116
turns out if you print the value of that
on drop knocked out optional
210
00:13:37,016 --> 00:13:41,022
you see that optional is non well
211
00:13:41,076 --> 00:13:44,149
thats but not too difficult to fix you
instead try
212
00:13:45,049 --> 00:13:48,122
if not and that will let you and and
that will make the
213
00:13:49,022 --> 00:13:53,076
unwrapping code conditional on there