aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2loc.c
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/dwarf2loc.c
parentecfb656c37b982479d8eb07f240b434772d98fd6 (diff)
downloadgdb-9c5417255690af00751c7d506172459afe856894.zip
gdb-9c5417255690af00751c7d506172459afe856894.tar.gz
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/dwarf2loc.c')
-rw-r--r--gdb/dwarf2loc.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 93c45a7..127167d 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -42,6 +42,7 @@
#include <algorithm>
#include <vector>
#include <unordered_set>
+#include "common/underlying.h"
extern int dwarf_always_disassemble;
@@ -1191,7 +1192,7 @@ call_site_parameter_matches (struct call_site_parameter *parameter,
case CALL_SITE_PARAMETER_FB_OFFSET:
return kind_u.fb_offset == parameter->u.fb_offset;
case CALL_SITE_PARAMETER_PARAM_OFFSET:
- return kind_u.param_offset.cu_off == parameter->u.param_offset.cu_off;
+ return kind_u.param_cu_off == parameter->u.param_cu_off;
}
return 0;
}
@@ -2255,7 +2256,8 @@ indirect_pieced_value (struct value *value)
TYPE_LENGTH (type), byte_order);
byte_offset += piece->v.ptr.offset;
- return indirect_synthetic_pointer (piece->v.ptr.die, byte_offset, c->per_cu,
+ return indirect_synthetic_pointer (piece->v.ptr.die_sect_off,
+ byte_offset, c->per_cu,
frame, type);
}
@@ -2280,7 +2282,7 @@ coerce_pieced_ref (const struct value *value)
gdb_assert (closure != NULL);
gdb_assert (closure->n_pieces == 1);
- return indirect_synthetic_pointer (closure->pieces->v.ptr.die,
+ return indirect_synthetic_pointer (closure->pieces->v.ptr.die_sect_off,
closure->pieces->v.ptr.offset,
closure->per_cu, frame, type);
}
@@ -3642,12 +3644,11 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
{
struct dwarf2_locexpr_baton block;
int size = (op == DW_OP_call2 ? 2 : 4);
- cu_offset offset;
uoffset = extract_unsigned_integer (op_ptr, size, byte_order);
op_ptr += size;
- offset.cu_off = uoffset;
+ cu_offset offset = (cu_offset) uoffset;
block = dwarf2_fetch_die_loc_cu_off (offset, per_cu,
get_ax_pc, expr);
@@ -4192,15 +4193,15 @@ disassemble_dwarf_expression (struct ui_file *stream,
case DW_OP_GNU_deref_type:
{
int addr_size = *data++;
- cu_offset offset;
struct type *type;
data = safe_read_uleb128 (data, end, &ul);
- offset.cu_off = ul;
+ cu_offset offset = (cu_offset) ul;
type = dwarf2_get_die_type (offset, per_cu);
fprintf_filtered (stream, "<");
type_print (type, "", stream, -1);
- fprintf_filtered (stream, " [0x%s]> %d", phex_nz (offset.cu_off, 0),
+ fprintf_filtered (stream, " [0x%s]> %d",
+ phex_nz (to_underlying (offset), 0),
addr_size);
}
break;
@@ -4208,15 +4209,15 @@ disassemble_dwarf_expression (struct ui_file *stream,
case DW_OP_const_type:
case DW_OP_GNU_const_type:
{
- cu_offset type_die;
struct type *type;
data = safe_read_uleb128 (data, end, &ul);
- type_die.cu_off = ul;
+ cu_offset type_die = (cu_offset) ul;
type = dwarf2_get_die_type (type_die, per_cu);
fprintf_filtered (stream, "<");
type_print (type, "", stream, -1);
- fprintf_filtered (stream, " [0x%s]>", phex_nz (type_die.cu_off, 0));
+ fprintf_filtered (stream, " [0x%s]>",
+ phex_nz (to_underlying (type_die), 0));
}
break;
@@ -4224,18 +4225,17 @@ disassemble_dwarf_expression (struct ui_file *stream,
case DW_OP_GNU_regval_type:
{
uint64_t reg;
- cu_offset type_die;
struct type *type;
data = safe_read_uleb128 (data, end, &reg);
data = safe_read_uleb128 (data, end, &ul);
- type_die.cu_off = ul;
+ cu_offset type_die = (cu_offset) ul;
type = dwarf2_get_die_type (type_die, per_cu);
fprintf_filtered (stream, "<");
type_print (type, "", stream, -1);
fprintf_filtered (stream, " [0x%s]> [$%s]",
- phex_nz (type_die.cu_off, 0),
+ phex_nz (to_underlying (type_die), 0),
locexpr_regname (arch, reg));
}
break;
@@ -4245,12 +4245,10 @@ disassemble_dwarf_expression (struct ui_file *stream,
case DW_OP_reinterpret:
case DW_OP_GNU_reinterpret:
{
- cu_offset type_die;
-
data = safe_read_uleb128 (data, end, &ul);
- type_die.cu_off = ul;
+ cu_offset type_die = (cu_offset) ul;
- if (type_die.cu_off == 0)
+ if (to_underlying (type_die) == 0)
fprintf_filtered (stream, "<0>");
else
{
@@ -4259,7 +4257,8 @@ disassemble_dwarf_expression (struct ui_file *stream,
type = dwarf2_get_die_type (type_die, per_cu);
fprintf_filtered (stream, "<");
type_print (type, "", stream, -1);
- fprintf_filtered (stream, " [0x%s]>", phex_nz (type_die.cu_off, 0));
+ fprintf_filtered (stream, " [0x%s]>",
+ phex_nz (to_underlying (type_die), 0));
}
}
break;