How to compile ruby in debug mode? - ruby

There are plenty of ruby debug log calls in the source code that help me better understand internals.
How do you debug ruby vm? Do you have a documentation for that?
I haven't found any information in the GitHub documentation. What I tried but didn't get any result are:
Compile ruby in kind of debug mode:
./autogen.sh
mkdir build && cd build # it's good practice to build outside of source dir
mkdir ~/.rubies # we will install to .rubies/ruby-master in our home dir
../configure cppflags='-DUSE_RUBY_DEBUG_LOG=1 -DRUBY_DEBUG' --prefix="${HOME}/.rubies/ruby-master"
make install
Tried to run ruby with -d flag
export RUBY_DEBUG_LOG='/home/root/ruby.log'
export USE_RUBY_DEBUG_LOG=1
export DEBUG=1
bin/ruby -d ~/test.rb

Related

Building Linux perf from source: how to modify the install directory?

I am following this wiki page to build perf from source as below:
PYTHON=python3 make -C tools/perf install
where ~/bin will be the default build directory.
How can I change the build directory to let's say ~/bin/test? I already have another perf build in ~/bin, and I want to have the new build in a different directory.
I have tried to modify the Makefile (if that is how to do it), but I could not figure it out.
One last silly question: Can I just move my current perf build to another directory or it will screw up its links?
You should be able to easily install into a different directory by specifying prefix=... or DESTDIR=... when running make. You will see this and other info if you run make -C tools/perf help:
$ make -C tools/perf help
...
Perf install targets:
NOTE: documentation build requires asciidoc, xmlto packages to be installed
HINT: use "prefix" or "DESTDIR" to install to a particular
path like "make prefix=/usr/local install install-doc"
install - install compiled binaries
...
Make sure to pass an absolute path to avoid problems (you can use realpath for that):
PYTHON=python3 make -C tools/perf prefix=$(realpath ~/bin/test) install

Cannot compile Redis 6.2.6 when tests passed

I could not install redis-cli version 6 with apt install redis-tools, only version 5.0.7 was installed:
$ redis-cli -v
redis-cli 5.0.7
So I decide compile it from source code using redis documentation. After missing libs (tcl and pkg-config) I still cannot compile it. My tests pass without any problem:
$ make test
...
...
...
\o/ All tests passed without errors!
It looks like it should be OK, but make command cannot compile it and ask me to run tests again:
$ make
cd src && make all
make[1]: Entering directory '/home/dorinand/Downloads/redis-6.2.6/src'
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory '/home/dorinand/Downloads/redis-6.2.6/src'
Can anybody help me to compile it and explain, why tests passed even it cannot be compiled?
I am using Ubuntu 20.04.3 LTS.

Getting cmake to work under Cygwin on Windows 7

I installed the latest Cygwin on my Windows 7 machine: version 2.893 (64-bits). I made sure I included cmake, i.e. I was able to add several packages by running the Cygwin net release setup program again, after doing the first installation. I then tried to use cmake and made sure I invoked it from the bin directory:
user008#L0147816 /bin
$ ./cmake
CMake Error: Could not find CMAKE_ROOT !!!
CMake has most likely not been installed correctly.
Modules directory not found in
//share/cmake-3.6.2
Usage
cmake [options] <path-to-source>
cmake [options] <path-to-existing-build>
Specify a source directory to (re-)generate a build system for it in the
current working directory. Specify an existing build directory to
re-generate its build system.
Run 'cmake --help' for more information.
I don't know where the build directory could be. I'm relatively new to Cygwin. I hope somebody has found a solution for getting cmake installed and working properly under Cygwin.
This looks cmake 101.
Assuming you want to just build a software download from somewhere
eg gl2ps:
# choosing a test area
$ cd /tmp
# downloading source
$ wget http://geuz.org/gl2ps/src/gl2ps-1.4.0.tgz
# expanding source code
$ tar -xf gl2ps-1.4.0.tgz
$ ls gl2ps-1.4.0-source/
CMakeLists.txt COPYING.LGPL gl2ps.h gl2ps.tex gl2psTestSimple.c
COPYING.GL2PS gl2ps.c gl2ps.pdf gl2psTest.c README.txt
# preparing a build area
$ mkdir build
$ cd build
# invoking cmake and pointing to the source directory
$ cmake ../gl2ps-1.4.0-source/
-- The C compiler identification is GNU 7.3.0
[cut ...]
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/build
# running the build
$ make
Scanning dependencies of target shared
[ 11%] Building C object CMakeFiles/shared.dir/gl2ps.o
...
[ 88%] Building C object CMakeFiles/gl2psTestSimple.dir/gl2psTestSimple.o
[100%] Linking C executable gl2psTestSimple.exe
[100%] Built target gl2psTestSimple
Instead for learning how to build with cmake, go to
https://cmake.org/cmake-tutorial/
Here a solution I just found.
Let's name 3 directories:
{cygwin64-path}/bin/: cmake.exe is here.
{cygwin64-path}/usr/share/: cmake module directory (such as cmake-3.20.0) is here.
{cygwin64-path}/share/: cmake.exe trying to find cmake-module-directory here, but it doesn't exist.
It's wired because cygwin install cmake-module-directory in {cygwin64-path}/usr/share/, but cmake.exe looks for the directory in {cygwin64-path}/share/.
So solution is simple. Each one below works.
METHOD 1: Create the directory {cygwin64-path}/share/ and copy all relevant directories and files from {cygwin64-path}/usr/share/ to the new directory.
METHOD 2: Create a Symbolic links {cygwin64-path}/share/ to {cygwin64-path}/usr/share/.
In windows 10 Administrator cmd.exe: mklink /J share usr\share and all works.
Or use WSL or Cygwin64 Terminal: ln -s usr/share share

