Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use 'Console.CancelKeyPress' instead of unmanaged semaphores.

  • Loading branch information...
commit a5088ebf3e2dfc8fb1d02dd9ea4a2b4d7a774101 1 parent 757dc9c
Martin Baulig authored
View
3  backend/ThreadManager.cs
@@ -83,9 +83,6 @@ internal ThreadManager (DebuggerServant backend)
static extern int mono_debugger_server_global_wait (out int status);
[DllImport("monodebuggerserver")]
- static extern int mono_debugger_server_get_pending_sigint ();
-
- [DllImport("monodebuggerserver")]
static extern Inferior.ChildEventType mono_debugger_server_dispatch_simple (int status, out int arg);
void start_inferior ()
View
29 backend/server/darwin-ptrace.c
@@ -1086,35 +1086,6 @@ server_ptrace_kill (ServerHandle *handle)
return COMMAND_ERROR_NONE;
}
-static sem_t *manager_semaphore;
-
-static void
-server_ptrace_sem_init (void)
-{
- manager_semaphore = sem_open ("mdb", O_CREAT, 0666, 1);
-}
-
-static void
-server_ptrace_sem_wait (void)
-{
- sem_wait (manager_semaphore);
-}
-
-static void
-server_ptrace_sem_post (void)
-{
- sem_post (manager_semaphore);
-}
-
-static int
-server_ptrace_sem_get_value (void)
-{
- int ret;
-
- sem_getvalue (manager_semaphore, &ret);
- return ret;
-}
-
static ServerType
server_ptrace_get_server_type (void)
{
View
30 backend/server/library.c
@@ -522,33 +522,3 @@ mono_debugger_server_static_init (void)
{
(* global_vtable->static_init) ();
}
-
-int
-mono_debugger_server_get_pending_sigint (void)
-{
- return (* global_vtable->get_pending_sigint) ();
-}
-
-void
-mono_debugger_server_sem_init (void)
-{
- (* global_vtable->sem_init) ();
-}
-
-void
-mono_debugger_server_sem_wait (void)
-{
- (* global_vtable->sem_wait) ();
-}
-
-void
-mono_debugger_server_sem_post (void)
-{
- (* global_vtable->sem_post) ();
-}
-
-int
-mono_debugger_server_sem_get_value (void)
-{
- return (* global_vtable->sem_get_value) ();
-}
View
8 backend/server/monodebuggerserver.def
@@ -13,7 +13,6 @@ mono_debugger_mutex_unlock
mono_debugger_mutex_trylock
mono_debugger_server_static_init
-mono_debugger_server_get_pending_sigint
mono_debugger_server_global_init
mono_debugger_server_create_inferior
mono_debugger_server_spawn
@@ -23,11 +22,6 @@ mono_debugger_server_get_current_pid
mono_debugger_server_get_current_thread
mono_debugger_server_get_signal_info
-mono_debugger_server_sem_init
-mono_debugger_server_sem_wait
-mono_debugger_server_sem_post
-mono_debugger_server_sem_get_value
-
mono_debugger_server_get_target_info
mono_debugger_server_dispatch_event
mono_debugger_server_get_application
@@ -47,4 +41,4 @@ mono_debugger_breakpoint_manager_lookup_by_id
mono_debugger_breakpoint_manager_get_breakpoints
mono_debugger_breakpoint_manager_remove
mono_debugger_breakpoint_info_get_id
-mono_debugger_breakpoint_info_get_is_enabled
+mono_debugger_breakpoint_info_get_is_enabled
View
20 backend/server/server.h
@@ -446,16 +446,6 @@ struct InferiorVTable {
guint32 (*get_current_pid) (void);
guint64 (*get_current_thread) (void);
-
- void (*sem_init) (void);
-
- void (*sem_wait) (void);
-
- void (*sem_post) (void);
-
- int (*sem_get_value) (void);
-
- int (*get_pending_sigint) (void);
};
/*
@@ -738,16 +728,6 @@ mono_debugger_server_get_current_pid (void);
guint64
mono_debugger_server_get_current_thread (void);
-
-/* POSIX semaphores */
-
-void mono_debugger_server_sem_init (void);
-void mono_debugger_server_sem_wait (void);
-void mono_debugger_server_sem_post (void);
-int mono_debugger_server_sem_get_value (void);
-
-int mono_debugger_server_get_pending_sigint (void);
-
G_END_DECLS
#endif
View
29 backend/server/x86-linux-ptrace.c
@@ -1,32 +1,3 @@
-static sem_t manager_semaphore;
-
-static void
-server_ptrace_sem_init (void)
-{
- sem_init (&manager_semaphore, 1, 0);
-}
-
-static void
-server_ptrace_sem_wait (void)
-{
- sem_wait (&manager_semaphore);
-}
-
-static void
-server_ptrace_sem_post (void)
-{
- sem_post (&manager_semaphore);
-}
-
-static int
-server_ptrace_sem_get_value (void)
-{
- int ret;
-
- sem_getvalue (&manager_semaphore, &ret);
- return ret;
-}
-
static ServerType
server_ptrace_get_server_type (void)
{
View
38 backend/server/x86-ptrace.c
@@ -574,40 +574,9 @@ server_ptrace_get_current_thread (void)
return pthread_self ();
}
-static gboolean initialized = FALSE;
-int pending_sigint = 0;
-
-static void
-sigint_signal_handler (int _dummy)
-{
- pending_sigint++;
- server_ptrace_sem_post ();
-}
-
static void
server_ptrace_static_init (void)
{
- struct sigaction sa;
-
- if (initialized)
- return;
-
- /* catch SIGINT */
- sa.sa_handler = sigint_signal_handler;
- sigemptyset (&sa.sa_mask);
- sa.sa_flags = 0;
- g_assert (sigaction (SIGINT, &sa, NULL) != -1);
-
- initialized = TRUE;
-}
-
-static int
-server_ptrace_get_pending_sigint (void)
-{
- if (pending_sigint > 0)
- return pending_sigint--;
-
- return 0;
}
extern void GC_start_blocking (void);
@@ -690,10 +659,5 @@ InferiorVTable i386_ptrace_inferior = {
server_ptrace_restart_notification,
server_ptrace_get_registers_from_core_file,
server_ptrace_get_current_pid,
- server_ptrace_get_current_thread,
- server_ptrace_sem_init,
- server_ptrace_sem_wait,
- server_ptrace_sem_post,
- server_ptrace_sem_get_value,
- server_ptrace_get_pending_sigint,
+ server_ptrace_get_current_thread
};
View
14 backend/server/x86-ptrace.h
@@ -43,8 +43,6 @@ struct InferiorHandle
#endif /* PTRACE_EVENT_FORK */
-extern int pending_sigint;
-
static ServerCommandError
_server_ptrace_check_errno (InferiorHandle *);
@@ -110,16 +108,4 @@ server_ptrace_get_signal_info (ServerHandle *handle, SignalInfo **sinfo);
static gboolean
_server_ptrace_wait_for_new_thread (ServerHandle *handle);
-static void
-server_ptrace_sem_init (void);
-
-static void
-server_ptrace_sem_wait (void);
-
-static void
-server_ptrace_sem_post (void);
-
-static int
-server_ptrace_sem_get_value (void);
-
#endif
View
97 backend/server/x86-windows.c
@@ -307,13 +307,8 @@ but how and which information should be placed there is not yet clear. To shield
internal changes accessor function will be used. This accessor functions are yet to be written and
one must expect them to change over time */
static DEBUG_INFO m_debug_info;
-static gboolean initialized = FALSE;
-static HANDLE manager_semaphore;
-static LONG sem_count = 0;
static GAsyncQueue *bridge;
-static int pending_sigint = 0;
-
@@ -332,7 +327,6 @@ static int get_set_registers (CONTEXT *context, enum READ_FLAG flag);
static int single_step_checks (guint32 eip);
static BOOL decrement_ip (HANDLE debuggee_thread_handle);
static int resume_from_imports_table (int flag);
-static void emul_sem_post (void);
static BreakpointInfo* on_breakpoint_exception (DWORD address,int *b_continue);
@@ -655,8 +649,6 @@ static BOOL do_debug_exception_event (LPDEBUG_EVENT pde, HANDLE debuggee_handle,
}
m_debug_info.debuggee.thread_handle = save_thread_handle;
m_debug_info.debuggee.thread_id = save_thread_id;
- pending_sigint++;
- emul_sem_post ();
return (b_continue);
}
@@ -1198,25 +1190,11 @@ static void format_windows_error_message (DWORD error_code)
}
}
-static BOOL WINAPI HandlerRoutine (DWORD dwCtrlType)
-{
- ReleaseSemaphore (manager_semaphore, 1, &sem_count);
- return TRUE;
-}
-
static void
server_win32_static_init (void)
{
- if (initialized)
- return;
-
- SetConsoleCtrlHandler (HandlerRoutine, TRUE);
- g_thread_init (NULL);
-
- initialized = TRUE;
}
-
static ServerCommandError
server_win32_get_signal_info (ServerHandle *handle, SignalInfo **sinfo_out)
{
@@ -2306,74 +2284,6 @@ server_win32_get_current_thread (void)
return GetCurrentThreadId ();
}
-static void emul_sem_post (void) {
-
- LONG l_val;
- BOOL b_rval;
-
- SetLastError (0);
- b_rval = ReleaseSemaphore (manager_semaphore, pending_sigint, &l_val);
- if (! b_rval) {
- format_windows_error_message (GetLastError ());
- g_debug ("%s", windows_error_message);
- }
- /* frido test 2009-05-22 */
- //SetEvent (m_command_events [EVENT_RESUME]);
-}
-
-
-
-
-static void
-server_win32_sem_init (void)
-{
- manager_semaphore = CreateSemaphore (
- NULL, // default security attributes
- 0, // initial count
- 12, // maximum count
- NULL); // unnamed semaphore
- if (! manager_semaphore) {
- format_windows_error_message (GetLastError ());
- g_debug ("sever_win32_sem_init, error: %s", windows_error_message);
- }
-}
-
-static void
-server_win32_sem_wait (void)
-{
- WaitForSingleObject ( manager_semaphore, INFINITE);
- // WaitForSingleObject ( manager_semaphore, 45000);
-}
-
-
-
-static void
-server_win32_sem_post (void)
-{
-
- BOOL b_rval;
- SetLastError (0);
- b_rval = ReleaseSemaphore (manager_semaphore, 1, &sem_count);
- if (! b_rval) {
- format_windows_error_message (GetLastError ());
- g_debug ("%s, sem_count = %d", windows_error_message,sem_count);
- }
-}
-
-static int
-server_win32_sem_get_value (void)
-{
- return sem_count;
-}
-
-static int
-server_win32_get_pending_sigint (void)
-{
- if (pending_sigint > 0)
- return pending_sigint--;
-
- return 0;
-}
static ServerCommandError
read_write_memory (ServerHandle *server_handle, guint64 start, guint32 size, gpointer buffer, int read)
@@ -2528,12 +2438,7 @@ InferiorVTable i386_windows_inferior = {
NULL, /*server_ptrace_restart_notification, */
NULL, /*get_registers_from_core_file, */
server_win32_get_current_pid, /*get_current_pid, */
- server_win32_get_current_thread, /*get_current_thread, */
- server_win32_sem_init, /*sem_init, */
- server_win32_sem_wait, /*sem_wait, */
- server_win32_sem_post, /*sem_post, */
- server_win32_sem_get_value, /*sem_get_value, */
- server_win32_get_pending_sigint, /*get_pending_sigint, */
+ server_win32_get_current_thread /*get_current_thread, */
};
View
47 classes/Semaphore.cs
@@ -1,47 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-
-namespace Mono.Debugger.Backend
-{
- public static class Semaphore
- {
- [DllImport("monodebuggerserver")]
- static extern void mono_debugger_server_sem_init ();
-
- [DllImport("monodebuggerserver")]
- static extern void mono_debugger_server_sem_wait ();
-
- [DllImport("monodebuggerserver")]
- static extern void mono_debugger_server_sem_post ();
-
- [DllImport("monodebuggerserver")]
- static extern int mono_debugger_server_sem_get_value ();
-
- static Semaphore ()
- {
- mono_debugger_server_sem_init ();
- }
-
- public static void Wait ()
- {
- Report.Debug (DebugFlags.Mutex, "{0} waiting for semaphore",
- DebuggerWaitHandle.CurrentThread);
- mono_debugger_server_sem_wait ();
- Report.Debug (DebugFlags.Mutex, "{0} done waiting for semaphore",
- DebuggerWaitHandle.CurrentThread);
- }
-
- public static void Set ()
- {
- Report.Debug (DebugFlags.Mutex, "{0} signalling semaphore",
- DebuggerWaitHandle.CurrentThread);
- mono_debugger_server_sem_post ();
- }
-
- public static int Value {
- get {
- return mono_debugger_server_sem_get_value ();
- }
- }
- }
-}
View
46 frontend/Main.cs
@@ -45,7 +45,6 @@ public class CommandLineInterpreter
int line = 0;
bool is_inferior_main;
- ST.Thread interrupt_thread;
ST.Thread main_thread;
ST.AutoResetEvent interrupt_event;
@@ -55,17 +54,6 @@ public class CommandLineInterpreter
Stack<CommandLineInterpreter.MainLoop> main_loop_stack;
- [DllImport("monodebuggerserver")]
- static extern int mono_debugger_server_static_init ();
-
- [DllImport("monodebuggerserver")]
- static extern int mono_debugger_server_get_pending_sigint ();
-
- static CommandLineInterpreter ()
- {
- mono_debugger_server_static_init ();
- }
-
internal CommandLineInterpreter (DebuggerOptions options, bool is_interactive)
{
if (options.HasDebugFlags)
@@ -97,6 +85,8 @@ internal CommandLineInterpreter (DebuggerOptions options, bool is_interactive)
line_editor.AutoCompleteEvent += delegate (string text, int pos) {
return engine.Completer.Complete (text, pos);
};
+
+ Console.CancelKeyPress += control_c_event;
}
interrupt_event = new ST.AutoResetEvent (false);
@@ -107,9 +97,6 @@ internal CommandLineInterpreter (DebuggerOptions options, bool is_interactive)
main_thread = new ST.Thread (new ST.ThreadStart (main_thread_main));
main_thread.IsBackground = true;
-
- interrupt_thread = new ST.Thread (new ST.ThreadStart (interrupt_thread_main));
- interrupt_thread.IsBackground = true;
}
public CommandLineInterpreter (Interpreter interpreter)
@@ -123,14 +110,21 @@ public CommandLineInterpreter (Interpreter interpreter)
interrupt_event = new ST.AutoResetEvent (false);
nested_break_state_event = new ST.AutoResetEvent (false);
+ Console.CancelKeyPress += control_c_event;
+
main_loop_stack = new Stack<MainLoop> ();
main_loop_stack.Push (new MainLoop (interpreter));
main_thread = new ST.Thread (new ST.ThreadStart (main_thread_main));
main_thread.IsBackground = true;
+ }
- interrupt_thread = new ST.Thread (new ST.ThreadStart (interrupt_thread_main));
- interrupt_thread.IsBackground = true;
+ void control_c_event (object sender, ConsoleCancelEventArgs a)
+ {
+ a.Cancel = true;
+
+ if (interpreter.Interrupt () > 2)
+ interrupt_event.Set ();
}
public void DoRunMainLoop ()
@@ -242,8 +236,6 @@ protected void RunMainLoop ()
{
is_inferior_main = false;
- interrupt_thread.Start ();
-
try {
if (interpreter.Options.StartTarget)
interpreter.Start ();
@@ -265,8 +257,6 @@ public void RunInferiorMainLoop ()
{
is_inferior_main = true;
- interrupt_thread.Start ();
-
TextReader old_stdin = Console.In;
TextWriter old_stdout = Console.Out;
TextWriter old_stderr = Console.Error;
@@ -309,8 +299,6 @@ public void RunInferiorMainLoop ()
interpreter.IsScript = old_is_script;
interpreter.IsInteractive = old_is_interactive;
}
-
- interrupt_thread.Abort ();
}
public string ReadInput (bool is_complete)
@@ -345,18 +333,6 @@ public void Error (int pos, string message)
}
}
- void interrupt_thread_main ()
- {
- do {
- Semaphore.Wait ();
- if (mono_debugger_server_get_pending_sigint () == 0)
- continue;
-
- if (interpreter.Interrupt () > 2)
- interrupt_event.Set ();
- } while (true);
- }
-
public static void Main (string[] args)
{
DebuggerOptions options = DebuggerOptions.ParseCommandLine (args);
Please sign in to comment.
Something went wrong with that request. Please try again.