Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
2007-12-08 Martin Baulig <martin@ximian.com>
Browse files Browse the repository at this point in the history
	* configure.in: Bumped version number to 0.60.

2007-12-08  Martin Baulig  <martin@ximian.com>

	Changed default behavior: don't follow fork() by default.

	* classes/DebuggerConfiguration.cs
	(DebuggerConfiguration.FollowFork): Changed default to false.

	* test/testsuite/NUnit.cs
	(NUnitInterpreter.ctor): Override configuration: enable `FollowFork'.

2007-12-08  Martin Baulig  <martin@ximian.com>

	* frontend/Command.cs
	(ConfigCommand): New command.

2007-12-08  Martin Baulig  <martin@ximian.com>

	* backend/Inferior.cs
	(Inferior): Replaced InitializeAfterFork() by DetachAfterFork().

	* backend/SingleSteppingEngine.cs
	(SSE.InitAfterFork): New method.
	(OperationInitializeAfterFork): New operation.  To avoid a race
	condition, we need to wait until the target stopped the first time
	before we can disable the local breakpoints.

	* backend/server/server.h
	(mono_debugger_server_init_after_fork): Renamed info
	mono_debugger_server_detach_after_fork().

	* backend/server/x86-arch.h
	(x86_arch_enable_breakpoint): Add prototype.
	(x86_arch_disable_breakpoint): Add prototype.

	* backend/server/i386-arch.c
	(do_enable): Renamed into x86_arch_enable_breakpoint().
	(do_disable): Renamed into x86_arch_disable_breakpoint().

	* backend/server/x86_64-arch.c
	(do_enable): Renamed into x86_arch_enable_breakpoint().
	(do_disable): Renamed into x86_arch_disable_breakpoint().


svn path=/trunk/debugger/; revision=90993
  • Loading branch information
Martin Baulig committed Dec 8, 2007
1 parent 6b6f250 commit 072acf3
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 86 deletions.
46 changes: 46 additions & 0 deletions ChangeLog
@@ -1,3 +1,49 @@
2007-12-08 Martin Baulig <martin@ximian.com>

* configure.in: Bumped version number to 0.60.

2007-12-08 Martin Baulig <martin@ximian.com>

Changed default behavior: don't follow fork() by default.

* classes/DebuggerConfiguration.cs
(DebuggerConfiguration.FollowFork): Changed default to false.

* test/testsuite/NUnit.cs
(NUnitInterpreter.ctor): Override configuration: enable `FollowFork'.

2007-12-08 Martin Baulig <martin@ximian.com>

* frontend/Command.cs
(ConfigCommand): New command.

2007-12-08 Martin Baulig <martin@ximian.com>

* backend/Inferior.cs
(Inferior): Replaced InitializeAfterFork() by DetachAfterFork().

* backend/SingleSteppingEngine.cs
(SSE.InitAfterFork): New method.
(OperationInitializeAfterFork): New operation. To avoid a race
condition, we need to wait until the target stopped the first time
before we can disable the local breakpoints.

* backend/server/server.h
(mono_debugger_server_init_after_fork): Renamed info
mono_debugger_server_detach_after_fork().

* backend/server/x86-arch.h
(x86_arch_enable_breakpoint): Add prototype.
(x86_arch_disable_breakpoint): Add prototype.

* backend/server/i386-arch.c
(do_enable): Renamed into x86_arch_enable_breakpoint().
(do_disable): Renamed into x86_arch_disable_breakpoint().

* backend/server/x86_64-arch.c
(do_enable): Renamed into x86_arch_enable_breakpoint().
(do_disable): Renamed into x86_arch_disable_breakpoint().

2007-12-08 Martin Baulig <martin@ximian.com>

* backend/ProcessServant.cs
Expand Down
28 changes: 19 additions & 9 deletions backend/Inferior.cs
Expand Up @@ -168,7 +168,7 @@ internal class Inferior : TargetAccess, ITargetNotification, IDisposable
static extern TargetError mono_debugger_server_get_application (IntPtr handle, out string exe_file, out string cwd, out int nargs, out IntPtr data);

[DllImport("monodebuggerserver")]
static extern TargetError mono_debugger_server_init_after_fork (IntPtr handle, bool follow_fork);
static extern TargetError mono_debugger_server_detach_after_fork (IntPtr handle);

