Skip to content

Commit

Permalink
[lldb] BreakpointResolver{*}::CreateFromStructuredData should return …
Browse files Browse the repository at this point in the history
…shared pointers (#71477)

BreakpointResolver::CreateFromStructuredData returns a
BreakpointResolverSP, but all of the subclasses return raw pointers.
Instead of creating a raw pointer and shoving it into a shared pointer,
it seems reasonable to just create the shared pointer directly.
  • Loading branch information
bulbazord authored Nov 7, 2023
1 parent 009ba77 commit 03a92f0
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion lldb/include/lldb/Breakpoint/BreakpointResolverAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BreakpointResolverAddress : public BreakpointResolver {

~BreakpointResolverAddress() override = default;

static BreakpointResolver *
static lldb::BreakpointResolverSP
CreateFromStructuredData(const lldb::BreakpointSP &bkpt,
const StructuredData::Dictionary &options_dict,
Status &error);
Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BreakpointResolverFileLine : public BreakpointResolver {
const SourceLocationSpec &location_spec,
std::optional<llvm::StringRef> removed_prefix_opt = std::nullopt);

static BreakpointResolver *
static lldb::BreakpointResolverSP
CreateFromStructuredData(const lldb::BreakpointSP &bkpt,
const StructuredData::Dictionary &data_dict,
Status &error);
Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Breakpoint/BreakpointResolverFileRegex.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BreakpointResolverFileRegex : public BreakpointResolver {
const lldb::BreakpointSP &bkpt, RegularExpression regex,
const std::unordered_set<std::string> &func_name_set, bool exact_match);

static BreakpointResolver *
static lldb::BreakpointResolverSP
CreateFromStructuredData(const lldb::BreakpointSP &bkpt,
const StructuredData::Dictionary &options_dict,
Status &error);
Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Breakpoint/BreakpointResolverName.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class BreakpointResolverName : public BreakpointResolver {
lldb::LanguageType language, lldb::addr_t offset,
bool skip_prologue);

static BreakpointResolver *
static lldb::BreakpointResolverSP
CreateFromStructuredData(const lldb::BreakpointSP &bkpt,
const StructuredData::Dictionary &data_dict,
Status &error);
Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Breakpoint/BreakpointResolverScripted.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BreakpointResolverScripted : public BreakpointResolver {

~BreakpointResolverScripted() override = default;

static BreakpointResolver *
static lldb::BreakpointResolverSP
CreateFromStructuredData(const lldb::BreakpointSP &bkpt,
const StructuredData::Dictionary &options_dict,
Status &error);
Expand Down
19 changes: 9 additions & 10 deletions lldb/source/Breakpoint/BreakpointResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,25 @@ BreakpointResolverSP BreakpointResolver::CreateFromStructuredData(
return result_sp;
}

BreakpointResolver *resolver = nullptr;
switch (resolver_type) {
case FileLineResolver:
resolver = BreakpointResolverFileLine::CreateFromStructuredData(
result_sp = BreakpointResolverFileLine::CreateFromStructuredData(
nullptr, *subclass_options, error);
break;
case AddressResolver:
resolver = BreakpointResolverAddress::CreateFromStructuredData(
result_sp = BreakpointResolverAddress::CreateFromStructuredData(
nullptr, *subclass_options, error);
break;
case NameResolver:
resolver = BreakpointResolverName::CreateFromStructuredData(
result_sp = BreakpointResolverName::CreateFromStructuredData(
nullptr, *subclass_options, error);
break;
case FileRegexResolver:
resolver = BreakpointResolverFileRegex::CreateFromStructuredData(
result_sp = BreakpointResolverFileRegex::CreateFromStructuredData(
nullptr, *subclass_options, error);
break;
case PythonResolver:
resolver = BreakpointResolverScripted::CreateFromStructuredData(
result_sp = BreakpointResolverScripted::CreateFromStructuredData(
nullptr, *subclass_options, error);
break;
case ExceptionResolver:
Expand All @@ -139,12 +138,12 @@ BreakpointResolverSP BreakpointResolver::CreateFromStructuredData(
llvm_unreachable("Should never get an unresolvable resolver type.");
}

if (!resolver || error.Fail())
return result_sp;
if (error.Fail() || !result_sp)
return {};

// Add on the global offset option:
resolver->SetOffset(offset);
return BreakpointResolverSP(resolver);
result_sp->SetOffset(offset);
return result_sp;
}

StructuredData::DictionarySP BreakpointResolver::WrapOptionsDict(
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Breakpoint/BreakpointResolverAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ BreakpointResolverAddress::BreakpointResolverAddress(const BreakpointSP &bkpt,
: BreakpointResolver(bkpt, BreakpointResolver::AddressResolver),
m_addr(addr), m_resolved_addr(LLDB_INVALID_ADDRESS) {}

BreakpointResolver *BreakpointResolverAddress::CreateFromStructuredData(
BreakpointResolverSP BreakpointResolverAddress::CreateFromStructuredData(
const BreakpointSP &bkpt, const StructuredData::Dictionary &options_dict,
Status &error) {
llvm::StringRef module_name;
Expand All @@ -56,7 +56,8 @@ BreakpointResolver *BreakpointResolverAddress::CreateFromStructuredData(
}
module_filespec.SetFile(module_name, FileSpec::Style::native);
}
return new BreakpointResolverAddress(bkpt, address, module_filespec);
return std::make_shared<BreakpointResolverAddress>(bkpt, address,
module_filespec);
}

StructuredData::ObjectSP
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ BreakpointResolverFileLine::BreakpointResolverFileLine(
m_location_spec(location_spec), m_skip_prologue(skip_prologue),
m_removed_prefix_opt(removed_prefix_opt) {}

BreakpointResolver *BreakpointResolverFileLine::CreateFromStructuredData(
BreakpointResolverSP BreakpointResolverFileLine::CreateFromStructuredData(
const BreakpointSP &bkpt, const StructuredData::Dictionary &options_dict,
Status &error) {
llvm::StringRef filename;
Expand Down Expand Up @@ -90,8 +90,8 @@ BreakpointResolver *BreakpointResolverFileLine::CreateFromStructuredData(
if (!location_spec)
return nullptr;

return new BreakpointResolverFileLine(bkpt, offset, skip_prologue,
location_spec);
return std::make_shared<BreakpointResolverFileLine>(
bkpt, offset, skip_prologue, location_spec);
}

StructuredData::ObjectSP
Expand Down
10 changes: 5 additions & 5 deletions lldb/source/Breakpoint/BreakpointResolverFileRegex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ BreakpointResolverFileRegex::BreakpointResolverFileRegex(
m_regex(std::move(regex)), m_exact_match(exact_match),
m_function_names(func_names) {}

BreakpointResolver *BreakpointResolverFileRegex::CreateFromStructuredData(
const lldb::BreakpointSP &bkpt, const StructuredData::Dictionary &options_dict,
Status &error) {
BreakpointResolverSP BreakpointResolverFileRegex::CreateFromStructuredData(
const lldb::BreakpointSP &bkpt,
const StructuredData::Dictionary &options_dict, Status &error) {
bool success;

llvm::StringRef regex_string;
Expand Down Expand Up @@ -67,8 +67,8 @@ BreakpointResolver *BreakpointResolverFileRegex::CreateFromStructuredData(
}
}

return new BreakpointResolverFileRegex(bkpt, std::move(regex), names_set,
exact_match);
return std::make_shared<BreakpointResolverFileRegex>(bkpt, std::move(regex),
names_set, exact_match);
}

StructuredData::ObjectSP
Expand Down
17 changes: 9 additions & 8 deletions lldb/source/Breakpoint/BreakpointResolverName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ BreakpointResolverName::BreakpointResolverName(
m_regex(rhs.m_regex), m_match_type(rhs.m_match_type),
m_language(rhs.m_language), m_skip_prologue(rhs.m_skip_prologue) {}

BreakpointResolver *BreakpointResolverName::CreateFromStructuredData(
BreakpointResolverSP BreakpointResolverName::CreateFromStructuredData(
const BreakpointSP &bkpt, const StructuredData::Dictionary &options_dict,
Status &error) {
LanguageType language = eLanguageTypeUnknown;
Expand Down Expand Up @@ -122,8 +122,8 @@ BreakpointResolver *BreakpointResolverName::CreateFromStructuredData(
success = options_dict.GetValueForKeyAsString(
GetKey(OptionNames::RegexString), regex_text);
if (success) {
return new BreakpointResolverName(bkpt, RegularExpression(regex_text),
language, offset, skip_prologue);
return std::make_shared<BreakpointResolverName>(
bkpt, RegularExpression(regex_text), language, offset, skip_prologue);
} else {
StructuredData::Array *names_array;
success = options_dict.GetValueForKeyAsArray(
Expand Down Expand Up @@ -172,13 +172,14 @@ BreakpointResolver *BreakpointResolverName::CreateFromStructuredData(
name_masks.push_back(static_cast<FunctionNameType>(fnt));
}

BreakpointResolverName *resolver = new BreakpointResolverName(
bkpt, names[0].c_str(), name_masks[0], language,
Breakpoint::MatchType::Exact, offset, skip_prologue);
std::shared_ptr<BreakpointResolverName> resolver_sp =
std::make_shared<BreakpointResolverName>(
bkpt, names[0].c_str(), name_masks[0], language,
Breakpoint::MatchType::Exact, offset, skip_prologue);
for (size_t i = 1; i < num_elem; i++) {
resolver->AddNameLookup(ConstString(names[i]), name_masks[i]);
resolver_sp->AddNameLookup(ConstString(names[i]), name_masks[i]);
}
return resolver;
return resolver_sp;
}
}

Expand Down
9 changes: 4 additions & 5 deletions lldb/source/Breakpoint/BreakpointResolverScripted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ void BreakpointResolverScripted::NotifyBreakpointSet() {
CreateImplementationIfNeeded(GetBreakpoint());
}

BreakpointResolver *
BreakpointResolverScripted::CreateFromStructuredData(
BreakpointResolverSP BreakpointResolverScripted::CreateFromStructuredData(
const BreakpointSP &bkpt, const StructuredData::Dictionary &options_dict,
Status &error) {
llvm::StringRef class_name;
bool success;

success = options_dict.GetValueForKeyAsString(
GetKey(OptionNames::PythonClassName), class_name);
if (!success) {
Expand All @@ -80,8 +79,8 @@ BreakpointResolverScripted::CreateFromStructuredData(
if (options_dict.GetValueForKeyAsDictionary(GetKey(OptionNames::ScriptArgs),
args_dict))
args_data_impl.SetObjectSP(args_dict->shared_from_this());
return new BreakpointResolverScripted(bkpt, class_name, depth,
args_data_impl);
return std::make_shared<BreakpointResolverScripted>(bkpt, class_name, depth,
args_data_impl);
}

StructuredData::ObjectSP
Expand Down

0 comments on commit 03a92f0

Please sign in to comment.