<?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>Debugging | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/category/debugging/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Sat, 26 Apr 2025 14:24:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>Debugging | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>Debugging C/C++ and Rust with codelldb</title>
		<link>https://learncgames.com/debugging-c-c-and-rust-with-codelldb/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=debugging-c-c-and-rust-with-codelldb</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 26 Apr 2025 23:05:03 +0000</pubDate>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Rust]]></category>
		<category><![CDATA[debugging]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3381</guid>

					<description><![CDATA[<p>As a user of Visual Studio since about VS 5, I&#8217;ve become accustomed to being able to debug. With VS Code, it&#8217;s also been easy but now that I program in C and Rust, the codelldb extension makes things very easy. You need other extensions: for Rust- the Rust Analyzer extension and for C/C++ the [&#8230;]</p>
The post <a href="https://learncgames.com/debugging-c-c-and-rust-with-codelldb/">Debugging C/C++ and Rust with codelldb</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img fetchpriority="high" decoding="async" class="alignleft size-full wp-image-3385" src="https://learncgames.com/wp-content/uploads/2025/04/extensions.png" alt="Extensions for C/C++" width="350" height="562" srcset="https://learncgames.com/wp-content/uploads/2025/04/extensions.png 350w, https://learncgames.com/wp-content/uploads/2025/04/extensions-187x300.png 187w" sizes="(max-width: 350px) 100vw, 350px" />As a user of Visual Studio since about VS 5, I&#8217;ve become accustomed to being able to debug. With VS Code, it&#8217;s also been easy but now that I program in C and Rust, the <strong>codelldb</strong> extension makes things very easy. You need other extensions: for Rust- the Rust Analyzer extension and for C/C++ the Microsoft C/C++ extension.</p>
<p>And for debugging for both the codelldb extension which is shown.  It uses the usual Microsoft debugging keys: F5 to start F10 to step over, F11 to step into and F9 to toggle a breakpoint.</p>
<p>Below is an example of debugging a Rust program.</p>
<p><img decoding="async" class="alignleft size-full wp-image-3386" src="https://learncgames.com/wp-content/uploads/2025/04/debuggingRust.png" alt="debugging Rust program in VS Code" width="1094" height="557" srcset="https://learncgames.com/wp-content/uploads/2025/04/debuggingRust.png 1094w, https://learncgames.com/wp-content/uploads/2025/04/debuggingRust-300x153.png 300w, https://learncgames.com/wp-content/uploads/2025/04/debuggingRust-1024x521.png 1024w, https://learncgames.com/wp-content/uploads/2025/04/debuggingRust-768x391.png 768w" sizes="(max-width: 1094px) 100vw, 1094px" /></p>The post <a href="https://learncgames.com/debugging-c-c-and-rust-with-codelldb/">Debugging C/C++ and Rust with codelldb</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3381</post-id>	</item>
		<item>
		<title>How to debug programs using SDL</title>
		<link>https://learncgames.com/how-to-debug-programs-using-sdl/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-debug-programs-using-sdl</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 01 Jan 2023 00:00:51 +0000</pubDate>
				<category><![CDATA[bugs]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[fprintf]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3174</guid>

					<description><![CDATA[<p>There&#8217;s nothing worse than a program halting with a simple &#8220;Segmentation fault&#8221; and no idea where or why. It happened to me today working on the 2nd eBook (for Raspberry Pi) and I had to figure out where it was going wrong. In the end it was a really silly bug, I was trying to [&#8230;]</p>
The post <a href="https://learncgames.com/how-to-debug-programs-using-sdl/">How to debug programs using SDL</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><script type='application/json' class='__iawmlf-post-loop-links'>[{"id":35,"href":"https:\/\/www.educba.com\/stderr-in-c","archived_href":"http:\/\/web-wp.archive.org\/web\/20260206111555\/https:\/\/www.educba.com\/stderr-in-c\/","redirect_href":"https:\/\/www.educba.com\/stderr-in-c\/","checks":[{"date":"2026-02-06 22:25:29","http_code":200},{"date":"2026-02-10 08:53:49","http_code":200},{"date":"2026-02-13 20:32:51","http_code":200},{"date":"2026-02-17 13:34:58","http_code":200},{"date":"2026-02-21 07:08:05","http_code":503},{"date":"2026-02-24 21:19:48","http_code":200},{"date":"2026-02-28 13:10:48","http_code":200},{"date":"2026-03-04 05:12:26","http_code":200},{"date":"2026-03-09 21:59:48","http_code":200},{"date":"2026-03-15 12:33:12","http_code":200},{"date":"2026-03-21 03:40:03","http_code":200},{"date":"2026-03-24 15:23:00","http_code":200},{"date":"2026-03-29 10:24:48","http_code":503},{"date":"2026-04-01 20:14:49","http_code":200},{"date":"2026-04-05 02:03:12","http_code":200},{"date":"2026-04-08 11:16:00","http_code":200},{"date":"2026-04-11 14:30:33","http_code":200},{"date":"2026-04-15 09:28:36","http_code":200},{"date":"2026-04-19 12:07:25","http_code":200},{"date":"2026-04-24 14:23:39","http_code":200},{"date":"2026-04-28 11:16:25","http_code":200},{"date":"2026-05-02 00:14:50","http_code":200},{"date":"2026-05-05 20:18:16","http_code":200},{"date":"2026-05-09 09:16:20","http_code":200}],"broken":false,"last_checked":{"date":"2026-05-09 09:16:20","http_code":200},"process":"done"}]</script><img decoding="async" class="alignleft size-full wp-image-3176" src="https://learncgames.com/wp-content/uploads/2023/01/fprintf.png" alt="Terminal fprintf output" width="373" height="117" srcset="https://learncgames.com/wp-content/uploads/2023/01/fprintf.png 373w, https://learncgames.com/wp-content/uploads/2023/01/fprintf-300x94.png 300w" sizes="(max-width: 373px) 100vw, 373px" />There&#8217;s nothing worse than a program halting with a simple &#8220;Segmentation fault&#8221; and no idea where or why. It happened to me today working on the 2nd eBook (for Raspberry Pi) and I had to figure out where it was going wrong.</p>
<p>In the end it was a really silly bug, I was trying to load masks but had left the <strong>masks/</strong> folder out of the filename.</p>
<p>How did I find it? I sprinkled a few <strong>fprintf(stderr,&#8221;message&#8221;);</strong> throughout the program changing &#8220;message&#8221; to something appropriate and launched it from a terminal. I&#8217;d thought it was in a function <strong>LoadTextures()</strong> so added a call before and after but you can see that worked and the segmentation fault happened <em>after</em> <strong>LoadTextures()</strong>.</p>
<p>So I added it before and after <strong>LoadMasks()</strong> and my second run it happened before it reached the <strong>After LoadMasks</strong> message.</p>
<p>Note, I used <strong>stderr</strong> as the output path because, unlike <strong>stdout</strong> which is buffered and can be cleared, anything sent to <strong>stderr</strong> appears immediately.  More about this in this <a title="Link to article about stderr" href="https://www.educba.com/stderr-in-c/" target="_blank" rel="nofollow noopener">offsite article</a>.</p>
<p>The <strong>using SDL</strong> part of the title is just to show that you can find bugs even in programs that use SDL.</p>The post <a href="https://learncgames.com/how-to-debug-programs-using-sdl/">How to debug programs using SDL</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3174</post-id>	</item>
		<item>
		<title>Code::Blocks revisited</title>
		<link>https://learncgames.com/codeblocks-revisited/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=codeblocks-revisited</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 17 May 2020 23:00:09 +0000</pubDate>
				<category><![CDATA[Code::Blocks]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[SDL]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=627</guid>

					<description><![CDATA[<p>So after yesterday&#8217;s post I also installed Code::Blocks on Ubuntu 20.04 LTS, the recent six monthly Ubuntu release. Guess what, it&#8217;s a much newer version of Code::Blocks that looks slightly different and does include SDL2. Although the demo program it creates is C++ not C (That coloured bar picture is the demo).  I haven&#8217;t used [&#8230;]</p>
The post <a href="https://learncgames.com/codeblocks-revisited/">Code::Blocks revisited</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="alignleft size-medium wp-image-630" src="https://learncgames.com/wp-content/uploads/2020/05/codeblocks_SDL2_demo-300x243.png" alt="Code::Blocks SDL2 demo" width="300" height="243" srcset="https://learncgames.com/wp-content/uploads/2020/05/codeblocks_SDL2_demo-300x243.png 300w, https://learncgames.com/wp-content/uploads/2020/05/codeblocks_SDL2_demo.png 640w" sizes="auto, (max-width: 300px) 100vw, 300px" />So after yesterday&#8217;s post I also installed Code::Blocks on Ubuntu 20.04 LTS, the recent six monthly Ubuntu release. Guess what, it&#8217;s a much newer version of Code::Blocks that looks slightly different and does include SDL2. Although the demo program it creates is C++ not C (That coloured bar picture is the demo).  I haven&#8217;t used it enough to see what&#8217;s different between this and version 16.01.</p>
<p>The version of Code::Blocks on the 18.04LTS Ubuntu  was 16.01 and on Ubuntu 20.04 LTS it&#8217;s Code::Blocks 20.03. I keep my Ubuntus up to date but the 18.04 LTS hasn&#8217;t switched to the newer Code::Blocks which surprised me. I&#8217;m guessing that the maintainers of the 18.04 LTS Ubuntu repositories just haven&#8217;t updated their copy of Code::Blocks.</p>
<p>One thing I hadn&#8217;t explored in Code::Blocks is the debugging and this seems a lot more powerful than what you get in Visual Studio Code.   This screenshot below from version 20 shows it is more akin to Visual Studio debugging rather than Visual Studio Code debugging what with CPU registers, stack, memory dump and threads.</p>
<p><img loading="lazy" decoding="async" class="alignleft size-medium wp-image-631" src="https://learncgames.com/wp-content/uploads/2020/05/codeblocks_debugging_menu-300x297.png" alt="Code::Blocks Debugging Menu" width="300" height="297" srcset="https://learncgames.com/wp-content/uploads/2020/05/codeblocks_debugging_menu-300x297.png 300w, https://learncgames.com/wp-content/uploads/2020/05/codeblocks_debugging_menu-150x150.png 150w, https://learncgames.com/wp-content/uploads/2020/05/codeblocks_debugging_menu.png 534w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/codeblocks-revisited/">Code::Blocks revisited</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">627</post-id>	</item>
		<item>
		<title>And the bug is fixed</title>
		<link>https://learncgames.com/and-the-bug-is-fixed/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=and-the-bug-is-fixed</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Mon, 06 Apr 2020 23:00:56 +0000</pubDate>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[bugs]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=320</guid>

					<description><![CDATA[<p>How did I fix it? Did I spend hours debugging, poring over every line? No. I woke up in the middle of the night and thought about it and remembered that I&#8217;d had a similar bug in this chapter when working on the original Ebook. Stupidly I&#8217;d put the fix in the sources for the [&#8230;]</p>
The post <a href="https://learncgames.com/and-the-bug-is-fixed/">And the bug is fixed</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="size-full wp-image-321 alignleft" src="https://learncgames.com/wp-content/uploads/2020/03/bug-tracking.png" alt="Showing the comparison of two sources and tracking a bug down" width="500" height="116" srcset="https://learncgames.com/wp-content/uploads/2020/03/bug-tracking.png 500w, https://learncgames.com/wp-content/uploads/2020/03/bug-tracking-300x70.png 300w" sizes="auto, (max-width: 500px) 100vw, 500px" />How did I fix it? Did I spend hours debugging, poring over every line? No. I woke up in the middle of the night and thought about it and remembered that</p>
<p>I&#8217;d had a similar bug in this chapter when working on the original Ebook.</p>
<p>Stupidly I&#8217;d put the fix in the sources for the next chapter (44) but hadn&#8217;t applied it to the sources in the chapter where it had occurred (42). So I fired up my favourite code comparison tool (Devart Code Compare) and looked for differences between the source files for each chapter.</p>
<p>This was in the function AddObjectToCells and is part of the collision detection. It&#8217;s when an asteroid or player ship is partly on screen and calculating the cell coordinates that the object lies over. The fix was just adding these two lines so it doesn&#8217;t try and access the cells array with negative indices.</p>
<pre><code class="language-c" data-line="">if (cellx &lt; 0) cellx = 0;
if (celly &lt; 0) celly = 0;</code></pre>The post <a href="https://learncgames.com/and-the-bug-is-fixed/">And the bug is fixed</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">320</post-id>	</item>
		<item>
		<title>Bugs and crashes!</title>
		<link>https://learncgames.com/bugs-and-crashes/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=bugs-and-crashes</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 04 Apr 2020 23:00:27 +0000</pubDate>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[bugs]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=311</guid>

					<description><![CDATA[<p>I&#8217;m up to chapter 42 in the Linux e-book. The rest have gone very smoothly though I&#8217;m still unable to debug either on my Hyper-V Ubuntu or my Ubuntu running laptop. Both still have the same problem XDG_RUNTIME_DIR not set in the environment. I&#8217;ve been reading up on that and it seems if you switch [&#8230;]</p>
The post <a href="https://learncgames.com/bugs-and-crashes/">Bugs and crashes!</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><script type='application/json' class='__iawmlf-post-loop-links'>[{"id":786,"href":"https:\/\/pixabay.com\/users\/ROverhate-1759589\/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=1142373","archived_href":"","redirect_href":"","checks":[],"broken":false,"last_checked":null,"process":"done"},{"id":787,"href":"https:\/\/pixabay.com\/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=1142373","archived_href":"","redirect_href":"","checks":[],"broken":false,"last_checked":null,"process":"done"},{"id":14,"href":"https:\/\/github.com\/David-H-Bolton\/LearnCOnLinux","archived_href":"http:\/\/web-wp.archive.org\/web\/20250213114627\/https:\/\/github.com\/David-H-Bolton\/LearnCOnLinux","redirect_href":"","checks":[{"date":"2026-02-06 10:35:12","http_code":206},{"date":"2026-02-09 16:40:14","http_code":206},{"date":"2026-02-12 18:24:15","http_code":206},{"date":"2026-02-15 22:16:31","http_code":206},{"date":"2026-02-18 22:19:30","http_code":206},{"date":"2026-02-21 22:22:05","http_code":206},{"date":"2026-02-25 04:17:24","http_code":206},{"date":"2026-02-28 04:17:49","http_code":206},{"date":"2026-03-03 04:22:25","http_code":206},{"date":"2026-03-06 04:38:10","http_code":206},{"date":"2026-03-09 08:48:04","http_code":206},{"date":"2026-03-12 09:17:10","http_code":206},{"date":"2026-03-15 10:18:26","http_code":206},{"date":"2026-03-18 12:43:49","http_code":206},{"date":"2026-03-21 15:14:39","http_code":206},{"date":"2026-03-24 15:19:12","http_code":206},{"date":"2026-03-27 16:38:15","http_code":206},{"date":"2026-03-30 19:05:39","http_code":206},{"date":"2026-04-02 19:29:41","http_code":206},{"date":"2026-04-05 21:51:33","http_code":206},{"date":"2026-04-08 22:18:13","http_code":206},{"date":"2026-04-11 22:18:38","http_code":206},{"date":"2026-04-14 22:20:58","http_code":206},{"date":"2026-04-18 07:27:41","http_code":206},{"date":"2026-04-21 10:16:46","http_code":206},{"date":"2026-04-24 10:43:49","http_code":206},{"date":"2026-04-27 13:14:21","http_code":206},{"date":"2026-04-30 15:34:31","http_code":206},{"date":"2026-05-03 16:18:12","http_code":206},{"date":"2026-05-06 16:19:35","http_code":206}],"broken":false,"last_checked":{"date":"2026-05-06 16:19:35","http_code":206},"process":"done"}]</script><figure id="attachment_312" aria-describedby="caption-attachment-312" style="width: 300px" class="wp-caption alignleft"><img loading="lazy" decoding="async" class="size-medium wp-image-312" src="https://learncgames.com/wp-content/uploads/2020/03/beetle-1142373_640-300x200.jpg" alt="A bug!" width="300" height="200" srcset="https://learncgames.com/wp-content/uploads/2020/03/beetle-1142373_640-300x200.jpg 300w, https://learncgames.com/wp-content/uploads/2020/03/beetle-1142373_640.jpg 640w" sizes="auto, (max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-312" class="wp-caption-text">Image by <a href="https://pixabay.com/users/ROverhate-1759589/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1142373">Ronny Overhate</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1142373">Pixabay</a></figcaption></figure></p>
<p>I&#8217;m up to chapter 42 in the Linux e-book. The rest have gone very smoothly though I&#8217;m still unable to debug either on my Hyper-V Ubuntu or my Ubuntu running laptop. Both still have the same problem XDG_RUNTIME_DIR not set in the environment.</p>
<p>I&#8217;ve been reading up on that and it seems if you switch into root and the value of the environment variable $XAUTHORITY is blank then that is the problem.</p>
<p>My error logging is picking up problems with sound channels not playing. I think the problem is, when I hit the b key to make lots of asteroids explode, it uses up all available sound channels and there&#8217;s still explosions happening.  Not really a problem.</p>
<p>But to cap it all, there is a segmentation error happening with a core dump. A segfault which kills the program. But it&#8217;s not related to the sound problem. I&#8217;ve proved that by commenting out the entire PlayASound function. It now looks like this which I call the sound of silence.</p>
<pre><code class="language-c" data-line="">void PlayASound(int soundindex) {
	//int success=Mix_PlayChannel(-1, sounds[soundindex], 0);
	//if (success == -1) {
	//	LogError2(&quot;Mix_PlayChannel failed to play audio sound #&quot;,SDL_ltoa(soundindex,buffer,10));
	//}
}</code></pre>
<p>So without being able to run the program in a debugger, I&#8217;m forced to start putting in lots of logging calls and figure out where the segfault happens that way. It&#8217;s an effective way of finding bugs BUT it&#8217;s not the fastest! I have also enabled apport to try and get the crash files created in /var/crash so that may be a faster way forward.</p>
<p>Once I have fixed the segmentation fault, I&#8217;ll upload the fixed code to <a href="https://github.com/David-H-Bolton/LearnCOnLinux" target="_blank" rel="noopener noreferrer">Github</a>. It&#8217;ll be somewhere in the new code added between chapter 37 and chapter 42, to do with collision detection. Time to put on a deerstalker hat!</p>The post <a href="https://learncgames.com/bugs-and-crashes/">Bugs and crashes!</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">311</post-id>	</item>
		<item>
		<title>Logging on Windows &#8211; OutputDebugString</title>
		<link>https://learncgames.com/logging-on-windows-outputdebugstring/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=logging-on-windows-outputdebugstring</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Wed, 01 Apr 2020 23:00:56 +0000</pubDate>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[debugview]]></category>
		<category><![CDATA[windows]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=280</guid>

					<description><![CDATA[<p>In the post about rsyslog three days ago, I explained how to log from Linux programs using the rsyslog daemon. It&#8217;s slightly different in Windows. There&#8217;s a built in function called OutputDebugString(LPCWSTR str) that you can call from anywhere in your program. It dumps the string str into the Output window if you are debugging it [&#8230;]</p>
The post <a href="https://learncgames.com/logging-on-windows-outputdebugstring/">Logging on Windows – OutputDebugString</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><script type='application/json' class='__iawmlf-post-loop-links'>[{"id":789,"href":"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/api\/debugapi\/nf-debugapi-outputdebugstringw","archived_href":"http:\/\/web-wp.archive.org\/web\/20220819064318\/https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/api\/debugapi\/nf-debugapi-outputdebugstringw","redirect_href":"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/debugapi\/nf-debugapi-outputdebugstringw","checks":[{"date":"2026-02-08 05:17:00","http_code":206},{"date":"2026-02-13 08:40:21","http_code":206},{"date":"2026-02-18 15:47:52","http_code":206},{"date":"2026-02-24 23:21:28","http_code":206},{"date":"2026-03-04 10:13:43","http_code":206},{"date":"2026-03-08 15:24:42","http_code":206},{"date":"2026-03-13 06:58:56","http_code":206},{"date":"2026-03-17 04:40:40","http_code":206},{"date":"2026-03-21 12:48:49","http_code":206},{"date":"2026-03-25 06:20:54","http_code":206},{"date":"2026-03-30 06:45:16","http_code":206},{"date":"2026-04-09 10:45:00","http_code":206},{"date":"2026-04-13 03:46:54","http_code":206},{"date":"2026-04-19 12:07:22","http_code":206},{"date":"2026-04-25 14:37:03","http_code":206},{"date":"2026-04-28 17:19:36","http_code":206},{"date":"2026-05-04 05:42:54","http_code":206},{"date":"2026-05-08 06:43:13","http_code":206}],"broken":false,"last_checked":{"date":"2026-05-08 06:43:13","http_code":206},"process":"done"},{"id":722,"href":"https:\/\/docs.microsoft.com\/en-gb\/sysinternals\/downloads\/debugview","archived_href":"http:\/\/web-wp.archive.org\/web\/20220506060827\/https:\/\/docs.microsoft.com\/en-gb\/sysinternals\/downloads\/debugview","redirect_href":"","checks":[{"date":"2026-02-06 17:54:37","http_code":206},{"date":"2026-02-13 08:40:20","http_code":206},{"date":"2026-02-17 09:55:02","http_code":206},{"date":"2026-02-20 12:43:20","http_code":206},{"date":"2026-02-24 23:21:27","http_code":206},{"date":"2026-03-04 10:13:43","http_code":206},{"date":"2026-03-08 13:20:42","http_code":206},{"date":"2026-03-13 06:59:03","http_code":206},{"date":"2026-03-17 04:40:37","http_code":206},{"date":"2026-03-21 12:48:49","http_code":206},{"date":"2026-03-25 06:20:55","http_code":206},{"date":"2026-03-30 06:45:16","http_code":206},{"date":"2026-04-09 10:45:00","http_code":206},{"date":"2026-04-13 03:46:54","http_code":206},{"date":"2026-04-19 12:07:19","http_code":206},{"date":"2026-04-25 14:37:03","http_code":206},{"date":"2026-04-28 17:19:36","http_code":206},{"date":"2026-05-04 05:42:53","http_code":206},{"date":"2026-05-08 06:43:15","http_code":206}],"broken":false,"last_checked":{"date":"2026-05-08 06:43:15","http_code":206},"process":"done"}]</script><img loading="lazy" decoding="async" class="size-medium wp-image-282 alignleft" src="https://learncgames.com/wp-content/uploads/2020/03/outputdebugstring-300x204.png" alt="Shows OutputDebugString being calld in the debugger" width="300" height="204" srcset="https://learncgames.com/wp-content/uploads/2020/03/outputdebugstring-300x204.png 300w, https://learncgames.com/wp-content/uploads/2020/03/outputdebugstring.png 430w" sizes="auto, (max-width: 300px) 100vw, 300px" />In the post about rsyslog three days ago, I explained how to log from Linux programs using the rsyslog daemon.</p>
<p>It&#8217;s slightly different in Windows. There&#8217;s a built in function called <a href="https://docs.microsoft.com/en-us/windows/win32/api/debugapi/nf-debugapi-outputdebugstringw" target="_blank" rel="noopener noreferrer">OutputDebugString(LPCWSTR str)</a> that you can call from anywhere in your program. It dumps the string str into the Output window if you are debugging it in Visual Studio.</p>
<p>If you are running this outside of a debugger, the output is lost unless you can capture it with a suitable utility. <a href="https://docs.microsoft.com/en-gb/sysinternals/downloads/debugview" target="_blank" rel="noopener noreferrer">DebugView</a> from SysInternals.com (it redirects to Microsoft) is one such utility. That&#8217;s a screenshot of it below.</p>
<p><img loading="lazy" decoding="async" class="size-medium wp-image-283 alignleft" src="https://learncgames.com/wp-content/uploads/2020/03/debugview-300x144.png" alt="Showing DebugView in action" width="300" height="144" srcset="https://learncgames.com/wp-content/uploads/2020/03/debugview-300x144.png 300w, https://learncgames.com/wp-content/uploads/2020/03/debugview.png 441w" sizes="auto, (max-width: 300px) 100vw, 300px" />Just run DebugView and leave it there. It might catch other stuff from Windows, but when you run your program from the command line or double click on it, it will execute quickly and you&#8217;ll see any strings captured like this one.</p>
<p>&nbsp;</p>
<p>This is the program that I ran. In Release it compiles to a 9 KB exe! Because OutPutDebugString needs a <a href="https://docs.microsoft.com/en-us/windows/win32/api/debugapi/nf-debugapi-outputdebugstringw" target="_blank" rel="noopener noreferrer">LPCWSTR </a> (Long Pointer to a WideString), I declared the text as wchar_t.</p>
<pre><code class="language-c" data-line="">#include &lt;Windows.h&gt;

int main()
{
    wchar_t * text=L&quot;Hello World!\n&quot;;
    OutputDebugString(text);
}
</code></pre>
<p>At work I developed a very large program that only worked running on another computer. I used OutputDebugString extensively and without it, debugging would have been much harder.</p>The post <a href="https://learncgames.com/logging-on-windows-outputdebugstring/">Logging on Windows – OutputDebugString</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">280</post-id>	</item>
		<item>
		<title>Using rsyslog to log</title>
		<link>https://learncgames.com/using-rsyslog-to-log/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-rsyslog-to-log</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 29 Mar 2020 23:00:49 +0000</pubDate>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[syslog]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=260</guid>

					<description><![CDATA[<p>I&#8217;m a great fan of logging; it helps you find out what&#8217;s happening in a program even if you can&#8217;t debug it. Linux, well Ubuntu has a service (sorry Daemon!)  called rsyslog that logs messages from all sorts of processes and it&#8217;s quite easy to use in our programs as well. If we don’t do [&#8230;]</p>
The post <a href="https://learncgames.com/using-rsyslog-to-log/">Using rsyslog to log</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><script type='application/json' class='__iawmlf-post-loop-links'>[{"id":790,"href":"https:\/\/pixabay.com\/users\/OpenClipart-Vectors-30363\/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=1294359","archived_href":"","redirect_href":"","checks":[],"broken":false,"last_checked":null,"process":"done"},{"id":791,"href":"https:\/\/pixabay.com\/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=1294359","archived_href":"","redirect_href":"","checks":[],"broken":false,"last_checked":null,"process":"done"},{"id":792,"href":"https:\/\/unix.stackexchange.com\/questions\/40533\/lubuntu-12-04-syslog-to-custom-file-not-var-log-syslog-but-var-log-mylog","archived_href":"http:\/\/web-wp.archive.org\/web\/20260206185812\/https:\/\/unix.stackexchange.com\/questions\/40533\/lubuntu-12-04-syslog-to-custom-file-not-var-log-syslog-but-var-log-mylog","redirect_href":"","checks":[{"date":"2026-02-07 19:52:38","http_code":200},{"date":"2026-02-13 08:40:20","http_code":200},{"date":"2026-02-18 15:47:54","http_code":200},{"date":"2026-02-27 16:02:31","http_code":200},{"date":"2026-03-04 18:48:24","http_code":200},{"date":"2026-03-13 06:58:56","http_code":200},{"date":"2026-03-17 04:40:35","http_code":200},{"date":"2026-03-24 21:28:23","http_code":200},{"date":"2026-03-30 07:56:13","http_code":200},{"date":"2026-04-05 13:01:10","http_code":200},{"date":"2026-04-08 17:15:23","http_code":200},{"date":"2026-04-11 18:47:03","http_code":200},{"date":"2026-04-15 13:31:17","http_code":200},{"date":"2026-04-19 12:07:27","http_code":200},{"date":"2026-05-02 04:43:08","http_code":200},{"date":"2026-05-06 10:27:40","http_code":200}],"broken":false,"last_checked":{"date":"2026-05-06 10:27:40","http_code":200},"process":"done"},{"id":793,"href":"https:\/\/unix.stackexchange.com\/users\/19704\/giuspen","archived_href":"http:\/\/web-wp.archive.org\/web\/20260206200312\/https:\/\/unix.stackexchange.com\/users\/19704\/giuspen","redirect_href":"","checks":[{"date":"2026-02-07 19:52:33","http_code":200},{"date":"2026-02-12 06:17:39","http_code":200},{"date":"2026-02-18 15:47:54","http_code":200},{"date":"2026-02-27 16:02:28","http_code":200},{"date":"2026-03-04 18:48:23","http_code":200},{"date":"2026-03-13 06:59:00","http_code":200},{"date":"2026-03-17 04:40:38","http_code":200},{"date":"2026-03-24 21:28:24","http_code":200},{"date":"2026-03-30 07:56:14","http_code":200},{"date":"2026-04-05 13:01:10","http_code":200},{"date":"2026-04-08 17:15:23","http_code":200},{"date":"2026-04-11 18:47:03","http_code":200},{"date":"2026-04-15 13:31:17","http_code":200},{"date":"2026-04-20 06:38:04","http_code":200},{"date":"2026-05-02 04:43:08","http_code":200},{"date":"2026-05-06 10:27:34","http_code":200}],"broken":false,"last_checked":{"date":"2026-05-06 10:27:34","http_code":200},"process":"done"}]</script><figure id="attachment_263" aria-describedby="caption-attachment-263" style="width: 300px" class="wp-caption alignleft"><img loading="lazy" decoding="async" class="size-medium wp-image-263" src="https://learncgames.com/wp-content/uploads/2020/03/computer-1294359_640-300x300.png" alt="logging" width="300" height="300" srcset="https://learncgames.com/wp-content/uploads/2020/03/computer-1294359_640-300x300.png 300w, https://learncgames.com/wp-content/uploads/2020/03/computer-1294359_640-150x150.png 150w, https://learncgames.com/wp-content/uploads/2020/03/computer-1294359_640.png 640w" sizes="auto, (max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-263" class="wp-caption-text">Image by <a href="https://pixabay.com/users/OpenClipart-Vectors-30363/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1294359">OpenClipart-Vectors</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1294359">Pixabay</a></figcaption></figure></p>
<p>I&#8217;m a great fan of logging; it helps you find out what&#8217;s happening in a program even if you can&#8217;t debug it. Linux, well Ubuntu has a service (sorry Daemon!)  called rsyslog that logs messages from all sorts of processes and it&#8217;s quite easy to use in our programs as well.</p>
<p>If we don’t do the next steps all the log messages will go into a file called syslog in <strong>/var/log</strong> and as this gets a lot of stuff it can grow reasonably quickly. But if you do the following steps, all logged output will instead go into</p>
<pre>/var/log/asteroids.log.</pre>
<p>From a terminal type the following command:</p>
<pre>sudo gedit /etc/rsyslog.d/30-debugging.conf</pre>
<p>Type this in and then save it (<em>click the Save button</em>) and close gedit.</p>
<pre>if $programname == 'asteroids' then /var/log/asteroids.log
&amp; ~</pre>
<p>Now run this command:</p>
<pre>sudo service rsyslog restart</pre>
<p>It should return immediately and means that any logging to syslog from a program called asteroids will from now on be redirected to /var/log/asteroids.log.</p>
<h2>Using rsyslog in a C program</h2>
<p>Here&#8217;s a short C Program that puts a message in the asteroids file.</p>
<pre><code class="language-c" data-line="">#include &lt;syslog.h&gt;
#include &lt;stdio.h&gt;

int main() {
    openlog(&quot;asteroids&quot;,LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);    
    syslog(LOG_INFO,&quot;Test Message %d&quot;,1);
    closelog();
}</code></pre>
<p>In a typical program you&#8217;d put the openlog statement in main() near the start and the closelog() near the end of main, and uses as many syslog() calls throughout your program as you need.</p>
<p>Now what I suggest you do is open another terminal and run this command before you run your main program. This will just sit there printing out each message line as it appears in asteroids.log. You can stop tail by hitting ctrl-c.</p>
<pre>tail -f /var/log/asteroids.log</pre>
<p>H/T to <a href="https://unix.stackexchange.com/questions/40533/lubuntu-12-04-syslog-to-custom-file-not-var-log-syslog-but-var-log-mylog" target="_blank" rel="noopener noreferrer">this StackExchange</a> answer from almost 8 years ago and answer by <a href="https://unix.stackexchange.com/users/19704/giuspen">giuspen</a>.</p>The post <a href="https://learncgames.com/using-rsyslog-to-log/">Using rsyslog to log</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">260</post-id>	</item>
		<item>
		<title>Problems debugging SDL2 with Visual Studio Code</title>
		<link>https://learncgames.com/problems-debugging-sdl2-with-visual-studio-code/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=problems-debugging-sdl2-with-visual-studio-code</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 29 Mar 2020 00:00:40 +0000</pubDate>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[SDL]]></category>
		<category><![CDATA[Visual Studio Code]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=255</guid>

					<description><![CDATA[<p>So my demo program runs fine when I run it from the terminal. It creates a SDL Window and blits lots of numbers, but if I try to start it in the debugger, it gets to this function and fails in the SDL_CreateWindowAndRenderer. void InitSetup() { srand((int)time(NULL)); SDL_Init(SDL_INIT_EVERYTHING); SDL_CreateWindowAndRenderer(WIDTH, HEIGHT, SDL_WINDOW_SHOWN, &#38;screen, &#38;renderer); if (!screen) [&#8230;]</p>
The post <a href="https://learncgames.com/problems-debugging-sdl2-with-visual-studio-code/">Problems debugging SDL2 with Visual Studio Code</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="size-medium wp-image-257 alignleft" src="https://learncgames.com/wp-content/uploads/2020/03/500-Numbers-300x233.png" alt="500 numbers blitted to screen by SDL2" width="300" height="233" srcset="https://learncgames.com/wp-content/uploads/2020/03/500-Numbers-300x233.png 300w, https://learncgames.com/wp-content/uploads/2020/03/500-Numbers.png 600w" sizes="auto, (max-width: 300px) 100vw, 300px" />So my demo program runs fine when I run it from the terminal. It creates a SDL Window and blits lots of numbers, but if I try to start it in the debugger, it gets to this function and fails in the SDL_CreateWindowAndRenderer.</p>
<pre><code class="language-c" data-line="">void InitSetup() {
	srand((int)time(NULL));
	SDL_Init(SDL_INIT_EVERYTHING);
	SDL_CreateWindowAndRenderer(WIDTH, HEIGHT, SDL_WINDOW_SHOWN, &amp;screen, &amp;renderer);
	if (!screen) {
		LogError(&quot;InitSetup failed to create window&quot;);
	}
	SetCaption(&quot;Example Two&quot;);
	LoadTextures();
}</code></pre>
<p>And in the Debug Console I can see two of these:</p>
<p><strong>@&#8221;error: XDG_RUNTIME_DIR not set in the environment.\r\n&#8221;</strong></p>
<p>followed by my error message <code class="language-c" data-line="">InitSetup failed to create window.</code></p>
<p>I&#8217;ve looked online and there&#8217;s one or two mentions. Now possibly it might be because I&#8217;m running <em>Ubuntu 18.04 LTS</em> <strong>under Hyper-V Manager</strong>.  I&#8217;ll try this on a laptop where I&#8217;ve installed the same version of Ubuntu on and see if the same thing happens.</p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/problems-debugging-sdl2-with-visual-studio-code/">Problems debugging SDL2 with Visual Studio Code</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">255</post-id>	</item>
	</channel>
</rss>
