Git Product home page Git Product logo

Comments (2)

leculver avatar leculver commented on May 21, 2024

Apologies for the delay in responding, it's been a busy week. I suppose this should be better documented, but CreateFromDebuggerInterface expects that you have set up IDebugClient in a way such that it is ready to be used. The HRESULT is the giveaway: 0x8000fff is the "catastrophic" error code that dbgeng hands out when it's not ready for the APIs that are called. The goal with this API is to allow you to construct a DataTarget from your own DbgEng debugger session.

Here is a minimal example of it working properly:

using Microsoft.Diagnostics.Runtime;
using Microsoft.Diagnostics.Runtime.Interop;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

class Program
{
    static void Main(string[] args)
    {
        Guid debugClientGuid = typeof(IDebugClient).GUID;
        object debugClientIUnknown;
        int hr = DebugCreate(ref debugClientGuid, out debugClientIUnknown);
        Debug.Assert(hr == 0);

        IDebugClient client = (IDebugClient)debugClientIUnknown;
        IDebugControl control = (IDebugControl)debugClientIUnknown;
        int hr = client.OpenDumpFile(@"crash.dmp");
        Debug.Assert(hr == 0);
        hr = control.WaitForEvent(DEBUG_WAIT.DEFAULT, 5000);
        Debug.Assert(hr == 0);

        using (DataTarget target = DataTarget.CreateFromDebuggerInterface(client))
        {
            // TODO
        }
    }

    [DllImport("dbgeng.dll")]
    public static extern int DebugCreate(ref Guid InterfaceId, [MarshalAs(UnmanagedType.IUnknown)] out object Interface);
}

Similarly, you can look in the ClrMD source's test infrastructure to see more examples of using DbgEng (specifically https://github.com/Microsoft/clrmd/blob/master/src/Microsoft.Diagnostics.Runtime.Tests/Debugger.cs and things that call it). However, DbgEng itself (IDebugClient and related interfaces) is a Microsoft library independent from ClrMD, so you should consult its documentation on how to use it...

Does this address your concern?

from clrmd.

keithfink avatar keithfink commented on May 21, 2024

Hi Lee,
Thank you for the response! Yes, this is certainly helpful. I actually figured this out yesterday morning and the key was the call to WaitForEvent. Once I added that, it started working.
The reason I used this approach is because in addition to all the great things ClrMd offer, I would also like to be able to execute debugger commands via IDebugControl::Execute / ExecuteWide. I didn't see an API exposed in ClrMd for actually executing commands through the engine, so that's why I went with this approach. Though I suppose I could just cast the DataTarget.DebuggerInterface to an IDebugControl. Hmm... I wonder I didn't do that to start with.
Thanks for all the great work here. I am writing some diagnostic tooling for our company and ClrMd is a fantastic help. Before this, I worked for Microsoft Developer Support for many years so am very familiar with sos, psscor, windbg, etc. (though this is my first attempt at using the dbgeng API).

Thanks,

Keith
Date: Thu, 12 Nov 2015 18:28:25 -0800
From: [email protected]
To: [email protected]
CC: [email protected]
Subject: Re: [clrmd] DataTarget.CreateFromDebuggerInterface Throws Exception (#32)

Apologies for the delay in responding, it's been a busy week. I suppose this should be better documented, but CreateFromDebuggerInterface expects that you have set up IDebugClient in a way such that it is ready to be used. The HRESULT is the giveaway: 0x8000fff is the "catastrophic" error code that dbgeng hands out when it's not ready for the APIs that are called. The goal with this API is to allow you to construct a DataTarget from a DbgEng debugger session.

Here is a minimal example of it working properly:

using Microsoft.Diagnostics.Runtime;
using Microsoft.Diagnostics.Runtime.Interop;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

class Program
{
static void Main(string[] args)
{
Guid debugClientGuid = typeof(IDebugClient).GUID;
object debugClientIUnknown;
int hr = DebugCreate(ref debugClientGuid, out debugClientIUnknown);
Debug.Assert(hr == 0);

    IDebugClient client = (IDebugClient)debugClientIUnknown;
    IDebugControl control = (IDebugControl)debugClientIUnknown;
    int hr = client.OpenDumpFile(@"crash.dmp");
    Debug.Assert(hr == 0);
    control.WaitForEvent(DEBUG_WAIT.DEFAULT, 5000);
    Debug.Assert(hr == 0);

    using (DataTarget target = DataTarget.CreateFromDebuggerInterface(client))
    {
        // TODO
    }
}

[DllImport("dbgeng.dll")]
public static extern int DebugCreate(ref Guid InterfaceId, [MarshalAs(UnmanagedType.IUnknown)] out object Interface);

}

Similarly, you can look in the ClrMD source's test infrastructure to see more examples of using DbgEng (specifically https://github.com/Microsoft/clrmd/blob/master/src/Microsoft.Diagnostics.Runtime.Tests/Debugger.cs and things that call it). However, DbgEng itself (IDebugClient and related interfaces) is a Microsoft library independent from ClrMD, so you should consult its documentation on how to use it...

Does this address your concern?


Reply to this email directly or view it on GitHub.

from clrmd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.