Skip to content

Commit d2d55fa

Browse files
committed
resolve lldb-dap persistent breakpoints with symbol name and instructions offset
1 parent 89c9849 commit d2d55fa

File tree

20 files changed

+98
-102
lines changed

20 files changed

+98
-102
lines changed

lldb/include/lldb/API/SBTarget.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "lldb/API/SBValue.h"
2424
#include "lldb/API/SBWatchpoint.h"
2525
#include "lldb/API/SBWatchpointOptions.h"
26-
#include "lldb/lldb-types.h"
2726

2827
namespace lldb_private {
2928
namespace python {
@@ -659,6 +658,14 @@ class LLDB_API SBTarget {
659658
lldb::LanguageType symbol_language,
660659
const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list);
661660

661+
lldb::SBBreakpoint BreakpointCreateByName(
662+
const char *symbol_name,
663+
uint32_t
664+
name_type_mask, // Logical OR one or more FunctionNameType enum bits
665+
lldb::LanguageType symbol_language, lldb::addr_t offset,
666+
bool offset_is_insn_count, const SBFileSpecList &module_list,
667+
const SBFileSpecList &comp_unit_list);
668+
662669
#ifdef SWIG
663670
lldb::SBBreakpoint BreakpointCreateByNames(
664671
const char **symbol_name, uint32_t num_names,
@@ -738,11 +745,6 @@ class LLDB_API SBTarget {
738745

739746
lldb::SBBreakpoint BreakpointCreateBySBAddress(SBAddress &address);
740747

741-
lldb::SBBreakpoint
742-
BreakpointCreateByFileAddress(const SBFileSpec &file_spec, addr_t file_addr,
743-
addr_t offset = 0,
744-
addr_t instructions_offset = 0);
745-
746748
/// Create a breakpoint using a scripted resolver.
747749
///
748750
/// \param[in] class_name

lldb/include/lldb/Breakpoint/BreakpointResolver.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class BreakpointResolver : public Searcher {
4848
/// The concrete breakpoint resolver type for this breakpoint.
4949
BreakpointResolver(const lldb::BreakpointSP &bkpt, unsigned char resolverType,
5050
lldb::addr_t offset = 0,
51-
lldb::addr_t instructions_offset = 0);
51+
bool offset_is_insn_count = false);
5252

5353
/// The Destructor is virtual, all significant breakpoint resolvers derive
5454
/// from this class.
@@ -77,6 +77,7 @@ class BreakpointResolver : public Searcher {
7777
void SetOffset(lldb::addr_t offset);
7878

7979
lldb::addr_t GetOffset() const { return m_offset; }
80+
lldb::addr_t GetOffsetIsInsnCount() const { return m_offset_is_insn_count; }
8081

8182
/// In response to this method the resolver scans all the modules in the
8283
/// breakpoint's target, and adds any new locations it finds.
@@ -183,7 +184,6 @@ class BreakpointResolver : public Searcher {
183184
SearchDepth,
184185
SkipPrologue,
185186
SymbolNameArray,
186-
InstructionsOffset,
187187
LastOptionName
188188
};
189189
static const char
@@ -222,8 +222,8 @@ class BreakpointResolver : public Searcher {
222222
lldb::BreakpointWP m_breakpoint; // This is the breakpoint we add locations to.
223223
lldb::addr_t m_offset; // A random offset the user asked us to add to any
224224
// breakpoints we set.
225-
lldb::addr_t m_instructions_offset; // Number of instructions to add to the
226-
// resolved breakpoint address.
225+
bool m_offset_is_insn_count; // Use the offset as an instruction count
226+
// instead of an address offset.
227227

228228
// Subclass identifier (for llvm isa/dyn_cast)
229229
const unsigned char SubclassID;

lldb/include/lldb/Breakpoint/BreakpointResolverAddress.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ class BreakpointResolverAddress : public BreakpointResolver {
2828
const Address &addr,
2929
const FileSpec &module_spec);
3030

31-
BreakpointResolverAddress(const lldb::BreakpointSP &bkpt, const Address &addr,
32-
const FileSpec &module_spec, lldb::addr_t offset,
33-
lldb::addr_t instructions_offset);
34-
3531
~BreakpointResolverAddress() override = default;
3632

3733
static lldb::BreakpointResolverSP

lldb/include/lldb/Breakpoint/BreakpointResolverName.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class BreakpointResolverName : public BreakpointResolver {
2727
lldb::FunctionNameType name_type_mask,
2828
lldb::LanguageType language,
2929
Breakpoint::MatchType type, lldb::addr_t offset,
30-
bool skip_prologue);
30+
bool offset_is_insn_count, bool skip_prologue);
3131

3232
// This one takes an array of names. It is always MatchType = Exact.
3333
BreakpointResolverName(const lldb::BreakpointSP &bkpt, const char *names[],

lldb/include/lldb/Target/Target.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -725,10 +725,10 @@ class Target : public std::enable_shared_from_this<Target>,
725725
bool request_hardware);
726726

727727
// Use this to create a breakpoint from a file address and a module file spec
728-
lldb::BreakpointSP CreateAddressInModuleBreakpoint(
729-
lldb::addr_t file_addr, bool internal, const FileSpec &file_spec,
730-
bool request_hardware, lldb::addr_t offset = 0,
731-
lldb::addr_t instructions_offset = 0);
728+
lldb::BreakpointSP CreateAddressInModuleBreakpoint(lldb::addr_t file_addr,
729+
bool internal,
730+
const FileSpec &file_spec,
731+
bool request_hardware);
732732

733733
// Use this to create Address breakpoints:
734734
lldb::BreakpointSP CreateBreakpoint(const Address &addr, bool internal,
@@ -753,8 +753,8 @@ class Target : public std::enable_shared_from_this<Target>,
753753
const FileSpecList *containingModules,
754754
const FileSpecList *containingSourceFiles, const char *func_name,
755755
lldb::FunctionNameType func_name_type_mask, lldb::LanguageType language,
756-
lldb::addr_t offset, LazyBool skip_prologue, bool internal,
757-
bool request_hardware);
756+
lldb::addr_t offset, bool offset_is_insn_count, LazyBool skip_prologue,
757+
bool internal, bool request_hardware);
758758

759759
lldb::BreakpointSP
760760
CreateExceptionBreakpoint(enum lldb::LanguageType language, bool catch_bp,

lldb/source/API/SBTarget.cpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -766,16 +766,19 @@ SBBreakpoint SBTarget::BreakpointCreateByName(const char *symbol_name,
766766
const bool hardware = false;
767767
const LazyBool skip_prologue = eLazyBoolCalculate;
768768
const lldb::addr_t offset = 0;
769+
const bool offset_is_insn_count = false;
769770
if (module_name && module_name[0]) {
770771
FileSpecList module_spec_list;
771772
module_spec_list.Append(FileSpec(module_name));
772773
sb_bp = target_sp->CreateBreakpoint(
773774
&module_spec_list, nullptr, symbol_name, eFunctionNameTypeAuto,
774-
eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
775+
eLanguageTypeUnknown, offset, offset_is_insn_count, skip_prologue,
776+
internal, hardware);
775777
} else {
776778
sb_bp = target_sp->CreateBreakpoint(
777779
nullptr, nullptr, symbol_name, eFunctionNameTypeAuto,
778-
eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
780+
eLanguageTypeUnknown, offset, offset_is_insn_count, skip_prologue,
781+
internal, hardware);
779782
}
780783
}
781784

@@ -811,6 +814,17 @@ lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
811814
const SBFileSpecList &comp_unit_list) {
812815
LLDB_INSTRUMENT_VA(this, symbol_name, name_type_mask, symbol_language,
813816
module_list, comp_unit_list);
817+
return BreakpointCreateByName(symbol_name, name_type_mask, symbol_language, 0,
818+
false, module_list, comp_unit_list);
819+
}
820+
821+
lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
822+
const char *symbol_name, uint32_t name_type_mask,
823+
LanguageType symbol_language, lldb::addr_t offset,
824+
bool offset_is_insn_count, const SBFileSpecList &module_list,
825+
const SBFileSpecList &comp_unit_list) {
826+
LLDB_INSTRUMENT_VA(this, symbol_name, name_type_mask, symbol_language, offset,
827+
offset_is_insn_count, module_list, comp_unit_list);
814828

815829
SBBreakpoint sb_bp;
816830
if (TargetSP target_sp = GetSP();
@@ -821,7 +835,8 @@ lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
821835
std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
822836
FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
823837
sb_bp = target_sp->CreateBreakpoint(module_list.get(), comp_unit_list.get(),
824-
symbol_name, mask, symbol_language, 0,
838+
symbol_name, mask, symbol_language,
839+
offset, offset_is_insn_count,
825840
skip_prologue, internal, hardware);
826841
}
827842

@@ -949,24 +964,6 @@ SBBreakpoint SBTarget::BreakpointCreateBySBAddress(SBAddress &sb_address) {
949964
return sb_bp;
950965
}
951966

952-
SBBreakpoint
953-
SBTarget::BreakpointCreateByFileAddress(const SBFileSpec &file_spec,
954-
addr_t file_addr, addr_t offset,
955-
addr_t instructions_offset) {
956-
LLDB_INSTRUMENT_VA(this, file_spec, file_addr);
957-
958-
SBBreakpoint sb_bp;
959-
if (TargetSP target_sp = GetSP()) {
960-
std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
961-
const bool hardware = false;
962-
sb_bp = target_sp->CreateAddressInModuleBreakpoint(
963-
file_addr, false, *file_spec.get(), hardware, offset,
964-
instructions_offset);
965-
}
966-
967-
return sb_bp;
968-
}
969-
970967
lldb::SBBreakpoint
971968
SBTarget::BreakpointCreateBySourceRegex(const char *source_regex,
972969
const lldb::SBFileSpec &source_file,

lldb/source/Breakpoint/BreakpointResolver.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ const char *BreakpointResolver::g_ty_to_name[] = {"FileAndLine", "Address",
4343

4444
const char *BreakpointResolver::g_option_names[static_cast<uint32_t>(
4545
BreakpointResolver::OptionNames::LastOptionName)] = {
46-
"AddressOffset", "Exact", "FileName",
47-
"Inlines", "Language", "LineNumber",
48-
"Column", "ModuleName", "NameMask",
49-
"Offset", "PythonClass", "Regex",
50-
"ScriptArgs", "SectionName", "SearchDepth",
51-
"SkipPrologue", "SymbolNames", "InstructionsOffset"};
46+
"AddressOffset", "Exact", "FileName", "Inlines", "Language",
47+
"LineNumber", "Column", "ModuleName", "NameMask", "Offset",
48+
"PythonClass", "Regex", "ScriptArgs", "SectionName", "SearchDepth",
49+
"SkipPrologue", "SymbolNames"};
5250

5351
const char *BreakpointResolver::ResolverTyToName(enum ResolverTy type) {
5452
if (type > LastKnownResolverType)
@@ -69,9 +67,9 @@ BreakpointResolver::NameToResolverTy(llvm::StringRef name) {
6967
BreakpointResolver::BreakpointResolver(const BreakpointSP &bkpt,
7068
const unsigned char resolverTy,
7169
lldb::addr_t offset,
72-
lldb::addr_t instructions_offset)
70+
bool offset_is_insn_count)
7371
: m_breakpoint(bkpt), m_offset(offset),
74-
m_instructions_offset(instructions_offset), SubclassID(resolverTy) {}
72+
m_offset_is_insn_count(offset_is_insn_count), SubclassID(resolverTy) {}
7573

7674
BreakpointResolver::~BreakpointResolver() = default;
7775

@@ -369,14 +367,15 @@ void BreakpointResolver::AddLocation(SearchFilter &filter,
369367

370368
BreakpointLocationSP BreakpointResolver::AddLocation(Address loc_addr,
371369
bool *new_location) {
372-
if (m_instructions_offset != 0) {
370+
if (m_offset_is_insn_count && m_offset > 0) {
373371
Target &target = GetBreakpoint()->GetTarget();
374372
const DisassemblerSP instructions =
375-
target.ReadInstructions(loc_addr, m_instructions_offset);
373+
target.ReadInstructions(loc_addr, m_offset);
376374
loc_addr.Slide(instructions->GetInstructionList().GetTotalByteSize());
375+
} else if (!m_offset_is_insn_count) {
376+
loc_addr.Slide(m_offset);
377377
}
378378

379-
loc_addr.Slide(m_offset);
380379
return GetBreakpoint()->AddLocation(loc_addr, new_location);
381380
}
382381

lldb/source/Breakpoint/BreakpointResolverAddress.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ BreakpointResolverAddress::BreakpointResolverAddress(const BreakpointSP &bkpt,
3030
: BreakpointResolver(bkpt, BreakpointResolver::AddressResolver),
3131
m_addr(addr), m_resolved_addr(LLDB_INVALID_ADDRESS) {}
3232

33-
BreakpointResolverAddress::BreakpointResolverAddress(
34-
const BreakpointSP &bkpt, const Address &addr, const FileSpec &module_spec,
35-
lldb::addr_t offset, lldb::addr_t instructions_offset)
36-
: BreakpointResolver(bkpt, BreakpointResolver::AddressResolver, offset,
37-
instructions_offset),
38-
m_addr(addr), m_resolved_addr(LLDB_INVALID_ADDRESS),
39-
m_module_filespec(module_spec) {}
40-
4133
BreakpointResolverSP BreakpointResolverAddress::CreateFromStructuredData(
4234
const StructuredData::Dictionary &options_dict, Status &error) {
4335
llvm::StringRef module_name;

lldb/source/Breakpoint/BreakpointResolverName.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
using namespace lldb;
2525
using namespace lldb_private;
2626

27-
BreakpointResolverName::BreakpointResolverName(const BreakpointSP &bkpt,
28-
const char *name_cstr, FunctionNameType name_type_mask,
29-
LanguageType language, Breakpoint::MatchType type, lldb::addr_t offset,
27+
BreakpointResolverName::BreakpointResolverName(
28+
const BreakpointSP &bkpt, const char *name_cstr,
29+
FunctionNameType name_type_mask, LanguageType language,
30+
Breakpoint::MatchType type, lldb::addr_t offset, bool offset_is_insn_count,
3031
bool skip_prologue)
31-
: BreakpointResolver(bkpt, BreakpointResolver::NameResolver, offset),
32+
: BreakpointResolver(bkpt, BreakpointResolver::NameResolver, offset,
33+
offset_is_insn_count),
3234
m_match_type(type), m_language(language), m_skip_prologue(skip_prologue) {
3335
if (m_match_type == Breakpoint::Regexp) {
3436
m_regex = RegularExpression(name_cstr);
@@ -81,7 +83,7 @@ BreakpointResolverName::BreakpointResolverName(const BreakpointSP &bkpt,
8183
BreakpointResolverName::BreakpointResolverName(
8284
const BreakpointResolverName &rhs)
8385
: BreakpointResolver(rhs.GetBreakpoint(), BreakpointResolver::NameResolver,
84-
rhs.GetOffset()),
86+
rhs.GetOffset(), rhs.GetOffsetIsInsnCount()),
8587
m_lookups(rhs.m_lookups), m_class_name(rhs.m_class_name),
8688
m_regex(rhs.m_regex), m_match_type(rhs.m_match_type),
8789
m_language(rhs.m_language), m_skip_prologue(rhs.m_skip_prologue) {}
@@ -177,7 +179,7 @@ BreakpointResolverSP BreakpointResolverName::CreateFromStructuredData(
177179
std::shared_ptr<BreakpointResolverName> resolver_sp =
178180
std::make_shared<BreakpointResolverName>(
179181
nullptr, names[0].c_str(), name_masks[0], language,
180-
Breakpoint::MatchType::Exact, offset, skip_prologue);
182+
Breakpoint::MatchType::Exact, offset, false, skip_prologue);
181183
for (size_t i = 1; i < num_elem; i++) {
182184
resolver_sp->AddNameLookup(ConstString(names[i]), name_masks[i]);
183185
}

lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ void DynamicLoaderDarwinKernel::SetNotificationBreakpointIfNeeded() {
15611561
.CreateBreakpoint(&module_spec_list, nullptr,
15621562
"OSKextLoadedKextSummariesUpdated",
15631563
eFunctionNameTypeFull, eLanguageTypeUnknown, 0,
1564-
skip_prologue, internal_bp, hardware)
1564+
false, skip_prologue, internal_bp, hardware)
15651565
.get();
15661566

15671567
bp->SetCallback(DynamicLoaderDarwinKernel::BreakpointHitCallback, this,

0 commit comments

Comments
 (0)