From 619d9aaf011c975159a79d34259083a596162bf1 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 7 Jul 2009 14:35:10 +0200 Subject: Add support for constant struct member field offsets. * loc2c.h (c_translate_add_offset): New function prototype. * loc2c.c (c_translate_add_offset): New function implementation. * loc2c-test.c (handle_variable): Use c_translate_add_offset if appropriate. * dwflpp.cxx (translate_location): Likewise. --- loc2c.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'loc2c.c') diff --git a/loc2c.c b/loc2c.c index f95400bb..5f4e4495 100644 --- a/loc2c.c +++ b/loc2c.c @@ -1669,7 +1669,38 @@ c_translate_pointer_store (struct obstack *pool, int indent, } +/* Translate a fragment to add an offset to the currently calculated + address of the input location. Used for struct fields. Only works + when location is already an actual base address. +*/ +void +c_translate_add_offset (struct obstack *pool, int indent, const char *comment, + Dwarf_Sword off, struct location **input) +{ + indent++; + if (comment == NULL || comment[0] == '\0') + comment = "field offset"; + switch ((*input)->type) + { + case loc_address: + obstack_printf (pool, "%*saddr += " SFORMAT "; // %s\n", + indent * 2 + 2, "", off, comment); + *input = (*input)->next = new_synthetic_loc (pool, *input, false); + break; + + case loc_register: + FAIL (*input, N_("cannot add offset of object in register")); + break; + case loc_noncontiguous: + FAIL (*input, N_("cannot add offset of noncontiguous object")); + break; + + default: + abort (); + break; + } +} /* Determine the element stride of an array type. */ static Dwarf_Word -- cgit