(C++ Builder) DWARF debug info in separate file? - c++builder

Is there a way to instruct C++ Builder's linker to output DWARF debug information (64-bit C++ apps) in standalone file rather than inject it directly into executable? I.e. the option similar to "Place debug information in separate TDS file" (which does not work for DWARF debug format).
If there is no such option - is there a way to strip info from already compiled executable?

To place debug info in separate file follow below steps
// Build
$ clang -O2 -g -o hello.full hello.c
// Package hello.stripped is run as "hello" in production environment
$ strip -o hello.stripped hello.full
// Extract debug info to separate file
$ objcopy --only-keep-debug hello.full hello.debug
// Create a section which contains a reference to debug file
$ objcopy --strip-debug --add-gnu-debuglink=hello.debug hello.full hello
// Debug - GDB automatically reads hello.debug
$ gdb hello
. . .
Reading symbols from ./hello...
Reading symbols from /homes/syrajendra/hello.debug...done.
(gdb)
// Core from hello.stripped
$ gdb --core core-file --exec hello

Assuming you are on a platform with GNU Binutils you can use objcopy to extract the DWARF information to a separate file as a post-compilation step. If you like you can then use strip to remove the debugging information from the executable binary.

Related

LLVM - Run concrete pass with clang [duplicate]

I am working on LLVM obfuscation project. I have written a llvm pass(lets say flow flattening pass) which i am running on source (test.c) with following command:
clang -emit-llvm test.c -c -o test.bc
opt -load ../../.. LLVMFlattening.so -fla <test.bc>/dev/null
But i have seen that in O-LLVM project they achieved same thing using:
clang -emit-llvm test.c -c -o test.bc -mllvm -fla
Can someone tell me what is -mllvm here and how this changed to a simple command?
-mllvm means Additional arguments to forward to LLVM's option processing. Therefore -mllvm -fla will pass -fla to the LLVM's option processing.
Clang and LLVM could run seperately. If you want clang to run llvm, and also have some options which you want llvm to aware. -mllvm is what you need.
Defautly, LLVM does not turn on all the transformation passes. With -fla, LLVM will turn on the pass registered with command line argument fla by call function RegisterPass<typename passName>.
In your command line, opt's -load option is used to load plugin. If you want to use the simple command line as expect. Your pass need to be linked into the opt binary. This could be done in the following two ways:
(Without modify the existing LLVM source tree): Add your only pass's source by adding CMakeLists.txt mentioned in this link
Directly copy your pass source code folder into <LLVM root>/lib/Transform directory. And modify the <LLVM root>/lib/Transform/CMakeLists.txt, add add_subdirectory(<pass name>) line just like others.
I'm working on O-LLVM rencently, and came into the same problem. Here is my solution:
1.add static cl::opt<bool> YOUR_FLA("fla", cl::init(false),"info...") to PassManagerBuilder.cpp
2.add function Pass *createYOUR_FLA(bool flag) in your obfuscation pass source code
3.add MPM.add(createYOUR_FLA(YOUR_FLA)); to function populateModulePassManager in PassManagerBuilder.cpp
The solution above works with my simple pass.

How to get exploded graph from clang analyzer

I am trying to get exploded graph from one of the debug checkers called
debug.ViewExplodedGraph.
So I run command
clang -cc1 -analyze -analyzer-checker=debug.ViewExplodedGraph someprogram.c
It run successfully, but graph file no where to be found .
Where can we see the generated file?
I guess you should build the clang yourself. Then use the debug mode 'clang', call the command. The system clang is in release mode.
I use the system clang, it outputs nothing. But I use the clang that I build, it output something.
➜ bin ./clang -cc1 -analyze -analyzer-checker=debug.ViewExplodedGraph ~/Desktop/clang_test/test.c
Writing '/var/folders/_6/5wkxc9p92t94vdh0kyq2qyh40000gn/T/ExprEngine-9e6797.dot'... done.
Trying 'open' program... Remember to erase graph file: /var/folders/_6/5wkxc9p92t94vdh0kyq2qyh40000gn/T/ExprEngine-9e6797.dot
Warning: viewing graph requires assertions
➜ bin clang -cc1 -analyze -analyzer-checker=debug.ViewExplodedGraph ~/Desktop/clang_test/test.c
Warning: viewing graph requires assertions
cd to T folder
➜ T dot -Tsvg ExprEngine-9e6797.dot -o ~/Desktop/test.svg
then use chrome open test.svg

