<?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>Visual C++ Tips &#187; Debugging Tips</title>
	<atom:link href="http://weseetips.com/category/debugging-tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://weseetips.com</link>
	<description>Gold mine of Visual C++ tricks!</description>
	<lastBuildDate>Thu, 11 Mar 2010 09:09:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>How to Watch Variables in Binary by using Visual Studio Debugger?</title>
		<link>http://weseetips.com/2009/01/01/how-to-watch-variables-in-binary-by-using-visual-studio-debugger/</link>
		<comments>http://weseetips.com/2009/01/01/how-to-watch-variables-in-binary-by-using-visual-studio-debugger/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 20:18:38 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Debugging Tips]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[variable in binary]]></category>
		<category><![CDATA[visual studio debugger]]></category>
		<category><![CDATA[visual studio debugging tips]]></category>
		<category><![CDATA[visual studio variable in binary]]></category>
		<category><![CDATA[watch binary]]></category>
		<category><![CDATA[watch value in binary]]></category>
		<category><![CDATA[watch variable in binary]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=806</guid>
		<description><![CDATA[In visual studio you can watch variable values in different formats. For instance, for viewing in hex add this to watch window &#8211; var,x and for octal &#8211; var,o. But its a pity that visual studio doesn&#8217;t support displaying variables in binaries. So how can you watch the value of a variable in binary, with [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.wordpress.com/files/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
In visual studio you can watch variable values in different formats. For instance, for viewing in hex add this to watch window &#8211; <strong>var,x</strong> and for octal &#8211; <strong>var,o</strong>. But its a pity that <span style="color:#0000ff;">visual studio doesn&#8217;t support displaying variables in binaries</span>. So how can <strong>you watch</strong> the value of a <strong>variable</strong> in binary, <strong>with debugger</strong>? <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img class="alignnone size-full wp-image-808" title="watchvarinbinary_1" src="http://weseetips.wordpress.com/files/2009/01/watchvarinbinary_1.jpg" alt="watchvarinbinary_1" width="500" height="300" /><br />
Image Courtesy &#8211; <a title="Pixdaus" href="http://pixdaus.com/single.php?id=22790" target="_blank">Pixdaus</a>.</p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.wordpress.com/files/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
Well, we have to <span style="color:#0000ff;">utilize the special feature of visual studio debugger</span>. Basically the <span style="color:#0000ff;">watch window </span>is not just a tool to display the variable value. It <span style="color:#0000ff;">can evaluate and execute small code snippets as well. </span>If you <span style="color:#0000ff;">add a function call to the watch window,</span> that<span style="color:#0000ff;"> function will be called</span> when debugger refreshes the watch values. So, all you have to do is &#8211; Add a global function which accepts integer value, converts it to binary string then display it to output window. Have a look at the function.</p>
<pre>// Global function which converts integer to binary
// and dump to the output window.
void DumpBinary( DWORD Value )
{
    // Buffer to hold the converted string.
    TCHAR Buffer[255] = { 0 };

    // Convert the value to binary string.
    _itot( Value, Buffer, 2 );

    // Display to output window.
    CString csMessage;
    csMessage.Format( _T("\n%d in binary: %s"), Value, Buffer );
    OutputDebugString( csMessage );
}</pre>
<p>Now <span style="color:#0000ff;">if you want to convert the 100 to binary,</span> break at some location and just add <span style="color:#0000ff;"><strong>DumpBinary(100)</strong></span> to watch window and check the output in the output window. See the screenshot below.</p>
<p><img class="alignnone size-full wp-image-807" title="watchvarinbinary" src="http://weseetips.wordpress.com/files/2009/01/watchvarinbinary.jpg" alt="watchvarinbinary" width="510" height="382" /></p>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.wordpress.com/files/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
Just now I realized &#8211; how powerful the Visual Studio Debugger is. Hats off to Visual Studio Team!</p>
<p>Well, please note that <span style="color:#0000ff;">in visual studio 2008 </span>and may be in siblings, When you add this to watch window, <span style="color:#0000ff;">its possible to see this error</span> &#8211; &#8220;<span style="color:#0000ff;">CXX0001: Error: error attempting to execute user function&#8221;</span>. In that case <span style="color:#0000ff;">just click the &#8220;Evaluate button&#8221;</span> which appears next to it and the expression will be re-evaluate.</p>
<p><img class="alignnone size-full wp-image-54" title="advancedseries" src="http://weseetips.wordpress.com/files/2008/03/advancedseries.jpg" alt="advancedseries" width="217" height="32" /><br />
Targeted Audiance &#8211; Advanced.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2009/01/01/how-to-watch-variables-in-binary-by-using-visual-studio-debugger/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Debug the Release Build?</title>
		<link>http://weseetips.com/2008/11/16/how-to-debug-the-release-build/</link>
		<comments>http://weseetips.com/2008/11/16/how-to-debug-the-release-build/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 12:43:32 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Debugging Tips]]></category>
		<category><![CDATA[debug release build]]></category>
		<category><![CDATA[debug the release build]]></category>
		<category><![CDATA[release build]]></category>
		<category><![CDATA[release build problems]]></category>
		<category><![CDATA[release build tips]]></category>
		<category><![CDATA[visual C++ debugging tips]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=607</guid>
		<description><![CDATA[&#8220;Debugging in release build!!! Is it possible?&#8221; I&#8217;ve heard this questions a couple of time, especially from Visual C++ Novices. Yes! its possible. But why? I still remember my first project. We did everything right, debugged and fixed all bugs in debug build and released the application. But client tested the release version and it [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><span style="color:#000000;"><br />
<span style="color:#0000ff;">&#8220;Debugging in release build!!! Is it possible?&#8221;</span> I&#8217;ve heard this questions a couple of time, especially from Visual C++ Novices. <span style="color:#0000ff;">Yes! its possible</span>. But why? </span> I still remember my first project. We did everything right, debugged and fixed all bugs in debug build and released the application. But client tested the release version and it was like <strong><a title="FatMan" href="http://en.wikipedia.org/wiki/Fat_Man" target="_self">FatMan</a></strong>, a lot of crashes.</p>
<p>So, <span style="color:#0000ff;">Debugging in release build is important</span> <span style="color:#0000ff;">because</span>, even though the debug build can catch most of issues, there might be <span style="color:#0000ff;">some bugs or crashes still hiding under the release version</span> of application. For catching them, there is now way other than to debug the release build itself.</p>
<p><img class="alignnone size-full wp-image-597" title="debuginreleasebuild" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/11/debuginreleasebuild.jpg" alt="debuginreleasebuild" width="450" height="405" /></p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
Well, basically compiler needs debug information for stepping into code while debugging and In release build, by default there will not be any debug information. Compilers cannot interpret or understand optimized code and in release build, optimization will be enabled by default. For <span style="color:#0000ff;">debugging in release build,</span> you&#8217;ve to <span style="color:#0000ff;">generate debug information</span> and to <span style="color:#0000ff;">turn off optimizations</span>. Follow the steps about how to tweak project settings for that.</p>
<p>1) Take project settings by <span style="color:#0000ff;">Alt+F7</span>.<br />
2) Select Release configuration.<br />
3) Select &#8220;<span style="color:#0000ff;">C/C++</span>&#8221; tab. Set &#8220;<span style="color:#0000ff;">Optimizations</span>&#8221; as &#8220;<span style="color:#0000ff;">Disable Debug</span>&#8221; and &#8220;<span style="color:#0000ff;">Debug Info</span>&#8221; as <span style="color:#0000ff;">&#8220;Program Database&#8221;</span>.</p>
<p><img class="alignnone size-full wp-image-600" title="debuginreleasebuild1" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/11/debuginreleasebuild1.jpg" alt="debuginreleasebuild1" width="510" height="332" /></p>
<p>4) Take &#8220;<span style="color:#0000ff;">Link</span>&#8221; tab. Enable &#8220;<span style="color:#0000ff;">Generate Debug Info</span>&#8220;.</p>
<p><img class="alignnone size-full wp-image-601" title="debuginreleasebuild2" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/11/debuginreleasebuild2.jpg" alt="debuginreleasebuild2" width="510" height="332" /></p>
<p>5) Now from menu, take &#8211; &#8220;<span style="color:#0000ff;">Build &gt; Set active configuration&#8230;</span>&#8221; and select <span style="color:#0000ff;">Release build</span> as default.</p>
<p><img class="alignnone size-full wp-image-602" title="debuginreleasebuild3" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/11/debuginreleasebuild3.jpg" alt="debuginreleasebuild3" width="381" height="239" /></p>
<p>6) Rebuild the project by <span style="color:#0000ff;">F7</span>.<br />
7) Now what are you waiting for? <span style="color:#0000ff;">Press F5</span> to debug and enjoy!</p>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
Since my first project, I don&#8217;t forget how to debug in release version. <img src='http://weseetips.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  and this is my advice for you &#8211; &#8220;<span style="color:#0000ff;">Its fine to do the entire debugging in debug build</span>, because its tuned to catch a lot of bugs. <span style="color:#0000ff;">But </span><span style="color:#0000ff;">before releasing check the release build too</span>.&#8221;</p>
<p><img class="alignnone size-medium wp-image-51" title="beginnerseries" src="http://weseetips.files.wordpress.com/2008/03/beginnerseries.jpg?w=215" alt="" width="215" height="32" /><br />
Targeted Audience &#8211; Beginners.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/11/16/how-to-debug-the-release-build/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Be careful while watching variables with Visual Studio Debugger&#039;s tooltip.</title>
		<link>http://weseetips.com/2008/07/17/be-careful-while-watching-variables-with-visual-studio-debuggers-tooltip/</link>
		<comments>http://weseetips.com/2008/07/17/be-careful-while-watching-variables-with-visual-studio-debuggers-tooltip/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 17:44:29 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Debugging Tips]]></category>
		<category><![CDATA[debugger tooltip]]></category>
		<category><![CDATA[visual studio debugger]]></category>
		<category><![CDATA[visual studio gotcha]]></category>
		<category><![CDATA[visual studio pitfall]]></category>
		<category><![CDATA[watch local variable]]></category>
		<category><![CDATA[watch struct variable]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=229</guid>
		<description><![CDATA[We used to watch variables values by hovering mouse over them. So visual studio will show the variable value as tooltip. But beware, pitfalls are waiting for you, especially while watching structures. If you just hover the mouse over a variable, Visual Studio will pick the variable name just below and shows its value as [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
We used to <span style="color:#0000ff;">watch variables values by hovering mouse over them.</span> So visual studio will show the variable value as tooltip. <span style="color:#0000ff;">But beware, pitfalls are waiting for you</span>, especially while watching structures.</p>
<p><img class="alignnone size-medium wp-image-15" src="http://weseetips.files.wordpress.com/2008/03/icon_underthehood.jpg?w=208" alt="" width="208" height="32" /><br />
If you just hover the mouse over a variable, <span style="color:#0000ff;">Visual Studio will pick the variable name just below and shows its value as tooltip.</span> But it can be <span style="color:#0000ff;">dangerous</span>. For instance, assume you&#8217;ve a structure, and local variable with name same as structure member. Check the code snippet.</p>
<pre>// Some structure.
struct Drive
{
    BOOL Present;
};

void Function()
{
    // Local variable with same name
    // as structure member.
    BOOL Present = FALSE;

    // Structure with variable
    Drive CdDrive = { 0 };

    // If you watch the var by mouse hover,
    // the value displayed will be that of
    // local variable.
    CdDrive.Present = TRUE;
}</pre>
<p><span style="color:#0000ff;">If you just mouse hover on the structure member variable, you&#8217;re going to deep trouble. </span>The value displayed will be wrong. <span style="color:#0000ff;">Since debugger choose just the variable name under the mouse</span>, if a <span style="color:#0000ff;">local variable of same name exists, </span>the <span style="color:#0000ff;">value of local variable will be displayed</span>. Enough and more to get mis-guided. Have a look at the screenshot.</p>
<p><img class="alignnone size-full wp-image-230" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/07/visualstudiotooltip1.jpg" alt="" width="510" height="385" /></p>
<p>So always watch structure members by selecting the full variable name. See following screenshot.</p>
<p><img class="alignnone size-full wp-image-231" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/07/visualstudiotooltip2.jpg" alt="" width="510" height="384" /></p>
<p><img class="alignnone size-medium wp-image-18" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
Silly stuff. But it can grab a lot of time by blaming the compiler and rebuilding source again and again as I did. <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
<img class="alignnone size-medium wp-image-53" src="http://weseetips.files.wordpress.com/2008/03/intermediateseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audience &#8211; Intermediate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/07/17/be-careful-while-watching-variables-with-visual-studio-debuggers-tooltip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to watch a range of values inside huge array?</title>
		<link>http://weseetips.com/2008/07/03/how-to-watch-a-range-of-values-inside-huge-array/</link>
		<comments>http://weseetips.com/2008/07/03/how-to-watch-a-range-of-values-inside-huge-array/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 19:33:29 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Debugging Tips]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[debug array]]></category>
		<category><![CDATA[watch]]></category>
		<category><![CDATA[watch array range]]></category>
		<category><![CDATA[watch window]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=196</guid>
		<description><![CDATA[Assume you&#8217;ve an array with 1000 elements in it and you want to watch elements from 500 ~ 510, what will you do? One method is you can watch the array directly which will list all the 1000 variables and you&#8217;ve to scroll up to 500th element and have to watch. Is there any trick [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
<span style="color:#0000ff;"> Assume you&#8217;ve an array with 1000 elements</span> in it and <span style="color:#0000ff;">you want to watch elements from 500 ~ 510</span>, what will you do? One method is you can watch the array directly which will list all the 1000 variables and <span style="color:#0000ff;">you&#8217;ve to scroll up to 500th element and have to watch</span>. Is there any trick to watch just the range of 10 elements between 500 to 510?</p>
<p><img class="alignnone size-medium wp-image-12" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
Yes! Basically the idea is, you&#8217;ve to add &#8211; <span style="color:#0000ff;"><strong>(Array+RangeStart)+RangeCount</strong></span> to the watch window. But there are different scenarios and obviously the trick varies slightly. See examples below.</p>
<p><span style="text-decoration:underline;"><strong>1) If you have dynamically allocated array.</strong></span><br />
Check the code snippet.</p>
<pre>// Array ptr with 1000 elements.
int* pArray = new int[1000];

// Initialize range 500 to 509 as 1.
for( int ArrayIndex = 500; ArrayIndex &lt; 510; ++ArrayIndex )
{
    pArray[ ArrayIndex ] = 1;
}</pre>
<p>In this case for watching range 500 ~ 510, you&#8217;ve to add &#8211; <strong><span style="color:#0000ff;">(pArray+500),10</span></strong> to watch window. See the screenshot.<br />
<img class="alignnone size-full wp-image-199" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/07/watchrange_ptr.jpg" alt="" width="510" height="249" /></p>
<p><span style="text-decoration:underline;"><strong>2) If you have array on stack.</strong></span><br />
If you&#8217;re array is on stack, if you add your array to watch window, the debugger automatically expands all elements, since it knows the max size of array. But we just want to see the range. See the code snippet.</p>
<pre>// Array with 1000 elements.
int Array[1000] = { 0 };

// Initialize range 500 to 509 as 1.
for( int ArrayIndex = 500; ArrayIndex &lt; 510; ++ArrayIndex )
{
    Array[ ArrayIndex ] = 1;
}</pre>
<p>In this case for watching range 500 ~ 510, you&#8217;ve to add &#8211; <strong><span style="color:#0000ff;">(<span style="color:#ff00ff;">(</span><span style="color:#ff00ff;">int*)</span>Array+500),10</span></strong> to watch window. See the screenshot.<br />
<img class="alignnone size-full wp-image-198" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/07/watchrange_array.jpg" alt="" width="510" height="252" /></p>
<p><img class="alignnone size-medium wp-image-18" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
Watch window is a Treasure chest! isn&#8217;t it? <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img class="alignnone size-medium wp-image-53" src="http://weseetips.files.wordpress.com/2008/03/intermediateseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audience &#8211; Intermediate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/07/03/how-to-watch-a-range-of-values-inside-huge-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to watch vectors more easily?</title>
		<link>http://weseetips.com/2008/06/23/how-to-watch-vectors-more-easily/</link>
		<comments>http://weseetips.com/2008/06/23/how-to-watch-vectors-more-easily/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 18:50:43 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Debugging Tips]]></category>
		<category><![CDATA[quick watch]]></category>
		<category><![CDATA[std::vector]]></category>
		<category><![CDATA[vector watch]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=183</guid>
		<description><![CDATA[Everyone uses vectors and during debugging if we&#8217;ve to watch the elements, its a real headache. The usual method that follows is to quick watch the vector and we add index to the _First element. For instance, assume we&#8217;ve the vector generated by following code snippet. // The String Vector. vector&#60;CString&#62; StringVector; // Add some [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
Everyone uses vectors and during debugging if we&#8217;ve to watch the elements, its a real headache. <span style="color:#0000ff;">The usual method that follows is to quick watch the vector and we add index to the _First element</span>. For instance, assume we&#8217;ve the vector generated by following code snippet.</p>
<pre>// The String Vector.
vector&lt;CString&gt; StringVector;

// Add some strings to it.
StringVector.push_back(_T("WeSeeTips"));
StringVector.push_back(_T("is"));
StringVector.push_back(_T("Cool!"));</pre>
<p>For watching it, we quick watch and click the <span style="color:#0000ff;">_First </span>member of vector and <span style="color:#0000ff;">adds an index to it to skip to the nth element</span>. See the screenshot.</p>
<p><img class="alignnone size-full wp-image-184" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/06/vector_watchusualmethod.jpg" alt="" width="498" height="327" /></p>
<p>Is there any better way to watch the whole vector instead of this iteration?</p>
<p><img class="alignnone size-medium wp-image-12" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
Yes! you can. First you&#8217;ve to get the vector size by adding &#8220;<span style="color:#0000ff;">StringVector.size()</span>&#8221; to watch window. Then you&#8217;ll get the <span style="color:#0000ff;">size</span>. Now add &#8220;<span style="color:#0000ff;">StringVector._First,size</span>&#8221; to the watch window. That will show all the elements in that vector. Just see the screenshot.</p>
<p><img class="alignnone size-full wp-image-185" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/06/vector_watchwindow.jpg" alt="" width="510" height="175" /></p>
<p><img class="alignnone size-medium wp-image-18" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
You can evaluate the same expression in your quick watch window. Have fun!</p>
<p><img class="alignnone size-medium wp-image-53" src="http://weseetips.files.wordpress.com/2008/03/intermediateseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audience &#8211; Intermediate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/06/23/how-to-watch-vectors-more-easily/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to detect Memory Leaks by using CRT?</title>
		<link>http://weseetips.com/2008/06/17/how-to-detect-memory-leaks-by-using-crt/</link>
		<comments>http://weseetips.com/2008/06/17/how-to-detect-memory-leaks-by-using-crt/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 18:50:28 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Debugging Tips]]></category>
		<category><![CDATA[CRT memory leaks]]></category>
		<category><![CDATA[crtdbg.h]]></category>
		<category><![CDATA[detect memory leaks]]></category>
		<category><![CDATA[memory leaks]]></category>
		<category><![CDATA[_CRTDBG_MAP_ALLOC]]></category>
		<category><![CDATA[_CrtDumpMemoryLeaks()]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=178</guid>
		<description><![CDATA[Memory leaks are every programmers nightmare. Usually we used to use memory leak detection tools such as Numega BoundsChecker, Rational Purify to find memory leaks. But do you know that our C Runtime library have pretty good support for isolating memory leaks? You&#8217;ve to enable memory leak tracking by defining constant &#8211; _CRTDBG_MAP_ALLOC and then [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
<span style="color:#0000ff;"> Memory leaks </span>are every <span style="color:#0000ff;">programmers nightmare</span>. Usually we used to use <span style="color:#0000ff;">memory leak detection tools</span> such as <span style="color:#0000ff;">Numega BoundsChecker</span>, <span style="color:#0000ff;">Rational Purify</span> to find memory leaks. But do you know that our <span style="color:#0000ff;">C Runtime library have pretty good support for isolating memory leaks?</span></p>
<p><img class="alignnone size-medium wp-image-12" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /></p>
<p>You&#8217;ve to enable memory leak tracking by defining constant &#8211; <span style="color:#0000ff;">_CRTDBG_MAP_ALLOC</span> and then call &#8211; <span style="color:#0000ff;">_CrtDumpMemoryLeaks()</span>. Now the leaks will be dumped to the Visual Studio output window. See the following code snippet.</p>
<pre>// Declare this in header.
#define _CRTDBG_MAP_ALLOC
#include &lt;crtdbg.h&gt;
...
void DetectLeaks()
{
    // Create some leaks.
    CString* pString = new CString;
    BYTE* pBuffer = new BYTE[100];

    // Dump memory leaks to output window.
    _CrtDumpMemoryLeaks();
}</pre>
<p>When you call <span style="color:#0000ff;">_CrtDumpMemoryLeaks()</span> the memory leak information <span style="color:#0000ff;">will be dumped to the output window</span>. For instance, see the dump for memory leaks that we&#8217;ve made in <span style="color:#0000ff;">DetectLeaks()</span>.</p>
<pre>Detected memory leaks!
Dumping objects -&gt;
C:\Jijo\Studies\VC++\MFC\RabbitDlg\<span style="color:#0000ff;">RabbitDlgDlg.cpp(183)</span> : {194} normal block at 0x00294990, 100 bytes long.
 Data: &lt;                &gt; CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
C:\Jijo\Studies\VC++\MFC\RabbitDlg\<span style="color:#0000ff;">RabbitDlgDlg.cpp(182)</span> : {193} normal block at 0x00293B20, 4 bytes long.
 Data: &lt;   _&gt; 14 FB 8C 5F
...
Object dump complete.</pre>
<p>The filename and line number of leak will be present in the dump. So easy, nah?</p>
<p><img class="alignnone size-medium wp-image-18" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
While creating your MFC applications, did you ever noticed a code block as follows in your files?</p>
<pre>#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif</pre>
<p>This is for <span style="color:#0000ff;">debug information</span>. By using this information, the <span style="color:#0000ff;">_CrtDumpMemoryLeaks()</span> keep track of the filename. <span style="color:#0000ff;">If you comment out this, the filename will not be present in the dump</span> which will make our task difficult. So never remove those line. I swear, they are really important! <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img class="alignnone size-medium wp-image-53" src="http://weseetips.files.wordpress.com/2008/03/intermediateseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audience &#8211; Intermediate</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/06/17/how-to-detect-memory-leaks-by-using-crt/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to enable/disable all breakpoints in single keystroke?</title>
		<link>http://weseetips.com/2008/06/09/how-to-enabledisable-all-breakpoints-in-single-keystroke/</link>
		<comments>http://weseetips.com/2008/06/09/how-to-enabledisable-all-breakpoints-in-single-keystroke/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 17:52:44 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Debugging Tips]]></category>
		<category><![CDATA[Breakpoint]]></category>
		<category><![CDATA[disable breakpoint]]></category>
		<category><![CDATA[enable breakpoint]]></category>
		<category><![CDATA[keystroke]]></category>
		<category><![CDATA[macros]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=161</guid>
		<description><![CDATA[During heavy debugging, we usually have dozens of breakpoints dropped in various locations of source. Some of these breakpoints can also be in the application startup route. While stopping and starting programs during debugging, these breakpoints are really irritating, because they stop always. I&#8217;ve to press F5 a couple to times to start the application [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
During heavy debugging, we usually <span style="color:#0000ff;">have dozens of breakpoints</span> dropped in various locations of source. Some of these breakpoints can also be in the application startup route. <span style="color:#0000ff;">While stopping and starting programs during debugging</span>, these <span style="color:#0000ff;">breakpoints are really irritating</span>, because they stop always. <span style="color:#0000ff;">I&#8217;ve to press F5 a couple to times to start the application and run it.</span> If there&#8217;s some <span style="color:#0000ff;">shortcuts to enable and disable all break points at one single keystroke,</span> it will be nice. isn&#8217;t it? But how?</p>
<p><img class="alignnone size-medium wp-image-12" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
You can use the <span style="color:#0000ff;">VisualStudio&#8217;s powerful object model</span> to do so. See the macro code for enabling and disabling the breakpoints. <span style="color:#0000ff;">In later steps, i&#8217;ll explain how to map it to keystroke.</span> The macro code is as follows,</p>
<pre>' Macro to Enable all Breakpoints.
Sub EnableBreakPoints()
    Dim myBreakpoint
    For Each myBreakpoint in Debugger.Breakpoints
        ' Enable the break points.
        myBreakpoint.Enabled=True
    Next
End Sub

' Macro to Disable all Breakpoints.
Sub DisableBreakPoints()
    Dim myBreakpoint
    For Each myBreakpoint in Debugger.Breakpoints
        ' Disable the break points.
        myBreakpoint.Enabled=False
    Next
End Sub</pre>
<p><span style="text-decoration:underline;"><strong>How to map the macros to Keystroke</strong></span><br />
1) Take <span style="color:#0000ff;">Tools &gt; Macro</span>.<br />
2) Now you&#8217;ll see your macro window and <span style="color:#0000ff;">i assume no macros are defined</span> in your macro file. For getting the macro editor, enter <span style="color:#0000ff;">some dummy macro name</span> and click <span style="color:#0000ff;">&#8220;edit&#8221; button</span>.<br />
<img class="alignnone size-full wp-image-162" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/06/breakpoint_inkeystroke_macros.jpg" alt="" width="337" height="309" /></p>
<p>3) Now Macro editor will be opened and copy-paste the Enable/Disable macro code in your macro editor and save it.<br />
4) Now take <span style="color:#0000ff;">Tools &gt; Macro</span> again and VisualStudio will ask, <span style="color:#0000ff;">whether to reload the macros</span>. <span style="color:#0000ff;">Press Yes</span>.<br />
5) Now you&#8217;ll see the macro dialog, and click &#8220;<span style="color:#0000ff;">Options</span>&#8221; and &#8220;<span style="color:#0000ff;">Keystrokes</span>&#8220;.<br />
<img class="alignnone size-full wp-image-163" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/06/breakpoint_inkeystroke_macros1.jpg" alt="" width="337" height="403" /></p>
<p>6) Now <span style="color:#0000ff;">select the macro</span> and <span style="color:#0000ff;">press a key combination</span>, then click <span style="color:#0000ff;">&#8220;Assign&#8221;</span>.<br />
<img class="alignnone size-full wp-image-164" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/06/breakpoint_inkeystroke_macros2.jpg" alt="" width="451" height="313" /></p>
<p>7) The <span style="color:#0000ff;">greatest difficult </span>that you&#8217;ll face <span style="color:#0000ff;">is to find a free slot of key combination.</span> Almost all are reserved by visual studio itself. <img src='http://weseetips.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  After some R&amp;D I&#8217;ve found <span style="color:#0000ff;">two working key combination</span> &#8211; <span style="color:#0000ff;">Alt+z</span> and<span style="color:#0000ff;"> Alt+x</span>. Map your enable/disable macros to those shortcuts.</p>
<p>8 ) Now take visual studio and press the key combination to disable the breakpoints. <span style="color:#0000ff;"><strong>Note that the breakpoints will not be visually disabled</strong></span> but if you <span style="color:#0000ff;"><strong>take breakpoint window by Ctrl+B you can see all are disabled.</strong></span> This happens because we&#8217;ve modified the internal structure of VisualStudio, but GUI is not refreshed.</p>
<p><img class="alignnone size-medium wp-image-18" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
The only drawback is the breakpoints will not be visually disabled on keystroke. I&#8217;m searching for some solution and hope i&#8217;ll be back soon. Till then enjoy this one. <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img class="alignnone size-medium wp-image-53" src="http://weseetips.files.wordpress.com/2008/03/intermediateseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audience &#8211; Intermediate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/06/09/how-to-enabledisable-all-breakpoints-in-single-keystroke/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>CRT Debug support &#8211; The Magic Memory values.</title>
		<link>http://weseetips.com/2008/04/29/crt-debug-support-the-magic-memory-values/</link>
		<comments>http://weseetips.com/2008/04/29/crt-debug-support-the-magic-memory-values/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 05:26:39 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Debugging Tips]]></category>
		<category><![CDATA[/GZ]]></category>
		<category><![CDATA[0xCD]]></category>
		<category><![CDATA[0xDD]]></category>
		<category><![CDATA[0xFD]]></category>
		<category><![CDATA[CRT]]></category>
		<category><![CDATA[debug heap]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[NoMansLand]]></category>
		<category><![CDATA[OxCC]]></category>
		<category><![CDATA[VC++]]></category>
		<category><![CDATA[Visual C++]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=88</guid>
		<description><![CDATA[Memory corruptions are every programmer’s nightmare. But Debug Heap provides some facility in debug build to help you to get rid of those memory corrupting problems. Depending to the type of memory allocation we have done, the debug heap will fill some magic value for the allocated memory contents. Take care that, this will be [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" src="http://weseetips.wordpress.com/files/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
Memory corruptions are every programmer’s nightmare. But Debug Heap provides some facility in debug build to help you to get rid of those memory corrupting problems. Depending to the type of memory allocation we have done, the debug heap will fill some magic value for the allocated memory contents. Take care that, this will be available only in debug build. Please see below.</p>
<p><img class="alignnone size-medium wp-image-15" src="http://weseetips.wordpress.com/files/2008/03/icon_underthehood.jpg?w=208" alt="" width="208" height="32" /></p>
<ol>
<li><span style="color: #0000ff;">0xCD</span> – The memory locations filled with this magic number are allocated in heap and is not initialized.</li>
<li><span style="color: #0000ff;">0xFD</span> – This magic number is known as <span style="color: #0000ff;">“NoMansLand”</span>. The debug heap will fill the boundary of the allocated memory block will this value. If you are rewriting this value, then it means, you are beyond an allocated memory block.</li>
<li><span style="color: #0000ff;">0xCC</span> – The memory locations filled with this magic number means, it’s allocated in stack but not initialized. You can see this when you a variable on stack and look at its memory location. You can use <span style="color: #0000ff;">/GZ</span> compiler option to get the same feature in release build.</li>
<li><span style="color: #0000ff;">0xDD</span> – The memory locations filled with this magic number are Released heap memory.</li>
</ol>
<p><img class="alignnone size-medium wp-image-18" src="http://weseetips.wordpress.com/files/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
Regarding the 4th one &#8211; 0xDD, when I tried, the deleted memory locations are filled with 0xFEEE. I&#8217;ve to check it further. as per documentation its 0xDD.</p>
<p><img class="alignnone size-medium wp-image-53" src="http://weseetips.wordpress.com/files/2008/03/intermediateseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audience &#8211; Intermediate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/04/29/crt-debug-support-the-magic-memory-values/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to take command Prompt with default path as Selected Folder Path.</title>
		<link>http://weseetips.com/2008/04/22/how-to-take-command-prompt-with-default-path-as-selected-folder-path/</link>
		<comments>http://weseetips.com/2008/04/22/how-to-take-command-prompt-with-default-path-as-selected-folder-path/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 17:41:52 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Debugging Tips]]></category>
		<category><![CDATA[cmd.exe]]></category>
		<category><![CDATA[default path]]></category>
		<category><![CDATA[windows explorer]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=79</guid>
		<description><![CDATA[Usually in huge frameworks, we&#8217;ve to run a lot of console applications for starting up the system. Sometimes we&#8217;ve to start it by specifying long commandline arguments. In those cases, instead of double click and running the application, usually we take command prompt and start applications by entering commandline. When, Console opens, it points to [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
Usually in huge frameworks, we&#8217;ve to run a lot of console applications for starting up the system. Sometimes we&#8217;ve to start it by specifying long commandline arguments. In those cases, instead of double click and running the application, usually we take command prompt and start applications by entering commandline.</p>
<p>When, Console opens, it points to the default path and we&#8217;ve change the directory to required folder by CD command. Is there any easy way to start command prompt with default path as selected folder in Windows explorer? Yep! there is.</p>
<p><img class="alignnone size-medium wp-image-12" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
Just do the following steps.</p>
<p>1) Take <span style="color:#0000ff;">Windows explorer</span>.<br />
2) Take <span style="color:#0000ff;">Tools &gt; Folder options</span>.<br />
3) Take <span style="color:#0000ff;">File Types</span> tab.<br />
4) Select &#8220;<span style="color:#0000ff;">Folder</span>&#8221; Filetype.<br />
5) Click <span style="color:#0000ff;">advanced</span>.<br />
6) Click &#8220;<span style="color:#0000ff;">New</span>&#8221;<br />
7) Now give Action: &#8220;<span style="color:#0000ff;">Cmd</span>&#8221; and application used to perform action as &#8220;<span style="color:#0000ff;">cmd.exe</span>&#8221;<br />
8 ) Now, click <span style="color:#0000ff;">ok in all dialogs</span>.<br />
9) Now press <span style="color:#0000ff;">WinKey+E</span> to see the windows explorer.<br />
10) Now <span style="color:#0000ff;">right click on any of the folders in tree</span> and you can see the menu item <span style="color:#0000ff;">cmd</span>.<br />
11) Now click on that, a new console will be opened with default path as selected folder&#8217;s path.</p>
<p><img class="alignnone size-medium wp-image-51" src="http://weseetips.files.wordpress.com/2008/03/beginnerseries.jpg?w=215" alt="" width="215" height="32" /><br />
Targeted Audience &#8211; Beginners.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/04/22/how-to-take-command-prompt-with-default-path-as-selected-folder-path/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to locate the source code which pops the error message &#8211; More easily.</title>
		<link>http://weseetips.com/2008/04/17/how-to-locate-the-source-code-which-pops-the-error-message-more-easily/</link>
		<comments>http://weseetips.com/2008/04/17/how-to-locate-the-source-code-which-pops-the-error-message-more-easily/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 16:08:34 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Debugging Tips]]></category>
		<category><![CDATA[breaking at messagebox]]></category>
		<category><![CDATA[Breakpoint]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[MessageBox]]></category>
		<category><![CDATA[VC++]]></category>
		<category><![CDATA[Visual C++]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=74</guid>
		<description><![CDATA[While debugging huge code bases, unexpectedly some error messages can be popped up. Most probably we might be seeing it for the first time and don&#8217;t have any idea, from which location of the code base, the error message get fired. How to locate it easily? Just follow the steps - 1) Start the project [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-11" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg" alt="" width="166" height="32" /><br />
While debugging huge code bases, unexpectedly some error messages can be popped up. Most probably we might be seeing it for the first time and don&#8217;t have any idea, from which location of the code base, the error message get fired. How to locate it easily?</p>
<p><img class="alignnone size-full wp-image-12" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg" alt="" width="220" height="32" /><br />
Just follow the steps -</p>
<p>1) Start the project by <span style="color:#0000ff;">F5</span>.<br />
2) Do the steps to make the error messagebox to be shown. <span style="color:#0000ff;">Now the error message will be shown.<br />
</span>3) Now instead of clicking of in the error message, take debugger and click menu, <span style="color:#0000ff;">Debug -&gt; Break</span>.<br />
4) Now take <span style="color:#0000ff;">Debug -&gt; Threads </span>to see the threads running in your application.<br />
5) You can see one of your thread, which is paused in a messagebox showing routine.<br />
6) Select that thread and <span style="color:#0000ff;">click SetFocus</span>, to focus that thread.<br />
7) Now take the <span style="color:#0000ff;">Call Stack</span> by <span style="color:#0000ff;">Alt+7</span> and iterate through it from top to bottom.<br />
8 ) <span style="color:#0000ff;">You see one familiar function?</span> Yes! its the one which pops the error message. Now go and fix the bug <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img class="alignnone size-medium wp-image-18" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg" alt="" width="94" height="32" /><br />
You can also put a breakpoint by finding the memory address of the functions that can be used for showing error messages. But, if the application uses some custom dialogs, then you&#8217;ve to put more effort. This method is the handy one with least headaches. Try it!</p>
<p><img class="alignnone size-medium wp-image-51" src="http://weseetips.files.wordpress.com/2008/03/beginnerseries.jpg" alt="" width="215" height="32" /><br />
Targeted Audience &#8211; Beginners.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/04/17/how-to-locate-the-source-code-which-pops-the-error-message-more-easily/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

