Index: lldb/trunk/include/lldb/Host/FileAction.h =================================================================== --- lldb/trunk/include/lldb/Host/FileAction.h +++ lldb/trunk/include/lldb/Host/FileAction.h @@ -0,0 +1,58 @@ +//===-- FileAction.h --------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLDB_HOST_FILEACTION_H +#define LLDB_HOST_FILEACTION_H + +#include "lldb/Utility/FileSpec.h" +#include + +namespace lldb_private { + +class FileAction { +public: + enum Action { + eFileActionNone, + eFileActionClose, + eFileActionDuplicate, + eFileActionOpen + }; + + FileAction(); + + void Clear(); + + bool Close(int fd); + + bool Duplicate(int fd, int dup_fd); + + bool Open(int fd, const FileSpec &file_spec, bool read, bool write); + + int GetFD() const { return m_fd; } + + Action GetAction() const { return m_action; } + + int GetActionArgument() const { return m_arg; } + + llvm::StringRef GetPath() const; + + const FileSpec &GetFileSpec() const; + + void Dump(Stream &stream) const; + +protected: + Action m_action; // The action for this file + int m_fd; // An existing file descriptor + int m_arg; // oflag for eFileActionOpen*, dup_fd for eFileActionDuplicate + FileSpec + m_file_spec; // A file spec to use for opening after fork or posix_spawn +}; + +} // namespace lldb_private + +#endif Index: lldb/trunk/include/lldb/Host/ProcessInfo.h =================================================================== --- lldb/trunk/include/lldb/Host/ProcessInfo.h +++ lldb/trunk/include/lldb/Host/ProcessInfo.h @@ -0,0 +1,101 @@ +//===-- ProcessInfo.h -------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_ProcessInfo_h_ +#define liblldb_ProcessInfo_h_ + +// LLDB headers +#include "lldb/Utility/ArchSpec.h" +#include "lldb/Utility/Args.h" +#include "lldb/Utility/Environment.h" +#include "lldb/Utility/FileSpec.h" + +namespace lldb_private { +//---------------------------------------------------------------------- +// ProcessInfo +// +// A base class for information for a process. This can be used to fill +// out information for a process prior to launching it, or it can be used for +// an instance of a process and can be filled in with the existing values for +// that process. +//---------------------------------------------------------------------- +class ProcessInfo { +public: + ProcessInfo(); + + ProcessInfo(const char *name, const ArchSpec &arch, lldb::pid_t pid); + + void Clear(); + + const char *GetName() const; + + size_t GetNameLength() const; + + FileSpec &GetExecutableFile() { return m_executable; } + + void SetExecutableFile(const FileSpec &exe_file, + bool add_exe_file_as_first_arg); + + const FileSpec &GetExecutableFile() const { return m_executable; } + + uint32_t GetUserID() const { return m_uid; } + + uint32_t GetGroupID() const { return m_gid; } + + bool UserIDIsValid() const { return m_uid != UINT32_MAX; } + + bool GroupIDIsValid() const { return m_gid != UINT32_MAX; } + + void SetUserID(uint32_t uid) { m_uid = uid; } + + void SetGroupID(uint32_t gid) { m_gid = gid; } + + ArchSpec &GetArchitecture() { return m_arch; } + + const ArchSpec &GetArchitecture() const { return m_arch; } + + void SetArchitecture(const ArchSpec &arch) { m_arch = arch; } + + lldb::pid_t GetProcessID() const { return m_pid; } + + void SetProcessID(lldb::pid_t pid) { m_pid = pid; } + + bool ProcessIDIsValid() const { return m_pid != LLDB_INVALID_PROCESS_ID; } + + void Dump(Stream &s, Platform *platform) const; + + Args &GetArguments() { return m_arguments; } + + const Args &GetArguments() const { return m_arguments; } + + llvm::StringRef GetArg0() const; + + void SetArg0(llvm::StringRef arg); + + void SetArguments(const Args &args, bool first_arg_is_executable); + + void SetArguments(char const **argv, bool first_arg_is_executable); + + Environment &GetEnvironment() { return m_environment; } + const Environment &GetEnvironment() const { return m_environment; } + +protected: + FileSpec m_executable; + std::string m_arg0; // argv[0] if supported. If empty, then use m_executable. + // Not all process plug-ins support specifying an argv[0] that differs from + // the resolved platform executable (which is in m_executable) + Args m_arguments; // All program arguments except argv[0] + Environment m_environment; + uint32_t m_uid; + uint32_t m_gid; + ArchSpec m_arch; + lldb::pid_t m_pid; +}; +} + +#endif // #ifndef liblldb_ProcessInfo_h_ Index: lldb/trunk/include/lldb/Host/ProcessLaunchInfo.h =================================================================== --- lldb/trunk/include/lldb/Host/ProcessLaunchInfo.h +++ lldb/trunk/include/lldb/Host/ProcessLaunchInfo.h @@ -0,0 +1,170 @@ +//===-- ProcessLaunchInfo.h -------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_ProcessLaunch_Info_h +#define liblldb_ProcessLaunch_Info_h + +// C++ Headers +#include + +// LLDB Headers +#include "lldb/Utility/Flags.h" + +#include "lldb/Host/FileAction.h" +#include "lldb/Host/Host.h" +#include "lldb/Host/ProcessInfo.h" +#include "lldb/Host/PseudoTerminal.h" +#include "lldb/Utility/FileSpec.h" + +namespace lldb_private { + +//---------------------------------------------------------------------- +// ProcessLaunchInfo +// +// Describes any information that is required to launch a process. +//---------------------------------------------------------------------- + +class ProcessLaunchInfo : public ProcessInfo { +public: + ProcessLaunchInfo(); + + ProcessLaunchInfo(const FileSpec &stdin_file_spec, + const FileSpec &stdout_file_spec, + const FileSpec &stderr_file_spec, + const FileSpec &working_dir, uint32_t launch_flags); + + void AppendFileAction(const FileAction &info) { + m_file_actions.push_back(info); + } + + bool AppendCloseFileAction(int fd); + + bool AppendDuplicateFileAction(int fd, int dup_fd); + + bool AppendOpenFileAction(int fd, const FileSpec &file_spec, bool read, + bool write); + + bool AppendSuppressFileAction(int fd, bool read, bool write); + + // Redirect stdin/stdout/stderr to a pty, if no action for the respective file + // descriptor is specified. (So if stdin and stdout already have file actions, + // but stderr doesn't, then only stderr will be redirected to a pty.) + llvm::Error SetUpPtyRedirection(); + + size_t GetNumFileActions() const { return m_file_actions.size(); } + + const FileAction *GetFileActionAtIndex(size_t idx) const; + + const FileAction *GetFileActionForFD(int fd) const; + + Flags &GetFlags() { return m_flags; } + + const Flags &GetFlags() const { return m_flags; } + + const FileSpec &GetWorkingDirectory() const; + + void SetWorkingDirectory(const FileSpec &working_dir); + + const char *GetProcessPluginName() const; + + void SetProcessPluginName(llvm::StringRef plugin); + + const FileSpec &GetShell() const; + + void SetShell(const FileSpec &shell); + + uint32_t GetResumeCount() const { return m_resume_count; } + + void SetResumeCount(uint32_t c) { m_resume_count = c; } + + bool GetLaunchInSeparateProcessGroup() const { + return m_flags.Test(lldb::eLaunchFlagLaunchInSeparateProcessGroup); + } + + void SetLaunchInSeparateProcessGroup(bool separate); + + bool GetShellExpandArguments() const { + return m_flags.Test(lldb::eLaunchFlagShellExpandArguments); + } + + void SetShellExpandArguments(bool expand); + + void Clear(); + + bool ConvertArgumentsForLaunchingInShell(Status &error, bool localhost, + bool will_debug, + bool first_arg_is_full_shell_command, + int32_t num_resumes); + + void + SetMonitorProcessCallback(const Host::MonitorChildProcessCallback &callback, + bool monitor_signals); + + Host::MonitorChildProcessCallback GetMonitorProcessCallback() const { + return m_monitor_callback; + } + + /// A Monitor callback which does not take any action on process events. Use + /// this if you don't need to take any particular action when the process + /// terminates, but you still need to reap it. + static bool NoOpMonitorCallback(lldb::pid_t pid, bool exited, int signal, + int status); + + bool GetMonitorSignals() const { return m_monitor_signals; } + + // If the LaunchInfo has a monitor callback, then arrange to monitor the + // process. Return true if the LaunchInfo has taken care of monitoring the + // process, and false if the caller might want to monitor the process + // themselves. + + bool MonitorProcess() const; + + PseudoTerminal &GetPTY() { return *m_pty; } + + // Get and set the actual listener that will be used for the process events + lldb::ListenerSP GetListener() const { return m_listener_sp; } + + void SetListener(const lldb::ListenerSP &listener_sp) { + m_listener_sp = listener_sp; + } + + lldb::ListenerSP GetHijackListener() const { return m_hijack_listener_sp; } + + void SetHijackListener(const lldb::ListenerSP &listener_sp) { + m_hijack_listener_sp = listener_sp; + } + + void SetLaunchEventData(const char *data) { m_event_data.assign(data); } + + const char *GetLaunchEventData() const { return m_event_data.c_str(); } + + void SetDetachOnError(bool enable); + + bool GetDetachOnError() const { + return m_flags.Test(lldb::eLaunchFlagDetachOnError); + } + +protected: + FileSpec m_working_dir; + std::string m_plugin_name; + FileSpec m_shell; + Flags m_flags; // Bitwise OR of bits from lldb::LaunchFlags + std::vector m_file_actions; // File actions for any other files + std::shared_ptr m_pty; + uint32_t m_resume_count; // How many times do we resume after launching + Host::MonitorChildProcessCallback m_monitor_callback; + void *m_monitor_callback_baton; + bool m_monitor_signals; + std::string m_event_data; // A string passed to the plugin launch, having no + // meaning to the upper levels of lldb. + lldb::ListenerSP m_listener_sp; + lldb::ListenerSP m_hijack_listener_sp; +}; +} + +#endif // liblldb_ProcessLaunch_Info_h Index: lldb/trunk/include/lldb/Target/FileAction.h =================================================================== --- lldb/trunk/include/lldb/Target/FileAction.h +++ lldb/trunk/include/lldb/Target/FileAction.h @@ -1,58 +0,0 @@ -//===-- FileAction.h --------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef liblldb_Target_FileAction_h -#define liblldb_Target_FileAction_h - -#include "lldb/Utility/FileSpec.h" -#include - -namespace lldb_private { - -class FileAction { -public: - enum Action { - eFileActionNone, - eFileActionClose, - eFileActionDuplicate, - eFileActionOpen - }; - - FileAction(); - - void Clear(); - - bool Close(int fd); - - bool Duplicate(int fd, int dup_fd); - - bool Open(int fd, const FileSpec &file_spec, bool read, bool write); - - int GetFD() const { return m_fd; } - - Action GetAction() const { return m_action; } - - int GetActionArgument() const { return m_arg; } - - llvm::StringRef GetPath() const; - - const FileSpec &GetFileSpec() const; - - void Dump(Stream &stream) const; - -protected: - Action m_action; // The action for this file - int m_fd; // An existing file descriptor - int m_arg; // oflag for eFileActionOpen*, dup_fd for eFileActionDuplicate - FileSpec - m_file_spec; // A file spec to use for opening after fork or posix_spawn -}; - -} // namespace lldb_private - -#endif Index: lldb/trunk/include/lldb/Target/Process.h =================================================================== --- lldb/trunk/include/lldb/Target/Process.h +++ lldb/trunk/include/lldb/Target/Process.h @@ -28,14 +28,14 @@ #include "lldb/Core/ThreadSafeValue.h" #include "lldb/Core/UserSettingsController.h" #include "lldb/Host/HostThread.h" +#include "lldb/Host/ProcessInfo.h" +#include "lldb/Host/ProcessLaunchInfo.h" #include "lldb/Host/ProcessRunLock.h" #include "lldb/Interpreter/Options.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Target/ExecutionContextScope.h" #include "lldb/Target/InstrumentationRuntime.h" #include "lldb/Target/Memory.h" -#include "lldb/Target/ProcessInfo.h" -#include "lldb/Target/ProcessLaunchInfo.h" #include "lldb/Target/QueueList.h" #include "lldb/Target/ThreadList.h" #include "lldb/Utility/ArchSpec.h" Index: lldb/trunk/include/lldb/Target/ProcessInfo.h =================================================================== --- lldb/trunk/include/lldb/Target/ProcessInfo.h +++ lldb/trunk/include/lldb/Target/ProcessInfo.h @@ -1,101 +0,0 @@ -//===-- ProcessInfo.h -------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef liblldb_ProcessInfo_h_ -#define liblldb_ProcessInfo_h_ - -// LLDB headers -#include "lldb/Utility/ArchSpec.h" -#include "lldb/Utility/Args.h" -#include "lldb/Utility/Environment.h" -#include "lldb/Utility/FileSpec.h" - -namespace lldb_private { -//---------------------------------------------------------------------- -// ProcessInfo -// -// A base class for information for a process. This can be used to fill -// out information for a process prior to launching it, or it can be used for -// an instance of a process and can be filled in with the existing values for -// that process. -//---------------------------------------------------------------------- -class ProcessInfo { -public: - ProcessInfo(); - - ProcessInfo(const char *name, const ArchSpec &arch, lldb::pid_t pid); - - void Clear(); - - const char *GetName() const; - - size_t GetNameLength() const; - - FileSpec &GetExecutableFile() { return m_executable; } - - void SetExecutableFile(const FileSpec &exe_file, - bool add_exe_file_as_first_arg); - - const FileSpec &GetExecutableFile() const { return m_executable; } - - uint32_t GetUserID() const { return m_uid; } - - uint32_t GetGroupID() const { return m_gid; } - - bool UserIDIsValid() const { return m_uid != UINT32_MAX; } - - bool GroupIDIsValid() const { return m_gid != UINT32_MAX; } - - void SetUserID(uint32_t uid) { m_uid = uid; } - - void SetGroupID(uint32_t gid) { m_gid = gid; } - - ArchSpec &GetArchitecture() { return m_arch; } - - const ArchSpec &GetArchitecture() const { return m_arch; } - - void SetArchitecture(const ArchSpec &arch) { m_arch = arch; } - - lldb::pid_t GetProcessID() const { return m_pid; } - - void SetProcessID(lldb::pid_t pid) { m_pid = pid; } - - bool ProcessIDIsValid() const { return m_pid != LLDB_INVALID_PROCESS_ID; } - - void Dump(Stream &s, Platform *platform) const; - - Args &GetArguments() { return m_arguments; } - - const Args &GetArguments() const { return m_arguments; } - - llvm::StringRef GetArg0() const; - - void SetArg0(llvm::StringRef arg); - - void SetArguments(const Args &args, bool first_arg_is_executable); - - void SetArguments(char const **argv, bool first_arg_is_executable); - - Environment &GetEnvironment() { return m_environment; } - const Environment &GetEnvironment() const { return m_environment; } - -protected: - FileSpec m_executable; - std::string m_arg0; // argv[0] if supported. If empty, then use m_executable. - // Not all process plug-ins support specifying an argv[0] that differs from - // the resolved platform executable (which is in m_executable) - Args m_arguments; // All program arguments except argv[0] - Environment m_environment; - uint32_t m_uid; - uint32_t m_gid; - ArchSpec m_arch; - lldb::pid_t m_pid; -}; -} - -#endif // #ifndef liblldb_ProcessInfo_h_ Index: lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h =================================================================== --- lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h +++ lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h @@ -1,170 +0,0 @@ -//===-- ProcessLaunchInfo.h -------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef liblldb_ProcessLaunch_Info_h -#define liblldb_ProcessLaunch_Info_h - -// C++ Headers -#include - -// LLDB Headers -#include "lldb/Utility/Flags.h" - -#include "lldb/Host/Host.h" -#include "lldb/Host/PseudoTerminal.h" -#include "lldb/Target/FileAction.h" -#include "lldb/Target/ProcessInfo.h" -#include "lldb/Utility/FileSpec.h" - -namespace lldb_private { - -//---------------------------------------------------------------------- -// ProcessLaunchInfo -// -// Describes any information that is required to launch a process. -//---------------------------------------------------------------------- - -class ProcessLaunchInfo : public ProcessInfo { -public: - ProcessLaunchInfo(); - - ProcessLaunchInfo(const FileSpec &stdin_file_spec, - const FileSpec &stdout_file_spec, - const FileSpec &stderr_file_spec, - const FileSpec &working_dir, uint32_t launch_flags); - - void AppendFileAction(const FileAction &info) { - m_file_actions.push_back(info); - } - - bool AppendCloseFileAction(int fd); - - bool AppendDuplicateFileAction(int fd, int dup_fd); - - bool AppendOpenFileAction(int fd, const FileSpec &file_spec, bool read, - bool write); - - bool AppendSuppressFileAction(int fd, bool read, bool write); - - // Redirect stdin/stdout/stderr to a pty, if no action for the respective file - // descriptor is specified. (So if stdin and stdout already have file actions, - // but stderr doesn't, then only stderr will be redirected to a pty.) - llvm::Error SetUpPtyRedirection(); - - size_t GetNumFileActions() const { return m_file_actions.size(); } - - const FileAction *GetFileActionAtIndex(size_t idx) const; - - const FileAction *GetFileActionForFD(int fd) const; - - Flags &GetFlags() { return m_flags; } - - const Flags &GetFlags() const { return m_flags; } - - const FileSpec &GetWorkingDirectory() const; - - void SetWorkingDirectory(const FileSpec &working_dir); - - const char *GetProcessPluginName() const; - - void SetProcessPluginName(llvm::StringRef plugin); - - const FileSpec &GetShell() const; - - void SetShell(const FileSpec &shell); - - uint32_t GetResumeCount() const { return m_resume_count; } - - void SetResumeCount(uint32_t c) { m_resume_count = c; } - - bool GetLaunchInSeparateProcessGroup() const { - return m_flags.Test(lldb::eLaunchFlagLaunchInSeparateProcessGroup); - } - - void SetLaunchInSeparateProcessGroup(bool separate); - - bool GetShellExpandArguments() const { - return m_flags.Test(lldb::eLaunchFlagShellExpandArguments); - } - - void SetShellExpandArguments(bool expand); - - void Clear(); - - bool ConvertArgumentsForLaunchingInShell(Status &error, bool localhost, - bool will_debug, - bool first_arg_is_full_shell_command, - int32_t num_resumes); - - void - SetMonitorProcessCallback(const Host::MonitorChildProcessCallback &callback, - bool monitor_signals); - - Host::MonitorChildProcessCallback GetMonitorProcessCallback() const { - return m_monitor_callback; - } - - /// A Monitor callback which does not take any action on process events. Use - /// this if you don't need to take any particular action when the process - /// terminates, but you still need to reap it. - static bool NoOpMonitorCallback(lldb::pid_t pid, bool exited, int signal, - int status); - - bool GetMonitorSignals() const { return m_monitor_signals; } - - // If the LaunchInfo has a monitor callback, then arrange to monitor the - // process. Return true if the LaunchInfo has taken care of monitoring the - // process, and false if the caller might want to monitor the process - // themselves. - - bool MonitorProcess() const; - - PseudoTerminal &GetPTY() { return *m_pty; } - - // Get and set the actual listener that will be used for the process events - lldb::ListenerSP GetListener() const { return m_listener_sp; } - - void SetListener(const lldb::ListenerSP &listener_sp) { - m_listener_sp = listener_sp; - } - - lldb::ListenerSP GetHijackListener() const { return m_hijack_listener_sp; } - - void SetHijackListener(const lldb::ListenerSP &listener_sp) { - m_hijack_listener_sp = listener_sp; - } - - void SetLaunchEventData(const char *data) { m_event_data.assign(data); } - - const char *GetLaunchEventData() const { return m_event_data.c_str(); } - - void SetDetachOnError(bool enable); - - bool GetDetachOnError() const { - return m_flags.Test(lldb::eLaunchFlagDetachOnError); - } - -protected: - FileSpec m_working_dir; - std::string m_plugin_name; - FileSpec m_shell; - Flags m_flags; // Bitwise OR of bits from lldb::LaunchFlags - std::vector m_file_actions; // File actions for any other files - std::shared_ptr m_pty; - uint32_t m_resume_count; // How many times do we resume after launching - Host::MonitorChildProcessCallback m_monitor_callback; - void *m_monitor_callback_baton; - bool m_monitor_signals; - std::string m_event_data; // A string passed to the plugin launch, having no - // meaning to the upper levels of lldb. - lldb::ListenerSP m_listener_sp; - lldb::ListenerSP m_hijack_listener_sp; -}; -} - -#endif // liblldb_ProcessLaunch_Info_h Index: lldb/trunk/include/lldb/Target/Target.h =================================================================== --- lldb/trunk/include/lldb/Target/Target.h +++ lldb/trunk/include/lldb/Target/Target.h @@ -23,10 +23,10 @@ #include "lldb/Core/ModuleList.h" #include "lldb/Core/UserSettingsController.h" #include "lldb/Expression/Expression.h" +#include "lldb/Host/ProcessLaunchInfo.h" #include "lldb/Symbol/TypeSystem.h" #include "lldb/Target/ExecutionContextScope.h" #include "lldb/Target/PathMappingList.h" -#include "lldb/Target/ProcessLaunchInfo.h" #include "lldb/Target/SectionLoadHistory.h" #include "lldb/Utility/ArchSpec.h" #include "lldb/Utility/Broadcaster.h" Index: lldb/trunk/include/lldb/module.modulemap =================================================================== --- lldb/trunk/include/lldb/module.modulemap +++ lldb/trunk/include/lldb/module.modulemap @@ -17,6 +17,7 @@ module Editline { header "Host/Editline.h" export * } module FileCache { header "Host/FileCache.h" export * } module File { header "Host/File.h" export * } + module FileAction { header "Host/FileAction.h" export * } module FileSystem { header "Host/FileSystem.h" export * } module HostGetOpt { header "Host/HostGetOpt.h" export * } module Host { header "Host/Host.h" export * } @@ -38,7 +39,9 @@ module PipeBase { header "Host/PipeBase.h" export * } module Pipe { header "Host/Pipe.h" export * } module PosixApi { header "Host/PosixApi.h" export * } + module ProcessInfo { header "Host/ProcessInfo.h" export * } module ProcessLauncher { header "Host/ProcessLauncher.h" export * } + module ProcessLaunchInfo { header "Host/ProcessLaunchInfo.h" export * } module ProcessRunLock { header "Host/ProcessRunLock.h" export * } module PseudoTerminal { header "Host/PseudoTerminal.h" export * } module SafeMachO { header "Host/SafeMachO.h" export * } Index: lldb/trunk/source/API/SBLaunchInfo.cpp =================================================================== --- lldb/trunk/source/API/SBLaunchInfo.cpp +++ lldb/trunk/source/API/SBLaunchInfo.cpp @@ -10,7 +10,7 @@ #include "lldb/API/SBFileSpec.h" #include "lldb/API/SBListener.h" -#include "lldb/Target/ProcessLaunchInfo.h" +#include "lldb/Host/ProcessLaunchInfo.h" using namespace lldb; using namespace lldb_private; Index: lldb/trunk/source/Host/CMakeLists.txt =================================================================== --- lldb/trunk/source/Host/CMakeLists.txt +++ lldb/trunk/source/Host/CMakeLists.txt @@ -19,6 +19,7 @@ add_host_subdirectory(common common/File.cpp + common/FileAction.cpp common/FileCache.cpp common/FileSystem.cpp common/GetOptInc.cpp @@ -36,6 +37,8 @@ common/NativeThreadProtocol.cpp common/OptionParser.cpp common/PipeBase.cpp + common/ProcessInfo.cpp + common/ProcessLaunchInfo.cpp common/ProcessRunLock.cpp common/PseudoTerminal.cpp common/Socket.cpp Index: lldb/trunk/source/Host/common/FileAction.cpp =================================================================== --- lldb/trunk/source/Host/common/FileAction.cpp +++ lldb/trunk/source/Host/common/FileAction.cpp @@ -0,0 +1,90 @@ +//===-- FileAction.cpp ------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include + +#include "lldb/Host/FileAction.h" +#include "lldb/Host/PosixApi.h" +#include "lldb/Utility/Stream.h" + +using namespace lldb_private; + +//---------------------------------------------------------------------------- +// FileAction member functions +//---------------------------------------------------------------------------- + +FileAction::FileAction() + : m_action(eFileActionNone), m_fd(-1), m_arg(-1), m_file_spec() {} + +void FileAction::Clear() { + m_action = eFileActionNone; + m_fd = -1; + m_arg = -1; + m_file_spec.Clear(); +} + +llvm::StringRef FileAction::GetPath() const { return m_file_spec.GetCString(); } + +const FileSpec &FileAction::GetFileSpec() const { return m_file_spec; } + +bool FileAction::Open(int fd, const FileSpec &file_spec, bool read, + bool write) { + if ((read || write) && fd >= 0 && file_spec) { + m_action = eFileActionOpen; + m_fd = fd; + if (read && write) + m_arg = O_NOCTTY | O_CREAT | O_RDWR; + else if (read) + m_arg = O_NOCTTY | O_RDONLY; + else + m_arg = O_NOCTTY | O_CREAT | O_WRONLY; + m_file_spec = file_spec; + return true; + } else { + Clear(); + } + return false; +} + +bool FileAction::Close(int fd) { + Clear(); + if (fd >= 0) { + m_action = eFileActionClose; + m_fd = fd; + } + return m_fd >= 0; +} + +bool FileAction::Duplicate(int fd, int dup_fd) { + Clear(); + if (fd >= 0 && dup_fd >= 0) { + m_action = eFileActionDuplicate; + m_fd = fd; + m_arg = dup_fd; + } + return m_fd >= 0; +} + +void FileAction::Dump(Stream &stream) const { + stream.PutCString("file action: "); + switch (m_action) { + case eFileActionClose: + stream.Printf("close fd %d", m_fd); + break; + case eFileActionDuplicate: + stream.Printf("duplicate fd %d to %d", m_fd, m_arg); + break; + case eFileActionNone: + stream.PutCString("no action"); + break; + case eFileActionOpen: + stream.Printf("open fd %d with '%s', OFLAGS = 0x%x", m_fd, + m_file_spec.GetCString(), m_arg); + break; + } +} Index: lldb/trunk/source/Host/common/Host.cpp =================================================================== --- lldb/trunk/source/Host/common/Host.cpp +++ lldb/trunk/source/Host/common/Host.cpp @@ -46,16 +46,16 @@ #include +#include "lldb/Host/FileAction.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" #include "lldb/Host/HostProcess.h" #include "lldb/Host/MonitoringProcessLauncher.h" +#include "lldb/Host/ProcessLaunchInfo.h" #include "lldb/Host/ProcessLauncher.h" #include "lldb/Host/ThreadLauncher.h" #include "lldb/Host/posix/ConnectionFileDescriptorPosix.h" -#include "lldb/Target/FileAction.h" -#include "lldb/Target/ProcessLaunchInfo.h" #include "lldb/Target/UnixSignals.h" #include "lldb/Utility/DataBufferLLVM.h" #include "lldb/Utility/FileSpec.h" Index: lldb/trunk/source/Host/common/MonitoringProcessLauncher.cpp =================================================================== --- lldb/trunk/source/Host/common/MonitoringProcessLauncher.cpp +++ lldb/trunk/source/Host/common/MonitoringProcessLauncher.cpp @@ -9,7 +9,7 @@ #include "lldb/Host/MonitoringProcessLauncher.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/HostProcess.h" -#include "lldb/Target/ProcessLaunchInfo.h" +#include "lldb/Host/ProcessLaunchInfo.h" #include "lldb/Utility/Log.h" #include "llvm/Support/FileSystem.h" Index: lldb/trunk/source/Host/common/ProcessInfo.cpp =================================================================== --- lldb/trunk/source/Host/common/ProcessInfo.cpp +++ lldb/trunk/source/Host/common/ProcessInfo.cpp @@ -0,0 +1,113 @@ +//===-- ProcessInfo.cpp -----------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "lldb/Host/ProcessInfo.h" + +#include + +#include "lldb/Host/PosixApi.h" +#include "lldb/Utility/Stream.h" + +#include "llvm/ADT/SmallString.h" + +using namespace lldb; +using namespace lldb_private; + +ProcessInfo::ProcessInfo() + : m_executable(), m_arguments(), m_environment(), m_uid(UINT32_MAX), + m_gid(UINT32_MAX), m_arch(), m_pid(LLDB_INVALID_PROCESS_ID) {} + +ProcessInfo::ProcessInfo(const char *name, const ArchSpec &arch, + lldb::pid_t pid) + : m_executable(name), m_arguments(), m_environment(), m_uid(UINT32_MAX), + m_gid(UINT32_MAX), m_arch(arch), m_pid(pid) {} + +void ProcessInfo::Clear() { + m_executable.Clear(); + m_arguments.Clear(); + m_environment.clear(); + m_uid = UINT32_MAX; + m_gid = UINT32_MAX; + m_arch.Clear(); + m_pid = LLDB_INVALID_PROCESS_ID; +} + +const char *ProcessInfo::GetName() const { + return m_executable.GetFilename().GetCString(); +} + +size_t ProcessInfo::GetNameLength() const { + return m_executable.GetFilename().GetLength(); +} + +void ProcessInfo::Dump(Stream &s, Platform *platform) const { + s << "Executable: " << GetName() << "\n"; + s << "Triple: "; + m_arch.DumpTriple(s); + s << "\n"; + + s << "Arguments:\n"; + m_arguments.Dump(s); + + s.Format("Environment:\n{0}", m_environment); +} + +void ProcessInfo::SetExecutableFile(const FileSpec &exe_file, + bool add_exe_file_as_first_arg) { + if (exe_file) { + m_executable = exe_file; + if (add_exe_file_as_first_arg) { + llvm::SmallString<128> filename; + exe_file.GetPath(filename); + if (!filename.empty()) + m_arguments.InsertArgumentAtIndex(0, filename); + } + } else { + m_executable.Clear(); + } +} + +llvm::StringRef ProcessInfo::GetArg0() const { + return m_arg0; +} + +void ProcessInfo::SetArg0(llvm::StringRef arg) { + m_arg0 = arg; +} + +void ProcessInfo::SetArguments(char const **argv, + bool first_arg_is_executable) { + m_arguments.SetArguments(argv); + + // Is the first argument the executable? + if (first_arg_is_executable) { + const char *first_arg = m_arguments.GetArgumentAtIndex(0); + if (first_arg) { + // Yes the first argument is an executable, set it as the executable in + // the launch options. Don't resolve the file path as the path could be a + // remote platform path + m_executable.SetFile(first_arg, FileSpec::Style::native); + } + } +} + +void ProcessInfo::SetArguments(const Args &args, bool first_arg_is_executable) { + // Copy all arguments + m_arguments = args; + + // Is the first argument the executable? + if (first_arg_is_executable) { + const char *first_arg = m_arguments.GetArgumentAtIndex(0); + if (first_arg) { + // Yes the first argument is an executable, set it as the executable in + // the launch options. Don't resolve the file path as the path could be a + // remote platform path + m_executable.SetFile(first_arg, FileSpec::Style::native); + } + } +} Index: lldb/trunk/source/Host/common/ProcessLaunchInfo.cpp =================================================================== --- lldb/trunk/source/Host/common/ProcessLaunchInfo.cpp +++ lldb/trunk/source/Host/common/ProcessLaunchInfo.cpp @@ -0,0 +1,347 @@ +//===-- ProcessLaunchInfo.cpp -----------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include + +#include "lldb/Host/Config.h" +#include "lldb/Host/FileAction.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Host/HostInfo.h" +#include "lldb/Host/ProcessLaunchInfo.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" + +#include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/FileSystem.h" + +#if !defined(_WIN32) +#include +#endif + +using namespace lldb; +using namespace lldb_private; + +//---------------------------------------------------------------------------- +// ProcessLaunchInfo member functions +//---------------------------------------------------------------------------- + +ProcessLaunchInfo::ProcessLaunchInfo() + : ProcessInfo(), m_working_dir(), m_plugin_name(), m_flags(0), + m_file_actions(), m_pty(new PseudoTerminal), m_resume_count(0), + m_monitor_callback(nullptr), m_monitor_callback_baton(nullptr), + m_monitor_signals(false), m_listener_sp(), m_hijack_listener_sp() {} + +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(), m_flags(launch_flags), + m_file_actions(), m_pty(new PseudoTerminal), m_resume_count(0), + m_monitor_callback(nullptr), m_monitor_callback_baton(nullptr), + m_monitor_signals(false), m_listener_sp(), m_hijack_listener_sp() { + if (stdin_file_spec) { + FileAction file_action; + const bool read = true; + const bool write = false; + if (file_action.Open(STDIN_FILENO, stdin_file_spec, read, write)) + AppendFileAction(file_action); + } + if (stdout_file_spec) { + FileAction file_action; + const bool read = false; + const bool write = true; + if (file_action.Open(STDOUT_FILENO, stdout_file_spec, read, write)) + AppendFileAction(file_action); + } + if (stderr_file_spec) { + FileAction file_action; + const bool read = false; + const bool write = true; + if (file_action.Open(STDERR_FILENO, stderr_file_spec, read, write)) + AppendFileAction(file_action); + } + if (working_directory) + SetWorkingDirectory(working_directory); +} + +bool ProcessLaunchInfo::AppendCloseFileAction(int fd) { + FileAction file_action; + if (file_action.Close(fd)) { + AppendFileAction(file_action); + return true; + } + return false; +} + +bool ProcessLaunchInfo::AppendDuplicateFileAction(int fd, int dup_fd) { + FileAction file_action; + if (file_action.Duplicate(fd, dup_fd)) { + AppendFileAction(file_action); + return true; + } + return false; +} + +bool ProcessLaunchInfo::AppendOpenFileAction(int fd, const FileSpec &file_spec, + bool read, bool write) { + FileAction file_action; + if (file_action.Open(fd, file_spec, read, write)) { + AppendFileAction(file_action); + return true; + } + return false; +} + +bool ProcessLaunchInfo::AppendSuppressFileAction(int fd, bool read, + bool write) { + FileAction file_action; + if (file_action.Open(fd, FileSpec(FileSystem::DEV_NULL), read, write)) { + AppendFileAction(file_action); + return true; + } + return false; +} + +const FileAction *ProcessLaunchInfo::GetFileActionAtIndex(size_t idx) const { + if (idx < m_file_actions.size()) + return &m_file_actions[idx]; + return nullptr; +} + +const FileAction *ProcessLaunchInfo::GetFileActionForFD(int fd) const { + for (size_t idx = 0, count = m_file_actions.size(); idx < count; ++idx) { + if (m_file_actions[idx].GetFD() == fd) + return &m_file_actions[idx]; + } + return nullptr; +} + +const FileSpec &ProcessLaunchInfo::GetWorkingDirectory() const { + return m_working_dir; +} + +void ProcessLaunchInfo::SetWorkingDirectory(const FileSpec &working_dir) { + m_working_dir = working_dir; +} + +const char *ProcessLaunchInfo::GetProcessPluginName() const { + return (m_plugin_name.empty() ? nullptr : m_plugin_name.c_str()); +} + +void ProcessLaunchInfo::SetProcessPluginName(llvm::StringRef plugin) { + m_plugin_name = plugin; +} + +const FileSpec &ProcessLaunchInfo::GetShell() const { return m_shell; } + +void ProcessLaunchInfo::SetShell(const FileSpec &shell) { + m_shell = shell; + if (m_shell) { + FileSystem::Instance().ResolveExecutableLocation(m_shell); + m_flags.Set(lldb::eLaunchFlagLaunchInShell); + } else + m_flags.Clear(lldb::eLaunchFlagLaunchInShell); +} + +void ProcessLaunchInfo::SetLaunchInSeparateProcessGroup(bool separate) { + if (separate) + m_flags.Set(lldb::eLaunchFlagLaunchInSeparateProcessGroup); + else + m_flags.Clear(lldb::eLaunchFlagLaunchInSeparateProcessGroup); +} + +void ProcessLaunchInfo::SetShellExpandArguments(bool expand) { + if (expand) + m_flags.Set(lldb::eLaunchFlagShellExpandArguments); + else + m_flags.Clear(lldb::eLaunchFlagShellExpandArguments); +} + +void ProcessLaunchInfo::Clear() { + ProcessInfo::Clear(); + m_working_dir.Clear(); + m_plugin_name.clear(); + m_shell.Clear(); + m_flags.Clear(); + m_file_actions.clear(); + m_resume_count = 0; + m_listener_sp.reset(); + m_hijack_listener_sp.reset(); +} + +void ProcessLaunchInfo::SetMonitorProcessCallback( + const Host::MonitorChildProcessCallback &callback, bool monitor_signals) { + m_monitor_callback = callback; + m_monitor_signals = monitor_signals; +} + +bool ProcessLaunchInfo::NoOpMonitorCallback(lldb::pid_t pid, bool exited, int signal, int status) { + Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS); + LLDB_LOG(log, "pid = {0}, exited = {1}, signal = {2}, status = {3}", pid, + exited, signal, status); + return true; +} + +bool ProcessLaunchInfo::MonitorProcess() const { + if (m_monitor_callback && ProcessIDIsValid()) { + Host::StartMonitoringChildProcess(m_monitor_callback, GetProcessID(), + m_monitor_signals); + return true; + } + return false; +} + +void ProcessLaunchInfo::SetDetachOnError(bool enable) { + if (enable) + m_flags.Set(lldb::eLaunchFlagDetachOnError); + else + m_flags.Clear(lldb::eLaunchFlagDetachOnError); +} + +llvm::Error ProcessLaunchInfo::SetUpPtyRedirection() { + Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS); + LLDB_LOG(log, "Generating a pty to use for stdin/out/err"); + + int open_flags = O_RDWR | O_NOCTTY; +#if !defined(_WIN32) + // We really shouldn't be specifying platform specific flags that are + // intended for a system call in generic code. But this will have to + // do for now. + open_flags |= O_CLOEXEC; +#endif + if (!m_pty->OpenFirstAvailableMaster(open_flags, nullptr, 0)) { + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "PTY::OpenFirstAvailableMaster failed"); + } + const FileSpec slave_file_spec(m_pty->GetSlaveName(nullptr, 0)); + + // Only use the slave tty if we don't have anything specified for + // input and don't have an action for stdin + if (GetFileActionForFD(STDIN_FILENO) == nullptr) + AppendOpenFileAction(STDIN_FILENO, slave_file_spec, true, false); + + // Only use the slave tty if we don't have anything specified for + // output and don't have an action for stdout + if (GetFileActionForFD(STDOUT_FILENO) == nullptr) + AppendOpenFileAction(STDOUT_FILENO, slave_file_spec, false, true); + + // Only use the slave tty if we don't have anything specified for + // error and don't have an action for stderr + if (GetFileActionForFD(STDERR_FILENO) == nullptr) + AppendOpenFileAction(STDERR_FILENO, slave_file_spec, false, true); + return llvm::Error::success(); +} + +bool ProcessLaunchInfo::ConvertArgumentsForLaunchingInShell( + Status &error, bool localhost, bool will_debug, + bool first_arg_is_full_shell_command, int32_t num_resumes) { + error.Clear(); + + if (GetFlags().Test(eLaunchFlagLaunchInShell)) { + if (m_shell) { + std::string shell_executable = m_shell.GetPath(); + + const char **argv = GetArguments().GetConstArgumentVector(); + if (argv == nullptr || argv[0] == nullptr) + return false; + Args shell_arguments; + std::string safe_arg; + shell_arguments.AppendArgument(shell_executable); + const llvm::Triple &triple = GetArchitecture().GetTriple(); + if (triple.getOS() == llvm::Triple::Win32 && + !triple.isWindowsCygwinEnvironment()) + shell_arguments.AppendArgument(llvm::StringRef("/C")); + else + shell_arguments.AppendArgument(llvm::StringRef("-c")); + + StreamString shell_command; + if (will_debug) { + // Add a modified PATH environment variable in case argv[0] is a + // relative path. + const char *argv0 = argv[0]; + FileSpec arg_spec(argv0); + if (arg_spec.IsRelative()) { + // 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") + 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) { + new_path += working_dir.GetPath(); + } else { + llvm::SmallString<64> cwd; + if (! llvm::sys::fs::current_path(cwd)) + new_path += cwd; + } + std::string curr_path; + if (HostInfo::GetEnvironmentVar("PATH", curr_path)) { + if (new_path.size() > empty_path_len) + new_path += ':'; + new_path += curr_path; + } + new_path += "\" "; + shell_command.PutCString(new_path); + } + + if (triple.getOS() != llvm::Triple::Win32 || + triple.isWindowsCygwinEnvironment()) + shell_command.PutCString("exec"); + + // Only Apple supports /usr/bin/arch being able to specify the + // architecture + if (GetArchitecture().IsValid() && // Valid architecture + GetArchitecture().GetTriple().getVendor() == + llvm::Triple::Apple && // Apple only + GetArchitecture().GetCore() != + ArchSpec::eCore_x86_64_x86_64h) // Don't do this for x86_64h + { + shell_command.Printf(" /usr/bin/arch -arch %s", + GetArchitecture().GetArchitectureName()); + // Set the resume count to 2: + // 1 - stop in shell + // 2 - stop in /usr/bin/arch + // 3 - then we will stop in our program + SetResumeCount(num_resumes + 1); + } else { + // Set the resume count to 1: + // 1 - stop in shell + // 2 - then we will stop in our program + SetResumeCount(num_resumes); + } + } + + if (first_arg_is_full_shell_command) { + // There should only be one argument that is the shell command itself + // to be used as is + if (argv[0] && !argv[1]) + shell_command.Printf("%s", argv[0]); + else + return false; + } else { + for (size_t i = 0; argv[i] != nullptr; ++i) { + const char *arg = + Args::GetShellSafeArgument(m_shell, argv[i], safe_arg); + shell_command.Printf(" %s", arg); + } + } + shell_arguments.AppendArgument(shell_command.GetString()); + m_executable = m_shell; + m_arguments = shell_arguments; + return true; + } else { + error.SetErrorString("invalid shell path"); + } + } else { + error.SetErrorString("not launching in shell"); + } + return false; +} Index: lldb/trunk/source/Host/macosx/objcxx/Host.mm =================================================================== --- lldb/trunk/source/Host/macosx/objcxx/Host.mm +++ lldb/trunk/source/Host/macosx/objcxx/Host.mm @@ -56,9 +56,9 @@ #include "lldb/Host/ConnectionFileDescriptor.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/HostInfo.h" +#include "lldb/Host/ProcessLaunchInfo.h" #include "lldb/Host/ThreadLauncher.h" #include "lldb/Target/Process.h" -#include "lldb/Target/ProcessLaunchInfo.h" #include "lldb/Utility/ArchSpec.h" #include "lldb/Utility/CleanUp.h" #include "lldb/Utility/DataBufferHeap.h" Index: lldb/trunk/source/Host/posix/ProcessLauncherPosixFork.cpp =================================================================== --- lldb/trunk/source/Host/posix/ProcessLauncherPosixFork.cpp +++ lldb/trunk/source/Host/posix/ProcessLauncherPosixFork.cpp @@ -10,7 +10,7 @@ #include "lldb/Host/Host.h" #include "lldb/Host/HostProcess.h" #include "lldb/Host/Pipe.h" -#include "lldb/Target/ProcessLaunchInfo.h" +#include "lldb/Host/ProcessLaunchInfo.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/Log.h" #include "llvm/Support/Errno.h" Index: lldb/trunk/source/Host/windows/ProcessLauncherWindows.cpp =================================================================== --- lldb/trunk/source/Host/windows/ProcessLauncherWindows.cpp +++ lldb/trunk/source/Host/windows/ProcessLauncherWindows.cpp @@ -8,7 +8,7 @@ #include "lldb/Host/windows/ProcessLauncherWindows.h" #include "lldb/Host/HostProcess.h" -#include "lldb/Target/ProcessLaunchInfo.h" +#include "lldb/Host/ProcessLaunchInfo.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/ConvertUTF.h" Index: lldb/trunk/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm +++ lldb/trunk/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm @@ -16,7 +16,7 @@ #include // Project includes #include "lldb/Host/PseudoTerminal.h" -#include "lldb/Target/FileAction.h" +#include "lldb/Host/FileAction.h" #include "llvm/ADT/StringRef.h" Index: lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -8,7 +8,6 @@ #include "PlatformPOSIX.h" - #include "lldb/Core/Debugger.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" @@ -22,11 +21,11 @@ #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" +#include "lldb/Host/ProcessLaunchInfo.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Target/DynamicLoader.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Process.h" -#include "lldb/Target/ProcessLaunchInfo.h" #include "lldb/Target/Thread.h" #include "lldb/Utility/CleanUp.h" #include "lldb/Utility/DataBufferHeap.h" Index: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp =================================================================== --- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -23,6 +23,7 @@ #include "lldb/Core/ModuleSpec.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostProcess.h" +#include "lldb/Host/ProcessLaunchInfo.h" #include "lldb/Host/PseudoTerminal.h" #include "lldb/Host/ThreadLauncher.h" #include "lldb/Host/common/NativeRegisterContext.h" @@ -31,7 +32,6 @@ #include "lldb/Host/posix/ProcessLauncherPosixFork.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Target/Process.h" -#include "lldb/Target/ProcessLaunchInfo.h" #include "lldb/Target/Target.h" #include "lldb/Utility/LLDBAssert.h" #include "lldb/Utility/RegisterValue.h" Index: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp =================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -21,13 +21,13 @@ #include "lldb/Core/ModuleSpec.h" #include "lldb/Host/Config.h" #include "lldb/Host/File.h" +#include "lldb/Host/FileAction.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" #include "lldb/Host/SafeMachO.h" #include "lldb/Interpreter/OptionArgParser.h" #include "lldb/Symbol/ObjectFile.h" -#include "lldb/Target/FileAction.h" #include "lldb/Target/Platform.h" #include "lldb/Target/Process.h" #include "lldb/Utility/Endian.h" Index: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp =================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -20,6 +20,7 @@ #include "lldb/Host/ConnectionFileDescriptor.h" #include "lldb/Host/Debug.h" #include "lldb/Host/File.h" +#include "lldb/Host/FileAction.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" @@ -27,7 +28,6 @@ #include "lldb/Host/common/NativeProcessProtocol.h" #include "lldb/Host/common/NativeRegisterContext.h" #include "lldb/Host/common/NativeThreadProtocol.h" -#include "lldb/Target/FileAction.h" #include "lldb/Target/MemoryRegionInfo.h" #include "lldb/Utility/Args.h" #include "lldb/Utility/DataBuffer.h" Index: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp =================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp @@ -21,9 +21,9 @@ #include "lldb/Host/Config.h" #include "lldb/Host/ConnectionFileDescriptor.h" +#include "lldb/Host/FileAction.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" -#include "lldb/Target/FileAction.h" #include "lldb/Target/Platform.h" #include "lldb/Target/Process.h" #include "lldb/Target/UnixSignals.h" Index: lldb/trunk/source/Target/CMakeLists.txt =================================================================== --- lldb/trunk/source/Target/CMakeLists.txt +++ lldb/trunk/source/Target/CMakeLists.txt @@ -2,7 +2,6 @@ ABI.cpp CPPLanguageRuntime.cpp ExecutionContext.cpp - FileAction.cpp JITLoader.cpp JITLoaderList.cpp InstrumentationRuntime.cpp @@ -17,8 +16,6 @@ PathMappingList.cpp Platform.cpp Process.cpp - ProcessInfo.cpp - ProcessLaunchInfo.cpp Queue.cpp QueueItem.cpp QueueList.cpp Index: lldb/trunk/source/Target/FileAction.cpp =================================================================== --- lldb/trunk/source/Target/FileAction.cpp +++ lldb/trunk/source/Target/FileAction.cpp @@ -1,90 +0,0 @@ -//===-- FileAction.cpp ------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include - -#include "lldb/Host/PosixApi.h" -#include "lldb/Target/FileAction.h" -#include "lldb/Utility/Stream.h" - -using namespace lldb_private; - -//---------------------------------------------------------------------------- -// FileAction member functions -//---------------------------------------------------------------------------- - -FileAction::FileAction() - : m_action(eFileActionNone), m_fd(-1), m_arg(-1), m_file_spec() {} - -void FileAction::Clear() { - m_action = eFileActionNone; - m_fd = -1; - m_arg = -1; - m_file_spec.Clear(); -} - -llvm::StringRef FileAction::GetPath() const { return m_file_spec.GetCString(); } - -const FileSpec &FileAction::GetFileSpec() const { return m_file_spec; } - -bool FileAction::Open(int fd, const FileSpec &file_spec, bool read, - bool write) { - if ((read || write) && fd >= 0 && file_spec) { - m_action = eFileActionOpen; - m_fd = fd; - if (read && write) - m_arg = O_NOCTTY | O_CREAT | O_RDWR; - else if (read) - m_arg = O_NOCTTY | O_RDONLY; - else - m_arg = O_NOCTTY | O_CREAT | O_WRONLY; - m_file_spec = file_spec; - return true; - } else { - Clear(); - } - return false; -} - -bool FileAction::Close(int fd) { - Clear(); - if (fd >= 0) { - m_action = eFileActionClose; - m_fd = fd; - } - return m_fd >= 0; -} - -bool FileAction::Duplicate(int fd, int dup_fd) { - Clear(); - if (fd >= 0 && dup_fd >= 0) { - m_action = eFileActionDuplicate; - m_fd = fd; - m_arg = dup_fd; - } - return m_fd >= 0; -} - -void FileAction::Dump(Stream &stream) const { - stream.PutCString("file action: "); - switch (m_action) { - case eFileActionClose: - stream.Printf("close fd %d", m_fd); - break; - case eFileActionDuplicate: - stream.Printf("duplicate fd %d to %d", m_fd, m_arg); - break; - case eFileActionNone: - stream.PutCString("no action"); - break; - case eFileActionOpen: - stream.Printf("open fd %d with '%s', OFLAGS = 0x%x", m_fd, - m_file_spec.GetCString(), m_arg); - break; - } -} Index: lldb/trunk/source/Target/ProcessInfo.cpp =================================================================== --- lldb/trunk/source/Target/ProcessInfo.cpp +++ lldb/trunk/source/Target/ProcessInfo.cpp @@ -1,113 +0,0 @@ -//===-- ProcessInfo.cpp -----------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "lldb/Target/ProcessInfo.h" - -#include - -#include "lldb/Host/PosixApi.h" -#include "lldb/Utility/Stream.h" - -#include "llvm/ADT/SmallString.h" - -using namespace lldb; -using namespace lldb_private; - -ProcessInfo::ProcessInfo() - : m_executable(), m_arguments(), m_environment(), m_uid(UINT32_MAX), - m_gid(UINT32_MAX), m_arch(), m_pid(LLDB_INVALID_PROCESS_ID) {} - -ProcessInfo::ProcessInfo(const char *name, const ArchSpec &arch, - lldb::pid_t pid) - : m_executable(name), m_arguments(), m_environment(), m_uid(UINT32_MAX), - m_gid(UINT32_MAX), m_arch(arch), m_pid(pid) {} - -void ProcessInfo::Clear() { - m_executable.Clear(); - m_arguments.Clear(); - m_environment.clear(); - m_uid = UINT32_MAX; - m_gid = UINT32_MAX; - m_arch.Clear(); - m_pid = LLDB_INVALID_PROCESS_ID; -} - -const char *ProcessInfo::GetName() const { - return m_executable.GetFilename().GetCString(); -} - -size_t ProcessInfo::GetNameLength() const { - return m_executable.GetFilename().GetLength(); -} - -void ProcessInfo::Dump(Stream &s, Platform *platform) const { - s << "Executable: " << GetName() << "\n"; - s << "Triple: "; - m_arch.DumpTriple(s); - s << "\n"; - - s << "Arguments:\n"; - m_arguments.Dump(s); - - s.Format("Environment:\n{0}", m_environment); -} - -void ProcessInfo::SetExecutableFile(const FileSpec &exe_file, - bool add_exe_file_as_first_arg) { - if (exe_file) { - m_executable = exe_file; - if (add_exe_file_as_first_arg) { - llvm::SmallString<128> filename; - exe_file.GetPath(filename); - if (!filename.empty()) - m_arguments.InsertArgumentAtIndex(0, filename); - } - } else { - m_executable.Clear(); - } -} - -llvm::StringRef ProcessInfo::GetArg0() const { - return m_arg0; -} - -void ProcessInfo::SetArg0(llvm::StringRef arg) { - m_arg0 = arg; -} - -void ProcessInfo::SetArguments(char const **argv, - bool first_arg_is_executable) { - m_arguments.SetArguments(argv); - - // Is the first argument the executable? - if (first_arg_is_executable) { - const char *first_arg = m_arguments.GetArgumentAtIndex(0); - if (first_arg) { - // Yes the first argument is an executable, set it as the executable in - // the launch options. Don't resolve the file path as the path could be a - // remote platform path - m_executable.SetFile(first_arg, FileSpec::Style::native); - } - } -} - -void ProcessInfo::SetArguments(const Args &args, bool first_arg_is_executable) { - // Copy all arguments - m_arguments = args; - - // Is the first argument the executable? - if (first_arg_is_executable) { - const char *first_arg = m_arguments.GetArgumentAtIndex(0); - if (first_arg) { - // Yes the first argument is an executable, set it as the executable in - // the launch options. Don't resolve the file path as the path could be a - // remote platform path - m_executable.SetFile(first_arg, FileSpec::Style::native); - } - } -} Index: lldb/trunk/source/Target/ProcessLaunchInfo.cpp =================================================================== --- lldb/trunk/source/Target/ProcessLaunchInfo.cpp +++ lldb/trunk/source/Target/ProcessLaunchInfo.cpp @@ -1,347 +0,0 @@ -//===-- ProcessLaunchInfo.cpp -----------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include - -#include "lldb/Host/Config.h" -#include "lldb/Host/FileSystem.h" -#include "lldb/Host/HostInfo.h" -#include "lldb/Target/FileAction.h" -#include "lldb/Target/ProcessLaunchInfo.h" -#include "lldb/Utility/Log.h" -#include "lldb/Utility/StreamString.h" - -#include "llvm/Support/ConvertUTF.h" -#include "llvm/Support/FileSystem.h" - -#if !defined(_WIN32) -#include -#endif - -using namespace lldb; -using namespace lldb_private; - -//---------------------------------------------------------------------------- -// ProcessLaunchInfo member functions -//---------------------------------------------------------------------------- - -ProcessLaunchInfo::ProcessLaunchInfo() - : ProcessInfo(), m_working_dir(), m_plugin_name(), m_flags(0), - m_file_actions(), m_pty(new PseudoTerminal), m_resume_count(0), - m_monitor_callback(nullptr), m_monitor_callback_baton(nullptr), - m_monitor_signals(false), m_listener_sp(), m_hijack_listener_sp() {} - -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(), m_flags(launch_flags), - m_file_actions(), m_pty(new PseudoTerminal), m_resume_count(0), - m_monitor_callback(nullptr), m_monitor_callback_baton(nullptr), - m_monitor_signals(false), m_listener_sp(), m_hijack_listener_sp() { - if (stdin_file_spec) { - FileAction file_action; - const bool read = true; - const bool write = false; - if (file_action.Open(STDIN_FILENO, stdin_file_spec, read, write)) - AppendFileAction(file_action); - } - if (stdout_file_spec) { - FileAction file_action; - const bool read = false; - const bool write = true; - if (file_action.Open(STDOUT_FILENO, stdout_file_spec, read, write)) - AppendFileAction(file_action); - } - if (stderr_file_spec) { - FileAction file_action; - const bool read = false; - const bool write = true; - if (file_action.Open(STDERR_FILENO, stderr_file_spec, read, write)) - AppendFileAction(file_action); - } - if (working_directory) - SetWorkingDirectory(working_directory); -} - -bool ProcessLaunchInfo::AppendCloseFileAction(int fd) { - FileAction file_action; - if (file_action.Close(fd)) { - AppendFileAction(file_action); - return true; - } - return false; -} - -bool ProcessLaunchInfo::AppendDuplicateFileAction(int fd, int dup_fd) { - FileAction file_action; - if (file_action.Duplicate(fd, dup_fd)) { - AppendFileAction(file_action); - return true; - } - return false; -} - -bool ProcessLaunchInfo::AppendOpenFileAction(int fd, const FileSpec &file_spec, - bool read, bool write) { - FileAction file_action; - if (file_action.Open(fd, file_spec, read, write)) { - AppendFileAction(file_action); - return true; - } - return false; -} - -bool ProcessLaunchInfo::AppendSuppressFileAction(int fd, bool read, - bool write) { - FileAction file_action; - if (file_action.Open(fd, FileSpec(FileSystem::DEV_NULL), read, write)) { - AppendFileAction(file_action); - return true; - } - return false; -} - -const FileAction *ProcessLaunchInfo::GetFileActionAtIndex(size_t idx) const { - if (idx < m_file_actions.size()) - return &m_file_actions[idx]; - return nullptr; -} - -const FileAction *ProcessLaunchInfo::GetFileActionForFD(int fd) const { - for (size_t idx = 0, count = m_file_actions.size(); idx < count; ++idx) { - if (m_file_actions[idx].GetFD() == fd) - return &m_file_actions[idx]; - } - return nullptr; -} - -const FileSpec &ProcessLaunchInfo::GetWorkingDirectory() const { - return m_working_dir; -} - -void ProcessLaunchInfo::SetWorkingDirectory(const FileSpec &working_dir) { - m_working_dir = working_dir; -} - -const char *ProcessLaunchInfo::GetProcessPluginName() const { - return (m_plugin_name.empty() ? nullptr : m_plugin_name.c_str()); -} - -void ProcessLaunchInfo::SetProcessPluginName(llvm::StringRef plugin) { - m_plugin_name = plugin; -} - -const FileSpec &ProcessLaunchInfo::GetShell() const { return m_shell; } - -void ProcessLaunchInfo::SetShell(const FileSpec &shell) { - m_shell = shell; - if (m_shell) { - FileSystem::Instance().ResolveExecutableLocation(m_shell); - m_flags.Set(lldb::eLaunchFlagLaunchInShell); - } else - m_flags.Clear(lldb::eLaunchFlagLaunchInShell); -} - -void ProcessLaunchInfo::SetLaunchInSeparateProcessGroup(bool separate) { - if (separate) - m_flags.Set(lldb::eLaunchFlagLaunchInSeparateProcessGroup); - else - m_flags.Clear(lldb::eLaunchFlagLaunchInSeparateProcessGroup); -} - -void ProcessLaunchInfo::SetShellExpandArguments(bool expand) { - if (expand) - m_flags.Set(lldb::eLaunchFlagShellExpandArguments); - else - m_flags.Clear(lldb::eLaunchFlagShellExpandArguments); -} - -void ProcessLaunchInfo::Clear() { - ProcessInfo::Clear(); - m_working_dir.Clear(); - m_plugin_name.clear(); - m_shell.Clear(); - m_flags.Clear(); - m_file_actions.clear(); - m_resume_count = 0; - m_listener_sp.reset(); - m_hijack_listener_sp.reset(); -} - -void ProcessLaunchInfo::SetMonitorProcessCallback( - const Host::MonitorChildProcessCallback &callback, bool monitor_signals) { - m_monitor_callback = callback; - m_monitor_signals = monitor_signals; -} - -bool ProcessLaunchInfo::NoOpMonitorCallback(lldb::pid_t pid, bool exited, int signal, int status) { - Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS); - LLDB_LOG(log, "pid = {0}, exited = {1}, signal = {2}, status = {3}", pid, - exited, signal, status); - return true; -} - -bool ProcessLaunchInfo::MonitorProcess() const { - if (m_monitor_callback && ProcessIDIsValid()) { - Host::StartMonitoringChildProcess(m_monitor_callback, GetProcessID(), - m_monitor_signals); - return true; - } - return false; -} - -void ProcessLaunchInfo::SetDetachOnError(bool enable) { - if (enable) - m_flags.Set(lldb::eLaunchFlagDetachOnError); - else - m_flags.Clear(lldb::eLaunchFlagDetachOnError); -} - -llvm::Error ProcessLaunchInfo::SetUpPtyRedirection() { - Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS); - LLDB_LOG(log, "Generating a pty to use for stdin/out/err"); - - int open_flags = O_RDWR | O_NOCTTY; -#if !defined(_WIN32) - // We really shouldn't be specifying platform specific flags that are - // intended for a system call in generic code. But this will have to - // do for now. - open_flags |= O_CLOEXEC; -#endif - if (!m_pty->OpenFirstAvailableMaster(open_flags, nullptr, 0)) { - return llvm::createStringError(llvm::inconvertibleErrorCode(), - "PTY::OpenFirstAvailableMaster failed"); - } - const FileSpec slave_file_spec(m_pty->GetSlaveName(nullptr, 0)); - - // Only use the slave tty if we don't have anything specified for - // input and don't have an action for stdin - if (GetFileActionForFD(STDIN_FILENO) == nullptr) - AppendOpenFileAction(STDIN_FILENO, slave_file_spec, true, false); - - // Only use the slave tty if we don't have anything specified for - // output and don't have an action for stdout - if (GetFileActionForFD(STDOUT_FILENO) == nullptr) - AppendOpenFileAction(STDOUT_FILENO, slave_file_spec, false, true); - - // Only use the slave tty if we don't have anything specified for - // error and don't have an action for stderr - if (GetFileActionForFD(STDERR_FILENO) == nullptr) - AppendOpenFileAction(STDERR_FILENO, slave_file_spec, false, true); - return llvm::Error::success(); -} - -bool ProcessLaunchInfo::ConvertArgumentsForLaunchingInShell( - Status &error, bool localhost, bool will_debug, - bool first_arg_is_full_shell_command, int32_t num_resumes) { - error.Clear(); - - if (GetFlags().Test(eLaunchFlagLaunchInShell)) { - if (m_shell) { - std::string shell_executable = m_shell.GetPath(); - - const char **argv = GetArguments().GetConstArgumentVector(); - if (argv == nullptr || argv[0] == nullptr) - return false; - Args shell_arguments; - std::string safe_arg; - shell_arguments.AppendArgument(shell_executable); - const llvm::Triple &triple = GetArchitecture().GetTriple(); - if (triple.getOS() == llvm::Triple::Win32 && - !triple.isWindowsCygwinEnvironment()) - shell_arguments.AppendArgument(llvm::StringRef("/C")); - else - shell_arguments.AppendArgument(llvm::StringRef("-c")); - - StreamString shell_command; - if (will_debug) { - // Add a modified PATH environment variable in case argv[0] is a - // relative path. - const char *argv0 = argv[0]; - FileSpec arg_spec(argv0); - if (arg_spec.IsRelative()) { - // 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") - 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) { - new_path += working_dir.GetPath(); - } else { - llvm::SmallString<64> cwd; - if (! llvm::sys::fs::current_path(cwd)) - new_path += cwd; - } - std::string curr_path; - if (HostInfo::GetEnvironmentVar("PATH", curr_path)) { - if (new_path.size() > empty_path_len) - new_path += ':'; - new_path += curr_path; - } - new_path += "\" "; - shell_command.PutCString(new_path); - } - - if (triple.getOS() != llvm::Triple::Win32 || - triple.isWindowsCygwinEnvironment()) - shell_command.PutCString("exec"); - - // Only Apple supports /usr/bin/arch being able to specify the - // architecture - if (GetArchitecture().IsValid() && // Valid architecture - GetArchitecture().GetTriple().getVendor() == - llvm::Triple::Apple && // Apple only - GetArchitecture().GetCore() != - ArchSpec::eCore_x86_64_x86_64h) // Don't do this for x86_64h - { - shell_command.Printf(" /usr/bin/arch -arch %s", - GetArchitecture().GetArchitectureName()); - // Set the resume count to 2: - // 1 - stop in shell - // 2 - stop in /usr/bin/arch - // 3 - then we will stop in our program - SetResumeCount(num_resumes + 1); - } else { - // Set the resume count to 1: - // 1 - stop in shell - // 2 - then we will stop in our program - SetResumeCount(num_resumes); - } - } - - if (first_arg_is_full_shell_command) { - // There should only be one argument that is the shell command itself - // to be used as is - if (argv[0] && !argv[1]) - shell_command.Printf("%s", argv[0]); - else - return false; - } else { - for (size_t i = 0; argv[i] != nullptr; ++i) { - const char *arg = - Args::GetShellSafeArgument(m_shell, argv[i], safe_arg); - shell_command.Printf(" %s", arg); - } - } - shell_arguments.AppendArgument(shell_command.GetString()); - m_executable = m_shell; - m_arguments = shell_arguments; - return true; - } else { - error.SetErrorString("invalid shell path"); - } - } else { - error.SetErrorString("not launching in shell"); - } - return false; -} Index: lldb/trunk/unittests/Host/CMakeLists.txt =================================================================== --- lldb/trunk/unittests/Host/CMakeLists.txt +++ lldb/trunk/unittests/Host/CMakeLists.txt @@ -1,9 +1,12 @@ set (FILES + FileActionTest.cpp FileSystemTest.cpp HostInfoTest.cpp HostTest.cpp MainLoopTest.cpp NativeProcessProtocolTest.cpp + ProcessInfoTest.cpp + ProcessLaunchInfoTest.cpp SocketAddressTest.cpp SocketTest.cpp SymbolsTest.cpp Index: lldb/trunk/unittests/Host/FileActionTest.cpp =================================================================== --- lldb/trunk/unittests/Host/FileActionTest.cpp +++ lldb/trunk/unittests/Host/FileActionTest.cpp @@ -0,0 +1,20 @@ +//===-- FileActionTest.cpp --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Host/FileAction.h" +#include "gtest/gtest.h" + +using namespace lldb_private; + +TEST(FileActionTest, Open) { + FileAction Action; + Action.Open(47, FileSpec("/tmp"), /*read*/ true, /*write*/ false); + EXPECT_EQ(Action.GetAction(), FileAction::eFileActionOpen); + EXPECT_EQ(Action.GetFileSpec(), FileSpec("/tmp")); +} Index: lldb/trunk/unittests/Host/ProcessInfoTest.cpp =================================================================== --- lldb/trunk/unittests/Host/ProcessInfoTest.cpp +++ lldb/trunk/unittests/Host/ProcessInfoTest.cpp @@ -0,0 +1,20 @@ +//===-- ProcessInfoTest.cpp -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Host/ProcessInfo.h" +#include "gtest/gtest.h" + +using namespace lldb_private; + +TEST(ProcessInfoTest, Constructor) { + ProcessInfo Info("foo", ArchSpec("x86_64-pc-linux"), 47); + EXPECT_STREQ("foo", Info.GetName()); + EXPECT_EQ(ArchSpec("x86_64-pc-linux"), Info.GetArchitecture()); + EXPECT_EQ(47, Info.GetProcessID()); +} Index: lldb/trunk/unittests/Host/ProcessLaunchInfoTest.cpp =================================================================== --- lldb/trunk/unittests/Host/ProcessLaunchInfoTest.cpp +++ lldb/trunk/unittests/Host/ProcessLaunchInfoTest.cpp @@ -0,0 +1,28 @@ +//===-- ProcessLaunchInfoTest.cpp -------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Host/ProcessLaunchInfo.h" +#include "gtest/gtest.h" + +using namespace lldb_private; +using namespace lldb; + +TEST(ProcessLaunchInfoTest, Constructor) { + ProcessLaunchInfo Info(FileSpec("/stdin"), FileSpec("/stdout"), + FileSpec("/stderr"), FileSpec("/wd"), + eLaunchFlagStopAtEntry); + EXPECT_EQ(FileSpec("/stdin"), + Info.GetFileActionForFD(STDIN_FILENO)->GetFileSpec()); + EXPECT_EQ(FileSpec("/stdout"), + Info.GetFileActionForFD(STDOUT_FILENO)->GetFileSpec()); + EXPECT_EQ(FileSpec("/stderr"), + Info.GetFileActionForFD(STDERR_FILENO)->GetFileSpec()); + EXPECT_EQ(FileSpec("/wd"), Info.GetWorkingDirectory()); + EXPECT_EQ(eLaunchFlagStopAtEntry, Info.GetFlags().Get()); +} Index: lldb/trunk/unittests/tools/lldb-server/tests/TestClient.h =================================================================== --- lldb/trunk/unittests/tools/lldb-server/tests/TestClient.h +++ lldb/trunk/unittests/tools/lldb-server/tests/TestClient.h @@ -11,7 +11,7 @@ #include "MessageObjects.h" #include "Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h" -#include "lldb/Target/ProcessLaunchInfo.h" +#include "lldb/Host/ProcessLaunchInfo.h" #include "lldb/Utility/ArchSpec.h" #include "lldb/Utility/Connection.h" #include "llvm/ADT/Optional.h" Index: lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp =================================================================== --- lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp +++ lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp @@ -10,7 +10,6 @@ #include "lldb/Host/HostInfo.h" #include "lldb/Host/common/TCPSocket.h" #include "lldb/Host/posix/ConnectionFileDescriptorPosix.h" -#include "lldb/Target/ProcessLaunchInfo.h" #include "lldb/Utility/Args.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/Path.h"