Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add -no-redirect command line argument to prevent redirecting stdin a…

…nd stdout.

2009-03-19  Martin Baulig  <martin@ximian.com>

	* classes/DebuggerOptions.cs
	(DebuggerOptions.RedirectOutput): New public property.
	(DebuggerOptions.ParseCommandLine): Added `-no-redirect' command
	line argument to prevent redirecting stdin and stdout.

	* backend/ProcessStart.cs
	(ProcessStart.RedirectOutput): New public property.

	* backend/server/x86-ptrace.c
	(mono_debugger_server_spawn): Added `gboolean redirect_fds'.

svn path=/trunk/debugger/; revision=129751
  • Loading branch information...
commit 6f563d052a51ba3a124e14dad79d9fb8b254f45b 1 parent 2bed204
Martin Baulig authored
View
13 ChangeLog
@@ -1,3 +1,16 @@
+2009-03-19 Martin Baulig <martin@ximian.com>
+
+ * classes/DebuggerOptions.cs
+ (DebuggerOptions.RedirectOutput): New public property.
+ (DebuggerOptions.ParseCommandLine): Added `-no-redirect' command
+ line argument to prevent redirecting stdin and stdout.
+
+ * backend/ProcessStart.cs
+ (ProcessStart.RedirectOutput): New public property.
+
+ * backend/server/x86-ptrace.c
+ (mono_debugger_server_spawn): Added `gboolean redirect_fds'.
+
2009-03-05 Martin Baulig <martin@ximian.com>
* languages/mono/MonoSymbolFile.cs
View
12 backend/Inferior.cs
@@ -65,7 +65,7 @@ internal class Inferior : TargetAccess, ITargetNotification, IDisposable
[DllImport("monodebuggerserver")]
static extern TargetError mono_debugger_server_io_thread_main (IntPtr io_data, ChildOutputHandler output_handler);
[DllImport("monodebuggerserver")]
- static extern TargetError mono_debugger_server_spawn (IntPtr handle, string working_directory, string[] argv, string[] envp, out int child_pid, out IntPtr io_data, out IntPtr error);
+ static extern TargetError mono_debugger_server_spawn (IntPtr handle, string working_directory, string[] argv, string[] envp, bool redirect_fds, out int child_pid, out IntPtr io_data, out IntPtr error);
[DllImport("monodebuggerserver")]
static extern TargetError mono_debugger_server_attach (IntPtr handle, int child_pid);
@@ -609,7 +609,7 @@ public int Run ()
TargetError result = mono_debugger_server_spawn (
server_handle, start.WorkingDirectory, start.CommandLineArguments,
- start.Environment, out child_pid, out io_data, out error);
+ start.Environment, start.RedirectOutput, out child_pid, out io_data, out error);
if (result != TargetError.None) {
string message = Marshal.PtrToStringAuto (error);
g_free (error);
@@ -618,9 +618,11 @@ public int Run ()
TargetError.CannotStartTarget, message);
}
- ST.Thread io_thread = new ST.Thread (new ST.ThreadStart (io_thread_main));
- io_thread.IsBackground = true;
- io_thread.Start ();
+ if (start.RedirectOutput) {
+ ST.Thread io_thread = new ST.Thread (new ST.ThreadStart (io_thread_main));
+ io_thread.IsBackground = true;
+ io_thread.Start ();
+ }
return child_pid;
}
View
6 backend/ProcessStart.cs
@@ -16,6 +16,7 @@ internal sealed class ProcessStart : DebuggerMarshalByRefObject
string cwd;
string base_dir;
bool stop_in_main = true;
+ bool redirect_output = true;
string[] argv;
string[] envp;
DebuggerOptions options;
@@ -80,6 +81,7 @@ internal ProcessStart (DebuggerSession session)
throw new ArgumentException ("InferiorArgs null", "options");
stop_in_main = options.StopInMain;
+ redirect_output = options.RedirectOutput;
cwd = options.WorkingDirectory;
if (cwd == null)
@@ -229,6 +231,10 @@ public void SetupApplication (string exe_file, string cwd, string[] cmdline_args
get { return stop_in_main; }
}
+ public bool RedirectOutput {
+ get { return redirect_output; }
+ }
+
void AddUserEnvironment (Hashtable hash)
{
if (options.UserEnvironment == null)
View
4 backend/SingleSteppingEngine.cs
@@ -1058,6 +1058,8 @@ ExceptionAction throw_exception (TargetAddress stack, TargetAddress exc, TargetA
if (exc_obj == null)
return ExceptionAction.None; // OOOPS
+ Report.Debug (DebugFlags.SSE, "{0} throwing exception: {1}", this, exc_obj.Type.Name);
+
bool stop;
if (process.Client.GenericExceptionCatchPoint (exc_obj.Type.Name, out stop)) {
Report.Debug (DebugFlags.SSE,
@@ -1622,6 +1624,8 @@ internal bool ActivatePendingBreakpoints ()
update_current_frame (main_frame);
}
+ Report.Debug (DebugFlags.SSE, "{0} activate pending breakpoints", this);
+
Queue pending = new Queue ();
foreach (Event e in process.Session.Events) {
Breakpoint breakpoint = e as Breakpoint;
View
6 backend/server/library.c
@@ -51,13 +51,13 @@ mono_debugger_server_io_thread_main (IOThreadData *io_data, ChildOutputFunc func
ServerCommandError
mono_debugger_server_spawn (ServerHandle *handle, const gchar *working_directory,
- const gchar **argv, const gchar **envp, gint *child_pid,
- IOThreadData **io_data, gchar **error)
+ const gchar **argv, const gchar **envp, gboolean redirect_fds,
+ gint *child_pid, IOThreadData **io_data, gchar **error)
{
if (!global_vtable->spawn)
return COMMAND_ERROR_NOT_IMPLEMENTED;
- return (* global_vtable->spawn) (handle, working_directory, argv, envp,
+ return (* global_vtable->spawn) (handle, working_directory, argv, envp, redirect_fds,
child_pid, io_data, error);
}
View
2  backend/server/server.h
@@ -145,6 +145,7 @@ struct InferiorVTable {
const gchar *working_directory,
const gchar **argv,
const gchar **envp,
+ gboolean redirect_fds,
gint *child_pid,
IOThreadData **io_data,
gchar **error);
@@ -431,6 +432,7 @@ mono_debugger_server_spawn (ServerHandle *handle,
const gchar *working_directory,
const gchar **argv,
const gchar **envp,
+ gboolean redirect_fds,
gint *child_pid,
IOThreadData **io_data,
gchar **error);
View
60 backend/server/x86-ptrace.c
@@ -415,36 +415,42 @@ child_setup_func (InferiorHandle *inferior)
if (ptrace (PT_TRACE_ME, getpid (), NULL, 0))
g_error (G_STRLOC ": Can't PT_TRACEME: %s", g_strerror (errno));
- dup2 (inferior->output_fd[1], 1);
- dup2 (inferior->error_fd[1], 2);
+ if (inferior->redirect_fds) {
+ dup2 (inferior->output_fd[1], 1);
+ dup2 (inferior->error_fd[1], 2);
+ }
}
static ServerCommandError
server_ptrace_spawn (ServerHandle *handle, const gchar *working_directory,
- const gchar **argv, const gchar **envp, gint *child_pid,
- IOThreadData **io_data, gchar **error)
+ const gchar **argv, const gchar **envp, gboolean redirect_fds,
+ gint *child_pid, IOThreadData **io_data, gchar **error)
{
InferiorHandle *inferior = handle->inferior;
- int fd[2], open_max, ret, len, i;
+ int fd[2], ret, len, i;
ServerCommandError result;
*error = NULL;
+ inferior->redirect_fds = redirect_fds;
- pipe (fd);
-
- inferior->redirect_fds = TRUE;
+ if (redirect_fds) {
+ pipe (inferior->output_fd);
+ pipe (inferior->error_fd);
- pipe (inferior->output_fd);
- pipe (inferior->error_fd);
+ *io_data = g_new0 (IOThreadData, 1);
+ (*io_data)->output_fd = inferior->output_fd[0];
+ (*io_data)->error_fd = inferior->error_fd[0];
+ } else {
+ *io_data = NULL;
+ }
- *io_data = g_new0 (IOThreadData, 1);
- (*io_data)->output_fd = inferior->output_fd[0];
- (*io_data)->error_fd = inferior->error_fd[0];
+ pipe (fd);
*child_pid = fork ();
if (*child_pid == 0) {
gchar *error_message;
struct rlimit core_limit;
+ int open_max;
open_max = sysconf (_SC_OPEN_MAX);
for (i = 3; i < open_max; i++)
@@ -465,10 +471,12 @@ server_ptrace_spawn (ServerHandle *handle, const gchar *working_directory,
write (fd [1], error_message, len);
_exit (1);
} else if (*child_pid < 0) {
- close (inferior->output_fd[0]);
- close (inferior->output_fd[1]);
- close (inferior->error_fd[0]);
- close (inferior->error_fd[1]);
+ if (redirect_fds) {
+ close (inferior->output_fd[0]);
+ close (inferior->output_fd[1]);
+ close (inferior->error_fd[0]);
+ close (inferior->error_fd[1]);
+ }
close (fd [0]);
close (fd [1]);
@@ -476,8 +484,10 @@ server_ptrace_spawn (ServerHandle *handle, const gchar *working_directory,
return COMMAND_ERROR_CANNOT_START_TARGET;
}
- close (inferior->output_fd[1]);
- close (inferior->error_fd[1]);
+ if (redirect_fds) {
+ close (inferior->output_fd[1]);
+ close (inferior->error_fd[1]);
+ }
close (fd [1]);
ret = read (fd [0], &len, sizeof (len));
@@ -488,8 +498,10 @@ server_ptrace_spawn (ServerHandle *handle, const gchar *working_directory,
*error = g_malloc0 (len);
read (fd [0], *error, len);
close (fd [0]);
- close (inferior->output_fd[0]);
- close (inferior->error_fd[0]);
+ if (redirect_fds) {
+ close (inferior->output_fd[0]);
+ close (inferior->error_fd[0]);
+ }
return COMMAND_ERROR_CANNOT_START_TARGET;
}
@@ -499,8 +511,10 @@ server_ptrace_spawn (ServerHandle *handle, const gchar *working_directory,
result = _server_ptrace_setup_inferior (handle);
if (result != COMMAND_ERROR_NONE) {
- close (inferior->output_fd[0]);
- close (inferior->error_fd[0]);
+ if (redirect_fds) {
+ close (inferior->output_fd[0]);
+ close (inferior->error_fd[0]);
+ }
return result;
}
View
26 classes/DebuggerOptions.cs
@@ -25,6 +25,7 @@ public class DebuggerOptions : DebuggerMarshalByRefObject
DebugFlags? debug_flags;
bool? stop_in_main;
bool? start_target;
+ bool? redirect_output;
/* The executable file we're debugging */
public string File {
@@ -64,6 +65,11 @@ public class DebuggerOptions : DebuggerMarshalByRefObject
get { return start_target ?? false; }
set { start_target = value; }
}
+
+ public bool RedirectOutput {
+ get { return redirect_output ?? true; }
+ set { redirect_output = value; }
+ }
/* the value of the -debug-flags: command line argument */
public DebugFlags DebugFlags {
@@ -136,6 +142,7 @@ public DebuggerOptions Clone ()
options.WorkingDirectory = WorkingDirectory;
options.IsScript = IsScript;
options.start_target = start_target;
+ options.redirect_output = redirect_output;
options.debug_flags = debug_flags;
options.DebugOutput = DebugOutput;
options.MonoPrefix = MonoPrefix;
@@ -281,6 +288,7 @@ static void Usage ()
" -mono-prefix:PATH Override the mono prefix\n" +
" -start Start inferior without halting in Main()\n" +
" -run Start inferior and stop in Main()\n" +
+ " -no-redirect Don't redirect standard output\n" +
" -script \n" +
" -usage \n" +
" -version Display version and licensing information (short -V)\n" +
@@ -288,6 +296,16 @@ static void Usage ()
);
}
+ public static DebuggerOptions CreateXSP (string root)
+ {
+ DebuggerOptions options = new DebuggerOptions ();
+ options.InferiorArgs = new string [0];
+ options.StartXSP = true;
+ options.XSP_Root = root;
+ options.SetupXSP ();
+ return options;
+ }
+
public static DebuggerOptions ParseCommandLine (string[] args)
{
DebuggerOptions options = new DebuggerOptions ();
@@ -507,6 +525,14 @@ void SetupXSP ()
debug_options.StopInMain = true;
return true;
+ case "-no-redirect":
+ if (ms_value != null) {
+ Usage ();
+ Environment.Exit (1);
+ }
+ debug_options.RedirectOutput = false;
+ return true;
+
#if HAVE_XSP
case "-xsp":
value = GetValue (ref args, ref i, ms_value);
Please sign in to comment.
Something went wrong with that request. Please try again.