How to make gdb for a target and use it there - linux

I am trying to compile gdb-8.2 from source.
Build machine: x86-64
Host AND target: arm-linux-gnueabi
I ran:
CC=arm-linux-gnueabi-gcc ./configure --host=arm-linux-gnueabi --target=arm-linux-gnueabi
make
Then I ran:
make DESTDIR=<Some Path>/gdb_installation install
So I got a usr folder inside gdb_installation folder. I copied the usr/local/bin/gdb to my target and ran
./gdb
Output:
#./gdb
#
But it does not show anything. It exits without any message.
What am I missing here?
Running the file command shows that the gdb executable is indeed built for my target.
PS: Running a sample hello world program using arm-linux-gnueabi-gcc works perfectly fine on the target; and file command shows the same output that it did for gdb.

What am I missing here?
Your build looks correct, but doesn't work. It's not clear why, so you need to debug that.
What is the exit status of this gdb on the target?
./gdb --version; echo $?
Does it actually do anything? strace ./gdb --version
Is there anything interesting in the kernel message log?
Depending on answers to above questions, further guesses of what has gone wrong will be possible.
Perhaps there is some .gdbinit that tells GDB to quit? What does this do:
./gdb -nx --version?

Related

How to install valgrind on linux

enter image description here
I have basically tried every tutorial out there and still cant run valgrind.
So far....
I installed valgrind from their website to directory 'memcheck'
tar xvf valgrind-3.18.1.tar.bz2
the picture is the outcome of "./configure" ,I cant tell if it was successful or not.
then the command "make" gives: make: *** No targets specified and no makefile found. Stop.
and the same for "make install"
this is what i tried to do. How to install valgrind properly?
If the output from configure contains "configure: error:" then it failed.
Installing with your package manager will be easiest.
Otherwise, you will need
A C compiler (e.g., gcc or clang), always.
GNU make, always.
Perl, probably always.
Sed and awk, always.
Autotools, m4, if regenerating the configure script.
Lots of packages if you want to generate the docs.
A C++ compiler (g++ or clang++) if you want to build and run the regression tests.

How do I downgrade Make from 4.2.1 to 3.82?

I want to use make version 3.82, so I am downgrading from version 4.2.1.
After downloading the make-3.82.tar.gz file from the https://ftp.gnu.org/gnu/make/ site, extract the file and run ./configure ./build.sh to create a make file.
if run the make file, I get an error called Segmentation error (core dump).
How do I make make work properly?
If you set ulimit -c unlimited then re-run make, it will generate a core file that you can inspect with gdb to see what happened. You may need to recompile make with -g3 or similar to ensure the binary contains debugging information.

How to do runtime linking in make using LDFLAGS -R option, or some other way

This is a question on run time linking in make, in general.
I am trying to install tmux from source, on a linux system. It has dependency on "libevent" which I have installed in home dir. I am not the root on this system so I can't install it in system wide area.
DIR=$HOME/libevent
./configure --prefix=$HOME/site/tmux/ CFLAGS="-I$DIR/include" LDFLAGS="-L$DIR/lib/"
Though above command works but I need to have $HOME/libevent included in the LD_LIBRARY_PATH all the time for tmux to work. I think there should be a better way.
I need a run time linking so that I don't have to mess with LD_LIBRARY_PATH. I read here http://www.ilkda.com/compile/Environment_Variables.htm that, this can be achieved using "-R" option.
./configure --prefix=$HOME/site/tmux/ CFLAGS="-I$DIR/include" LDFLAGS="-L$DIR/lib/" LDFLAGS="-R$DIR/lib/"
But this is not working and produces the following error:
configure: error: "libevent not found"
Can someone let me know how to do run time linking in make while running configure script.
LDFLAGS="-L$DIR/lib/" LDFLAGS="-R$DIR/lib/"
The sets LDFLAGS to -L$DIR/lib/, and then immediately overrides it with -R$DIR/lib/, not unlike x = 1; x = 2; results in x == 2.
What you want is: LDFLAGS="-L$DIR/lib/ -R$DIR/lib/"
"libevent not found"
I trusted you to read the man page, but you didn't. The -R flag means RUNPATH to linker on Solaris, but it means something else to Linux linker.
What you want then is:
LDFLAGS="-L$DIR/lib/ -Wl,--rpath=$DIR/lib/"

cross-gdb: fix a mismatch between libthread_db and libpthread

