How to debug clangCodeGen in LLVM project - llvm

I get source of LLVM and make a project on Visual Studio as guiding in https://clang.llvm.org/get_started.html
I would like to debug clangCodeGen to know how IR is generated or Code Generation do in LLVM. However there is no main() method or something like this in clangCodeGen project.
Do you have any suggestion for me ?

The clangCodeGen project is a static library, so it doesn't have main function and you can't debug it right away.
What you need to do is:
Come up with clang invocation you want to debug. For instance, clang test.c.
Append -v flag and look at the command's output. It should contain large clang command starting with "full\\path\\\\to\\clang.exe" -cc1 ...
Choose whatever project you like in your solution, open its Properties windows and go to Debugging tab.
Set Command field to "full\\path\\\\to\\clang.exe" and Command Arguments to the rest of clang -v output.
Build the solution.
Right-click on the chosen project and select Start debugging.

Related

How to set compiler options in Arduino Eclipse IDE?

I installed the Arduino Eclipse plugin, and created a new project. I want to compile my code with the -std=c++11 option, but by default Eclipse does not use that option. Under Project Properties, for other C++ projects build options can be set in the C++ Build tab, but it is missing for my Arduino project. Is there any way to set the build options?
I recently installed this plugin, and I wanted to do the same thing, in order to generate mixed C and Assembler listing. In summary, (This is for OSX, you will have to figure out the paths if you are on a different platform.)
Look in /Users/concunningham/.arduinocdt/packages/arduino/hardware/avr/1.6.23 for a file called platform.txt.
In there you will find a line like this:
compiler.cpp.extra_flags=-Wa,-adhln -g > "$<".lst
You can see I added "-Wa,-adhln -g > "$<".lst" as extra options for the cpp compiler.
Now, this is key - restart Eclipse, clean the project in question, and rebuild. You should see your extra options take effect. Peep at the makefile to be sure.

how can build options be changed in code::blocks?

I recently started using code::blocks, so I'm a newb here.
I am writing a game, in SDL with C++ and all of the code I am writing depends on the build options similar to this: g++ -Wall -o "%e" "%f" -lSDL -lSDL_image
Code::Blocks seems to work fine when I select to start a NEW SDL project, and convert my programs to project files. However, I have many source files, and I dont want to convert them all to project files, I would rather just change the build options for code blocks.
I am using version svn 10528, on Linux if that helps. I have formerly been using geany, which was very simple to change, and set build options in.
Ok, I found it, In Code::Blocks, go to Project> Build options
a window appears. it lists build options.
right click on that and add new. from there you can give it a name, add compiler options, and add linker options.
save it and youre done.
I saw some errors in the IDE when trying to use this, and found if you click continue it works fine. if you click cancel, the IDE crashes.

"Program is not a recognized executable" error in Eclipse

I'm trying to debug a C++ programme in Eclipse Indigo. The project is using autotools/configure (and the respective plugin) as build system.
After successful build I right-clicked on the binary in the project browser and chose "Debug As". Then I used the file browser to select the binary. Clicking on "Debug" then opens a dialog which just says "program is not a recognized executable".
Any ideas?
I found the answer: the binary parsers configured in eclipse were the wrong ones. Adding the correct binary parser under Project --> Properties --> C/C++ Build --> Settings solves he problem.
If you're using libtool in your project, what looks like the binary may actually be a wrapper script used to set LD_LIBRARY_PATH and stuff like that before executing the real binary (which is stored in the .libs directory). This may be what causes Eclipse to fail, but I'm not sure how you should go about fixing that.
There seem to be a bit of documentation about Eclipse CDT and libtool on the internet which may have the infos you need though: http://www.freerdp.com/wiki/doku.php?id=eclipse#debug_configuration
From OSX snow leopard on, gcc seems to build 64 bit executables by default. And those won’t be recognized from Eclipse in return. To solve the error, you’ve got to explicitly set your architecture to i386.
Enter your project properties and add the command line option “-arch i386″ for each C++ Linker, C++ Compiler and C Compiler. After a clean build, you should be clear to debug again. In Linker options make sure to NOT set it up as -Xlinker option.
Original Source

Compile a specific obj in a Visual Studio Project from the Command Line?

I want to compile file.obj from the commandline. Within the IDE, if I'm viewing file.cpp, I can click on Build -> Compile (or just hit Ctrl-F7), and it will compile just the file.obj object. I would like to be able to do this from the commandline. Ideally, something akin to:
vcbuild project.vcproj Debug file.obj // not a valid command
I have looked at the documentation for vcbuild, msbuild, and devenv. I've also experimented with all three, but I cannot find a way to do this. I can find a way to build an entire project, but that's not what I want. I want to build a specific source file. /pass1 tells vcbuild to just compile (not link), but it compiles the entire project.
I also looked at using cl, but that is just the compiler. In order to use it, I would have to know all the right parameters to pass to set up my environment correctly. All that is automatically taken care of with msbuild/vcbuild.
With Makefiles, I could always do make file.obj, and it would properly set path, include dirs, etc.
Any options for this? Is there an automated way to extract the appropriate settings from the .vcproj file, and pass them to cl?
Using cl is the way to compile single files from the command line. Like you say, it requires/allows you to specify exactly the options you want to use. All the options!
If you actually don't want to do that, why not use the IDE to have it done automagically for you? Why do it the hardest way, if you don't like that?
if you just want to compile the project, run the visual studio command line and call msbuild.
Example:
MSBuild.exe MyProj.proj /property:Configuration=Debug
this will compile the MyProj Project from the current directory.
more info on msbuild
http://msdn.microsoft.com/en-us/library/dd393574.aspx
Or if you need to build a single file you can use cl as stated above. You can see all the parameters passed by visual studio to cl if you go in the properties of the project. Usually under:
Configuration Properties -> C/C++ -> Command Line
and for linking:
Configuration Properties -> Linker -> Command Line

dSYM Directories While Compiling C++ Code in MacOS

Why compiling C++ in Mac always create *.dSYM directories?
Is there a way to disable that?
It's because your Xcode project is set up to build debug symbols with an external dSYM file. This is actually very handy for release builds, as it means that you can strip debug symbols from your app, and when a user sends a crashdump to you, you can use the original dSYM file to generate a proper stacktrace for debugging.
Anyways, you don't need to disable debug symbol generation in your project. Instead, just change the debug symbol type to DWARF (instead of "DWARF with dSYM File"). You can also use Stabs, but that's the old format.
Edit: Ah, I see you meant from the command line, not from Xcode. I'm not sitting in front of my mac atm, but I see from the gcc4 manpage than you can specify -gstabs to use the Stabs format.
I assume your using Xcode. Go to "Project"/"Edit Project Settings" menu item, click on build tab, under "GCC 4.0 - Code Generation" section, uncheck Generate Debug Symbols. You can type in "sym" in search field to help find it.