Skip to content

Commit

Permalink
[lldb] Remove FileSpec(FileSpec*) constructor
Browse files Browse the repository at this point in the history
This constructor was the cause of some pretty weird behavior. Remove it,
and update all code to properly dereference the argument instead.
  • Loading branch information
labath committed Dec 4, 2019
1 parent 16d2013 commit 28e4942
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 42 deletions.
12 changes: 0 additions & 12 deletions lldb/include/lldb/Utility/FileSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,6 @@ class FileSpec {

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

/// Copy constructor
///
/// Makes a copy of the uniqued directory and filename strings from \a rhs
/// if it is not nullptr.
///
/// \param[in] rhs
/// A const FileSpec object pointer to copy if non-nullptr.
FileSpec(const FileSpec *rhs);

/// Destructor.
~FileSpec();

bool DirectoryEquals(const FileSpec &other) const;

bool FileEquals(const FileSpec &other) const;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/API/SBThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ SBError SBThread::JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line) {

Thread *thread = exe_ctx.GetThreadPtr();

Status err = thread->JumpToLine(file_spec.get(), line, true);
Status err = thread->JumpToLine(file_spec.ref(), line, true);
sb_error.SetError(err);
return LLDB_RECORD_RESULT(sb_error);
}
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ const char *ObjectFilePECOFF::GetPluginDescriptionStatic() {
ObjectFile *ObjectFilePECOFF::CreateInstance(const lldb::ModuleSP &module_sp,
DataBufferSP &data_sp,
lldb::offset_t data_offset,
const lldb_private::FileSpec *file,
const lldb_private::FileSpec *file_p,
lldb::offset_t file_offset,
lldb::offset_t length) {
FileSpec file = file_p ? *file_p : FileSpec();
if (!data_sp) {
data_sp = MapFileData(file, length, file_offset);
if (!data_sp)
Expand All @@ -135,7 +136,7 @@ ObjectFile *ObjectFilePECOFF::CreateInstance(const lldb::ModuleSP &module_sp,
}

auto objfile_up = std::make_unique<ObjectFilePECOFF>(
module_sp, data_sp, data_offset, file, file_offset, length);
module_sp, data_sp, data_offset, file_p, file_offset, length);
if (!objfile_up || !objfile_up->ParseHeader())
return nullptr;

Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ static FileSpec GetXcodeSelectPath() {
std::string command_output;
Status status =
Host::RunShellCommand("/usr/bin/xcode-select --print-path",
nullptr, // current working directory
FileSpec(), // current working directory
&exit_status, &signo, &command_output,
std::chrono::seconds(2), // short timeout
false); // don't run in a shell
Expand Down
10 changes: 5 additions & 5 deletions lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ ConstString PlatformMacOSX::GetSDKDirectory(lldb_private::Target &target) {
std::string output;
const char *command = "xcrun -sdk macosx --show-sdk-path";
lldb_private::Status error = RunShellCommand(
command, // shell command to run
nullptr, // current working directory
&status, // Put the exit status of the process in here
&signo, // Put the signal that caused the process to exit in
// here
command, // shell command to run
FileSpec(), // current working directory
&status, // Put the exit status of the process in here
&signo, // Put the signal that caused the process to exit in
// here
&output, // Get the output from the command and place it in this
// string
std::chrono::seconds(3));
Expand Down
10 changes: 5 additions & 5 deletions lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static uint32_t chown_file(Platform *platform, const char *path,
command.Printf(":%d", gid);
command.Printf("%s", path);
int status;
platform->RunShellCommand(command.GetData(), nullptr, &status, nullptr,
platform->RunShellCommand(command.GetData(), FileSpec(), &status, nullptr,
nullptr, std::chrono::seconds(10));
return status;
}
Expand All @@ -248,7 +248,7 @@ PlatformPOSIX::PutFile(const lldb_private::FileSpec &source,
StreamString command;
command.Printf("cp %s %s", src_path.c_str(), dst_path.c_str());
int status;
RunShellCommand(command.GetData(), nullptr, &status, nullptr, nullptr,
RunShellCommand(command.GetData(), FileSpec(), &status, nullptr, nullptr,
std::chrono::seconds(10));
if (status != 0)
return Status("unable to perform copy");
Expand Down Expand Up @@ -278,7 +278,7 @@ PlatformPOSIX::PutFile(const lldb_private::FileSpec &source,
GetHostname(), dst_path.c_str());
LLDB_LOGF(log, "[PutFile] Running command: %s\n", command.GetData());
int retcode;
Host::RunShellCommand(command.GetData(), nullptr, &retcode, nullptr,
Host::RunShellCommand(command.GetData(), FileSpec(), &retcode, nullptr,
nullptr, std::chrono::minutes(1));
if (retcode == 0) {
// Don't chown a local file for a remote system
Expand Down Expand Up @@ -314,7 +314,7 @@ lldb_private::Status PlatformPOSIX::GetFile(
StreamString cp_command;
cp_command.Printf("cp %s %s", src_path.c_str(), dst_path.c_str());
int status;
RunShellCommand(cp_command.GetData(), nullptr, &status, nullptr, nullptr,
RunShellCommand(cp_command.GetData(), FileSpec(), &status, nullptr, nullptr,
std::chrono::seconds(10));
if (status != 0)
return Status("unable to perform copy");
Expand All @@ -335,7 +335,7 @@ lldb_private::Status PlatformPOSIX::GetFile(
dst_path.c_str());
LLDB_LOGF(log, "[GetFile] Running command: %s\n", command.GetData());
int retcode;
Host::RunShellCommand(command.GetData(), nullptr, &retcode, nullptr,
Host::RunShellCommand(command.GetData(), FileSpec(), &retcode, nullptr,
nullptr, std::chrono::minutes(1));
if (retcode == 0)
return Status();
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Symbol/LocateSymbolFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,19 @@ static FileSpec LocateExecutableSymbolFileDsym(const ModuleSpec &module_spec) {

ModuleSpec Symbols::LocateExecutableObjectFile(const ModuleSpec &module_spec) {
ModuleSpec result;
const FileSpec *exec_fspec = module_spec.GetFileSpecPtr();
const FileSpec &exec_fspec = module_spec.GetFileSpec();
const ArchSpec *arch = module_spec.GetArchitecturePtr();
const UUID *uuid = module_spec.GetUUIDPtr();
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(
func_cat, "LocateExecutableObjectFile (file = %s, arch = %s, uuid = %p)",
exec_fspec ? exec_fspec->GetFilename().AsCString("<NULL>") : "<NULL>",
exec_fspec ? exec_fspec.GetFilename().AsCString("<NULL>") : "<NULL>",
arch ? arch->GetArchitectureName() : "<NULL>", (const void *)uuid);

ModuleSpecList module_specs;
ModuleSpec matched_module_spec;
if (exec_fspec &&
ObjectFile::GetModuleSpecifications(*exec_fspec, 0, 0, module_specs) &&
ObjectFile::GetModuleSpecifications(exec_fspec, 0, 0, module_specs) &&
module_specs.FindMatchingModuleSpec(module_spec, matched_module_spec)) {
result.GetFileSpec() = exec_fspec;
} else {
Expand Down
7 changes: 3 additions & 4 deletions lldb/source/Target/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ Target::CreateAddressInModuleBreakpoint(lldb::addr_t file_addr, bool internal,
bool request_hardware) {
SearchFilterSP filter_sp(
new SearchFilterForUnconstrainedSearches(shared_from_this()));
BreakpointResolverSP resolver_sp(
new BreakpointResolverAddress(nullptr, file_addr, file_spec));
BreakpointResolverSP resolver_sp(new BreakpointResolverAddress(
nullptr, file_addr, file_spec ? *file_spec : FileSpec()));
return CreateBreakpoint(filter_sp, resolver_sp, internal, request_hardware,
false);
}
Expand Down Expand Up @@ -1425,8 +1425,7 @@ void Target::SetExecutableModule(ModuleSP &executable_sp,
ModuleList added_modules;
executable_objfile->GetDependentModules(dependent_files);
for (uint32_t i = 0; i < dependent_files.GetSize(); i++) {
FileSpec dependent_file_spec(
dependent_files.GetFileSpecPointerAtIndex(i));
FileSpec dependent_file_spec(dependent_files.GetFileSpecAtIndex(i));
FileSpec platform_dependent_file_spec;
if (m_platform_sp)
m_platform_sp->GetFileWithUUID(dependent_file_spec, nullptr,
Expand Down
9 changes: 0 additions & 9 deletions lldb/source/Utility/FileSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@ FileSpec::FileSpec(llvm::StringRef path, Style style) : m_style(style) {
FileSpec::FileSpec(llvm::StringRef path, const llvm::Triple &triple)
: FileSpec{path, triple.isOSWindows() ? Style::windows : Style::posix} {}

// Copy constructor
FileSpec::FileSpec(const FileSpec *rhs) : m_directory(), m_filename() {
if (rhs)
*this = *rhs;
}

// Virtual destructor in case anyone inherits from this class.
FileSpec::~FileSpec() {}

namespace {
/// Safely get a character at the specified index.
///
Expand Down

0 comments on commit 28e4942

Please sign in to comment.