[DllImport("monodebuggerserver")]
static extern TargetError mono_debugger_server_push_registers (IntPtr handle, out long new_rsp);
Expand Down Expand Up @@ -1284,11 +1284,10 @@ protected string GetApplication (out string cwd, out string[] cmdline_args)
}
}

public void InitializeAfterFork (bool follow_fork)
public void DetachAfterFork ()
{
check_error (mono_debugger_server_init_after_fork (server_handle, follow_fork));
if (follow_fork)
breakpoint_manager.InitializeAfterFork (this);
mono_debugger_server_detach_after_fork (server_handle);
Dispose ();
}

public TargetAddress PushRegisters ()
Expand Down Expand Up @@ -1381,16 +1380,27 @@ ServerStackFrame get_current_frame ()
{
check_disposed ();
ServerStackFrame frame;
TargetError result = mono_debugger_server_get_frame (
server_handle, out frame);
TargetError result = mono_debugger_server_get_frame (server_handle, out frame);
check_error (result);
return frame;
}

public StackFrame GetCurrentFrame (bool may_fail)
{
check_disposed ();
ServerStackFrame frame;
TargetError result = mono_debugger_server_get_frame (server_handle, out frame);
if (result == TargetError.None)
return new StackFrame (target_info, frame);
else if (may_fail)
return null;
else
throw new TargetException (result);
}

public StackFrame GetCurrentFrame ()
{
ServerStackFrame frame = get_current_frame ();
return new StackFrame (target_info, frame);
return GetCurrentFrame (false);
}

public TargetMemoryArea[] GetMemoryMaps ()
Expand Down
5 changes: 2 additions & 3 deletions backend/ProcessServant.cs
Expand Up @@ -200,9 +200,8 @@ internal void ChildForked (Inferior inferior, int pid)
manager, new_process, new_process.ProcessStart);
new_inferior.InitializeThread (pid);

new_inferior.InitializeAfterFork (manager.Debugger.Configuration.FollowFork);
if (!manager.Debugger.Configuration.FollowFork) {
new_inferior.Detach ();
new_inferior.DetachAfterFork ();
return;
}

Expand All @@ -216,7 +215,7 @@ internal void ChildForked (Inferior inferior, int pid)
// Order is important: first add the new engine to the manager's hash table,
// then call inferior.Initialize() / inferior.Attach().
manager.AddEngine (new_thread);
new_thread.StartThread (false);
new_thread.InitAfterFork ();

manager.Debugger.OnProcessCreatedEvent (new_process);
new_process.OnThreadCreatedEvent (new_thread);
Expand Down
42 changes: 38 additions & 4 deletions backend/SingleSteppingEngine.cs
Expand Up @@ -127,6 +127,13 @@ public CommandResult StartThread (bool do_attach)
return result;
}

internal void InitAfterFork ()
{
CommandResult result = new ThreadCommandResult (thread);
current_operation = new OperationRun (this, result);
PushOperation (new OperationInitAfterFork (this));
}

#region child event processing
// <summary>
// This is called from the SingleSteppingEngine's main event loop to give
Expand Down Expand Up @@ -967,8 +974,8 @@ bool throw_exception (TargetAddress stack, TargetAddress exc, TargetAddress ip)
"{0} throwing exception {1} at {2} while running {3}", this, exc, ip,
current_operation);

if ((current_operation != null) && !current_operation.StartFrame.IsNull &&
current_operation.StartFrame == ip)
if ((current_operation != null) && (current_operation.StartFrame != null) &&
(current_operation.StartFrame.Address == ip))
return false;

if (current_operation is OperationRuntimeInvoke)
Expand Down Expand Up @@ -1974,7 +1981,7 @@ protected enum EventResult
protected readonly Inferior inferior;

public readonly CommandResult Result;
public TargetAddress StartFrame = TargetAddress.Null;
public Inferior.StackFrame StartFrame;
public int PendingBreakpoint = -1;

protected Operation (SingleSteppingEngine sse, CommandResult result)
Expand All @@ -1990,7 +1997,7 @@ protected Operation (SingleSteppingEngine sse, CommandResult result)

public virtual void Execute ()
{
StartFrame = inferior.CurrentFrame;
StartFrame = inferior.GetCurrentFrame (true);
Report.Debug (DebugFlags.SSE, "{0} executing {1} at {2}",
sse, this, StartFrame);
DoExecute ();
Expand Down Expand Up @@ -2344,6 +2351,33 @@ protected override EventResult CallbackCompleted (long data1, long data2)
}
}

