I have the following problem:
I have a Matlab program in form of some set of *.m files. It is later compiled into executable and used. The problem is that occasionally the resulted executable just hangs and this behavior cannot be reproduced when debugging/running *.m files from IDE (even using the same input data).
To figure out what hapens I intended to:
compile (somehow) *.m files into C/C++
compile C/C++ as debug to get .exe and .pdb
And later when .exe hangs just 'attach' visual studio debugger to hanged .exe to check where it 'loops/waits'.
Unfortunaley Matlab Compiler (as I was told today) does not produce C/C++ code before creating executable. I was misleaded by -g option of mcc which according to the documenttion is supposed to do the following:
-g Generate Debugging Information
Include debugging symbol information for the C/C++ code generated by MATLAB Compiler.
It looks exacly like the thing I want to archive.
I would appreciate if someone could explain me that discapency or suggest how to archive what I am trying to do (if it can be done at all).
It is not possible to create a debuggable code in Matlab compiler, because the deployed code uses MCR. (Matlab virtual machine) .
See this question : Is there any way to debug compiled components using Matlab Debugger?
Since you don't have errors, but rather an infinite loop, the best solution in that case would be screen outputs, and hopefully you will trace the bug.
Related
How to directly run a c++ file present in read-only storage like CD-drive without making executable files using g++? There must be some arguments for that to work.
The process of a C/C++ program when you make one till you run it:
You write the program's source code.
The compiler comes in here and compiles the source code to object files.
Note: Remember that the program cannot be executed at this stage. It's only an object file. You'd know this if you have worked on bigger size programs, but if you haven't here is how it works. Remember using those header files in your programs? These header files just tell the compiler that there are some things that are not defined in your program. They are somewhere else. So your compile compiles the program to the object file leaving out things that have a prototype (which is in the header files).
This is a very important point. Here a program called 'linker' comes into play. What linker does is to take all the object files created by compiler and combines them into one. Say for example your compiler created a single object file. Now, you're using math library or anything from standard library. The compiler-linker package (often called only compiler) comes with object files for these standard library definitions. So, linker takes your object file and combines it with other object files from the package and then converts it to an executable file. This is the file that you can run. Nothing else is runnable directly.
To run source code the process is explained already, we have to use the g++. Now
What I understand from your question is that you want to know if a program can be run once it's compiled and linked properly (hence an executable has been generated). Answer to that would be yes.
Alternatively, may sound strange, there is an interpreter I know called Cling that can be of use to bypass the compilation of C++ program.
After all C++ is generally seen as a compiled language. However, any programming language can be implemented as a compiler or as an interpreter and Cling happens to be an interactive C++ interpreter based on LLVM and Clang.
Take a thorough look at this
I have a quite large x64 c++ program that is compiled with Visual Studio. There are two ways how do we compile it - one is with sln solution file (from IDE or through msbuild), another is through Makefile in VS command prompt (which then internally uses Visual Studio's cl.exe and link.exe).
Somehow I got into situation that binary build through Makefile produces executable with /AVX instructions enabled, and I don't want that, so I want to find out how to get rid of it.
I try to compile and link it without any parameters (especially without /arch:AVX). I hope that I compile and link the same sources and libs in both sln and Makefile.
What is the easy way how to find out where the AVX comes from? Project includes dozens of h/cpp files, around 40 own libs, 10 windows libs. How would you proceed?
The simple way, find an old PC without AVX, run your app in debugger, it’ll crash with invalid instruction runtime error and will trap to debugger. This way you’ll immediately find out what code compiled into that instruction.
Another, harder way, write a C# console app that disassembles the compiled DLL or EXE, and searches for AVX instruction. You’ll need Gee.External.Capstone nuget package for disassembling, PeNet package for parsing into sections. Also this code to disassemble. The disassembleStreamEx method will return you the stream of the instructions. Search for X86InstructionGroup.AVX or X86InstructionGroup.AVX2 instructions, print addresses, then use e.g. WinDBG + PDB file to translate addresses into source code location.
Update: before doing that, search your codebase for files containing _mm256_, and *.asm files. If you’re lucky you won’t have to do anything else.
LLVM debugger (lldb) uses a source file for debugging (e.g. for breakpoint). I want to use lldb without having source files, only with intermediate representation files (.ll files).
Is it possible? If not, can I do that with gdb debugger? Is there another idea?
I'm not sure you can debug using the IR, but in the worst case, you can always just debug the bare assembly without symbols of any kind. Having at least function labels is nice, though.
I have much trouble compiling OpenCV 245 with GPU support. With some effort I managed to have cuda support up and running, but now I am stuck on opencl, here is the problem:
At some point during the compilation, the file kernels.cpp is generated, containing all kernel functions as strings. For what I understand, they are converted automatically from the .cl files with the cl2cpp.cmake script.
What I don't understand is that one file is excluded from the build: nonfree_surf.cl (which is on my disk, alongside all other .cl files) is not included, either in the visual studio project, or in the kernels.cpp that is automatically generated. This leads to an undefined error at link time.
I have tried manually adding the nonfree_surf.cl to the visual studio project. This does not change anything. In the CMakeLists.txt for ocl module, all the cl files seem to be automatically added with the line:
file(GLOB CL_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/kernels/*.cl")
I have tried manually adding nonfree_surf to CL_FILES, with no effect.
I have very little knowledge of CMake, hence I don't understand well what is going on. Can somebody give me a clue how I could find the reason of this behavior, namely:
Why are all .cl files added to my VS project, except nonfree_surf.cl ?
How can I correct this ?
Maybe I can execute cl2cpp.cmake script manually ? If so, how ?
Managed it by manually running the script:
cmake -DOUTPUT_PATH=c:/opencv/kernels2.cpp -DCL_DIR:PATH=c:/opencv/modules/ocl/src/kernels -P "c:\opencv\modules\ocl\cl2cpp.cmake"
For some reason (probably the same that makes nonfree_surf not be processed), not every necessary function are processed this way, so I juste copy-pasted the nonfree_surf string into kernels.cpp, and proceeded with the build.
If anyone needs the binaries, since they are a pain to compile, here they are:
Opencv 2.4.5 binaries compiled with VS2010 x86 (WIN32) including ocl and gpu library.
i have created a debuggable fortran executable (let's call it 'myfortranprogram') and I am able to debug, set breakpoints, etc. by passing it through the gdb debugger:
cd sourcedir/
gdb myfortranprogram
#start debugging
Suppose the source files are in the same source directory 'sourcedir', if that makes a difference at all.
So compiling with the terminal becomes a little bit slow for very large projects and I would prefer to debug using the XCode interface. Since myfortranprogram is already a debuggable executable, what are the steps i have to take to get it debugged in XCode? It is my understanding that XCode is able to debug using gdb.
Thanks!
Ah, found the answer:
http://forums.macrumors.com/archive/index.php/t-807021.html
it's simple, just create an empty project in xcode, point a new custom executable to the path of the compiled application, and do 'run myexecutablename'