forked from flang-compiler/f18-llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandObjectBreakpoint.cpp
2486 lines (2111 loc) · 86 KB
/
CommandObjectBreakpoint.cpp
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
//===-- CommandObjectBreakpoint.cpp ---------------------------------------===//
//
// 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 "CommandObjectBreakpoint.h"
#include "CommandObjectBreakpointCommand.h"
#include "lldb/Breakpoint/Breakpoint.h"
#include "lldb/Breakpoint/BreakpointIDList.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Host/OptionParser.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandOptionArgumentTable.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionGroupPythonClassWithDict.h"
#include "lldb/Interpreter/OptionValueBoolean.h"
#include "lldb/Interpreter/OptionValueFileColonLine.h"
#include "lldb/Interpreter/OptionValueString.h"
#include "lldb/Interpreter/OptionValueUInt64.h"
#include "lldb/Interpreter/Options.h"
#include "lldb/Target/Language.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/ThreadSpec.h"
#include "lldb/Utility/RegularExpression.h"
#include "lldb/Utility/StreamString.h"
#include <memory>
#include <optional>
#include <vector>
using namespace lldb;
using namespace lldb_private;
static void AddBreakpointDescription(Stream *s, Breakpoint *bp,
lldb::DescriptionLevel level) {
s->IndentMore();
bp->GetDescription(s, level, true);
s->IndentLess();
s->EOL();
}
// Modifiable Breakpoint Options
#pragma mark Modify::CommandOptions
#define LLDB_OPTIONS_breakpoint_modify
#include "CommandOptions.inc"
class lldb_private::BreakpointOptionGroup : public OptionGroup {
public:
BreakpointOptionGroup() : m_bp_opts(false) {}
~BreakpointOptionGroup() override = default;
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
return llvm::ArrayRef(g_breakpoint_modify_options);
}
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
ExecutionContext *execution_context) override {
Status error;
const int short_option =
g_breakpoint_modify_options[option_idx].short_option;
const char *long_option =
g_breakpoint_modify_options[option_idx].long_option;
switch (short_option) {
case 'c':
// Normally an empty breakpoint condition marks is as unset. But we need
// to say it was passed in.
m_bp_opts.SetCondition(option_arg.str().c_str());
m_bp_opts.m_set_flags.Set(BreakpointOptions::eCondition);
break;
case 'C':
m_commands.push_back(std::string(option_arg));
break;
case 'd':
m_bp_opts.SetEnabled(false);
break;
case 'e':
m_bp_opts.SetEnabled(true);
break;
case 'G': {
bool value, success;
value = OptionArgParser::ToBoolean(option_arg, false, &success);
if (success)
m_bp_opts.SetAutoContinue(value);
else
error = CreateOptionParsingError(option_arg, short_option, long_option,
g_bool_parsing_error_message);
} break;
case 'i': {
uint32_t ignore_count;
if (option_arg.getAsInteger(0, ignore_count))
error = CreateOptionParsingError(option_arg, short_option, long_option,
g_int_parsing_error_message);
else
m_bp_opts.SetIgnoreCount(ignore_count);
} break;
case 'o': {
bool value, success;
value = OptionArgParser::ToBoolean(option_arg, false, &success);
if (success) {
m_bp_opts.SetOneShot(value);
} else
error = CreateOptionParsingError(option_arg, short_option, long_option,
g_bool_parsing_error_message);
} break;
case 't': {
lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID;
if (option_arg == "current") {
if (!execution_context) {
error = CreateOptionParsingError(
option_arg, short_option, long_option,
"No context to determine current thread");
} else {
ThreadSP ctx_thread_sp = execution_context->GetThreadSP();
if (!ctx_thread_sp || !ctx_thread_sp->IsValid()) {
error =
CreateOptionParsingError(option_arg, short_option, long_option,
"No currently selected thread");
} else {
thread_id = ctx_thread_sp->GetID();
}
}
} else if (option_arg.getAsInteger(0, thread_id)) {
error = CreateOptionParsingError(option_arg, short_option, long_option,
g_int_parsing_error_message);
}
if (thread_id != LLDB_INVALID_THREAD_ID)
m_bp_opts.SetThreadID(thread_id);
} break;
case 'T':
m_bp_opts.GetThreadSpec()->SetName(option_arg.str().c_str());
break;
case 'q':
m_bp_opts.GetThreadSpec()->SetQueueName(option_arg.str().c_str());
break;
case 'x': {
uint32_t thread_index = UINT32_MAX;
if (option_arg.getAsInteger(0, thread_index)) {
error = CreateOptionParsingError(option_arg, short_option, long_option,
g_int_parsing_error_message);
} else {
m_bp_opts.GetThreadSpec()->SetIndex(thread_index);
}
} break;
default:
llvm_unreachable("Unimplemented option");
}
return error;
}
void OptionParsingStarting(ExecutionContext *execution_context) override {
m_bp_opts.Clear();
m_commands.clear();
}
Status OptionParsingFinished(ExecutionContext *execution_context) override {
if (!m_commands.empty()) {
auto cmd_data = std::make_unique<BreakpointOptions::CommandData>();
for (std::string &str : m_commands)
cmd_data->user_source.AppendString(str);
cmd_data->stop_on_error = true;
m_bp_opts.SetCommandDataCallback(cmd_data);
}
return Status();
}
const BreakpointOptions &GetBreakpointOptions() { return m_bp_opts; }
std::vector<std::string> m_commands;
BreakpointOptions m_bp_opts;
};
#define LLDB_OPTIONS_breakpoint_dummy
#include "CommandOptions.inc"
class BreakpointDummyOptionGroup : public OptionGroup {
public:
BreakpointDummyOptionGroup() = default;
~BreakpointDummyOptionGroup() override = default;
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
return llvm::ArrayRef(g_breakpoint_dummy_options);
}
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
ExecutionContext *execution_context) override {
Status error;
const int short_option =
g_breakpoint_dummy_options[option_idx].short_option;
switch (short_option) {
case 'D':
m_use_dummy = true;
break;
default:
llvm_unreachable("Unimplemented option");
}
return error;
}
void OptionParsingStarting(ExecutionContext *execution_context) override {
m_use_dummy = false;
}
bool m_use_dummy;
};
#define LLDB_OPTIONS_breakpoint_set
#include "CommandOptions.inc"
// CommandObjectBreakpointSet
class CommandObjectBreakpointSet : public CommandObjectParsed {
public:
enum BreakpointSetType {
eSetTypeInvalid,
eSetTypeFileAndLine,
eSetTypeAddress,
eSetTypeFunctionName,
eSetTypeFunctionRegexp,
eSetTypeSourceRegexp,
eSetTypeException,
eSetTypeScripted,
};
CommandObjectBreakpointSet(CommandInterpreter &interpreter)
: CommandObjectParsed(
interpreter, "breakpoint set",
"Sets a breakpoint or set of breakpoints in the executable.",
"breakpoint set <cmd-options>"),
m_python_class_options("scripted breakpoint", true, 'P') {
// We're picking up all the normal options, commands and disable.
m_all_options.Append(&m_python_class_options,
LLDB_OPT_SET_1 | LLDB_OPT_SET_2, LLDB_OPT_SET_11);
m_all_options.Append(&m_bp_opts,
LLDB_OPT_SET_1 | LLDB_OPT_SET_3 | LLDB_OPT_SET_4,
LLDB_OPT_SET_ALL);
m_all_options.Append(&m_dummy_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
m_all_options.Append(&m_options);
m_all_options.Finalize();
}
~CommandObjectBreakpointSet() override = default;
Options *GetOptions() override { return &m_all_options; }
class CommandOptions : public OptionGroup {
public:
CommandOptions() = default;
~CommandOptions() override = default;
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
ExecutionContext *execution_context) override {
Status error;
const int short_option =
g_breakpoint_set_options[option_idx].short_option;
const char *long_option =
g_breakpoint_set_options[option_idx].long_option;
switch (short_option) {
case 'a': {
m_load_addr = OptionArgParser::ToAddress(execution_context, option_arg,
LLDB_INVALID_ADDRESS, &error);
} break;
case 'A':
m_all_files = true;
break;
case 'b':
m_func_names.push_back(std::string(option_arg));
m_func_name_type_mask |= eFunctionNameTypeBase;
break;
case 'u':
if (option_arg.getAsInteger(0, m_column))
error =
CreateOptionParsingError(option_arg, short_option, long_option,
g_int_parsing_error_message);
break;
case 'E': {
LanguageType language = Language::GetLanguageTypeFromString(option_arg);
llvm::StringRef error_context;
switch (language) {
case eLanguageTypeC89:
case eLanguageTypeC:
case eLanguageTypeC99:
case eLanguageTypeC11:
m_exception_language = eLanguageTypeC;
break;
case eLanguageTypeC_plus_plus:
case eLanguageTypeC_plus_plus_03:
case eLanguageTypeC_plus_plus_11:
case eLanguageTypeC_plus_plus_14:
m_exception_language = eLanguageTypeC_plus_plus;
break;
case eLanguageTypeObjC:
m_exception_language = eLanguageTypeObjC;
break;
case eLanguageTypeObjC_plus_plus:
error_context =
"Set exception breakpoints separately for c++ and objective-c";
break;
case eLanguageTypeUnknown:
error_context = "Unknown language type for exception breakpoint";
break;
default:
error_context = "Unsupported language type for exception breakpoint";
}
if (!error_context.empty())
error = CreateOptionParsingError(option_arg, short_option,
long_option, error_context);
} break;
case 'f':
m_filenames.AppendIfUnique(FileSpec(option_arg));
break;
case 'F':
m_func_names.push_back(std::string(option_arg));
m_func_name_type_mask |= eFunctionNameTypeFull;
break;
case 'h': {
bool success;
m_catch_bp = OptionArgParser::ToBoolean(option_arg, true, &success);
if (!success)
error =
CreateOptionParsingError(option_arg, short_option, long_option,
g_bool_parsing_error_message);
} break;
case 'H':
m_hardware = true;
break;
case 'K': {
bool success;
bool value;
value = OptionArgParser::ToBoolean(option_arg, true, &success);
if (value)
m_skip_prologue = eLazyBoolYes;
else
m_skip_prologue = eLazyBoolNo;
if (!success)
error =
CreateOptionParsingError(option_arg, short_option, long_option,
g_bool_parsing_error_message);
} break;
case 'l':
if (option_arg.getAsInteger(0, m_line_num))
error =
CreateOptionParsingError(option_arg, short_option, long_option,
g_int_parsing_error_message);
break;
case 'L':
m_language = Language::GetLanguageTypeFromString(option_arg);
if (m_language == eLanguageTypeUnknown)
error =
CreateOptionParsingError(option_arg, short_option, long_option,
g_language_parsing_error_message);
break;
case 'm': {
bool success;
bool value;
value = OptionArgParser::ToBoolean(option_arg, true, &success);
if (value)
m_move_to_nearest_code = eLazyBoolYes;
else
m_move_to_nearest_code = eLazyBoolNo;
if (!success)
error =
CreateOptionParsingError(option_arg, short_option, long_option,
g_bool_parsing_error_message);
break;
}
case 'M':
m_func_names.push_back(std::string(option_arg));
m_func_name_type_mask |= eFunctionNameTypeMethod;
break;
case 'n':
m_func_names.push_back(std::string(option_arg));
m_func_name_type_mask |= eFunctionNameTypeAuto;
break;
case 'N': {
if (BreakpointID::StringIsBreakpointName(option_arg, error))
m_breakpoint_names.push_back(std::string(option_arg));
else
error = CreateOptionParsingError(
option_arg, short_option, long_option, "Invalid breakpoint name");
break;
}
case 'R': {
lldb::addr_t tmp_offset_addr;
tmp_offset_addr = OptionArgParser::ToAddress(execution_context,
option_arg, 0, &error);
if (error.Success())
m_offset_addr = tmp_offset_addr;
} break;
case 'O':
m_exception_extra_args.AppendArgument("-O");
m_exception_extra_args.AppendArgument(option_arg);
break;
case 'p':
m_source_text_regexp.assign(std::string(option_arg));
break;
case 'r':
m_func_regexp.assign(std::string(option_arg));
break;
case 's':
m_modules.AppendIfUnique(FileSpec(option_arg));
break;
case 'S':
m_func_names.push_back(std::string(option_arg));
m_func_name_type_mask |= eFunctionNameTypeSelector;
break;
case 'w': {
bool success;
m_throw_bp = OptionArgParser::ToBoolean(option_arg, true, &success);
if (!success)
error =
CreateOptionParsingError(option_arg, short_option, long_option,
g_bool_parsing_error_message);
} break;
case 'X':
m_source_regex_func_names.insert(std::string(option_arg));
break;
case 'y':
{
OptionValueFileColonLine value;
Status fcl_err = value.SetValueFromString(option_arg);
if (!fcl_err.Success()) {
error = CreateOptionParsingError(option_arg, short_option,
long_option, fcl_err.AsCString());
} else {
m_filenames.AppendIfUnique(value.GetFileSpec());
m_line_num = value.GetLineNumber();
m_column = value.GetColumnNumber();
}
} break;
default:
llvm_unreachable("Unimplemented option");
}
return error;
}
void OptionParsingStarting(ExecutionContext *execution_context) override {
m_filenames.Clear();
m_line_num = 0;
m_column = 0;
m_func_names.clear();
m_func_name_type_mask = eFunctionNameTypeNone;
m_func_regexp.clear();
m_source_text_regexp.clear();
m_modules.Clear();
m_load_addr = LLDB_INVALID_ADDRESS;
m_offset_addr = 0;
m_catch_bp = false;
m_throw_bp = true;
m_hardware = false;
m_exception_language = eLanguageTypeUnknown;
m_language = lldb::eLanguageTypeUnknown;
m_skip_prologue = eLazyBoolCalculate;
m_breakpoint_names.clear();
m_all_files = false;
m_exception_extra_args.Clear();
m_move_to_nearest_code = eLazyBoolCalculate;
m_source_regex_func_names.clear();
m_current_key.clear();
}
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
return llvm::ArrayRef(g_breakpoint_set_options);
}
// Instance variables to hold the values for command options.
std::string m_condition;
FileSpecList m_filenames;
uint32_t m_line_num = 0;
uint32_t m_column = 0;
std::vector<std::string> m_func_names;
std::vector<std::string> m_breakpoint_names;
lldb::FunctionNameType m_func_name_type_mask = eFunctionNameTypeNone;
std::string m_func_regexp;
std::string m_source_text_regexp;
FileSpecList m_modules;
lldb::addr_t m_load_addr = 0;
lldb::addr_t m_offset_addr;
bool m_catch_bp = false;
bool m_throw_bp = true;
bool m_hardware = false; // Request to use hardware breakpoints
lldb::LanguageType m_exception_language = eLanguageTypeUnknown;
lldb::LanguageType m_language = lldb::eLanguageTypeUnknown;
LazyBool m_skip_prologue = eLazyBoolCalculate;
bool m_all_files = false;
Args m_exception_extra_args;
LazyBool m_move_to_nearest_code = eLazyBoolCalculate;
std::unordered_set<std::string> m_source_regex_func_names;
std::string m_current_key;
};
protected:
void DoExecute(Args &command, CommandReturnObject &result) override {
Target &target = GetSelectedOrDummyTarget(m_dummy_options.m_use_dummy);
// The following are the various types of breakpoints that could be set:
// 1). -f -l -p [-s -g] (setting breakpoint by source location)
// 2). -a [-s -g] (setting breakpoint by address)
// 3). -n [-s -g] (setting breakpoint by function name)
// 4). -r [-s -g] (setting breakpoint by function name regular
// expression)
// 5). -p -f (setting a breakpoint by comparing a reg-exp
// to source text)
// 6). -E [-w -h] (setting a breakpoint for exceptions for a
// given language.)
BreakpointSetType break_type = eSetTypeInvalid;
if (!m_python_class_options.GetName().empty())
break_type = eSetTypeScripted;
else if (m_options.m_line_num != 0)
break_type = eSetTypeFileAndLine;
else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
break_type = eSetTypeAddress;
else if (!m_options.m_func_names.empty())
break_type = eSetTypeFunctionName;
else if (!m_options.m_func_regexp.empty())
break_type = eSetTypeFunctionRegexp;
else if (!m_options.m_source_text_regexp.empty())
break_type = eSetTypeSourceRegexp;
else if (m_options.m_exception_language != eLanguageTypeUnknown)
break_type = eSetTypeException;
BreakpointSP bp_sp = nullptr;
FileSpec module_spec;
const bool internal = false;
// If the user didn't specify skip-prologue, having an offset should turn
// that off.
if (m_options.m_offset_addr != 0 &&
m_options.m_skip_prologue == eLazyBoolCalculate)
m_options.m_skip_prologue = eLazyBoolNo;
switch (break_type) {
case eSetTypeFileAndLine: // Breakpoint by source position
{
FileSpec file;
const size_t num_files = m_options.m_filenames.GetSize();
if (num_files == 0) {
if (!GetDefaultFile(target, file, result)) {
result.AppendError("No file supplied and no default file available.");
return;
}
} else if (num_files > 1) {
result.AppendError("Only one file at a time is allowed for file and "
"line breakpoints.");
return;
} else
file = m_options.m_filenames.GetFileSpecAtIndex(0);
// Only check for inline functions if
LazyBool check_inlines = eLazyBoolCalculate;
bp_sp = target.CreateBreakpoint(
&(m_options.m_modules), file, m_options.m_line_num,
m_options.m_column, m_options.m_offset_addr, check_inlines,
m_options.m_skip_prologue, internal, m_options.m_hardware,
m_options.m_move_to_nearest_code);
} break;
case eSetTypeAddress: // Breakpoint by address
{
// If a shared library has been specified, make an lldb_private::Address
// with the library, and use that. That way the address breakpoint
// will track the load location of the library.
size_t num_modules_specified = m_options.m_modules.GetSize();
if (num_modules_specified == 1) {
const FileSpec &file_spec =
m_options.m_modules.GetFileSpecAtIndex(0);
bp_sp = target.CreateAddressInModuleBreakpoint(
m_options.m_load_addr, internal, file_spec, m_options.m_hardware);
} else if (num_modules_specified == 0) {
bp_sp = target.CreateBreakpoint(m_options.m_load_addr, internal,
m_options.m_hardware);
} else {
result.AppendError("Only one shared library can be specified for "
"address breakpoints.");
return;
}
break;
}
case eSetTypeFunctionName: // Breakpoint by function name
{
FunctionNameType name_type_mask = m_options.m_func_name_type_mask;
if (name_type_mask == 0)
name_type_mask = eFunctionNameTypeAuto;
bp_sp = target.CreateBreakpoint(
&(m_options.m_modules), &(m_options.m_filenames),
m_options.m_func_names, name_type_mask, m_options.m_language,
m_options.m_offset_addr, m_options.m_skip_prologue, internal,
m_options.m_hardware);
} break;
case eSetTypeFunctionRegexp: // Breakpoint by regular expression function
// name
{
RegularExpression regexp(m_options.m_func_regexp);
if (llvm::Error err = regexp.GetError()) {
result.AppendErrorWithFormat(
"Function name regular expression could not be compiled: %s",
llvm::toString(std::move(err)).c_str());
// Check if the incorrect regex looks like a globbing expression and
// warn the user about it.
if (!m_options.m_func_regexp.empty()) {
if (m_options.m_func_regexp[0] == '*' ||
m_options.m_func_regexp[0] == '?')
result.AppendWarning(
"Function name regex does not accept glob patterns.");
}
return;
}
bp_sp = target.CreateFuncRegexBreakpoint(
&(m_options.m_modules), &(m_options.m_filenames), std::move(regexp),
m_options.m_language, m_options.m_skip_prologue, internal,
m_options.m_hardware);
} break;
case eSetTypeSourceRegexp: // Breakpoint by regexp on source text.
{
const size_t num_files = m_options.m_filenames.GetSize();
if (num_files == 0 && !m_options.m_all_files) {
FileSpec file;
if (!GetDefaultFile(target, file, result)) {
result.AppendError(
"No files provided and could not find default file.");
return;
} else {
m_options.m_filenames.Append(file);
}
}
RegularExpression regexp(m_options.m_source_text_regexp);
if (llvm::Error err = regexp.GetError()) {
result.AppendErrorWithFormat(
"Source text regular expression could not be compiled: \"%s\"",
llvm::toString(std::move(err)).c_str());
return;
}
bp_sp = target.CreateSourceRegexBreakpoint(
&(m_options.m_modules), &(m_options.m_filenames),
m_options.m_source_regex_func_names, std::move(regexp), internal,
m_options.m_hardware, m_options.m_move_to_nearest_code);
} break;
case eSetTypeException: {
Status precond_error;
bp_sp = target.CreateExceptionBreakpoint(
m_options.m_exception_language, m_options.m_catch_bp,
m_options.m_throw_bp, internal, &m_options.m_exception_extra_args,
&precond_error);
if (precond_error.Fail()) {
result.AppendErrorWithFormat(
"Error setting extra exception arguments: %s",
precond_error.AsCString());
target.RemoveBreakpointByID(bp_sp->GetID());
return;
}
} break;
case eSetTypeScripted: {
Status error;
bp_sp = target.CreateScriptedBreakpoint(
m_python_class_options.GetName().c_str(), &(m_options.m_modules),
&(m_options.m_filenames), false, m_options.m_hardware,
m_python_class_options.GetStructuredData(), &error);
if (error.Fail()) {
result.AppendErrorWithFormat(
"Error setting extra exception arguments: %s", error.AsCString());
target.RemoveBreakpointByID(bp_sp->GetID());
return;
}
} break;
default:
break;
}
// Now set the various options that were passed in:
if (bp_sp) {
bp_sp->GetOptions().CopyOverSetOptions(m_bp_opts.GetBreakpointOptions());
if (!m_options.m_breakpoint_names.empty()) {
Status name_error;
for (auto name : m_options.m_breakpoint_names) {
target.AddNameToBreakpoint(bp_sp, name.c_str(), name_error);
if (name_error.Fail()) {
result.AppendErrorWithFormat("Invalid breakpoint name: %s",
name.c_str());
target.RemoveBreakpointByID(bp_sp->GetID());
return;
}
}
}
}
if (bp_sp) {
Stream &output_stream = result.GetOutputStream();
const bool show_locations = false;
bp_sp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial,
show_locations);
if (&target == &GetDummyTarget())
output_stream.Printf("Breakpoint set in dummy target, will get copied "
"into future targets.\n");
else {
// Don't print out this warning for exception breakpoints. They can
// get set before the target is set, but we won't know how to actually
// set the breakpoint till we run.
if (bp_sp->GetNumLocations() == 0 && break_type != eSetTypeException) {
output_stream.Printf("WARNING: Unable to resolve breakpoint to any "
"actual locations.\n");
}
}
result.SetStatus(eReturnStatusSuccessFinishResult);
} else if (!bp_sp) {
result.AppendError("Breakpoint creation failed: No breakpoint created.");
}
}
private:
bool GetDefaultFile(Target &target, FileSpec &file,
CommandReturnObject &result) {
uint32_t default_line;
// First use the Source Manager's default file. Then use the current stack
// frame's file.
if (!target.GetSourceManager().GetDefaultFileAndLine(file, default_line)) {
StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
if (cur_frame == nullptr) {
result.AppendError(
"No selected frame to use to find the default file.");
return false;
} else if (!cur_frame->HasDebugInformation()) {
result.AppendError("Cannot use the selected frame to find the default "
"file, it has no debug info.");
return false;
} else {
const SymbolContext &sc =
cur_frame->GetSymbolContext(eSymbolContextLineEntry);
if (sc.line_entry.GetFile()) {
file = sc.line_entry.GetFile();
} else {
result.AppendError("Can't find the file for the selected frame to "
"use as the default file.");
return false;
}
}
}
return true;
}
BreakpointOptionGroup m_bp_opts;
BreakpointDummyOptionGroup m_dummy_options;
OptionGroupPythonClassWithDict m_python_class_options;
CommandOptions m_options;
OptionGroupOptions m_all_options;
};
// CommandObjectBreakpointModify
#pragma mark Modify
class CommandObjectBreakpointModify : public CommandObjectParsed {
public:
CommandObjectBreakpointModify(CommandInterpreter &interpreter)
: CommandObjectParsed(interpreter, "breakpoint modify",
"Modify the options on a breakpoint or set of "
"breakpoints in the executable. "
"If no breakpoint is specified, acts on the last "
"created breakpoint. "
"With the exception of -e, -d and -i, passing an "
"empty argument clears the modification.",
nullptr) {
CommandObject::AddIDsArgumentData(eBreakpointArgs);
m_options.Append(&m_bp_opts,
LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3,
LLDB_OPT_SET_ALL);
m_options.Append(&m_dummy_opts, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
m_options.Finalize();
}
~CommandObjectBreakpointModify() override = default;
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eBreakpointCompletion, request, nullptr);
}
Options *GetOptions() override { return &m_options; }
protected:
void DoExecute(Args &command, CommandReturnObject &result) override {
Target &target = GetSelectedOrDummyTarget(m_dummy_opts.m_use_dummy);
std::unique_lock<std::recursive_mutex> lock;
target.GetBreakpointList().GetListMutex(lock);
BreakpointIDList valid_bp_ids;
CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
command, &target, result, &valid_bp_ids,
BreakpointName::Permissions::PermissionKinds::disablePerm);
if (result.Succeeded()) {
const size_t count = valid_bp_ids.GetSize();
for (size_t i = 0; i < count; ++i) {
BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
Breakpoint *bp =
target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
BreakpointLocation *location =
bp->FindLocationByID(cur_bp_id.GetLocationID()).get();
if (location)
location->GetLocationOptions().CopyOverSetOptions(
m_bp_opts.GetBreakpointOptions());
} else {
bp->GetOptions().CopyOverSetOptions(
m_bp_opts.GetBreakpointOptions());
}
}
}
}
}
private:
BreakpointOptionGroup m_bp_opts;
BreakpointDummyOptionGroup m_dummy_opts;
OptionGroupOptions m_options;
};
// CommandObjectBreakpointEnable
#pragma mark Enable
class CommandObjectBreakpointEnable : public CommandObjectParsed {
public:
CommandObjectBreakpointEnable(CommandInterpreter &interpreter)
: CommandObjectParsed(interpreter, "enable",
"Enable the specified disabled breakpoint(s). If "
"no breakpoints are specified, enable all of them.",
nullptr) {
CommandObject::AddIDsArgumentData(eBreakpointArgs);
}
~CommandObjectBreakpointEnable() override = default;
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eBreakpointCompletion, request, nullptr);
}
protected:
void DoExecute(Args &command, CommandReturnObject &result) override {
Target &target = GetSelectedOrDummyTarget();
std::unique_lock<std::recursive_mutex> lock;
target.GetBreakpointList().GetListMutex(lock);
const BreakpointList &breakpoints = target.GetBreakpointList();
size_t num_breakpoints = breakpoints.GetSize();
if (num_breakpoints == 0) {
result.AppendError("No breakpoints exist to be enabled.");
return;
}
if (command.empty()) {
// No breakpoint selected; enable all currently set breakpoints.
target.EnableAllowedBreakpoints();
result.AppendMessageWithFormat("All breakpoints enabled. (%" PRIu64
" breakpoints)\n",
(uint64_t)num_breakpoints);
result.SetStatus(eReturnStatusSuccessFinishNoResult);
} else {
// Particular breakpoint selected; enable that breakpoint.
BreakpointIDList valid_bp_ids;
CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
command, &target, result, &valid_bp_ids,
BreakpointName::Permissions::PermissionKinds::disablePerm);
if (result.Succeeded()) {
int enable_count = 0;
int loc_count = 0;
const size_t count = valid_bp_ids.GetSize();
for (size_t i = 0; i < count; ++i) {
BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
Breakpoint *breakpoint =
target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
BreakpointLocation *location =
breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get();
if (location) {
location->SetEnabled(true);
++loc_count;
}
} else {
breakpoint->SetEnabled(true);
++enable_count;
}
}
}
result.AppendMessageWithFormat("%d breakpoints enabled.\n",
enable_count + loc_count);
result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
}
}
};
// CommandObjectBreakpointDisable
#pragma mark Disable
class CommandObjectBreakpointDisable : public CommandObjectParsed {
public:
CommandObjectBreakpointDisable(CommandInterpreter &interpreter)
: CommandObjectParsed(
interpreter, "breakpoint disable",
"Disable the specified breakpoint(s) without deleting "
"them. If none are specified, disable all "
"breakpoints.",
nullptr) {
SetHelpLong(
"Disable the specified breakpoint(s) without deleting them. \
If none are specified, disable all breakpoints."
R"(
)"
"Note: disabling a breakpoint will cause none of its locations to be hit \
regardless of whether individual locations are enabled or disabled. After the sequence:"
R"(
(lldb) break disable 1
(lldb) break enable 1.1
execution will NOT stop at location 1.1. To achieve that, type:
(lldb) break disable 1.*
(lldb) break enable 1.1
)"
"The first command disables all locations for breakpoint 1, \
the second re-enables the first location.");
CommandObject::AddIDsArgumentData(eBreakpointArgs);
}
~CommandObjectBreakpointDisable() override = default;
void