Wednesday, July 30, 2008

Windbg cheat-sheet

*** steps to find an exception

.symfix
.sympath+
.reload
sxd *
.loadby sos mscorwks
!threads
kp
!do *throwable*
!do *_stackTraceString*

*** debugging dump

lmv mmscorwks
.reload /f mscorwks.dll
!load sos
!threads
!clrstack
!pe -nested

*** setup

.sympath srv*g:\binaries*http://msdl.microsoft.com/download/symbols
.reload
.symfix
ld -> loads module symbols
ld moduleName
.loadby sos mscorwks

*** memory

d
dw
dd
dd /c 1 00401060 -> display dwords in 1 column from address 00401060
db
da -> ascii
du -> unicode
dds myFunction -> try to resolve symbol
dv -> display variables (needs symbols)
dv /V
dt -> display type
dt _EXCEPTION_POINTERS
ln -> list near

*** search

s -> search memory
s -a 77f75acc L80 "B" -> searches from 77f75acc to 77f75acc+80 for the ascci 'B'
s 77f75acc L80 42 40 3a -> searches from 77f75acc to 77f75acc+80 for the string 42, 40 and 3a
x -> search symbols
x *! -> list of all the modules in the process with their beginning and ending memory locations
x *!my* -> list the functions that start with 'my' in all modules
x my!* -> list the functions in 'my' module

*** registers

r
rm

*** step

g -> go until breakpoint
p -> step
t -> step into
gu -> step out
pa -> st
ta -> trace into to address
.restart
bp function -> set breakpoint
bp function "command" (ex.: bp kernel32!CreateFileW "du poi(esp+4); g")
bp address

*** stack

k
kP
.frame
kb 50 -> show 50 frames
~*k5 -> for each thread, show 5 frames

*** assembly

u -> unassemble function
uf myFunction
!u -> unassemble managed function

*** exceptions

sxe ld (to disable sxd)
sxe clr -> break in CLR exceptions

*** windows

!gle -> GetLastError()

*** dumps

!threads
!DumpObj = !do
!DumpStackObjects
!dt
!dso
!pe -nested
!peb
.cordll -u -l
!dumpheap -type theType

*** dumps (2)

