[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.
This commit is contained in:
Pavel Labath 2019-11-28 17:02:07 +01:00
parent 16d2013044
commit 28e4942b2c
9 changed files with 21 additions and 42 deletions

View File

@ -75,18 +75,6 @@ public:
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;

View File

@ -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);
}

View File

@ -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)
@ -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;

View File

@ -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

View File

@ -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));

View File

@ -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;
}
@ -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");
@ -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
@ -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");
@ -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();

View File

@ -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 {

View File

@ -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);
}
@ -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,

View File

@ -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.
///