aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2expr.h
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2017-04-04 20:03:26 +0100
committerPedro Alves <palves@redhat.com>2017-04-04 20:03:26 +0100
commit9c5417255690af00751c7d506172459afe856894 (patch)
tree8d6da311b5442e8add81838cb178eb1aba8ad13d /gdb/dwarf2expr.h
parentecfb656c37b982479d8eb07f240b434772d98fd6 (diff)
downloadfsf-binutils-gdb-9c5417255690af00751c7d506172459afe856894.zip
fsf-binutils-gdb-9c5417255690af00751c7d506172459afe856894.tar.gz
fsf-binutils-gdb-9c5417255690af00751c7d506172459afe856894.tar.bz2
Make sect_offset and cu_offset strong typedefs instead of structs
A while ago, back when GDB was a C program, the sect_offset and cu_offset types were made structs in order to prevent incorrect mixing of those offsets. Now that we require C++11, we can make them integers again, while keeping the safety, by exploiting "enum class". We can add a bit more safety, even, by defining operators that the types _should_ support, helping making the suspicious uses stand out more. Getting at the underlying type is done with the new to_underlying function added by the previous patch, which also helps better spot where do we need to step out of the safety net. Mostly, that's around parsing the DWARF, and when we print the offset for complaint/debug purposes. But there are other occasional uses. Since we have to define the sect_offset/cu_offset types in a header anyway, I went ahead and generalized/library-fied the idea of "offset" types, making it trivial to add more such types if we find a use. See common/offset-type.h and the DEFINE_OFFSET_TYPE macro. I needed a couple generaly-useful preprocessor bits (e.g., yet another CONCAT implementation), so I started a new common/preprocessor.h file. I included units tests covering the "offset" types API. These are mostly compile-time tests, using SFINAE to check that expressions that shouldn't compile (e.g., comparing unrelated offset types) really are invalid and would fail to compile. This same idea appeared in my pending enum-flags revamp from a few months ago (though this version is a bit further modernized compared to what I had posted), and I plan on reusing the "check valid expression" bits added here in that series, so I went ahead and defined the CHECK_VALID_EXPR macro in its own header -- common/valid-expr.h. I think that's nicer regardless. I was borderline between calling the new types "offset" types, or "index" types, BTW. I stuck with "offset" simply because that's what we're already calling them, mostly. gdb/ChangeLog: 2017-04-04 Pedro Alves <palves@redhat.com> * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add unittests/offset-type-selftests.c. (SUBDIR_UNITTESTS_OBS): Add offset-type-selftests.o. * common/offset-type.h: New file. * common/preprocessor.h: New file. * common/traits.h: New file. * common/valid-expr.h: New file. * dwarf2expr.c: Include "common/underlying.h". Adjust to use sect_offset and cu_offset strong typedefs throughout. * dwarf2expr.h: Adjust to use sect_offset and cu_offset strong typedefs throughout. * dwarf2loc.c: Include "common/underlying.h". Adjust to use sect_offset and cu_offset strong typedefs throughout. * dwarf2read.c: Adjust to use sect_offset and cu_offset strong typedefs throughout. * gdbtypes.h: Include "common/offset-type.h". (cu_offset): Now an offset type (strong typedef) instead of a struct. (sect_offset): Likewise. (union call_site_parameter_u): Rename "param_offset" field to "param_cu_off". * unittests/offset-type-selftests.c: New file.
Diffstat (limited to 'gdb/dwarf2expr.h')
-rw-r--r--gdb/dwarf2expr.h16
1 files changed, 8 insertions, 8 deletions
diff --git a/gdb/dwarf2expr.h b/gdb/dwarf2expr.h
index 2df310f..7df697d 100644
--- a/gdb/dwarf2expr.h
+++ b/gdb/dwarf2expr.h
@@ -172,16 +172,16 @@ struct dwarf_expr_context
virtual CORE_ADDR get_tls_address (CORE_ADDR offset) = 0;
/* Execute DW_AT_location expression for the DWARF expression
- subroutine in the DIE at DIE_OFFSET in the CU. Do not touch
+ subroutine in the DIE at DIE_CU_OFF in the CU. Do not touch
STACK while it being passed to and returned from the called DWARF
subroutine. */
- virtual void dwarf_call (cu_offset die_offset) = 0;
+ virtual void dwarf_call (cu_offset die_cu_off) = 0;
- /* Return the base type given by the indicated DIE. This can throw
- an exception if the DIE is invalid or does not represent a base
- type. SIZE is non-zero if this function should verify that the
- resulting type has the correct size. */
- virtual struct type *get_base_type (cu_offset die, int size)
+ /* Return the base type given by the indicated DIE at DIE_CU_OFF.
+ This can throw an exception if the DIE is invalid or does not
+ represent a base type. SIZE is non-zero if this function should
+ verify that the resulting type has the correct size. */
+ virtual struct type *get_base_type (cu_offset die_cu_off, int size)
{
/* Anything will do. */
return builtin_type (this->gdbarch)->builtin_int;
@@ -249,7 +249,7 @@ struct dwarf_expr_piece
struct
{
/* The referent DIE from DW_OP_implicit_pointer. */
- sect_offset die;
+ sect_offset die_sect_off;
/* The byte offset into the resulting data. */
LONGEST offset;
} ptr;