Dyldinfo commamd not found

mac os 10.13.4
I write the command 'dyldinfo' in shell, but is wroing
-bash: dyldinfo: command not found
hope you help me
On recent versions of macOS you can run the tool with xcrun dyldinfo (as long as you have Xcode installed)
First, make sure you have either Xcode or Command Line Tools installed.
If you have one of those, you can find dyldinfo in /Library/Developer/CommandLineTools/usr/bin.
So, to run it, type this into your bash:
/Library/Developer/CommandLineTools/usr/bin/dyldinfo
You can check the dyldinfo path using following command:
$ xcrun --sdk dyldinfo
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dyldinfo
Showing that the command dyldinfo is under the path:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dyldinfo, which means commands like dyldinfo belong to Toolchains of Xcode. Therefore, 'dyldinfo' cannot be used as a separate shell command. Instead, you must invoke it by using xcrun <sdk>.
$ xcrun dyldinfo
Usage: dyldinfo [-arch <arch>] <options> <mach-o file>
-dylibs print dependent dylibs
-dr print dependent dylibs and show any recorded DR info
-rebase print addresses dyld will adjust if file not loaded at preferred address
-bind print addresses dyld will set based on symbolic lookups
-weak_bind print symbols which dyld must coalesce
-lazy_bind print addresses dyld will lazily set on first use
-export print addresses of all symbols this file exports
-opcodes print opcodes used to generate the rebase and binding information
-function_starts print table of function start addresses
-export_dot print a GraphViz .dot file of the exported symbols trie
-data_in_code print any data-in-code information

Get Lua running with Torch on Windows 10 (with limited admin rights)

