How can i include the debug info in my binary? - c++

I have a C++ application, using VS2008, and i want to include the debug information into the binary so that i don't need to publish the ".pdb" file with my application. My application has made use of the dgbhelp.dll, and i do need those debug information so that i can get the source code line number when there's exception occurred. But without the ".pdb" file, my application failed to get the line number, and it would be better if i can include the debug info in the ".pdb" file into the binary.

According to the documentation, you need /Z7 instead of /Zi. (I've never tried it though.)

Related

Xml parsing exception on relative path with Eclipse gdb DSF debug

I'm using Eclipse Mars, with gdb 7.2.
While trying to debug a C++ application in Eclipse gdb DSF, I'm getting a parse exception. But I don't get the parse exception when I run the same program with gdb outside of Eclipse.
The exception states: "Fatal error during XML Parsing: unable to open primary document entity /path/to/file.xml"
But the actual path in xml is a relative path: "../../../../path/to/file.xml".
The C++ application is reading in the XML and trying to open this file.
It's as if the ../..'s are just getting chopped off, and that's why the error states essentially "I don't know about a /path/to/file.xml"
I imagine that something is wrong with my gdb setup in Eclipse, but I'm not sure what. I've tried many different things, none of which seem to work.
I imagine that this has something to do with relative paths not being recognized by gdb, or the working path being different in Eclipse vs gdb.
Does anyone have an idea what is wrong?
You need to make sure the Working Directory matches the location of the executable in the File System.
https://sourceware.org/gdb/onlinedocs/gdb/Working-Directory.html
Actually, this was a simple issue: It turns out that my Working Directory(in Debug Configurations under the Arguments tab) had to be set to the full path of the location of my executable.
I also had to set the path of my executable to the full File System path of the executable.
It works as expected now.

How do I set up this visual studio (2015) custom build step (tool?). Basically I want a pre-preprocessor step that modifies header files (c++)

I want a run a build step that looks at a .h file, adds some code based on some external params, and hands the resulting file to the preprocessor.
I see the "Custom Build Step" in the project properties. It seems to need an output file. I just want to forward the results to the preprocessor.
It seems like the custom build step wants to do a 1-time process, not per-file or by file type.
The problem is that I don't know how to send my external executable the file currently being processed (eg, "HelloWorld.cpp"). $(InputName) and %(Filename) are blank and docs say it's deprecated. How do I send the filename to my external executable?
But even if I get that working, I don't want to set this per-file. I want all header files to go through this process.
Any ideas?
I've looked at:
https://msdn.microsoft.com/en-us/library/dd293663.aspx?f=255&MSPPError=-2147217396
https://msdn.microsoft.com/en-us/library/hefydhhy(v=vs.90).aspx
https://msdn.microsoft.com/en-us/library/ff770593(v=vs.140).aspx
working on a debug, x64 config on windows.
First of all, No, you cannot modify a file and pass along the results to the next stage (that I could see). I'd need some sort of Program Transformation System.
So I need an intermediate file. That file has to be added to the project, even if it gets overwritten by your code generator. I can associate c++ header files with a custom build tool, and they will all get called one-by-one in the stage of the build specified in the Custom Build Step. The custom build tool will modify the intermediate file(s), and all is well.
The VS 2015 name for the current file being processed is %(Filename). In older versions it has been $(ProjectName) and $(InputName).

Can I instrument an exe file using vsinstr?

I've been trying to verify the code coverage of an exe file. To achieve this, I'm trying to instrument the exe file (not dll) and then start/stop the coverage.
Every tutorial describes about the instrumentation of dll only. Is it possible to achieve it for exe? If yes, what are the special options I need to give.
Here are the commands, I've been trying for exe:
vsinstr -coverage Test.exe
Returns success message and creates another copy of exe
vsperfcmd -start:coverage -output:Result.coverage
vsperfcmd -shutdown
It creates the output file successfully. But when the file opened in visual studio shows the error message:
"Empty results generated: No binaries were instrumented. Make sure the tests ran, required binaries were loaded, had matching symbol files, and were not excluded through custom settings."
Please help
Your first command starts the profiler service and your second one shuts it down (and causes it to write its output). What you're missing is the -attach command.
vsperfcmd -attach:PID
where PID is your process's numerical ID.
Once you're attached to a process, it will start collecting coverage data. Do whatever you need to exercise your code, then run the shutdown command to get your output.

Debugger ignores the edited file

Why doesn't 'Edit & Continue' feature work in VS2015?
The debugger will ignore the edit and you will see an error message when you continue execution and I get the following
“The source file has changed. It no longer matches the version of the
file used to build the application being debugged.”
You must set the Debug Information Format to be “Program Database for Edit and Continue (/ZI)”. If this option is incorrectly set the debugger will ignore the edit, it will be just like modifying a file with edit and continue disabled.
If you make an edit in a binary not compiled with this option, the debugger will ignore the edit and you will see an error message when you continue execution “The source file has changed. It no longer matches the version of the file used to build the application being debugged.”
Open the Property Pages of the project.
Under Configuration Properties -> C/C++ -> set the Debug Information
Format to “Program Database for Edit and Continue (/ZI)”
Edit & Continue has only been introduced in VS2015, therefore this option is not available on earlier versions.

C++ profiler which shows the call path of specific part of program

I'm wondering if there is a way to see the call path of specific part in c++ program. I'm working in open source code where it contains of many libraries. I tries to follow the code from the path I end up in a template. So if there such a library or profiler to show the call path for just specific part of the code?
Thanks!
Compile application with full debug info, issue a fatal exception in place of interest and do the stack backtracking to console with full call path - source file names and line numbers (if available). Profilers will not be able to do that themselves if there is not enough debug information