Debug the program using preprocessed file output? - visual-studio

Let say I have a file that has a lot of preprocessor macros that generate loads of code. Normally when debugging such a file I wouldn't be able to step into macroses like functions as debugger does not have line number information. On the other hand it is possible to generate a preprocessed file using /P directive to the compiler, which will result in a file that contains all generated code and no macros.
Is it possible to make Visual Studio use preprocessed file for debugging?

One solution (not very convenient though) is to copy the preprocessed file back to the source file and compile it again. One must remember to generate the processed file without line numbers and to keep the original source code somewhere.

Related

Visual Studio custom build tool doesn't rebuild from scratch

I have a generally question about "custom build tool" tab in settings.
I already used this feature and like it. But this time the result is not what I expected :/
I try to automatically convert a Performance Monitor manifest file (.man) to a corresponding .h and .rc file (ctrpp.exe). But this should not matter, just about the principle.
After I assign the custom step to the .man file, it is possible to compile the file in context menu. The build tool also recognize a modification and builds the output files again. Also the output files were deleted at rebuild.
But that's my problem.
Manual compile and inkremental build works fine, but why the files wasn't build automaticall after a first check out or at rebuild?? I expected that compiler forces a build, if it no output files found.
As result, the compiler don't find the corresponding header file in my files.
This page (in German) describes when the update is triggered. Can I force to generate the output files?

Decompiling/Unpacking a File (Reverse Engineering the Compiler)

I'm using a program that can pack/compile a folder with files into a single *.xyz file that only that program can decompile and read. In order for the program to create a compiled file the flag:
[Compile]
Decompile=1
must be in the file Meta.ini. If not, the file cannot be unpacked/decompiled and there is no way to get back the source files.
I have created a compiled file and have lost the source files. I forgot to add the decompile flag, so I currently have no way to unpack the file and continue my work. I can still compile and decompile files using the program as long as I include the flag. The file produced is in the FoxPro FPT format. The program is written in Visual Basic.
To Summarise:
I have a compiled/packed file that I need to decompile/unpack.
I have access to the program that can compile and decompile the file.
I don't have the required decompile flag in the file.
The file produced is in the FoxPro FPT format.
The program is written in Visual Basic.
I know where the flag needs to go but I have no way of inserting it without first decompiling/unpacking the file (that I know of). My options are either to find a way of decompiling the file itself, or find a way to isolate the decompiler from the rest of the program. Any help would be greatly appreciated.
Thanks
You are saying
I have access to the program that can compile and decompile the file.
Then simply modify the portion that checks that flag and decompile.

How to view the .cod file generated by VC++ compiler?

In Visual Studio there is a way to output the compilation result in the form of both source code, assembler code and the machine code by setting the compiler output properties:
The generated file has the .cod extension which is by default associated with Visual Studio. However, on opening the file it is just opened as a plain text file, no syntax highlighting etc. is available here:
Is there any tool that would allow me to visualize these files, at least to be able to separate the comments containing the source code, addresses and the assembly code optically?
EDIT: I tried NotePad++, my preferred editor, as the very firs solution and it is already quite good how I can visualize it there using Assembler as a language, but still there are problems with hexadecimal numbers, the assembly code is not aligned properly etc...
Try Notepad ++.
and don;t forget to select the Language by clicking Language->A->Assembly
You will get the necessary syntax highlighting

visual studio 2010 c# simple compile help

Hey I developed a small application and would like to compile it, however it comes with loads of extra stuff I dont want. All I want is a stand alone .exe file but instead I am getting pdb vshost.exe files etc. Is there anyway to get rid of these as I just want 1 .exe
Just copy/paste the exe file out. VS uses those files internally, and one is full of debugging symbols. Your going to want it if you plan on stepping into the code.
All these ''extra stuff'' is not required to run your ''small application''. You can verify that by copying the .exe file to a location where it will be standing alone indeed.
If it is not standing alone, as you say in the comment below: perhaps part of your code does compile to .dll, or you reference external dlls? Could you supply a list of filenames of files that are created?

Is there a way to debug preprocessed code in VisualStudio

I've a visual C++ project I'd like to debug. However, several functions are actually generated by macro expansion ( like set##Name for a particular property). So, while debugging I can't follow the execution flow inside these generated functions.
Do I have to use the /P flag and then debug the preprocessed code?
You would have to preprocess the code using the /P flag in some other project (or on the command line, if you fancy spelling out all the include and library folders), and then compile this preprocessed code instead of the source file in your real project. Then you can debug through it.
That said, once you're at it, can't you eliminate the macros? With const, inline, and templates, I rarely ever feel the need to resort to macros, and if I do, it's usually very small, isolated pieces of code. These are either too trivial to need debugging, or I manually replace one instance of the macro with the code it generates and debug that. (However, this might have happened to me thrice in the last decade.)

Resources