qemu quits when pressing ctrl-c in gdb - gdb

Debugging my own kernel with qemu and gdb seems to be unnecessarily hard because pressing ctrl-c in gdb to break qemu does not break it, but makes it quit with the message
qemu-system-x86_64: terminating on signal 2
[Inferior 1 (Remote target) exited normally]
qemu command line:
qemu-system-x86_64 -s -no-shutdown -no-reboot -enable-kvm -m 1G -smp cores=1 -cpu qemu64 -drive if=pflash,format=raw,file=ovmf/OVMF.fd -drive file=fat:rw:hda,format=raw -net none -debugcon file:debug.log -global isa-debugcon.iobase=0x402 &
The behavior is the same without KVM. Could someone please help, how to solve this?
qemu-system-x86_64 v3.1.0
gdb v8.2.1
I would like not to build the latest versions of these from source as it seems to be a daunting task to do.
EDIT: Created a minimal environment where the issue can be reproduced. I may have tracked it down to running the whole thing from a shell script, but can't seem to progress further. Commenting out the gdb call in the script and starting it from a separate terminal, solves the issue (however i like things that work with as few keystrokes as possible).
You can download it here.
Just start the script called qd
(Is there a nicer way to provide files? I will delete this after a while.)

I tested with QEMU 5.0.0 and GDB 9.2, same issue, and same solution, that is commenting out the GDB call in the script and starting it from a separate terminal. You could probably just modify your script so that QEMU would be started in another
terminal. Starting QEMU using nohup is not working either.
I included the script I am usually using for building fresh versions of QEMU and GDB: latest versions are likely to have fixed bugs. The script is working on Ubuntu 20.04, and is probably still working on 16.04 and 18.04 - you may have to make small adjustments at the beginning of the script. Feel free to report issues, I would be willing to fix them.
build-qemu-gdb.sh:
#!/bin/bash
set -e
# Xenial/16.04
PERL_MODULES_VERSION=5.22
SPHINX=python-sphinx
# Bionic/18.04
PERL_MODULES_VERSION=5.26
SPHINX=python-sphinx
# Focal/20.04
PERL_MODULES_VERSION=5.30
SPHINX="sphinx-doc sphinx-common"
# Qemu
QEMU_VERSION=5.0.0
PREFIX=/opt/qemu-${QEMU_VERSION}
# GDB
GDB_VERSION=9.2
do_get_gdb()
{
if [ -f gdb-${GDB_VERSION}.tar.xz ]
then
echo "gdb-${GDB_VERSION}.tar.xz is present."
else
wget http://ftp.gnu.org/gnu/gdb/gdb-${GDB_VERSION}.tar.xz
fi
}
do_get_qemu()
{
if [ -f qemu-${QEMU_VERSION}.tar.xz ]
then
echo "qemu-${QEMU_VERSION}.tar.xz is present."
else
wget https://download.qemu.org/qemu-${QEMU_VERSION}.tar.xz
fi
}
do_install_prerequisites()
{
sudo apt-get install libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev libaio-dev libbluetooth-dev libbrlapi-dev libbz2-dev libcap-dev libcap-ng-dev libcurl4-gnutls-dev libgtk-3-dev libibverbs-dev \
libjpeg8-dev libncurses5-dev libnuma-dev librbd-dev librdmacm-dev libsasl2-dev libsdl2-dev libseccomp-dev libsnappy-dev libssh2-1-dev libvde-dev libvdeplug-dev libvte-2.91-dev libxen-dev liblzo2-dev \
valgrind xfslibs-dev liblzma-dev flex bison texinfo gettext perl perl-modules-${PERL_MODULES_VERSION} ${SPHINX}
}
do_configure()
{
local TARGET_LIST="x86_64-softmmu"
pushd qemu-${QEMU_VERSION}
./configure --target-list="${TARGET_LIST}" --prefix=${PREFIX} --extra-cflags="-I$(pwd)/packages/include" --extra-ldflags="-L$(pwd)/packages/lib"
popd
}
do_extract_qemu()
{
echo "extracting QEMU..."
rm -rf qemu-${QEMU_VERSION}
tar Jxf qemu-${QEMU_VERSION}.tar.xz
}
do_build_qemu()
{
echo "building..."
pushd qemu-${QEMU_VERSION}
make all
popd
}
do_install_qemu()
{
echo "installing..."
pushd qemu-${QEMU_VERSION}
sudo make install
popd
}
do_build_qemu()
{
do_extract_qemu
do_configure
do_build_qemu
do_install_qemu
}
do_extract_gdb()
{
echo "extracting GDB..."
rm -rf gdb-${GDB_VERSION}
tar Jxf gdb-${GDB_VERSION}.tar.xz
}
do_build_gdb()
{
do_extract_gdb
rm -rf gdb
mkdir gdb
pushd gdb
../gdb-${GDB_VERSION}/configure --enable-tui --prefix=/opt/gdb-${GDB_VERSION}-x86_64-none-elf --target=x86_64-none-elf --program-prefix=x86_64-none-elf-
make all install
popd
}
# main
do_install_prerequisites
do_get_qemu
do_build_qemu
do_get_gdb
do_build_gdb
The resulting new paths for QEMU and GDB after installation would be:
/opt/qemu-5.0.0/bin/qemu-system-x86_64
/opt/gdb-9.2-x86_64-none-elf/bin/x86_64-none-elf-gdb

