debugging cuda files in visual studio - visual-studio-2010

i have a cpp function (function.cpp") which i "mex"-ed. then i open the function.cpp file in visual studio and attach visual studio to a running matlab process.
when i call the function in matlab i am able to set breakpoints in the function.cpp file and step through it observing the variables.
The debugging process breaks down when i change the function to a cuda file (function.cu). Following the process described above i am still able to stop within function.cu but i cannot see any variables. when i try to "watch" a variable it says "Error symbol .. not found"
i have nsight installed in visual studio. question: how can i observe my variables in the file function.cu in the debug mode as i do for the function.cpp file. Is this possible ?
Note that the function.cu is not in a project. it is just a standalone file with cpp code of a function (say somefunction(){}). for debugging purpose i am opening it up in visual studio. i am compiling the function.cu file in matlab using "nvmex -g wrapper.cu" the wrapper.cu is a matlab mexfunction wrapper which makes calls to somefunction() written inside function.cu

You're using the VS debugger which is a host debugger, so it doesn't know how to debug device programs. To debug device code in Windows you should look at Parallel Nsight Visual Studio Edition.
You can search the docs for a guide to attaching to a running process, for the current release (2.2) the specific page is here.

You attached VS in, but stopped in function 'main'. Looks like you are still hitting the CPU code. When you follow Tom's suggestion to attach the debugger, have you choosed "NVIDIA GPU Debugger" in the Transport dropdown?

To debug any cuda-code you'll need a gpu on which no desktop environment/server is running. For windows that means, that you need a second gpu. I'm not to 100% sure if it has to be a nvida gpu, too. Than you will be able to bedubg your code.
Under linux you're able to debug with only one gpu because you can shut down the x-server and debug with cuda-gdb per command line.
Further informations will give you the cuda-gdb manual

Related

Debugging information for 'mpiexec' cannot be found or doesn't match

I am going to start parallel programming using MPI on visual studio c++ 2015. I made all configurations for MPI. I want to make the call from visual studio. So I followed the steps in this screenshot
and I got this error :
Debugging information for 'mpiexec' cannot be found or doesn't
match.Cannot find or open the PDB file
I trying to add MPI Cluster Debugger in Debugger to launch list,but there is no MPI Cluster Debugger in the list.
What i need to do?

Debugging Makefile project (mingw-gcc) on Visual Studio

I installed MinGW and created a makefile project on Visual Studio Community 2015 today and got it working for compilation.
Still two things are bugging me:
Interface
I can't tell Visual Studio to prevent closing the console window after running the program. Even Start Without Debugging closes the window and the project properties are not the same as a normal VS project, so I don't know how to configure this.
Debugging
Setting breakpoints is hopeless. Apparently the debugger won't understand debug info from files compiled with other compilers. I get Module was built without symbols..
I've tried setting up gdb according to this answer, but then starting the debugger lead me to this window:
which indicates that the executable has indeed debugging symbols (I'm compiling with -g)
I can feel I'm getting pretty close. What am I missing?
mingw-gcc generates DWARF format debugging information in its
executables. The Visual Studio debugger expects separate PDB
debugging files as produced by Microsoft's compilers. It can't
recognize DWARF.
You can debug MinGW executables either with
the gdb console, as you have almost started to do, or for
"visual" debugging you can do it in an IDE that supports gdb,
on Windows, such as CodeLite, Eclipse-CDT, CodeBlocks. If you
are wedded to Visual Studio you might try your luck with
Microsoft's open sourced Visual Studio MI Debug Engine ,
which according to its blurb "enables debugging with debuggers that support the gdb Machine Interface ("MI") specification such as GDB, LLDB, and CLRDBG".
I know nothing more about it

Nvidia visual studio Nsight CPU and GPU debugging

The NVIDIA Nsight Visual Studio Edition does not seem to be capable of debugging CPU (host code) and GPU (cuda code) at the same time. With the Nsight Eclipse Edition (or cuda-gdb) this is quite simple, for example, you can "step in" to a CUDA kernel from the host execution. How to do the same with Visual Studio?
From the Nsight manual
It says
Use a separate Visual Studio instance to debug the host portion of a
target application. If you wish to debug the host portion of your CUDA
application while the CUDA Debugger is attached, you must attach using
a different Visual Studio instance. Attaching the same instance of
Visual Studio to debug both the host portion and the device portion of
a target application will cause the debuggers to conflict. The result
is that the target application and the CUDA Debugger hang while being
blocked by operations of the native debugger.
So to debug a CUDA application here are the steps:
Open Visual Studio (VS instance #1) and set a breakpoint in a CUDA kernel and click "Start CUDA Debugging." This will start the application instance and stop where u set the breakpoint.
Open another instance of Visual Studio (VS instance #2) (needs to be run as admin for some reason) and attach to the process you started in step 1.
In VS instance #2 browse to the file you wish to do your CPU debugging and set a breakpoint.
In VS instance #1 continue the execution (should fall out of the current CUDA kernel). At this point the CPU breakpoint you set in VS instance #2 should be hit.
Extra credit: Debugging your CUDA application remotely.
Steps:
On the target machine run the msvsmon.exe (remote debugger) as admin. This can be found at
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Remote Debugger\x64.
On the host machine (the one from which you want to control the debugging), open VS and make sure the Nsight debugger is pointed to the remote machine (Nsight User Properties > Launch > Connection Name). NOTE: the Nvidia Nsight monitor must be running on the target machine for this to work.
Do steps 1 and 2 from the previous (non-remote debugging) section. In step 2 you will need to point to the remote machine for CPU debugging (Debug>Attach to Process>Qualifier should be set to the target machine name or IP).
The non-remote debugging steps 3 and 4 apply apply here as well.
NOTE: It looks as if VS's remote CPU debugging is not as capable as its local CPU debugging. For example, when you mouse-over CPU variables, there values to not appear as you would expect when you are doing local debugging.
STILL UNANSWERED: Is it possible to start debugging the host code before hitting a CUDA breakpoint? It seems like a big limitation that you can only debug host code following your first CUDA kernel. What if you wish to debug the host code before the first CUDA kernel?

Debugging with 'Attach to Process' magic with Visual Studio 2010/Xcode/gdb

I see that with the 'Attach to Process', one can debug the process by setting up break point in Visual Studio IDE.
I think it's pretty cool, and I'm curious what's the mechanism that enables it. I also found that gdb and Mac's Xcode supports the technology.
Q1 : Can anyone explain how does this work? How can the process mapped to a breakpoint in an IDE or gdb environment?
Q2 : Are there other compiler/debugger options than /Zi or -g (adding debug info)?
Q3 : Is this the way to debug dll (dynamic library)?
ADDED
I found this one with MSDN - http://msdn.microsoft.com/en-us/library/c6wf8e4z.aspx
The most common scenario I know of is using a browser to debug web code. In these cases, you start Visual Studio in debug mode and then attach to the browser and call the page in question. When the page is called it starts running the code in the debugger. Essentially, the debugger watches the process and when it hits code in VS, it starts debugging.
The same is true with other applications that are calling code you are running in Visual Studio. When you cross the boundary to the code, the debugger catches the call and starts running code in VS.
I use it fairly frequently when developing plugins for existing applications (Maya, Reaper, etc). As a general rule, plugins can't be run independently, so in order to debug them I have to run the host program and use "Attach to Process" to run the debugger on my plugin, at which point I can set breakpoints and all that other debugging goodness. You need to have debugging symbols and al that for the plugin, but you don't need to have them for the host application.

How to debug a process using Visual Studio?

If an application† crashes,
I hit "Debug" and Visual Studio is my currently registered Just-In-Time (JIT) debugger:
Visual Studio appears, but there's no way to debug anything:
I do not see any disassembly
I do not see any registers (assuming it runs on a CPU with registers)
The call stack is empty (assuming the CPU has a stack pointer)
I do not see any symbols (assuming it had any)
I do not see reconstructed source code from reflection (assuming it was managed)
Other JIT debugger products are able to show disassembly, but they are either command-line based (Debugging Tools for Windows), or do not support symbols (OllyDbg, Delphi). Additionally, my question is about debugging using Visual Studio, since I already have it installed, and it is already my registered JIT.
How do you debug a program using Visual Studio?
Alternatively: has anyone written a graphical debugger that supports the Microsoft symbol server?
† Not, necessarily, written in Visual Studio.
Edit: Changes title to process rather than application, since the latter somehow implies "my application."
Edit: Assume the original application was written in assembly language by Steve Gibson. That is, there is no source code or debug information. Visual Studio should still be able to show me an assembly dump.
Looking at the screenshot it appears that Visual Studio is currently debugging in Run mode - you need to break execution of the process before it makes sense to look at things like the call stack, etc...
To break execution of the process you either need to hit a breakpoint, or you can break execution of the process at any time by using the Pause / Break all toolbar item (Control + Alt + Break).
Then you should be able to access the following windows under the Debug -> Windows menu:
The disassembly window
The registers window
The call stack window
The modules window shows a list of loaded modules along with where their corresponding symbols are loaded from (if loaded)
Some other useful windows:
The processes window is useful if you are debugging more than one process at a time
The Threads window
The Memory window (there are four of them)
The Locals window
Some of these might not be visible by default depending on which window configuration you selected when you first started Visual Studio - if you can't find them then right click on the toolbar and goto customise to add them.
Visual studio doesn't reconstruct soucre code from disassembly - you really need to have the original source code available to you, otherwise the symbols almost certainly won't match the source code you are debugging.
If you are debugging unmanaged modules without source code then I recommend you at least try WinDbg - its user interface is a bit clunky at times, and it does have a steep learning curve, however it is a very powerful debugger supporting many features that Visual Studio doesn't - it may be more suited to the sort of debugging you need to do.
(Visual Studio is a fantastic debugger, however it's primarily used to debug modules where the source code is available and so it lacks certain features in favour of a better user experience).
Assuming this is your application that you wrote in VS, just press F5 to run the program and either use a breakpoint, or manually break the program to start debugging.
The problem in the last screenshot is that Visual Studio did not enter break mode automatically. That seems like a bug. If you hit the 'pause' button on the toolbar, it would enter break mode, giving you disassembly, and a callstack.
According to that last screenshot you were actually attached to the program ... the output windows shows it loaded stripped symbols for OLE and the crt.
You can debug a program with Visual Studio if you have the debug information available for this program. It's the difference between compiling a Release version (normally without debug information) and compiling a Debug version.
This dialog to debug a program is handy if you are testing the debug version of your self-written program. You can attach it "on-the-fly" to your Visual Studio debugger and look for the problem.
If it is not your program or it is your program, but does not provide debugging information which Visual Studio can understand, then you are out of luck.
Use menu Debug -> Windows -> Disassembly (I think the keyboard shortcut is Alt + 8, but I am configured for VC 6.0 bindings, because that's how I roll, and it may have changed).
You can get public symbols for the operating system from http://msdl.microsoft.com/download/symbols. Add it to the list in menu Tools -> Options -> Debugging -> Symbols -> Symbol file locations.
Also, make sure you are running in the same integrity level as the application. Or always run Visual Studio as Administrator.
I guess you are already in the Debug mode. The "Run" button is disabled. Just go to Debug -> windows -> Disassembly to view disassembly.

Resources