<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Fooling Around &#187; debug</title>
	<atom:link href="http://alax.info/blog/tag/debug/feed" rel="self" type="application/rss+xml" />
	<link>http://alax.info/blog</link>
	<description>// Software Production Line</description>
	<lastBuildDate>Wed, 02 May 2012 15:42:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Endangered species &#8211; Debugging Tools for Windows</title>
		<link>http://alax.info/blog/1363</link>
		<comments>http://alax.info/blog/1363#comments</comments>
		<pubDate>Wed, 02 May 2012 15:42:49 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[tools. windows. troubleshooting]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1363</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1363" title="Endangered species - Debugging Tools for Windows"></a>A standalone redistributable installation before, Debugging Tools for Windows was finally absorbed into Windows SDK. MSDN quote from Download and Install Debugging Tools for Windows: Install Debugging Tools for Windows as a Standalone Component If you do not want an &#8230;<p class="read-more"><a href="http://alax.info/blog/1363">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1363" title="Endangered species - Debugging Tools for Windows"></a><p>A standalone redistributable installation before, Debugging Tools for Windows was finally absorbed into Windows SDK. MSDN quote from <a href="http://msdn.microsoft.com/en-us/windows/hardware/gg463009.aspx">Download and Install Debugging Tools for Windows</a>:</p>
