We are having issues with debugging inline assembly code in Visual Studio 2022 Community. It worked fine in previous versions, such as 2017, 2019. Even though the optimizations are disabled, debuggable assembly is set to Yes, support just my code debugging is set to No, Debug Information format is set to Program Database /Zi, Basic Runtime Checks are set to Default...
...the debugger incorrectly shows the current line, when stepping over an inline assembly code. It can be clearly seen when Debug Window Disassembly is shown - instructions are not detected properly to align to the source code. Thus when debugging without disassembly, debugger shows incorrect lines, and - breakpoints do not work as they are not detected at proper instructions.
I was wondering if anyone has a hint for any other options that we could try to switch to get this working. We've been fighting this a few months, and Microsoft Support requires you to pay 149 Eur just to file a bug.
adding debug windows modules and output:
Related
I want to debug a C++ MFC/CLI program developped on Visual Studio 2019.
Until now, I can debug C++ native (MFC) code.
DebugType in Debug panel is set to Auto.
All breakpoints in C++/CLI modules are flagged as inactive (a red circle with an interrogation character in a yellow triangle).
After having changed DebugType from Auto to 'Mixed (.Net Framework), Visual Studio, when starting a debug session, is displaying following warning box.
But my build is in DEBUG mode !
What is happening ?
What must I do to debug pure C++ AND CLI C++ code ?
PS: I have also tried to debug in only C++/CLI code, but Visual Studio 2019 is displaying same message !
On Visual Studio 2019, how to debug pure C++ and CLI C++ in a C++
Debug program?
Since I do not have your project and cannot troubleshoot the issue quickly unless you provide a sample.
You can try the following suggestions:
Suggestions
1) try to reset all settings by Tools-->Import and Export Settings-->Reset All Settings
2) disable any third party extensions under Extensions-->Manage Extensions in case one of them causes the behavior.
3) check Use Managed Compatibility Mode option, Enable .NET Framework source stepping option and Suppress JIT optimization on module load (Managed only) option under Tools-->Options-->Debugging-->General.
4) close VS, delete .vs hidden folder, Debug folder from the solution folder and also Debug folder in the project folder. Then restart your project to test again.
I'm putting this here because it might help someone in the future, and because it's completely nuts.
I've followed all instructions I could find, including the ones on this question, reinstalled VS twice, with different versions, and nothing.
What solved for me was to simply delete the lines of code and write them again.
Yes.
I know.
After updating from Visual Studio 2013 to Visual Studio 2017, if I try to start a debug session of my C++/CLI project (.vcxproj project file) Visual Studio stops and displays a dialog which says:
You are debugging a Release build of Foo.exe. Using Just My Code with Release builds using compiler optimizations results in a degraded debugging experience (e.g. breakpoints will not be hit).
I can then either stop debugging or continue with the debug session, either with "Just My Code" turned on or off.
The project is clearly built with Debug information and without any optimization whatsoever. Consequently, the old Visual Studio 2013 did not show any warning.
Both this SO question and this SO question deal with the same warning emitted by Visual Studio 2015, but after reading through the suggestions and hints offered there I have to say that none of them seems a convincing solution to my problem. Specifically, I was able to get rid of the warning by enabling the Visual Studio option "Suppress JIT optimization on module load (Managed only)", but I think this is only treating a symptom, not fixing the actual cause of the problem.
What do I have to do to make Visual Studio 2017 detect that my C++/CLI project is a debug build so that it no longer displays the annoying (and actually misleading) warning?
Environment:
Visual Studio 2017 Version 15.5.2
Visual Studio option "Just My Code" is enabled
Visual Studio option "Suppress JIT optimization on module load (Managed only)" is disabled
Project is a native project (.vcxproj project file) built with CLR support (compiler option /CLR), debug information (linker option /DEBUG), and no optimizations (compiler option /Od)
The solution to my problem is that the project needs to be built with the project setting "Debuggable Assembly" set to "Yes" (linker option /ASSEMBLYDEBUG). By default this linker option is unset and apparently defaults to /ASSEMBLYDEBUG:DISABLE. Cf. Microsoft's documentation of the linker option.
Setting /ASSEMBLYDEBUG is the same as writing
[assembly:Debuggable(true, true)];
in code. According to the MSDN documentation of this DebuggableAttribute constructor, this code tells the debugger to set
isJITTrackingEnabled = true
isJITOptimizerDisabled = true
So the initial workaround I mentioned in the question, where I enabled the Visual Studio option "Suppress JIT optimization on module load (Managed only)", wasn't too far off the track. But I believe that knowing what I'm doing and setting a fine-grained, project-specific linker setting is preferrable to having no clue and randomly making a change to a global Visual Studio setting.
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
I attach VS 2010 to service process; after that I put breakpoint in several methods but they never seem to be hit. Any idea or tips?
Note: The services process installed is a release build. Do I have to have a debug build installed for this?
You need to have a debug build for this.
In release mode, the debug info is discarded and code is optimized, so there is no way to link to original source code.
In debug mode, debugging and project state information is retained so the debugger canlink to the source code. It also emits DebuggableAttribute that tells JIT compiler that the assembly has debug info.
Helpful link: http://msdn.microsoft.com/en-us/library/ms241903.aspx
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.