summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/Host/FileSpec.h11
-rw-r--r--lldb/include/lldb/Target/TargetList.h4
-rw-r--r--lldb/source/API/SBDebugger.cpp14
-rw-r--r--lldb/source/Commands/CommandObjectProcess.cpp6
-rw-r--r--lldb/source/Commands/CommandObjectTarget.cpp20
-rw-r--r--lldb/source/Host/common/FileSpec.cpp24
-rw-r--r--lldb/source/Host/common/Host.cpp2
-rw-r--r--lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp3
-rw-r--r--lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp3
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp3
-rw-r--r--lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp3
-rw-r--r--lldb/source/Target/TargetList.cpp67
12 files changed, 96 insertions, 64 deletions
diff --git a/lldb/include/lldb/Host/FileSpec.h b/lldb/include/lldb/Host/FileSpec.h
index 77bbab54a58..1551ec7f816 100644
--- a/lldb/include/lldb/Host/FileSpec.h
+++ b/lldb/include/lldb/Host/FileSpec.h
@@ -342,6 +342,17 @@ public:
bool
IsSourceImplementationFile () const;
+ //------------------------------------------------------------------
+ /// Returns true if the filespec represents path that is relative
+ /// path to the current working directory.
+ ///
+ /// @return
+ /// \b true if the filespec represents a current working
+ /// directory relative path, \b false otherwise.
+ //------------------------------------------------------------------
+ bool
+ IsRelativeToCurrentWorkingDirectory () const;
+
TimeValue
GetModificationTime () const;
diff --git a/lldb/include/lldb/Target/TargetList.h b/lldb/include/lldb/Target/TargetList.h
index 2e5663aba57..41404e11c7f 100644
--- a/lldb/include/lldb/Target/TargetList.h
+++ b/lldb/include/lldb/Target/TargetList.h
@@ -98,7 +98,7 @@ public:
//------------------------------------------------------------------
Error
CreateTarget (Debugger &debugger,
- const FileSpec& file_spec,
+ const char *user_exe_path,
const char *triple_cstr,
bool get_dependent_modules,
const OptionGroupPlatform *platform_options,
@@ -112,7 +112,7 @@ public:
//------------------------------------------------------------------
Error
CreateTarget (Debugger &debugger,
- const FileSpec& file_spec,
+ const char *user_exe_path,
const ArchSpec& arch,
bool get_dependent_modules,
lldb::PlatformSP &platform_sp,
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 3540b28a64c..94af6799b84 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -511,12 +511,11 @@ SBDebugger::CreateTarget (const char *filename,
if (m_opaque_sp)
{
sb_error.Clear();
- FileSpec filename_spec (filename, true);
OptionGroupPlatform platform_options (false);
platform_options.SetPlatformName (platform_name);
sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
- filename_spec,
+ filename,
target_triple,
add_dependent_modules,
&platform_options,
@@ -554,10 +553,9 @@ SBDebugger::CreateTargetWithFileAndTargetTriple (const char *filename,
TargetSP target_sp;
if (m_opaque_sp)
{
- FileSpec file_spec (filename, true);
const bool add_dependent_modules = true;
Error error (m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
- file_spec,
+ filename,
target_triple,
add_dependent_modules,
NULL,
@@ -584,12 +582,11 @@ SBDebugger::CreateTargetWithFileAndArch (const char *filename, const char *arch_
TargetSP target_sp;
if (m_opaque_sp)
{
- FileSpec file (filename, true);
Error error;
const bool add_dependent_modules = true;
- error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
- file,
+ error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
+ filename,
arch_cstr,
add_dependent_modules,
NULL,
@@ -618,14 +615,13 @@ SBDebugger::CreateTarget (const char *filename)
TargetSP target_sp;
if (m_opaque_sp)
{
- FileSpec file (filename, true);
ArchSpec arch = Target::GetDefaultArchitecture ();
Error error;
const bool add_dependent_modules = true;
PlatformSP platform_sp(m_opaque_sp->GetPlatformList().GetSelectedPlatform());
error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
- file,
+ filename,
arch,
add_dependent_modules,
platform_sp,
diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp
index 441aee9758f..764b1280813 100644
--- a/lldb/source/Commands/CommandObjectProcess.cpp
+++ b/lldb/source/Commands/CommandObjectProcess.cpp
@@ -521,11 +521,10 @@ protected:
{
// If there isn't a current target create one.
TargetSP new_target_sp;
- FileSpec emptyFileSpec;
Error error;
error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(),
- emptyFileSpec,
+ NULL,
NULL,
false,
NULL, // No platform options
@@ -1022,10 +1021,9 @@ protected:
if (!target_sp)
{
// If there isn't a current target create one.
- FileSpec emptyFileSpec;
error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(),
- emptyFileSpec,
+ NULL,
NULL,
false,
NULL, // No platform options
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 8c46487bb20..a8da9b880e8 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -221,17 +221,12 @@ protected:
{
const char *file_path = command.GetArgumentAtIndex(0);
Timer scoped_timer(__PRETTY_FUNCTION__, "(lldb) target create '%s'", file_path);
- FileSpec file_spec;
-
- if (file_path)
- file_spec.SetFile (file_path, true);
-
TargetSP target_sp;
Debugger &debugger = m_interpreter.GetDebugger();
const char *arch_cstr = m_arch_option.GetArchitectureName();
const bool get_dependent_files = true;
Error error (debugger.GetTargetList().CreateTarget (debugger,
- file_spec,
+ file_path,
arch_cstr,
get_dependent_files,
&m_platform_options,
@@ -1241,14 +1236,11 @@ DumpModuleUUID (Stream &strm, Module *module)
}
static uint32_t
-DumpCompileUnitLineTable
-(
- CommandInterpreter &interpreter,
- Stream &strm,
- Module *module,
- const FileSpec &file_spec,
- bool load_addresses
- )
+DumpCompileUnitLineTable (CommandInterpreter &interpreter,
+ Stream &strm,
+ Module *module,
+ const FileSpec &file_spec,
+ bool load_addresses)
{
uint32_t num_matches = 0;
if (module)
diff --git a/lldb/source/Host/common/FileSpec.cpp b/lldb/source/Host/common/FileSpec.cpp
index d104bd21c47..d356ff68495 100644
--- a/lldb/source/Host/common/FileSpec.cpp
+++ b/lldb/source/Host/common/FileSpec.cpp
@@ -996,4 +996,28 @@ FileSpec::IsSourceImplementationFile () const
return false;
}
+bool
+FileSpec::IsRelativeToCurrentWorkingDirectory () const
+{
+ const char *directory = m_directory.GetCString();
+ if (directory && directory[0])
+ {
+ // If the path doesn't start with '/' or '~', return true
+ switch (directory[0])
+ {
+ case '/':
+ case '~':
+ return false;
+ default:
+ return true;
+ }
+ }
+ else if (m_filename)
+ {
+ // No directory, just a basename, return true
+ return true;
+ }
+ return false;
+}
+
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index b25f8bcf1b1..2b5bec09121 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -1247,7 +1247,7 @@ Host::GetDummyTarget (lldb_private::Debugger &debugger)
if (!arch.IsValid())
arch = Host::GetArchitecture ();
Error err = debugger.GetTargetList().CreateTarget(debugger,
- FileSpec(),
+ NULL,
arch.GetTriple().getTriple().c_str(),
false,
NULL,
diff --git a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
index 5ed9b96ab13..0535626c0fd 100644
--- a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
+++ b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
@@ -498,11 +498,10 @@ PlatformFreeBSD::Attach(ProcessAttachInfo &attach_info,
if (target == NULL)
{
TargetSP new_target_sp;
- FileSpec emptyFileSpec;
ArchSpec emptyArchSpec;
error = debugger.GetTargetList().CreateTarget (debugger,
- emptyFileSpec,
+ NULL,
emptyArchSpec,
false,
m_remote_platform_sp,
diff --git a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
index 8d4ef495836..e45d6ed91c9 100644
--- a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
+++ b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
@@ -408,11 +408,10 @@ PlatformLinux::Attach(ProcessAttachInfo &attach_info,
if (target == NULL)
{
TargetSP new_target_sp;
- FileSpec emptyFileSpec;
ArchSpec emptyArchSpec;
error = debugger.GetTargetList().CreateTarget (debugger,
- emptyFileSpec,
+ NULL,
emptyArchSpec,
false,
m_remote_platform_sp,
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 4d5c722260d..7deadc0a493 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -533,10 +533,9 @@ PlatformDarwin::Attach (ProcessAttachInfo &attach_info,
if (target == NULL)
{
TargetSP new_target_sp;
- FileSpec emptyFileSpec;
error = debugger.GetTargetList().CreateTarget (debugger,
- emptyFileSpec,
+ NULL,
NULL,
false,
NULL,
diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
index 2f3b77e9cd7..5931f87bfb6 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -368,10 +368,9 @@ PlatformRemoteGDBServer::Attach (lldb_private::ProcessAttachInfo &attach_info,
if (target == NULL)
{
TargetSP new_target_sp;
- FileSpec emptyFileSpec;
error = debugger.GetTargetList().CreateTarget (debugger,
- emptyFileSpec,
+ NULL,
NULL,
false,
NULL,
diff --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp
index 3f24dd60226..93ac3339943 100644
--- a/lldb/source/Target/TargetList.cpp
+++ b/lldb/source/Target/TargetList.cpp
@@ -57,7 +57,7 @@ TargetList::~TargetList()
Error
TargetList::CreateTarget (Debugger &debugger,
- const FileSpec& file,
+ const char *user_exe_path,
const char *triple_cstr,
bool get_dependent_files,
const OptionGroupPlatform *platform_options,
@@ -112,39 +112,25 @@ TargetList::CreateTarget (Debugger &debugger,
platform_arch = arch;
error = TargetList::CreateTarget (debugger,
- file,
+ user_exe_path,
platform_arch,
get_dependent_files,
platform_sp,
target_sp);
-
- if (target_sp)
- {
- if (file.GetDirectory())
- {
- FileSpec file_dir;
- file_dir.GetDirectory() = file.GetDirectory();
- target_sp->GetExecutableSearchPaths ().Append (file_dir);
- }
- }
return error;
}
Error
-TargetList::CreateTarget
-(
- Debugger &debugger,
- const FileSpec& file,
- const ArchSpec& specified_arch,
- bool get_dependent_files,
- PlatformSP &platform_sp,
- TargetSP &target_sp
-)
+TargetList::CreateTarget (Debugger &debugger,
+ const char *user_exe_path,
+ const ArchSpec& specified_arch,
+ bool get_dependent_files,
+ PlatformSP &platform_sp,
+ TargetSP &target_sp)
{
Timer scoped_timer (__PRETTY_FUNCTION__,
- "TargetList::CreateTarget (file = '%s/%s', arch = '%s')",
- file.GetDirectory().AsCString(),
- file.GetFilename().AsCString(),
+ "TargetList::CreateTarget (file = '%s', arch = '%s')",
+ user_exe_path,
specified_arch.GetArchitectureName());
Error error;
@@ -168,12 +154,28 @@ TargetList::CreateTarget
if (!arch.IsValid())
arch = specified_arch;
-
+ FileSpec file (user_exe_path, false);
if (file)
{
+ if (file.IsRelativeToCurrentWorkingDirectory())
+ {
+ // Ignore paths that start with "./" and "../"
+ if (!((user_exe_path[0] == '.' && user_exe_path[1] == '/') ||
+ (user_exe_path[0] == '.' && user_exe_path[1] == '.' && user_exe_path[2] == '/')))
+ {
+ char cwd[PATH_MAX];
+ if (getcwd (cwd, sizeof(cwd)))
+ {
+ std::string cwd_user_exe_path (cwd);
+ cwd_user_exe_path += '/';
+ cwd_user_exe_path += user_exe_path;
+ file.SetFile(cwd_user_exe_path.c_str(), false);
+ }
+ }
+ }
+
ModuleSP exe_module_sp;
- FileSpec resolved_file(file);
if (platform_sp)
{
FileSpecList executable_search_paths (Target::GetDefaultExecutableSearchPaths());
@@ -217,9 +219,22 @@ TargetList::CreateTarget
if (target_sp)
{
+ if (user_exe_path)
+ {
+ // Use exactly what the user typed as the first argument when we exec or posix_spawn
+ target_sp->SetArg0 (user_exe_path);
+ }
+ if (file.GetDirectory())
+ {
+ FileSpec file_dir;
+ file_dir.GetDirectory() = file.GetDirectory();
+ target_sp->GetExecutableSearchPaths ().Append (file_dir);
+ }
Mutex::Locker locker(m_target_list_mutex);
m_selected_target_idx = m_target_list.size();
m_target_list.push_back(target_sp);
+
+
}
return error;
OpenPOWER on IntegriCloud