I' ve a cross-gdb configured with --host=i686-pc-linux-gnu --target=powerpc-e300c3-linux-gnu. i can correctly debug an application on a remote board with gdbserver but i get an error about a version mismatch between libthread_db and libpthread so i can't debug threads correctly (gdb recognizes only one thread instead of three threads). Maybe it's is due to a different version of libc: on host machine i've libc2.15 and on target machine lib2.5. I tried to rebuid libc2.5 for host in order to link gdb against to it but it's an hell. Before i get crazy to rebuild it, could someone confirm that it's a libc problem?
I tried to rebuid libc2.5 for host in order to link gdb against to it
That's not what you need.
What you need, is for gdb to find and load libthread_db.so.1, that matches your target libpthread.so.0.
For this, you need to
build libc-2.5 for host, and
set GDB's libthread-db-search-path such that it finds the libthread_db.so.1 built in step 1.
You don't actually need to build the entire libc in step 1. Something like this should suffice:
mkdir build && cd build
../configure --prefix=/usr
make -C ../nptl_db objdir=`pwd`
Update:
i have GDB 6.6 and there isn't libthread-db-search-path. What is another way to specify that path?
That GDB will just dlopen("libthread_db.so.1", ...). So to make it find the right libthread_db.so.1, you need to adjust LD_LIBRARY_PATH. Using bash:
LD_LIBRARY_PATH=/tmp/glibc-2.5/build/nptl_db gdb /path/to/target/a.out

How to debug my Cross compiled Linux Kernel?

I 've cross compiled a Linux Kernel (for ARM on i686 - using Cross-LFS).
Now I'm trying to boot this Kernel using QEMU.
$ qemu-system-arm -m 128 -kernel /mnt/clfs-dec4/boot/clfskernel-2.6.38.2 --nographic -M versatilepb
Then, it shows this line and waits for infinite time !!
Uncompressing Linux... done, booting the kernel.
So, I want to debug the kernel, so that I can study what exactly is happening.
I'm new to these kernel builds, Can someone please help me to debug my custom built kernel as it is not even showing anything after that statement. Is there any possibility of the kernel being broken? ( I dont think so, b'se it didnot give any error while compiling )
And my aim is to generate a custom build very minimal Linux OS. Any suggestions regarding any tool-chains etc which would be easy & flexible depending on my requirements like drivers etc.,
ThankYou
You can use GDB to debug your kernel with QEMU you can use -s -S options. If you want a simple and reliable toolchain, you can use ELDK from DENX (http://www.denx.de/wiki/DULG/ELDK).
You can install it like this (It's not the last version, but you got the idea):
wget http://ftp.denx.de/pub/eldk/4.2/arm-linux-x86/iso/arm-2008-11-24.iso
sudo mkdir -p /mnt/cdrom (if necessary)
sudo mount -o loop arm-2008-11-24.iso /mnt/cdrom
/mnt/cdrom/install -d $HOME/EMBEDDED_TOOLS/ELDK/
The command above should install the toolchain under $HOLE/EMBEDDED_TOOLS/ELDK (modify it if you need)
echo "export PATH=$PATH:$HOME/EMBEDDED_TOOLS/ELDK/ELDK42/usr/bin" >> $HOME/.bashrc
You can then see the version of your ARM toolchain like this:
arm-linux-gcc -v
You can test a hello_world.c program like this:
arm-linux-gcc hello_world.c -o hello_world
And you type: file hello_wrold to see the target architecture of the binary, it should be something like this:
hello_wrold: ELF 32-bit LSB executable, ARM, version 1 (SYSV)
Now if you want to compile a production kernel, you need to optimize it (i suggest using busybox) and if you want just one for testing now, try this steps:
Create a script to set your chain tool set_toolchain.sh:
#! /usr/bin/sh
PATH=$PATH:$HOME/EMBEDDED_TOOLS/ELDK/ELDK42/usr/bin
ARCH=arm
CROSS_COMPILE=arm-linux-gnueabi-
export PATH ARCH CROSS_COMPILE
And run your script (source ./set_toolchain.sh)
Download a linux kernel and unzip it (Let's assume 2.6.x, it's an old kernel, but there are a lot of chances that it work without compilation errors).
Inside your unzipped kernel:
cd ~/linux-2.6.29/arch/arm/configs
make versatile_defconfig
Here we use versatile chip, you may need to use make menuconfig to modify the option OABI and set it to ARM EABI, this option is under Kernel features menu
After all this steps, you can compile you kernel:
make
if you want verbose compilation make v=1
After this you got your kernel under arch/arm/boot/zImage.
Hope this help.
Regards.
I would suggest to build your kernel by activating the option in the section Kernel hacking of your configuration file.
Then you may use kdb or kgdb which is easier to use but requires another machine running gdb.
`
You can also connect Qemu and GDB. Qemu has the -s and -S options that run a GDB server and allow you to connect to it via TCP to localhost:1234. Then you can load your kernel image (the unzipped one) in GDB and see how far your kernel boots.

Resources