Make shell does not inherit console shell environment variables

I am working on a Makefile to build an application where frontend and backend are completely separated in two different directories, like:
- myapp
|_be
|_fe
This is my Makefile:
.ONESHELL:
all: frontend backend
frontend:
cd ./fe && \
npm install && \
./node_modules/webpack/bin/webpack.js
backend: clean
cd ./be && \
gem install bundler && \
bundle install
clean:
rm -f ./fe/public/bundle.js && rm -rf ./fe/public/resources
webpack:
cd ./fe && \
.node_modules/webpack/bin/webpack.js
test:
cd ./fe && \
npm test
run:
cd ./be && \
rackup config.ru
The frontend is a React application and it is being built correctly when I type make frontend. No issues here.
But the backend is a Rack application written in Ruby. During the build process I need to enter its directory (be), make sure bundler is installed and run bundle install.
It happens that make creates its own shell to run the Makefile commands. And this shell does NOT inherit the environment variables of the console shell I am working. This turns out to be a problem to me, because I use rvm and rvm uses some environment variables to pick the correct gems. I use the .ruby-gemset and .ruby-version to create a private bundle to my application, not using the default gemset. This is necessary, because I have applications using many different Ruby versions and don't want to care about this.
This particular application uses JRuby 9.1.7.0 and then my Gemfile (inside be directory) has the following line:
ruby '2.3.1', :engine => 'jruby', :engine_version => '9.1.7.0'
I noticed all this issue because I got the following error when I typed make backend:
Your Ruby engine is ruby, but your Gemfile specified jruby
As far as I know rvm (and I know it quite well), this means it is trying to use my default Ruby version (which is set to Ruby 2.5.0) as engine, instead of the correct JRuby version.
Now, here is my question: Is there a way to force the make inner shell to use the same configuration of the console shell I am using?
This would solve the issue, because the console shell is already configured by rvm. I know it is because when I enter the be directory manually and run bundle install inside it, everything goes fine.
I used the .ONESHELL directive to force make to do this, but it seems it is not what I need.
Suggestions?
EDIT: make documentation says the -e flag may be used to force the make grab all console shell variables. I tried it and it didn't work.
EDIT: It all works if I do
rvm use --default jruby-9.1.7.0
before doing my make backend. But for many reasons it is not convenient to do this. Besides, I really believe this is a better way to do this. make is too smart not to allow something as simple as this.
I believe there are 2 problems:
1) when rvm creates its environment variables, it does not export them, so they are not visible to child shells, and
2) because the child shell is not started as a login shell, it does not see and process the rvm function declarations, and can therefore not execute rvm my-ruby-version.
Here are a couple of workarounds:
Before creating the child shell, do something like this:
export RVM_VERSION=`rvm current`
When starting the child shell, do so in login mode:
zsh --login
or
bash --login
Then, rvm should be a function, and this should work:
rvm $RVM_VERSION
First I added two lines to my backend: recipe, which now was reading
backend:
cd ./be && \
source $(HOME)/.rvm/scripts/rvm && \
rvm use jruby-9.1.7.0 && \
gem install bundler && \
bundle install
The idea was setting the correct Ruby (JRuby 9.1.7.0) without having to change it permanently at the console.
It happened this wouldn't work, because I wasn't choosing the shell I was using and it seems for some reason it wasn't /bin/bash and source wouldn't work. As a sequel, rvm wouldn't work either and I would receive that irritating message saying
rvm is not a function
Then I added
SHELL = /bin/bash
right after the .ONESHELL: directive.
And now everything worked fine!

