<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-24686577</id><updated>2011-07-08T03:08:48.404Z</updated><category term='FamilyLife'/><title type='text'>I'll think of a name later...</title><subtitle type='html'>Aide memoire.
Developing, debugging, cries for help...</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://kerneldanb.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24686577/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://kerneldanb.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Dan</name><uri>http://www.blogger.com/profile/17203824346657072247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_qcToVRgg4NQ/SqVa9n6KfLI/AAAAAAAAAAM/zPIAcTVHYzY/S220/dan.png'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-24686577.post-6046133421606081352</id><published>2009-10-29T09:50:00.004Z</published><updated>2009-10-29T09:59:41.694Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='FamilyLife'/><title type='text'></title><content type='html'>&lt;div&gt;&lt;b&gt;Control&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;This morning, my wife (who is three quarters of the way through a chemotherapy course to treat her leukaemia) observed &lt;div&gt;"If I attempt movements that involve fine motor control, I start to shake".&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I wasn't paying close attention to what she was doing, so simply responded &lt;/div&gt;&lt;div&gt;"Stick to gross movements then" &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;to which she replied:&lt;/div&gt;&lt;div&gt;"If I do that, I'll end up with mascara in my ears!"&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/24686577-6046133421606081352?l=kerneldanb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kerneldanb.blogspot.com/feeds/6046133421606081352/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=24686577&amp;postID=6046133421606081352' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24686577/posts/default/6046133421606081352'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24686577/posts/default/6046133421606081352'/><link rel='alternate' type='text/html' href='http://kerneldanb.blogspot.com/2009/10/control-this-morning-my-wife-who-is.html' title=''/><author><name>Dan</name><uri>http://www.blogger.com/profile/17203824346657072247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_qcToVRgg4NQ/SqVa9n6KfLI/AAAAAAAAAAM/zPIAcTVHYzY/S220/dan.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-24686577.post-114331009201940366</id><published>2006-03-25T18:02:00.000Z</published><updated>2006-03-26T00:52:45.506Z</updated><title type='text'></title><content type='html'>Finding/counting instances of (leaked) C++ classes in crash dumps using WinDbg.&lt;br /&gt;&lt;br /&gt;When dealing with memory leaks you have an armoury of stuff at your disposal: debugging versions of memory allocation routines, leak tracking tools from Microsoft (see &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=9bfa49bc-376b-4a54-95aa-73c9156706e7&amp;DisplayLang=en"&gt;DebugDiag&lt;/a&gt; and &lt;a href="http://support.microsoft.com/kb/268343/"&gt;UMDH&lt;/a&gt;) and others.&lt;br /&gt;&lt;br /&gt;An additional technique that I've used with some success (when for various reasons the above techniques are not immediately available) on full crash dumps is to go hunting for instances of C++ classes that I suspect may be being leaked.&lt;br /&gt;&lt;br /&gt;Note that this technique only works for classes that contain virtual functions, and you'll need your symbols to be lined up properly.&lt;br /&gt;&lt;br /&gt;Consider how a C++ class instance with (virtual functions) is typically laid out in memory:  it starts with a pointer to a virtual function table, followed by the member data of the class.  The values stored in the member data for different instances of the same class will vary, but the pointer to the virtual function table will be invariant.&lt;br /&gt;&lt;br /&gt;That's nice: it means that if we know the whereabouts in memory of the virtual function table for a particular class, we can go hunting in memory for instances of that class.  We can find out whereabouts in memory the virtual function table is by asking &lt;a href="http://www.microsoft.com/whdc/devtools/debugging/default.mspx"&gt;WinDbg&lt;/a&gt;.  The X command is what we need here.  Let's say we want to find the address of the virtual function table for class CMyClass in module mylibrary.dll. We can ask WinDbg to tell us by executing the command&lt;br /&gt;&lt;br /&gt;x mylibrary!CMyClass::*vftable*&lt;br /&gt;&lt;br /&gt;The * characters above are wildcards - I find it faster to type * than the more correct ` (backtick) character and it's also useful to know if there's more than one virtual function table associated with the class.&lt;br /&gt;&lt;br /&gt;WindDbg will list the addresses of all the virtual function tables in the CMyClass class - there may be more than one if you are dealing with multiple inheritance and/or nested classes.  For now, let's assume that there's only one.  You should see something like this:&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;0123abc4 mylibrary!CMyClass::`vftable' = &lt;no&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:georgia;"&gt;Thus we know that we need to look for the address 0123abc4.  We also need to know &lt;span style="font-style: italic;"&gt;where&lt;/span&gt; to look in memory.  Microsoft's &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=9bfa49bc-376b-4a54-95aa-73c9156706e7&amp;DisplayLang=en"&gt;DebugDiag&lt;/a&gt; tool is handy here: running it's memory analysis script over your dump will let you know which heaps belong to which modules, where their segments are located in memory and other interesting things. &lt;/span&gt;&lt;/no&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="font-family:georgia;"&gt;The WinDbg !heap metacommand is also useful for listing the heap segments, but it won't tell you which heap belongs to which module. &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="font-family:georgia;"&gt;&lt;br /&gt;&lt;br /&gt;Armed with this heap segment addresses and a virtual function table address, you can go hunting for instances of your class in the appropriate segment(s) in memory.   &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="font-family:georgia;"&gt;The WinDbg s (for search) command is what we need here - and we also need  to have a WinDbg log file open before we start in case there's a lot to be found.   Say we have discovered that mylibrary has a nice big heap segment from 0d000000 to 0d400000, we can search it for CMyClass instances with the command&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;s -d &lt;/span&gt;&lt;/span&gt;0d000000 0d400000 0123abc4&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="font-family:georgia;"&gt;&lt;br /&gt;Of course, it helps if you have a reasonable idea of the number of CMyClass instances to expect at this stage of the game, so you can tell if you find too many.  Note also that if you do have a leak, its possible (likely, even) that the leaked instances will be splattered across multiple heap segments, so you'll want to search in all the heap segments associated with your module.&lt;br /&gt;&lt;br /&gt;I often use a perl script to convert the output of the !heap command into a little batch file of commands to feed into WinDbg via the $$&lt; command. &lt;br /&gt;&lt;br /&gt;One other useful thing: often you may not know which class (or classes) are being leaked.  You might get lucky with the information that DebugDiag provides about sizes of memory allocations.   DebugDiag will tell you the most frequently occurring allocation sizes, and the sizes of allocations associated with the greatest memory consumption.  You can use the C++ sizeof(...) expression in WinDbg with the C++ expression evaluator thus: &lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;?? sizeof(mylibrary!CMyClass)  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;to see if the size of instances of CMyClass agrees with what DebugDiag tells you about the most frequently allocated size.  A better thing to do is to ask WinDbg to tell you the names of ALL the classes in your module, then run sizeof on each of them. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;x mymodule::*vftable*&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;is your friend here if you have more classes to deal with than you can comfortably enumerate by hand. Note that won't be all the C++ classes, just those with virtual functions).  I use a perl script to produce a list of class name/size of instance pairs sorted by size to give a good list of candidate class types to start hunting for. &lt;br /&gt;&lt;br /&gt;As I said originally, I've had some success with this "hunt the vftable" technique.  Your mileage may vary. Happy hunting!  &lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/24686577-114331009201940366?l=kerneldanb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kerneldanb.blogspot.com/feeds/114331009201940366/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=24686577&amp;postID=114331009201940366' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24686577/posts/default/114331009201940366'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24686577/posts/default/114331009201940366'/><link rel='alternate' type='text/html' href='http://kerneldanb.blogspot.com/2006/03/findingcounting-instances-of-leaked-c.html' title=''/><author><name>Dan</name><uri>http://www.blogger.com/profile/17203824346657072247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_qcToVRgg4NQ/SqVa9n6KfLI/AAAAAAAAAAM/zPIAcTVHYzY/S220/dan.png'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-24686577.post-114323981386252810</id><published>2006-03-24T21:31:00.000Z</published><updated>2006-03-25T17:53:43.820Z</updated><title type='text'>First go...recovering a call stack in WinDbg</title><content type='html'>I thought I'd write a bit about the fun I've had with debugging.  This is mostly for my benefit, but if it helps you too, then whoopedoo.&lt;br /&gt;&lt;br /&gt;If you're not already familiar with WinDbg, two really great places to go for information are John Robbins excellent book "&lt;a href="http://www.amazon.co.uk/exec/obidos/ASIN/0735615365/qid=1143307457/sr=1-1/ref=sr_1_2_1/203-5916368-5948767"&gt;Debugging applications for Microsoft .Net and Microsoft Windows&lt;/a&gt;" and Tess Fernandez's blog "&lt;a href="http://blogs.msdn.com/tess/"&gt;If broken it is, fix it you should&lt;/a&gt;".&lt;br /&gt;&lt;br /&gt;Mostly I've been wrasslin' with Microsoft's &lt;a href="http://www.microsoft.com/whdc/devtools/debugging/default.mspx"&gt;WinDbg&lt;/a&gt;, trawling through crash  dumps with my "Wha' 'appen?" hat on.  These sessions tend to go in fits and starts as there are occassional (blessed) hiatuses when the system doesn't need my undivided attention.  Following a gap between debugging sessions the anaesthetics of time and family life conspire to drain my memory  and I usually spend the first few minutes of analyzing a new dump in an unproductive haze.  I've done this often enough to think "I gotta write some of this stuff down somewhere I can find it again."&lt;br /&gt;&lt;br /&gt;I tend to deal with crash dumps from COM+ packages that have gone south, and one of the things I forget most frequently is "How do I recover the stack trace when COM+ has caught an exception?"&lt;br /&gt;&lt;br /&gt;First things first: get your symbols straight.  This used to be fiddly (for me, being a bear of very little brain), but since Microsoft made their symbols available on the net and made the symbol server available to us reg'lar folks it's pretty straightforward.   &lt;a href="http://www.microsoft.com/whdc/devtools/debugging/debugstart.mspx"&gt;Read the docs&lt;/a&gt;, point at Microsoft's symbols, set your own symbol server up and move along. You only gotta do this once, and if you're really lucky you can get one of your &lt;strike&gt;minions&lt;/strike&gt; (sorry Neil:) colleagues to do it for you - it's a public service, and we all feel the benefit.&lt;br /&gt;&lt;br /&gt;An early port of call is Microsoft's excellent DebugDiag tool available &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=9bfa49bc-376b-4a54-95aa-73c9156706e7&amp;amp;DisplayLang=en"&gt;here&lt;/a&gt; (or &lt;a href="http://www.google.com/search?q=%22IIS+Diagnostics+Toolkit%22+site%3Amicrosoft.com"&gt;google "IIS Diagnostics Toolkit"&lt;/a&gt; ).   Running DebugDiag's crash and memory analysis scripts can show a nice recovered call stack following an exception.  This is fine, and with a following wind might even be all you need.  However, when  you are not blessed weatherwise it's time to break out WinDbg and have a good ol' root 'round.&lt;br /&gt;&lt;br /&gt;When you've got your dump loaded into WinDbg and the faulting thread shows that you've ended up with an exception, the call stack doesn't show the calls leading up to the instruction that threw the exception.  What you'd like to see is the nice "recovered" call stack that DebugDiag shows you, and poke around on that stack to get some more info about how things got to be so broken.  To reach this happy (or at least happier) state, you need to use the .cxr WinDbg command.&lt;br /&gt;&lt;br /&gt;I can usually remember this much. But then I come unglued.  How do I figure out what argument to feed to the .cxr command to get my nice happy call stack back?  I know I've seen this written down somewhere, but what with age, attention span of a butterfly, etc.  I can't remember where.  So I keep having to find out again.  What I remember now (prior to writing this, where I promise I'll look in future) is that I can work it out by looking at DebugDiag's crash dump analysis scripts.   This is still pretty tedious (I remember I start by grepping for "recovered call stack" or some such if you need a clue).&lt;br /&gt;&lt;br /&gt;When you've had an exception in a COM+ package, one way of finding the address to feed to the .cxr command (which is divinable from DebugDiag's crash dump analysis script) is to look at the call stack you currently have with the trusty kb command.  If you can spot a call to comsvcs!ComSvcsExceptionFilter, you're in good shape.  The first agument to this call is a pointer to an exception structure.    Dump the first few bytes of this structure with the dd command thus:&lt;br /&gt;&lt;br /&gt;dd xxxxxxxx&lt;br /&gt;&lt;br /&gt;where xxxxxxxx is the value of the first argument to comsvcs!ComSvcsExceptionFilter.  The second DWORD dumped by the dd command above is what  you need to provide as the argument to the .cxr command to get the original exception-throwing call stack back with another kb command.&lt;br /&gt;&lt;br /&gt;I think you can play pretty much the same game with kernel32!UnhandledExceptionFilter and NTDLL!rtlDispatchException, but I've yet to try it in anger.&lt;br /&gt;&lt;br /&gt;Hope this helps (either you or me).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/24686577-114323981386252810?l=kerneldanb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kerneldanb.blogspot.com/feeds/114323981386252810/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=24686577&amp;postID=114323981386252810' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24686577/posts/default/114323981386252810'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24686577/posts/default/114323981386252810'/><link rel='alternate' type='text/html' href='http://kerneldanb.blogspot.com/2006/03/first-gorecovering-call-stack-in.html' title='First go...recovering a call stack in WinDbg'/><author><name>Dan</name><uri>http://www.blogger.com/profile/17203824346657072247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_qcToVRgg4NQ/SqVa9n6KfLI/AAAAAAAAAAM/zPIAcTVHYzY/S220/dan.png'/></author><thr:total>1</thr:total></entry></feed>
