[Lldb-commits] [lldb] r144922 - in /lldb/trunk: include/lldb/Target/Process.h source/Commands/CommandObjectProcess.cpp source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp source/Target/Platform.cpp source/Target/Process.cpp
Greg Clayton
gclayton at apple.com
Thu Nov 17 14:14:32 PST 2011
Author: gclayton
Date: Thu Nov 17 16:14:31 2011
New Revision: 144922
URL: http://llvm.org/viewvc/llvm-project?rev=144922&view=rev
Log:
Use a pseudoterminal for local processes if no STDIO redirection or other
file actions have been specified.
Modified:
lldb/trunk/include/lldb/Target/Process.h
lldb/trunk/source/Commands/CommandObjectProcess.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/trunk/source/Target/Platform.cpp
lldb/trunk/source/Target/Process.cpp
Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=144922&r1=144921&r2=144922&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Thu Nov 17 16:14:31 2011
@@ -42,6 +42,7 @@
#include "lldb/Target/Memory.h"
#include "lldb/Target/ThreadList.h"
#include "lldb/Target/UnixSignals.h"
+#include "lldb/Utility/PseudoTerminal.h"
namespace lldb_private {
@@ -496,6 +497,7 @@
m_shell (),
m_flags (0),
m_file_actions (),
+ m_pty (),
m_resume_count (0),
m_monitor_callback (NULL),
m_monitor_callback_baton (NULL),
@@ -514,6 +516,7 @@
m_shell (),
m_flags (launch_flags),
m_file_actions (),
+ m_pty (),
m_resume_count (0),
m_monitor_callback (NULL),
m_monitor_callback_baton (NULL),
@@ -602,7 +605,8 @@
}
void
- FinalizeFileActions (Target *target);
+ FinalizeFileActions (Target *target,
+ bool default_to_use_pty);
size_t
GetNumFileActions () const
@@ -756,6 +760,11 @@
return false;
}
+ lldb_utility::PseudoTerminal &
+ GetPTY ()
+ {
+ return m_pty;
+ }
protected:
std::string m_working_dir;
@@ -763,6 +772,7 @@
std::string m_shell;
Flags m_flags; // Bitwise OR of bits from lldb::LaunchFlags
std::vector<FileAction> m_file_actions; // File actions for any other files
+ lldb_utility::PseudoTerminal 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;
@@ -2845,6 +2855,9 @@
lldb::ProcessSP
GetSP ();
+ void
+ SetSTDIOFileDescriptor (int file_descriptor);
+
protected:
//------------------------------------------------------------------
// NextEventAction provides a way to register an action on the next
@@ -3041,9 +3054,6 @@
void
ResetProcessInputReader ();
- void
- SetUpProcessInputReader (int file_descriptor);
-
static size_t
ProcessInputReaderCallback (void *baton,
InputReader &reader,
Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=144922&r1=144921&r2=144922&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Thu Nov 17 16:14:31 2011
@@ -236,7 +236,10 @@
if (environment.GetArgumentCount() > 0)
m_options.launch_info.GetEnvironmentEntries ().AppendArguments (environment);
- m_options.launch_info.FinalizeFileActions (target);
+ // Finalize the file actions, and if none were given, default to opening
+ // up a pseudo terminal
+ const bool default_to_use_pty = true;
+ m_options.launch_info.FinalizeFileActions (target, default_to_use_pty);
if (state == eStateConnected)
{
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=144922&r1=144921&r2=144922&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Thu Nov 17 16:14:31 2011
@@ -593,7 +593,7 @@
if (!disable_stdio)
{
if (pty.GetMasterFileDescriptor() != lldb_utility::PseudoTerminal::invalid_fd)
- SetUpProcessInputReader (pty.ReleaseMasterFileDescriptor());
+ SetSTDIOFileDescriptor (pty.ReleaseMasterFileDescriptor());
}
}
}
Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=144922&r1=144921&r2=144922&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Thu Nov 17 16:14:31 2011
@@ -588,6 +588,16 @@
// 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
+ // so we can read/write stdin/out/err.
+ int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor();
+ if (pty_fd != lldb_utility::PseudoTerminal::invalid_fd)
+ {
+ process_sp->SetSTDIOFileDescriptor(pty_fd);
+ }
}
}
}
Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=144922&r1=144921&r2=144922&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Thu Nov 17 16:14:31 2011
@@ -251,7 +251,7 @@
}
void
-ProcessLaunchInfo::FinalizeFileActions (Target *target)
+ProcessLaunchInfo::FinalizeFileActions (Target *target, bool default_to_use_pty)
{
// If notthing was specified, then check the process for any default
// settings that were set with "settings set"
@@ -270,36 +270,32 @@
// (lldb) settings set target.input-path
// (lldb) settings set target.output-path
// (lldb) settings set target.error-path
+ const char *in_path = NULL;
+ const char *out_path = NULL;
+ const char *err_path = NULL;
if (target)
{
- path = target->GetStandardErrorPath();
- if (path)
- {
- const bool read = true;
- const bool write = true;
- AppendOpenFileAction(STDERR_FILENO, path, read, write);
- }
- path = target->GetStandardInputPath();
- if (path)
- {
- const bool read = true;
- const bool write = false;
- AppendOpenFileAction(STDIN_FILENO, path, read, write);
- }
-
- path = target->GetStandardOutputPath();
- if (path)
+ in_path = target->GetStandardErrorPath();
+ out_path = target->GetStandardInputPath();
+ err_path = target->GetStandardOutputPath();
+ }
+
+ if (default_to_use_pty && (!in_path && !out_path && !err_path))
+ {
+ if (m_pty.OpenFirstAvailableMaster (O_RDWR|O_NOCTTY, NULL, 0))
{
- const bool read = false;
- const bool write = true;
- AppendOpenFileAction(STDOUT_FILENO, path, read, write);
+ in_path = out_path = err_path = m_pty.GetSlaveName (NULL, 0);
}
}
- // If we still don't have any actions...
- if (m_file_actions.empty())
- {
- }
+ if (in_path)
+ AppendOpenFileAction(STDERR_FILENO, in_path, true, true);
+
+ if (out_path)
+ AppendOpenFileAction(STDIN_FILENO, out_path, true, false);
+
+ if (err_path)
+ AppendOpenFileAction(STDOUT_FILENO, err_path, false, true);
}
}
}
@@ -3549,7 +3545,7 @@
}
void
-Process::SetUpProcessInputReader (int file_descriptor)
+Process::SetSTDIOFileDescriptor (int file_descriptor)
{
// First set up the Read Thread for reading/handling process I/O
More information about the lldb-commits
mailing list