warning: this only works if you have a gui/gnome installed.

thanks goes to this superb tutorial with screenshots: http://xmodulo.com/debug-program-nemiver-debugger.html

For Debian based distributions, it should be pretty straightforward:

apt-get install nemiver; # Debian and Ubuntu
pacman -S nemiver; # For Arch Linux
yum install nemiver; # For CentOS/RedHat/Fedora

create a new file with the text editor (vim, emacs, vi, nano, pluma) of your choice:

vim step_test2.c


#include <stdlib.h>
#include <stdio.h>
int main()
{
        int x=0;
        x++;
        printf("testing %d\n",x);
        return 0;
}

compile it like this:

gcc -g step_test2.c -o step_test2.bin
# -g = with debug symbols
# -o = output to this file
# -v = verbose

now you are ready to step debug a c program:

nemiver step_test2.bin; # start nemiver and pass the program to debug

nemiver hotkeys and shortcuts:

F6 = next step
F7 = step into
Shift+F7 = step out
F5 = run until you hit a breakpoint
F11 = run to cursor

you can r-click into the “in scope expression” field and add a variable to monitor:

now the trouble starts…

“Locate File”

what is neat… just like in Java if your program is functions/libraries that do not ship with your program… it will ask for it’s sources, in this case you might get hit with this message:

Locate File libc-start.c or printf.c “please specify the location of this file”

this is obviously from: Roland McGrath glibc! (Stallman wrote gcc) without it Linux would be impossible so please call it GNU Linux!

https://www.gnu.org/software/libc/

https://en.wikipedia.org/wiki/GNU_C_Library

… so let’s give it to em X-D

sudo bash; # become root
mkdir -p /build/glibc-x07mZ9; # create the dir nemiver is asking for
cd /build/glibc-x07mZ9;
# if you need a different version of glibc sources look here
wget https://ftp.gnu.org/gnu/libc/glibc-2.24.tar.bz2
tar fxv glibc-2.24.tar.bz2; # unpack
chown -R user:user /build/; # chown to your default non-root user

navigate to the specific folder… all subsequent files nemiver will find automatically.

NOW YOU CAN STEP DEBUG AROUND GLIBC! 🙂

 … and checkout the internal workings of printf! YEAH 🙂

… i could NOT think of any more fun thing to do in summer.

About GlibC

GNU C Library – The GNU C Library, commonly known as glibc, is the GNU Projects implementation of the C standard library. Despite its name, it now also directly supports C++ and it was started in the early 1990s by the Free Software Foundation for their GNU operating system. Released under the GNU Lesser General Public License, glibc is free software, the Glibc project was initially written mostly by Roland McGrath,  working for the Free Software Foundation in the 1980s. In February 1988, FSF described glibc as having completed the functionality required by ANSI C. By 1992, it had the ANSI C-1989 and POSIX. 1-1990 functions implemented, in September 1995 Ulrich Drepper

made his first contribution to the glibc project and gradually became over the 1990s the core contributor and maintainer of glibc. Drepper held the position for many years and accumulated until 2012 63% of all commits of the project. In the early 1990s, the developers of the Linux kernel forked glibc and their fork, called Linux libc, was maintained separately for years and released versions 2 through 5. At this point, the Linux kernel developers discontinued their fork, the last used version of Linux libc used the internal name libc. so.5. Following on from this, glibc 2. x on Linux uses the soname libc. so.6, the *. so file name is often abbreviated as libc6 following the normal conventions for libraries. Starting in 2001 the librarys development had been overseen by a committee, with Ulrich Drepper kept as the lead contributor, the steering committee installation was surrounded by a public controversy as it was openly described by Ulrich Drepper as a failed hostile takeover maneuver by RMS.

While previously in a CVS repository, in 2009 glibc was migrated to a Git repository on Sourceware, after the change in glibc maintainership Debian and other projects migrated back to the glibc, who before switched to alternatives. Also, since the beginning of 2014, the glibc fork EGLIBC is no longer being developed, for most systems, the version of glibc can be obtained by executing the lib file.2, with all extensions common to XSI compliant systems along with all X/Open UNIX extensions. In addition, glibc also provides extensions that have been deemed useful or necessary while developing GNU, Glibc is used in systems that run many different kernels and different hardware architectures. It officially supports the Hurd and Linux kernels, additionally, there are heavily patched versions that run on the kernels of FreeBSD and NetBSD, as well as a forked-version of OpenSolaris. It is also used and named libroot. so in BeOS, Glibc has been criticized as being bloated and slower than other libraries in the past, e. g. by Linus Torvalds and embedded Linux programmers. For this reason, several alternative C standard libraries have been created which emphasize a smaller footprint, however, many small-device projects use GNU libc over the smaller alternatives because of its application support, standards compliance, and completeness. Examples include Openmoko and Familiar Linux for iPaq handhelds, there are compatibility layers to allow programs written for other ecosystems, e. g. Googles Android and Microsofts Windows, to run on glibc interface offering systems. Libhybris is a compatibility layer for Androids Bionic and Wine can be seen as compatibility layer from Win32 API/ABI to glibc

after 30 years McGarth gives up parentship of glibc https://www.pro-linux.de/news/1/24923/roland-mcgrath-tritt-als-glibc-betreuer-zur%C3%BCck.html

thanks

thanks to: https://github.com/GNOME/nemiver

all contributors.

 

glibc security:

nobody is perfect, not even Einstein… so expect things to fail.

http://seclists.org/oss-sec/2017/q4/385

“The glibc DNS bug is unusually bad,” Kaminsky says. “Even Shellshock and Heartbleed tended to affect things we knew were on the network and knew we had to defend. This affects a universally used library (glibc) at a universally used protocol (DNS). Generic tools that we didn’t even know had network surface (sudo) are thus exposed, as is software written in programming languages designed explicitly to be safe.”

http://www.bankinfosecurity.com/alert-patch-critical-skeleton-key-flaw-in-linux-a-8884

glibc news:

safer, faster linux

“Aside from hand-tuning functions, glibc has received some tweaking around its malloc API for faster and safer process termination. Glibc 2.27 also has fixed a handful of security issues and other improvements are baking.”

https://www.phoronix.com/scan.php?page=news_item&px=Glibc-2.27-Features

subscribe to more free software news: https://sourceware.org/

off topic:

other cool stuff to compile: TombRaider for Linux

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin