SBBreakpoint.cpp
34.2 KB
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
//===-- SBBreakpoint.cpp ----------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lldb/API/SBBreakpoint.h"
#include "SBReproducerPrivate.h"
#include "lldb/API/SBBreakpointLocation.h"
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBEvent.h"
#include "lldb/API/SBProcess.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBStringList.h"
#include "lldb/API/SBStructuredData.h"
#include "lldb/API/SBThread.h"
#include "lldb/Breakpoint/Breakpoint.h"
#include "lldb/Breakpoint/BreakpointIDList.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Breakpoint/BreakpointResolver.h"
#include "lldb/Breakpoint/BreakpointResolverScripted.h"
#include "lldb/Breakpoint/StoppointCallbackContext.h"
#include "lldb/Core/Address.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Core/StructuredDataImpl.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/ScriptInterpreter.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadSpec.h"
#include "lldb/Utility/Stream.h"
#include "SBBreakpointOptionCommon.h"
#include "lldb/lldb-enumerations.h"
#include "llvm/ADT/STLExtras.h"
using namespace lldb;
using namespace lldb_private;
SBBreakpoint::SBBreakpoint() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBBreakpoint); }
SBBreakpoint::SBBreakpoint(const SBBreakpoint &rhs)
: m_opaque_wp(rhs.m_opaque_wp) {
LLDB_RECORD_CONSTRUCTOR(SBBreakpoint, (const lldb::SBBreakpoint &), rhs);
}
SBBreakpoint::SBBreakpoint(const lldb::BreakpointSP &bp_sp)
: m_opaque_wp(bp_sp) {
LLDB_RECORD_CONSTRUCTOR(SBBreakpoint, (const lldb::BreakpointSP &), bp_sp);
}
SBBreakpoint::~SBBreakpoint() = default;
const SBBreakpoint &SBBreakpoint::operator=(const SBBreakpoint &rhs) {
LLDB_RECORD_METHOD(const lldb::SBBreakpoint &,
SBBreakpoint, operator=,(const lldb::SBBreakpoint &), rhs);
m_opaque_wp = rhs.m_opaque_wp;
return LLDB_RECORD_RESULT(*this);
}
bool SBBreakpoint::operator==(const lldb::SBBreakpoint &rhs) {
LLDB_RECORD_METHOD(
bool, SBBreakpoint, operator==,(const lldb::SBBreakpoint &), rhs);
return m_opaque_wp.lock() == rhs.m_opaque_wp.lock();
}
bool SBBreakpoint::operator!=(const lldb::SBBreakpoint &rhs) {
LLDB_RECORD_METHOD(
bool, SBBreakpoint, operator!=,(const lldb::SBBreakpoint &), rhs);
return m_opaque_wp.lock() != rhs.m_opaque_wp.lock();
}
break_id_t SBBreakpoint::GetID() const {
LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::break_id_t, SBBreakpoint, GetID);
break_id_t break_id = LLDB_INVALID_BREAK_ID;
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp)
break_id = bkpt_sp->GetID();
return break_id;
}
bool SBBreakpoint::IsValid() const {
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpoint, IsValid);
return this->operator bool();
}
SBBreakpoint::operator bool() const {
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpoint, operator bool);
BreakpointSP bkpt_sp = GetSP();
if (!bkpt_sp)
return false;
else if (bkpt_sp->GetTarget().GetBreakpointByID(bkpt_sp->GetID()))
return true;
else
return false;
}
void SBBreakpoint::ClearAllBreakpointSites() {
LLDB_RECORD_METHOD_NO_ARGS(void, SBBreakpoint, ClearAllBreakpointSites);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
bkpt_sp->ClearAllBreakpointSites();
}
}
SBBreakpointLocation SBBreakpoint::FindLocationByAddress(addr_t vm_addr) {
LLDB_RECORD_METHOD(lldb::SBBreakpointLocation, SBBreakpoint,
FindLocationByAddress, (lldb::addr_t), vm_addr);
SBBreakpointLocation sb_bp_location;
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
if (vm_addr != LLDB_INVALID_ADDRESS) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
Address address;
Target &target = bkpt_sp->GetTarget();
if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) {
address.SetRawAddress(vm_addr);
}
sb_bp_location.SetLocation(bkpt_sp->FindLocationByAddress(address));
}
}
return LLDB_RECORD_RESULT(sb_bp_location);
}
break_id_t SBBreakpoint::FindLocationIDByAddress(addr_t vm_addr) {
LLDB_RECORD_METHOD(lldb::break_id_t, SBBreakpoint, FindLocationIDByAddress,
(lldb::addr_t), vm_addr);
break_id_t break_id = LLDB_INVALID_BREAK_ID;
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp && vm_addr != LLDB_INVALID_ADDRESS) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
Address address;
Target &target = bkpt_sp->GetTarget();
if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) {
address.SetRawAddress(vm_addr);
}
break_id = bkpt_sp->FindLocationIDByAddress(address);
}
return break_id;
}
SBBreakpointLocation SBBreakpoint::FindLocationByID(break_id_t bp_loc_id) {
LLDB_RECORD_METHOD(lldb::SBBreakpointLocation, SBBreakpoint, FindLocationByID,
(lldb::break_id_t), bp_loc_id);
SBBreakpointLocation sb_bp_location;
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
sb_bp_location.SetLocation(bkpt_sp->FindLocationByID(bp_loc_id));
}
return LLDB_RECORD_RESULT(sb_bp_location);
}
SBBreakpointLocation SBBreakpoint::GetLocationAtIndex(uint32_t index) {
LLDB_RECORD_METHOD(lldb::SBBreakpointLocation, SBBreakpoint,
GetLocationAtIndex, (uint32_t), index);
SBBreakpointLocation sb_bp_location;
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
sb_bp_location.SetLocation(bkpt_sp->GetLocationAtIndex(index));
}
return LLDB_RECORD_RESULT(sb_bp_location);
}
void SBBreakpoint::SetEnabled(bool enable) {
LLDB_RECORD_METHOD(void, SBBreakpoint, SetEnabled, (bool), enable);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
bkpt_sp->SetEnabled(enable);
}
}
bool SBBreakpoint::IsEnabled() {
LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpoint, IsEnabled);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
return bkpt_sp->IsEnabled();
} else
return false;
}
void SBBreakpoint::SetOneShot(bool one_shot) {
LLDB_RECORD_METHOD(void, SBBreakpoint, SetOneShot, (bool), one_shot);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
bkpt_sp->SetOneShot(one_shot);
}
}
bool SBBreakpoint::IsOneShot() const {
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpoint, IsOneShot);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
return bkpt_sp->IsOneShot();
} else
return false;
}
bool SBBreakpoint::IsInternal() {
LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpoint, IsInternal);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
return bkpt_sp->IsInternal();
} else
return false;
}
void SBBreakpoint::SetIgnoreCount(uint32_t count) {
LLDB_RECORD_METHOD(void, SBBreakpoint, SetIgnoreCount, (uint32_t), count);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
bkpt_sp->SetIgnoreCount(count);
}
}
void SBBreakpoint::SetCondition(const char *condition) {
LLDB_RECORD_METHOD(void, SBBreakpoint, SetCondition, (const char *),
condition);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
bkpt_sp->SetCondition(condition);
}
}
const char *SBBreakpoint::GetCondition() {
LLDB_RECORD_METHOD_NO_ARGS(const char *, SBBreakpoint, GetCondition);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
return bkpt_sp->GetConditionText();
}
return nullptr;
}
void SBBreakpoint::SetAutoContinue(bool auto_continue) {
LLDB_RECORD_METHOD(void, SBBreakpoint, SetAutoContinue, (bool),
auto_continue);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
bkpt_sp->SetAutoContinue(auto_continue);
}
}
bool SBBreakpoint::GetAutoContinue() {
LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpoint, GetAutoContinue);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
return bkpt_sp->IsAutoContinue();
}
return false;
}
uint32_t SBBreakpoint::GetHitCount() const {
LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBBreakpoint, GetHitCount);
uint32_t count = 0;
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
count = bkpt_sp->GetHitCount();
}
return count;
}
uint32_t SBBreakpoint::GetIgnoreCount() const {
LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBBreakpoint, GetIgnoreCount);
uint32_t count = 0;
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
count = bkpt_sp->GetIgnoreCount();
}
return count;
}
void SBBreakpoint::SetThreadID(tid_t tid) {
LLDB_RECORD_METHOD(void, SBBreakpoint, SetThreadID, (lldb::tid_t), tid);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
bkpt_sp->SetThreadID(tid);
}
}
tid_t SBBreakpoint::GetThreadID() {
LLDB_RECORD_METHOD_NO_ARGS(lldb::tid_t, SBBreakpoint, GetThreadID);
tid_t tid = LLDB_INVALID_THREAD_ID;
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
tid = bkpt_sp->GetThreadID();
}
return tid;
}
void SBBreakpoint::SetThreadIndex(uint32_t index) {
LLDB_RECORD_METHOD(void, SBBreakpoint, SetThreadIndex, (uint32_t), index);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
bkpt_sp->GetOptions()->GetThreadSpec()->SetIndex(index);
}
}
uint32_t SBBreakpoint::GetThreadIndex() const {
LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBBreakpoint, GetThreadIndex);
uint32_t thread_idx = UINT32_MAX;
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
const ThreadSpec *thread_spec =
bkpt_sp->GetOptions()->GetThreadSpecNoCreate();
if (thread_spec != nullptr)
thread_idx = thread_spec->GetIndex();
}
return thread_idx;
}
void SBBreakpoint::SetThreadName(const char *thread_name) {
LLDB_RECORD_METHOD(void, SBBreakpoint, SetThreadName, (const char *),
thread_name);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
bkpt_sp->GetOptions()->GetThreadSpec()->SetName(thread_name);
}
}
const char *SBBreakpoint::GetThreadName() const {
LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBBreakpoint, GetThreadName);
const char *name = nullptr;
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
const ThreadSpec *thread_spec =
bkpt_sp->GetOptions()->GetThreadSpecNoCreate();
if (thread_spec != nullptr)
name = thread_spec->GetName();
}
return name;
}
void SBBreakpoint::SetQueueName(const char *queue_name) {
LLDB_RECORD_METHOD(void, SBBreakpoint, SetQueueName, (const char *),
queue_name);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
bkpt_sp->GetOptions()->GetThreadSpec()->SetQueueName(queue_name);
}
}
const char *SBBreakpoint::GetQueueName() const {
LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBBreakpoint, GetQueueName);
const char *name = nullptr;
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
const ThreadSpec *thread_spec =
bkpt_sp->GetOptions()->GetThreadSpecNoCreate();
if (thread_spec)
name = thread_spec->GetQueueName();
}
return name;
}
size_t SBBreakpoint::GetNumResolvedLocations() const {
LLDB_RECORD_METHOD_CONST_NO_ARGS(size_t, SBBreakpoint,
GetNumResolvedLocations);
size_t num_resolved = 0;
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
num_resolved = bkpt_sp->GetNumResolvedLocations();
}
return num_resolved;
}
size_t SBBreakpoint::GetNumLocations() const {
LLDB_RECORD_METHOD_CONST_NO_ARGS(size_t, SBBreakpoint, GetNumLocations);
BreakpointSP bkpt_sp = GetSP();
size_t num_locs = 0;
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
num_locs = bkpt_sp->GetNumLocations();
}
return num_locs;
}
void SBBreakpoint::SetCommandLineCommands(SBStringList &commands) {
LLDB_RECORD_METHOD(void, SBBreakpoint, SetCommandLineCommands,
(lldb::SBStringList &), commands);
BreakpointSP bkpt_sp = GetSP();
if (!bkpt_sp)
return;
if (commands.GetSize() == 0)
return;
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
new BreakpointOptions::CommandData(*commands, eScriptLanguageNone));
bkpt_sp->GetOptions()->SetCommandDataCallback(cmd_data_up);
}
bool SBBreakpoint::GetCommandLineCommands(SBStringList &commands) {
LLDB_RECORD_METHOD(bool, SBBreakpoint, GetCommandLineCommands,
(lldb::SBStringList &), commands);
BreakpointSP bkpt_sp = GetSP();
if (!bkpt_sp)
return false;
StringList command_list;
bool has_commands =
bkpt_sp->GetOptions()->GetCommandLineCallbacks(command_list);
if (has_commands)
commands.AppendList(command_list);
return has_commands;
}
bool SBBreakpoint::GetDescription(SBStream &s) {
LLDB_RECORD_METHOD(bool, SBBreakpoint, GetDescription, (lldb::SBStream &), s);
return GetDescription(s, true);
}
bool SBBreakpoint::GetDescription(SBStream &s, bool include_locations) {
LLDB_RECORD_METHOD(bool, SBBreakpoint, GetDescription,
(lldb::SBStream &, bool), s, include_locations);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
s.Printf("SBBreakpoint: id = %i, ", bkpt_sp->GetID());
bkpt_sp->GetResolverDescription(s.get());
bkpt_sp->GetFilterDescription(s.get());
if (include_locations) {
const size_t num_locations = bkpt_sp->GetNumLocations();
s.Printf(", locations = %" PRIu64, (uint64_t)num_locations);
}
return true;
}
s.Printf("No value");
return false;
}
SBError SBBreakpoint::AddLocation(SBAddress &address) {
LLDB_RECORD_METHOD(lldb::SBError, SBBreakpoint, AddLocation,
(lldb::SBAddress &), address);
BreakpointSP bkpt_sp = GetSP();
SBError error;
if (!address.IsValid()) {
error.SetErrorString("Can't add an invalid address.");
return LLDB_RECORD_RESULT(error);
}
if (!bkpt_sp) {
error.SetErrorString("No breakpoint to add a location to.");
return LLDB_RECORD_RESULT(error);
}
if (!llvm::isa<BreakpointResolverScripted>(bkpt_sp->GetResolver().get())) {
error.SetErrorString("Only a scripted resolver can add locations.");
return LLDB_RECORD_RESULT(error);
}
if (bkpt_sp->GetSearchFilter()->AddressPasses(address.ref()))
bkpt_sp->AddLocation(address.ref());
else {
StreamString s;
address.get()->Dump(&s, &bkpt_sp->GetTarget(),
Address::DumpStyleModuleWithFileAddress);
error.SetErrorStringWithFormat("Address: %s didn't pass the filter.",
s.GetData());
}
return LLDB_RECORD_RESULT(error);
}
void SBBreakpoint ::SetCallback(SBBreakpointHitCallback callback, void *baton) {
LLDB_RECORD_DUMMY(void, SBBreakpoint, SetCallback,
(lldb::SBBreakpointHitCallback, void *), callback, baton);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton));
bkpt_sp->SetCallback(SBBreakpointCallbackBaton
::PrivateBreakpointHitCallback, baton_sp,
false);
}
}
void SBBreakpoint::SetScriptCallbackFunction(
const char *callback_function_name) {
LLDB_RECORD_METHOD(void, SBBreakpoint, SetScriptCallbackFunction,
(const char *), callback_function_name);
SBStructuredData empty_args;
SetScriptCallbackFunction(callback_function_name, empty_args);
}
SBError SBBreakpoint::SetScriptCallbackFunction(
const char *callback_function_name,
SBStructuredData &extra_args) {
LLDB_RECORD_METHOD(SBError, SBBreakpoint, SetScriptCallbackFunction,
(const char *, SBStructuredData &), callback_function_name, extra_args);
SBError sb_error;
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
Status error;
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
BreakpointOptions *bp_options = bkpt_sp->GetOptions();
error = bkpt_sp->GetTarget()
.GetDebugger()
.GetScriptInterpreter()
->SetBreakpointCommandCallbackFunction(bp_options,
callback_function_name,
extra_args.m_impl_up
->GetObjectSP());
sb_error.SetError(error);
} else
sb_error.SetErrorString("invalid breakpoint");
return LLDB_RECORD_RESULT(sb_error);
}
SBError SBBreakpoint::SetScriptCallbackBody(const char *callback_body_text) {
LLDB_RECORD_METHOD(lldb::SBError, SBBreakpoint, SetScriptCallbackBody,
(const char *), callback_body_text);
BreakpointSP bkpt_sp = GetSP();
SBError sb_error;
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
BreakpointOptions *bp_options = bkpt_sp->GetOptions();
Status error =
bkpt_sp->GetTarget()
.GetDebugger()
.GetScriptInterpreter()
->SetBreakpointCommandCallback(bp_options, callback_body_text);
sb_error.SetError(error);
} else
sb_error.SetErrorString("invalid breakpoint");
return LLDB_RECORD_RESULT(sb_error);
}
bool SBBreakpoint::AddName(const char *new_name) {
LLDB_RECORD_METHOD(bool, SBBreakpoint, AddName, (const char *), new_name);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
Status error; // Think I'm just going to swallow the error here, it's
// probably more annoying to have to provide it.
bkpt_sp->GetTarget().AddNameToBreakpoint(bkpt_sp, new_name, error);
if (error.Fail())
return false;
}
return true;
}
void SBBreakpoint::RemoveName(const char *name_to_remove) {
LLDB_RECORD_METHOD(void, SBBreakpoint, RemoveName, (const char *),
name_to_remove);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
bkpt_sp->GetTarget().RemoveNameFromBreakpoint(bkpt_sp,
ConstString(name_to_remove));
}
}
bool SBBreakpoint::MatchesName(const char *name) {
LLDB_RECORD_METHOD(bool, SBBreakpoint, MatchesName, (const char *), name);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
return bkpt_sp->MatchesName(name);
}
return false;
}
void SBBreakpoint::GetNames(SBStringList &names) {
LLDB_RECORD_METHOD(void, SBBreakpoint, GetNames, (lldb::SBStringList &),
names);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
std::vector<std::string> names_vec;
bkpt_sp->GetNames(names_vec);
for (std::string name : names_vec) {
names.AppendString(name.c_str());
}
}
}
bool SBBreakpoint::EventIsBreakpointEvent(const lldb::SBEvent &event) {
LLDB_RECORD_STATIC_METHOD(bool, SBBreakpoint, EventIsBreakpointEvent,
(const lldb::SBEvent &), event);
return Breakpoint::BreakpointEventData::GetEventDataFromEvent(event.get()) !=
nullptr;
}
BreakpointEventType
SBBreakpoint::GetBreakpointEventTypeFromEvent(const SBEvent &event) {
LLDB_RECORD_STATIC_METHOD(lldb::BreakpointEventType, SBBreakpoint,
GetBreakpointEventTypeFromEvent,
(const lldb::SBEvent &), event);
if (event.IsValid())
return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent(
event.GetSP());
return eBreakpointEventTypeInvalidType;
}
SBBreakpoint SBBreakpoint::GetBreakpointFromEvent(const lldb::SBEvent &event) {
LLDB_RECORD_STATIC_METHOD(lldb::SBBreakpoint, SBBreakpoint,
GetBreakpointFromEvent, (const lldb::SBEvent &),
event);
if (event.IsValid())
return LLDB_RECORD_RESULT(
SBBreakpoint(Breakpoint::BreakpointEventData::GetBreakpointFromEvent(
event.GetSP())));
return LLDB_RECORD_RESULT(SBBreakpoint());
}
SBBreakpointLocation
SBBreakpoint::GetBreakpointLocationAtIndexFromEvent(const lldb::SBEvent &event,
uint32_t loc_idx) {
LLDB_RECORD_STATIC_METHOD(lldb::SBBreakpointLocation, SBBreakpoint,
GetBreakpointLocationAtIndexFromEvent,
(const lldb::SBEvent &, uint32_t), event, loc_idx);
SBBreakpointLocation sb_breakpoint_loc;
if (event.IsValid())
sb_breakpoint_loc.SetLocation(
Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent(
event.GetSP(), loc_idx));
return LLDB_RECORD_RESULT(sb_breakpoint_loc);
}
uint32_t
SBBreakpoint::GetNumBreakpointLocationsFromEvent(const lldb::SBEvent &event) {
LLDB_RECORD_STATIC_METHOD(uint32_t, SBBreakpoint,
GetNumBreakpointLocationsFromEvent,
(const lldb::SBEvent &), event);
uint32_t num_locations = 0;
if (event.IsValid())
num_locations =
(Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent(
event.GetSP()));
return num_locations;
}
bool SBBreakpoint::IsHardware() const {
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpoint, IsHardware);
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp)
return bkpt_sp->IsHardware();
return false;
}
BreakpointSP SBBreakpoint::GetSP() const { return m_opaque_wp.lock(); }
// This is simple collection of breakpoint id's and their target.
class SBBreakpointListImpl {
public:
SBBreakpointListImpl(lldb::TargetSP target_sp) : m_target_wp() {
if (target_sp && target_sp->IsValid())
m_target_wp = target_sp;
}
~SBBreakpointListImpl() = default;
size_t GetSize() { return m_break_ids.size(); }
BreakpointSP GetBreakpointAtIndex(size_t idx) {
if (idx >= m_break_ids.size())
return BreakpointSP();
TargetSP target_sp = m_target_wp.lock();
if (!target_sp)
return BreakpointSP();
lldb::break_id_t bp_id = m_break_ids[idx];
return target_sp->GetBreakpointList().FindBreakpointByID(bp_id);
}
BreakpointSP FindBreakpointByID(lldb::break_id_t desired_id) {
TargetSP target_sp = m_target_wp.lock();
if (!target_sp)
return BreakpointSP();
for (lldb::break_id_t &break_id : m_break_ids) {
if (break_id == desired_id)
return target_sp->GetBreakpointList().FindBreakpointByID(break_id);
}
return BreakpointSP();
}
bool Append(BreakpointSP bkpt) {
TargetSP target_sp = m_target_wp.lock();
if (!target_sp || !bkpt)
return false;
if (bkpt->GetTargetSP() != target_sp)
return false;
m_break_ids.push_back(bkpt->GetID());
return true;
}
bool AppendIfUnique(BreakpointSP bkpt) {
TargetSP target_sp = m_target_wp.lock();
if (!target_sp || !bkpt)
return false;
if (bkpt->GetTargetSP() != target_sp)
return false;
lldb::break_id_t bp_id = bkpt->GetID();
if (find(m_break_ids.begin(), m_break_ids.end(), bp_id) ==
m_break_ids.end())
return false;
m_break_ids.push_back(bkpt->GetID());
return true;
}
bool AppendByID(lldb::break_id_t id) {
TargetSP target_sp = m_target_wp.lock();
if (!target_sp)
return false;
if (id == LLDB_INVALID_BREAK_ID)
return false;
m_break_ids.push_back(id);
return true;
}
void Clear() { m_break_ids.clear(); }
void CopyToBreakpointIDList(lldb_private::BreakpointIDList &bp_list) {
for (lldb::break_id_t id : m_break_ids) {
bp_list.AddBreakpointID(BreakpointID(id));
}
}
TargetSP GetTarget() { return m_target_wp.lock(); }
private:
std::vector<lldb::break_id_t> m_break_ids;
TargetWP m_target_wp;
};
SBBreakpointList::SBBreakpointList(SBTarget &target)
: m_opaque_sp(new SBBreakpointListImpl(target.GetSP())) {
LLDB_RECORD_CONSTRUCTOR(SBBreakpointList, (lldb::SBTarget &), target);
}
SBBreakpointList::~SBBreakpointList() {}
size_t SBBreakpointList::GetSize() const {
LLDB_RECORD_METHOD_CONST_NO_ARGS(size_t, SBBreakpointList, GetSize);
if (!m_opaque_sp)
return 0;
else
return m_opaque_sp->GetSize();
}
SBBreakpoint SBBreakpointList::GetBreakpointAtIndex(size_t idx) {
LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBBreakpointList, GetBreakpointAtIndex,
(size_t), idx);
if (!m_opaque_sp)
return LLDB_RECORD_RESULT(SBBreakpoint());
BreakpointSP bkpt_sp = m_opaque_sp->GetBreakpointAtIndex(idx);
return LLDB_RECORD_RESULT(SBBreakpoint(bkpt_sp));
}
SBBreakpoint SBBreakpointList::FindBreakpointByID(lldb::break_id_t id) {
LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBBreakpointList, FindBreakpointByID,
(lldb::break_id_t), id);
if (!m_opaque_sp)
return LLDB_RECORD_RESULT(SBBreakpoint());
BreakpointSP bkpt_sp = m_opaque_sp->FindBreakpointByID(id);
return LLDB_RECORD_RESULT(SBBreakpoint(bkpt_sp));
}
void SBBreakpointList::Append(const SBBreakpoint &sb_bkpt) {
LLDB_RECORD_METHOD(void, SBBreakpointList, Append,
(const lldb::SBBreakpoint &), sb_bkpt);
if (!sb_bkpt.IsValid())
return;
if (!m_opaque_sp)
return;
m_opaque_sp->Append(sb_bkpt.m_opaque_wp.lock());
}
void SBBreakpointList::AppendByID(lldb::break_id_t id) {
LLDB_RECORD_METHOD(void, SBBreakpointList, AppendByID, (lldb::break_id_t),
id);
if (!m_opaque_sp)
return;
m_opaque_sp->AppendByID(id);
}
bool SBBreakpointList::AppendIfUnique(const SBBreakpoint &sb_bkpt) {
LLDB_RECORD_METHOD(bool, SBBreakpointList, AppendIfUnique,
(const lldb::SBBreakpoint &), sb_bkpt);
if (!sb_bkpt.IsValid())
return false;
if (!m_opaque_sp)
return false;
return m_opaque_sp->AppendIfUnique(sb_bkpt.GetSP());
}
void SBBreakpointList::Clear() {
LLDB_RECORD_METHOD_NO_ARGS(void, SBBreakpointList, Clear);
if (m_opaque_sp)
m_opaque_sp->Clear();
}
void SBBreakpointList::CopyToBreakpointIDList(
lldb_private::BreakpointIDList &bp_id_list) {
if (m_opaque_sp)
m_opaque_sp->CopyToBreakpointIDList(bp_id_list);
}
namespace lldb_private {
namespace repro {
template <>
void RegisterMethods<SBBreakpoint>(Registry &R) {
LLDB_REGISTER_CONSTRUCTOR(SBBreakpoint, ());
LLDB_REGISTER_CONSTRUCTOR(SBBreakpoint, (const lldb::SBBreakpoint &));
LLDB_REGISTER_CONSTRUCTOR(SBBreakpoint, (const lldb::BreakpointSP &));
LLDB_REGISTER_METHOD(const lldb::SBBreakpoint &,
SBBreakpoint, operator=,(const lldb::SBBreakpoint &));
LLDB_REGISTER_METHOD(bool,
SBBreakpoint, operator==,(const lldb::SBBreakpoint &));
LLDB_REGISTER_METHOD(bool,
SBBreakpoint, operator!=,(const lldb::SBBreakpoint &));
LLDB_REGISTER_METHOD_CONST(lldb::break_id_t, SBBreakpoint, GetID, ());
LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, IsValid, ());
LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, operator bool, ());
LLDB_REGISTER_METHOD(void, SBBreakpoint, ClearAllBreakpointSites, ());
LLDB_REGISTER_METHOD(lldb::SBBreakpointLocation, SBBreakpoint,
FindLocationByAddress, (lldb::addr_t));
LLDB_REGISTER_METHOD(lldb::break_id_t, SBBreakpoint,
FindLocationIDByAddress, (lldb::addr_t));
LLDB_REGISTER_METHOD(lldb::SBBreakpointLocation, SBBreakpoint,
FindLocationByID, (lldb::break_id_t));
LLDB_REGISTER_METHOD(lldb::SBBreakpointLocation, SBBreakpoint,
GetLocationAtIndex, (uint32_t));
LLDB_REGISTER_METHOD(void, SBBreakpoint, SetEnabled, (bool));
LLDB_REGISTER_METHOD(bool, SBBreakpoint, IsEnabled, ());
LLDB_REGISTER_METHOD(void, SBBreakpoint, SetOneShot, (bool));
LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, IsOneShot, ());
LLDB_REGISTER_METHOD(bool, SBBreakpoint, IsInternal, ());
LLDB_REGISTER_METHOD(void, SBBreakpoint, SetIgnoreCount, (uint32_t));
LLDB_REGISTER_METHOD(void, SBBreakpoint, SetCondition, (const char *));
LLDB_REGISTER_METHOD(const char *, SBBreakpoint, GetCondition, ());
LLDB_REGISTER_METHOD(void, SBBreakpoint, SetAutoContinue, (bool));
LLDB_REGISTER_METHOD(bool, SBBreakpoint, GetAutoContinue, ());
LLDB_REGISTER_METHOD_CONST(uint32_t, SBBreakpoint, GetHitCount, ());
LLDB_REGISTER_METHOD_CONST(uint32_t, SBBreakpoint, GetIgnoreCount, ());
LLDB_REGISTER_METHOD(void, SBBreakpoint, SetThreadID, (lldb::tid_t));
LLDB_REGISTER_METHOD(lldb::tid_t, SBBreakpoint, GetThreadID, ());
LLDB_REGISTER_METHOD(void, SBBreakpoint, SetThreadIndex, (uint32_t));
LLDB_REGISTER_METHOD_CONST(uint32_t, SBBreakpoint, GetThreadIndex, ());
LLDB_REGISTER_METHOD(void, SBBreakpoint, SetThreadName, (const char *));
LLDB_REGISTER_METHOD_CONST(const char *, SBBreakpoint, GetThreadName, ());
LLDB_REGISTER_METHOD(void, SBBreakpoint, SetQueueName, (const char *));
LLDB_REGISTER_METHOD_CONST(const char *, SBBreakpoint, GetQueueName, ());
LLDB_REGISTER_METHOD_CONST(size_t, SBBreakpoint, GetNumResolvedLocations,
());
LLDB_REGISTER_METHOD_CONST(size_t, SBBreakpoint, GetNumLocations, ());
LLDB_REGISTER_METHOD(void, SBBreakpoint, SetCommandLineCommands,
(lldb::SBStringList &));
LLDB_REGISTER_METHOD(bool, SBBreakpoint, GetCommandLineCommands,
(lldb::SBStringList &));
LLDB_REGISTER_METHOD(bool, SBBreakpoint, GetDescription,
(lldb::SBStream &));
LLDB_REGISTER_METHOD(bool, SBBreakpoint, GetDescription,
(lldb::SBStream &, bool));
LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpoint, AddLocation,
(lldb::SBAddress &));
LLDB_REGISTER_METHOD(void, SBBreakpoint, SetScriptCallbackFunction,
(const char *));
LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpoint, SetScriptCallbackFunction,
(const char *, SBStructuredData &));
LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpoint, SetScriptCallbackBody,
(const char *));
LLDB_REGISTER_METHOD(bool, SBBreakpoint, AddName, (const char *));
LLDB_REGISTER_METHOD(void, SBBreakpoint, RemoveName, (const char *));
LLDB_REGISTER_METHOD(bool, SBBreakpoint, MatchesName, (const char *));
LLDB_REGISTER_METHOD(void, SBBreakpoint, GetNames, (lldb::SBStringList &));
LLDB_REGISTER_STATIC_METHOD(bool, SBBreakpoint, EventIsBreakpointEvent,
(const lldb::SBEvent &));
LLDB_REGISTER_STATIC_METHOD(lldb::BreakpointEventType, SBBreakpoint,
GetBreakpointEventTypeFromEvent,
(const lldb::SBEvent &));
LLDB_REGISTER_STATIC_METHOD(lldb::SBBreakpoint, SBBreakpoint,
GetBreakpointFromEvent,
(const lldb::SBEvent &));
LLDB_REGISTER_STATIC_METHOD(lldb::SBBreakpointLocation, SBBreakpoint,
GetBreakpointLocationAtIndexFromEvent,
(const lldb::SBEvent &, uint32_t));
LLDB_REGISTER_STATIC_METHOD(uint32_t, SBBreakpoint,
GetNumBreakpointLocationsFromEvent,
(const lldb::SBEvent &));
LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, IsHardware, ());
}
template <>
void RegisterMethods<SBBreakpointList>(Registry &R) {
LLDB_REGISTER_CONSTRUCTOR(SBBreakpointList, (lldb::SBTarget &));
LLDB_REGISTER_METHOD_CONST(size_t, SBBreakpointList, GetSize, ());
LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBBreakpointList,
GetBreakpointAtIndex, (size_t));
LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBBreakpointList,
FindBreakpointByID, (lldb::break_id_t));
LLDB_REGISTER_METHOD(void, SBBreakpointList, Append,
(const lldb::SBBreakpoint &));
LLDB_REGISTER_METHOD(void, SBBreakpointList, AppendByID,
(lldb::break_id_t));
LLDB_REGISTER_METHOD(bool, SBBreakpointList, AppendIfUnique,
(const lldb::SBBreakpoint &));
LLDB_REGISTER_METHOD(void, SBBreakpointList, Clear, ());
}
}
}