Binutils with MCST patches
Go to file
Tom Tromey 9d3421afbb Change ptype/o to print bit offset
Consider this short C example:

    struct inner
    {
      unsigned x;
      unsigned y : 3;
      unsigned z : 3;
    };

    struct outer
    {
      unsigned char o : 3;
      struct inner i __attribute__ ((packed));
    };

When I use "ptype/o" on this, I get:

    (gdb) ptype/o struct outer
    /* offset    |  size */  type = struct outer {
    /*    0: 5   |     1 */    unsigned char o : 3;
    /* XXX  5-bit hole  */
    /*    1      |     8 */    struct inner {
    /*    1      |     4 */        unsigned int x;
    /*    5:29   |     4 */        unsigned int y : 3;
    /*    5:26   |     4 */        unsigned int z : 3;
    /* XXX  2-bit padding  */
    /* XXX  3-byte padding */

				   /* total size (bytes):    8 */
			       } i;

			       /* total size (bytes):    9 */
			     }

In the location of "o" ("0: 5"), the "5" means "there are 5 bits left
relative to the size of the underlying type.

I find this very difficult to follow.  On irc, Sergio said that this
choice came because it is what pahole does.  However, I think it's not
very useful, and maybe is just an artifact of the way that
DW_AT_bit_offset was defined in DWARF 3.

This patch changes ptype/o to print the offset of a bitfield in a more
natural way, that is, using the bit number according to the platform's
bit numbering.

With this patch, the output is now:

    (gdb) ptype/o struct outer
    /* offset    |  size */  type = struct outer {
    /*    0: 0   |     1 */    unsigned char o : 3;
    /* XXX  5-bit hole  */
    /*    1      |     8 */    struct inner {
    /*    1      |     4 */        unsigned int x;
    /*    5: 0   |     4 */        unsigned int y : 3;
    /*    5: 3   |     4 */        unsigned int z : 3;
    /* XXX  2-bit padding  */
    /* XXX  3-byte padding */

				   /* total size (bytes):    8 */
			       } i;

			       /* total size (bytes):    9 */
			     }

This is better, IMO, because now the "offset" of a bitfield is
consistent with the offset of an ordinary member, referring to its
offset from the start of the structure.

gdb/ChangeLog
2019-05-08  Tom Tromey  <tromey@adacore.com>

	* typeprint.c (print_offset_data::update): Print the bit offset,
	not the number of bits remaining.

gdb/doc/ChangeLog
2019-05-08  Tom Tromey  <tromey@adacore.com>

	* gdb.texinfo (Symbols): Document change to ptype/o.

gdb/testsuite/ChangeLog
2019-05-08  Tom Tromey  <tromey@adacore.com>

	* gdb.base/ptype-offsets.exp: Update tests.
2019-05-08 10:15:51 -06:00
bfd Do not force the m68k-elf linker to fail if it encoutners a non-ELF format file. 2019-05-08 14:51:32 +01:00
binutils Sign-extend start and stop address inputs to objdump 2019-05-08 09:07:35 -07:00
config
contrib
cpu
elfcpp [binutils, ARM, 10/16] BFCSEL infrastructure with new global reloc R_ARM_THM_BF12 2019-04-15 12:31:34 +01:00
etc
gas gas/elf dwarf2 tests 2019-05-08 09:40:08 +09:30
gdb Change ptype/o to print bit offset 2019-05-08 10:15:51 -06:00
gold Check whether symbols with MOVW_.ABS relocations require PLT entries (aarch64). 2019-02-19 16:13:24 -08:00
gprof PR24520, gprof fails to read compressed debug data 2019-05-08 09:40:07 +09:30
include Add load-link, store-conditional paired EVA instructions 2019-05-06 06:43:32 -07:00
intl
ld Fix compile time warning when building the linker in a MinGw32 environment using gcc 8. 2019-05-08 16:54:16 +01:00
libdecnumber
libiberty Pull in patch for libiberty that fixes a stack exhaustion bug when demangling a pathalogically constructed mangled name. 2019-04-10 15:49:36 +01:00
opcodes Add load-link, store-conditional paired EVA instructions 2019-05-06 06:43:32 -07:00
readline Readline: Cleanup some warnings 2019-01-31 17:25:06 +00:00
sim sim: Use host not target byte order for merging and splitting values 2019-04-13 22:21:14 +01:00
texinfo
zlib
.cvsignore
.gitattributes
.gitignore
COPYING
COPYING.LIB
COPYING.LIBGLOSS
COPYING.NEWLIB
COPYING3
COPYING3.LIB
ChangeLog Pull in patch for libiberty that fixes a stack exhaustion bug when demangling a pathalogically constructed mangled name. 2019-04-10 15:49:36 +01:00
MAINTAINERS
Makefile.def
Makefile.in
Makefile.tpl
README
README-maintainer-mode
ar-lib
compile
config-ml.in
config.guess
config.rpath
config.sub
configure
configure.ac
depcomp
djunpack.bat
install-sh
libtool.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
makefile.vms
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
setup.com
src-release.sh Move potentially obsolete BFD targets into the definitely obsolete section. Add a note to the README-how-to-make-a-release document about doing this. 2019-02-07 14:30:02 +00:00
symlink-tree
test-driver
ylwrap

README

		   README for GNU development tools

This directory contains various GNU compilers, assemblers, linkers, 
debuggers, etc., plus their support routines, definitions, and documentation.

If you are receiving this as part of a GDB release, see the file gdb/README.
If with a binutils release, see binutils/README;  if with a libg++ release,
see libg++/README, etc.  That'll give you info about this
package -- supported targets, how to use it, how to report bugs, etc.

It is now possible to automatically configure and build a variety of
tools with one command.  To build all of the tools contained herein,
run the ``configure'' script here, e.g.:

	./configure 
	make

To install them (by default in /usr/local/bin, /usr/local/lib, etc),
then do:
	make install

(If the configure script can't determine your type of computer, give it
the name as an argument, for instance ``./configure sun4''.  You can
use the script ``config.sub'' to test whether a name is recognized; if
it is, config.sub translates it to a triplet specifying CPU, vendor,
and OS.)

If you have more than one compiler on your system, it is often best to
explicitly set CC in the environment before running configure, and to
also set CC when running make.  For example (assuming sh/bash/ksh):

	CC=gcc ./configure
	make

A similar example using csh:

	setenv CC gcc
	./configure
	make

Much of the code and documentation enclosed is copyright by
the Free Software Foundation, Inc.  See the file COPYING or
COPYING.LIB in the various directories, for a description of the
GNU General Public License terms under which you can copy the files.

REPORTING BUGS: Again, see gdb/README, binutils/README, etc., for info
on where and how to report problems.