How to use intel pin tools on applications? - c++

I am trying to execute pin tools on my own executables. I am asked to use cache simulator (allcache) in order to collect miss rates.
I'm struggling with the parameters and I faced with a lot of errors actually.
The operating system is Win10-64 Bit but I'm using CygWin.
Currently I am trying to trigger it with pin.exe which is under intel64/bin folder.
$ pin.exe -t allcache.cpp -- myOwnThingy.exe
But I'm getting this error:
E: Failure to open DLL file C:\cygwin64\home\blabla\pin-3.7-97619-g0d0c92f4f-msvc-windows\intel64\bin\allcache.cpp
Why does it need to open a dll file especially when there are only .cpps and header files in the examples?

Pin tools must be compiled to be used. You can't run the source files. Use 'make' to build the pintool.

Related

Moving away from DevC++ to command line compiling

I've inherited a large volume of C++ code for running & monitoring laboratory equipment. Currently the deployment is managed by compiling all of the individual modules (each it's own program) using DevC++, manually moving all the .exe files to a Dropbox folder, and then running them on the host machine manually.
I'm trying to automate this process somewhat to make rolling out an implementation on a new machine simpler and making sure the most up to date binaries are what is running on any given machine quickly. However, I don't know anything about deploying software in a Windows environment (I'm used to working on linux systems where a simple makefile would suffice) What tools (preferably command line) are available to compile & organize binaries in a portable way on windows systems?
Assume that you have a C++ compiler usable on the command line, on one translation unit. For example, GCC is such a compiler (and mingw is or contains a variant of GCC). Assume also that it is capable of linking (e.g. by driving the system linker).
Then you need to use some build automation tool to drive such compilation commands. For example GNU make or ninja (but there are many others). AFAIK they exist on Windows (so you could port your Makefile on Linux to Windows).
Once you have chosen your build automation tool, studied its documentation and understood how to use it, you'll write the relevant configuration file for it. For make, you'll write a Makefile (caveat : tab characters are significant). For ninja, you'll write some build.ninja files (but you'll probably generate it, perhaps with meson).
Notice that some build tools (e.g. cmake) are cross-platform.
BTW, DevC++ is an IDE, not a compiler.

Using Arduino C++ libraries on PC platform

