Debug messages (logs) generated by kDebug() and kWarning() are not visible on MS Windows unless application is compiled in so-called CONSOLE subsystem. To show these messages also in WINDOWS subsystem, you can use DebugView tool, coming from SysInternals (currently acquired by Microsoft). The tool offers searching in logs, filtering and saving them to file.

+

WinDbg, distributed as a part of ''Debugging Tools for Windows'', is a user-mode and kernel-mode debugger with a graphical interface. It can also be used to debug user-mode crash dumps. It uses the Microsoft Visual Studio debug symbol formats for source-level debugging. [[Projects/KDE_on_Windows/Tools#WinDbg|more...]]

Debug messages (logs) generated by kDebug() and kWarning() are not visible on MS Windows unless application is compiled in so-called CONSOLE subsystem. To show these messages also in WINDOWS subsystem, you can use DebugView tool, coming from SysInternals (currently acquired by Microsoft). [[Projects/KDE_on_Windows/Tools#DebugView|more...]]

+

+

===Getting a backtrace with DrKonqi===

+

[[Projects/KDE_on_Windows/Getting_a_Backtrace_with_DrKonqi|more...]]

+

+

===Debugging kioslaves===

kioslaves on windows are started by klauncher (or kio) as separate kioslave processes. The kioslave executable then loads the related kioslave dll dynamically.

kioslaves on windows are started by klauncher (or kio) as separate kioslave processes. The kioslave executable then loads the related kioslave dll dynamically.

+

==== Using KDE_SLAVE_DEBUG_WAIT variable ====

To debug kioslaves:

To debug kioslaves:

−

#Set the KDE_SLAVE_DEBUG_WAIT environment variable in a current cmd.exe shell to the name of the kioslave's protocol (the first parameter of KIO::SlaveBase() constructor), e.g.<pre>set KDE_SLAVE_DEBUG_WAIT=file</pre>

+

#Set the KDE_SLAVE_DEBUG_WAIT environment variable in a current cmd.exe shell to the name of the kioslave's protocol (the first parameter of KIO::SlaveBase() constructor), e.g. <tt>set KDE_SLAVE_DEBUG_WAIT=file</tt>

#Terminate <tt>klauncher</tt> process so it can be restarted.

#Terminate <tt>klauncher</tt> process so it can be restarted.

−

#Any application you want to debug at kioslave level have to be executed within the scope of the current environment (cmd.exe), what also means that if you want to use development environment, you have to do taht in the environment as well, e.g. for MSVC Express, by typing <tt>vcepress</tt>.

+

#Any application you want to debug at kioslave level have to be executed within the scope of the current environment (cmd.exe), what also means that if you want to use development environment, you have to do that in the environment as well, e.g. for MSVC Express, by typing <tt>vcexpress</tt>.

−

{{Note|For example, set the variable to 'file' for the kio_file slave, '''but''' set it to 'smtps' for the kio_smtp is you want to debug smtp protocol secured with SSL.}}

+

If the kioslave is requested the next time, a debugger will be started and attached to the kioslave process immediatly before the kioslave's kdemain() function.

−

{{Note|'''Vista only:''' ''kioslave.exe has stopped working'' message dialog can appear istead of offer for starting the debugger. Do not close the dialog but instead attach in with your debugger to the process, then close the window with upper-right [x] button.}}

+

On mingw platform gdb is launched and connected to the kioslave process. On msvc platforms the currently installed just-in-time debugger is used. This may be msvc's IDE or the [[Projects/KDE_on_Windows/Tools#WinDbg|WinDbg debugger]]. The latter could be set as jit-debugger by running 'windbg -I' command (capital -I like ICE, see [http://msdn2.microsoft.com/en-us/library/cc266343.aspx]).

−

If the kioslave is requested the next time, a debugger will be started and attached to the kioslave process immediatly before the kioslave's kdemain() function.

+

==== Using KDE_SLAVE_DEBUG_POPUP variable ====

+

Alternatively, you can set <tt>KDE_SLAVE_DEBUG_POPUP</tt> variable instead of <tt>KDE_SLAVE_DEBUG_WAIT</tt>. This will display a native message box so developer you can attach the debugger to the KIO slave process and click OK. No DebugBreak() is invoked. Just click OK without attaching to continue using the KIO slave without debugging.

−

On mingw platform gdb is launched and connected to the kioslave process. On msvc platforms the currently installed just-in-time debugger is used. This may be msvc's IDE or the [http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx windbg debugger]. The latter could be set as jit-debugger by running 'windbg -I' command.

+

==== Notes ====

+

*You can set, say, the variable to 'file' for the kio_file slave, '''but''' set it to 'smtps' for the kio_smtp is you want to debug smtp protocol secured with SSL.

**Use <tt>KDE_SLAVE_DEBUG_POPUP</tt> instead of <tt>KDE_SLAVE_DEBUG_WAIT</tt>. See the [[#Using_KDE_SLAVE_DEBUG_POPUP_variable|Using KDE_SLAVE_DEBUG_POPUP variable]] above for more info.

+

**(not possible under msvc 2005): start applications and klauncher without administration permissions or attach the debugger manually before the debugger catches unhandled exceptions or an user-defined breakpoint (DebugBreak()).

+

*You may want to inspect kioslave sources [http://lxr.kde.org/source/KDE/kdelibs/kinit/kioslave.cpp] for more informations.

−

You may inspect kioslave sources [http://lxr.kde.org/source/KDE/kdelibs/kinit/kioslave.cpp] for more informations.

+

=== Checking dependency of shared libraries ===

+

Dependency Walker is a free utility that scans any 32-bit or 64-bit Windows module (exe, dll, ocx, sys, etc.) and builds a hierarchical tree diagram of all dependent modules. [[Projects/KDE_on_Windows/Tools#Dependency_Walker|more...]]

−

= MS Visual Studio hints =

+

== MS Visual Studio hints ==

−

== Using MS Visual Studio environment for just debugging ==

+

=== Using MS Visual Studio environment for just debugging ===

Let's assume you're using command line tools (typically CMake) and want to use MS Visual Studio environment for just debugging. You don't need to create msvc project for your KDE application to be able to start debugging.

Let's assume you're using command line tools (typically CMake) and want to use MS Visual Studio environment for just debugging. You don't need to create msvc project for your KDE application to be able to start debugging.

Line 30:

Line 43:

* compile and working executable version of your appliation (compiled in debug mode)

* compile and working executable version of your appliation (compiled in debug mode)

* run msvc environment

* run msvc environment

−

* execute ''File->Open project''

+

* execute ''File->Open Project/Solution''

* pick your exe file in the file window

* pick your exe file in the file window

* you can set command line arguments as usual, by pick ''Project->...Properties'' command and enter all of them it in ''Command Arguments'' field

* you can set command line arguments as usual, by pick ''Project->...Properties'' command and enter all of them it in ''Command Arguments'' field

Line 40:

Line 53:

* after compilation you can start debugging again

* after compilation you can start debugging again

* on exit you will be asked to save .sln file (so-called ''solution file'') with your debugging session -- do it and you will be able just to click the .sln file to start your debugging again

* on exit you will be asked to save .sln file (so-called ''solution file'') with your debugging session -- do it and you will be able just to click the .sln file to start your debugging again

−

* it's recommended to save the .sln file in the .exe file directory

+

* it's recommended to save the .sln file in the same directory where the .exe file sits

−

* next time you will run msvc environment, you can see name of your application's .sln file in ''File->Recent Projects'' submenu - you can click it to load your debugging session

+

*hints on reopening the debugging session:

+

**Next time you will run msvc environment, you can see name of your application's .sln file in ''File->Recent Projects'' submenu - you can click it to load your debugging session.

+

**On command line you can type "cd path-to-your-sln-file; <yourfilename>.sln".

+

**You can also use "vcexpress /debugexe <myapplication> <args>".

−

== Attaching to running application ==

+

=== Attaching to running application ===

If you have your application is already running, you can attach to it and then start debugging.

If you have your application is already running, you can attach to it and then start debugging.

−

* run msvc environment

+

* run the msvc development environment

−

* execute ''Debug->processes''

+

* execute ''Debug->Atach to Process''

* select your from the processes list and click "Attach..."

* select your from the processes list and click "Attach..."

* msvc environment will load your .sln file if it exists in the same directory as the .exe file, so your breakpoints set in previous session will be active again

* msvc environment will load your .sln file if it exists in the same directory as the .exe file, so your breakpoints set in previous session will be active again

* your program will stop on any breakpoint you have set

* your program will stop on any breakpoint you have set

−

== One-step attaching to running application ==

+

=== One-step attaching to running application ===

−

You can create a macro that automates the task. See [http://blogs.msdn.com/jimgries/archive/2005/11/30/498264.aspx].

+

*You can create a macro that automates the task. See [http://blogs.msdn.com/jimgries/archive/2005/11/30/498264.aspx].

+

*MSVC 2008 or later can always attach to the running process when you execute "Start Debugging" command (F5). Just set the "Attach" option to "Yes" in the "Project->[yourapp] Properties" window. <br/>Note that in this case if the process is not present, you will experience "Unable to attach error" message, so you need to start the process intependently of the development environment first. The advantage of this is faster startup of your application.

−

== Memory Values ==

+

=== Memory Values ===

If you are using the debug heap, memory is initialized and cleared with special values. Most interesting values are:

If you are using the debug heap, memory is initialized and cleared with special values. Most interesting values are:

From the msvc docs: "While debugging, Data Tips and items in the Watch and Variable windows are automatically expanded to show their most important elements. The expansion follows the format given by the rules in this file. You can add rules for your types or change the predefined rules." ([http://www.thedatafarm.com/blog/content/binary/datatips2.jpg example screen])

From the msvc docs: "While debugging, Data Tips and items in the Watch and Variable windows are automatically expanded to show their most important elements. The expansion follows the format given by the rules in this file. You can add rules for your types or change the predefined rules." ([http://www.thedatafarm.com/blog/content/binary/datatips2.jpg example screen])

* autoexp.dat file has been replaced with a new xml file called default.natvis. To force VS to use the old system, go to "Tools->Options->Debugging->Edit and Continue" and turn on "Enable native Edit and Continue".

+

+

===WINDOWS and CONSOLE subsystems===

+

CONSOLE subsystem is the one that displays console window (used for standard output and error streams) in addition to application's windows. WINDOWS subsystem redirects standard output and error streams to system debugging subsystem that can be displayed if needed in [[Projects/KDE_on_Windows/Tools#DebugView|DebugView]] or debuggers like msvc or [[Projects/KDE_on_Windows/Tools#WinDbg|WinDbg]].

Note: Qt's qmake syntax supports ''console'' and ''windows'' parameters of the ''CONFIG'' variable, so CONSOLE subsystem can be enabled by specifying <tt>CONFIG += console</tt> in the .pro file, windows subsystem can be enabled with <tt>CONFIG += windows</tt>.

+

+

===Deployment===

+

Running a VC++2005 SP1 app on another computer: manifest files are needed. See [http://www.codeproject.com/KB/cpp/vcredists_x86.aspx] and [http://blogs.msdn.com/nikolad/archive/2005/09/02/460368.aspx].

+

+

====Note on debug builds====

+

The hints above are for release builds (or ReleaseWithDebugInfo). Moving Debug versions of binaries to other computers is only allowed (and technicallu possible) if you have Express Edition installed there, as there is no redistributable package for Debug versions provided and even the license disallows distribution of any debug binaries (even your own).

+

+

== MinGW debugging hints ==

+

+

There are gdb binaries you can directly run after unpacking them, e.g. from

the command prompt use the run command with the arguments for your application, e.g. <tt>run --nofork</tt>. Now wait until your applications starts and go on reproducing the crash. Once you encounter the crash, gdb will be in control

+

in the command line again. <tt>bt</tt> will get you the backtrace.

−

= MinGW hints =

+

Instead of running gdb from the beginning, you can also attach to a running process. Use the regular "task-manager" to see which process. Enable the process id columns so you can see the number. Now you can start gdb (still give it the path to the application executable if you can) and use the <tt>attach</tt> command with the process id you want to attach to from the

+

gdb prompt. Gdb will stop the process it attached to, so you can say <t>continue</tt> and then try to produce the crash.

* Dr. Mingw - Just in Time Debugger [http://jrfonseca.planetaclix.pt/projects/gnu-win32/software/drmingw/]

* Dr. Mingw - Just in Time Debugger [http://jrfonseca.planetaclix.pt/projects/gnu-win32/software/drmingw/]

'''''WARNING''''': If you are having crashes when starting applications via GDB beware of certain applications (mostly anti-virus software) that could cause problems like "Embassy Trust Suite", for example. See this [http://www.cygwin.com/ml/cygwin/2007-06/msg00405.html post].

WinDbg, distributed as a part of Debugging Tools for Windows, is a user-mode and kernel-mode debugger with a graphical interface. It can also be used to debug user-mode crash dumps. It uses the Microsoft Visual Studio debug symbol formats for source-level debugging. more...

Debug messages (logs) generated by kDebug() and kWarning() are not visible on MS Windows unless application is compiled in so-called CONSOLE subsystem. To show these messages also in WINDOWS subsystem, you can use DebugView tool, coming from SysInternals (currently acquired by Microsoft). more...

Set the KDE_SLAVE_DEBUG_WAIT environment variable in a current cmd.exe shell to the name of the kioslave's protocol (the first parameter of KIO::SlaveBase() constructor), e.g. set KDE_SLAVE_DEBUG_WAIT=file

Terminate klauncher process so it can be restarted.

Any application you want to debug at kioslave level have to be executed within the scope of the current environment (cmd.exe), what also means that if you want to use development environment, you have to do that in the environment as well, e.g. for MSVC Express, by typing vcexpress.

If the kioslave is requested the next time, a debugger will be started and attached to the kioslave process immediatly before the kioslave's kdemain() function.

On mingw platform gdb is launched and connected to the kioslave process. On msvc platforms the currently installed just-in-time debugger is used. This may be msvc's IDE or the WinDbg debugger. The latter could be set as jit-debugger by running 'windbg -I' command (capital -I like ICE, see [1]).

Alternatively, you can set KDE_SLAVE_DEBUG_POPUP variable instead of KDE_SLAVE_DEBUG_WAIT. This will display a native message box so developer you can attach the debugger to the KIO slave process and click OK. No DebugBreak() is invoked. Just click OK without attaching to continue using the KIO slave without debugging.

(not possible under msvc 2005): start applications and klauncher without administration permissions or attach the debugger manually before the debugger catches unhandled exceptions or an user-defined breakpoint (DebugBreak()).

Let's assume you're using command line tools (typically CMake) and want to use MS Visual Studio environment for just debugging. You don't need to create msvc project for your KDE application to be able to start debugging.

compile and working executable version of your appliation (compiled in debug mode)

run msvc environment

execute File->Open Project/Solution

pick your exe file in the file window

you can set command line arguments as usual, by pick Project->...Properties command and enter all of them it in Command Arguments field

if you have libraries placed in other directories than your application's .exe file, and you want to step into these libraries' source code while debugging, pick Project->...Properties command and enter paths to these directories in Symbol Path field

hit F5 to run the application start the application or F10 to start step by step

all debugging functions like setting breakpoints will be available, so you can open source code in the integrated editor and press F9 where needed

you can even edit your source code but to compile it, do it with your external, command line tools. You cannot compile the application in the msvc environment because you have not defined a project file

before compiling your application, stop debugging session to unlock binaries; no need to close msvc window

after compilation you can start debugging again

on exit you will be asked to save .sln file (so-called solution file) with your debugging session -- do it and you will be able just to click the .sln file to start your debugging again

it's recommended to save the .sln file in the same directory where the .exe file sits

hints on reopening the debugging session:

Next time you will run msvc environment, you can see name of your application's .sln file in File->Recent Projects submenu - you can click it to load your debugging session.

On command line you can type "cd path-to-your-sln-file; <yourfilename>.sln".

MSVC 2008 or later can always attach to the running process when you execute "Start Debugging" command (F5). Just set the "Attach" option to "Yes" in the "Project->[yourapp] Properties" window. Note that in this case if the process is not present, you will experience "Unable to attach error" message, so you need to start the process intependently of the development environment first. The advantage of this is faster startup of your application.

From the msvc docs: "While debugging, Data Tips and items in the Watch and Variable windows are automatically expanded to show their most important elements. The expansion follows the format given by the rules in this file. You can add rules for your types or change the predefined rules." (example screen)

MSVC 2005: To add support for expanding Qt data structures like QString of QRect, edit {msvc_installation_directory}\Common7\Packages\Debugger\autoexp.dat file and paste definitions after [AutoExpand] and [Visualizer] lines.

autoexp.dat file has been replaced with a new xml file called default.natvis. To force VS to use the old system, go to "Tools->Options->Debugging->Edit and Continue" and turn on "Enable native Edit and Continue".

CONSOLE subsystem is the one that displays console window (used for standard output and error streams) in addition to application's windows. WINDOWS subsystem redirects standard output and error streams to system debugging subsystem that can be displayed if needed in DebugView or debuggers like msvc or WinDbg.
Hint: To remove CONSOLE subsystem from already built .exe file, type editbin /subsystem:windows file.exe
Note: Qt's qmake syntax supports console and windows parameters of the CONFIG variable, so CONSOLE subsystem can be enabled by specifying CONFIG += console in the .pro file, windows subsystem can be enabled with CONFIG += windows.

The hints above are for release builds (or ReleaseWithDebugInfo). Moving Debug versions of binaries to other computers is only allowed (and technicallu possible) if you have Express Edition installed there, as there is no redistributable package for Debug versions provided and even the license disallows distribution of any debug binaries (even your own).

To get a backtrace for a crash you can reproduce: Start the gdb binary with the full path to the executable on the command line, for example like
..\gdb\gdb.exe c:\programme\kontact\bin\kontact.exe. When getting
the command prompt use the run command with the arguments for your application, e.g. run --nofork. Now wait until your applications starts and go on reproducing the crash. Once you encounter the crash, gdb will be in control
in the command line again. bt will get you the backtrace.

Instead of running gdb from the beginning, you can also attach to a running process. Use the regular "task-manager" to see which process. Enable the process id columns so you can see the number. Now you can start gdb (still give it the path to the application executable if you can) and use the attach command with the process id you want to attach to from the
gdb prompt. Gdb will stop the process it attached to, so you can say <t>continue</tt> and then try to produce the crash.

WARNING: If you are having crashes when starting applications via GDB beware of certain applications (mostly anti-virus software) that could cause problems like "Embassy Trust Suite", for example. See this post.