Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WinDbg and C# application

470 views
Skip to first unread message

George

unread,
Jul 4, 2008, 6:48:01 AM7/4/08
to
Hello everyone,


When I use bu or bm to set a breakpoint into a process running C#, there is
always error message like -- "Operation not supported by integrated managed
debugging."

How to make WinDbg support .Net application debug?

(I made a search to find some similar questions, but not quite helpful.)


thanks in advance,
George

Brian Rasmussen [C# MVP]

unread,
Jul 4, 2008, 7:28:56 AM7/4/08
to
You need to load sos.dll to make WinDbg work with managed code. John Robbins
wrote an introduction you may find helpful:
http://msdn.microsoft.com/en-us/magazine/cc164138.aspx

Regards,
Brian Rasmussen [C# MVP]

"George" <Geo...@discussions.microsoft.com> wrote in message
news:C53AF2D2-F346-4DF2...@microsoft.com...

George

unread,
Jul 4, 2008, 7:50:00 AM7/4/08
to
Thanks Brian!


I have using .load to load the SOS package. And I have tried I can use
extension commands like !threads.

But when I use bu or bm to set a breakpoint, for example, bu Foo (Foo is a
function in class FooUtility), there is error message like -- "Operation not
supported by integrated managed debugging.". How to solve it?


regards,
George

Brian Rasmussen [C# MVP]

unread,
Jul 4, 2008, 1:53:19 PM7/4/08
to
You have to use special breakpoint commands for managed code. Sos includes a
!bpmd command, but it's rather limited. If you add sosex.dll as well, you'll
be a little better off, but for this type of debugging Visual Studio gives
you a lot more. John Robbins wrote a post regarding sosex.dll and
breakpoints which you can find here:
http://www.wintellect.com/cs/blogs/jrobbins/archive/2007/06/19/great-sosex-a-phenomenal-net-debugging-extension-to-see-the-hard-stuff-steve-johnson-is-my-hero.aspx

--

Regards,
Brian Rasmussen [C# MVP]

http://kodehoved.dk


"George" <Geo...@discussions.microsoft.com> wrote in message

news:8F74849D-09F3-4530...@microsoft.com...

George

unread,
Jul 6, 2008, 8:23:00 AM7/6/08
to
Thanks Brian,


Great help! I have tried !bpmd works. So, the root cause is bm/bu only works
for unmanaged code, and for managed code I have to use !bpmd, correct?

(sorry for asking this simple question, I am previous migrated from
unmanaged C++ developer to C# developer.)


regards,
George

Brian Rasmussen [C# MVP]

unread,
Jul 6, 2008, 8:53:32 AM7/6/08
to
Well, your managed code eventually ends up as regular code after being
JITed. This code is just like any other code and can be
inspected/manipulated by WinDbg as needed. However, to handle managed code
as managed code WinDbg needs a little help from e.g. sos and sosex.

--
Regards,
Brian Rasmussen [C# MVP]
http://kodehoved.dk

"George" <Geo...@discussions.microsoft.com> wrote in message

news:1D07140C-B420-415E...@microsoft.com...

George

unread,
Jul 6, 2008, 9:17:00 AM7/6/08
to
Thanks Brian,


1.

Does it mean bu/bm command can not be used in managed code even if I load SOS?

(I have to use !bpmd to set break point in managed code)

2.

Here is another question about using !bpmd with managed code, if you have
time, could you take a look please? :-)

http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.windbg&tid=9cc02d99-757d-46d8-abcb-3060b25e89db&cat=en_us_71ae2d42-79fc-41e7-919b-2aa531b66ae6&lang=en&cr=us&sloc=&p=1


regards,
George

Marc Sherman

unread,
Jul 7, 2008, 11:28:49 AM7/7/08
to
"George" <Geo...@discussions.microsoft.com> wrote in message
news:4993BFA0-CCE7-43CC...@microsoft.com...

> Thanks Brian,
>
>
> 1.
>
> Does it mean bu/bm command can not be used in managed code even if I load
> SOS?
>
> (I have to use !bpmd to set break point in managed code)

Once the managed function is JITed, you can use bu on the address of the
JITed function. But you cannot use bu on the managed function name.

Marc

George

unread,
Jul 8, 2008, 1:44:00 AM7/8/08
to
Thanks Marc,


Basically I agree with you. The issue is, how (from developer point of view)
you know the JITed function name if you developing C# (or other managed
code)? :-)


regards,
George

Marc Sherman

unread,
Jul 8, 2008, 9:36:30 AM7/8/08
to
"George" <Geo...@discussions.microsoft.com> wrote in message
news:D677D274-C19B-4F6D...@microsoft.com...

> Basically I agree with you. The issue is, how (from developer point of
> view)
> you know the JITed function name if you developing C# (or other managed
> code)? :-)

From my limited experience, The JITed function name and containing assembly
can be recovered using `!sos.ip2md <address>` where <address> is an address
which lies within the JITed function.

ps. When replying please include enough text of the post to which you're
replying in order to provide adequate context.

Marc


George

unread,
Jul 9, 2008, 2:25:01 AM7/9/08
to
Thanks Marc,


Here is my code, and I want to learn from you how to use !sos.ip2md to
convert from native JITed address to managed symbol name. Could you show me a
sample please? (I have tried a couple of times, but failed to find how to use
the command.)

[Code]
namespace TestDebugManaged1
{
class Program
{
public void foo()
{
int a = 100;
while (true)
{
Thread.Sleep(10000);
a++;
}
}

static void Main(string[] args)
{
Program instance = new Program();
instance.foo();
return;
}
}
}
[/Code]


regards,
George

Marc Sherman

unread,
Jul 9, 2008, 9:31:01 AM7/9/08
to
"George" <Geo...@discussions.microsoft.com> wrote in message
news:6CEBF1FE-08F7-4E71...@microsoft.com...

if `Thread.Sleep()` eventually calls kernel32!Sleep(), then set a breakpoint
there with `bu kernel32!Sleep`. Once that breakpoint is hit get a stack
trace with `kb`. Then, for each stack frame that looks like a it was called
from a managed frame, do a `ip2md <retrurn address>`.

Marc


George

unread,
Jul 10, 2008, 10:34:02 PM7/10/08
to
Great Marc!


I have checked SleepEx other than Sleep is called. :-)

Here is my call stack. I am interested in two points,

1.

"Then, for each stack frame that looks like a it was called from a managed

frame" -- if the stack is from mscorwks.dll, is means it is called from a
managed frame?

2.

I have tried one return address and using !ip2md, and seems it is not
working. Any ideas?

0:004> !ip2md 00000642`7f5c2cf5
Failed to request MethodData, not in JIT code range

--------------------
Child-SP RetAddr Call Site
00000000`0012eca8 00000000`77d705d6 ntdll!ZwDelayExecution+0xa
00000000`0012ecb0 00000642`7f497fd9 KERNEL32!SleepEx+0xaf
00000000`0012ed50 00000642`7f5c2cf5 mscorwks!EESleepEx+0x31
00000000`0012edd0 00000642`7f5c32e2 mscorwks!Thread::UserSleep+0x79
00000000`0012ee30 00000642`80150271 mscorwks!ThreadNative::Sleep+0x116
00000000`0012efe0 00000642`80150182 0x642`80150271
00000000`0012f020 00000642`7f67d4a2 0x642`80150182
00000000`0012f060 00000642`7f5108f5 mscorwks!CallDescrWorker+0x82
00000000`0012f0b0 00000642`7f522ff6 mscorwks!CallDescrWorkerWithHandler+0xe5
00000000`0012f150 00000642`7f49a94b mscorwks!MethodDesc::CallDescr+0x306
00000000`0012f380 00000642`7f474ae4 mscorwks!ClassLoader::RunMain+0x23f
00000000`0012f5e0 00000642`7f5efb1a mscorwks!Assembly::ExecuteMainMethod+0xbc
00000000`0012f8d0 00000642`7f467d97
mscorwks!SystemDomain::ExecuteMainMethod+0x492
00000000`0012fea0 00000642`7f482c24 mscorwks!ExecuteEXE+0x47
00000000`0012fef0 00000642`7ee69ade mscorwks!_CorExeMain+0xac
00000000`0012ff50 00000000`77d5964c mscoree!_CorExeMain+0x3e
00000000`0012ff80 00000000`00000000 KERNEL32!BaseProcessStart+0x29
--------------------


regards,
George

Marc Sherman

unread,
Jul 11, 2008, 9:31:59 AM7/11/08
to

"George" <Geo...@discussions.microsoft.com> wrote in message
news:5E23E16E-3171-4BFB...@microsoft.com...

> Great Marc!
>
>
> I have checked SleepEx other than Sleep is called. :-)
>
> Here is my call stack. I am interested in two points,
>
> 1.
>
> "Then, for each stack frame that looks like a it was called from a managed
> frame" -- if the stack is from mscorwks.dll, is means it is called from a
> managed frame?
>
> 2.
>
> I have tried one return address and using !ip2md, and seems it is not
> working. Any ideas?
>
> 0:004> !ip2md 00000642`7f5c2cf5
> Failed to request MethodData, not in JIT code range

Try 00000642`80150271 and 00000642`80150182

Marc

George

unread,
Jul 13, 2008, 8:28:07 AM7/13/08
to
Great Marc!


I have tried. And it works. Here are the output. Two more comments,

1.

Why the 2 address you pointed out works, but the address I used before
00000642`7f5c2cf5 is not working?

2.

Normally how to utilize the result returned by !ip2md? I have tried to find
help but seems the help of the command in not in debugger.chm. Do you have
any documents?

WinDbg output

--------------------
0:000> !ip2md 00000642`80150271
MethodDesc: 0000064280013568
Method Name: TestDebugManaged1.Program.foo()
Class: 00000642801421c0
MethodTable: 0000064280013580
mdToken: 06000001
Module: 0000064280012e20
IsJitted: yes
m_CodeOrIL: 0000064280150230
0:000> !ip2md 00000642`80150182
MethodDesc: 0000064280013570
Method Name: TestDebugManaged1.Program.Main(System.String[])
Class: 00000642801421c0
MethodTable: 0000064280013580
mdToken: 06000002
Module: 0000064280012e20
IsJitted: yes
m_CodeOrIL: 0000064280150120
--------------------


regards,
George

Marc Sherman

unread,
Jul 14, 2008, 9:25:41 AM7/14/08
to
"George" <Geo...@discussions.microsoft.com> wrote in message
news:529701E9-A3C1-452C...@microsoft.com...

> Great Marc!
> I have tried. And it works. Here are the output. Two more comments,
>
> 1.
>
> Why the 2 address you pointed out works, but the address I used before
> 00000642`7f5c2cf5 is not working?

Probably because it was not in a JITed code range.

>
> 2.
>
> Normally how to utilize the result returned by !ip2md? I have tried to
> find
> help but seems the help of the command in not in debugger.chm. Do you have
> any documents?

try `!sos.help`

Marc


George

unread,
Jul 14, 2008, 11:12:00 PM7/14/08
to
Thanks Mark,


1.

JITed code range means it is native code which is generated from managed
code at runtime?

2.

Looks like SOS help is not working, But I have checked the SOS chain is
installed. Here is my WinDbg output, any ideas?

0:000> !sos.help
The call to LoadLibrary(sos) failed, Win32 error 0n2
"The system cannot find the file specified."
Please check your debugger configuration and/or network access.
0:000> .chain
Extension DLL chain:
C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\sos.dll: image
2.0.50727.1433, API 1.0.0, built Wed Oct 24 13:22:20 2007
[path: C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\sos.dll]


regards,
George

0 new messages