Skip to content

Commit 23f1b98

Browse files
author
George Hu
committed
Address comment
1 parent cfe7d17 commit 23f1b98

File tree

5 files changed

+33
-48
lines changed

5 files changed

+33
-48
lines changed

lldb/include/lldb/Core/ModuleList.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ class ModuleList {
478478
GetSharedModule(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
479479
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
480480
bool *did_create_ptr, bool always_create = false,
481-
bool allow_locate_callback = true);
481+
bool invoke_locate_callback = true);
482482

483483
static bool RemoveSharedModule(lldb::ModuleSP &module_sp);
484484

lldb/include/lldb/Core/ModuleSpec.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "lldb/Utility/Iterable.h"
1717
#include "lldb/Utility/Stream.h"
1818
#include "lldb/Utility/UUID.h"
19+
#include "lldb/lldb-forward.h"
1920

2021
#include "llvm/Support/Chrono.h"
2122

@@ -127,15 +128,9 @@ class ModuleSpec {
127128

128129
lldb::DataBufferSP GetData() const { return m_data; }
129130

130-
Target *GetTargetPtr() {
131-
auto locked = m_target.lock();
132-
return locked.get();
133-
}
131+
lldb::TargetSP GetTargetSP() { return m_target.lock(); }
134132

135-
const Target *GetTargetPtr() const {
136-
auto locked = m_target.lock();
137-
return locked.get();
138-
}
133+
lldb::TargetSP GetTargetSP() const { return m_target.lock(); }
139134

140135
void SetTarget(std::shared_ptr<Target> target) { m_target = target; }
141136

lldb/source/Core/ModuleList.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ Status
10331033
ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
10341034
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
10351035
bool *did_create_ptr, bool always_create,
1036-
bool allow_locate_callback) {
1036+
bool invoke_locate_callback) {
10371037
ModuleList &shared_module_list = GetSharedModuleList();
10381038
std::lock_guard<std::recursive_mutex> guard(
10391039
shared_module_list.m_modules_mutex);
@@ -1089,18 +1089,16 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
10891089
if (module_sp)
10901090
return error;
10911091

1092-
// Try target's platform locate module callback before second attempt
1093-
if (allow_locate_callback) {
1094-
ModuleSpec module_spec_copy(module_spec);
1095-
Target *target = module_spec_copy.GetTargetPtr();
1096-
if (target && target->IsValid()) {
1097-
Platform *platform = target->GetPlatform().get();
1098-
if (platform) {
1092+
// Try target's platform locate module callback before second attempt.
1093+
if (invoke_locate_callback) {
1094+
TargetSP target_sp = module_spec.GetTargetSP();
1095+
if (target_sp && target_sp->IsValid()) {
1096+
if (PlatformSP platform_sp = target_sp->GetPlatform()) {
10991097
FileSpec symbol_file_spec;
1100-
platform->CallLocateModuleCallbackIfSet(
1098+
platform_sp->CallLocateModuleCallbackIfSet(
11011099
module_spec, module_sp, symbol_file_spec, did_create_ptr);
11021100
if (module_sp) {
1103-
// Success! The callback found a module
1101+
// The callback found a module.
11041102
return error;
11051103
}
11061104
}
@@ -1134,13 +1132,12 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
11341132
module_sp.reset();
11351133
}
11361134

1137-
// Get module search paths from the target if available
1138-
ModuleSpec module_spec_copy(module_spec);
1139-
Target *target = module_spec_copy.GetTargetPtr();
1135+
// Get module search paths from the target if available.
1136+
lldb::TargetSP target_sp = module_spec.GetTargetSP();
11401137
FileSpecList module_search_paths;
11411138
FileSpecList *module_search_paths_ptr = nullptr;
1142-
if (target && target->IsValid()) {
1143-
module_search_paths = target->GetExecutableSearchPaths();
1139+
if (target_sp && target_sp->IsValid()) {
1140+
module_search_paths = target_sp->GetExecutableSearchPaths();
11441141
module_search_paths_ptr = &module_search_paths;
11451142
}
11461143

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -350,16 +350,13 @@ Status PlatformDarwin::GetSharedModule(
350350
old_modules, did_create_ptr);
351351

352352
const FileSpec &platform_file = module_spec.GetFileSpec();
353-
// Get module search paths from the target if available
354-
ModuleSpec module_spec_copy(module_spec);
355-
Target *target = module_spec_copy.GetTargetPtr();
353+
// Get module search paths from the target if available.
354+
TargetSP target_sp = module_spec.GetTargetSP();
356355
FileSpecList module_search_paths;
357-
FileSpecList *module_search_paths_ptr = nullptr;
358-
if (target) {
359-
module_search_paths = target->GetExecutableSearchPaths();
360-
module_search_paths_ptr = &module_search_paths;
356+
if (target_sp) {
357+
module_search_paths = target_sp->GetExecutableSearchPaths();
361358
}
362-
if (!module_sp && module_search_paths_ptr && platform_file) {
359+
if (!module_sp && !module_search_paths.IsEmpty() && platform_file) {
363360
// We can try to pull off part of the file path up to the bundle
364361
// directory level and try any module search paths...
365362
FileSpec bundle_directory;
@@ -382,10 +379,10 @@ Status PlatformDarwin::GetSharedModule(
382379
const size_t bundle_directory_len =
383380
bundle_directory.GetPath(bundle_dir, sizeof(bundle_dir));
384381
char new_path[PATH_MAX];
385-
size_t num_module_search_paths = module_search_paths_ptr->GetSize();
382+
size_t num_module_search_paths = module_search_paths.GetSize();
386383
for (size_t i = 0; i < num_module_search_paths; ++i) {
387384
const size_t search_path_len =
388-
module_search_paths_ptr->GetFileSpecAtIndex(i).GetPath(
385+
module_search_paths.GetFileSpecAtIndex(i).GetPath(
389386
new_path, sizeof(new_path));
390387
if (search_path_len < sizeof(new_path)) {
391388
snprintf(new_path + search_path_len,
@@ -1311,17 +1308,14 @@ lldb_private::Status PlatformDarwin::FindBundleBinaryInExecSearchPaths(
13111308
const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp,
13121309
llvm::SmallVectorImpl<ModuleSP> *old_modules, bool *did_create_ptr) {
13131310
const FileSpec &platform_file = module_spec.GetFileSpec();
1314-
ModuleSpec module_spec_copy(module_spec);
1315-
Target *target = module_spec_copy.GetTargetPtr();
1311+
TargetSP target_sp = module_spec.GetTargetSP();
13161312
FileSpecList module_search_paths;
1317-
FileSpecList *module_search_paths_ptr = nullptr;
1318-
if (target) {
1319-
module_search_paths = target->GetExecutableSearchPaths();
1320-
module_search_paths_ptr = &module_search_paths;
1313+
if (target_sp) {
1314+
module_search_paths = target_sp->GetExecutableSearchPaths();
13211315
}
1322-
// See if the file is present in any of the module_search_paths_ptr
1316+
// See if the file is present in any of the module_search_paths
13231317
// directories.
1324-
if (!module_sp && module_search_paths_ptr && platform_file) {
1318+
if (!module_sp && !module_search_paths.IsEmpty() && platform_file) {
13251319
// create a vector of all the file / directory names in platform_file e.g.
13261320
// this might be
13271321
// /System/Library/PrivateFrameworks/UIFoundation.framework/UIFoundation
@@ -1335,21 +1329,21 @@ lldb_private::Status PlatformDarwin::FindBundleBinaryInExecSearchPaths(
13351329
std::reverse(path_parts.begin(), path_parts.end());
13361330
const size_t path_parts_size = path_parts.size();
13371331

1338-
size_t num_module_search_paths = module_search_paths_ptr->GetSize();
1332+
size_t num_module_search_paths = module_search_paths.GetSize();
13391333
for (size_t i = 0; i < num_module_search_paths; ++i) {
13401334
Log *log_verbose = GetLog(LLDBLog::Host);
13411335
LLDB_LOGF(
13421336
log_verbose,
13431337
"PlatformRemoteDarwinDevice::GetSharedModule searching for binary in "
13441338
"search-path %s",
1345-
module_search_paths_ptr->GetFileSpecAtIndex(i).GetPath().c_str());
1339+
module_search_paths.GetFileSpecAtIndex(i).GetPath().c_str());
13461340
// Create a new FileSpec with this module_search_paths_ptr plus just the
13471341
// filename ("UIFoundation"), then the parent dir plus filename
13481342
// ("UIFoundation.framework/UIFoundation") etc - up to four names (to
13491343
// handle "Foo.framework/Contents/MacOS/Foo")
13501344

13511345
for (size_t j = 0; j < 4 && j < path_parts_size - 1; ++j) {
1352-
FileSpec path_to_try(module_search_paths_ptr->GetFileSpecAtIndex(i));
1346+
FileSpec path_to_try(module_search_paths.GetFileSpecAtIndex(i));
13531347

13541348
// Add the components backwards. For
13551349
// .../PrivateFrameworks/UIFoundation.framework/UIFoundation path_parts

lldb/source/Target/Platform.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,15 +764,14 @@ Status Platform::ResolveExecutable(const ModuleSpec &module_spec,
764764
for (const ArchSpec &arch : GetSupportedArchitectures(process_host_arch)) {
765765
resolved_module_spec.GetArchitecture() = arch;
766766

767-
// Call locate module callback first, then fallback to standard path
767+
// Call locate module callback first, then fallback to standard path.
768768
FileSpec symbol_file_spec;
769769
CallLocateModuleCallbackIfSet(resolved_module_spec, exe_module_sp,
770770
symbol_file_spec, nullptr);
771771

772-
if (!exe_module_sp) {
772+
if (!exe_module_sp)
773773
error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
774774
nullptr, nullptr);
775-
}
776775

777776
error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
778777
nullptr, nullptr);

0 commit comments

Comments
 (0)