Arduino has some good C++ libraries which I would like to use on a PC platform. Another advantage is that one can test and debug Arduino code on a PC. It is much easier to do debugging on a PC.
One library I am particularly keen on is the String library. https://www.arduino.cc/en/Reference/String
Is it possible to somehow import the Arduino String library into a C++ IDE like Visual Studio given that the Arduino library is open-source? How can this be done?
I have been struggling with this issue on and off for the last three months, and I have spent a few hundred hours staring at my computer screen, trying stuff, documenting the results, trying other stuff (repeat). I have done a fair amount of digging on the internet and have found very little that constitutes a definitive resource on this topic. That being said, here is what I have found that WORKS. One caveat is that these instructions are based on ESP32 hardware. Note that this is still a work-in-process, as there is some clean-up left to do. Also note that this avoids having to do the manual/command line tasks such as "makefile". If you are coming from using the Arduino IDE environment you will probably appreciate this.
First of all, some details on the development environment:
Install MS Visual Studio Community Edition (free). I installed "Desktop development with C++ option" (Visual Studio link)
Note that I am developing code for an ESP32 module. There are lots of different modules to select from, they are low cost (~$7 on a breakout board), are very powerful (compared to Arduino hardware) and have Bluetooth and WiFi embedded. If you are using some other hardware then some of the remaining steps may not apply/will need to change.
Install drivers (these are used so the ESP32 gets assigned a COM port automatically) (Silabs link)
Install VisualGDB (download link) for MSVS as described in this link: (VisualGDB tutorial) Note that downloading the ESP32 toolchain as described in the link takes a long time (an hour?), be patient.
Note where the folder \SysGCC\esp32 is located on your computer (most likely in the root of your C drive). This is the ESP32 toolchain that you installed on the previous step.
As part of the VisualGDB install step that is described in the VisualGDB tutorial, you have to change the "Path Mapping". I was prompted by the install to download CMake.exe from VisualGDB at this point. In the field "Absolute Paths (starting with /)" you will need to enter the path to SysGCC that I described above (mine was C:\SysGCC\esp32)
At this point you should be able to connect an ESP32 module to your computer and use the "New Embedded Project" wizard in VisualGDB to create a simple project. I generally choose "LEDBlink". Note that most of the ESP32 boards I have used have the built-in LED on GPIO 2, not GPIO 5 (which is the default in the wizard).
So far, so good. Confirm that you can blink the LED. Clap your hands, shout with glee, grab a beer, or do whatever else you want to celebrate. At this point we have not really done much to help the importing of Arduino code, so here is where the fun REALLY begins.
Note the location of your LEDBlink project folder on your hard drive.
Download the Arduino core for ESP32 from Espressif on Github.
Copy all the *.h, *.c, and *.cpp files from your downloaded Arduino Core into your Blink project folder, EXCEPT the files that are in the "variants" folder. I ended up copying 77 files. In fact, what I did was first create a new folder called "bulk libraries" to copy all the source and header files into, in order to make it easier to perform this step for each project.
The "variants" folder contains a load of subfolders, each containing one file named "pins_arduino.h". You have to find the folder for your particular ESP32 module, and put that particular "pins_arduino.h" file in your project folder.
In your project source code, add the following line:
#include "Arduino.h"
Build the project and you should get no errors.
Note that in the MSVS Solution Explorer window for your project, under External Dependencies, you will see a list of all the *.h files that you copied into the project folder. This won't happen right away, but in the lower left corner of the MSVS app you will see a bunch of things going on in the background, parsing files etc., THEN the External Dependencies will appear.
Now in app_main() add the following lines:
initArduino();
Serial.begin(115200);
If you rebuild the project you will get a few errors during linking, because all of the file references to the *.cpp files are not (yet) included in your project.
In the Solution Explorer, right click "Source Files" and "Add Existing Item" and add all the *.c and *.cpp files to your project (not the *.h files)
Rebuild your project. You will most likely get some errors of "(something).h: no such file or directory". That is because at the time of this writing, the Arduino core provided by Espressif is not complete. In the Error list, note the file location of the error, and REMOVE this file from the project in the Solution Explorer. For example, I had the following error:
"vfs_api.h: no such file or directory", and the error was located in the file SD.cpp. So I removed SD.cpp from the project. Keep iterating through this step one file at a time until you get a build with no errors. Take notes as you remove files (don't delete them) so you can add them back if you make a mistake. You may need to do some additional debugging here depending on what source files you added to your project. Be patient and expect a little trial-and-error as you review the Error List that is generated during the Rebuild. When you have a project that compiles without errors, celebrate with another beer (or two).
In your project source code, add the line:
Serial.println("Hello World!");
I put this in the while(1) loop of the blink-task function. This line of code will write to the serial port once every time the LED blinks. Since Serial.println is an Arduino function, you can be assured that at least this Arduino library is up and running. I believe you should be able to add more #includes (such as Wire.h) to your project and proceed in the same way (but wait on that for now).
Rebuild and upload to the ESP32. Open the serial port monitor (button near the top of the MSVS window, to the immediate right of the COM port pull-down) and verify that you are getting the "Hello World!" messages as the LED blinks.
Now, before you give me any grief about "dumping" all the library, header, and source files into my project folder, I realize this is not best practice. If you created a "bulk libraries" folder as I suggested, you should be able to organize your project better. This is left a simple step for the reader.
Since this solution relies on ESP32 hardware and VisualGDB, it won't work for everyone. However it allows you to migrate away from the "mysteries" that take place behind-the-scenes in the Arduino IDE, and allows you to create a foundation for better source control and project development. For a related discussion, see this link on sysprogs.com.
The String library is mostly free of platform-specific dependencies, so you could simply add WString.h and WString.cpp to your source files. You will likely have to do a little bit of porting (cleaning up some macros, I suspect), but there's no reason it shouldn't eventually build.
Many other libraries are going to be considerably more difficult to port over to your PC; anything that touches peripherals of the MCU are not going to port well.

Integrate Octave with C++ in QtCreator IDE

I am trying to do some DSP operations in C++ using Octave...I have been trying to integrate Octave with QtCreator 5.1 (MinGW compiler) with no success...I have done the following steps...
Downloaded Octave3.4.3_gcc4.5.2-install.exe and intsalled in C drive. I have added the address of the bin folder of octave to the environmental variable PATH
Set the INCLUDEPATH and LIBS according to the location of the header files and the libraries of the Octave directory.
This is the sample program I am trying to run .
The code builds successfully. However while running it hangs up. Debugging yeilds the following message.
I tried to create an executable using the command prompt of octave using the command mkoctfile --link-stand-alone octavetest.cpp -o octavetest. The executable created also hangs up with an error message.
If anyone can point out where exactly I am going wrong in the integrating process it would be realy helpful. Is there any other simple way to set up the environment to call Octave APIs from C++? I have almost checked on the internet forums including stack overflow with no luck...
Your gcc/libstdc++ version will likely be incompatible with the one octave got compiled with.
This compiler is as close as i got to the one used to build the current octave-binaries.
If you extract both archives and add their bin directories to your path variable, you should be able to build octave programs. Your linked sample builds for me.
You can also add the compiler in QtCreator. (Tools⇒Options⇒Build&Run)
I have done exactly the same thing on Windows. In my experience, you need to build Octave with exactly the same compiler that you're building your executable with. That's all there's to it. This really means you have to build Octave from sources. I have wasted a lot of time avoiding to build Octave, and in the end could never be sure that it'll be stable or not. Octave will build with VS 2012 with very minor tweaks.
Building Octave is really the only practical way to go, I think. The amount of time you spend setting up an Octave build will insignificant in the long run.

Automatically compiling object files on save in Eclipse

In Eclipse, is there a way for, when I save a code file, to compile the object file for the file saved, and then link them together when I go to run or debug? This is with C++ on Linux with GCC.
I don't think so. In Eclipse CDT build process is started explicitly. I think that "Build automatically" option is used for Java and other languages which Eclipse knows how to build. C++ projects are usually built using some kind of make utility. You can customize your make file to set different build targets to improve performance and reduce build/compile times.

Is there a way to get C++ source compiled into a binary so gdb can see it?

Say I have a build machine and test machine and the source code is only on the build machine. (Linux)
I have a debug build C/C++ executable and I want to run it with gdb on the test machine.
In the debugger running on the test machine it is still looking for the actual source files which are not there.
Is there a way to have g++ actual include the source in the executable itself with the other debug information so files are not needed?
There is no way to have the source compiled into the binary to allow gdb debugging in this manner.
Probably the best mechanism in this case is to use gdbserver - which allows you to run the application remotely and debug it on the build machine.
If you can't use remote debugging, then an alternative is to mount the directory containing the source on the test machine, and then use the set substitute-path to map the directory that the test machine has vs. the build machine.
No, but the good news is that is no necessary. You should set your source path. It should accept a network path.