how to use and install SystemC in terminal mac OS X?

how to use and install SystemC in terminal mac OS X?
I tried the Logic poet application, But i use os x 10.10 so it doesn't work.
so i want to know how can i compile and execute SystemC in terminal.
I could't find the detail of SystemC in terminal.
Thank you
The other answer is correct and perfectly fine, however, I thought I'd also answer and provide a little more detail.
Install Apple's "Command Line Tools"
You have two options: install Xcode (a big download), or just the command line tools (a much smaller download). If your goal is simply building SystemC applications at the command line, then I recommend the latter.
Install Apple's "Command Line Tools" by launching Terminal, entering
$ xcode-select --install
then clicking Install. After that, you'll have make, clang and more available at the command line.
Build and install Accellera's SystemC implementation
Download the latest release from the Accellera Downloads page (annoyingly, you'll have to provide a few personal details) and extract the contents of the .zip file.
I like to keep a copy of the SystemC source code available, because it can be useful for debugging or understanding how something works. Therefore, I move the extracted folder (systemc-2.3.1) into ~/Work/Other. That's where I keep source code for third party libraries. However, you can put it wherever you like.
Open Terminal, change into the extracted folder (systemc-2.3.1), and execute:
$ mkdir build
$ cd build
$ export CXX=clang++
$ ../configure --with-arch-suffix=
$ make install
The --with-arch-suffix= option prevents a -macosx64 suffix being add to the lib folder name, allowing your build scripts to be simpler.
After that process, the salient include and lib folders should be available within the systemc-2.3.1 folder.
Configure your build environment
There are many ways you can do this; I have a simple approach that I believe is close to what the SystemC maintainers envisioned. I define two environment variables in my .bash_profile (which is executed for every new Terminal session on OS X):
export CXX="clang++ -fcolor-diagnostics"
export SYSTEMC_HOME=~/Work/Other/systemc-2.3.1
Build a SystemC application
You could use Make, the quintessential build tool, which you get with Apple's "Command Line Tools", or any one of the plethora of other options. I use SCons with SConstruct files that look something like this:
import os
env = Environment(CXX=os.environ["CXX"],
SYSTEMC_HOME=os.environ["SYSTEMC_HOME"],
CPPPATH="$SYSTEMC_HOME/include",
LIBPATH="$SYSTEMC_HOME/lib")
env.Program("main.cpp", LIBS="systemc")
View trace (VCD) files
Scansion is a nice tool for this. GTKWave is another option, but it's a bit clunky.
Ensure you have xcode command line tools installed.
Follow instructions provided in the official repository.
From personal experience.
Compiling SystemC library with clang results in segmentation fault: 11
error every time I include systemc library into my code. To avoid this use gcc instead.
Note that I use gcc-8, installed with homebrew.
$ cd path/to/systemc-2.3.3
$ mkdir objdir
$ cd objdir
$ export CXX=g++-8
$ ../configure
$ make
$ make install
Use $ make check to launch examples compilation and unit tests.
To compile and run hello world example:
$ export SYSTEMC_HOME=path/to/systemc-2.3.3
$ g++-8 hello.cpp -o hello.o -L $SYSTEMC_HOME/lib-macosx64 -I $SYSTEMC_HOME/include/ -l systemc
$ ./hello.o
Tested on macOS 10.13.6; gcc version 8.2.0; systemc-2.3.3
Install
Go here click the first link and fill in your information to get the source code
http://www.accellera.org/downloads/standards/systemc
Then cd to the folder
Then run the following commands
./configure --with-unix-layout
gmake
sudo gmake install
gmake clean
After you do that it should all be saved in your use/local/(lib&include) directories
To Use
In code do this
#include "systemc.h"
I use a single makefile normally. But you could write the following to link the library. Given your cpp file is called main.
g++ -o main main.cpp -I/usr/local/include -L/usr/local/lib -lsystemc

Resources