Visual Studio Debugger C++ - breakpoints not recognized - c++

Beginner programmer using Visual Studio release January 2021 on Windows 10. I have yet to get breakpoints to work. When placing a breakpoint in the helloworld.cpp program below and running the debugger, I get the following message and no breakpoint is set.
Breakpoint warning: Unexpected symbol reader error while processing helloworld.exe. - c:\RetireRecipe\Simulator\helloworld.cpp:5
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
}

In my opinion, I suggest that you could try the following methods.
Select Debbug->(APP) Properties, and make suer they are consistent and Debug. Breakpoint operation can only be in Debug mode.
Clean the project, rebuild the project and check if this folder Project Name\Debug has .pdb by Right click your project ->Open Floder in File Explorer.
Go to Debug -> Options and Settings. On the Debugging/General page, clear the Require source files that exactly match the original version option.
Debug -> (app) Properties-> Configuration Properties -> Debugging -> change from Auto to Mixed.
Configuration Properties -> Linker -> Debugging -> Generate Debug Info -> Generate Debug Information optimized for sharing and publishing
If it still work, I suggest that you could reinstall VS.

After several hours of reading various VS Code install videos, I ended up reinstalling twice. The overall solution for me was the reinstall and using the g++ compiler and gdb debugger. I can now set breakpoints, etc.

Related

Reasons why my C++ Program runs extremely slow/stalls using Visual Studio debugging (F5) and fast/no stalls not using it (Ctrl+F5) in the same config

It's basically a Hello, World application with all vanilla settings with the addition of one external library and an init to it. The program takes about 21 seconds to run within Visual Studio using the debugger (F5 or Start Debugging), but runs instantly otherwise. Happens in Release and Debug.
The library is for the Julia programming language. I include it's lib and header directory and simply call jl_init(). Half the stall happens before the line is even hit.
From the command line (cmd to the project dir and type x64\myprogram.exe) or Ctrl+F5 it runs instantly.
From Visual Studio using F5 or hitting "Start Debugging" take about 10 seconds to even reach the jl_init() line which is the very first line of the program. Then another 10 seconds to get through it.
int main(int argc, char** argv)
{
jl_init(); // takes almost 10 seconds to reach this line, before it even runs.
printf("Hello, World!\n"); // takes another 10 seconds to reach this line.
return 0;
}
I'm on VS 2019 v142. Windows 10. The project is on a local SSD. I'm not sure how to tackle this problem. Any ideas?
Edit:
It could be related to loading symbols, but these files are mostly build without symbols though:
'Julia.exe' (Win32): Loaded 'D:\Program Files\Julia-1.6.2\bin\libjulia.dll'. Module was built without symbols.
I'll add that I went into Tools>Options>Debugging>Symbols and selected "Load all modules, unless excluded", then added these dlls into the list of excluded modules. I also unchecked all symbol file location checking in the same dialog. I don't see any indication in the output or the modules debug window that my changes took effect. I also tried disabling ALL symbol loading in Tools>Options>Debugging>Symbols by selecting "Load only specified modules" and specifying no modules. Making these changes didn't help.
I think it's definitely related to dll loading but don't know how.
Edit 2: disabling Tools > Options > Debugging > General “Load debug symbols in external process” made the stall go from 21 seconds to about 12, which indicates it's symbol related.
One of possible issues here is PDB loading.
PDB's are needed to debug libraries, and help debugger resolve callstacks when there are functions from that library in it. In many cases you can debug your app just as well without most of them loaded.
You can disable automatic loading, or set whitelist of modules for which you want to load PDB's following Microsoft documentation: https://learn.microsoft.com/en-us/visualstudio/debugger/specify-symbol-dot-pdb-and-source-files-in-the-visual-studio-debugger?view=vs-2019#symbol-file-locations-and-loading-behavior

Visual Studio error D8016: '/ZI' and '/O2' command-line options are incompatible

Visual Studio error D8016: '/ZI' and '/O2' command-line options are incompatible
I'm using optimization for the first time with C++.
When I 'build solution' I keep getting this error.
In the property pages, I have configuration set to Release
Under project/properties/c++/optimization I tried all the options except for disable.
Under project/properties/c++/General I also tried all the options under 'Debug Information Format' (assume 'None' is a good choice?).
I think it might have something to do with the linker settings, but still don't know what to do.
Go to the project's property page and change the value for:
C/C++ | General | Debug Information Format
To something other than "Program Database for Edit and Continue (/ZI)"
For example, "Program Database (/Zi)" should work.
After changing
C/C++ | General | Debug Information Format
to Program Database (/Zi)
You might need to set the solution configurations to Release.
Verify that under Linker -> Debugging says Generate Debug Info -> No.
I had this problem as well.

Codeblocks doesn't stop at breakpoints

I am trying to debug C++ project in Codeblocks, but it's not stopping at breakpoints. I read the other answers and have tried the following things so far:
(Build Options > Compiler Settings) Produce debugging symbols is checked, strip all symbols is unchecked.
No spaces/non-ascii values in my file path.
Running the debug version.
Debugger in (Settings > Compiler > Toolchain Executables) set to GDB/CDB Debugger:Default
Executable path in (Settings > Debugger > GDB/CDB Debugger:Default) is C:\MinGW\bin\gdb.exe.
Its still not stopping at breakpoints and the debugger log is mentioning that no debugging symbols found
What am I missing here ?
While trying to fix this,I came across a lot of similar questions where CodeBlocks is ignoring breakpoints during debugging, so here's the fixes I have came across so far.
1.Clean and rebuild.
2.Ensure that (Build Options > Compiler Settings) Produce debugging symbols is checked, strip all symbols is unchecked. Please ensure this is done in global settings AND project settings.This fixed it for me.
3.Check so that there are no spaces/non-ASCII values in the project file path.
4.Check if you are running the debug version, not release.The executable from Release build will be \bin\Release , and the executable from a Debug build will be in \bin\Debug .
5. Check that Debugger in (Settings > Compiler > Toolchain Executables) is set to GDB/CDB Debugger:Default.
6.Check that executable path in (Settings > Debugger > GDB/CDB Debugger:Default) is valid gdb path like (C:\MinGW\bin\gdb.exe).
7.Update Codeblocks(last resort).
Please add in comments anything else that worked for you.
I had this problem too, however, it was because a long time ago I'd set
Settings > Debugger > GDB / CDB Debugger > Default > Debugger initialization commands
to
"set follow-fork-mode child"
so GDB was actually debugging another program entirely.
The only thing which worked for me:
Path with spaces
Breakpoints could not work if the path/folder you've placed your project contains spaces or other special characters. To be safe use English letters, digits and '_'.
Source: Debugging with Code::Blocks
Also you can check menu: Build->Select target->Debug
For me the thing which worked was, to delete the file main.o, which is contained in obj/Debug.
Hope it helps someone.

OCCI app crashes when running in debug mode in Visual Studio 2005

I'm attempting to get a development environment up and running for developing applications with Oracle C++ Call Interface (OCCI) in Visual Studio 2005.
My system specs are:
OS: Windows 7, 64-bit
Oracle: 11g release 11.2.0.2, 32-bit
Instant Client: BasicLite and SDK version 11.2.0.4 32-bit
Visual Studio 2005 Professional Edition version 8.0 with 32-bit tools enabled
I've followed this guide by Mark Williams and I got the example running but only in release mode. When I switch to debug mode the app will build, but when I run it I get the following error:
Problem signature:
Problem Event Name: APPCRASH
Application Name: OCCITest.exe
Application Version: 0.0.0.0
Application Timestamp: 53f5dfdd
Fault Module Name: KERNELBASE.dll
Fault Module Version: 6.1.7601.18229
The small example program that triggers this error is:
#include "employees.h"
using namespace std;
using namespace oracle::occi;
int main (void)
{
Employees *pEmployees = new Employees();
delete pEmployees;
return 0;
}
Employees::Employees()
{
user = "hr";
passwd = "hr";
db = "localhost:1521/service_name";
env = Environment::createEnvironment(Environment::DEFAULT);
try
{
con = env->createConnection(user, passwd, db);
}
catch (SQLException& ex)
{
cout << ex.getMessage();
exit(EXIT_FAILURE);
}
}
Employees::~Employees()
{
env->terminateConnection (con);
Environment::terminateEnvironment (env);
}
If I remove all calls to OCCI functionality the application doesn’t crash. That is, this program runs error-free:
#include "employees.h"
using namespace std;
using namespace oracle::occi;
int main (void)
{
Employees *pEmployees = new Employees();
delete pEmployees;
return 0;
}
Employees::Employees()
{
user = "hr";
passwd = "hr";
db = "localhost:1521/service_name";
cout<<"Look at me, I'm running"<<endl;
}
Employees::~Employees()
{}
In the guide Mark mentions that when running in debug mode, the linker should use the library file oraocci11d.lib. However, this file is not included in the Instant Client SDK version 11.2.0.4, so I’m using the input file oraocci11.lib for both the release and debug version.
I'm running out of ideas about how to proceed in solving this problem, and I would greatly appreciate any and all help.
If the Oracle DLL receives and/or passes objects such as std::string or any other object that either:
Manipulates the heap in any way, or
The objects could have differing internals between app and DLL,
then you have no choice but to use the correct library to link with. Otherwise you wind up with binary or heap incompatible objects being passed, which leads to what you're seeing now.
See here: http://docs.oracle.com/cd/E11882_01/appdev.112/e10764/install.htm#CBHGBBJI
The link above mentions both the debug import library and debug version of the DLL. Also this is stated at the link:
Applications that link to MSVCRTD.DLL, a debug version of Microsoft C-Runtime, /MDd compiler flag, should link with these specific OCCI libraries: oraocci11d.lib and oraocci11d.dll.
Since it took me quite some time to get the debug environment working I figured I'd answer my own question now that I did.
I got a variety of errors throughout the ordeal, but the error that I got most stuck on was an error saying:
'The application was unable to start correctly (0xc0150002).
Click OK to close the application.'
Also, I used http://www.dependencywalker.com which repeatedly told me that either oraocci11d.dll or a the following list of dll's could not be found.
API-MS-WIN-APPMODEL-RUNTIME-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL
API-MS-WIN-SHCORE-SCALING-L1-1-1.DLL
DCOMP.DLL
IESHIMS.DLL
However, what was really missing was for the executable to be able to find oci.dll. I'm just mentioning the errors in case someone else runs into these.
Here is what was needed to make it work:
First of all, the Instant Client does not contain the oraocci11d.lib or oraocci11d.dll, so it is necessary to install the full Oracle Client.
Next, the following must be added to the PATH:
C:\Program Files\Oracle\11.2.0\OCI\lib\MSVC\vc8
C:\Program Files\Oracle\11.2.0\BIN
In Visual Studio, select Tools -> Options, unfold 'Projects and Solutions' and select VC++ Directories. In 'Show directories for' under:
Include Files add C:\Program Files\Oracle\11.2.0\OCI\include
Library files add C:\Program Files\Oracle\11.2.0\OCI\lib\MSVC\vc8
In the property page for your project under Configuration Properties -> Linker select Input and under Additional Dependencies add oraocci11d.lib (or oraocci11.lib for release mode). Then select debug/release mode in the Configuration Manager
I have a related problem in that I am successfully using oraocci12d.dll/msvcr100d.dll, but this in turn is using oci.dll/msvcr100.dll. ie, oci.dll is not using the debug version of msvcr100.
My program seems to run okay, but any memory leak reporting disappears on exit.