Related

Create PDF reports using R Markdown (TinyTeX) in Snakemake using Conda

I am currently having problems using TinyTeX in a conda environment with Snakemake. I have to install TinyTeX installation files using the command tinytex::install_tinytex() before running the pipeline. This installs TinyTeX outside of the created environment (which isn't that big of a problem... but not preferred either) . The main problem is that every time I execute my Snakemake pipeline it will try to reinstall this installation which I don't want. Could anyone tell me what the easiest way is for me to check whether it's installed already? Should I be using the command Rscript -e \"tinytex:::is_tinytex()\" with an if-statement? And what is the best way to write that if-statement by calling Rscript -e in Snakemake? Or should I just write a boolean text-file on first run which specifies whether TinyTeX has been installed before?
It kinda sucks that the TinyTeX conda dependency doesn't work on its own without additional installation...
Snakemake rule (ignore input/output):
rule assembly_report_rmarkdown:
input:
rules.assembly_graph2image_bandage.output,
rules.assembly_assessment_quast.output,
rules.coverage_calculator_shortreads.output,
rules.coverage_calculator_longreads.output
output:
config["outdir"] + "Hybrid_assembly_report.pdf"
conda:
"envs/r-rmarkdown.yaml"
shell:
"""
cp report/RMarkdown/Hybrid_assembly_report.Rmd {config[outdir]}Hybrid_assembly_report.Rmd
Rscript -e \"tinytex::install_tinytex()\"
Rscript -e \"rmarkdown::render('{config[outdir]}Hybrid_assembly_report.Rmd')\"
rm -f {config[outdir]}Hybrid_assembly_report.Rmd {config[outdir]}Hybrid_assembly_report.tex
"""
Conda YAML:
name: r-rmarkdown
channels:
- conda-forge
- bioconda
dependencies:
- r-base=4.0.3
- r-rmarkdown=2.5
- r-tinytex=0.27
Thanks in advance.
I think I've solved the issue. Instead of calling Rscript -e, I have put the following if-statement in the setup chunk in R Markdown (Which runs before running any other code if i'm correct). I then proceeded to uninstall TinyTeX to see whether it will install for once only which it did.
knitr::opts_chunk$set(echo = TRUE)
library(knitr)
if (!tinytex:::is_tinytex()){
tinytex::install_tinytex()
}

Fixing gcc undefined include<> by manually installing library

I am running the golang command "go get -t github.com/otiai10/gosseract" , causing the error tessbridge.cpp:5:10: fatal error: leptonica/allheaders.h: No such file or directory, #include <leptonica/allheaders.h>. That library is https://github.com/DanBloomberg/leptonica. How do I install it from source so that the gcc command will work.
Before that command was producing the error "gcc not found", but then I followed https://superuser.com/questions/1294343/install-gcc-in-git-for-windows-bash-environment to setup gcc on windows.
I have not been able to find any references for what gcc expects when it encounters an include<>, and where those files should be located on the file system for it to link properly. Is it possible to install this library manually?
Here is much simpler solution for you. There was no need to install gcc on git-bash.
Install MSYS2. Follow complete installation guide.
On MSYS2 console enter the following commands :
pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-x86_64-leptonica
Add C:\msys64\mingw64\bin to PATH.
First step can be further simplified if you use Chocolatey. Just run these commands in elevated powershell : (Ignore first command if choco is already installed.)
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Reopen elevated powershell and run these:
choco install -y msys2 --params="/InstallDir:C:\msys64"
refreshenv
$env:Path += ";C:\msys64\usr\bin"
pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-x86_64-leptonica
[Environment]::SetEnvironmentVariable("Path", "C:\msys64\mingw64\bin;" + $env:Path, "User")

