Index: include/lldb/Host/Host.h =================================================================== --- include/lldb/Host/Host.h +++ include/lldb/Host/Host.h @@ -261,22 +261,22 @@ ShellExpandArguments (ProcessLaunchInfo &launch_info); static Error - RunShellCommand (const char *command, // Shouldn't be NULL - const char *working_dir, // Pass NULL to use the current working directory - int *status_ptr, // Pass NULL if you don't want the process exit status - int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit - std::string *command_output, // Pass NULL if you don't want the command output - uint32_t timeout_sec, - bool run_in_default_shell = true); + RunShellCommand(const char *command, // Shouldn't be NULL + const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory + int *status_ptr, // Pass NULL if you don't want the process exit status + int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit + std::string *command_output, // Pass NULL if you don't want the command output + uint32_t timeout_sec, + bool run_in_default_shell = true); static Error - RunShellCommand (const Args& args, - const char *working_dir, // Pass NULL to use the current working directory - int *status_ptr, // Pass NULL if you don't want the process exit status - int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit - std::string *command_output, // Pass NULL if you don't want the command output - uint32_t timeout_sec, - bool run_in_default_shell = true); + RunShellCommand(const Args& args, + const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory + int *status_ptr, // Pass NULL if you don't want the process exit status + int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit + std::string *command_output, // Pass NULL if you don't want the command output + uint32_t timeout_sec, + bool run_in_default_shell = true); static lldb::DataBufferSP GetAuxvData (lldb_private::Process *process); Index: include/lldb/Target/Platform.h =================================================================== --- include/lldb/Target/Platform.h +++ include/lldb/Target/Platform.h @@ -26,8 +26,9 @@ #include "lldb/Core/ConstString.h" #include "lldb/Core/PluginInterface.h" #include "lldb/Core/UserSettingsController.h" -#include "lldb/Interpreter/Options.h" +#include "lldb/Host/FileSpec.h" #include "lldb/Host/Mutex.h" +#include "lldb/Interpreter/Options.h" // TODO pull NativeDelegate class out of NativeProcessProtocol so we // can just forward ref the NativeDelegate rather than include it here. @@ -94,7 +95,7 @@ /// /// There should only be one of these for each host that LLDB runs /// upon that should be statically compiled in and registered using - /// preprocessor macros or other similar build mechanisms in a + /// preprocessor macros or other similar build mechanisms in a /// PlatformSubclass::Initialize() function. /// /// This platform will be used as the default platform when launching @@ -122,10 +123,10 @@ static lldb::PlatformSP Create (const ArchSpec &arch, ArchSpec *platform_arch_ptr, Error &error); - + static uint32_t GetNumConnectedRemotePlatforms (); - + static lldb::PlatformSP GetConnectedRemotePlatformAtIndex (uint32_t idx); @@ -161,12 +162,12 @@ // FindPlugin (Process *process, const ConstString &plugin_name); //------------------------------------------------------------------ - /// Set the target's executable based off of the existing - /// architecture information in \a target given a path to an + /// Set the target's executable based off of the existing + /// architecture information in \a target given a path to an /// executable \a exe_file. /// /// Each platform knows the architectures that it supports and can - /// select the correct architecture slice within \a exe_file by + /// select the correct architecture slice within \a exe_file by /// inspecting the architecture in \a target. If the target had an /// architecture specified, then in can try and obey that request /// and optionally fail if the architecture doesn't match up. @@ -184,7 +185,7 @@ lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr); - + //------------------------------------------------------------------ /// Find a symbol file given a symbol file module specification. /// @@ -247,20 +248,20 @@ FileSpec &resolved_platform_path); bool - GetOSVersion (uint32_t &major, - uint32_t &minor, - uint32_t &update); - + GetOSVersion(uint32_t &major, + uint32_t &minor, + uint32_t &update); + bool - SetOSVersion (uint32_t major, - uint32_t minor, - uint32_t update); + SetOSVersion(uint32_t major, + uint32_t minor, + uint32_t update); bool - GetOSBuildString (std::string &s); - + GetOSBuildString(std::string &s); + bool - GetOSKernelDescription (std::string &s); + GetOSKernelDescription(std::string &s); // Returns the name of the platform ConstString @@ -273,20 +274,20 @@ GetDescription () = 0; //------------------------------------------------------------------ - /// Report the current status for this platform. + /// Report the current status for this platform. /// /// The returned string usually involves returning the OS version /// (if available), and any SDK directory that might be being used /// for local file caching, and if connected a quick blurb about /// what this platform is connected to. - //------------------------------------------------------------------ + //------------------------------------------------------------------ virtual void GetStatus (Stream &strm); //------------------------------------------------------------------ // Subclasses must be able to fetch the current OS version // - // Remote classes must be connected for this to succeed. Local + // Remote classes must be connected for this to succeed. Local // subclasses don't need to override this function as it will just // call the HostInfo::GetOSVersion(). //------------------------------------------------------------------ @@ -302,7 +303,7 @@ s.clear(); return false; } - + virtual bool GetRemoteOSKernelDescription (std::string &s) { @@ -316,15 +317,15 @@ { return ArchSpec(); // Return an invalid architecture } - - virtual ConstString + + virtual FileSpec GetRemoteWorkingDirectory() { return m_working_dir; } - + virtual bool - SetRemoteWorkingDirectory(const ConstString &path); + SetRemoteWorkingDirectory(const FileSpec &working_dir); virtual const char * GetUserName (uint32_t uid); @@ -361,7 +362,7 @@ /// An error object. //------------------------------------------------------------------ virtual Error - GetFileWithUUID (const FileSpec &platform_file, + GetFileWithUUID (const FileSpec &platform_file, const UUID *uuid_ptr, FileSpec &local_file); @@ -407,7 +408,7 @@ /// \b true. /// /// @return - /// \b true if \a arch was filled in and is valid, \b false + /// \b true if \a arch was filled in and is valid, \b false /// otherwise. //------------------------------------------------------------------ virtual bool @@ -418,7 +419,7 @@ BreakpointSite *bp_site) = 0; //------------------------------------------------------------------ - /// Launch a new process on a platform, not necessarily for + /// Launch a new process on a platform, not necessarily for /// debugging, it could be just for running the process. //------------------------------------------------------------------ virtual Error @@ -433,7 +434,7 @@ //------------------------------------------------------------------ virtual Error ShellExpandArguments (ProcessLaunchInfo &launch_info); - + //------------------------------------------------------------------ /// Kill process on a platform. //------------------------------------------------------------------ @@ -451,15 +452,15 @@ //------------------------------------------------------------------ /// Not all platforms will support debugging a process by spawning - /// somehow halted for a debugger (specified using the - /// "eLaunchFlagDebug" launch flag) and then attaching. If your + /// somehow halted for a debugger (specified using the + /// "eLaunchFlagDebug" launch flag) and then attaching. If your /// platform doesn't support this, override this function and return /// false. //------------------------------------------------------------------ virtual bool CanDebugProcess () { - return true; + return true; } //------------------------------------------------------------------ @@ -478,10 +479,10 @@ //------------------------------------------------------------------ /// Attach to an existing process using a process ID. /// - /// Each platform subclass needs to implement this function and + /// Each platform subclass needs to implement this function and /// attempt to attach to the process with the process ID of \a pid. - /// The platform subclass should return an appropriate ProcessSP - /// subclass that is attached to the process, or an empty shared + /// The platform subclass should return an appropriate ProcessSP + /// subclass that is attached to the process, or an empty shared /// pointer with an appropriate error. /// /// @param[in] pid @@ -489,7 +490,7 @@ /// /// @return /// An appropriate ProcessSP containing a valid shared pointer - /// to the default Process subclass for the platform that is + /// to the default Process subclass for the platform that is /// attached to the process, or an empty shared pointer with an /// appropriate error fill into the \a error object. //------------------------------------------------------------------ @@ -517,10 +518,10 @@ /// LLDB_INVALID_PROCESS_ID if attaching fails. //------------------------------------------------------------------ // virtual lldb::ProcessSP -// Attach (const char *process_name, -// bool wait_for_launch, +// Attach (const char *process_name, +// bool wait_for_launch, // Error &error) = 0; - + //------------------------------------------------------------------ // The base class Platform will take care of the host platform. // Subclasses will need to fill in the remote case. @@ -531,7 +532,7 @@ virtual bool GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &proc_info); - + //------------------------------------------------------------------ // Set a breakpoint on all functions that can end up creating a thread // for this platform. This is needed when running expressions and @@ -539,7 +540,7 @@ //------------------------------------------------------------------ virtual lldb::BreakpointSP SetThreadCreationBreakpoint (Target &target); - + //------------------------------------------------------------------ // Given a target, find the local SDK directory if one exists on the // current host. @@ -567,14 +568,14 @@ { return !m_is_host; } - + virtual bool IsConnected () const { // Remote subclasses should override this function return IsHost(); } - + const ArchSpec & GetSystemArchitecture(); @@ -598,7 +599,7 @@ { return m_max_gid_name_len; } - + const ConstString & GetSDKRootDirectory () const { @@ -616,45 +617,45 @@ { return m_sdk_build; } - + void SetSDKBuild (const ConstString &sdk_build) { m_sdk_build = sdk_build; } - + // Override this to return true if your platform supports Clang modules. // You may also need to override AddClangModuleCompilationOptions to pass the right Clang flags for your platform. virtual bool SupportsModules () { return false; } - + // Appends the platform-specific options required to find the modules for the current platform. virtual void AddClangModuleCompilationOptions (Target *target, std::vector &options); - ConstString - GetWorkingDirectory (); - + FileSpec + GetWorkingDirectory(); + bool - SetWorkingDirectory (const ConstString &path); - + SetWorkingDirectory(const FileSpec &working_dir); + // There may be modules that we don't want to find by default for operations like "setting breakpoint by name". // The platform will return "true" from this call if the passed in module happens to be one of these. - + virtual bool ModuleIsExcludedForUnconstrainedSearches (Target &target, const lldb::ModuleSP &module_sp) { return false; } - + virtual Error - MakeDirectory (const char *path, uint32_t permissions); - + MakeDirectory(const FileSpec &file_spec, uint32_t permissions); + virtual Error - GetFilePermissions (const char *path, uint32_t &file_permissions); + GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions); virtual Error - SetFilePermissions (const char *path, uint32_t file_permissions); + SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions); virtual lldb::user_id_t OpenFile (const FileSpec& file_spec, @@ -664,14 +665,14 @@ { return UINT64_MAX; } - + virtual bool CloseFile (lldb::user_id_t fd, Error &error) { return false; } - + virtual lldb::user_id_t GetFileSize (const FileSpec& file_spec) { @@ -688,7 +689,7 @@ error.SetErrorStringWithFormat ("Platform::ReadFile() is not supported in the %s platform", GetName().GetCString()); return -1; } - + virtual uint64_t WriteFile (lldb::user_id_t fd, uint64_t offset, @@ -699,11 +700,11 @@ error.SetErrorStringWithFormat ("Platform::ReadFile() is not supported in the %s platform", GetName().GetCString()); return -1; } - + virtual Error GetFile (const FileSpec& source, const FileSpec& destination); - + virtual Error PutFile (const FileSpec& source, const FileSpec& destination, @@ -711,8 +712,8 @@ uint32_t gid = UINT32_MAX); virtual Error - CreateSymlink (const char *src, // The name of the link is in src - const char *dst);// The symlink points to dst + CreateSymlink(const FileSpec &src, // The name of the link is in src + const FileSpec &dst); // The symlink points to dst //---------------------------------------------------------------------- /// Install a file or directory to the remote system. @@ -743,12 +744,12 @@ virtual size_t GetEnvironment (StringList &environment); - + virtual bool GetFileExists (const lldb_private::FileSpec& file_spec); - + virtual Error - Unlink (const char *path); + Unlink(const FileSpec &file_spec); virtual uint64_t ConvertMmapFlagsToPlatform(unsigned flags); @@ -758,104 +759,104 @@ { return m_supports_rsync; } - + virtual void SetSupportsRSync(bool flag) { m_supports_rsync = flag; } - + virtual const char* GetRSyncOpts () { return m_rsync_opts.c_str(); } - + virtual void SetRSyncOpts (const char* opts) { m_rsync_opts.assign(opts); } - + virtual const char* GetRSyncPrefix () { return m_rsync_prefix.c_str(); } - + virtual void SetRSyncPrefix (const char* prefix) { m_rsync_prefix.assign(prefix); } - + virtual bool GetSupportsSSH () { return m_supports_ssh; } - + virtual void SetSupportsSSH(bool flag) { m_supports_ssh = flag; } - + virtual const char* GetSSHOpts () { return m_ssh_opts.c_str(); } - + virtual void SetSSHOpts (const char* opts) { m_ssh_opts.assign(opts); } - + virtual bool GetIgnoresRemoteHostname () { return m_ignores_remote_hostname; } - + virtual void SetIgnoresRemoteHostname(bool flag) { m_ignores_remote_hostname = flag; } - + virtual lldb_private::OptionGroupOptions * GetConnectionOptions (CommandInterpreter& interpreter) { return NULL; } - + virtual lldb_private::Error - RunShellCommand (const char *command, // Shouldn't be NULL - const char *working_dir, // Pass NULL to use the current working directory - int *status_ptr, // Pass NULL if you don't want the process exit status - int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit - std::string *command_output, // Pass NULL if you don't want the command output - uint32_t timeout_sec); // Timeout in seconds to wait for shell program to finish - + RunShellCommand(const char *command, // Shouldn't be NULL + const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory + int *status_ptr, // Pass NULL if you don't want the process exit status + int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit + std::string *command_output, // Pass NULL if you don't want the command output + uint32_t timeout_sec); // Timeout in seconds to wait for shell program to finish + virtual void SetLocalCacheDirectory (const char* local); - + virtual const char* GetLocalCacheDirectory (); - + virtual std::string GetPlatformSpecificConnectionInformation() { return ""; } - + virtual bool CalculateMD5 (const FileSpec& file_spec, uint64_t &low, uint64_t &high); - + virtual int32_t GetResumeCountForLaunchInfo (ProcessLaunchInfo &launch_info) { @@ -868,7 +869,7 @@ /// On a system using libdispatch ("Grand Central Dispatch") style /// queues, a thread may be associated with a GCD queue or not, /// and a queue may be associated with multiple threads. - /// The process/thread must provide a way to find the "dispatch_qaddr" + /// The process/thread must provide a way to find the "dispatch_qaddr" /// for each thread, and from that dispatch_qaddr this Platform method /// will locate the queue name and provide that. /// @@ -880,7 +881,7 @@ /// /// @return /// The name of the queue, if there is one. An empty string - /// means that this thread is not associated with a dispatch + /// means that this thread is not associated with a dispatch /// queue. //------------------------------------------------------------------ virtual std::string @@ -895,7 +896,7 @@ /// On a system using libdispatch ("Grand Central Dispatch") style /// queues, a thread may be associated with a GCD queue or not, /// and a queue may be associated with multiple threads. - /// The process/thread must provide a way to find the "dispatch_qaddr" + /// The process/thread must provide a way to find the "dispatch_qaddr" /// for each thread, and from that dispatch_qaddr this Platform method /// will locate the queue ID and provide that. /// @@ -924,7 +925,7 @@ /// in the process of calling the handler) and the frame above the handler /// needs to be treated by the unwinder's "frame 0" rules instead of its /// "middle of the stack frame" rules. - /// + /// /// In a user process debugging scenario, the list of trap handlers is /// typically just "_sigtramp". /// @@ -999,7 +1000,7 @@ protected: bool m_is_host; - // Set to true when we are able to actually set the OS version while + // Set to true when we are able to actually set the OS version while // being connected. For remote platforms, we might set the version ahead // of time before we actually connect and this version might change when // we actually connect to a remote platform. For the host platform this @@ -1008,7 +1009,7 @@ bool m_system_arch_set_while_connected; ConstString m_sdk_sysroot; // the root location of where the SDK files are all located ConstString m_sdk_build; - ConstString m_working_dir; // The working directory which is used when installing modules that have no install path set + FileSpec m_working_dir; // The working directory which is used when installing modules that have no install path set std::string m_remote_url; std::string m_name; uint32_t m_major_os_version; @@ -1073,7 +1074,7 @@ if (m_max_uid_name_len < name_len) m_max_uid_name_len = name_len; // Const strings lives forever in our const string pool, so we can return the const char * - return const_name.GetCString(); + return const_name.GetCString(); } void @@ -1082,7 +1083,6 @@ Mutex::Locker locker (m_mutex); m_uid_map[uid] = ConstString(); } - void ClearCachedUserNames () @@ -1090,7 +1090,7 @@ Mutex::Locker locker (m_mutex); m_uid_map.clear(); } - + const char * GetCachedGroupName (uint32_t gid) { @@ -1116,7 +1116,7 @@ if (m_max_gid_name_len < name_len) m_max_gid_name_len = name_len; // Const strings lives forever in our const string pool, so we can return the const char * - return const_name.GetCString(); + return const_name.GetCString(); } void @@ -1175,7 +1175,6 @@ DISALLOW_COPY_AND_ASSIGN (Platform); }; - class PlatformList { public: @@ -1185,11 +1184,11 @@ m_selected_platform_sp() { } - + ~PlatformList() { } - + void Append (const lldb::PlatformSP &platform_sp, bool set_selected) { @@ -1233,7 +1232,7 @@ Mutex::Locker locker (m_mutex); if (!m_selected_platform_sp && !m_platforms.empty()) m_selected_platform_sp = m_platforms.front(); - + return m_selected_platform_sp; } @@ -1266,35 +1265,35 @@ private: DISALLOW_COPY_AND_ASSIGN (PlatformList); }; - + class OptionGroupPlatformRSync : public lldb_private::OptionGroup { public: OptionGroupPlatformRSync (); - + virtual ~OptionGroupPlatformRSync (); - + virtual lldb_private::Error SetOptionValue (CommandInterpreter &interpreter, uint32_t option_idx, const char *option_value); - + void OptionParsingStarting (CommandInterpreter &interpreter); - + const lldb_private::OptionDefinition* GetDefinitions (); - + virtual uint32_t GetNumDefinitions (); - + // Options table: Required for subclasses of Options. - + static lldb_private::OptionDefinition g_option_table[]; - + // Instance variables to hold the values for command options. - + bool m_rsync; std::string m_rsync_opts; std::string m_rsync_prefix; @@ -1302,35 +1301,35 @@ private: DISALLOW_COPY_AND_ASSIGN(OptionGroupPlatformRSync); }; - + class OptionGroupPlatformSSH : public lldb_private::OptionGroup { public: OptionGroupPlatformSSH (); - + virtual ~OptionGroupPlatformSSH (); - + virtual lldb_private::Error SetOptionValue (CommandInterpreter &interpreter, uint32_t option_idx, const char *option_value); - + void OptionParsingStarting (CommandInterpreter &interpreter); - + virtual uint32_t GetNumDefinitions (); - + const lldb_private::OptionDefinition* GetDefinitions (); - + // Options table: Required for subclasses of Options. - + static lldb_private::OptionDefinition g_option_table[]; - + // Instance variables to hold the values for command options. - + bool m_ssh; std::string m_ssh_opts; @@ -1338,40 +1337,40 @@ DISALLOW_COPY_AND_ASSIGN(OptionGroupPlatformSSH); }; - + class OptionGroupPlatformCaching : public lldb_private::OptionGroup { public: OptionGroupPlatformCaching (); - + virtual ~OptionGroupPlatformCaching (); - + virtual lldb_private::Error SetOptionValue (CommandInterpreter &interpreter, uint32_t option_idx, const char *option_value); - + void OptionParsingStarting (CommandInterpreter &interpreter); - + virtual uint32_t GetNumDefinitions (); - + const lldb_private::OptionDefinition* GetDefinitions (); - + // Options table: Required for subclasses of Options. - + static lldb_private::OptionDefinition g_option_table[]; - + // Instance variables to hold the values for command options. - + std::string m_cache_dir; private: DISALLOW_COPY_AND_ASSIGN(OptionGroupPlatformCaching); }; - + } // namespace lldb_private #endif // liblldb_Platform_h_ Index: include/lldb/Target/ProcessLaunchInfo.h =================================================================== --- include/lldb/Target/ProcessLaunchInfo.h +++ include/lldb/Target/ProcessLaunchInfo.h @@ -36,11 +36,11 @@ ProcessLaunchInfo (); - ProcessLaunchInfo (const char *stdin_path, - const char *stdout_path, - const char *stderr_path, - const char *working_directory, - uint32_t launch_flags); + ProcessLaunchInfo(const FileSpec &stdin_path, + const FileSpec &stdout_path, + const FileSpec &stderr_path, + const FileSpec &working_dir, + uint32_t launch_flags); void AppendFileAction (const FileAction &info) @@ -88,17 +88,11 @@ return m_flags; } - const char * + const FileSpec & GetWorkingDirectory () const; void - SetWorkingDirectory (const char *working_dir); - - void - SwapWorkingDirectory (std::string &working_dir) - { - m_working_dir.swap (working_dir); - } + SetWorkingDirectory(const FileSpec &working_dir); const char * GetProcessPluginName () const; @@ -238,7 +232,7 @@ } protected: - std::string m_working_dir; + FileSpec m_working_dir; std::string m_plugin_name; FileSpec m_shell; Flags m_flags; // Bitwise OR of bits from lldb::LaunchFlags Index: source/API/SBLaunchInfo.cpp =================================================================== --- source/API/SBLaunchInfo.cpp +++ source/API/SBLaunchInfo.cpp @@ -175,13 +175,13 @@ const char * SBLaunchInfo::GetWorkingDirectory () const { - return m_opaque_sp->GetWorkingDirectory(); + return m_opaque_sp->GetWorkingDirectory().GetPath().c_str(); } void SBLaunchInfo::SetWorkingDirectory (const char *working_dir) { - m_opaque_sp->SetWorkingDirectory(working_dir); + m_opaque_sp->SetWorkingDirectory(FileSpec{working_dir, false}); } uint32_t Index: source/API/SBPlatform.cpp =================================================================== --- source/API/SBPlatform.cpp +++ source/API/SBPlatform.cpp @@ -318,7 +318,7 @@ { PlatformSP platform_sp(GetSP()); if (platform_sp) - return platform_sp->GetWorkingDirectory().GetCString(); + return platform_sp->GetWorkingDirectory().GetPath().c_str(); return NULL; } @@ -329,9 +329,9 @@ if (platform_sp) { if (path) - platform_sp->SetWorkingDirectory(ConstString(path)); + platform_sp->SetWorkingDirectory(FileSpec{path, false}); else - platform_sp->SetWorkingDirectory(ConstString()); + platform_sp->SetWorkingDirectory(FileSpec{}); return true; } return false; @@ -540,12 +540,12 @@ const char *working_dir = shell_command.GetWorkingDirectory(); if (working_dir == NULL) { - working_dir = platform_sp->GetWorkingDirectory().GetCString(); + working_dir = platform_sp->GetWorkingDirectory().GetPath().c_str(); if (working_dir) shell_command.SetWorkingDirectory(working_dir); } return platform_sp->RunShellCommand(command, - working_dir, + FileSpec{working_dir, false}, &shell_command.m_opaque_ptr->m_status, &shell_command.m_opaque_ptr->m_signo, &shell_command.m_opaque_ptr->m_output, @@ -598,7 +598,7 @@ PlatformSP platform_sp(GetSP()); if (platform_sp) { - sb_error.ref() = platform_sp->MakeDirectory(path, file_permissions); + sb_error.ref() = platform_sp->MakeDirectory(FileSpec{path, false}, file_permissions); } else { @@ -614,11 +614,10 @@ if (platform_sp) { uint32_t file_permissions = 0; - platform_sp->GetFilePermissions(path, file_permissions); + platform_sp->GetFilePermissions(FileSpec{path, false}, file_permissions); return file_permissions; } return 0; - } SBError @@ -628,13 +627,12 @@ PlatformSP platform_sp(GetSP()); if (platform_sp) { - sb_error.ref() = platform_sp->SetFilePermissions(path, file_permissions); + sb_error.ref() = platform_sp->SetFilePermissions(FileSpec{path, false}, file_permissions); } else { sb_error.SetErrorString("invalid platform"); } return sb_error; - } Index: source/API/SBProcess.cpp =================================================================== --- source/API/SBProcess.cpp +++ source/API/SBProcess.cpp @@ -169,11 +169,11 @@ { if (stop_at_entry) launch_flags |= eLaunchFlagStopAtEntry; - ProcessLaunchInfo launch_info (stdin_path, - stdout_path, - stderr_path, - working_directory, - launch_flags); + ProcessLaunchInfo launch_info(FileSpec{stdin_path, false}, + FileSpec{stdout_path, false}, + FileSpec{stderr_path, false}, + FileSpec{working_directory, false}, + launch_flags); Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer(); if (exe_module) launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); Index: source/API/SBTarget.cpp =================================================================== --- source/API/SBTarget.cpp +++ source/API/SBTarget.cpp @@ -345,7 +345,11 @@ if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO")) launch_flags |= eLaunchFlagDisableSTDIO; - ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags); + ProcessLaunchInfo launch_info(FileSpec{stdin_path, false}, + FileSpec{stdout_path, false}, + FileSpec{stderr_path, false}, + FileSpec{working_directory, false}, + launch_flags); Module *exe_module = target_sp->GetExecutableModulePointer(); if (exe_module) Index: source/Commands/CommandObjectPlatform.cpp =================================================================== --- source/Commands/CommandObjectPlatform.cpp +++ source/Commands/CommandObjectPlatform.cpp @@ -558,7 +558,7 @@ if (platform_sp) { if (m_option_working_dir.GetOptionValue().OptionWasSet()) - platform_sp->SetWorkingDirectory (ConstString(m_option_working_dir.GetOptionValue().GetCurrentValue().GetPath().c_str())); + platform_sp->SetWorkingDirectory(m_option_working_dir.GetOptionValue().GetCurrentValue()); } else { @@ -618,7 +618,7 @@ mode = options_permissions->m_permissions; else mode = lldb::eFilePermissionsUserRWX | lldb::eFilePermissionsGroupRWX | lldb::eFilePermissionsWorldRX; - Error error = platform_sp->MakeDirectory(cmd_line.c_str(), mode); + Error error = platform_sp->MakeDirectory(FileSpec{cmd_line.c_str(), false}, mode); if (error.Success()) { result.SetStatus (eReturnStatusSuccessFinishResult); @@ -2147,16 +2147,16 @@ if (expr == NULL) expr = raw_command_line; - + PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); Error error; if (platform_sp) { - const char *working_dir = NULL; + FileSpec working_dir{}; std::string output; int status = -1; int signo = -1; - error = (platform_sp->RunShellCommand (expr, working_dir, &status, &signo, &output, m_options.timeout)); + error = (platform_sp->RunShellCommand(expr, working_dir, &status, &signo, &output, m_options.timeout)); if (!output.empty()) result.GetOutputStream().PutCString(output.c_str()); if (status > 0) Index: source/Host/common/Host.cpp =================================================================== --- source/Host/common/Host.cpp +++ source/Host/common/Host.cpp @@ -107,7 +107,7 @@ info_ptr->callback = callback; info_ptr->callback_baton = callback_baton; info_ptr->monitor_signals = monitor_signals; - + char thread_name[256]; ::snprintf(thread_name, sizeof(thread_name), "", pid); return ThreadLauncher::LaunchThread(thread_name, MonitorChildProcessThreadFunction, info_ptr, NULL); @@ -198,7 +198,7 @@ memset(&sigUsr1Action, 0, sizeof(sigUsr1Action)); sigUsr1Action.sa_handler = SigUsr1Handler; ::sigaction(SIGUSR1, &sigUsr1Action, nullptr); -#endif // __linux__ +#endif // __linux__ while (1) { @@ -280,7 +280,7 @@ bool callback_return = false; if (callback) callback_return = callback (callback_baton, wait_pid, exited, signal, exit_status); - + // If our process exited, then this thread should exit if (exited && wait_pid == abs(pid)) { @@ -544,25 +544,25 @@ } Error -Host::RunShellCommand (const char *command, - const char *working_dir, - int *status_ptr, - int *signo_ptr, - std::string *command_output_ptr, - uint32_t timeout_sec, - bool run_in_default_shell) +Host::RunShellCommand(const char *command, + const FileSpec &working_dir, + int *status_ptr, + int *signo_ptr, + std::string *command_output_ptr, + uint32_t timeout_sec, + bool run_in_default_shell) { return RunShellCommand(Args(command), working_dir, status_ptr, signo_ptr, command_output_ptr, timeout_sec, run_in_default_shell); } Error -Host::RunShellCommand (const Args &args, - const char *working_dir, - int *status_ptr, - int *signo_ptr, - std::string *command_output_ptr, - uint32_t timeout_sec, - bool run_in_default_shell) +Host::RunShellCommand(const Args &args, + const FileSpec &working_dir, + int *status_ptr, + int *signo_ptr, + std::string *command_output_ptr, + uint32_t timeout_sec, + bool run_in_default_shell) { Error error; ProcessLaunchInfo launch_info; @@ -587,11 +587,11 @@ const bool first_arg_is_executable = true; launch_info.SetArguments(args, first_arg_is_executable); } - + if (working_dir) launch_info.SetWorkingDirectory(working_dir); llvm::SmallString output_file_path; - + if (command_output_ptr) { // Create a temporary file to get the stdout/stderr and redirect the @@ -608,7 +608,7 @@ llvm::sys::fs::createTemporaryFile("lldb-shell-output.%%%%%%", "", output_file_path); } } - + launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false); if (!output_file_path.empty()) { @@ -620,19 +620,19 @@ launch_info.AppendSuppressFileAction (STDOUT_FILENO, false, true); launch_info.AppendSuppressFileAction (STDERR_FILENO, false, true); } - + // The process monitor callback will delete the 'shell_info_ptr' below... std::unique_ptr shell_info_ap (new ShellInfo()); - + const bool monitor_signals = false; launch_info.SetMonitorProcessCallback(MonitorShellCommand, shell_info_ap.get(), monitor_signals); - + error = LaunchProcess (launch_info); const lldb::pid_t pid = launch_info.GetProcessID(); - + if (error.Success() && pid == LLDB_INVALID_PROCESS_ID) error.SetErrorString("failed to get process ID"); - + if (error.Success()) { // The process successfully launched, so we can defer ownership of @@ -651,7 +651,7 @@ if (timed_out) { error.SetErrorString("timed out waiting for shell command to complete"); - + // Kill the process since it didn't complete within the timeout specified Kill (pid, SIGKILL); // Wait for the monitor callback to get the message @@ -664,10 +664,10 @@ { if (status_ptr) *status_ptr = shell_info->status; - + if (signo_ptr) *signo_ptr = shell_info->signo; - + if (command_output_ptr) { command_output_ptr->clear(); @@ -689,7 +689,7 @@ } shell_info->can_delete.SetValue(true, eBroadcastAlways); } - + FileSpec output_file_spec(output_file_path.c_str(), false); if (FileSystem::GetFileExists(output_file_spec)) FileSystem::Unlink(output_file_path.c_str()); @@ -715,23 +715,23 @@ #if defined (__APPLE__) if (launch_info.GetFlags().Test (eLaunchFlagExec)) flags |= POSIX_SPAWN_SETEXEC; // Darwin specific posix_spawn flag - + if (launch_info.GetFlags().Test (eLaunchFlagDebug)) flags |= POSIX_SPAWN_START_SUSPENDED; // Darwin specific posix_spawn flag - + if (launch_info.GetFlags().Test (eLaunchFlagDisableASLR)) flags |= _POSIX_SPAWN_DISABLE_ASLR; // Darwin specific posix_spawn flag - + if (launch_info.GetLaunchInSeparateProcessGroup()) flags |= POSIX_SPAWN_SETPGROUP; - + #ifdef POSIX_SPAWN_CLOEXEC_DEFAULT #if defined (__APPLE__) && (defined (__x86_64__) || defined (__i386__)) static LazyBool g_use_close_on_exec_flag = eLazyBoolCalculate; if (g_use_close_on_exec_flag == eLazyBoolCalculate) { g_use_close_on_exec_flag = eLazyBoolNo; - + uint32_t major, minor, update; if (HostInfo::GetOSVersion(major, minor, update)) { @@ -794,11 +794,11 @@ // posix_spawnattr_setbinpref_np appears to be an Apple extension per: // http://www.unix.com/man-page/OSX/3/posix_spawnattr_setbinpref_np/ #if defined (__APPLE__) && !defined (__arm__) - + // Don't set the binpref if a shell was provided. After all, that's only going to affect what version of the shell // is launched, not what fork of the binary is launched. We insert "arch --arch as part of the shell invocation // to do that job on OSX. - + if (launch_info.GetShell() == nullptr) { // We don't need to do this for ARM, and we really shouldn't now that we @@ -810,7 +810,7 @@ if (cpu != 0 && cpu != static_cast(UINT32_MAX) && cpu != static_cast(LLDB_INVALID_CPUTYPE) && - !(cpu == 0x01000007 && sub == 8)) // If haswell is specified, don't try to set the CPU type or we will fail + !(cpu == 0x01000007 && sub == 8)) // If haswell is specified, don't try to set the CPU type or we will fail { size_t ocount = 0; error.SetError( ::posix_spawnattr_setbinpref_np (&attr, 1, &cpu, &ocount), eErrorTypePOSIX); @@ -843,7 +843,7 @@ current_dir[0] = '\0'; #endif - const char *working_dir = launch_info.GetWorkingDirectory(); + const char *working_dir = launch_info.GetWorkingDirectory().GetPath().c_str(); if (working_dir) { #if defined (__APPLE__) Index: source/Host/macosx/Host.mm =================================================================== --- source/Host/macosx/Host.mm +++ source/Host/macosx/Host.mm @@ -411,9 +411,9 @@ if (arch_spec.IsValid()) command.Printf(" --arch=%s", arch_spec.GetArchitectureName()); - const char *working_dir = launch_info.GetWorkingDirectory(); + FileSpec working_dir{launch_info.GetWorkingDirectory()}; if (working_dir) - command.Printf(" --working-dir '%s'", working_dir); + command.Printf(" --working-dir '%s'", working_dir.GetPath().c_str()); else { char cwd[PATH_MAX]; Index: source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h =================================================================== --- source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h +++ source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h @@ -77,12 +77,12 @@ lldb_private::ModuleSpec &module_spec) override; lldb_private::Error - RunShellCommand (const char *command, - const char *working_dir, - int *status_ptr, - int *signo_ptr, - std::string *command_output, - uint32_t timeout_sec) override; + RunShellCommand(const char *command, + const lldb_private::FileSpec &working_dir, + int *status_ptr, + int *signo_ptr, + std::string *command_output, + uint32_t timeout_sec) override; lldb_private::Error ResolveExecutable (const lldb_private::ModuleSpec &module_spec, Index: source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp =================================================================== --- source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp +++ source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp @@ -156,12 +156,12 @@ } lldb_private::Error -PlatformFreeBSD::RunShellCommand (const char *command, - const char *working_dir, - int *status_ptr, - int *signo_ptr, - std::string *command_output, - uint32_t timeout_sec) +PlatformFreeBSD::RunShellCommand(const char *command, + const FileSpec &working_dir, + int *status_ptr, + int *signo_ptr, + std::string *command_output, + uint32_t timeout_sec) { if (IsHost()) return Host::RunShellCommand(command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec); Index: source/Plugins/Platform/POSIX/PlatformPOSIX.h =================================================================== --- source/Plugins/Platform/POSIX/PlatformPOSIX.h +++ source/Plugins/Platform/POSIX/PlatformPOSIX.h @@ -24,10 +24,10 @@ { public: PlatformPOSIX (bool is_host); - + virtual ~PlatformPOSIX(); - + //------------------------------------------------------------ // lldb_private::Platform functions //------------------------------------------------------------ @@ -55,46 +55,47 @@ const lldb_private::FileSpec& destination, uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX) override; - + lldb::user_id_t OpenFile (const lldb_private::FileSpec& file_spec, uint32_t flags, uint32_t mode, lldb_private::Error &error) override; - + bool CloseFile (lldb::user_id_t fd, lldb_private::Error &error) override; - + uint64_t ReadFile (lldb::user_id_t fd, uint64_t offset, void *dst, uint64_t dst_len, lldb_private::Error &error) override; - + uint64_t WriteFile (lldb::user_id_t fd, uint64_t offset, const void* src, uint64_t src_len, lldb_private::Error &error) override; - + lldb::user_id_t - GetFileSize (const lldb_private::FileSpec& file_spec) override; + GetFileSize(const lldb_private::FileSpec& file_spec) override; lldb_private::Error - CreateSymlink(const char *src, const char *dst) override; + CreateSymlink(const lldb_private::FileSpec &src, + const lldb_private::FileSpec &dst) override; lldb_private::Error - GetFile (const lldb_private::FileSpec& source, - const lldb_private::FileSpec& destination) override; - - lldb_private::ConstString + GetFile(const lldb_private::FileSpec &source, + const lldb_private::FileSpec &destination) override; + + lldb_private::FileSpec GetRemoteWorkingDirectory() override; - + bool - SetRemoteWorkingDirectory(const lldb_private::ConstString &path) override; + SetRemoteWorkingDirectory(const lldb_private::FileSpec &working_dir) override; bool GetRemoteOSVersion () override; @@ -115,27 +116,27 @@ IsConnected () const override; lldb_private::Error - RunShellCommand (const char *command, // Shouldn't be NULL - const char *working_dir, // Pass NULL to use the current working directory - int *status_ptr, // Pass NULL if you don't want the process exit status - int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit - std::string *command_output, // Pass NULL if you don't want the command output - uint32_t timeout_sec) override;// Timeout in seconds to wait for shell program to finish + RunShellCommand (const char *command, // Shouldn't be NULL + const lldb_private::FileSpec &working_dir, // Pass empty FileSpec to use the current working directory + int *status_ptr, // Pass NULL if you don't want the process exit status + int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit + std::string *command_output, // Pass NULL if you don't want the command output + uint32_t timeout_sec) override; // Timeout in seconds to wait for shell program to finish lldb_private::Error - MakeDirectory (const char *path, uint32_t mode) override; - + MakeDirectory(const lldb_private::FileSpec &file_spec, uint32_t mode) override; + lldb_private::Error - GetFilePermissions (const char *path, uint32_t &file_permissions) override; + GetFilePermissions(const lldb_private::FileSpec &file_spec, uint32_t &file_permissions) override; lldb_private::Error - SetFilePermissions (const char *path, uint32_t file_permissions) override; + SetFilePermissions(const lldb_private::FileSpec &file_spec, uint32_t file_permissions) override; bool GetFileExists (const lldb_private::FileSpec& file_spec) override; - + lldb_private::Error - Unlink (const char *path) override; + Unlink(const lldb_private::FileSpec &file_spec) override; lldb_private::Error LaunchProcess (lldb_private::ProcessLaunchInfo &launch_info) override; @@ -157,7 +158,7 @@ std::string GetPlatformSpecificConnectionInformation() override; - + bool CalculateMD5 (const lldb_private::FileSpec& file_spec, uint64_t &low, @@ -174,12 +175,12 @@ protected: std::unique_ptr m_options; - + lldb::PlatformSP m_remote_platform_sp; // Allow multiple ways to connect to a remote POSIX-compliant OS - + private: DISALLOW_COPY_AND_ASSIGN (PlatformPOSIX); - + }; #endif // liblldb_PlatformPOSIX_h_ Index: source/Plugins/Platform/POSIX/PlatformPOSIX.cpp =================================================================== --- source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -85,12 +85,12 @@ } lldb_private::Error -PlatformPOSIX::RunShellCommand (const char *command, // Shouldn't be NULL - const char *working_dir, // Pass NULL to use the current working directory - int *status_ptr, // Pass NULL if you don't want the process exit status - int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit - std::string *command_output, // Pass NULL if you don't want the command output - uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish +PlatformPOSIX::RunShellCommand(const char *command, // Shouldn't be NULL + const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory + int *status_ptr, // Pass NULL if you don't want the process exit status + int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit + std::string *command_output, // Pass NULL if you don't want the command output + uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish { if (IsHost()) return Host::RunShellCommand(command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec); @@ -104,30 +104,30 @@ } Error -PlatformPOSIX::MakeDirectory (const char *path, uint32_t file_permissions) +PlatformPOSIX::MakeDirectory(const FileSpec &file_spec, uint32_t file_permissions) { if (m_remote_platform_sp) - return m_remote_platform_sp->MakeDirectory(path, file_permissions); + return m_remote_platform_sp->MakeDirectory(file_spec, file_permissions); else - return Platform::MakeDirectory(path ,file_permissions); + return Platform::MakeDirectory(file_spec ,file_permissions); } Error -PlatformPOSIX::GetFilePermissions (const char *path, uint32_t &file_permissions) +PlatformPOSIX::GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions) { if (m_remote_platform_sp) - return m_remote_platform_sp->GetFilePermissions(path, file_permissions); + return m_remote_platform_sp->GetFilePermissions(file_spec, file_permissions); else - return Platform::GetFilePermissions(path ,file_permissions); + return Platform::GetFilePermissions(file_spec ,file_permissions); } Error -PlatformPOSIX::SetFilePermissions (const char *path, uint32_t file_permissions) +PlatformPOSIX::SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions) { if (m_remote_platform_sp) - return m_remote_platform_sp->SetFilePermissions(path, file_permissions); + return m_remote_platform_sp->SetFilePermissions(file_spec, file_permissions); else - return Platform::SetFilePermissions(path ,file_permissions); + return Platform::SetFilePermissions(file_spec, file_permissions); } lldb::user_id_t @@ -305,7 +305,7 @@ } lldb::user_id_t -PlatformPOSIX::GetFileSize (const FileSpec& file_spec) +PlatformPOSIX::GetFileSize(const FileSpec &file_spec) { if (IsHost()) return FileSystem::GetFileSize(file_spec); @@ -316,10 +316,10 @@ } Error -PlatformPOSIX::CreateSymlink(const char *src, const char *dst) +PlatformPOSIX::CreateSymlink(const FileSpec &src, const FileSpec &dst) { if (IsHost()) - return FileSystem::Symlink(src, dst); + return FileSystem::Symlink(src.GetPath().c_str(), dst.GetPath().c_str()); else if (m_remote_platform_sp) return m_remote_platform_sp->CreateSymlink(src, dst); else @@ -327,7 +327,7 @@ } bool -PlatformPOSIX::GetFileExists (const FileSpec& file_spec) +PlatformPOSIX::GetFileExists(const FileSpec &file_spec) { if (IsHost()) return file_spec.Exists(); @@ -338,19 +338,19 @@ } Error -PlatformPOSIX::Unlink (const char *path) +PlatformPOSIX::Unlink(const FileSpec &file_spec) { if (IsHost()) - return FileSystem::Unlink(path); + return FileSystem::Unlink(file_spec.GetPath().c_str()); else if (m_remote_platform_sp) - return m_remote_platform_sp->Unlink(path); + return m_remote_platform_sp->Unlink(file_spec); else - return Platform::Unlink(path); + return Platform::Unlink(file_spec); } lldb_private::Error -PlatformPOSIX::GetFile (const lldb_private::FileSpec& source /* remote file path */, - const lldb_private::FileSpec& destination /* local file path */) +PlatformPOSIX::GetFile(const lldb_private::FileSpec &source /* remote file path */, + const lldb_private::FileSpec &destination /* local file path */) { Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM)); @@ -433,8 +433,8 @@ return Error("unable to open source file"); uint32_t permissions = 0; - error = GetFilePermissions(source.GetPath().c_str(), permissions); - + error = GetFilePermissions(source, permissions); + if (permissions == 0) permissions = lldb::eFilePermissionsFileDefault; @@ -535,7 +535,7 @@ return false; } -lldb_private::ConstString +FileSpec PlatformPOSIX::GetRemoteWorkingDirectory() { if (IsRemote() && m_remote_platform_sp) @@ -545,12 +545,12 @@ } bool -PlatformPOSIX::SetRemoteWorkingDirectory(const lldb_private::ConstString &path) +PlatformPOSIX::SetRemoteWorkingDirectory(const FileSpec &working_dir) { if (IsRemote() && m_remote_platform_sp) - return m_remote_platform_sp->SetRemoteWorkingDirectory(path); + return m_remote_platform_sp->SetRemoteWorkingDirectory(working_dir); else - return Platform::SetRemoteWorkingDirectory(path); + return Platform::SetRemoteWorkingDirectory(working_dir); } bool Index: source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h =================================================================== --- source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h +++ source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h @@ -31,7 +31,7 @@ static void Terminate (); - + static lldb::PlatformSP CreateInstance (bool force, const ArchSpec *arch); @@ -55,13 +55,13 @@ { return GetPluginNameStatic(); } - + uint32_t GetPluginVersion() override { return 1; } - + //------------------------------------------------------------ // lldb_private::Platform functions @@ -80,13 +80,13 @@ GetDescription () override; Error - GetFileWithUUID (const FileSpec &platform_file, + GetFileWithUUID (const FileSpec &platform_file, const UUID *uuid_ptr, FileSpec &local_file) override; bool GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &proc_info) override; - + uint32_t FindProcesses (const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos) override; @@ -120,7 +120,7 @@ bool GetRemoteOSBuildString (std::string &s) override; - + bool GetRemoteOSKernelDescription (std::string &s) override; @@ -128,11 +128,11 @@ ArchSpec GetRemoteSystemArchitecture () override; - ConstString + FileSpec GetRemoteWorkingDirectory() override; - + bool - SetRemoteWorkingDirectory(const ConstString &path) override; + SetRemoteWorkingDirectory(const FileSpec &working_dir) override; // Remote subclasses should override this and return a valid instance // name if connected. @@ -141,7 +141,7 @@ const char * GetUserName (uint32_t uid) override; - + const char * GetGroupName (uint32_t gid) override; @@ -153,30 +153,30 @@ Error DisconnectRemote () override; - + Error - MakeDirectory (const char *path, uint32_t file_permissions) override; - + MakeDirectory(const FileSpec &file_spec, uint32_t file_permissions) override; + Error - GetFilePermissions (const char *path, uint32_t &file_permissions) override; - + GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions) override; + Error - SetFilePermissions (const char *path, uint32_t file_permissions) override; - + SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions) override; + lldb::user_id_t OpenFile (const FileSpec& file_spec, uint32_t flags, uint32_t mode, Error &error) override; - + bool CloseFile (lldb::user_id_t fd, Error &error) override; - + uint64_t ReadFile (lldb::user_id_t fd, uint64_t offset, void *data_ptr, uint64_t len, Error &error) override; - + uint64_t WriteFile (lldb::user_id_t fd, uint64_t offset, @@ -192,23 +192,23 @@ const FileSpec& destination, uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX) override; - + Error - CreateSymlink (const char *src, const char *dst) override; + CreateSymlink(const FileSpec &src, const FileSpec &dst) override; bool GetFileExists (const FileSpec& file_spec) override; Error - Unlink (const char *path) override; + Unlink (const FileSpec &path) override; Error - RunShellCommand (const char *command, // Shouldn't be NULL - const char *working_dir, // Pass NULL to use the current working directory - int *status_ptr, // Pass NULL if you don't want the process exit status - int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit - std::string *command_output, // Pass NULL if you don't want the command output - uint32_t timeout_sec) override; // Timeout in seconds to wait for shell program to finish + RunShellCommand(const char *command, // Shouldn't be NULL + const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory + int *status_ptr, // Pass NULL if you don't want the process exit status + int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit + std::string *command_output, // Pass NULL if you don't want the command output + uint32_t timeout_sec) override; // Timeout in seconds to wait for shell program to finish void CalculateTrapHandlerSymbolNames () override; Index: source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp =================================================================== --- source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp +++ source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp @@ -120,7 +120,7 @@ // Send the get description packet } } - + if (!m_platform_description.empty()) return m_platform_description.c_str(); return GetDescriptionStatic(); @@ -233,9 +233,9 @@ } Error -PlatformRemoteGDBServer::GetFileWithUUID (const FileSpec &platform_file, - const UUID *uuid_ptr, - FileSpec &local_file) +PlatformRemoteGDBServer::GetFileWithUUID(const FileSpec &platform_file, + const UUID *uuid_ptr, + FileSpec &local_file) { // Default to the local case local_file = platform_file; @@ -320,24 +320,20 @@ return m_gdb_client.GetSystemArchitecture(); } -ConstString +FileSpec PlatformRemoteGDBServer::GetRemoteWorkingDirectory() { if (IsConnected()) { Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); - std::string cwd; - if (m_gdb_client.GetWorkingDir(cwd)) + FileSpec working_dir; + if (m_gdb_client.GetWorkingDir(working_dir)) { - ConstString working_dir(cwd.c_str()); if (log) - log->Printf("PlatformRemoteGDBServer::GetRemoteWorkingDirectory() -> '%s'", working_dir.GetCString()); - return working_dir; - } - else - { - return ConstString(); + log->Printf("PlatformRemoteGDBServer::GetRemoteWorkingDirectory() -> '%s'", + working_dir.GetPath().c_str()); } + return working_dir; } else { @@ -346,7 +342,7 @@ } bool -PlatformRemoteGDBServer::SetRemoteWorkingDirectory(const ConstString &path) +PlatformRemoteGDBServer::SetRemoteWorkingDirectory(const FileSpec &working_dir) { if (IsConnected()) { @@ -354,18 +350,19 @@ // for use to re-read it Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); if (log) - log->Printf("PlatformRemoteGDBServer::SetRemoteWorkingDirectory('%s')", path.GetCString()); - return m_gdb_client.SetWorkingDir(path.GetCString()) == 0; + log->Printf("PlatformRemoteGDBServer::SetRemoteWorkingDirectory('%s')", + working_dir.GetPath().c_str()); + return m_gdb_client.SetWorkingDir(working_dir) == 0; } else - return Platform::SetRemoteWorkingDirectory(path); + return Platform::SetRemoteWorkingDirectory(working_dir); } bool PlatformRemoteGDBServer::IsConnected () const { return m_gdb_client.IsConnected(); -} +} Error PlatformRemoteGDBServer::ConnectRemote (Args& args) @@ -373,8 +370,8 @@ Error error; if (IsConnected()) { - error.SetErrorStringWithFormat ("the platform is already connected to '%s', execute 'platform disconnect' to close the current connection", - GetHostname()); + error.SetErrorStringWithFormat("the platform is already connected to '%s', execute 'platform disconnect' to close the current connection", + GetHostname()); } else { @@ -398,7 +395,7 @@ m_gdb_client.GetHostInfo(); // If a working directory was set prior to connecting, send it down now if (m_working_dir) - m_gdb_client.SetWorkingDir(m_working_dir.GetCString()); + m_gdb_client.SetWorkingDir(m_working_dir); } else { @@ -507,13 +504,13 @@ m_gdb_client.SetDisableASLR (launch_info.GetFlags().Test (eLaunchFlagDisableASLR)); m_gdb_client.SetDetachOnError (launch_info.GetFlags().Test (eLaunchFlagDetachOnError)); - - const char *working_dir = launch_info.GetWorkingDirectory(); - if (working_dir && working_dir[0]) + + FileSpec working_dir = launch_info.GetWorkingDirectory(); + if (working_dir) { - m_gdb_client.SetWorkingDir (working_dir); + m_gdb_client.SetWorkingDir(working_dir); } - + // Send the environment and the program + arguments after we connect const char **envp = launch_info.GetEnvironmentEntries().GetConstArgumentVector(); @@ -526,10 +523,10 @@ break; } } - + ArchSpec arch_spec = launch_info.GetArchitecture(); const char *arch_triple = arch_spec.GetTriple().str().c_str(); - + m_gdb_client.SendLaunchArchPacket(arch_triple); if (log) log->Printf ("PlatformRemoteGDBServer::%s() set launch architecture triple to '%s'", __FUNCTION__, arch_triple ? arch_triple : ""); @@ -605,7 +602,7 @@ if (target == NULL) { TargetSP new_target_sp; - + error = debugger.GetTargetList().CreateTarget (debugger, NULL, NULL, @@ -616,15 +613,15 @@ } else error.Clear(); - + if (target && error.Success()) { debugger.GetTargetList().SetSelectedTarget(target); - + // The darwin always currently uses the GDB remote debugger plug-in // so even when debugging locally we are debugging remotely! process_sp = target->CreateProcess (launch_info.GetListenerForProcess(debugger), "gdb-remote", NULL); - + if (process_sp) { std::string connect_url = @@ -701,26 +698,26 @@ if (target == NULL) { TargetSP new_target_sp; - - error = debugger.GetTargetList().CreateTarget (debugger, - NULL, - NULL, - false, - NULL, - new_target_sp); + + error = debugger.GetTargetList().CreateTarget(debugger, + NULL, + NULL, + false, + NULL, + new_target_sp); target = new_target_sp.get(); } else error.Clear(); - + if (target && error.Success()) { debugger.GetTargetList().SetSelectedTarget(target); - + // The darwin always currently uses the GDB remote debugger plug-in // so even when debugging locally we are debugging remotely! process_sp = target->CreateProcess (attach_info.GetListenerForProcess(debugger), "gdb-remote", NULL); - + if (process_sp) { std::string connect_url = @@ -751,33 +748,36 @@ } Error -PlatformRemoteGDBServer::MakeDirectory (const char *path, uint32_t mode) +PlatformRemoteGDBServer::MakeDirectory(const FileSpec &file_spec, uint32_t mode) { - Error error = m_gdb_client.MakeDirectory(path,mode); + Error error = m_gdb_client.MakeDirectory(file_spec, mode); Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); if (log) - log->Printf ("PlatformRemoteGDBServer::MakeDirectory(path='%s', mode=%o) error = %u (%s)", path, mode, error.GetError(), error.AsCString()); + log->Printf ("PlatformRemoteGDBServer::MakeDirectory(path='%s', mode=%o) error = %u (%s)", + file_spec.GetPath().c_str(), mode, error.GetError(), error.AsCString()); return error; } Error -PlatformRemoteGDBServer::GetFilePermissions (const char *path, uint32_t &file_permissions) +PlatformRemoteGDBServer::GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions) { - Error error = m_gdb_client.GetFilePermissions(path, file_permissions); + Error error = m_gdb_client.GetFilePermissions(file_spec, file_permissions); Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); if (log) - log->Printf ("PlatformRemoteGDBServer::GetFilePermissions(path='%s', file_permissions=%o) error = %u (%s)", path, file_permissions, error.GetError(), error.AsCString()); + log->Printf ("PlatformRemoteGDBServer::GetFilePermissions(path='%s', file_permissions=%o) error = %u (%s)", + file_spec.GetPath().c_str(), file_permissions, error.GetError(), error.AsCString()); return error; } Error -PlatformRemoteGDBServer::SetFilePermissions (const char *path, uint32_t file_permissions) +PlatformRemoteGDBServer::SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions) { - Error error = m_gdb_client.SetFilePermissions(path, file_permissions); + Error error = m_gdb_client.SetFilePermissions(file_spec, file_permissions); Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); if (log) - log->Printf ("PlatformRemoteGDBServer::SetFilePermissions(path='%s', file_permissions=%o) error = %u (%s)", path, file_permissions, error.GetError(), error.AsCString()); + log->Printf ("PlatformRemoteGDBServer::SetFilePermissions(path='%s', file_permissions=%o) error = %u (%s)", + file_spec.GetPath().c_str(), file_permissions, error.GetError(), error.AsCString()); return error; } @@ -824,54 +824,56 @@ } Error -PlatformRemoteGDBServer::PutFile (const FileSpec& source, - const FileSpec& destination, - uint32_t uid, - uint32_t gid) +PlatformRemoteGDBServer::PutFile(const FileSpec &source, + const FileSpec &destination, + uint32_t uid, + uint32_t gid) { - return Platform::PutFile(source,destination,uid,gid); + return Platform::PutFile(source, destination, uid, gid); } Error -PlatformRemoteGDBServer::CreateSymlink (const char *src, // The name of the link is in src - const char *dst) // The symlink points to dst +PlatformRemoteGDBServer::CreateSymlink(const FileSpec &src, // The name of the link is in src + const FileSpec &dst) // The symlink points to dst { - Error error = m_gdb_client.CreateSymlink (src, dst); + Error error = m_gdb_client.CreateSymlink(src, dst); Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); if (log) - log->Printf ("PlatformRemoteGDBServer::CreateSymlink(src='%s', dst='%s') error = %u (%s)", src, dst, error.GetError(), error.AsCString()); + log->Printf ("PlatformRemoteGDBServer::CreateSymlink(src='%s', dst='%s') error = %u (%s)", + src.GetPath().c_str(), dst.GetPath().c_str(), error.GetError(), error.AsCString()); return error; } Error -PlatformRemoteGDBServer::Unlink (const char *path) +PlatformRemoteGDBServer::Unlink(const FileSpec &file_spec) { - Error error = m_gdb_client.Unlink (path); + Error error = m_gdb_client.Unlink(file_spec); Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); if (log) - log->Printf ("PlatformRemoteGDBServer::Unlink(path='%s') error = %u (%s)", path, error.GetError(), error.AsCString()); + log->Printf ("PlatformRemoteGDBServer::Unlink(path='%s') error = %u (%s)", + file_spec.GetPath().c_str(), error.GetError(), error.AsCString()); return error; } bool -PlatformRemoteGDBServer::GetFileExists (const FileSpec& file_spec) +PlatformRemoteGDBServer::GetFileExists(const FileSpec& file_spec) { - return m_gdb_client.GetFileExists (file_spec); + return m_gdb_client.GetFileExists(file_spec); } Error -PlatformRemoteGDBServer::RunShellCommand (const char *command, // Shouldn't be NULL - const char *working_dir, // Pass NULL to use the current working directory - int *status_ptr, // Pass NULL if you don't want the process exit status - int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit - std::string *command_output, // Pass NULL if you don't want the command output - uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish +PlatformRemoteGDBServer::RunShellCommand(const char *command, // Shouldn't be NULL + const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory + int *status_ptr, // Pass NULL if you don't want the process exit status + int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit + std::string *command_output, // Pass NULL if you don't want the command output + uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish { - return m_gdb_client.RunShellCommand (command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec); + return m_gdb_client.RunShellCommand(command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec); } void PlatformRemoteGDBServer::CalculateTrapHandlerSymbolNames () -{ +{ m_trap_handlers.push_back (ConstString ("_sigtramp")); } Index: source/Plugins/Process/Linux/NativeProcessLinux.cpp =================================================================== --- source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -1463,13 +1463,13 @@ Error error; // Verify the working directory is valid if one was specified. - const char* working_dir = launch_info.GetWorkingDirectory (); + FileSpec working_dir{launch_info.GetWorkingDirectory()}; if (working_dir) { - FileSpec working_dir_fs (working_dir, true); - if (!working_dir_fs || working_dir_fs.GetFileType () != FileSpec::eFileTypeDirectory) + if (!working_dir || working_dir.GetFileType () != FileSpec::eFileTypeDirectory) { - error.SetErrorStringWithFormat ("No such file or directory: %s", working_dir); + error.SetErrorStringWithFormat ("No such file or directory: %s", + working_dir.GetPath().c_str()); return error; } } @@ -1538,7 +1538,7 @@ stdin_path, stdout_path, stderr_path, - working_dir, + working_dir.GetPath().c_str(), launch_info, error); Index: source/Plugins/Process/POSIX/ProcessPOSIX.cpp =================================================================== --- source/Plugins/Process/POSIX/ProcessPOSIX.cpp +++ source/Plugins/Process/POSIX/ProcessPOSIX.cpp @@ -52,9 +52,9 @@ { // FIXME: Putting this code in the ctor and saving the byte order in a // member variable is a hack to avoid const qual issues in GetByteOrder. - lldb::ModuleSP module = GetTarget().GetExecutableModule(); - if (module && module->GetObjectFile()) - m_byte_order = module->GetObjectFile()->GetByteOrder(); + lldb::ModuleSP module = GetTarget().GetExecutableModule(); + if (module && module->GetObjectFile()) + m_byte_order = module->GetObjectFile()->GetByteOrder(); } ProcessPOSIX::~ProcessPOSIX() @@ -176,12 +176,12 @@ Error error; assert(m_monitor == NULL); - const char* working_dir = launch_info.GetWorkingDirectory(); + FileSpec working_dir = launch_info.GetWorkingDirectory(); if (working_dir) { - FileSpec WorkingDir(working_dir, true); - if (!WorkingDir || WorkingDir.GetFileType() != FileSpec::eFileTypeDirectory) + if (!working_dir || working_dir.GetFileType() != FileSpec::eFileTypeDirectory) { - error.SetErrorStringWithFormat("No such file or directory: %s", working_dir); + error.SetErrorStringWithFormat("No such file or directory: %s", + working_dir.GetPath().c_str()); return error; } } @@ -206,16 +206,16 @@ file_action = launch_info.GetFileActionForFD (STDERR_FILENO); stderr_path = GetFilePath(file_action, stderr_path, dbg_pts_path); - m_monitor = new ProcessMonitor (this, - module, - launch_info.GetArguments().GetConstArgumentVector(), - launch_info.GetEnvironmentEntries().GetConstArgumentVector(), - stdin_path, - stdout_path, - stderr_path, - working_dir, - launch_info, - error); + m_monitor = new ProcessMonitor(this, + module, + launch_info.GetArguments().GetConstArgumentVector(), + launch_info.GetEnvironmentEntries().GetConstArgumentVector(), + stdin_path, + stdout_path, + stderr_path, + working_dir.GetPath().c_str(), + launch_info, + error); m_module = module; Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h =================================================================== --- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -98,9 +98,9 @@ SendAsyncSignal (int signo); bool - SendInterrupt (Mutex::Locker &locker, - uint32_t seconds_to_wait_for_stop, - bool &timed_out); + SendInterrupt(Mutex::Locker &locker, + uint32_t seconds_to_wait_for_stop, + bool &timed_out); lldb::pid_t GetCurrentProcessID (bool allow_lazy = true); @@ -110,7 +110,7 @@ uint16_t LaunchGDBserverAndGetPort (lldb::pid_t &pid, const char *remote_accept_hostname); - + bool KillSpawnedProcess (lldb::pid_t pid); @@ -153,19 +153,19 @@ int SendLaunchArchPacket (const char *arch); - + int SendLaunchEventDataPacket (const char *data, bool *was_supported = NULL); - + //------------------------------------------------------------------ - /// Sends a "vAttach:PID" where PID is in hex. + /// Sends a "vAttach:PID" where PID is in hex. /// /// @param[in] pid /// A process ID for the remote gdb server to attach to. /// /// @param[out] response /// The response received from the gdb server. If the return - /// value is zero, \a response will contain a stop reply + /// value is zero, \a response will contain a stop reply /// packet. /// /// @return @@ -173,8 +173,8 @@ /// an error code. //------------------------------------------------------------------ int - SendAttach (lldb::pid_t pid, - StringExtractorGDBRemote& response); + SendAttach(lldb::pid_t pid, + StringExtractorGDBRemote& response); //------------------------------------------------------------------ @@ -212,7 +212,7 @@ SetSTDERR (char const *path); //------------------------------------------------------------------ - /// Sets the disable ASLR flag to \a enable for a process that will + /// Sets the disable ASLR flag to \a enable for a process that will /// be launched with the 'A' packet. /// /// @param[in] enable @@ -223,7 +223,7 @@ //------------------------------------------------------------------ int SetDisableASLR (bool enable); - + //------------------------------------------------------------------ /// Sets the DetachOnError flag to \a enable for the process controlled by the stub. /// @@ -237,33 +237,33 @@ SetDetachOnError (bool enable); //------------------------------------------------------------------ - /// Sets the working directory to \a path for a process that will + /// Sets the working directory to \a path for a process that will /// be launched with the 'A' packet for non platform based /// connections. If this packet is sent to a GDB server that /// implements the platform, it will change the current working /// directory for the platform process. /// - /// @param[in] path + /// @param[in] working_dir /// The path to a directory to use when launching our process /// /// @return /// Zero if the for success, or an error code for failure. //------------------------------------------------------------------ int - SetWorkingDir (char const *path); + SetWorkingDir(const FileSpec &working_dir); //------------------------------------------------------------------ /// Gets the current working directory of a remote platform GDB /// server. /// - /// @param[out] cwd + /// @param[out] working_dir /// The current working directory on the remote platform. /// /// @return /// Boolean for success //------------------------------------------------------------------ bool - GetWorkingDir (std::string &cwd); + GetWorkingDir(FileSpec &working_dir); lldb::addr_t AllocateMemory (size_t size, uint32_t permissions); @@ -275,20 +275,20 @@ Detach (bool keep_stopped); Error - GetMemoryRegionInfo (lldb::addr_t addr, MemoryRegionInfo &range_info); + GetMemoryRegionInfo(lldb::addr_t addr, MemoryRegionInfo &range_info); Error - GetWatchpointSupportInfo (uint32_t &num); + GetWatchpointSupportInfo(uint32_t &num); Error GetWatchpointSupportInfo (uint32_t &num, bool& after); - + Error GetWatchpointsTriggerAfterInstruction (bool &after); const ArchSpec & GetHostArchitecture (); - + uint32_t GetHostDefaultPacketTimeout(); @@ -309,24 +309,24 @@ bool GetVAttachOrWaitSupported (); - + bool GetSyncThreadStateSupported(); - + void ResetDiscoverableSettings(); bool GetHostInfo (bool force = false); - + bool - GetOSVersion (uint32_t &major, - uint32_t &minor, - uint32_t &update); + GetOSVersion(uint32_t &major, + uint32_t &minor, + uint32_t &update); bool GetOSBuildString (std::string &s); - + bool GetOSKernelDescription (std::string &s); @@ -351,7 +351,7 @@ bool GetUserName (uint32_t uid, std::string &name); - + bool GetGroupName (uint32_t gid, std::string &name); @@ -366,13 +366,13 @@ { return GetVContSupported ('a'); } - + bool GetStopReply (StringExtractorGDBRemote &response); bool - GetThreadStopInfo (lldb::tid_t tid, - StringExtractorGDBRemote &response); + GetThreadStopInfo(lldb::tid_t tid, + StringExtractorGDBRemote &response); bool SupportsGDBStoppointPacket (GDBStoppointType type) @@ -402,12 +402,12 @@ // other end and avoids any of that work affecting the packet send // and response times. bool - SendSpeedTestPacket (uint32_t send_size, - uint32_t recv_size); - + SendSpeedTestPacket(uint32_t send_size, + uint32_t recv_size); + bool SetCurrentThread (uint64_t tid); - + bool SetCurrentThreadForRun (uint64_t tid); @@ -440,27 +440,27 @@ size_t GetCurrentThreadIDs (std::vector &thread_ids, bool &sequence_mutex_unavailable); - + bool GetInterruptWasSent () const { return m_interrupt_sent; } - + lldb::user_id_t OpenFile (const FileSpec& file_spec, uint32_t flags, mode_t mode, Error &error); - + bool CloseFile (lldb::user_id_t fd, Error &error); - + lldb::user_id_t - GetFileSize (const FileSpec& file_spec); - + GetFileSize(const FileSpec &file_spec); + Error - GetFilePermissions(const char *path, uint32_t &file_permissions); + GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions); Error - SetFilePermissions(const char *path, uint32_t file_permissions); + SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions); uint64_t ReadFile (lldb::user_id_t fd, @@ -468,38 +468,37 @@ void *dst, uint64_t dst_len, Error &error); - + uint64_t WriteFile (lldb::user_id_t fd, uint64_t offset, const void* src, uint64_t src_len, Error &error); - + Error - CreateSymlink (const char *src, - const char *dst); - + CreateSymlink(const FileSpec &src, const FileSpec &dst); + Error - Unlink (const char *path); + Unlink(const FileSpec &file_spec); Error - MakeDirectory (const char *path, uint32_t mode); - + MakeDirectory(const FileSpec &file_spec, uint32_t mode); + bool - GetFileExists (const FileSpec& file_spec); - + GetFileExists (const FileSpec &file_spec); + Error - RunShellCommand (const char *command, // Shouldn't be NULL - const char *working_dir, // Pass NULL to use the current working directory - int *status_ptr, // Pass NULL if you don't want the process exit status - int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit - std::string *command_output, // Pass NULL if you don't want the command output - uint32_t timeout_sec); // Timeout in seconds to wait for shell program to finish - + RunShellCommand(const char *command, // Shouldn't be NULL + const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory + int *status_ptr, // Pass NULL if you don't want the process exit status + int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit + std::string *command_output, // Pass NULL if you don't want the command output + uint32_t timeout_sec); // Timeout in seconds to wait for shell program to finish + bool CalculateMD5 (const FileSpec& file_spec, uint64_t &high, uint64_t &low); - + std::string HarmonizeThreadIdsForProfileData (ProcessGDBRemote *process, StringExtractorGDBRemote &inputStringExtractor); @@ -515,13 +514,13 @@ bool SaveRegisterState (lldb::tid_t tid, uint32_t &save_id); - + bool RestoreRegisterState (lldb::tid_t tid, uint32_t save_id); const char * GetGDBServerProgramName(); - + uint32_t GetGDBServerProgramVersion(); @@ -602,7 +601,7 @@ m_supports_z4:1, m_supports_QEnvironment:1, m_supports_QEnvironmentHexEncoded:1; - + lldb::pid_t m_curr_pid; lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc @@ -621,7 +620,7 @@ bool m_interrupt_sent; std::string m_partial_profile_data; std::map m_thread_id_to_used_usec_map; - + ArchSpec m_host_arch; ArchSpec m_process_arch; uint32_t m_os_version_major; @@ -634,10 +633,10 @@ uint32_t m_gdb_server_version; // from reply to qGDBServerVersion, zero if qGDBServerVersion is not supported uint32_t m_default_packet_timeout; uint64_t m_max_packet_size; // as returned by qSupported - + bool - DecodeProcessInfoResponse (StringExtractorGDBRemote &response, - ProcessInstanceInfo &process_info); + DecodeProcessInfoResponse(StringExtractorGDBRemote &response, + ProcessInstanceInfo &process_info); private: //------------------------------------------------------------------ // For GDBRemoteCommunicationClient only Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp =================================================================== --- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -1312,7 +1312,7 @@ const char *arg = NULL; const Args &launch_args = launch_info.GetArguments(); if (exe_file) - exe_path = exe_file.GetPath(); + exe_path = exe_file.GetPath(false); else { arg = launch_args.GetArgumentAtIndex(0); @@ -2258,7 +2258,7 @@ } bool -GDBRemoteCommunicationClient::GetWorkingDir (std::string &cwd) +GDBRemoteCommunicationClient::GetWorkingDir(FileSpec &working_dir) { StringExtractorGDBRemote response; if (SendPacketAndWaitForResponse ("qGetWorkingDir", response, false) == PacketResult::Success) @@ -2267,23 +2267,27 @@ return false; if (response.IsErrorResponse()) return false; - response.GetHexByteString (cwd); + std::string cwd; + response.GetHexByteString(cwd); + working_dir = FileSpec{cwd.c_str(), false}; return !cwd.empty(); } return false; } int -GDBRemoteCommunicationClient::SetWorkingDir (char const *path) +GDBRemoteCommunicationClient::SetWorkingDir(const FileSpec &working_dir) { - if (path && path[0]) + if (working_dir) { + std::string path{working_dir.GetPath(false)}; + StreamString packet; packet.PutCString("QSetWorkingDir:"); - packet.PutBytesAsRawHex8(path, strlen(path)); - + packet.PutCStringAsRawHex8(path.c_str()); + StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) + if (SendPacketAndWaitForResponse(packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) { if (response.IsOKResponse()) return 0; @@ -3133,22 +3137,23 @@ } lldb_private::Error -GDBRemoteCommunicationClient::RunShellCommand (const char *command, // Shouldn't be NULL - const char *working_dir, // Pass NULL to use the current working directory - int *status_ptr, // Pass NULL if you don't want the process exit status - int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit - std::string *command_output, // Pass NULL if you don't want the command output - uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish +GDBRemoteCommunicationClient::RunShellCommand(const char *command, // Shouldn't be NULL + const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory + int *status_ptr, // Pass NULL if you don't want the process exit status + int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit + std::string *command_output, // Pass NULL if you don't want the command output + uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish { lldb_private::StreamString stream; stream.PutCString("qPlatform_shell:"); stream.PutBytesAsRawHex8(command, strlen(command)); stream.PutChar(','); stream.PutHex32(timeout_sec); - if (working_dir && *working_dir) + if (working_dir) { + std::string path{working_dir.GetPath(false)}; stream.PutChar(','); - stream.PutBytesAsRawHex8(working_dir, strlen(working_dir)); + stream.PutCStringAsRawHex8(path.c_str()); } const char *packet = stream.GetData(); int packet_len = stream.GetSize(); @@ -3181,14 +3186,15 @@ } Error -GDBRemoteCommunicationClient::MakeDirectory (const char *path, - uint32_t file_permissions) +GDBRemoteCommunicationClient::MakeDirectory(const FileSpec &file_spec, + uint32_t file_permissions) { + std::string path{file_spec.GetPath(false)}; lldb_private::StreamString stream; stream.PutCString("qPlatform_mkdir:"); stream.PutHex32(file_permissions); stream.PutChar(','); - stream.PutBytesAsRawHex8(path, strlen(path)); + stream.PutCStringAsRawHex8(path.c_str()); const char *packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; @@ -3203,14 +3209,15 @@ } Error -GDBRemoteCommunicationClient::SetFilePermissions (const char *path, - uint32_t file_permissions) +GDBRemoteCommunicationClient::SetFilePermissions(const FileSpec &file_spec, + uint32_t file_permissions) { + std::string path{file_spec.GetPath(false)}; lldb_private::StreamString stream; stream.PutCString("qPlatform_chmod:"); stream.PutHex32(file_permissions); stream.PutChar(','); - stream.PutBytesAsRawHex8(path, strlen(path)); + stream.PutCStringAsRawHex8(path.c_str()); const char *packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; @@ -3253,9 +3260,9 @@ mode_t mode, Error &error) { + std::string path(file_spec.GetPath(false)); lldb_private::StreamString stream; stream.PutCString("vFile:open:"); - std::string path (file_spec.GetPath(false)); if (path.empty()) return UINT64_MAX; stream.PutCStringAsRawHex8(path.c_str()); @@ -3293,9 +3300,9 @@ lldb::user_id_t GDBRemoteCommunicationClient::GetFileSize (const lldb_private::FileSpec& file_spec) { + std::string path(file_spec.GetPath(false)); lldb_private::StreamString stream; stream.PutCString("vFile:size:"); - std::string path (file_spec.GetPath()); stream.PutCStringAsRawHex8(path.c_str()); const char* packet = stream.GetData(); int packet_len = stream.GetSize(); @@ -3311,12 +3318,14 @@ } Error -GDBRemoteCommunicationClient::GetFilePermissions(const char *path, uint32_t &file_permissions) +GDBRemoteCommunicationClient::GetFilePermissions(const FileSpec &file_spec, + uint32_t &file_permissions) { + std::string path{file_spec.GetPath(false)}; Error error; lldb_private::StreamString stream; stream.PutCString("vFile:mode:"); - stream.PutCStringAsRawHex8(path); + stream.PutCStringAsRawHex8(path.c_str()); const char* packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; @@ -3435,16 +3444,18 @@ } Error -GDBRemoteCommunicationClient::CreateSymlink (const char *src, const char *dst) +GDBRemoteCommunicationClient::CreateSymlink(const FileSpec &src, const FileSpec &dst) { + std::string src_path{src.GetPath(false)}, + dst_path{dst.GetPath(false)}; Error error; lldb_private::StreamGDBRemote stream; stream.PutCString("vFile:symlink:"); // the unix symlink() command reverses its parameters where the dst if first, // so we follow suit here - stream.PutCStringAsRawHex8(dst); + stream.PutCStringAsRawHex8(dst_path.c_str()); stream.PutChar(','); - stream.PutCStringAsRawHex8(src); + stream.PutCStringAsRawHex8(src_path.c_str()); const char* packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; @@ -3478,14 +3489,15 @@ } Error -GDBRemoteCommunicationClient::Unlink (const char *path) +GDBRemoteCommunicationClient::Unlink(const FileSpec &file_spec) { + std::string path{file_spec.GetPath(false)}; Error error; lldb_private::StreamGDBRemote stream; stream.PutCString("vFile:unlink:"); // the unix symlink() command reverses its parameters where the dst if first, // so we follow suit here - stream.PutCStringAsRawHex8(path); + stream.PutCStringAsRawHex8(path.c_str()); const char* packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; @@ -3522,9 +3534,9 @@ bool GDBRemoteCommunicationClient::GetFileExists (const lldb_private::FileSpec& file_spec) { + std::string path(file_spec.GetPath(false)); lldb_private::StreamString stream; stream.PutCString("vFile:exists:"); - std::string path (file_spec.GetPath()); stream.PutCStringAsRawHex8(path.c_str()); const char* packet = stream.GetData(); int packet_len = stream.GetSize(); @@ -3546,9 +3558,9 @@ uint64_t &high, uint64_t &low) { + std::string path(file_spec.GetPath(false)); lldb_private::StreamString stream; stream.PutCString("vFile:MD5:"); - std::string path (file_spec.GetPath()); stream.PutCStringAsRawHex8(path.c_str()); const char* packet = stream.GetData(); int packet_len = stream.GetSize(); @@ -3736,7 +3748,7 @@ const lldb_private::ArchSpec& arch_spec, ModuleSpec &module_spec) { - std::string module_path = module_file_spec.GetPath (false); + std::string module_path{module_file_spec.GetPath(false)}; if (module_path.empty ()) return false; @@ -3745,7 +3757,7 @@ packet.PutCStringAsRawHex8(module_path.c_str()); packet.PutCString(";"); const auto& triple = arch_spec.GetTriple().getTriple(); - packet.PutBytesAsRawHex8(triple.c_str(), triple.size()); + packet.PutCStringAsRawHex8(triple.c_str()); StringExtractorGDBRemote response; if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) != PacketResult::Success) Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp =================================================================== --- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -808,7 +808,7 @@ int status, signo; std::string output; Error err = Host::RunShellCommand(path.c_str(), - working_dir.empty() ? NULL : working_dir.c_str(), + FileSpec{working_dir.c_str(), true}, &status, &signo, &output, timeout); StreamGDBRemote response; if (err.Fail()) @@ -874,7 +874,7 @@ std::string path; packet.GetHexByteString(path); Error error = FileSystem::MakeDirectory(path.c_str(), mode); - + StreamGDBRemote response; response.Printf("F%u", error.GetError()); Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp =================================================================== --- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -951,21 +951,21 @@ GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_QSetWorkingDir (StringExtractorGDBRemote &packet) { - packet.SetFilePos (::strlen ("QSetWorkingDir:")); + packet.SetFilePos(::strlen ("QSetWorkingDir:")); std::string path; - packet.GetHexByteString (path); - m_process_launch_info.SwapWorkingDirectory (path); - return SendOKResponse (); + packet.GetHexByteString(path); + m_process_launch_info.SetWorkingDirectory(FileSpec{path.c_str(), true}); + return SendOKResponse(); } GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_qGetWorkingDir (StringExtractorGDBRemote &packet) { - const char *working_dir = m_process_launch_info.GetWorkingDirectory(); - if (working_dir && working_dir[0]) + FileSpec working_dir{m_process_launch_info.GetWorkingDirectory()}; + if (working_dir) { StreamString response; - response.PutBytesAsRawHex8(working_dir, strlen(working_dir)); + response.PutCStringAsRawHex8(working_dir.GetPath().c_str()); return SendPacketNoLock(response.GetData(), response.GetSize()); } Index: source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp =================================================================== --- source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -876,7 +876,7 @@ const char *stdin_path = NULL; const char *stdout_path = NULL; const char *stderr_path = NULL; - const char *working_dir = launch_info.GetWorkingDirectory(); + FileSpec working_dir = launch_info.GetWorkingDirectory(); const FileAction *file_action; file_action = launch_info.GetFileActionForFD (STDIN_FILENO); @@ -1003,9 +1003,9 @@ if (launch_event_data != NULL && *launch_event_data != '\0') m_gdb_comm.SendLaunchEventDataPacket (launch_event_data); - if (working_dir && working_dir[0]) + if (working_dir) { - m_gdb_comm.SetWorkingDir (working_dir); + m_gdb_comm.SetWorkingDir(working_dir); } // Send the environment and the program + arguments after we connect Index: source/Target/Platform.cpp =================================================================== --- source/Target/Platform.cpp +++ source/Target/Platform.cpp @@ -133,7 +133,7 @@ } //------------------------------------------------------------------ -/// Get the native host platform plug-in. +/// Get the native host platform plug-in. /// /// There should only be one of these for each host that LLDB runs /// upon that should be statically compiled in and registered using @@ -203,9 +203,9 @@ } Error -Platform::GetFileWithUUID (const FileSpec &platform_file, - const UUID *uuid_ptr, - FileSpec &local_file) +Platform::GetFileWithUUID(const FileSpec &platform_file, + const UUID *uuid_ptr, + FileSpec &local_file) { // Default to the local case local_file = platform_file; @@ -464,7 +464,7 @@ if (arch.IsValid()) { if (!arch.GetTriple().str().empty()) - strm.Printf(" Triple: %s\n", arch.GetTriple().str().c_str()); + strm.Printf(" Triple: %s\n", arch.GetTriple().str().c_str()); } if (GetOSVersion(major, minor, update)) @@ -498,22 +498,22 @@ if (GetWorkingDirectory()) { - strm.Printf("WorkingDir: %s\n", GetWorkingDirectory().GetCString()); + strm.Printf("WorkingDir: %s\n", GetWorkingDirectory().GetPath().c_str()); } if (!IsConnected()) return; std::string specific_info(GetPlatformSpecificConnectionInformation()); - + if (specific_info.empty() == false) strm.Printf("Platform-specific connection: %s\n", specific_info.c_str()); } bool -Platform::GetOSVersion (uint32_t &major, - uint32_t &minor, - uint32_t &update) +Platform::GetOSVersion(uint32_t &major, + uint32_t &minor, + uint32_t &update) { Mutex::Locker locker (m_mutex); @@ -527,12 +527,12 @@ m_os_version_set_while_connected = success; } } - else + else { // We have a remote platform. We can only fetch the remote // OS version if we are connected, and we don't want to do it // more than once. - + const bool is_connected = IsConnected(); bool fetch = false; @@ -602,23 +602,23 @@ { "-x", "c++", "-Xclang", "-nostdsysteminc", "-Xclang", "-nostdsysteminc" }; - + options.insert(options.end(), default_compilation_options.begin(), default_compilation_options.end()); } -ConstString +FileSpec Platform::GetWorkingDirectory () { if (IsHost()) { char cwd[PATH_MAX]; if (getcwd(cwd, sizeof(cwd))) - return ConstString(cwd); + return FileSpec{cwd, true}; else - return ConstString(); + return FileSpec{}; } else { @@ -650,24 +650,24 @@ // we have no way to copy pipes and sockets - ignore them and continue return FileSpec::eEnumerateDirectoryResultNext; break; - + case FileSpec::eFileTypeDirectory: { // make the new directory and get in there FileSpec dst_dir = rc_baton->dst; if (!dst_dir.GetFilename()) dst_dir.GetFilename() = src.GetLastPathComponent(); - std::string dst_dir_path (dst_dir.GetPath()); - Error error = rc_baton->platform_ptr->MakeDirectory(dst_dir_path.c_str(), lldb::eFilePermissionsDirectoryDefault); + Error error = rc_baton->platform_ptr->MakeDirectory(dst_dir, lldb::eFilePermissionsDirectoryDefault); if (error.Fail()) { - rc_baton->error.SetErrorStringWithFormat("unable to setup directory %s on remote end", dst_dir_path.c_str()); + rc_baton->error.SetErrorStringWithFormat("unable to setup directory %s on remote end", + dst_dir.GetPath().c_str()); return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out } - + // now recurse std::string src_dir_path (src.GetPath()); - + // Make a filespec that only fills in the directory of a FileSpec so // when we enumerate we can quickly fill in the filename for dst copies FileSpec recurse_dst; @@ -682,22 +682,20 @@ return FileSpec::eEnumerateDirectoryResultNext; } break; - + case FileSpec::eFileTypeSymbolicLink: { // copy the file and keep going FileSpec dst_file = rc_baton->dst; if (!dst_file.GetFilename()) dst_file.GetFilename() = src.GetFilename(); - - char buf[PATH_MAX]; - - rc_baton->error = FileSystem::Readlink(src.GetPath().c_str(), buf, sizeof(buf)); if (rc_baton->error.Fail()) return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out - - rc_baton->error = rc_baton->platform_ptr->CreateSymlink(dst_file.GetPath().c_str(), buf); + + FileSpec src_resolved = src; + src_resolved.ResolvePath(); + rc_baton->error = rc_baton->platform_ptr->CreateSymlink(dst_file, src_resolved); if (rc_baton->error.Fail()) return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out @@ -720,7 +718,7 @@ return FileSpec::eEnumerateDirectoryResultNext; } break; - + case FileSpec::eFileTypeInvalid: case FileSpec::eFileTypeOther: case FileSpec::eFileTypeUnknown: @@ -735,16 +733,16 @@ Platform::Install (const FileSpec& src, const FileSpec& dst) { Error error; - + Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); if (log) log->Printf ("Platform::Install (src='%s', dst='%s')", src.GetPath().c_str(), dst.GetPath().c_str()); FileSpec fixed_dst(dst); - + if (!fixed_dst.GetFilename()) fixed_dst.GetFilename() = src.GetFilename(); - ConstString working_dir = GetWorkingDirectory(); + FileSpec working_dir = GetWorkingDirectory(); if (dst) { @@ -764,7 +762,7 @@ std::string path; if (working_dir) { - relative_spec.SetFile(working_dir.GetCString(), false); + relative_spec = working_dir; relative_spec.AppendPathComponent(dst.GetPath().c_str()); fixed_dst.GetDirectory() = relative_spec.GetDirectory(); } @@ -779,7 +777,7 @@ { if (working_dir) { - fixed_dst.GetDirectory() = working_dir; + fixed_dst.GetDirectory() = ConstString{working_dir.GetPath()}; } else { @@ -792,7 +790,7 @@ { if (working_dir) { - fixed_dst.GetDirectory() = working_dir; + fixed_dst.GetDirectory() = ConstString{working_dir.GetPath()}; } else { @@ -800,9 +798,10 @@ return error; } } - + if (log) - log->Printf ("Platform::Install (src='%s', dst='%s') fixed_dst='%s'", src.GetPath().c_str(), dst.GetPath().c_str(), fixed_dst.GetPath().c_str()); + log->Printf ("Platform::Install (src='%s', dst='%s') fixed_dst='%s'", + src.GetPath().c_str(), dst.GetPath().c_str(), fixed_dst.GetPath().c_str()); if (GetSupportsRSync()) { @@ -815,18 +814,17 @@ case FileSpec::eFileTypeDirectory: { if (GetFileExists (fixed_dst)) - Unlink (fixed_dst.GetPath().c_str()); + Unlink(fixed_dst); uint32_t permissions = src.GetPermissions(); if (permissions == 0) permissions = eFilePermissionsDirectoryDefault; - std::string dst_dir_path(fixed_dst.GetPath()); - error = MakeDirectory(dst_dir_path.c_str(), permissions); + error = MakeDirectory(fixed_dst, permissions); if (error.Success()) { // Make a filespec that only fills in the directory of a FileSpec so // when we enumerate we can quickly fill in the filename for dst copies FileSpec recurse_dst; - recurse_dst.GetDirectory().SetCString(dst_dir_path.c_str()); + recurse_dst.GetDirectory() = ConstString{fixed_dst.GetPath()}; std::string src_dir_path (src.GetPath()); RecurseCopyBaton baton = { recurse_dst, this, Error() }; FileSpec::EnumerateDirectory(src_dir_path.c_str(), true, true, true, RecurseCopy_Callback, &baton); @@ -837,18 +835,18 @@ case FileSpec::eFileTypeRegular: if (GetFileExists (fixed_dst)) - Unlink (fixed_dst.GetPath().c_str()); + Unlink(fixed_dst); error = PutFile(src, fixed_dst); break; case FileSpec::eFileTypeSymbolicLink: { if (GetFileExists (fixed_dst)) - Unlink (fixed_dst.GetPath().c_str()); - char buf[PATH_MAX]; - error = FileSystem::Readlink(src.GetPath().c_str(), buf, sizeof(buf)); + Unlink(fixed_dst); + FileSpec src_resolved = src; + src_resolved.ResolvePath(); if (error.Success()) - error = CreateSymlink(dst.GetPath().c_str(), buf); + error = CreateSymlink(dst, src_resolved); } break; case FileSpec::eFileTypePipe: @@ -868,16 +866,17 @@ } bool -Platform::SetWorkingDirectory (const ConstString &path) +Platform::SetWorkingDirectory(const FileSpec &file_spec) { if (IsHost()) { Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); if (log) - log->Printf("Platform::SetWorkingDirectory('%s')", path.GetCString()); - if (path) + log->Printf("Platform::SetWorkingDirectory('%s')", + file_spec.GetPath().c_str()); + if (file_spec) { - if (chdir(path.GetCString()) == 0) + if (chdir(file_spec.GetPath().c_str()) == 0) return true; } return false; @@ -885,45 +884,48 @@ else { m_working_dir.Clear(); - return SetRemoteWorkingDirectory(path); + return SetRemoteWorkingDirectory(file_spec); } } Error -Platform::MakeDirectory (const char *path, uint32_t permissions) +Platform::MakeDirectory(const FileSpec &file_spec, uint32_t permissions) { if (IsHost()) - return FileSystem::MakeDirectory(path, permissions); + return FileSystem::MakeDirectory(file_spec.GetPath().c_str(), permissions); else { Error error; - error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__); + error.SetErrorStringWithFormat("remote platform %s doesn't support %s", + GetPluginName().GetCString(), __PRETTY_FUNCTION__); return error; } } Error -Platform::GetFilePermissions (const char *path, uint32_t &file_permissions) +Platform::GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions) { if (IsHost()) - return FileSystem::GetFilePermissions(path, file_permissions); + return FileSystem::GetFilePermissions(file_spec.GetPath().c_str(), file_permissions); else { Error error; - error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__); + error.SetErrorStringWithFormat("remote platform %s doesn't support %s", + GetPluginName().GetCString(), __PRETTY_FUNCTION__); return error; } } Error -Platform::SetFilePermissions (const char *path, uint32_t file_permissions) +Platform::SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions) { if (IsHost()) - return FileSystem::SetFilePermissions(path, file_permissions); + return FileSystem::SetFilePermissions(file_spec.GetPath().c_str(), file_permissions); else { Error error; - error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__); + error.SetErrorStringWithFormat("remote platform %s doesn't support %s", + GetPluginName().GetCString(), __PRETTY_FUNCTION__); return error; } } @@ -940,18 +942,19 @@ if (IsHost()) return "127.0.0.1"; - if (m_name.empty()) + if (m_name.empty()) return NULL; return m_name.c_str(); } bool -Platform::SetRemoteWorkingDirectory(const ConstString &path) +Platform::SetRemoteWorkingDirectory(const FileSpec &working_dir) { Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); if (log) - log->Printf("Platform::SetRemoteWorkingDirectory('%s')", path.GetCString()); - m_working_dir = path; + log->Printf("Platform::SetRemoteWorkingDirectory('%s')", + working_dir.GetPath().c_str()); + m_working_dir = working_dir; return true; } @@ -990,15 +993,15 @@ } bool -Platform::SetOSVersion (uint32_t major, - uint32_t minor, - uint32_t update) +Platform::SetOSVersion(uint32_t major, + uint32_t minor, + uint32_t update) { if (IsHost()) { // We don't need anyone setting the OS version for the host platform, // we should be able to figure it out by calling HostInfo::GetOSVersion(...). - return false; + return false; } else { @@ -1033,11 +1036,11 @@ { if (module_spec.GetArchitecture().IsValid()) { - error = ModuleList::GetSharedModule (module_spec, - exe_module_sp, - module_search_paths_ptr, - NULL, - NULL); + error = ModuleList::GetSharedModule(module_spec, + exe_module_sp, + module_search_paths_ptr, + NULL, + NULL); } else { @@ -1047,12 +1050,12 @@ ModuleSpec arch_module_spec(module_spec); for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, arch_module_spec.GetArchitecture()); ++idx) { - error = ModuleList::GetSharedModule (arch_module_spec, - exe_module_sp, - module_search_paths_ptr, - NULL, - NULL); - // Did we find an executable using one of the + error = ModuleList::GetSharedModule(arch_module_spec, + exe_module_sp, + module_search_paths_ptr, + NULL, + NULL); + // Did we find an executable using one of the if (error.Success() && exe_module_sp) break; } @@ -1077,7 +1080,6 @@ else error.SetErrorString("unable to resolve symbol file"); return error; - } @@ -1103,12 +1105,12 @@ m_system_arch_set_while_connected = m_system_arch.IsValid(); } } - else + else { // We have a remote platform. We can only fetch the remote // system architecture if we are connected, and we don't want to do it // more than once. - + const bool is_connected = IsConnected(); bool fetch = false; @@ -1162,7 +1164,7 @@ bool Platform::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info) { - // Take care of the host case so that each subclass can just + // Take care of the host case so that each subclass can just // call this function to get the host functionality. if (IsHost()) return Host::GetProcessInfo (pid, process_info); @@ -1173,12 +1175,12 @@ Platform::FindProcesses (const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos) { - // Take care of the host case so that each subclass can just + // Take care of the host case so that each subclass can just // call this function to get the host functionality. uint32_t match_count = 0; if (IsHost()) match_count = Host::FindProcesses (match_info, process_infos); - return match_count; + return match_count; } @@ -1196,7 +1198,7 @@ { if (::getenv ("LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY")) launch_info.GetFlags().Set (eLaunchFlagLaunchInTTY); - + if (launch_info.GetFlags().Test (eLaunchFlagLaunchInShell)) { const bool is_localhost = true; @@ -1260,10 +1262,10 @@ } lldb::ProcessSP -Platform::DebugProcess (ProcessLaunchInfo &launch_info, - Debugger &debugger, - Target *target, // Can be NULL, if NULL create a new target, else use existing one - Error &error) +Platform::DebugProcess(ProcessLaunchInfo &launch_info, + Debugger &debugger, + Target *target, // Can be NULL, if NULL create a new target, else use existing one + Error &error) { Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM)); if (log) @@ -1276,7 +1278,7 @@ // group, since then we can handle ^C interrupts ourselves w/o having to worry // about the target getting them as well. launch_info.SetLaunchInSeparateProcessGroup(true); - + error = LaunchProcess (launch_info); if (error.Success()) { @@ -1291,13 +1293,13 @@ if (log) log->Printf ("Platform::%s Attach() succeeded, Process plugin: %s", __FUNCTION__, process_sp->GetPluginName ().AsCString ()); launch_info.SetHijackListener(attach_info.GetHijackListener()); - + // Since we attached to the process, it will think it needs to detach // if the process object just goes away without an explicit call to - // Process::Kill() or Process::Detach(), so let it know to kill the + // Process::Kill() or Process::Detach(), so let it know to kill the // process if this happens. process_sp->SetShouldDetach (false); - + // If we didn't have any file actions, the pseudo terminal might // have been used where the slave side was given as the file to // open for stdin/out/err after we have already opened the master @@ -1452,29 +1454,29 @@ } Error -Platform::GetFile (const FileSpec& source, - const FileSpec& destination) +Platform::GetFile(const FileSpec &source, + const FileSpec &destination) { Error error("unimplemented"); return error; } Error -Platform::CreateSymlink (const char *src, // The name of the link is in src - const char *dst)// The symlink points to dst +Platform::CreateSymlink(const FileSpec &src, // The name of the link is in src + const FileSpec &dst) // The symlink points to dst { Error error("unimplemented"); return error; } bool -Platform::GetFileExists (const lldb_private::FileSpec& file_spec) +Platform::GetFileExists(const lldb_private::FileSpec &file_spec) { return false; } Error -Platform::Unlink (const char *path) +Platform::Unlink(const FileSpec &path) { Error error("unimplemented"); return error; @@ -1492,15 +1494,15 @@ } lldb_private::Error -Platform::RunShellCommand (const char *command, // Shouldn't be NULL - const char *working_dir, // Pass NULL to use the current working directory - int *status_ptr, // Pass NULL if you don't want the process exit status - int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit - std::string *command_output, // Pass NULL if you don't want the command output - uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish +Platform::RunShellCommand(const char *command, // Shouldn't be NULL + const FileSpec &working_dir, // Pass NULL to use the current working directory + int *status_ptr, // Pass NULL if you don't want the process exit status + int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit + std::string *command_output, // Pass NULL if you don't want the command output + uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish { if (IsHost()) - return Host::RunShellCommand (command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec); + return Host::RunShellCommand(command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec); else return Error("unimplemented"); } @@ -1607,24 +1609,24 @@ case 'r': m_rsync = true; break; - + case 'R': m_rsync_opts.assign(option_arg); break; - + case 'P': m_rsync_prefix.assign(option_arg); break; - + case 'i': m_ignores_remote_hostname = true; break; - + default: error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); break; } - + return error; } @@ -1673,16 +1675,16 @@ case 's': m_ssh = true; break; - + case 'S': m_ssh_opts.assign(option_arg); break; - + default: error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); break; } - + return error; } @@ -1724,12 +1726,12 @@ case 'c': m_cache_dir.assign(option_arg); break; - + default: error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); break; } - + return error; } Index: source/Target/Process.cpp =================================================================== --- source/Target/Process.cpp +++ source/Target/Process.cpp @@ -428,7 +428,7 @@ switch (short_option) { case 's': // Stop at program entry point - launch_info.GetFlags().Set (eLaunchFlagStopAtEntry); + launch_info.GetFlags().Set(eLaunchFlagStopAtEntry); break; case 'i': // STDIN for read only @@ -456,7 +456,7 @@ } case 'p': // Process plug-in name - launch_info.SetProcessPluginName (option_arg); + launch_info.SetProcessPluginName(option_arg); break; case 'n': // Disable STDIO @@ -472,11 +472,11 @@ } case 'w': - launch_info.SetWorkingDirectory (option_arg); + launch_info.SetWorkingDirectory(FileSpec{option_arg, false}); break; case 't': // Open process in new terminal window - launch_info.GetFlags().Set (eLaunchFlagLaunchInTTY); + launch_info.GetFlags().Set(eLaunchFlagLaunchInTTY); break; case 'a': Index: source/Target/ProcessLaunchInfo.cpp =================================================================== --- source/Target/ProcessLaunchInfo.cpp +++ source/Target/ProcessLaunchInfo.cpp @@ -42,8 +42,11 @@ { } -ProcessLaunchInfo::ProcessLaunchInfo(const char *stdin_path, const char *stdout_path, const char *stderr_path, - const char *working_directory, uint32_t launch_flags) : +ProcessLaunchInfo::ProcessLaunchInfo(const FileSpec &stdin_file_spec, + const FileSpec &stdout_file_spec, + const FileSpec &stderr_file_spec, + const FileSpec &working_directory, + uint32_t launch_flags) : ProcessInfo(), m_working_dir(), m_plugin_name(), @@ -57,28 +60,28 @@ m_listener_sp (), m_hijack_listener_sp() { - if (stdin_path) + if (stdin_file_spec) { FileAction file_action; const bool read = true; const bool write = false; - if (file_action.Open(STDIN_FILENO, stdin_path, read, write)) + if (file_action.Open(STDIN_FILENO, stdin_file_spec.GetPath().c_str(), read, write)) AppendFileAction (file_action); } - if (stdout_path) + if (stdout_file_spec) { FileAction file_action; const bool read = false; const bool write = true; - if (file_action.Open(STDOUT_FILENO, stdout_path, read, write)) + if (file_action.Open(STDOUT_FILENO, stdout_file_spec.GetPath().c_str(), read, write)) AppendFileAction (file_action); } - if (stderr_path) + if (stderr_file_spec) { FileAction file_action; const bool read = false; const bool write = true; - if (file_action.Open(STDERR_FILENO, stderr_path, read, write)) + if (file_action.Open(STDERR_FILENO, stderr_file_spec.GetPath().c_str(), read, write)) AppendFileAction (file_action); } if (working_directory) @@ -152,21 +155,16 @@ return NULL; } -const char * -ProcessLaunchInfo::GetWorkingDirectory () const +const FileSpec & +ProcessLaunchInfo::GetWorkingDirectory() const { - if (m_working_dir.empty()) - return NULL; - return m_working_dir.c_str(); + return m_working_dir; } void -ProcessLaunchInfo::SetWorkingDirectory (const char *working_dir) +ProcessLaunchInfo::SetWorkingDirectory(const FileSpec &working_dir) { - if (working_dir && working_dir[0]) - m_working_dir.assign (working_dir); - else - m_working_dir.clear(); + m_working_dir = working_dir; } const char * @@ -227,7 +225,7 @@ ProcessLaunchInfo::Clear () { ProcessInfo::Clear(); - m_working_dir.clear(); + m_working_dir.Clear(); m_plugin_name.clear(); m_shell.Clear(); m_flags.Clear(); @@ -432,14 +430,14 @@ { // We have a relative path to our executable which may not work if // we just try to run "a.out" (without it being converted to "./a.out") - const char *working_dir = GetWorkingDirectory(); + FileSpec working_dir = GetWorkingDirectory(); // Be sure to put quotes around PATH's value in case any paths have spaces... std::string new_path("PATH=\""); const size_t empty_path_len = new_path.size(); - if (working_dir && working_dir[0]) + if (working_dir) { - new_path += working_dir; + new_path += working_dir.GetPath(); } else { Index: source/Target/Target.cpp =================================================================== --- source/Target/Target.cpp +++ source/Target/Target.cpp @@ -2377,9 +2377,8 @@ if (is_main_executable) // TODO: add setting for always installing main executable??? { // Always install the main executable - remote_file = FileSpec(module_sp->GetFileSpec().GetFilename().AsCString(), - false, module_sp->GetArchitecture()); - remote_file.GetDirectory() = platform_sp->GetWorkingDirectory(); + remote_file = platform_sp->GetRemoteWorkingDirectory(); + remote_file.AppendPathComponent(module_sp->GetFileSpec().GetFilename().GetCString()); } } if (remote_file) @@ -2390,7 +2389,7 @@ module_sp->SetPlatformFileSpec(remote_file); if (is_main_executable) { - platform_sp->SetFilePermissions(remote_file.GetPath(false).c_str(), 0700); + platform_sp->SetFilePermissions(remote_file, 0700); if (launch_info) launch_info->SetExecutableFile(remote_file, false); }