visual studio 2010 issue

When I write a program using C++ and I want to run it, I can't catch the console window. I press CTRLF5 and it does not work.
I want the window to stay open and wait, even it finishes executing. Can anyone help me?
Thanks in advance.
http://connect.microsoft.com/VisualStudio/feedback/details/540969/missing-press-any-key-to-continue-when-lauching-with-ctrl-f5
In the older versions it would default to the console subsystem even if you selected "empty project", but not in 2010, so you have to set it manually. To do this select the project in the solution explorer on the right or left (probably is already selected so you don't have to worry about this). Then select "project" from the menu bar drop down menus, then select "*project_name* properties" > "configuration properties" > "linker" > "system" and set the first property, the drop down "subsystem" property to "console (/SUBSYSTEM:CONSOLE)". The console window should now stay open after execution as usual.
try using system("Pause"); as the last line on your code (before the return of your main function)
Ctrl+F5 should work. Just in case, if you have the source of your program, add the following just before the closing brace of main.
int x;
cin >> x;
the program will wait for you to enter some value.
If you want a breakpoint to be triggerred in debugger, do simple F5 instead of Ctrl+F5, after putting a breakpoint on the relevant source line (assuming the source/debug symbols are available)
Sorry to say, Ruba, but it looks like Microsoft removed this nifty little feature when moving from VS2008 to VS2010.
I can't find anything on MSDN, the web in general, or VS options to turn it back on.
My advice is to bypass the environment altogether for testing your application. Simply open a cmd.exe window in your runtime directory (debug or release or whatever), build the executable within the IDE then switch to the command window and enter testprog.exe to run your program.
Make sure you include any required command line parameters and, after you've entered it the first time, you can just use the up-arrow to retrieve the last command.
Yes, it's a bit of a pain but, until someone comes up with a better solution, it's probably the best way to ensure you see all the output while ensuring the program has shut down completely.
Just set a breakpoint at main()'s closing curly brace if you want to see the console after the program is finished.
You should create VS 2010 C++ Projects as below:
New project -> Visual C++ -> Win32 -> Win32ConsoleApplication
In this way you will be getting "Press any key to continue..." when you run program with ctrl+F5, as it was in VS 2008.
EDIT :
New project -> Visual C++ -> Win32 -> Win32ConsoleApplication -> Next -> Check 'Empty project' -> Finish = what you actually need.