Setting up Deep Learning Framework [Lua, Torch]:
I need to set up Lua running with Torch
on Windows 10 and the ZeroBrane IDE, with limited possibilities of installing Software and restricted download rights.
It took me so Long, so I thought I might share a recipe for you guys. I would be glad if it helped you.
SETTING UP
(Admin) Download/Install tdm64/gcc/5.1.0-2.exe Compiler
(Admin) Download/Install ZeroBrane (Lua IDE)
Download lua/5.3.4.tar.gz (https://www.lua.org/download.html)
Write batch file build.cmd
#echo off
setlocal
:: you may change the following variable's value
:: to suit the downloaded version
set lua_version=5.3.4
set work_dir=%~dp0
:: Removes trailing backslash
:: to enhance readability in the following steps
set work_dir=%work_dir:~0,-1%
set lua_install_dir=%work_dir%\lua
set compiler_bin_dir=%work_dir%\tdm-gcc\bin
set lua_build_dir=%work_dir%\lua-%lua_version%
set path=%compiler_bin_dir%;%path%
cd /D %lua_build_dir%
mingw32-make PLAT=mingw
echo.
echo **** COMPILATION TERMINATED ****
echo.
echo **** BUILDING BINARY DISTRIBUTION ****
echo.
:: create a clean "binary" installation
mkdir %lua_install_dir%
mkdir %lua_install_dir%\doc
mkdir %lua_install_dir%\bin
mkdir %lua_install_dir%\include
copy %lua_build_dir%\doc\*.* %lua_install_dir%\doc\*.*
copy %lua_build_dir%\src\*.exe %lua_install_dir%\bin\*.*
copy %lua_build_dir%\src\*.dll %lua_install_dir%\bin\*.*
copy %lua_build_dir%\src\luaconf.h %lua_install_dir%\include\*.*
copy %lua_build_dir%\src\lua.h %lua_install_dir%\include\*.*
copy %lua_build_dir%\src\lualib.h %lua_install_dir%\include\*.*
copy %lua_build_dir%\src\lauxlib.h %lua_install_dir%\include\*.*
copy %lua_build_dir%\src\lua.hpp %lua_install_dir%\include\*.*
echo.
echo **** BINARY DISTRIBUTION BUILT ****
echo.
%lua_install_dir%\bin\lua.exe -e"print [[Hello!]];print[[Simple Lua test successful!!!]]"
echo.
pause
SETTING UP TORCH UNDER LUA ON WINDOWS
--- Quick and dirty ---
Download and unzip the desired binary build from: https://github.com/hiili/WindowsTorch
Generate user.lua file in C:\Users\Name.zbstudio:
path.lua = [[C:\app\tools\torch\bin\luajit.exe]]
Move the C:\app\tools\torch\lua folder to C:\app\tools\torch\bin
--- Untested alternatives ---
Not tested, but I encourage you: https://github.com/torch/torch7/wiki/Windows#cmder
Maybe second best option is to build a virtual environment with linux
Note: More information on Torch can be found here
https://github.com/soumith/cvpr2015/blob/master/cvpr-torch.pdf
GET STARTED WITH LUA AND TORCH
http://torch.ch/docs/tutorials.html
I recommend Torch Video Tutorials to get the basics straight (https://github.com/Atcold/torch-Video-Tutorials)
This is a Torch Cheetsheet for further reading (https://github.com/torch/torch7/wiki/Cheatsheet):
- Newbies
- Installing and Running Torch
- Installing Packages
- Tutorials, Demos by Category
- Loading popular datasets
- List of Packages by Category

How do you set CMAKE_C_COMPILER and CMAKE_CXX_COMPILER for building Assimp for iOS?

When I try to build Assimp by running build_ios.sh, it tells me:
CMake Error: your C compiler: "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-g++" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
What I need the path to be is:
/Applications/XCode.app/Contents/Developer/Platforms/...
I've tried changing DEVROOT in build_ios.sh and IPHONE_xxxx_TOOLCHAIN.cmake, because that's what CMAKE_C_COMPILER etc seem to get generated from, but it still gives me the same errors.
Option 1:
You can set CMake variables at command line like this:
cmake -D CMAKE_C_COMPILER="/path/to/your/c/compiler/executable" -D CMAKE_CXX_COMPILER "/path/to/your/cpp/compiler/executable" /path/to/directory/containing/CMakeLists.txt
See this to learn how to create a CMake cache entry.
Option 2:
In your shell script build_ios.sh you can set environment variables CC and CXX to point to your C and C++ compiler executable respectively, example:
export CC=/path/to/your/c/compiler/executable
export CXX=/path/to/your/cpp/compiler/executable
cmake /path/to/directory/containing/CMakeLists.txt
Option 3:
Edit the CMakeLists.txt file of "Assimp": Add these lines at the top (must be added before you use project() or enable_language() command)
set(CMAKE_C_COMPILER "/path/to/your/c/compiler/executable")
set(CMAKE_CXX_COMPILER "/path/to/your/cpp/compiler/executable")
See this to learn how to use set command in CMake. Also this is a useful resource for understanding use of some of the common CMake variables.
Here is the relevant entry from the official FAQ: https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-do-i-use-a-different-compiler
The cc and cxx is located inside /Applications/Xcode.app. This should find the right paths
export CXX=`xcrun -find c++`
export CC=`xcrun -find cc`
SOLUTIONS
Sometimes the project is created before installing g++. So install g++ first and then recreate your project. This worked for me.
Paste the following line in CMakeCache.txt:
CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++
Note the path to g++ depends on OS. I have used my fedora path obtained using which g++

Resources