Comments (2)
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.
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)
- ClrMD should stop using HResult as a PInvoke return HOT 4
- [macOS] task_for_pid failing with `0x5` HOT 6
- HotColdInfo.HotSize is missing in v2 (it's present in v1) HOT 1
- CLRMD fails to load coreclr 7.0 dump - PEImage.Read() doesn't update offset HOT 1
- CLRMD fails to load coreclr 7.0 dump - PEImage.Read() does not apply fixups HOT 3
- Disparity in Objects... HOT 1
- COMException in CacheNativeMethods.Util.EnableDisablePrivilege HOT 2
- Links on FAQ page broken...
- Getting IL and Native Code Addresses... HOT 3
- Windows arm64 support HOT 5
- The license disorientation HOT 1
- ClrMD is moving to dotnet/diagnostics HOT 1
- ClrMD 3.0 will be the next release
- Get ClrValueType similar to !DumpVC HOT 3
- This repo is missing important files
- Could not find matching DAC for process on macOS after switching to ClrMD 2.1
- ILOffsetMap points to QuickJitted assembly code even after method has been Tier-1 compiled (.NET 7+) HOT 1
- Where are the release notes for ClrMD 3.0 ? HOT 3
- Threads are not update after flush HOT 3
- Unable to create DACLibrary for minidump from self contained app HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clrmd.