Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lldb/include/lldb/Host/ProcessLaunchInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ class ProcessLaunchInfo : public ProcessInfo {

bool MonitorProcess() const;

PseudoTerminal &GetPTY() { return *m_pty; }
PseudoTerminal &GetPTY() const { return *m_pty; }

std::shared_ptr<PseudoTerminal> GetPTYSP() const { return m_pty; }

void SetLaunchEventData(const char *data) { m_event_data.assign(data); }

Expand Down
42 changes: 33 additions & 9 deletions lldb/include/lldb/Host/PseudoTerminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ class PseudoTerminal {

/// Destructor
///
/// The destructor will close the primary and secondary file descriptors if
/// they are valid and ownership has not been released using one of: @li
/// PseudoTerminal::ReleasePrimaryFileDescriptor() @li
/// PseudoTerminal::ReleaseSaveFileDescriptor()
~PseudoTerminal();
/// The destructor will close the primary and secondary file
/// descriptor/HANDLEs if they are valid and ownership has not been released
/// using PseudoTerminal::Close().
virtual ~PseudoTerminal();

/// Close all the file descriptors or Handles of the PseudoTerminal if they
/// are valid.
virtual void Close();

/// Close the primary file descriptor if it is valid.
void ClosePrimaryFileDescriptor();
Expand All @@ -59,8 +62,7 @@ class PseudoTerminal {
///
/// This class will close the file descriptors for the primary/secondary when
/// the destructor is called. The file handles can be released using either:
/// @li PseudoTerminal::ReleasePrimaryFileDescriptor() @li
/// PseudoTerminal::ReleaseSaveFileDescriptor()
/// @li PseudoTerminal::ReleasePrimaryFileDescriptor()
///
/// \return
/// \b Parent process: a child process ID that is greater
Expand All @@ -82,6 +84,16 @@ class PseudoTerminal {
/// \see PseudoTerminal::ReleasePrimaryFileDescriptor()
int GetPrimaryFileDescriptor() const;

/// The primary HANDLE accessor.
///
/// This object retains ownership of the primary HANDLE when this
/// accessor is used.
///
/// \return
/// The primary HANDLE, or INVALID_HANDLE_VALUE if the primary HANDLE is
/// not currently valid.
virtual void *GetPrimaryHandle() const { return ((void *)(long long)-1); };

/// The secondary file descriptor accessor.
///
/// This object retains ownership of the secondary file descriptor when this
Expand All @@ -96,6 +108,8 @@ class PseudoTerminal {
/// \see PseudoTerminal::ReleaseSecondaryFileDescriptor()
int GetSecondaryFileDescriptor() const;

virtual void *GetSecondaryHandle() const { return ((void *)(long long)-1); };

/// Get the name of the secondary pseudo terminal.
///
/// A primary pseudo terminal should already be valid prior to
Expand All @@ -105,7 +119,17 @@ class PseudoTerminal {
/// The name of the secondary pseudo terminal.
///
/// \see PseudoTerminal::OpenFirstAvailablePrimary()
std::string GetSecondaryName() const;
virtual std::string GetSecondaryName() const;

/// The underlying Windows Pseudo Terminal HANDLE's accessor.
///
/// This object retains ownership of the ConPTY's HANDLE when this
/// accessor is used.
///
/// \return
/// The primary HANDLE, or INVALID_HANDLE_VALUE if the primary HANDLE is
/// not currently valid.
virtual void *GetPseudoTerminalHandle() { return ((void *)(long long)-1); };

/// Open the first available pseudo terminal.
///
Expand All @@ -126,7 +150,7 @@ class PseudoTerminal {
///
/// \see PseudoTerminal::GetPrimaryFileDescriptor() @see
/// PseudoTerminal::ReleasePrimaryFileDescriptor()
llvm::Error OpenFirstAvailablePrimary(int oflag);
virtual llvm::Error OpenFirstAvailablePrimary(int oflag);

/// Open the secondary for the current primary pseudo terminal.
///
Expand Down
39 changes: 39 additions & 0 deletions lldb/include/lldb/Host/windows/PseudoTerminalWindows.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
//
// 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_Host_Windows_PseudoTerminalWindows_H_
#define liblldb_Host_Windows_PseudoTerminalWindows_H_

#include "lldb/Host/PseudoTerminal.h"
#include "lldb/Host/windows/windows.h"

namespace lldb_private {

class PseudoTerminalWindows : public PseudoTerminal {

public:
void Close() override;

HPCON GetPseudoTerminalHandle() override { return m_conpty_handle; };

HANDLE GetPrimaryHandle() const override { return m_conpty_output; };

HANDLE GetSecondaryHandle() const override { return m_conpty_input; };

std::string GetSecondaryName() const override { return ""; };

llvm::Error OpenFirstAvailablePrimary(int oflag) override;

protected:
HANDLE m_conpty_handle = INVALID_HANDLE_VALUE;
HANDLE m_conpty_output = INVALID_HANDLE_VALUE;
HANDLE m_conpty_input = INVALID_HANDLE_VALUE;
};
}; // namespace lldb_private

#endif // liblldb_Host_Windows_PseudoTerminalWindows_H_
4 changes: 2 additions & 2 deletions lldb/include/lldb/Host/windows/windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#ifndef LLDB_lldb_windows_h_
#define LLDB_lldb_windows_h_

#define NTDDI_VERSION NTDDI_VISTA
#define NTDDI_VERSION NTDDI_WIN10_RS5
#undef _WIN32_WINNT // undef a previous definition to avoid warning
#define _WIN32_WINNT _WIN32_WINNT_VISTA
#define _WIN32_WINNT _WIN32_WINNT_WIN10
#define WIN32_LEAN_AND_MEAN
#define NOGDI
#undef NOMINMAX // undef a previous definition to avoid warning
Expand Down
9 changes: 9 additions & 0 deletions lldb/include/lldb/Target/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -2558,6 +2558,15 @@ void PruneThreadPlans();
/// \see lldb_private::ConnectionFileDescriptor
void SetSTDIOFileDescriptor(int file_descriptor);

/// Windows equivalent of Process::SetSTDIOFileDescriptor, with a
/// PseudoTerminalWindows instead of a file descriptor.
///
/// \param pty
/// The PseudoTerminal to use for process STDIO communication. It is not
/// managed by the created read thread.
virtual void
SetPseudoTerminalHandle(const std::shared_ptr<PseudoTerminal> &pty) {};

// Add a permanent region of memory that should never be read or written to.
// This can be used to ensure that memory reads or writes to certain areas of
// memory never end up being sent to the DoReadMemory or DoWriteMemory
Expand Down
1 change: 1 addition & 0 deletions lldb/source/Host/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ if (CMAKE_SYSTEM_NAME MATCHES "Windows")
windows/MainLoopWindows.cpp
windows/PipeWindows.cpp
windows/ProcessLauncherWindows.cpp
windows/PseudoTerminalWindows.cpp
windows/ProcessRunLock.cpp
)
else()
Expand Down
19 changes: 16 additions & 3 deletions lldb/source/Host/common/ProcessLaunchInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/FileSystem.h"

#if !defined(_WIN32)
#ifdef _WIN32
#include "lldb/Host/windows/PseudoTerminalWindows.h"
#else
#include <climits>
#endif

Expand All @@ -31,7 +33,12 @@ using namespace lldb_private;

ProcessLaunchInfo::ProcessLaunchInfo()
: ProcessInfo(), m_working_dir(), m_plugin_name(), m_flags(0),
m_file_actions(), m_pty(new PseudoTerminal), m_monitor_callback(nullptr) {
m_file_actions(), m_monitor_callback(nullptr) {
#ifdef _WIN32
m_pty = std::make_shared<PseudoTerminalWindows>();
#else
m_pty = std::make_shared<PseudoTerminal>();
#endif
}

ProcessLaunchInfo::ProcessLaunchInfo(const FileSpec &stdin_file_spec,
Expand All @@ -40,7 +47,13 @@ ProcessLaunchInfo::ProcessLaunchInfo(const FileSpec &stdin_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_file_actions() {
#ifdef _WIN32
m_pty = std::make_shared<PseudoTerminalWindows>();
#else
m_pty = std::make_shared<PseudoTerminal>();
#endif

if (stdin_file_spec) {
FileAction file_action;
const bool read = true;
Expand Down
12 changes: 4 additions & 8 deletions lldb/source/Host/common/PseudoTerminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "lldb/Host/PseudoTerminal.h"
#include "lldb/Host/Config.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/windows/windows.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Errno.h"
#include <cassert>
Expand All @@ -29,16 +30,11 @@

using namespace lldb_private;

// PseudoTerminal constructor
PseudoTerminal::PseudoTerminal() = default;

// Destructor
//
// The destructor will close the primary and secondary file descriptors if they
// are valid and ownership has not been released using the
// ReleasePrimaryFileDescriptor() or the ReleaseSaveFileDescriptor() member
// functions.
PseudoTerminal::~PseudoTerminal() {
PseudoTerminal::~PseudoTerminal() { Close(); }

void PseudoTerminal::Close() {
ClosePrimaryFileDescriptor();
CloseSecondaryFileDescriptor();
}
Expand Down
Loading
Loading