Skip to content

Commit 28e4942

Browse files
committed
[lldb] Remove FileSpec(FileSpec*) constructor
This constructor was the cause of some pretty weird behavior. Remove it, and update all code to properly dereference the argument instead.
1 parent 16d2013 commit 28e4942

File tree

9 files changed

+21
-42
lines changed

9 files changed

+21
-42
lines changed

lldb/include/lldb/Utility/FileSpec.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,6 @@ class FileSpec {
7575

7676
explicit FileSpec(llvm::StringRef path, const llvm::Triple &triple);
7777

78-
/// Copy constructor
79-
///
80-
/// Makes a copy of the uniqued directory and filename strings from \a rhs
81-
/// if it is not nullptr.
82-
///
83-
/// \param[in] rhs
84-
/// A const FileSpec object pointer to copy if non-nullptr.
85-
FileSpec(const FileSpec *rhs);
86-
87-
/// Destructor.
88-
~FileSpec();
89-
9078
bool DirectoryEquals(const FileSpec &other) const;
9179

9280
bool FileEquals(const FileSpec &other) const;

lldb/source/API/SBThread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ SBError SBThread::JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line) {
10371037

10381038
Thread *thread = exe_ctx.GetThreadPtr();
10391039

1040-
Status err = thread->JumpToLine(file_spec.get(), line, true);
1040+
Status err = thread->JumpToLine(file_spec.ref(), line, true);
10411041
sb_error.SetError(err);
10421042
return LLDB_RECORD_RESULT(sb_error);
10431043
}

lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ const char *ObjectFilePECOFF::GetPluginDescriptionStatic() {
114114
ObjectFile *ObjectFilePECOFF::CreateInstance(const lldb::ModuleSP &module_sp,
115115
DataBufferSP &data_sp,
116116
lldb::offset_t data_offset,
117-
const lldb_private::FileSpec *file,
117+
const lldb_private::FileSpec *file_p,
118118
lldb::offset_t file_offset,
119119
lldb::offset_t length) {
120+
FileSpec file = file_p ? *file_p : FileSpec();
120121
if (!data_sp) {
121122
data_sp = MapFileData(file, length, file_offset);
122123
if (!data_sp)
@@ -135,7 +136,7 @@ ObjectFile *ObjectFilePECOFF::CreateInstance(const lldb::ModuleSP &module_sp,
135136
}
136137

137138
auto objfile_up = std::make_unique<ObjectFilePECOFF>(
138-
module_sp, data_sp, data_offset, file, file_offset, length);
139+
module_sp, data_sp, data_offset, file_p, file_offset, length);
139140
if (!objfile_up || !objfile_up->ParseHeader())
140141
return nullptr;
141142

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ static FileSpec GetXcodeSelectPath() {
11061106
std::string command_output;
11071107
Status status =
11081108
Host::RunShellCommand("/usr/bin/xcode-select --print-path",
1109-
nullptr, // current working directory
1109+
FileSpec(), // current working directory
11101110
&exit_status, &signo, &command_output,
11111111
std::chrono::seconds(2), // short timeout
11121112
false); // don't run in a shell

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@ ConstString PlatformMacOSX::GetSDKDirectory(lldb_private::Target &target) {
180180
std::string output;
181181
const char *command = "xcrun -sdk macosx --show-sdk-path";
182182
lldb_private::Status error = RunShellCommand(
183-
command, // shell command to run
184-
nullptr, // current working directory
185-
&status, // Put the exit status of the process in here
186-
&signo, // Put the signal that caused the process to exit in
187-
// here
183+
command, // shell command to run
184+
FileSpec(), // current working directory
185+
&status, // Put the exit status of the process in here
186+
&signo, // Put the signal that caused the process to exit in
187+
// here
188188
&output, // Get the output from the command and place it in this
189189
// string
190190
std::chrono::seconds(3));

lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static uint32_t chown_file(Platform *platform, const char *path,
223223
command.Printf(":%d", gid);
224224
command.Printf("%s", path);
225225
int status;
226-
platform->RunShellCommand(command.GetData(), nullptr, &status, nullptr,
226+
platform->RunShellCommand(command.GetData(), FileSpec(), &status, nullptr,
227227
nullptr, std::chrono::seconds(10));
228228
return status;
229229
}
@@ -248,7 +248,7 @@ PlatformPOSIX::PutFile(const lldb_private::FileSpec &source,
248248
StreamString command;
249249
command.Printf("cp %s %s", src_path.c_str(), dst_path.c_str());
250250
int status;
251-
RunShellCommand(command.GetData(), nullptr, &status, nullptr, nullptr,
251+
RunShellCommand(command.GetData(), FileSpec(), &status, nullptr, nullptr,
252252
std::chrono::seconds(10));
253253
if (status != 0)
254254
return Status("unable to perform copy");
@@ -278,7 +278,7 @@ PlatformPOSIX::PutFile(const lldb_private::FileSpec &source,
278278
GetHostname(), dst_path.c_str());
279279
LLDB_LOGF(log, "[PutFile] Running command: %s\n", command.GetData());
280280
int retcode;
281-
Host::RunShellCommand(command.GetData(), nullptr, &retcode, nullptr,
281+
Host::RunShellCommand(command.GetData(), FileSpec(), &retcode, nullptr,
282282
nullptr, std::chrono::minutes(1));
283283
if (retcode == 0) {
284284
// Don't chown a local file for a remote system
@@ -314,7 +314,7 @@ lldb_private::Status PlatformPOSIX::GetFile(
314314
StreamString cp_command;
315315
cp_command.Printf("cp %s %s", src_path.c_str(), dst_path.c_str());
316316
int status;
317-
RunShellCommand(cp_command.GetData(), nullptr, &status, nullptr, nullptr,
317+
RunShellCommand(cp_command.GetData(), FileSpec(), &status, nullptr, nullptr,
318318
std::chrono::seconds(10));
319319
if (status != 0)
320320
return Status("unable to perform copy");
@@ -335,7 +335,7 @@ lldb_private::Status PlatformPOSIX::GetFile(
335335
dst_path.c_str());
336336
LLDB_LOGF(log, "[GetFile] Running command: %s\n", command.GetData());
337337
int retcode;
338-
Host::RunShellCommand(command.GetData(), nullptr, &retcode, nullptr,
338+
Host::RunShellCommand(command.GetData(), FileSpec(), &retcode, nullptr,
339339
nullptr, std::chrono::minutes(1));
340340
if (retcode == 0)
341341
return Status();

lldb/source/Symbol/LocateSymbolFile.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,19 +230,19 @@ static FileSpec LocateExecutableSymbolFileDsym(const ModuleSpec &module_spec) {
230230

231231
ModuleSpec Symbols::LocateExecutableObjectFile(const ModuleSpec &module_spec) {
232232
ModuleSpec result;
233-
const FileSpec *exec_fspec = module_spec.GetFileSpecPtr();
233+
const FileSpec &exec_fspec = module_spec.GetFileSpec();
234234
const ArchSpec *arch = module_spec.GetArchitecturePtr();
235235
const UUID *uuid = module_spec.GetUUIDPtr();
236236
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
237237
Timer scoped_timer(
238238
func_cat, "LocateExecutableObjectFile (file = %s, arch = %s, uuid = %p)",
239-
exec_fspec ? exec_fspec->GetFilename().AsCString("<NULL>") : "<NULL>",
239+
exec_fspec ? exec_fspec.GetFilename().AsCString("<NULL>") : "<NULL>",
240240
arch ? arch->GetArchitectureName() : "<NULL>", (const void *)uuid);
241241

242242
ModuleSpecList module_specs;
243243
ModuleSpec matched_module_spec;
244244
if (exec_fspec &&
245-
ObjectFile::GetModuleSpecifications(*exec_fspec, 0, 0, module_specs) &&
245+
ObjectFile::GetModuleSpecifications(exec_fspec, 0, 0, module_specs) &&
246246
module_specs.FindMatchingModuleSpec(module_spec, matched_module_spec)) {
247247
result.GetFileSpec() = exec_fspec;
248248
} else {

lldb/source/Target/Target.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ Target::CreateAddressInModuleBreakpoint(lldb::addr_t file_addr, bool internal,
404404
bool request_hardware) {
405405
SearchFilterSP filter_sp(
406406
new SearchFilterForUnconstrainedSearches(shared_from_this()));
407-
BreakpointResolverSP resolver_sp(
408-
new BreakpointResolverAddress(nullptr, file_addr, file_spec));
407+
BreakpointResolverSP resolver_sp(new BreakpointResolverAddress(
408+
nullptr, file_addr, file_spec ? *file_spec : FileSpec()));
409409
return CreateBreakpoint(filter_sp, resolver_sp, internal, request_hardware,
410410
false);
411411
}
@@ -1425,8 +1425,7 @@ void Target::SetExecutableModule(ModuleSP &executable_sp,
14251425
ModuleList added_modules;
14261426
executable_objfile->GetDependentModules(dependent_files);
14271427
for (uint32_t i = 0; i < dependent_files.GetSize(); i++) {
1428-
FileSpec dependent_file_spec(
1429-
dependent_files.GetFileSpecPointerAtIndex(i));
1428+
FileSpec dependent_file_spec(dependent_files.GetFileSpecAtIndex(i));
14301429
FileSpec platform_dependent_file_spec;
14311430
if (m_platform_sp)
14321431
m_platform_sp->GetFileWithUUID(dependent_file_spec, nullptr,

lldb/source/Utility/FileSpec.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,6 @@ FileSpec::FileSpec(llvm::StringRef path, Style style) : m_style(style) {
7575
FileSpec::FileSpec(llvm::StringRef path, const llvm::Triple &triple)
7676
: FileSpec{path, triple.isOSWindows() ? Style::windows : Style::posix} {}
7777

78-
// Copy constructor
79-
FileSpec::FileSpec(const FileSpec *rhs) : m_directory(), m_filename() {
80-
if (rhs)
81-
*this = *rhs;
82-
}
83-
84-
// Virtual destructor in case anyone inherits from this class.
85-
FileSpec::~FileSpec() {}
86-
8778
namespace {
8879
/// Safely get a character at the specified index.
8980
///

0 commit comments

Comments
 (0)