protected class OperationInitAfterFork : Operation
{
public OperationInitAfterFork (SingleSteppingEngine sse)
: base (sse, null)
{ }

public override bool IsSourceOperation {
get { return false; }
}

protected override void DoExecute ()
{ }

protected override EventResult DoProcessEvent (Inferior.ChildEvent cevent,
out TargetEventArgs args)
{
Report.Debug (DebugFlags.SSE,
"{0} init after fork ({1})", sse,
DebuggerWaitHandle.CurrentThread);

sse.ProcessServant.BreakpointManager.InitializeAfterFork (inferior);

args = null;
return EventResult.AskParent;
}
}

protected class OperationGetLMFAddr : OperationCallback
{
public OperationGetLMFAddr (SingleSteppingEngine sse, CommandResult result)
Expand Down
34 changes: 7 additions & 27 deletions backend/server/i386-arch.c
Expand Up @@ -745,7 +745,7 @@ runtime_info_disable_breakpoint (ServerHandle *handle, BreakpointInfo *breakpoin
}

static ServerCommandError
do_enable (ServerHandle *handle, BreakpointInfo *breakpoint)
x86_arch_enable_breakpoint (ServerHandle *handle, BreakpointInfo *breakpoint)
{
ServerCommandError result;
ArchInfo *arch = handle->arch;
Expand Down Expand Up @@ -795,7 +795,7 @@ do_enable (ServerHandle *handle, BreakpointInfo *breakpoint)
}

static ServerCommandError
do_disable (ServerHandle *handle, BreakpointInfo *breakpoint)
x86_arch_disable_breakpoint (ServerHandle *handle, BreakpointInfo *breakpoint)
{
ServerCommandError result;
ArchInfo *arch = handle->arch;
Expand Down Expand Up @@ -868,7 +868,7 @@ server_ptrace_insert_breakpoint (ServerHandle *handle, guint64 address, guint32
breakpoint->id = mono_debugger_breakpoint_manager_get_next_id ();
breakpoint->dr_index = -1;

result = do_enable (handle, breakpoint);
result = x86_arch_enable_breakpoint (handle, breakpoint);
if (result != COMMAND_ERROR_NONE) {
mono_debugger_breakpoint_manager_unlock ();
g_free (breakpoint);
Expand Down Expand Up @@ -902,7 +902,7 @@ server_ptrace_remove_breakpoint (ServerHandle *handle, guint32 bhandle)
goto out;
}

result = do_disable (handle, breakpoint);
result = x86_arch_disable_breakpoint (handle, breakpoint);
if (result != COMMAND_ERROR_NONE)
goto out;

Expand All @@ -929,26 +929,6 @@ x86_arch_remove_hardware_breakpoints (ServerHandle *handle)
}
}

static ServerCommandError
server_ptrace_init_after_fork (ServerHandle *handle, gboolean follow_fork)
{
GPtrArray *breakpoints;
int i;

mono_debugger_breakpoint_manager_lock ();

breakpoints = mono_debugger_breakpoint_manager_get_breakpoints (handle->bpm);
for (i = 0; i < breakpoints->len; i++) {
BreakpointInfo *info = g_ptr_array_index (breakpoints, i);

if (!follow_fork || (info->dr_index >= 0))
do_disable (handle, info);
}

mono_debugger_breakpoint_manager_unlock ();
return COMMAND_ERROR_NONE;
}

static ServerCommandError
find_free_hw_register (ServerHandle *handle, guint32 *idx)
{
Expand Down Expand Up @@ -992,7 +972,7 @@ server_ptrace_insert_hw_breakpoint (ServerHandle *handle, guint32 type, guint32
breakpoint->is_hardware_bpt = TRUE;
breakpoint->dr_index = *idx;

result = do_enable (handle, breakpoint);
result = x86_arch_enable_breakpoint (handle, breakpoint);
if (result != COMMAND_ERROR_NONE) {
mono_debugger_breakpoint_manager_unlock ();
g_free (breakpoint);
Expand Down Expand Up @@ -1021,7 +1001,7 @@ server_ptrace_enable_breakpoint (ServerHandle *handle, guint32 bhandle)
return COMMAND_ERROR_NO_SUCH_BREAKPOINT;
}

result = do_enable (handle, breakpoint);
result = x86_arch_enable_breakpoint (handle, breakpoint);
breakpoint->enabled = TRUE;
mono_debugger_breakpoint_manager_unlock ();
return result;
Expand All @@ -1040,7 +1020,7 @@ server_ptrace_disable_breakpoint (ServerHandle *handle, guint32 bhandle)
return COMMAND_ERROR_NO_SUCH_BREAKPOINT;
}

result = do_disable (handle, breakpoint);
result = x86_arch_disable_breakpoint (handle, breakpoint);
breakpoint->enabled = FALSE;
mono_debugger_breakpoint_manager_unlock ();
return result;
Expand Down
6 changes: 3 additions & 3 deletions backend/server/library.c
Expand Up @@ -413,12 +413,12 @@ mono_debugger_server_get_application (ServerHandle *handle, gchar **exe_file, gc
}

ServerCommandError
mono_debugger_server_init_after_fork (ServerHandle *handle, gboolean follow_fork)
mono_debugger_server_detach_after_fork (ServerHandle *handle)
{
if (!global_vtable->init_after_fork)
if (!global_vtable->detach_after_fork)
return COMMAND_ERROR_NOT_IMPLEMENTED;

return (* global_vtable->init_after_fork) (handle, follow_fork);
return (* global_vtable->detach_after_fork) (handle);
}

ServerCommandError
Expand Down
6 changes: 2 additions & 4 deletions backend/server/server.h
Expand Up @@ -358,8 +358,7 @@ struct InferiorVTable {
guint32 *nargs,
gchar ***cmdline_args);

ServerCommandError (* init_after_fork) (ServerHandle *handle,
gboolean follow_fork);
ServerCommandError (* detach_after_fork) (ServerHandle *handle);

ServerCommandError (* push_registers) (ServerHandle *handle,
guint64 *new_rsp);
Expand Down Expand Up @@ -580,8 +579,7 @@ mono_debugger_server_get_application (ServerHandle *handle,
gchar ***cmdline_args);

ServerCommandError
mono_debugger_server_init_after_fork (ServerHandle *handle,
gboolean follow_fork);
mono_debugger_server_detach_after_fork (ServerHandle *handle);

ServerCommandError
mono_debugger_server_push_registers (ServerHandle *handle,
Expand Down
5 changes: 4 additions & 1 deletion backend/server/x86-arch.h
Expand Up @@ -73,7 +73,10 @@ static ServerCommandError
x86_arch_get_registers (ServerHandle *handle);

static ServerCommandError
server_ptrace_init_after_fork (ServerHandle *handle, gboolean follow_fork);
x86_arch_disable_breakpoint (ServerHandle *handle, BreakpointInfo *breakpoint);

static ServerCommandError
x86_arch_enable_breakpoint (ServerHandle *handle, BreakpointInfo *breakpoint);

#if defined(__i386__)
#include "i386-arch.h"
Expand Down
26 changes: 26 additions & 0 deletions backend/server/x86-linux-ptrace.c
Expand Up @@ -455,3 +455,29 @@ server_ptrace_get_application (ServerHandle *handle, gchar **exe_file, gchar **c
g_ptr_array_free (array, FALSE);
return COMMAND_ERROR_NONE;
}

static ServerCommandError
server_ptrace_detach_after_fork (ServerHandle *handle)
{
GPtrArray *breakpoints;
guint32 status;
int i;

do_wait (handle->inferior->pid, &status);

mono_debugger_breakpoint_manager_lock ();

breakpoints = mono_debugger_breakpoint_manager_get_breakpoints (handle->bpm);
for (i = 0; i < breakpoints->len; i++) {
BreakpointInfo *info = g_ptr_array_index (breakpoints, i);

x86_arch_disable_breakpoint (handle, info);
}

mono_debugger_breakpoint_manager_unlock ();

if (ptrace (PT_DETACH, handle->inferior->pid, NULL, NULL) != 0)
return _server_ptrace_check_errno (handle->inferior);

return COMMAND_ERROR_NONE;
}
2 changes: 1 addition & 1 deletion backend/server/x86-ptrace.c
Expand Up @@ -585,7 +585,7 @@ InferiorVTable i386_ptrace_inferior = {
server_ptrace_get_signal_info,
server_ptrace_get_threads,
server_ptrace_get_application,
server_ptrace_init_after_fork,
server_ptrace_detach_after_fork,
server_ptrace_push_registers,
server_ptrace_pop_registers,
server_ptrace_get_callback_frame
Expand Down

0 comments on commit 072acf3

Please sign in to comment.