<blockquote><p>Install Debugging Tools for Windows as a Standalone Component</p>
<p>If you do not want an entire kit (WDK or SDK), you can install the Debugging Tools as a standalone component from the Windows SDK.</p>
<p>TO INTSTALL JUST DEBUGGING TOOLS: In the SDK installation wizard, select Debugging Tools, and clear other components that you don’t want. <strong><em>Note that .NET Framework 4.0 also will be installed.</em></strong></p>
<ul>
<li>Install Debugging Tools for Windows as a Standalone Component</li>
</ul>
<p>Install Debugging Tools for Windows without Installing .NET Framework</p>
<p><strong>If you do NOT want to install the .NET Framework, there are additional steps needed.</strong></p>
<blockquote><p>Start the install process on a different computer where it is okay to install the .NET Framework. The installer requires .NET Framework 4.0 or higher, and will install .NET if it is not already installed.</p>
<p>Install the Debugging Tools as a standalone component from the Windows SDK. In the installation wizard, select Debugging Tools, and clear other components that you don’t want.</p>
<p>After installation is complete, go to the program files directory and look for (%Program Files%)\Windows Kits\8.0\Debuggers\Redist.<br />
Copy and run the applicable MSIs on the computer that cannot have .NET.</p></blockquote>
</blockquote>
<p>Also, <a href="http://msdn.microsoft.com/en-us/windows/hardware/hh852363">Windows SDK for Windows 8 Consumer Preview</a> is not available as ISO download. So you have to use web downloader, install the gear, and having gone through this, the <code>.MSI</code> of interest are finally there.</p>
<p>You gotta be kidding me, though still thanks for not removing those completely.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1363/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LogProcessExceptions: Log Service Process Exceptions</title>
		<link>http://alax.info/blog/1359</link>
		<comments>http://alax.info/blog/1359#comments</comments>
		<pubDate>Sun, 29 Apr 2012 19:10:59 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Seriously]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[WTL]]></category>
		<category><![CDATA[.DMP]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[debugger]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[minidump]]></category>
		<category><![CDATA[service]]></category>
		<category><![CDATA[support]]></category>
		<category><![CDATA[troubleshooting]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1359</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1359" title="LogProcessExceptions: Log Service Process Exceptions"></a>One of the nasty issues with LogProcessExceptions utility was that it was unable to attach to service processes and track them to catch their exceptions. The actual problem was that the processes were not listed in first place, so there &#8230;<p class="read-more"><a href="http://alax.info/blog/1359">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1359" title="LogProcessExceptions: Log Service Process Exceptions"></a><p>One of the nasty issues with <a href="http://alax.info/blog/1211">LogProcessExceptions</a> utility was that it was unable to attach to service processes and track them to catch their exceptions.</p>
<p>The actual problem was that the processes were not listed in first place, so there was nothing to attach to. Access and security requirements necessary for a process to debug another process are listed in MSDN <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms679295%28v=vs.85%29.aspx"><code>DebugActiveProcess</code></a> article:</p>
<blockquote><p>The debugger must have appropriate access to the target process, and it must be able to open the process for <code>PROCESS_ALL_ACCESS</code>. <code>DebugActiveProcess</code> can fail if the target process is created with a security descriptor that grants the debugger anything less than full access. If the debugging process has the <code>SE_DEBUG_NAME</code> privilege granted and enabled, it can debug any process.</p></blockquote>
<p>The utility did enable the <code>SE_DEBUG_NAME</code> privilege, however it was doing it prior to starting debugging session and after the process of interest was already pointed to by user.</p>
<p>This was insufficient because <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms682629%28v=vs.85%29.aspx"><code>EnumProcesses</code></a> only lists service processes (not actually exactly services, but processes running in different security context) in case debug privilege is already enable by the time of the API call. The utility now enabled the privilege well in advance and list the services, so can be effectively applied to those.</p>
<p><img class="alignnone size-full wp-image-1360" title="LogProcessExceptions - Process List" src="http://alax.info/blog/wp-content/uploads/2012/04/Image0011.png" alt="" width="513" height="400" /></p>
<p>Download links:</p>
<ul>
<li>Partial Visual C++ .NET 2010 source code: <a href="http://www.alax.info/trac/public/browser/trunk/Utilities/LogProcessExceptions">Trac</a>, <a href="http://www.alax.info/svn/public/trunk/Utilities/LogProcessExceptions/">Subversion</a></li>
<li>Binaries: Win32 – <a href="http://www.alax.info/svn/public/trunk/Utilities/LogProcessExceptions/_Bin/Win32/Release/LogProcessExceptions.exe">LogProcessExceptions.exe</a>, x64 – <a href="http://www.alax.info/svn/public/trunk/Utilities/LogProcessExceptions/_Bin/x64/Release/LogProcessExceptions.exe">LogProcessExceptions.exe</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1359/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enabling ATLTRACE output in Release configuration builds</title>
		<link>http://alax.info/blog/1351</link>
		<comments>http://alax.info/blog/1351#comments</comments>
		<pubDate>Sun, 01 Apr 2012 11:40:10 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[OutputDebugString]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1351</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1351" title="Enabling ATLTRACE output in Release configuration builds"></a>The original intent is pretty clear, as MSDN states: In release builds, ATLTRACE2 compiles to (void) 0. As simple as this, but once in a while you are in a situation where release build fails to work for unknown reason &#8230;<p class="read-more"><a href="http://alax.info/blog/1351">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1351" title="Enabling ATLTRACE output in Release configuration builds"></a><p>The original intent is pretty clear, as <a href="http://msdn.microsoft.com/en-us/library/dhxsse89.aspx">MSDN states</a>:</p>
<blockquote><p>In release builds, <strong>ATLTRACE2</strong> compiles to <strong>(void) 0</strong>.</p></blockquote>
<p>As simple as this, but once in a while you are in a situation where release build fails to work for unknown reason and you need additional information for troubleshooting, and then you remember that you had debug tracing code still nicely available in the source, it is just being stripped out by definition of <a href="http://msdn.microsoft.com/en-us/library/6xkxyz08.aspx">ATLTRACE</a>/<a href="http://msdn.microsoft.com/en-us/library/dhxsse89.aspx">ATLTRACE2</a> macros for release builds.</p>
<p>To avoid reinvention of the wheel and putting new tracing, it might make sense to just re-enable existing tracing (certainly, if putting debug build binary is out of question, which might be the case in production environment and/or to avoid the hassle of installing additional runtime).</p>
<p>The macros need to be #undef&#8217;ined and redefined appropriately with or without limiting scope by <a href="http://msdn.microsoft.com/en-us/library/2bs04eza%28v=vs.100%29.aspx">push_macro</a>/pop_macro #pragma&#8217;s. The trick with macro has to reach two goals, to pick file name, line and current symbol name using <a href="http://msdn.microsoft.com/en-us/library/b0084kay%28v=VS.71%29.aspx">__FILE__</a> and friend macros, and also accept variable number of arguments.</p>
<p>The trick ATL does and we can use too is to define a helper class, with constructor taking file name, line and symbol name values, and cast operator () taking actual tracing parameters and arguments. Internally the output can be mapped to <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa363362%28v=vs.85%29.aspx">OutputDebugString </a>API so that output could be seen using external tool such as <a href="http://technet.microsoft.com/en-us/sysinternals/bb896647">DebugView</a>.</p>
<p>When everything is well set, new the macros in question can be defined as follows:</p>
<pre style="color: #000000; background: #ffffff;"><span style="color: #004a43;">#</span><span style="color: #004a43; font-weight: bold;">pragma </span><span style="color: #bb7977; font-weight: bold;">push_macro(</span><span style="color: #0000e6; font-weight: bold;">"ATLTRACE"</span><span style="color: #bb7977; font-weight: bold;">)</span>
<span style="color: #004a43;">#</span><span style="color: #004a43; font-weight: bold;">pragma </span><span style="color: #bb7977; font-weight: bold;">push_macro(</span><span style="color: #0000e6; font-weight: bold;">"ATLTRACE2"</span><span style="color: #bb7977; font-weight: bold;">)</span>

<span style="color: #004a43;">#</span><span style="color: #004a43;">undef</span><span style="color: #004a43;"> ATLTRACE</span>
<span style="color: #004a43;">#</span><span style="color: #004a43;">undef</span><span style="color: #004a43;"> ATLTRACE2</span>

<span style="color: #004a43;">#</span><span style="color: #004a43;">define</span><span style="color: #004a43;"> ATLTRACE2 CAtlTrace</span><span style="color: #808030;">(</span><span style="color: #004a43;">__FILE__</span><span style="color: #808030;">,</span><span style="color: #004a43;"> __LINE__</span><span style="color: #808030;">,</span><span style="color: #004a43;"> __FUNCTION__</span><span style="color: #808030;">)</span>
<span style="color: #004a43;">#</span><span style="color: #004a43;">define</span><span style="color: #004a43;"> ATLTRACE ATLTRACE2</span>

<span style="color: #800000; font-weight: bold;">int</span> _tmain<span style="color: #808030;">(</span><span style="color: #800000; font-weight: bold;">int</span> argc<span style="color: #808030;">,</span> _TCHAR<span style="color: #808030;">*</span> argv<span style="color: #808030;">[</span><span style="color: #808030;">]</span><span style="color: #808030;">)</span>
<span style="color: #800080;">{</span>
    ATLTRACE<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">First: </span><span style="color: #0f69ff;">%d</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> __LINE__<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    ATLTRACE<span style="color: #808030;">(</span><span style="color: #800000;">L"</span><span style="color: #0000e6;">Second: </span><span style="color: #0f69ff;">%d</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> __LINE__<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    ATLTRACE2<span style="color: #808030;">(</span>atlTraceGeneral<span style="color: #808030;">,</span> <span style="color: #008c00;">2</span><span style="color: #808030;">,</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">Third: </span><span style="color: #0f69ff;">%d</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> __LINE__<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    ATLTRACE2<span style="color: #808030;">(</span>atlTraceGeneral<span style="color: #808030;">,</span> <span style="color: #008c00;">2</span><span style="color: #808030;">,</span> <span style="color: #800000;">L"</span><span style="color: #0000e6;">Fourth: </span><span style="color: #0f69ff;">%d</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> __LINE__<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    <span style="color: #800000; font-weight: bold;">return</span> <span style="color: #008c00;">0</span><span style="color: #800080;">;</span>
<span style="color: #800080;">}</span>

<span style="color: #004a43;">#</span><span style="color: #004a43; font-weight: bold;">pragma </span><span style="color: #bb7977; font-weight: bold;">pop_macro(</span><span style="color: #0000e6; font-weight: bold;">"ATLTRACE2"</span><span style="color: #bb7977; font-weight: bold;">)</span>
<span style="color: #004a43;">#</span><span style="color: #004a43; font-weight: bold;">pragma </span><span style="color: #bb7977; font-weight: bold;">pop_macro(</span><span style="color: #0000e6; font-weight: bold;">"ATLTRACE"</span><span style="color: #bb7977; font-weight: bold;">)</span></pre>
<p>And the Release configuration output will be:</p>
<p><img class="alignnone size-full wp-image-1352" title="DebugView Output" src="http://alax.info/blog/wp-content/uploads/2012/04/Image001.png" alt="" width="772" height="343" /></p>
<p>Visual C++ .NET 2010 <a href="http://www.alax.info/trac/public/browser/trunk/Utilities/AtlTrace">source code</a> is available from SVN; in particular <strong>CAtlTrace</strong> class is <a href="http://www.alax.info/trac/public/browser/trunk/Utilities/AtlTrace/AtlTrace.cpp#L9">here</a>.</p>
<p>Bonus reading:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/2hfwwtbs%28v=vs.100%29.aspx">Debugging and Error Reporting Macros</a></li>
<li><a href="http://www.cprogramming.com/tutorial/visual_studio_trace_log_messages.html">Debugging with Visual Studio 2005/2008: Logging and Tracing</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1351/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hardware assisted memory corruption detection</title>
		<link>http://alax.info/blog/1319</link>
		<comments>http://alax.info/blog/1319#comments</comments>
		<pubDate>Sat, 19 Nov 2011 17:26:25 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Seriously]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[corruption]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[detection]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[protection]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1319</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1319" title="Hardware assisted memory corruption detection"></a>So you got a memory corruption issue with a piece of software. It comes in a unique scenario along the line of having a huge pile of weird code running well most of the time and then, right out of &#8230;<p class="read-more"><a href="http://alax.info/blog/1319">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1319" title="Hardware assisted memory corruption detection"></a><p>So you got a memory corruption issue with a piece of software. It comes in a unique scenario along the line of having a huge pile of weird code running well most of the time and then, right out of the blue, a corruption takes place followed by unexpected code execution and unstable software state in general.</p>
