Debugging Newlib built by the RSB

The RSB builds Newlib when building GCC as a single source tree with full debug information. This debugging information does not effect the size of the executable on your target hardware yet it does provide you with information you may need to debug the way you are using Newlib or a possible bug in Newlib.

If you reach a call to Newlib and you step the debugger it will step into the Newlib function however there often is no source available becaues the RSB cleans the source away after building the tools plus the path to the source is a relative path based on how GCC built Newlib. For example stepping into the function regcomp you might see:

(gdb) s
regcomp (preg=preg@entry=0x2a4ee0, pattern=0x2a5554 "test_regex_.*", cflags=cflags@entry=1) at ../../../../../../gcc-6-20160609/newlib/libc/posix/regcomp.c:192
192     ../../../../../../gcc-6-20160609/newlib/libc/posix/regcomp.c: No such file or directory.

Take note of the number of ../ levels in the source path above. In this example there are six. This can vary depending on build environment.

To make the source code available to the debugger you need to unpack the Newlib source used by the RSB and you need to tell the debugger where to find it.

My RSB is located at /opt/work/chris/rtems/rsb/rtems-source-builder.git and the source used to build the tools is under the rtems/source in the RSB.

The version of Newlib source to use is embedded into the GCC version string:

$ /opt/work/rtems/4.12/bin/i386-rtems4.12-gcc --version
i386-rtems4.12-gcc (GCC) 6.1.1 20160609 (RTEMS 4.12, RSB c476de6150f39afdf142c6f4420c59ba2f1aa2fe-modified, Newlib
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

The Newlib version is Newlib so the source is newlib-

Change directory to a convenient location on the host machine GDB is running on and create a directory to unpack the Newlib source. Create the directory and unpack the source inside it:

$ cd /opt/work/chris/rtems
$ mkdir src
$ cd src
$ tar zxf /opt/work/chris/rtems/rsb/rtems-source-builder.git/rtems/sources/newlib-

Create the specific GCC and Newlib directories GCC was built with the debugger printed out and link to the newlib source:

$ mkdir gcc-6-20160609
$ cd gcc-6-20160609
$ ln -s ../newlib- newlib
$ cd ..

Create dummy internal work directories like GCC had when Newlib was built. This is the number of levels that were noted above that you can see in the source path as the leading series of ../ (six in this example, but this can vary depending on your build environment):

$ mkdir -p 1/2/3/4/5/6

You now have a path the debugger can reference and find the source. Add to the GDB source search path using the dir command:

(gdb) dir /opt/work/chris/rtems/src/1/2/3/4/5/6
Source directories searched: /opt/work/chris/rtems/src/1/2/3/4/5/6:$cdir:$cwd
(gdb) l
187     int                             /* 0 success, otherwise REG_something */
188     regcomp(preg, pattern, cflags)
189     regex_t *__restrict preg;
190     const char *__restrict pattern;
191     int cflags;
192     {
193             struct parse pa;
194             struct re_guts *g;
195             struct parse *p = &pa;
196             int i;

You will now have the Newlib source available in the debugger.

Last modified on Sep 5, 2016 at 1:52:01 AM Last modified on Sep 5, 2016, 1:52:01 AM