dotnet clr:
I'm trying to use windbg's "!htrace" command to find the source of a
handle leak in a C# app I have. To understand the !htrace output, I
have created a little sample app that just opens a file:
static void Main(string[] args)
{
FileStream fs =3D File.OpenRead(@"c:\foo.txt");
Console.ReadLine(); // don't exit app
}
I then started my app, and I can see in process explorer that the file
handle for "foo.txt" is 0x2FC. So I start windbg and attach to the
app, and do "!htrace 2fc", which complains about symbols for
mscorlib.dll, but does give a stack trace (below).
Unfortunately, the htrace stack isn't very helpful. I was hoping to
see the symbols from my C# code somewhere in there (like
"ScratchConsoleApp.Class1.Main=AD").
I asked this question over in the microsoft.public.windbg group and got
an explanation about why my C# symbols don't show up in the !htrace
stack dump. I understand it, but I am still wondering if it's possible
to translate an address from the !htrace stack into a JIT-ed method.
In other words, I just want to figure out what code was responsible for
allocating the handle.
It looks like the !IP2MD command does something similar but when I
entered some addresses from the stack, it said it was not a valid
address (or something to that effect).
Can this be done?
PS> For what it's worth, I have loaded the SOS extensions and I can get
a full C# stack trace from !ClrStack just fine (also below).
-----------------------------------------------------
0:000> !htrace 2fc
------------------------------=AD--------
Handle =3D 0x000002FC - OPEN
Thread ID =3D 0x00000A58, Process ID =3D 0x00000EB8
0x0208A0D5: +0x0208A0D5
*** WARNING: Unable to verify checksum for
c:\windows\assembly\nativeimag=ADes1_v1.1.4322\mscorlib\1.0.500=AD0.0__b77a=
5c561934e089_4cd9dcc5=AD\mscorlib.dll
*** ERROR: Module load completed but symbols could not be loaded for
c:\windows\assembly\nativeimag=ADes1_v1.1.4322\mscorlib\1.0.500=AD0.0__b77a=
5c561934e089_4cd9dcc5=AD\mscorlib.dll
0x799B49DD: mscorlib_79990000+0x000249DD
0x799DE5BE: mscorlib_79990000+0x0004E5BE
0x791D94BC: mscorwks!CallDescrWorker+0x000=AD00030
0x791ED194: mscorwks!MethodDesc::CallDescr=AD+0x000001B8
0x791ED54B: mscorwks!MethodDesc::CallDescr=AD+0x0000004F
0x791ED5B9: mscorwks!MethodDesc::Call+0x00=AD000097
0x7921D82B: mscorwks!ClassLoader::CanAcces=ADs+0x000001D6
0x7921DA72: mscorwks!ClassLoader::ExecuteM=ADainMethod+0x0000049D
-----------------------------------------------------
0:000> !ClrStack
Thread 0
ESP EIP
0x0012f5d8 0x7c90eb94 [FRAME: NDirectMethodFrameStandalone] [DEFAULT]
I4 System.IO.__ConsoleStream.Read=ADFile(I,Ptr UI1,I4,ByRef I4,I)
0x0012f5f4 0x79aa78c9 [DEFAULT] I4
System.IO.__ConsoleStream.Read=ADFileNative(I,SZArray UI1,I4,I4,I4,ByRef
I4)
0x0012f620 0x79aa7762 [DEFAULT] [hasThis] I4
System.IO.__ConsoleStream.Read=AD(SZArray UI1,I4,I4)
0x0012f640 0x799ea04f [DEFAULT] [hasThis] I4
System.IO.StreamReader.ReadBuf=ADfer()
0x0012f64c 0x799e9f02 [DEFAULT] [hasThis] String
System.IO.StreamReader.ReadLin=ADe()
0x0012f660 0x79ab15ab [DEFAULT] [hasThis] String
System.IO.TextReader/SyncTextR=ADeader.ReadLine()
0x0012f668 0x79a097a5 [DEFAULT] String System.Console.ReadLine()
0x0012f68c 0x0251007b [DEFAULT] Void
ScratchConsoleApp.Class1.Main(=ADSZArray String)
at [+0x23] [+0x10] c:\dev\test\cs\scratchconsolea=ADpp\class1.cs:12
0x0012f8b0 0x791d94bc [FRAME: GCFrame]
0x0012f9b0 0x791d94bc [FRAME: GCFrame]
0x0012fa94 0x791d94bc [FRAME: GCFrame]