lmv mmscorwks
Find matching package at \\server\share and copy all files (except symbols) to c:\debuggers folder
.loadby sos mscorwks (or, if doesn't work, .load %debuggers%\sos.dll)
May need to execute .cordll –u –l

*** help

!help

*** sources

.srcpath
.lines
.l+, .l-

*** security descriptor

!object \BaseNamedObjects\CLR_CASOFF_MUTEX
dt nt!_OBJECT_HEADER objHeader
?? SecurityDescriptor & ~0x7
!sd *result* 1

*** kernel dbg setup

in Vista:
bcdedit /bootdebug ON
bcdedit /dbgsettings SERIAL DEBUGPORT:1 BAUDRATE:115200
in XP: in boot.ini
/debug /debugport=com1 /baudrate=115200
connect Vista to box XXX with a null cable
in XXX
- kd.exe -server tcp:port=999 -k com:port=com1,baud=115200
- from windbg: .server tcp:port=999

restart Vista
to start debugging, kd.exe -remote tcp:server=serverboxname,port=999

From WinPE:

bcdedit /store c:\boot\bcd -enum -v
GUID corresponding to Vista -> {GUID}
bcdedit /store c:\boot\bcd –debug {GUID} on

*** kernel dbg

!stacks -> list threads
!locks -> lists locks

*** SOS commands

Object Inspection
-----------------------------
DumpObj (do)
DumpArray (da)
DumpStackObjects (dso)
DumpHeap
DumpVC
GCRoot
ObjSize
FinalizeQueue
PrintException (pe)
TraverseHeap

Examining CLR data structures
-----------------------------
DumpDomain
EEHeap
Name2EE
SyncBlk
DumpMT
DumpClass
DumpMD
Token2EE
EEVersion
DumpModule
ThreadPool
DumpAssembly
DumpMethodSig
DumpRuntimeTypes
DumpSig
RCWCleanupList
DumpIL

Examining code and stacks
-----------------------------
Threads
CLRStack
IP2MD
U
DumpStack
EEStack
GCInfo
EHInfo
COMState
BPMD

Diagnostic Utilities
-----------------------------
VerifyHeap
DumpLog
FindAppDomain
SaveModule
GCHandles
GCHandleLeaks
VMMap
VMStat
ProcInfo
StopOnException (soe)
MinidumpMode

Thursday, May 15, 2008

IIS: RPS suddendly drops to zero while serving static files

Problem: while running tests on an IIS web site, RPS dropped to zero, then came back up, etc.

Solution: NTFS may be causing disk I/O to be the bottleneck by logging reads to those static files. Try setting

HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\NtfsDisableLastAccessUpdate

to 1 (DWORD), reboot (not sure which services need to be restarted for avoiding a reboot...), and try.

More details here.

Monday, April 14, 2008

Debugging: No Locals, Breakpoint not being hit, etc in Visual Studio

Problem: sometimes, VS has trouble seeing Locals for optimized assemblies. Also, even with symbols loaded for a module, a breakpoint is not hit. Or you attach to the w3wp.exe process only to not see your module as loaded (and you know it is).

Solution: say your assembly is My.dll

  1. Create a file called My.ini
  2. Put this content into that file:
  3. [.Net Framework Debugging Control]
    AllowOptimize=0
    GenerateTrackingInfo=1

  4. Copy the .ini file to the location of the assembly in the GAC

Tuesday, March 25, 2008

Performance: ASP.NET process not being registered by vsperfmon

Problem: by following these instructions: TN_1206: Profiling ASP.NET in instrumentation mode from the command line, I was not getting the w3wp.exe process being registered by vsperfmon, so no .vsp file was being generated.

Solution: make sure to call vsperfmon with the /crosssession parameter

Wednesday, January 16, 2008

SharePoint: Enabling Anonymous Access on a Site Collection

First, you need to configure the web application for anonymous access:

  1. go to Central Administration
  2. go to Application Management
  3. click on Authentication Providers
  4. choose the Web Application the site collection lives into
  5. click on the zone for the specified provider
  6. check Enable Anonymous Access and Save

Then, you need to enable anonymous access in the specific site collection:

  1. Go to Site Actions Site Settings Modify All Site Settings
  2. Click on Advanced Permissions
  3. Click on Settings Anonymous Access
  4. choose desired anonymous access, then OK

Tuesday, December 25, 2007

WCF with Transport security and self-signed certificate

Say you want to create a secure WCF channel and not having the client verifying the server's certificate (maybe because you are testing or the server's certificate is self-signed and you don't want to install that certificate in the client's trusted certificate's store).

1) Configure the server this way:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="MyContract">
<endpoint
address=""
binding="basicHttpBinding"
bindingConfiguration="NtlmSecurity"
contract="IMyContract" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="NtlmSecurity">
<security mode="Transport">
<transport clientCredentialType ="Ntlm" />
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>


2) Force not verifying the server's certificate. WARNING: this is intended only for test purposes. In production code, you don't want to avoid checking server's certificate at all.

private IMyContract GetChannel(Uri address)
{
// Create an endpoint address
EndpointAddress endpoint = new EndpointAddress(address);

// Create a binding
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;

ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(
delegate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
{
return (true);
});

// Create a channel to the service application endpoint
ChannelFactory<imycontract> factory = new ChannelFactory<IMyContract >(binding, endpoint);
return factory.CreateChannel();
}

Friday, December 21, 2007

SharePoint: How to add a web part to a page from a solution package

Assume you already got a solution package (.wsp) of the web part.

First, you have to install it:

SET STSADM="%full path%\STSADM.EXE"
SET URL="http://urlOfMySite"
SET SPACK="myWebPart.wsp"

%STSADM% -o retractsolution -name %SPACK% -immediate -url %URL%
%STSADM% -o execadmsvcjobs

%STSADM% -o deletesolution -name %SPACK% -override
%STSADM% -o execadmsvcjobs

%STSADM% -o addsolution -filename %SPACK%
%STSADM% -o execadmsvcjobs

%STSADM% -o deploysolution -name %SPACK% -immediate -allowgacdeployment -url %URL%
%STSADM% -o execadmsvcjobs

Then, from the site where you want to add the web part to a page:

Site Actions | Site Settings | Modify All Site Settings | Galleries | Web Parts, New
Choose your web part, click "Populate Gallery"

Then,

Site Actions | Site Settings | Modify All Site Settings | Site Collection Administration | Site Collection Features, click "Activate" to activate your web part

Then, you should be able to add your web part to a page on that site:

Navigate to a page
Site Actions | Edit Page, Add a Web Part, choose your web part, Add, Publish