techl / MonoRemoteDebugger

Other
83 stars 18 forks source link

Error during managed I/O, COMException (0x89710016): Unable to start program #41

Closed dermeister0 closed 5 years ago

dermeister0 commented 7 years ago

Installed product versions

Description

Can't debug a simple application remotely. Error during managed I/O message is shown.

Steps to recreate

I use Docker container to run MonoRemoteDebugger.Server.

Current behavior

Debug process does not start.

Dockerfile:

FROM debian:stretch-20170723

RUN apt-get update && apt-get install -y mono-devel wget unzip

WORKDIR /opt

RUN wget https://github.com/techl/MonoRemoteDebugger/releases/download/v1.3.0/MonoRemoteDebugger.Server.zip && \
    unzip -d MonoRemoteDebugger.Server MonoRemoteDebugger.Server.zip && \
    rm MonoRemoteDebugger.Server.zip

CMD mono /opt/MonoRemoteDebugger.Server/MonoRemoteDebugger.Server.exe
> docker build -t monodebugger .
> docker run --name mono3 -p 13001:13001 -p 11000:11000 monodebugger
2017-07-28 07:46:05.9862|TRACE|MonoRemoteDebugger.SharedLib.Server.MonoUtils|Platform=Unix, GetMonoPath=mono, GetMonoXsp4=xsp4, GetPdb2MdbPath=pdb2mdb
Mono pdb to mdb debug symbol store converter
Usage: pdb2mdb assembly
2017-07-28 07:46:06.2214|TRACE|MonoRemoteDebugger.SharedLib.Server.MonoDebugServer|Start announcing
2017-07-28 07:46:06.2385|INFO|MonoRemoteDebugger.SharedLib.Server.MonoDebugServer|Waiting for client
2017-07-28 07:46:21.8249|INFO|MonoRemoteDebugger.SharedLib.Server.MonoDebugServer|Accepted client: 172.17.0.1:37182
2017-07-28 07:46:21.8487|TRACE|MonoRemoteDebugger.SharedLib.Server.ClientSession|New Session from 172.17.0.1
2017-07-28 07:46:21.9587|INFO|MonoRemoteDebugger.SharedLib.Server.ClientSession|DebugLastContent-Message received
2017-07-28 07:46:21.9598|TRACE|MonoRemoteDebugger.SharedLib.Server.ClientSession|Check if content is already available from 172.17.0.1: /opt/MonoRemoteDebugger.Server/Temp/9C9E38330EA3888A2EAFAC6B2070201FFE392087352880DCB75A4759F64D747C
2017-07-28 07:46:21.9608|TRACE|MonoRemoteDebugger.SharedLib.Server.ClientSession|Content not found. Request new content from 172.17.0.1 ...
2017-07-28 07:46:22.0557|INFO|MonoRemoteDebugger.SharedLib.Server.ClientSession|DebugContent-Message received
2017-07-28 07:46:22.0557|TRACE|MonoRemoteDebugger.SharedLib.Server.ClientSession|Receiving content from 172.17.0.1
2017-07-28 07:46:22.1253|TRACE|MonoRemoteDebugger.SharedLib.Server.ClientSession|Extracted content from 172.17.0.1 to /opt/MonoRemoteDebugger.Server/Temp/9C9E38330EA3888A2EAFAC6B2070201FFE392087352880DCB75A4759F64D747C
2017-07-28 07:46:22.1298|TRACE|MonoRemoteDebugger.SharedLib.Server.ClientSession|AppType: Desktopapplication => choosing binaryDirectory=/opt/MonoRemoteDebugger.Server/Temp/9C9E38330EA3888A2EAFAC6B2070201FFE392087352880DCB75A4759F64D747C
2017-07-28 07:46:22.1315|TRACE|MonoRemoteDebugger.SharedLib.Server.Pdb2MdbGenerator|/opt/MonoRemoteDebugger.Server/Temp/9C9E38330EA3888A2EAFAC6B2070201FFE392087352880DCB75A4759F64D747C
2017-07-28 07:46:22.1337|TRACE|MonoRemoteDebugger.SharedLib.Server.Pdb2MdbGenerator|1
2017-07-28 07:46:22.1391|TRACE|MonoRemoteDebugger.SharedLib.Server.Pdb2MdbGenerator|Generate mdp for: /opt/MonoRemoteDebugger.Server/Temp/9C9E38330EA3888A2EAFAC6B2070201FFE392087352880DCB75A4759F64D747C/Test072801.exe
2017-07-28 07:46:22.3616|TRACE|MonoRemoteDebugger.SharedLib.Server.Pdb2MdbGenerator|Transformed Debuginformation pdb2mdb

I try to debug console application for .NET 4.6.2 or .NET 4.0.

public class Program
{
    public static void Main(string[] args)
    {
        System.Console.WriteLine("Hello world!");
    }
}