How to Install compiler g++-4.8.5 in ubuntu 20.04

As the title said I can't install that specific version of g++ in my current ubuntu (20.04).
I have been trying the usual things as: sudo apt install g++- (and displaying all posibilities but there where only versions from 8 to 10). Same happend looking for gcc possibilities.
Also tried this: gist.github.com/application2000/73fd6f4bf1be6600a2cf9f56315a2d91 (same problem)
And after looking for a while I gave up in my research and ended up here. Hope someone with more wisdom than me can give my a hand with this.
These steps should work:
sudo dpkg --add-architecture i386
sudo apt update
sudo apt upgrade
sudo apt-get install gcc-multilib libstdc++6:i386
wget https://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.bz2 --no-check-certificate
tar xf gcc-4.8.5.tar.bz2
# cd gcc-4.8.5
# ./contrib/download_prerequisites
# cd ..
sed -i -e 's/__attribute__/\/\/__attribute__/g' gcc-4.8.5/gcc/cp/cfns.h
sed -i 's/struct ucontext/ucontext_t/g' gcc-4.8.5/libgcc/config/i386/linux-unwind.h
mkdir xgcc-4.8.5
pushd xgcc-4.8.5
$PWD/../gcc-4.8.5/configure --enable-languages=c,c++ --prefix=/usr --enable-shared --enable-plugin --program-suffix=-4.8.5
make MAKEINFO="makeinfo --force" -j
sudo make install -j
Note that you have to uncomment the .../download_prerequisites on some platform. For me it worked without on Centos 7 or Ubuntu 20 with the mandatory packages installed:
Ubuntu/Debian:
sudo apt install make wget git gcc g++ lhasa libgmp-dev libmpfr-dev libmpc-dev flex bison gettext texinfo ncurses-dev autoconf rsync
Centos:
sudo yum install wget gcc gcc-c++ python git perl-Pod-Simple gperf patch autoconf automake make makedepend bison flex ncurses-devel gmp-devel mpfr-devel libmpc-devel gettext-devel texinfo
Few seconds later (/giggles) gcc-4.8.5 is installed and available.
Notes:
if you don't have the resources to run make -j omit -j or use -j4 (or a different number which is adequate for your system)
your milage may vary and you may need to install further i386 packages
Since I can't comment I will add to #bebbo solution that on an Ubuntu 20.04 I had to add to his steps patching the following patches:
Add an include to signal.h to libsanitizer/asan/asan_linux.cc
https://patchwork.ozlabs.org/project/gcc/patch/6824253.3U2boEivI2#devpool21/
change a line in libsanitizer/tsan/tsan_platform_linux.cc
as shown. line number may not be the one stated in the patch so search for the line that was changed. There is no need to apply the patch to the other files
https://git.pantherx.org/mirror/guix/commit/0b93d04ac537d6413999349ebe7cdcb1e961700e
Adding to kpeace's answer...
sed -i '/#include <pthread.h>/a #include <signal.h>' path_to_gcc4.8.5src/libsanitizer/asan/asan_linux.cc
sed -i 's/__res_state \\*statp = (__res_state\\*)state\\;/struct __res_state \\*statp = (struct __res_state\\*)state\\;/g' path_to_gcc4.8.5src/libsanitizer/tsan/tsan_platform_linux.cc
Just adding a couple of sed lines to patch them inline.
Also, I've been writing some Ruby scripts to install some software (for fun of course.) I've recently successfully compiled gcc-4.8.5 under LinuxMint 20.1 (Ubuntu 20.04 based, compiler is the system gcc: 9.3.0, installed with sudo apt install build-essential) with this script. Also, I've installed all the packages that Bebbo suggested, including gcc-multilib and libstdc++6:i386 before running this script. Check up InstGcc4 class at the bottom of the code.
install_gcc.rb
They might end up to be 'un-installable' state a few months later. But at least gcc-4.8.5 works now.
ps. I've started to compile this old gcc due to CUDA... My hardware is a decade old GeForce 9600/9400 (yeah 2008 MBP) and CUDA 6.5 was the best option for that machine.
pps. Anyway, strange thing is, I had to give out '-std=gnu++11' for CXXFLAGS to avoid errors.

pip install gitpython fails with python 3.x requirement

