<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Debugging Npp .exe without a debugger (beginner)]]></title><description><![CDATA[<p dir="auto">I’m using <a href="http://appveyor.com" rel="nofollow ugc">appveyor.com</a> to build debug versions of notepad++, as I’m trying to understand one small part of it (who’s curious can look at <a href="https://github.com/victorel-petrovich/notepad-plus-plus_lastRecentFileList.cpp" rel="nofollow ugc">https://github.com/victorel-petrovich/notepad-plus-plus_lastRecentFileList.cpp</a> ) .</p>
<p dir="auto">I researched today how to print to a console from a windows .exe, with <code>printf</code> or <code>cout</code> statements inserted in source code, and I want to share what I found,<br />
and maybe also I’ll find out better ways from you (while using appveyor building).</p>
<p dir="auto">So, I put the following in some initialization section (in my case - it works in lastRecentFileList.cpp, <code>initMenu()</code>):</p>
<pre><code>AllocConsole();
freopen("conin$","r",stdin);
freopen("conout$","w",stdout);
freopen("conout$","w",stderr);
printf("Debugging Window\n");	
printf("----------------\n");
</code></pre>
<p dir="auto">And then insert <code>printf</code> or <code>std::cout </code> (the latter with <code>#include &lt;iostream&gt;</code> at top of file) where I need.</p>
<p dir="auto">Another more primitive way is to insert <code>system("pause")</code> (no prerequisites needed) to get a popup window waiting for a keypress. Works as yes/no test.</p>
<p dir="auto">But maybe it’s possible better way, of specifying somewhere say in “appveyor.yml” that printing to a regular/parent console is allowed for a “debug” version…</p>
<p dir="auto">References (after a long search):<br />
<a href="https://stackoverflow.com/questions/2501968/visual-c-enable-console" rel="nofollow ugc">https://stackoverflow.com/questions/2501968/visual-c-enable-console</a><br />
<a href="https://stackoverflow.com/a/19406695/1558980" rel="nofollow ugc">https://stackoverflow.com/a/19406695/1558980</a><br />
<a href="https://stackoverflow.com/questions/40140248/output-to-windows-cmd-prompt" rel="nofollow ugc">https://stackoverflow.com/questions/40140248/output-to-windows-cmd-prompt</a></p>
<p dir="auto"><img src="/assets/uploads/files/1691603310537-f698a9f7-2094-4583-a2c9-969c7944dacd-debuggingwindow.png" alt="f698a9f7-2094-4583-a2c9-969c7944dacd-debuggingWindow.PNG" class=" img-fluid img-markdown" /> !</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/24805/debugging-npp-exe-without-a-debugger-beginner</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Jul 2026 13:28:58 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/24805.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 09 Aug 2023 17:47:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Debugging Npp .exe without a debugger (beginner) on Mon, 14 Aug 2023 21:19:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> said in <a href="/post/88568">Debugging Npp .exe without a debugger (beginner)</a>:</p>
<blockquote>
<p dir="auto">I assumed @Victorel-Petrovich wouldn’t mind it being moved</p>
</blockquote>
<p dir="auto">True</p>
]]></description><link>https://community.notepad-plus-plus.org/post/88614</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/88614</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Mon, 14 Aug 2023 21:19:24 GMT</pubDate></item><item><title><![CDATA[Reply to Debugging Npp .exe without a debugger (beginner) on Sun, 13 Aug 2023 16:33:45 GMT]]></title><description><![CDATA[<p dir="auto">Topic moved to the newly renamed and refocused “Notepad++ &amp; Plugin Development” category, where it naturally fits (I assumed @Victorel-Petrovich wouldn’t mind it being moved, since he was the one who wanted a specific place to ask such questions).</p>
<p dir="auto">Personally, when I am doing a lot of print-based debugging, I write wrapper functions or #define macros that encapsulate all the formatting into the string, and then call the proper output function with that string, so that I can just have a single line of code for each inline debug print, and I let the complications of definining a dummy buffer variable and the sprintf formatting elsewhere.</p>
<p dir="auto">But really, none of these questions are specific to debugging <em>Notepad++</em>, and is really a generic C/C++ “best way to debug without a debugger, without a console, or similar restriction” question.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/88568</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/88568</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Sun, 13 Aug 2023 16:33:45 GMT</pubDate></item><item><title><![CDATA[Reply to Debugging Npp .exe without a debugger (beginner) on Sun, 13 Aug 2023 04:43:16 GMT]]></title><description><![CDATA[<p dir="auto">Another option, pointed out to me by @Yaron10 on github:<br />
<code>printInt(int int2print)</code> and <code>printStr(const TCHAR *str2print)</code><br />
Will output in a message box…<br />
Comparable with OutputDebugString in the need to prepare the (complex) string beforehand, but doesn’t require a debugger or allocating a console.<br />
<a href="https://github.com/notepad-plus-plus/notepad-plus-plus/blob/master/PowerEditor/src/MISC/Common/Common.cpp#L32" rel="nofollow ugc">https://github.com/notepad-plus-plus/notepad-plus-plus/blob/master/PowerEditor/src/MISC/Common/Common.cpp#L32</a><br />
(The definitions also hint at how to properly pass the string).</p>
]]></description><link>https://community.notepad-plus-plus.org/post/88557</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/88557</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Sun, 13 Aug 2023 04:43:16 GMT</pubDate></item><item><title><![CDATA[Reply to Debugging Npp .exe without a debugger (beginner) on Thu, 10 Aug 2023 22:38:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> With column-mode editing, and duplication of lines etc, it’s not that bad.<br />
Much harder is to understand why I don’t get the results I expect, doing lots of googling , and try again and again.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/88521</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/88521</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Thu, 10 Aug 2023 22:38:29 GMT</pubDate></item><item><title><![CDATA[Reply to Debugging Npp .exe without a debugger (beginner) on Thu, 10 Aug 2023 18:23:31 GMT]]></title><description><![CDATA[<p dir="auto">@Victorel-Petrovich said in <a href="/post/88513">Debugging Npp .exe without a debugger (beginner)</a>:</p>
<blockquote>
<p dir="auto">But when you have several tens of outputs to write in every function you test</p>
</blockquote>
<p dir="auto">Hmm, no idea why that’s a problem…</p>
<p dir="auto">I think if this is how you’re considering debugging Notepad++ changes you might make…it is going to wear you down fast and you’ll give up trying to make changes.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/88514</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/88514</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Thu, 10 Aug 2023 18:23:31 GMT</pubDate></item><item><title><![CDATA[Reply to Debugging Npp .exe without a debugger (beginner) on Thu, 10 Aug 2023 18:10:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> said in <a href="/post/88511">Debugging Npp .exe without a debugger (beginner)</a>:</p>
<blockquote>
<p dir="auto">It’s just a matter of (in very simple terms):<br />
char buf[1024];<br />
sprintf(buf, “test”);<br />
OutputDebugString(buf);</p>
</blockquote>
<p dir="auto">But when you have several tens of outputs to write in every function you test… :/</p>
<p dir="auto"><img src="/assets/uploads/files/1691691034656-d390b628-0f66-493e-8f3e-127d0b706c2d-image.png" alt="d390b628-0f66-493e-8f3e-127d0b706c2d-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/88513</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/88513</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Thu, 10 Aug 2023 18:10:36 GMT</pubDate></item><item><title><![CDATA[Reply to Debugging Npp .exe without a debugger (beginner) on Thu, 10 Aug 2023 16:27:19 GMT]]></title><description><![CDATA[<p dir="auto">@Victorel-Petrovich said in <a href="/post/88509">Debugging Npp .exe without a debugger (beginner)</a>:</p>
<blockquote>
<p dir="auto">So printf() is easier to use (at least for most practical cases, IMO), and already familiar.</p>
</blockquote>
<p dir="auto">Really, only because you already have the “console” approach in your rearview mirror.</p>
<p dir="auto">If someone didn’t have that, OutputDebugString is easier.</p>
<p dir="auto">It’s just a matter of (in very simple terms):</p>
<p dir="auto">char buf[1024];<br />
sprintf(buf, “test”);<br />
OutputDebugString(buf);</p>
]]></description><link>https://community.notepad-plus-plus.org/post/88511</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/88511</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Thu, 10 Aug 2023 16:27:19 GMT</pubDate></item><item><title><![CDATA[Reply to Debugging Npp .exe without a debugger (beginner) on Thu, 10 Aug 2023 15:45:31 GMT]]></title><description><![CDATA[<p dir="auto">I’ve just downloaded DebugView from sysinternals (easy to use), and read in several pages about <code>OutputDebugString()</code>.<br />
So, yes, it’s good if you don’t want to create a console in the app with <code>AllocConsole()</code> like above.<br />
But then you usually need to prepare the formatted string in advance using <code>sprintf()</code> or similar, then pass to OutputDebugString…  (Or write a special function to do it… again extra inserted code or files).<br />
So <code>printf()</code> is easier to use (at least for most practical cases, IMO), and already familiar.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/88509</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/88509</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Thu, 10 Aug 2023 15:45:31 GMT</pubDate></item><item><title><![CDATA[Reply to Debugging Npp .exe without a debugger (beginner) on Thu, 10 Aug 2023 14:42:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> you’re a wizard</p>
]]></description><link>https://community.notepad-plus-plus.org/post/88507</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/88507</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Thu, 10 Aug 2023 14:42:27 GMT</pubDate></item><item><title><![CDATA[Reply to Debugging Npp .exe without a debugger (beginner) on Thu, 10 Aug 2023 05:29:30 GMT]]></title><description><![CDATA[<p dir="auto">@Victorel-Petrovich said in <a href="/post/88496">Debugging Npp .exe without a debugger (beginner)</a>:</p>
<blockquote>
<p dir="auto">Everywhere I read (including 2 ref-s above , and at microsoft) they say OutputDebugString() is for when the app is run from / has a debugger .</p>
</blockquote>
<p dir="auto">… but it is not limited to be used only by debuggers. Applications like <a href="https://learn.microsoft.com/en-us/sysinternals/downloads/debugview" rel="nofollow ugc">debugview</a> from sysinternals tools can be used to get this output.</p>
<p dir="auto">or a pythons script like</p>
<pre><code class="language-py">import ctypes
from ctypes.wintypes import HANDLE, DWORD, BOOL, LPVOID, LPCWSTR, LPHANDLE
import mmap
import struct
import os
from Npp import console
console.show()

kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)

CreateEventW = kernel32.CreateEventW
CreateEventW.argtypes = [LPVOID, BOOL, BOOL, LPCWSTR]
CreateEventW.restype = HANDLE

SetEvent = kernel32.SetEvent
SetEvent.argtypes = [HANDLE]
SetEvent.restype = BOOL

WaitForSingleObject = kernel32.WaitForSingleObject
WaitForSingleObject.argtypes = [HANDLE, DWORD]
WaitForSingleObject.restype = DWORD

WaitForMultipleObjects = kernel32.WaitForMultipleObjects
WaitForMultipleObjects.argtypes = [DWORD, LPHANDLE, BOOL, DWORD]
WaitForMultipleObjects.restype = DWORD

CloseHandle = kernel32.CloseHandle
CloseHandle.argtypes = [HANDLE]
CloseHandle.restype = BOOL

BUFFER_READY = kernel32.CreateEventW(None, 0, 0, 'DBWIN_BUFFER_READY')
DATA_READY = kernel32.CreateEventW(None, 0, 0, 'DBWIN_DATA_READY')
STOP_DBG_LOOP = kernel32.CreateEventW(None, 0, 0, 'STOP_DBG_LOOP')

HANDLES = (HANDLE * 2)(DATA_READY, STOP_DBG_LOOP)
buffer = mmap.mmap(0, 4096, "DBWIN_BUFFER", mmap.ACCESS_WRITE)
CURRENT_NPP_ID = os.getpid()

# Call SetEvent(STOP_DBG_LOOP) to stop the loop,
# either with a second script or by calling from the PS console

while True:
    SetEvent(BUFFER_READY)
    result = WaitForMultipleObjects(2, HANDLES, False, 0xFFFFFFFF)
    if result == 1:  # STOP_DBG_LOOP received
        break
    elif result == 0:
        buffer.seek(0)
        process_id, = struct.unpack("L", buffer.read(4))
        data = buffer.read(4092)
        if CURRENT_NPP_ID != process_id:  # to prevent seeing PS's own debug strings.
            if b"\0" in data:
                data = data[:data.index(b"\0")]
            print("Process:[{0}] {1}".format(process_id, data.decode().strip()))
    else:
        print('ooppss: {}'.format(result))
        break

CloseHandle(BUFFER_READY)
CloseHandle(DATA_READY)
CloseHandle(STOP_DBG_LOOP)
print('done')
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/88499</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/88499</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Thu, 10 Aug 2023 05:29:30 GMT</pubDate></item><item><title><![CDATA[Reply to Debugging Npp .exe without a debugger (beginner) on Wed, 09 Aug 2023 22:44:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> Thank you for answering <em>to the point</em> .</p>
<p dir="auto">Everywhere I read (including 2 ref-s above , and at <a href="https://learn.microsoft.com/en-us/windows/win32/api/debugapi/nf-debugapi-outputdebugstringa?redirectedfrom=MSDN" rel="nofollow ugc">microsoft</a>) they say OutputDebugString() is for when the app is run from / has a debugger .</p>
<blockquote>
<p dir="auto">But, it’s similar, and apparently what you have going now works, so…</p>
</blockquote>
<p dir="auto">Indeed.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/88496</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/88496</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 09 Aug 2023 22:44:49 GMT</pubDate></item><item><title><![CDATA[Reply to Debugging Npp .exe without a debugger (beginner) on Wed, 09 Aug 2023 21:16:45 GMT]]></title><description><![CDATA[<p dir="auto">@Victorel-Petrovich</p>
<p dir="auto">OutputDebugString() is where I’d go with it, rather than going to the trouble of getting a console.  But, it’s similar, and apparently what you have going now works, so…</p>
]]></description><link>https://community.notepad-plus-plus.org/post/88494</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/88494</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Wed, 09 Aug 2023 21:16:45 GMT</pubDate></item><item><title><![CDATA[Reply to Debugging Npp .exe without a debugger (beginner) on Wed, 09 Aug 2023 20:56:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rdipardo" aria-label="Profile: rdipardo">@<bdi>rdipardo</bdi></a> I only build debug versions to test, so I don’t need to differentiate between release vs debugs.</p>
<p dir="auto">Instead, I was curious about was whether it was possible to make the <code>printf</code> results appear in the console cmd.exe from where I run the Npp .exe. I thought since this is <em>debug</em> version, maybe some compilation settings are possible to allow that. But that’s just a curiosity; above setup seems to work well.</p>
<blockquote>
<p dir="auto">The extra code you’re inserting into the N++ binary may end up introducing bugs instead of detecting the ones already there.</p>
</blockquote>
<p dir="auto">I think it’s obvious / common sense that one doesn’t leave any “extra” (unnecessary) code in a PR.</p>
<blockquote>
<p dir="auto">I seriously doubt how useful it’s going to be</p>
</blockquote>
<p dir="auto">Very useful; I already tested some of my assumptions.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/88492</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/88492</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 09 Aug 2023 20:56:42 GMT</pubDate></item><item><title><![CDATA[Reply to Debugging Npp .exe without a debugger (beginner) on Wed, 09 Aug 2023 19:59:27 GMT]]></title><description><![CDATA[<blockquote>
<p dir="auto">But maybe it’s possible better way, of specifying somewhere say in “appveyor.yml” that printing to a regular/parent console is allowed for a “debug” version…</p>
</blockquote>
<p dir="auto">You can achieve what you’re asking with <em>conditional compilation</em>.</p>
<p dir="auto"><em>TL;DR</em></p>
<pre><code class="language-cpp">#ifdef _DEBUG
  // . . . print to console . . .
#endif
</code></pre>
<p dir="auto">This guards a block of code at build time by checking for a <a href="https://en.cppreference.com/w/cpp/preprocessor" rel="nofollow ugc">preprocessor definition</a> that should only be set <a href="https://github.com/notepad-plus-plus/notepad-plus-plus/blob/f6e1b2cab6b42530869f600121443350f0292ad6/PowerEditor/visual.net/notepadPlus.Cpp.props#L67" rel="nofollow ugc">in the debug configuration</a>.</p>
<p dir="auto">Now, as much as I admire the inventiveness of your <em>ad hoc</em> approach, I seriously doubt how useful it’s going to be. The extra code you’re inserting into the N++ binary may end up <em>introducing</em> bugs instead of detecting the ones already there.</p>
<p dir="auto">If your adverse/unable to get Visual Studio up and running, the N++ source code is still compatible with <a href="https://www.winlibs.com" rel="nofollow ugc">the MinGW toolchain</a>, which comes with a Makefile processor and the <a href="https://www.gdbtutorial.com" rel="nofollow ugc">GNU Debugger utility</a>. (At the time of writing, <a href="https://github.com/notepad-plus-plus/notepad-plus-plus/blob/f6e1b2cab6b42530869f600121443350f0292ad6/SUPPORTED_SYSTEM.md?plain=1#L25" rel="nofollow ugc">Windows Vista</a> is the oldest OS that can run <code>notepad++.exe</code> images built with MinGW).</p>
<p dir="auto">Once you have the tools installed and can <a href="https://github.com/notepad-plus-plus/notepad-plus-plus/blob/master/BUILD.md#gcc" rel="nofollow ugc">build N++</a> all by yourself, attaching the debugger should be as easy as entering: <code>&gt; gdb r C:\&lt;path&gt;\&lt;to&gt;\notepad++.exe</code>. There’s <a href="https://www-users.cse.umn.edu/~kauffman/tutorials/gdb.html#org3e2e52c" rel="nofollow ugc">an extensive suite</a> of command line options for stepping through code, inspecting variables, etc.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/88491</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/88491</guid><dc:creator><![CDATA[rdipardo]]></dc:creator><pubDate>Wed, 09 Aug 2023 19:59:27 GMT</pubDate></item></channel></rss>