예제 #1
0
        public jvmtiError GetSourceFileName(JvmVirtualMachineRemoteHandle virtualMachine, JvmClassRemoteHandle @class, out string sourceName)
        {
            JavaVM machine = JavaVM.GetInstance(virtualMachine);

            string     sourceNameResult = null;
            jvmtiError result           = jvmtiError.Internal;

            machine.InvokeOnJvmThread(
                (environment) =>
            {
                jvmtiInterface rawInterface = environment.RawInterface;

                IntPtr sourceNamePtr = IntPtr.Zero;
                try
                {
                    result = rawInterface.GetSourceFileName(environment.Handle, @class, out sourceNamePtr);

                    unsafe
                    {
                        if (sourceNamePtr != IntPtr.Zero)
                        {
                            sourceNameResult = ModifiedUTF8Encoding.GetString((byte *)sourceNamePtr);
                        }
                    }
                }
                finally
                {
                    rawInterface.Deallocate(environment.Handle, sourceNamePtr);
                }
            });

            sourceName = sourceNameResult;
            return(result);
        }
예제 #2
0
        internal void Deallocate(IntPtr handle)
        {
            if (!AgentExports.IsLoaded)
            {
                return;
            }

            _rawInterface.Deallocate(_env, handle);
        }
예제 #3
0
        public jvmtiError GetClassSignature(JvmVirtualMachineRemoteHandle virtualMachine, JvmClassRemoteHandle @class, out string signature, out string generic)
        {
            JavaVM machine = JavaVM.GetInstance(virtualMachine);

            string     signatureResult = null;
            string     genericResult   = null;
            jvmtiError result          = jvmtiError.Internal;

            machine.InvokeOnJvmThread(
                (environment) =>
            {
                jvmtiInterface rawInterface = environment.RawInterface;

                IntPtr signaturePtr = IntPtr.Zero;
                IntPtr genericPtr   = IntPtr.Zero;
                try
                {
                    result = rawInterface.GetClassSignature(environment.Handle, @class, out signaturePtr, out genericPtr);

                    unsafe
                    {
                        if (signaturePtr != IntPtr.Zero)
                        {
                            signatureResult = ModifiedUTF8Encoding.GetString((byte *)signaturePtr);
                        }
                        if (genericPtr != IntPtr.Zero)
                        {
                            genericResult = ModifiedUTF8Encoding.GetString((byte *)genericPtr);
                        }
                    }
                }
                finally
                {
                    rawInterface.Deallocate(environment.Handle, signaturePtr);
                    rawInterface.Deallocate(environment.Handle, genericPtr);
                }
            });

            signature = signatureResult;
            generic   = genericResult;
            return(result);
        }
예제 #4
0
        public jvmtiError Deallocate(JvmVirtualMachineRemoteHandle virtualMachine, long address)
        {
            JavaVM machine = JavaVM.GetInstance(virtualMachine);

            jvmtiError result = jvmtiError.Internal;

            machine.InvokeOnJvmThread(
                (environment) =>
            {
                jvmtiInterface rawInterface = environment.RawInterface;
                result = rawInterface.Deallocate(environment.Handle, (IntPtr)address);
            });

            return(result);
        }
예제 #5
0
        public jvmtiError GetLineNumberTable(JvmVirtualMachineRemoteHandle virtualMachine, JvmMethodRemoteHandle method, out JvmLineNumberEntry[] lineNumbers)
        {
            JavaVM machine = JavaVM.GetInstance(virtualMachine);

            List <JvmLineNumberEntry> lineNumbersList = new List <JvmLineNumberEntry>();
            jvmtiError result = jvmtiError.Internal;

            machine.InvokeOnJvmThread(
                (environment) =>
            {
                jvmtiInterface rawInterface = environment.RawInterface;

                IntPtr lineNumbersPtr = IntPtr.Zero;
                try
                {
                    int entryCount;
                    result = rawInterface.GetLineNumberTable(environment.Handle, (jmethodID)method, out entryCount, out lineNumbersPtr);

                    unsafe
                    {
                        jvmtiLineNumberEntry *rawLineNumbers = (jvmtiLineNumberEntry *)lineNumbersPtr;
                        for (int i = 0; i < entryCount; i++)
                        {
                            lineNumbersList.Add(new JvmLineNumberEntry(method, rawLineNumbers[i]));
                        }
                    }
                }
                finally
                {
                    rawInterface.Deallocate(environment.Handle, lineNumbersPtr);
                }
            });

            lineNumbers = lineNumbersList.ToArray();
            return(result);
        }
예제 #6
0
        public jvmtiError GetClassMethods(JvmVirtualMachineRemoteHandle virtualMachine, JvmClassRemoteHandle @class, out JvmMethodRemoteHandle[] methods)
        {
            JavaVM machine = JavaVM.GetInstance(virtualMachine);

            List <JvmMethodRemoteHandle> methodsList = new List <JvmMethodRemoteHandle>();
            jvmtiError result = jvmtiError.Internal;

            machine.InvokeOnJvmThread(
                (environment) =>
            {
                jvmtiInterface rawInterface = environment.RawInterface;

                IntPtr methodsPtr = IntPtr.Zero;
                try
                {
                    int methodCount;
                    result = rawInterface.GetClassMethods(environment.Handle, @class, out methodCount, out methodsPtr);

                    unsafe
                    {
                        jmethodID *rawMethods = (jmethodID *)methodsPtr;
                        for (int i = 0; i < methodCount; i++)
                        {
                            methodsList.Add(new JvmMethodRemoteHandle(rawMethods[i]));
                        }
                    }
                }
                finally
                {
                    rawInterface.Deallocate(environment.Handle, methodsPtr);
                }
            });

            methods = methodsList.ToArray();
            return(result);
        }