public EventProcessor(DebugProtocolService service)
            {
                Contract.Requires(service != null);
                _service = service;

                _eventCallbacks = new jvmtiEventCallbacks()
                {
                    VMInit = HandleVMInit,
                    VMDeath = HandleVMDeath,
                    ThreadStart = HandleThreadStart,
                    ThreadEnd = HandleThreadEnd,
                    ClassFileLoadHook = HandleClassFileLoadHook,
                    ClassLoad = HandleClassLoad,
                    ClassPrepare = HandleClassPrepare,
                    VMStart = HandleVMStart,
                    Exception = HandleException,
                    ExceptionCatch = HandleExceptionCatch,
                    SingleStep = HandleSingleStep,
                    FramePop = HandleFramePop,
                    Breakpoint = HandleBreakpoint,
                    FieldAccess = HandleFieldAccess,
                    FieldModification = HandleFieldModification,
                    MethodEntry = HandleMethodEntry,
                    MethodExit = HandleMethodExit,
                    NativeMethodBind = HandleNativeMethodBind,
                    CompiledMethodLoad = HandleCompiledMethodLoad,
                    CompiledMethodUnload = HandleCompiledMethodUnload,
                    DynamicCodeGenerated = HandleDynamicCodeGenerated,
                    DataDumpRequest = HandleDataDumpRequest,
                    MonitorWait = HandleMonitorWait,
                    MonitorWaited = HandleMonitorWaited,
                    MonitorContendedEnter = HandleMonitorContendedEnter,
                    MonitorContendedEntered = HandleMonitorContendedEntered,
                    ResourceExhausted = HandleResourceExhausted,
                    GarbageCollectionStart = HandleGarbageCollectionStart,
                    GarbageCollectionFinish = HandleGarbageCollectionFinish,
                    ObjectFree = HandleObjectFree,
                    VMObjectAlloc = HandleVMObjectAlloc
                };
            }
Beispiel #2
0
        public static unsafe int OnLoad(IntPtr vmPtr, IntPtr optionsPtr, IntPtr reserved)
        {
            _loaded = true;

            JavaVM vm = JavaVM.GetOrCreateInstance(new JavaVMHandle(vmPtr));

            string optionsString = null;
            if (optionsPtr != IntPtr.Zero)
                optionsString = ModifiedUTF8Encoding.GetString((byte*)optionsPtr);

            string[] options = new string[0];
            if (optionsString != null)
            {
                options = optionsString.Split(',', ';');
            }

#if false
            // quick test
            GetEnvironmentVersion(vm);

            Action<JavaVM> action = GetEnvironmentVersion;
            IAsyncResult result = action.BeginInvoke(vm, null, null);
            result.AsyncWaitHandle.WaitOne();
#endif

            AppDomain.CurrentDomain.AssemblyResolve += HandleAssemblyResolve;

            if (options.Contains("ShowAgentExceptions", StringComparer.OrdinalIgnoreCase))
            {
                AppDomain.CurrentDomain.FirstChanceException += HandleFirstChanceException;
                AppDomain.CurrentDomain.UnhandledException += HandleUnhandledException;
                //AppDomain.CurrentDomain.ProcessExit += HandleProcessExit;
            }

            if (options.Contains("DisableStatementStepping", StringComparer.OrdinalIgnoreCase))
            {
                JavaVM.DisableStatementStepping = true;
            }

            List<WaitHandle> waitHandles = new List<WaitHandle>();
            Binding binding;

            /*
             * start the wcf services and wait for the client to connect
             */

#if false
            /* IJvmEventsService
             */
            _jvmEventsPublisherHost = new ServiceHost(typeof(JvmEventsPublisher));
            Binding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                ReceiveTimeout = TimeSpan.MaxValue,
                SendTimeout = TimeSpan.MaxValue
            };

            _jvmEventsPublisherHost.AddServiceEndpoint(typeof(IJvmEventsService), binding, "net.pipe://localhost/Tvl.Java.DebugHost/JvmEventsService/");
            IAsyncResult jvmEventsPublisherStartResult = _jvmEventsPublisherHost.BeginOpen(null, null);
            waitHandles.Add(jvmEventsPublisherStartResult.AsyncWaitHandle);

            /* IJvmToolsInterfaceService
             */
            _jvmToolsInterfaceHost = new ServiceHost(typeof(JvmToolsInterfaceService));
            binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                ReceiveTimeout = TimeSpan.MaxValue,
                SendTimeout = TimeSpan.MaxValue
            };

            _jvmToolsInterfaceHost.AddServiceEndpoint(typeof(IJvmToolsInterfaceService), binding, "net.pipe://localhost/Tvl.Java.DebugHost/JvmToolsInterfaceService/");
            IAsyncResult toolsInterfaceStartResult = _jvmToolsInterfaceHost.BeginOpen(null, null);
            waitHandles.Add(toolsInterfaceStartResult.AsyncWaitHandle);

            /* IJvmDebugSessionService
             */
            _jvmDebugSessionHost = new ServiceHost(typeof(JvmDebugSessionService));
            binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                ReceiveTimeout = TimeSpan.MaxValue,
                SendTimeout = TimeSpan.MaxValue
            };

            _jvmDebugSessionHost.AddServiceEndpoint(typeof(IJvmDebugSessionService), binding, "net.pipe://localhost/Tvl.Java.DebugHost/JvmDebugSessionService/");
            IAsyncResult debugSessionStartResult = _jvmDebugSessionHost.BeginOpen(null, null);
            waitHandles.Add(debugSessionStartResult.AsyncWaitHandle);
#endif

            /* IDebugProtocolService
             */
            var debugProtocolService = new DebugProtocolService(vm);
            _debugProtocolHost = new ServiceHost(debugProtocolService);
            binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                MaxReceivedMessageSize = 10 * 1024 * 1024,
                ReceiveTimeout = TimeSpan.MaxValue,
                SendTimeout = TimeSpan.MaxValue
            };

            _debugProtocolHost.AddServiceEndpoint(typeof(IDebugProtocolService), binding, "net.pipe://localhost/Tvl.Java.DebugHost/DebugProtocolService/");
            IAsyncResult debugProtocolStartResult = _debugProtocolHost.BeginOpen(null, null);
            waitHandles.Add(debugProtocolStartResult.AsyncWaitHandle);

            /* Wait for the services to finish opening
             */
            WaitHandle.WaitAll(waitHandles.ToArray());

            EventWaitHandle eventWaitHandle = null;
            try
            {
                eventWaitHandle = EventWaitHandle.OpenExisting(string.Format("JavaDebuggerInitHandle{0}", Process.GetCurrentProcess().Id));
            }
            catch (WaitHandleCannotBeOpenedException)
            {
                // must have been launched without the debugger
            }

            if (eventWaitHandle != null)
            {
                eventWaitHandle.Set();
                Action waitAction = _debuggerAttachComplete.Wait;
                IAsyncResult waitResult = waitAction.BeginInvoke(vm.HandleAsyncOperationComplete, null);
                DispatcherFrame frame = new DispatcherFrame(true);
                JvmtiEnvironment environment = debugProtocolService.Environment;
                vm.PushDispatcherFrame(frame, environment, waitResult);
            }

            return 0;
        }