Working with Insight, a Graphical Debugger

Insight is a graphical user interface based tool giving us an interface to GDB by GNU, this tool is written in tcl/tk. Most of this tool is hosted/maintained on sourceware hence being the official website for the same, click here to follow. To use the tool we have to compile the source code of the various tagged released, for the purpose of this post we are taking the latest release as of today i.e. Insight6.8a and the target system would be Ubuntu 18.4 Bionic Beaver and for the examples we will be using arm assembly code debugging over GDB of ARM, same set-up can be use to debug any x86 platform code also. Lets get started.

Getting the source of Insight and resolving dependency packages

The source of the Insight has been downloaded form sourceware ftp servers, click here to download the 6.8 version for newer or older release we can follow up this link. The same can be downloaded from the terminal by below command.

$ mkdir Insight && cd Insight && wget ftp://sourceware.org/pub/insight/releases/insight-6.8a.tar.bz2

First we extract the code from the downloaded tar big zip in short tar.bz on our Linux machine by below command.

$ tar -jxvf insight-6.8a.tar.bz2

…with the source out from the closet lets go through the compilation process.Most help is taken from this link.As the usual most compiling routine we usually go to the source directory, following up with configure or menuconfig or directly make step.This source code has a process of configure involved hence we will start with that by hitting below command, you can cd to your respective downloaded code version we had insight6.8 directory which was generated by previous step. This gives us whether the system environment is ready to support the installation/compilation process or not. If the system is never has been used for any compilation there are highly chances that the packages will be missing.
There are command line options for type of installation and targets it supports below is an example, one can choose to be just configure for native compilation.

./configure –target=arm-elf –prefix=/usr/arm-linux-gnueabi/bin/

$ cd insight-6.8 && ./configure
.
.
.
checking for cxx… no
checking for cc++… no
checking for cl… no
checking for FCC… no
checking for KCC… no
checking for RCC… no
checking for xlC_r… no
checking for xlC… no
checking whether we are using the GNU C++ compiler… no
checking whether g++ accepts -g… no
checking for gnatbind… no
checking for gnatmake… no
checking whether compiler driver understands Ada… no
checking how to compare bootstrapped objects… cmp –ignore-initial=16 $$f1 $$f2
checking for bison… no
checking for byacc… no
checking for yacc… no
checking for bison… no
checking for gm4… no
checking for gnum4… no
checking for m4… no
checking for flex… no
checking for lex… no

The below command will install all the required package in one shot, if still missed any comment below to upgrade the command. Since, the package Insight multi-platform application hence its configure it design to configure for all platforms hence few of them will be always no.

$ sudo apt-get install -y byacc bison texinfo flex m4 expect gfortran dejagnu g++ gcc libx11-dev build-essential fakeroot libunwind-dev libncurses5-dev tk

since we will be working with arm tool chain we’ll install the arm tool-chain also at this point of installation stage.A bit about arm tool chains or naming convention of arm tool-chain, ignore this paragraph is not interested in ARM or Linux tool-chain naming convention or anything related to it.
Tool chain usually named as per <arch>-<vendor>-<os>-<ABI>, The arch section tells which architecture it is made for arm, x86, powerPC etc. Vendor tells who developed the tool-chain, arm tool-chains mostly the vendors are missing if found it will be a known name like apple eclipse etc.OS field indicates for which target OS it will generate the cross/-compiled binary. ABI section tells which type of application binary interface it is varying form android binary interface, gnu based binary interface.The gcc-arm-none-eabi tells that the its a C based compiler tool-chain targeted for arm architecture which has no vendor and none OS i.e. bare-metal binary which further uses embedded application binary interface.

$ sudo apt-get install g++-arm-linux-gnueabi sudo apt-get install gcc-arm-linux-gnueabi

Moving forward with our installation after configuration we proceed to make of the process. On this package we face the installation challenges related to bin-utils installation as follows:

$.
.
.
make[3]: Nothing to be done for ‘info’.
make[3]: Leaving directory ‘/home/ubuntu/Desktop/Insight/insight-6.8/bfd/po’
make[3]: Entering directory ‘/home/ubuntu/Desktop/Insight/insight-6.8/bfd’
make[3]: Nothing to be done for ‘info-am’.
make[3]: Leaving directory ‘/home/ubuntu/Desktop/Insight/insight-6.8/bfd’
Makefile:1090: recipe for target ‘info-recursive’ failed
make[2]: *** [info-recursive] Error 1
make[2]: Leaving directory ‘/home/ubuntu/Desktop/Insight/insight-6.8/bfd’
Makefile:3061: recipe for target ‘all-bfd’ failed
make[1]: *** [all-bfd] Error 2
make[1]: Leaving directory ‘/home/ubuntu/Desktop/Insight/insight-6.8’
Makefile:701: recipe for target ‘all’ failed
make: *** [all] Error 2

Fix for this is in the file insight6.8/bfd/doc/bfd.texinfo the variable colophon is having a typo i.e. @colophon should be @@colophon

$.
.
.
.
rc=$?; \
$restore $backupdir/* echo "./bfd.info" | sed 's|[^/]*$||'; \
fi; \
rm -rf $backupdir; exit $rc
./elf.texi:11: raising the section level of @subsubsection which is too low
Makefile:390: recipe for target ‘bfd.info’ failed
make[3]: *** [bfd.info] Error 1
make[3]: Leaving directory ‘/home/

The fix for above is in insight6.8/bfd/doc/elf.texi the variable subsection has a typo as subsubsection hence convert the @subsubsection to @subsection.
The above compilation errors were beyond understanding Thanks to this blog for explaining these errors [Link].
Modifying these changes will further lead to more errors related to compiler flags.which will be resolved by following command making changes to make file directly may later on fail the configure check later on.

$ make CFLAGS=”-Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-value -Wno-unused-but-set-variable -Wno-error=misleading-indentation -Wno-error=enum-compare -Wno-error=shift-negative-value”

The incomplete type error on linux-nat.h can be removed by replacing “struct siginfo” with “siginfo_t” this change will result in conflicting type errors Just keep on modifying the smillar where ever is required like the files linux-nat.c, linux-x86-64-low.c.The following error on amd64-linux-nat.c can be removed by replacing

ps_err_e
ps_get_thread_area (const struct ps_prochandle *ph,
lwpid_t lwpid, int idx, void **base)

with

ps_err_e
ps_get_thread_area (struct ps_prochandle *ph,
lwpid_t lwpid, int idx, void **base)

Also, where ever required the definition of ps_lsetfpregs by replacing mostly file affected with this one will be proc-service.c in <>/gdb and <>/gdb/server

ps_err_e
ps_lsetfpregs (
gdb_ps_prochandle_t  ph, lwpid_t lwpid, void * fpregset)

with

ps_err_e
ps_lsetfpregs (struct ps_prochandle* ph, lwpid_t lwpid, const prfpregset_t* fpregset)

Mostly with all above mods we were able to compile successfully and followed by sudo make install was able to install the insight binary.Might be chances these errors are not occurring while installation on higher versions like version 6.8.1Insight and highly suggested to work with 6.8.1 version.

$ sudo make install

Update 1
This installation may not work directly out of new terminal and you may get an error saying “arm-elf-insight: command not found”. The reason for this is environment variables in Linux, this is the same reason why you also may not get this error if by chance you already installed in the default path, which is included in the PATH variable of the system. In case if not then we may use a temp solution to add the path to the path variable for that terminal by below:

#Go to the path where your binaries are installed.
ubuntu@ubuntu:/usr/insight/bin$ pwd
/usr/insight/bin
ubuntu@ubuntu:/usr/insight/bin$ ls
arm-elf-gdb arm-elf-gdbtui arm-elf-insight arm-elf-run tclsh8.4 wish8.4
ubuntu@:/usr/insight/bin$
#For My system it is as above and this is not part of the std. path. to add it we can execute below command
ubuntu@ubuntu-VirtualBox:/usr/insight/bin$ export PATH=$PATH:$PWD

The above is temporary solution and have this path always in the system we need to modify the ~/.bashrc file and add the command to add the path to the path variable to the end of the file. export PATH=$PATH:<customPath>, here $PWD should be avoided and complete path should be added.You may need sudo permissions to edit this file.Restart the terminals to see the effect.

export PATH=$PATH:/usr/insight/bin

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s