Discussion:
[Bug cli/17095] New: print alignof (type or expression)
mjw at redhat dot com
2014-06-26 22:04:05 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=17095

Bug ID: 17095
Summary: print alignof (type or expression)
Product: gdb
Version: unknown
Status: NEW
Severity: normal
Priority: P2
Component: cli
Assignee: unassigned at sourceware dot org
Reporter: mjw at redhat dot com

It would be convenient if gdb supported alignof like it supports sizeof for a
type or expression.

GCC has had an GNU extension for it:
https://gcc.gnu.org/onlinedocs/gcc/Alignment.html
C++11 has a keyword alignof and C11 has _Alignof (with alignof when including
stdalign.h) both only work on a type, but as a GNU extension they also work on
expressions.

alignof has the same rules as sizeof, alignof on an array gives the alignment
of the element type, on a c++ reference type it gives the alignment of the
referenced type.
--
You are receiving this mail because:
You are on the CC list for the bug.
john.carter at taitradio dot com
2014-11-25 00:16:01 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=17095

John Carter <john.carter at taitradio dot com> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |john.carter at taitradio dot com
--
You are receiving this mail because:
You are on the CC list for the bug.
jrmuizel at gmail dot com
2017-07-14 19:05:16 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=17095

Jeff Muizelaar <jrmuizel at gmail dot com> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |jrmuizel at gmail dot com
--
You are receiving this mail because:
You are on the CC list for the bug.
tromey at sourceware dot org
2018-04-18 17:14:56 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=17095

Tom Tromey <tromey at sourceware dot org> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |tromey at sourceware dot org
Component|cli |exp
--
You are receiving this mail because:
You are on the CC list for the bug.
jrmuizel at gmail dot com
2018-04-19 21:52:51 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=17095

--- Comment #1 from Jeff Muizelaar <jrmuizel at gmail dot com> ---
This can be especially valuable for pretty printers because sometimes alignof
is used for layout.

See:
https://github.com/rust-lang/rust/blob/master/src/libstd/collections/hash/table.rs#L778
--
You are receiving this mail because:
You are on the CC list for the bug.
tromey at sourceware dot org
2018-04-20 18:27:53 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=17095

--- Comment #2 from Tom Tromey <tromey at sourceware dot org> ---
Actually implementing alignof in the expression parser is tricky,
because normally the alignment is not specified in the debug info,
and gdb doesn't know about the ABI rules here.

Maybe mirroring DW_AT_alignment for pretty-printers would be good
enough. At least rustc seems to emit this for many things -- at
least all the structures I've looked at (though not pointer types
or base types... so maybe not as useful as I thought).
--
You are receiving this mail because:
You are on the CC list for the bug.
tromey at sourceware dot org
2018-04-20 18:30:35 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=17095

--- Comment #3 from Tom Tromey <tromey at sourceware dot org> ---
You can see what I did so far, here:

https://github.com/tromey/gdb/tree/submit/alignment

This just reads DW_AT_alignment.
--
You are receiving this mail because:
You are on the CC list for the bug.
tromey at sourceware dot org
2018-04-20 19:16:32 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=17095

--- Comment #4 from Tom Tromey <tromey at sourceware dot org> ---
We discussed this on #gdb and came up with this idea:

<tromey> so the current plan is something like: [13:08]
<tromey> use DW_AT_alignment if it exists
<tromey> else, for int/float/pointer types, use gdbarch, and update the
arch_*_type calls
<tromey> and for struct/union types, use the max alignment of the fields
--
You are receiving this mail because:
You are on the CC list for the bug.
tromey at sourceware dot org
2018-04-20 20:34:37 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=17095

Tom Tromey <tromey at sourceware dot org> changed:

What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at sourceware dot org |tromey at sourceware dot org

--- Comment #5 from Tom Tromey <tromey at sourceware dot org> ---
Time to admit I'm doing this.
--
You are receiving this mail because:
You are on the CC list for the bug.
tromey at sourceware dot org
2018-04-24 17:33:08 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=17095

--- Comment #6 from Tom Tromey <tromey at sourceware dot org> ---
Submitted: https://sourceware.org/ml/gdb-patches/2018-04/msg00466.html
--
You are receiving this mail because:
You are on the CC list for the bug.
cvs-commit at gcc dot gnu.org
2018-04-30 17:30:37 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=17095

--- Comment #7 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom Tromey <***@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=007e1530347330d4dbba387c4e35aae05bc06498

commit 007e1530347330d4dbba387c4e35aae05bc06498
Author: Tom Tromey <***@tromey.com>
Date: Fri Apr 20 13:40:29 2018 -0600

Handle alignof and _Alignof

This adds alignof and _Alignof to the C/C++ expression parser, and
adds new tests to test the features. The tests are written to try to
ensure that gdb's knowledge of alignment rules stays in sync with the
compiler's.

2018-04-30 Tom Tromey <***@tromey.com>

PR exp/17095:
* NEWS: Update.
* std-operator.def (UNOP_ALIGNOF): New operator.
* expprint.c (dump_subexp_body_standard) <case UNOP_ALIGNOF>:
New.
* eval.c (evaluate_subexp_standard) <case UNOP_ALIGNOF>: New.
* c-lang.c (c_op_print_tab): Add alignof.
* c-exp.y (ALIGNOF): New token.
(exp): Add "ALIGNOF" production.
(ident_tokens): Add _Alignof and alignof.

2018-04-30 Tom Tromey <***@tromey.com>

PR exp/17095:
* gdb.dwarf2/dw2-align.exp: New file.
* gdb.cp/align.exp: New file.
* gdb.base/align.exp: New file.
* lib/gdb.exp (gdb_int128_helper): New proc.
(has_int128_c, has_int128_cxx): New caching procs.
--
You are receiving this mail because:
You are on the CC list for the bug.
tromey at sourceware dot org
2018-04-30 12:00:58 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=17095

Tom Tromey <tromey at sourceware dot org> changed:

What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |8.2

--- Comment #8 from Tom Tromey <tromey at sourceware dot org> ---
Fixed.
--
You are receiving this mail because:
You are on the CC list for the bug.
Loading...