<p>The biggest problem with memory corruption is that a fragment of code is modifying a memory block which it does not own, and it has no idea who actually is the owner of the block, while the real owner has no timely way to detect the modification. You only face the consequences being unable to capture the modification moment in first place.</p>
<p>To get back to the original cause, an engineer has to drop into a time machine, turn back time and step back to where the trouble took originally place. As developers are not actually given state-of-the-art time machines, the time turning step is speculative.</p>
<h4>CVirtualHeapPtr Class: Memory with Exception-on-Write access mode</h4>
<p>At the same time a Windows platform developer is or might be aware of <a href="http://msdn.microsoft.com/en-us/library/ms810627.aspx">virtual memory API</a> which among other things provides user mode application with capabilities to define memory protection modes. Having this on hands opens unique opportunity to apply read-only protection (PAGE_READONLY) onto a memory block and have exception raised at the very moment of unexpected memory modification, having call stack showing up a source of the problem. I refer to this mode of operation as &#8220;hardware assisted&#8221; because the access violation exception/condition would be generated purely in hardware without any need to additionally do any address comparison in code.</p>
<p>Needless to say that this way is completely convenient for the developer as he does not need to patch the monstrous application all around in order to compare access addresses against read-only fragment. Instead, a block defined as read-only will be immediately available as such for the whole process almost without any performance overhead.</p>
<p>As ATL provides a set of memory allocator templates (<a href="http://msdn.microsoft.com/en-us/library/3by29yh0%28v=vs.80%29.aspx">CHeapPtr</a> for heap backed memory blocks, allocated with <em>CCRTAllocator</em>, alternate options include <a href="http://msdn.microsoft.com/en-us/library/80zw33a6%28v=vs.80%29.aspx">CComHeapPtr</a> with <em>CComAllocator</em> wrapping <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms692727%28v=vs.85%29.aspx">CoTaskMemAlloc</a>/<em>CoTaskMemFree</em> API), let us make an alternate allocator option that mimic well-known class interface and would facilitate corruption detection.</p>
<p>Because virtual memory allocation unit is a page, and protection mode is defined for the whole page, this would be the allocation granularity. For a single allocated byte we would need to request <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms724958%28v=vs.85%29.aspx">SYSTEM_INFO::dwPageSize</a> bytes of virtual memory. Unlike normal memory heap manager, we have no way to share pages between allocations as we would be unable to effectively apply protection modes. This would definitely increase application pressure onto virtual memory, but is still acceptable for the sacred task of troubleshooting.</p>
<p>We define a <em>CVirtualAllocator</em> class to be compatible with ATL&#8217;s <em>CCRTAllocator</em>, however based on <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa366887%28v=vs.85%29.aspx">VirtualAlloc</a>/<em>VirtualFree</em> API. The smart pointer class over memory pointer would be defined as follows:</p>
<pre style="color: #000000; background: #ffffff;"><span style="color: #800000; font-weight: bold;">template</span> <span style="color: #800080;">&lt;</span><span style="color: #800000; font-weight: bold;">typename</span> T<span style="color: #800080;">&gt;</span>
<span style="color: #800000; font-weight: bold;">class</span> CVirtualHeapPtr <span style="color: #800080;">:</span>
    <span style="color: #800000; font-weight: bold;">public</span> CHeapPtr<span style="color: #800080;">&lt;</span>T<span style="color: #808030;">,</span> CVirtualAllocator<span style="color: #800080;">&gt;</span>
<span style="color: #800080;">{</span>
<span style="color: #800000; font-weight: bold;">public</span><span style="color: #e34adc;">:</span>
<span style="color: #696969;">// CVirtualHeapPtr</span>
    CVirtualHeapPtr<span style="color: #808030;">(</span><span style="color: #808030;">)</span> <span style="color: #800000; font-weight: bold;">throw</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    <span style="color: #800000; font-weight: bold;">explicit</span> CVirtualHeapPtr<span style="color: #808030;">(</span>_In_ T<span style="color: #808030;">*</span> pData<span style="color: #808030;">)</span> <span style="color: #800000; font-weight: bold;">throw</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    <span style="color: #603000;">VOID</span> SetProtection<span style="color: #808030;">(</span><span style="color: #603000;">DWORD</span> nProtection<span style="color: #808030;">)</span>
    <span style="color: #800080;">{</span>
        <span style="color: #696969;">// </span><span style="color: #ffffff; background: #808000;">TODO: ...</span>
    <span style="color: #800080;">}</span>
<span style="color: #800080;">}</span><span style="color: #800080;">;</span></pre>
<p>The <em>SetProtection</em> method is to define memory protection for the memory block. Full code for the classes <a href="http://www.alax.info/trac/public/browser/trunk/Utilities/VirtualHeapPtr/VirtualHeapPtr.h#L9">is available on Trac here</a> (lines 9-132):</p>
<ul>
<li><em>CGlobalVirtualAllocator</em> class is a singleton querying operating system for virtual memory page size, and provides alignment method</li>
<li><em>CVirtualAllocator</em> class is a <em>CCRTAllocator</em>-compatible allocator class</li>
<li><em>CVirtualHeapPtr</em> class is smart template class wrapping a pointer to allocated memory</li>
</ul>
<p>Use case code will be as follows. &#8220;SetProtection(PAGE_READONLY)&#8221; enables protection on memory block and turns on exception generation at the moment memory block modification attempt. &#8220;SetProtection(PAGE_READWRITE)&#8221; would restore normal mode of memory operation.</p>
<pre style="color: #000000; background: #ffffff;">CVirtualHeapPtr<span style="color: #800080;">&lt;</span><span style="color: #603000;">BYTE</span><span style="color: #800080;">&gt;</span> p<span style="color: #800080;">;</span>
p<span style="color: #808030;">.</span>Allocate<span style="color: #808030;">(</span><span style="color: #008c00;">2</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
p<span style="color: #808030;">[</span><span style="color: #008c00;">1</span><span style="color: #808030;">]</span> <span style="color: #808030;">=</span> <span style="color: #008000;">0x01</span><span style="color: #800080;">;</span>
p<span style="color: #808030;">.</span>SetProtection<span style="color: #808030;">(</span>PAGE_READONLY<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #696969;">// NOTE: Compile with /EHa on order to catch the exception</span>
_ATLTRY
<span style="color: #800080;">{</span>
    p<span style="color: #808030;">[</span><span style="color: #008c00;">1</span><span style="color: #808030;">]</span> <span style="color: #808030;">=</span> <span style="color: #008000;">0x02</span><span style="color: #800080;">;</span>
    <span style="color: #696969;">// NOTE: We never reach here due to exception</span>
<span style="color: #800080;">}</span>
_ATLCATCHALL<span style="color: #808030;">(</span><span style="color: #808030;">)</span>
<span style="color: #800080;">{</span>
    <span style="color: #696969;">// NOTE: Catching the access violation for now to be able to continue execution</span>
<span style="color: #800080;">}</span>
p<span style="color: #808030;">.</span>SetProtection<span style="color: #808030;">(</span>PAGE_READWRITE<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
p<span style="color: #808030;">[</span><span style="color: #008c00;">1</span><span style="color: #808030;">]</span> <span style="color: #808030;">=</span> <span style="color: #008000;">0x03</span><span style="color: #800080;">;</span></pre>
<p>Given the information what data gets corrupt, the pointer allocator provides an efficient opportunity to detect the violation attempt. The only thing remained is to keep memory read-only, and temporarily revert to write access when the &#8220;legal&#8221; memory modification code is about to be executed.</p>
<p><span id="more-1319"></span></p>
<h5>One-shot Read/Write Protection with Guard Pages</h5>
<p>Another option granted by memory protection modes is brought by PAGE_GUARD flag. MSDN says:</p>
<blockquote><p>A guard page provides a one-shot alarm for memory page access. This can be useful for an application that needs to monitor the growth of large dynamic data structures. For example, there are operating systems that use guard pages to implement automatic stack checking.</p></blockquote>
<p>Setting a guard page mode provides an additional option to trigger an exception with even read access to a protected memory block.</p>
<pre style="color: #000000; background: #ffffff;">p<span style="color: #808030;">.</span>SetProtection<span style="color: #808030;">(</span>PAGE_READWRITE <span style="color: #808030;">|</span> PAGE_GUARD<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #603000;">BYTE</span> n <span style="color: #808030;">=</span> p<span style="color: #808030;">[</span><span style="color: #008c00;">0</span><span style="color: #808030;">]</span><span style="color: #800080;">;</span></pre>
<h4>CDebugHeapPtr Class: More Options to Catch Memory Corruption Conditions</h4>
<p>While setting memory protection attributes on a memory block of interest provides unique troubleshooting opportunities, it still does not cover important typical problems with memory misuse scenarios. Those are writing immediately before the allocated block, and writing immediately after. Having array of N items, this would be writing to indices -1 and N respectively.</p>
<p>To address this scenarios of misuse we can extend CVirtualHeapPtr class so that it could additionally provide &#8220;sanity pages&#8221; with PAGE_NOACCESS protection at the boundary of allocation. Because virtual memory allocation is granular, we will have to have padding bytes that extend our block to the page boundary, however we have an option to put the padding bytes before or after the payload data block in order to capture after or before memory block writes respectively.</p>
<p>The figure below shows memory layout for the data:</p>
<p><img class="alignnone size-full wp-image-1320" title="CDebugHeapPtr Memory Layout" src="http://alax.info/blog/wp-content/uploads/2011/11/image.png" alt="" width="509" height="541" /></p>
<p>Source code for the <em>CDebugHeapPtr</em> class <a href="http://www.alax.info/trac/public/browser/trunk/Utilities/VirtualHeapPtr/VirtualHeapPtr.h#L155">is available on Trac</a> (lines 155-). The sanity pages create a block of inaccessible addresses which immediately cause access violation exception on either read of write access attempt. Under debugger, those are shows with question marks:</p>
<p><img class="alignnone size-full wp-image-1321" title="PAGE_NOACCESS Data" src="http://alax.info/blog/wp-content/uploads/2011/11/Image0011.png" alt="" width="673" height="288" /></p>
<p>The padding space is pre-initialized with hardcoded value 0&#215;77, and the space is checked for integrity at release of memory block call.</p>
<h4>Catching the Exceptions</h4>
<p>Having the exceptions generated on run-time, they immediately alter application execution code path and are easy to track and catch. There is no need to bring the feature rich debugger, such as Visual Studio to the production site in order to catch the exception and environment, instead a way simpler tool such as <a href="http://alax.info/blog/1248">LogProcessExceptions</a> would be able to create a minidump file and write the state of the application. The minidump can be transferred into debugger-enabled environment for detailed check.</p>
<p>Visual C++ .NET 2010 <a href="http://www.alax.info/trac/public/browser/trunk/Utilities/VirtualHeapPtr">source code</a> is available from SVN.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1319/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LogProcessExceptions: Minidumps on User Request</title>
		<link>http://alax.info/blog/1248</link>
		<comments>http://alax.info/blog/1248#comments</comments>
		<pubDate>Tue, 19 Jul 2011 14:20:57 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Seriously]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[.DMP]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[debugger]]></category>
		<category><![CDATA[minidump]]></category>
		<category><![CDATA[support]]></category>
		<category><![CDATA[troubleshooting]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1248</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1248" title="LogProcessExceptions: Minidumps on User Request"></a>An updated version of LogProcessExceptions utility is given an additional option to create minidump .DMP files for debugged process on user request. This is in particular useful in conjunction with flag choices (on the previous page of the wizard). Download &#8230;<p class="read-more"><a href="http://alax.info/blog/1248">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1248" title="LogProcessExceptions: Minidumps on User Request"></a><p>An updated version of <a href="http://alax.info/blog/1211">LogProcessExceptions</a> utility is given an additional option to create <a href="http://msdn.microsoft.com/en-us/library/d5zhxt22.aspx">minidump .DMP files</a> for debugged process on user request. This is in particular useful in conjunction with flag choices (on the previous page of the wizard).</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2011/07/Image0032.png"><img class="alignnone size-full wp-image-1249" title="Minidump Creation Link" src="http://alax.info/blog/wp-content/uploads/2011/07/Image0032.png" alt="" width="513" height="400" /></a></p>
<p>Download links:</p>
<ul>
<li>Partial Visual C++ .NET 2010 source code: <a href="http://www.alax.info/trac/public/browser/trunk/Utilities/LogProcessExceptions">Trac</a>, <a href="http://www.alax.info/svn/public/trunk/Utilities/LogProcessExceptions/">Subversion</a></li>
<li>Binaries: Win32 &#8211; <a href="http://www.alax.info/svn/public/trunk/Utilities/LogProcessExceptions/_Bin/Win32/Release/LogProcessExceptions.exe">LogProcessExceptions.exe</a>, x64 &#8211; <a href="http://www.alax.info/svn/public/trunk/Utilities/LogProcessExceptions/_Bin/x64/Release/LogProcessExceptions.exe">LogProcessExceptions.exe</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1248/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LogProcessExceptions: Automatically Create Minidump Files on C++ Exception in Monitored Process</title>
		<link>http://alax.info/blog/1211</link>
		<comments>http://alax.info/blog/1211#comments</comments>
		<pubDate>Wed, 18 May 2011 16:47:41 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Seriously]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[.DMP]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[debugger]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[minidump]]></category>
		<category><![CDATA[support]]></category>
		<category><![CDATA[troubleshooting]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1211</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1211" title="LogProcessExceptions: Automatically Create Minidump Files on C++ Exception in Monitored Process"></a>LogProcessExceptions utility implements a very basic debugger which attaches (see DebugActiveProcess on MSDN) to a running process and monitors its exceptions. Once exception takes place the utility creates a minidump file for the process (see MiniDumpWriteDump on MSDN) so that &#8230;<p class="read-more"><a href="http://alax.info/blog/1211">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1211" title="LogProcessExceptions: Automatically Create Minidump Files on C++ Exception in Monitored Process"></a><p>LogProcessExceptions utility implements a very basic debugger which attaches (see <a href="http://msdn.microsoft.com/en-us/library/ms679295%28VS.85%29.aspx">DebugActiveProcess</a> on MSDN) to a running process and monitors its exceptions. Once exception takes place the utility creates a minidump file for the process (see <a href="http://msdn.microsoft.com/en-us/library/ms680360%28VS.85%29.aspx">MiniDumpWriteDump</a> on MSDN) so that exception condition could be investigated off-site using debugger.</p>
<p>If you throw C++ exceptions in your C++ code in exceptional cases which indicate necessity to log the condition and possibly check it later, the utility will get the vital information for the application running at production location in environment without fully featured debugger (note that the utility is a simple download-and-run &#8220;wizard&#8221; style application, with no installation required), or will simply track the error letting the application continue execution without pretty much of an interruption.</p>
<p>The tool will prompt for debuggee process, and follow with minidump type choices and the debugging operation.</p>
<p><img class="alignnone size-full wp-image-1212" title="Log Process Exceptions - Processes" src="http://alax.info/blog/wp-content/uploads/2011/05/Image001.png" alt="" width="513" height="400" /></p>
<p><span id="more-1211"></span></p>
<p><img class="alignnone size-full wp-image-1213" title="Log Process Exceptions - Minidupm Type" src="http://alax.info/blog/wp-content/uploads/2011/05/Image0031.png" alt="" width="513" height="400" /> <img class="alignnone size-full wp-image-1214" title="Log Process Exceptions - Operation" src="http://alax.info/blog/wp-content/uploads/2011/05/Image0041.png" alt="" width="513" height="400" /></p>
<p>Minidump files are created automatically with the name file including:</p>
<ul>
<li>Excecutable Name</li>
<li>Process Identifier</li>
<li>Ordinal Number</li>
<li>Exception Code</li>
<li>C++/ATL Exception HRESULT Code (esp. for <a href="http://msdn.microsoft.com/en-us/library/9b1a94tx%28VS.80%29.aspx">CAtlException</a> exceptions)</li>
</ul>
<p>The utility is expected to work with Windows XP operating system and more recent.</p>
<p>Download links:</p>
<ul>
<li>Partial Visual C++ .NET 2010 source code: <a href="http://www.alax.info/trac/public/browser/trunk/Utilities/LogProcessExceptions">Trac</a>, <a href="http://www.alax.info/svn/public/trunk/Utilities/LogProcessExceptions/">Subversion</a></li>
<li>Binaries: Win32 &#8211; <a href="http://www.alax.info/svn/public/trunk/Utilities/LogProcessExceptions/_Bin/Win32/Release/LogProcessExceptions.exe">LogProcessExceptions.exe</a>, x64 &#8211; <a href="http://www.alax.info/svn/public/trunk/Utilities/LogProcessExceptions/_Bin/x64/Release/LogProcessExceptions.exe">LogProcessExceptions.exe</a></li>
</ul>
<p>Artwork credits: <a href="http://cristoildiablo.deviantart.com/">http://cristoildiablo.deviantart.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1211/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get HMODULE of msvcr90.dll</title>
		<link>http://alax.info/blog/1155</link>
		<comments>http://alax.info/blog/1155#comments</comments>
		<pubDate>Mon, 08 Nov 2010 08:02:11 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Seriously]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[ATL]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[psapi]]></category>
		<category><![CDATA[runtime]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1155</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1155" title="How to get HMODULE of msvcr90.dll"></a>Because Microsoft C++ Runtime library is distributed as a side-by-side assembly, GetModuleHandle and LoadLibrary is no longer available to locate the library within the process. Both API calls would return NULL handle. HMODULE hModule = GetModuleHandle(_T("msvcr90.dll")); HMODULE hModule = LoadLibrary(_T("msvcr90.dll")); &#8230;<p class="read-more"><a href="http://alax.info/blog/1155">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1155" title="How to get HMODULE of msvcr90.dll"></a><p>Because Microsoft C++ Runtime library is distributed as a <a href="http://msdn.microsoft.com/en-us/library/ms229072%28VS.80%29.aspx">side-by-side assembly</a>, <a href="http://msdn.microsoft.com/en-us/library/ms683199%28VS.85%29.aspx">GetModuleHandle</a> and <a href="http://msdn.microsoft.com/en-us/library/ms684175%28VS.85%29.aspx">LoadLibrary</a> is no longer available to locate the library within the process. Both API calls would return NULL handle.</p>
<pre style="color: #000000; background: none repeat scroll 0% 0% #ffffff;"><span style="color: #603000;">HMODULE</span> hModule <span style="color: #808030;">=</span> <span style="color: #400000;">GetModuleHandle</span><span style="color: #808030;">(</span>_T<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">msvcr90.dll</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #603000;">HMODULE</span> hModule <span style="color: #808030;">=</span> <span style="color: #400000;">LoadLibrary</span><span style="color: #808030;">(</span>_T<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">msvcr90.dll</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<p>Still, how to locate the modules in order to, for example, be able to check DLL version? <a href="http://msdn.microsoft.com/en-us/library/ms684884%28VS.85%29.aspx">Process Status API (PSAPI)</a> can help:</p>
<pre style="color: #000000; background: none repeat scroll 0% 0% #ffffff;"><span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">psapi.h</span><span style="color: #800000;">&gt;</span>
<span style="color: #004a43;">#</span><span style="color: #004a43; font-weight: bold;">pragma </span><span style="color: #bb7977; font-weight: bold;">comment(lib, </span><span style="color: #0000e6; font-weight: bold;">"psapi.lib"</span><span style="color: #bb7977; font-weight: bold;">)</span>

<span style="color: #808030;">.</span><span style="color: #808030;">.</span><span style="color: #808030;">.</span>

<span style="color: #603000;">DWORD</span> nDataSize <span style="color: #808030;">=</span> <span style="color: #008c00;">4</span> <span style="color: #808030;">&lt;</span><span style="color: #808030;">&lt;</span> <span style="color: #008c00;">10</span><span style="color: #800080;">;</span> <span style="color: #696969;">// 4K</span>
EnumProcessModules<span style="color: #808030;">(</span><span style="color: #400000;">GetCurrentProcess</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #7d0045;">NULL</span><span style="color: #808030;">,</span> <span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>nDataSize<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
nDataSize <span style="color: #808030;">+</span><span style="color: #808030;">=</span> nDataSize <span style="color: #808030;">/</span> <span style="color: #008c00;">2</span><span style="color: #800080;">;</span>
CTempBuffer<span style="color: #800080;">&lt;</span><span style="color: #603000;">HMODULE</span><span style="color: #800080;">&gt;</span> phModules<span style="color: #800080;">;</span>
ATLENSURE_THROW<span style="color: #808030;">(</span>phModules<span style="color: #808030;">.</span>AllocateBytes<span style="color: #808030;">(</span>nDataSize<span style="color: #808030;">)</span><span style="color: #808030;">,</span> E_OUTOFMEMORY<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span>EnumProcessModules<span style="color: #808030;">(</span><span style="color: #400000;">GetCurrentProcess</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> phModules<span style="color: #808030;">,</span> nDataSize<span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>nDataSize<span style="color: #808030;">)</span><span style="color: #808030;">)</span>
<span style="color: #800080;">{</span>
    <span style="color: #800000; font-weight: bold;">const</span> SIZE_T nCount <span style="color: #808030;">=</span> nDataSize <span style="color: #808030;">/</span> <span style="color: #800000; font-weight: bold;">sizeof</span> <span style="color: #808030;">*</span>phModules<span style="color: #800080;">;</span>
    <span style="color: #800000; font-weight: bold;">for</span><span style="color: #808030;">(</span>SIZE_T nIndex <span style="color: #808030;">=</span> <span style="color: #008c00;">0</span><span style="color: #800080;">;</span> nIndex <span style="color: #808030;">&lt;</span> nCount<span style="color: #800080;">;</span> nIndex<span style="color: #808030;">+</span><span style="color: #808030;">+</span><span style="color: #808030;">)</span>
    <span style="color: #800080;">{</span>
        CPath sPath <span style="color: #808030;">=</span> _VersionInfoHelper<span style="color: #800080;">::</span>GetModulePath<span style="color: #808030;">(</span>phModules<span style="color: #808030;">[</span>nIndex<span style="color: #808030;">]</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// uses GetModuleFileName</span>
        <span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span>_tcsicmp<span style="color: #808030;">(</span>FindFileName<span style="color: #808030;">(</span>sPath<span style="color: #808030;">)</span><span style="color: #808030;">,</span> _T<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">msvcr90.dll</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span> <span style="color: #808030;">=</span><span style="color: #808030;">=</span> <span style="color: #008c00;">0</span><span style="color: #808030;">)</span>
        <span style="color: #800080;">{</span>
            <span style="color: #696969;">// NOTE: Here we found it</span>
            ATLTRACE2<span style="color: #808030;">(</span>atlTraceGeneral<span style="color: #808030;">,</span> <span style="color: #008c00;">2</span><span style="color: #808030;">,</span> _T<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">msvcr90.dll version is </span><span style="color: #0f69ff;">%s</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> _VersionInfoHelper<span style="color: #800080;">::</span>GetVersionString<span style="color: #808030;">(</span>_VersionInfoHelper<span style="color: #800080;">::</span>GetFileVersion<span style="color: #808030;">(</span>sPath<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
            <span style="color: #800000; font-weight: bold;">break</span><span style="color: #800080;">;</span>
        <span style="color: #800080;">}</span>
    <span style="color: #800080;">}</span>
<span style="color: #800080;">}</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1155/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>ProcessSnapshot: Create process minidump for port-mortem debugging</title>
		<link>http://alax.info/blog/1119</link>
		<comments>http://alax.info/blog/1119#comments</comments>
		<pubDate>Wed, 24 Mar 2010 22:17:42 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[.DMP]]></category>
		<category><![CDATA[ATL]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[minidump]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[snapshot]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[utility]]></category>
		<category><![CDATA[WTL]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1119</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1119" title="ProcessSnapshot: Create process minidump for port-mortem debugging"></a>ProcessSnapshot is a utility to take a snapshot of process call stacks, and the snapshot taken is written into a human friendly text file. Additionally to this, the utility has been given a capability to create process minidump files, on &#8230;<p class="read-more"><a href="http://alax.info/blog/1119">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1119" title="ProcessSnapshot: Create process minidump for port-mortem debugging"></a><p><a href="http://alax.info/blog/665">ProcessSnapshot</a> is a utility to take a snapshot of process call stacks, and the snapshot taken is written into a human friendly text file.</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2010/03/24-Image001.png"><img class="alignnone size-medium wp-image-1120" title="ProcessSnapshot is taking process minidump files" src="http://alax.info/blog/wp-content/uploads/2010/03/24-Image001-320x189.png" alt="ProcessSnapshot is taking process minidump files" width="320" height="189" /></a></p>
<p>Additionally to this, the utility has been given a capability to create process <a href="http://msdn.microsoft.com/en-us/library/ms680369%28VS.85%29.aspx">minidump files</a>, on user request. The minidump files can be used with debugger to analyze the context of the process using feature rich debug environment, esp. Microsoft Visual Studio. To create a minidump for a process, check a corresponding box and press &#8220;Take a Dump&#8221; button. A file named &#8220;&lt;process-image-name&gt; &#8211; &lt;date&gt; &lt;time&gt;.dmp&#8221; will be created in the directory of the utility executable.</p>
<p>See also:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ms680369%28VS.85%29.aspx">Minidump Files (MSDN)</a></li>
<li><a href="http://support.microsoft.com/kb/315263">How to read the small memory dump files that Windows creates for debugging</a></li>
<li><a href="http://www.codeproject.com/KB/debug/postmortemdebug_standalone1.aspx">Post-Mortem Debugging Your Application with Minidumps and Visual Studio .NET</a></li>
<li><a href="http://www.pchell.com/support/minidumps.shtml">How to View Windows Minidump Files</a></li>
</ul>
<p>A binary [<a href="http://www.assembla.com/code/roatl-utilities/subversion/nodes/trunk/ProcessSnapshot/Win32/Release/ProcessSnapshot.exe?format=raw">Win32</a>, <a href="http://www.assembla.com/code/roatl-utilities/subversion/nodes/trunk/ProcessSnapshot/x64/Release/ProcessSnapshot.exe?format=raw">x64</a>] and partial Visual C++ .NET 2008 source code <a href="http://trac2.assembla.com/roatl-utilities/browser/trunk/ProcessSnapshot/Release/ProcessSnapshot.exe">are  available from SVN</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1119/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ahead Nero&#8217;s NeResize DirectShow Filter</title>
		<link>http://alax.info/blog/967</link>
		<comments>http://alax.info/blog/967#comments</comments>
		<pubDate>Mon, 29 Jun 2009 22:34:26 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Seriously]]></category>
		<category><![CDATA[access violation]]></category>
		<category><![CDATA[ahead]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[crap]]></category>
		<category><![CDATA[crash]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[debugger]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[NeResize]]></category>
		<category><![CDATA[nero]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=967</guid>
		<description><![CDATA[<a href="http://alax.info/blog/967" title="Ahead Nero&#039;s NeResize DirectShow Filter"></a>Another example of a negligence with a cost of incompatibility and enormous amount of support time. Ahead Nero installs a number of DirectShow filters into $(Program Files)\Common Files\Ahead\DSFilter directory. One of the files is NeResize.ax and it hosts a Nero &#8230;<p class="read-more"><a href="http://alax.info/blog/967">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/967" title="Ahead Nero&#039;s NeResize DirectShow Filter"></a><p>Another example of a negligence with a cost of incompatibility and enormous amount of support time. Ahead Nero installs a number of DirectShow filters into <em>$(Program Files)\Common Files\Ahead\DSFilter</em> directory. One of the files is <em>NeResize.ax</em> and it hosts a <em>Nero Resize</em> filter. Let us take a closer look:</p>
<p>CLSID: <strong>{30002E0C-C574-481E-A5DE-90AE54A79E10}</strong> (note that Nero 8 ships the same buggy stuff with new CLSID of <strong>{3D0A27C9-B4D6-487B-AFE4-E3CABD4B81F9}</strong><em> &#8211; 11.05.2010</em>)<br />
Merit: <strong>0&#215;00400000</strong> (<a href="http://msdn.microsoft.com/en-us/library/dd388793(VS.85).aspx">MERIT_UNLIKELY</a>)<br />
Input Pin&#8217;s Media Type: major type GUID_NULL, subtype GUID_NULL<br />
Output Pin&#8217;s Media Type: major type GUID_NULL, subtype GUID_NULL</p>
<p>The filter is clearly a video filter:</p>
<p><img class="alignnone size-full wp-image-969" title="Ahead Nero Resize Filter's Property Page" src="http://alax.info/blog/wp-content/uploads/2009/06/29-image001.png" alt="Ahead Nero Resize Filter's Property Page" width="376" height="292" /></p>
<p>So the filter register itself under a merit that allows taking it during <a href="http://msdn.microsoft.com/en-us/library/dd390342(VS.85).aspx">Intelligent Connect</a>, it registers using media type wildcard which is clearly widely than the filter can affectively operate with and the most interesting part is: with certain video media types the filter crashes (memory access violation) during pin connection negotiation process. That is, inaccurate filter <span style="text-decoration: underline;">may be crashing third party software it has nothing to deal with at all</span>.</p>
<pre>*** Unhandled Exception
Process: 0x000001d4, Thread: 0x00000ce4, Date: 6/29/2009, Time: 11:20:56 AM, Application: C:\Program Files\...
Module: C:\..., Product Version: 1.7.1.1, File Version: 1.7.1.20014, File Time: 23.06.2009, 19:02
Code: 0xc0000005, Flags: 0x00000000, Address: 0x05fc6c65
Parameters: 0x00000001, 0x15be9030

** Call Stack
NeResize!05fc6c65 DllUnregisterServer +21909 @05fc0000
NeResize!05fc7888 DllUnregisterServer +25016 @05fc0000
NeResize!05fc7204 DllUnregisterServer +23348 @05fc0000</pre>
<p>Additionally to that the filter does not allow its insertion in debugging environment, and it seems even with Visual Studio running without a debugging session active. Which means that developer may be unaware of issues until incompatibility comes up at a later stage such as testing, or at production site.</p>
<p>It is not the first Nero filter which is bringing real problems. Basically any user who want to keep his system far from issues while still having Nero installed, needs to do find <em>$(Program Files)\Common Files\Ahead\DSFilter</em> directory and immediately rename it to some <em>~DSFilter</em> in order to invalidate all Nero filters registration.</p>
<p>A few quotes from <a href="http://msdn.microsoft.com/en-us/library/dd388793(VS.85).aspx">Guidelines for Registering Filters</a>:</p>
<p style="padding-left: 30px;">Avoid specifying MEDIATYPE_None, MEDIASUBTYPE_None, or GUID_NULL in the <a id="ctl00_MTContentSelector1_mainContentContainer_ctl04" onclick="javascript:Track('ctl00_MTContentSelector1_mainContentContainer_ctl00|ctl00_MTContentSelector1_mainContentContainer_ctl04',this);" href="http://msdn.microsoft.com/en-us/library/dd373438%28VS.85%29.aspx"><strong>AMOVIESETUP_MEDIATYPE</strong></a> information for a pin. <strong>IFilterMapper2</strong> treats these as wildcards, which can slow the graph-building process.</p>
<p>Nero Resize does specify and obviously slows the system down.</p>
<p style="padding-left: 30px;">Choose the lowest merit value possible. Here are some guidelines:<br />
&#8230;<br />
Special purpose filter; any filter that is created directly by the application: MERIT_DO_NOT_USE</p>
<p>Nero Resize uses higher value and thus affects proper applications.</p>
<p>Software developers will be safer to prevent from <a href="http://msdn.microsoft.com/en-us/library/dd373399(VS.85).aspx">DirectShow Filter Graph Manager</a> considering the buggy filter to be used during <a href="http://msdn.microsoft.com/en-us/library/dd390342(VS.85).aspx">Intelligent Connect</a> by implementing <a href="http://msdn.microsoft.com/en-us/library/dd389376(VS.85).aspx">IAMGraphBuilderCallback</a> interface.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/967/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