2017-07-28_1446

2017-07-28_1451

2017-07-28 14:46:22.3965|TRACE|MonoRemoteDebugger.Debugger.DebugHelper|AD7Engine (entering) :  SetRegistryRoot
2017-07-28 14:46:22.3965|TRACE|MonoRemoteDebugger.Debugger.DebugHelper|AD7Engine (entering) :  SetLocale
2017-07-28 14:46:22.4165|TRACE|MonoRemoteDebugger.Debugger.DebugHelper|AD7Engine (entering) :  LaunchSuspended
2017-07-28 14:46:22.4446|ERROR|MonoRemoteDebugger.VSExtension.MonoVisualStudioExtension|System.Runtime.InteropServices.COMException (0x89710016): Unable to start program 'C:\Users\anton\Desktop\Test072801\bin\Debug\Test072801.exe'.

Error during managed I/O.
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at MonoRemoteDebugger.VSExtension.MonoVisualStudioExtension.<AttachDebugger>d__9.MoveNext()
2017-07-28 14:46:22.4446|ERROR|MonoRemoteDebugger.VSExtension.VSPackage|System.Runtime.InteropServices.COMException (0x89710016): Unable to start program 'C:\Users\anton\Desktop\Test072801\bin\Debug\Test072801.exe'.

Error during managed I/O.
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at MonoRemoteDebugger.VSExtension.MonoVisualStudioExtension.<AttachDebugger>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MonoRemoteDebugger.VSExtension.VSPackage.<StartSearching>d__11.MoveNext()

MDB file is generated successfully. The application works.

root@c5f5921c5c43:/opt/MonoRemoteDebugger.Server/Temp/9C9E38330EA3888A2EAFAC6B2070201FFE392087352880DCB75A4759F64D747C# ls
Test072801.exe  Test072801.exe.config  Test072801.exe.mdb  Test072801.pdb
root@c5f5921c5c43:/opt/MonoRemoteDebugger.Server/Temp/9C9E38330EA3888A2EAFAC6B2070201FFE392087352880DCB75A4759F64D747C# mono ./Test072801.exe
Hello world!

Current behavior

The debug process does not start.

Expected behavior

Debug process starts.

dermeister0 commented 7 years ago

I ran the extension under debugger.

System.IO.IOException: DWP Handshake failed.

Server stack trace:
   at Mono.Debugger.Soft.Connection.Connect()
   at Mono.Debugger.Soft.VirtualMachine.connect()
   at Mono.Debugger.Soft.VirtualMachineManager.Connect(Connection transport, StreamReader standardOutput, StreamReader standardError)
   at Mono.Debugger.Soft.VirtualMachineManager.ConnectInternal(Socket dbg_sock, Socket con_sock, IPEndPoint dbg_ep, IPEndPoint con_ep, TextWriter logWriter)
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message reqMsg, Boolean bProxyCase)
   at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData& msgData)
   at Mono.Debugger.Soft.VirtualMachineManager.ConnectCallback.EndInvoke(IAsyncResult result)
   at Mono.Debugger.Soft.VirtualMachineManager.EndConnect(IAsyncResult asyncResult)
   at Mono.Debugger.Soft.VirtualMachineManager.Connect(IPEndPoint endpoint, IPEndPoint consoleEndpoint, TextWriter logWriter)
   at Mono.Debugger.Soft.VirtualMachineManager.Connect(IPEndPoint endpoint, TextWriter logWriter)
   at Microsoft.MIDebugEngine.DebuggedProcess.StartDebugging()
   at MonoRemoteDebugger.Debugger.VisualStudio.AD7Engine.LaunchSuspended(String pszServer, IDebugPort2 port, String exe, String args, String dir, String env, String options, enum_LAUNCH_FLAGS launchFlags, UInt32 hStdInput, UInt32 hStdOutput, UInt32 hStdError, IDebugEventCallback2 ad7Callback, IDebugProcess2& process)

https://github.com/mono/debugger-libs/blob/fa8e6a9e7ec4784c4883d36233fe42200270b08f/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs#L1133

dermeister0 commented 7 years ago

It always fails for the first time (when need to copy files) and works for the second time. debugSessionStarted in AttachDebugger is false for the first time and true when application has not changed.

It works better under debugger. I think an error happens when multiple tasks run simultaneously in this place:

            var debugSessionStarted = await session.RestartDebuggingAsync(timeout);

            if (!debugSessionStarted)
            {
                await session.TransferFilesAsync();
                await session.WaitForAnswerAsync(timeout);
            }

I think that cancellation token should be used in WaitForAnswerAsync to cancel communication.ReceiveAsync task by timeout.

techcap commented 7 years ago

Can you test after updating mono to latest version? My current mono version is v5.0.1.