How to debug command line utility in visual studio - c++

I have C++ code in visual studio and an exe with pdb file, the exe is a command line utility.
I want to debug the executable. I cannot compile the source code in visual studio since it has a large no. of dependencies.
Is there a way where I can attach the debugger to debug the executable.

If it is compiled with VC++ then yes. Run your code, and attach the debugger from the menu: "Debug/Attach to process".
If you want to start the process with the debugger already attached, the follow this tutorial:
http://msdn.microsoft.com/en-us/library/0bxe8ytt.aspx.
To create an EXE project for an existing executable
On the File menu, click Open and select Project.
In the Open Project dialog box, click the drop-down list next to the File name box, and select All Project Files.
Locate the executable, and click OK.
This creates a temporary solution that contains the executable.
If yo did this, you can simply click on "Debug".

Related

Visual Studio 2015 can compile and run but I can't find .exe in both Release/ and Debug/

Today I code as usual. Everything seems to go well in Visual Studio 2015. It can compile and run the program successfully in VS2015. However, when I go to the Debug/ dir, I can't find .exe file, all I can see are below:
It seems that the VS2015 can't link these .obj to create a .exe file, while I have no idea how to fix it. Is there anyone who can help? Thx in advance.
You should right click on your main Visual C++ project in Visual Studio, select Properties, and check the Output Directory property on the General page. Also don't forget to check your build configuration and platform (e.g. Debug, x64) on the top of the settings page, as by the default settings those affect the output directory.
Visual C++ Project Settings Screenshot
I had the same problem. The exe is in a different "debug" folder, that is in the parent folder.
As in, when I right-click on the project in visual studio and select "show in folder", it opens source\repos<projectname><projectname> and in there is the .cpp file and a debug folder. But this is not the debug folder you are looking for.
Go to up a folder to sources\repos<projectname> theres another debug folder there that contains the exe

Debugging the C++ file called by an executable file in Visual Studio

I have an exe file which will execute the cpp files and capture the results. I want to debug the cpp file which is being called by the exe file in the visual studio.
Currently
I am loading the exe file as a project in the Visual studio, i open the c++ code which is called by exe file as well and keep breakpoints at relevant places. when I run the exe file it does not stop at the breakpoint but continues execution and stops.
Is any settings to be made in the visual studio to gain control over the cpp code while debugging.
#santosh I think you are loading VC++ Project file(Not Exe file)
you have t build your project (compilation of the project).
Put a breakpoint in menu bar debugging->start debugging or Press F5.
Even though your debugger not hitting the breakpoint check your "symbols" in VisualStudio in menu bar Tools -> Options -> Debugging-> Symbols tick the Microsoft symbol servers press ok.
Again build your project and debug.

How do I create an executable in Visual Studio 2013 w/ C++?

I can't find the exe file for my Hello World program that succeeded to work, and the program did not open as soon as it said it worked. I tried going to my documents and checking my project's folder. It was completely empty. Thanks for any and all help.
All executable files from Visual Studio should be located in the debug folder of your project, e.g:
Visual Studio Directory: c:\users\me\documents\visual studio
Then the project which was called 'hello world' would be in the directory:
c:\users\me\documents\visual studio\hello world
And your exe would be located in:
c:\users\me\documents\visual studio\hello world\Debug\hello world.exe
Note the exe being named the same as the project.
Otherwise, you could publish it to a specified folder of your choice which comes with an installation, which would be good if you wanted to distribute it quickly
EDIT:
Everytime you build your project in VS, the exe is updated with the new one according to the code (as long as it builds without errors). When you publish it, you can choose the location, aswell as other factors, and the setup exe will be in that location, aswell as some manifest files and other files about the project.
Click BUILD > Configuration Manager...
Under Project contexts > Configuration, select "Release"
BUILD > Build Solution or Rebuild Solution
Just click on "Build" on the top menu and then click on "Publish ".... Then a pop up will open and there u can define the folder which u want to save the .exe file and by clicking "Next" will allow u to set up the advanced settings...
DONE!
Do ctrl+F5 to compile and run your project without debugging. Look at the output pane (defaults to "Show output from Build"). If it compiled successfully, the path to the .exe file should be there after {projectname}.vcxproj ->

How do you see source code when debugging a native c++ dump file in Visual Studio

I got a minidump from a server on which my native c++ app was running. I also have the exe and pdb files. I am able to open the minidump using Visual Studio 2005 Pro and it correctly loads the symbols from the pdb file.
I run the debugger (F5) and it shows me that it crashed. When I click on the stack trace to see where, it tells me that it can't find the source code "There is no source code available for the current location.".
How do I tell Visual Studio where the source code is?
My exe is an optimized release build that I build with a pdb file.
From this MSDN page:
In the Solution Property Pages, you can change the directories where the debugger looks for sources files and tell the debugger to ignore selected source files. See Debug Source Files, Common Properties, Solution Property Pages Dialog Box.
Make sure you supply VS with the sources that correspond to the binaries and PDB files.
Normally, VS should ask you where the sources are when first double-clicking a stack frame. I ran into a problem where VS would pop up the There is no source code available for the current location. dialog when clicking on some stack frames only, but display the source for others. This turned out to be because the /Zi flag was not set for some projects, causing the link back to the source files to be missing. This flag can be set in Project Propery Pages > C/C++ > General > Debug Information Format.

debug DLL in a different solution

I have an *.exe project that was written in one solution under vs2005 and i have a DLL file
that the *.exe project is using.
the problem is that the dll was written in adiffrent solution and when i try to make attach
to the *.exe file (after i run it) from the dll solution in order to debug the dll , i get no symbols are loaded error (and i cant debug the dll) altough symbols were loaded (i can see the *.pdb files that created after i compiled the dll solution) .
What can I do?
First check the Output window, it will show whether or not it could find debugging symbols for the DLL when it got loaded. Next, switch to Debug + Windows + Modules, right-click your DLL and choose "Symbol load information". That shows where the debugger looked for .pdb files for the DLL. Ensure the .pdb is located in one of these paths.
If the problem is not getting source code for the DLL instead of missing .pdb files, first delete the hidden .suo file in the solution directory. The next time you debug into the DLL, Visual Studio will again prompt you to provide the path to the source code file. Don't press Escape, enter the path. Another thing you can do is right-click the solution in the Solution Explorer window, Properties, Common Properties, Debug Source Files. Add the path to the DLL source code directory.
If you have the visual studio project that generates the dll, compile it in debug configuration and launch debug. You'll be asked for an executable ; select the one you have (from your other solution) and you'll be able to debug the dll.
Now if you want to debug both at once, i believe your way is correct, as long as the dll that the exe uses is the exact one that you've just compiled in your other solution. That might be the problem you're encountering.