When I try to install gitpython via pip normally under python 2.7, it fails telling me python 3.x is required.
This particular script/process has worked until this morning.
$ sudo pip install gitpython
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting gitpython
Using cached https://www.piwheels.org/simple/gitpython/GitPython-2.1.12-py2.py3-none-any.whl
GitPython requires Python '>=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*' but the running Python is 2.7.16
I am running Python 2.7.16
$ python --version
Python 2.7.16
When I check the current documentation I see that Python 2.7 or newer is listed as a requirement. What am I missing?
Turns out the documentation was lagging, and Python 2.7 support was dropped in dac619e.
Assuming other folks are procrastinating as I am in getting to Python 3, I've created a fork of GitPython which is current with 2.1.12 and reverts only those changes which eliminated stated compatibility for Python 2.7. My fork is expected to remain static with the 0.2.12a release and otherwise even with mainline GitPython 2.1.12.
I've created a small batch file for folks who may want/need to automate the installation process of this fork:
#!/bin/bash
gitpython() {
local cwd repo pipList found
pipList=$(pip list)
found=$(grep -o "GitPython" <<< "$pipList" | wc -l)
repo="https://github.com/lbussy/GitPython.git"
if [ "$found" -eq "0" ]; then
echo -e "\nDownloading and installing GitPython for Python 2.7."
cwd=$(pwd)
git clone "$repo" "$HOME/git-python" &>/dev/null || die "$#"
cd "$HOME/git-python" || die "$#"
eval "python setup.py install" &>/dev/null || die "$#"
cd "$cwd" || die "$#"
rm -fr "$HOME/git-python"
echo -e "\nGitPython for Python 2.7 install complete."
else
echo -e "\nGitPython for Python 2.7 already installed."
fi
}
function die
{
local message=$1
[ -z "$message" ] && message="Died"
echo "${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: ${FUNCNAME[1]}: $message." >&2
exit 1
}
main() {
gitpython "$#"
}
main "$?" && exit 0
Installed in this manner, it is still able to be managed by pip going forward.

Running the "exec" command in Jenkins "Execute Shell"

I'm running Jenkins on a Linux host. I'm automating the build of a C++ application. In order to build the application I need to use the 4.7 version of g++ which includes support for c++11. In order to use this version of g++ I run the following command at a command prompt:
exec /usr/bin/scl enable devtoolset-1.1 bash
So I created a "Execute shell" build step and put the following commands, which properly builds the C++ application on the command prompt:
exec /usr/bin/scl enable devtoolset-1.1 bash
libtoolize
autoreconf --force --install
./configure --prefix=/home/tomcat/.jenkins/workspace/project
make
make install
cd procs
./makem.sh /home/tomcat/.jenkins/workspace/project
The problem is that Jenkins will not run any of the commands after the "exec /usr/bin/scl enable devtoolset-1.1 bash" command, but instead just runs the "exec" command, terminates and marks the build as successful.
Any ideas on how I can re-structure the above so that Jenkins will run all the commands?
Thanks!
At the begining of your "Execute shell" script, execute source /opt/rh/devtoolset-1.1/enable to enable the devtoolet "inside" of your shell.
Which gives:
source /opt/rh/devtoolset-1.1/enable
libtoolize
autoreconf --force --install
./configure --prefix=/home/tomcat/.jenkins/workspace/project
make
make install
cd procs
./makem.sh /home/tomcat/.jenkins/workspace/project
I needed to look up what scl actually does.
Examples
scl enable example 'less --version'
runs command 'less --version' in the environment with collection 'example' enabled
scl enable foo bar bash
runs bash instance with foo and bar Software Collections enabled
So what you are doing is running a bash shell. I guess, that the bash shell returns immediately, since you are in non-interactive mode. exec runs the the command within the shell without creating a new shell. That means if the newly opened bash ends it also ends your shell prematurely. I would suggest to put all your build steps into a bash script (e.g. run_my_build.sh) and call it in the following way.
exec /usr/bin/scl enable devtoolset-1.1 run_my_build.sh
This kind of thing normally works in "find" commands, but may work here. Rather than running two, or three processes, you run one "sh" that executes multiple things, like this:
exec sh -c "thing1; thing2; thing3"
If you require each step to succeed before the next step, replace the semi-colons with double ampersands:
exec sh -c "thing1 && thing2 && thing3"
I have no idea which of your steps you wish to run together, so I am hoping you can adapt the concept to fit your needs.
Or you can put the whole lot into a script and exec that.