+/* Until these have formal names, we define these here.
+ ref: http://gcc.gnu.org/wiki/DebugFission
+ Each entry in .debug_loc.dwo begins with a byte that describes the entry,
+ and is then followed by data specific to that entry. */
+
+enum debug_loc_kind
+{
+ /* Indicates the end of the list of entries. */
+ DEBUG_LOC_END_OF_LIST = 0,
+
+ /* This is followed by an unsigned LEB128 number that is an index into
+ .debug_addr and specifies the base address for all following entries. */
+ DEBUG_LOC_BASE_ADDRESS = 1,
+
+ /* This is followed by two unsigned LEB128 numbers that are indices into
+ .debug_addr and specify the beginning and ending addresses, and then
+ a normal location expression as in .debug_loc. */
+ DEBUG_LOC_START_END = 2,
+
+ /* This is followed by an unsigned LEB128 number that is an index into
+ .debug_addr and specifies the beginning address, and a 4 byte unsigned
+ number that specifies the length, and then a normal location expression
+ as in .debug_loc. */
+ DEBUG_LOC_START_LENGTH = 3,
+
+ /* An internal value indicating there is insufficient data. */
+ DEBUG_LOC_BUFFER_OVERFLOW = -1,
+
+ /* An internal value indicating an invalid kind of entry was found. */
+ DEBUG_LOC_INVALID_ENTRY = -2
+};
+
+/* Helper function which throws an error if a synthetic pointer is
+ invalid. */
+
+static void
+invalid_synthetic_pointer (void)
+{
+ error (_("access outside bounds of object "
+ "referenced via synthetic pointer"));
+}
+
+/* Decode the addresses in a non-dwo .debug_loc entry.
+ A pointer to the next byte to examine is returned in *NEW_PTR.
+ The encoded low,high addresses are return in *LOW,*HIGH.
+ The result indicates the kind of entry found. */
+
+static enum debug_loc_kind
+decode_debug_loc_addresses (const gdb_byte *loc_ptr, const gdb_byte *buf_end,
+ const gdb_byte **new_ptr,
+ CORE_ADDR *low, CORE_ADDR *high,
+ enum bfd_endian byte_order,
+ unsigned int addr_size,
+ int signed_addr_p)
+{
+ CORE_ADDR base_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
+
+ if (buf_end - loc_ptr < 2 * addr_size)
+ return DEBUG_LOC_BUFFER_OVERFLOW;
+
+ if (signed_addr_p)
+ *low = extract_signed_integer (loc_ptr, addr_size, byte_order);
+ else
+ *low = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
+ loc_ptr += addr_size;
+
+ if (signed_addr_p)
+ *high = extract_signed_integer (loc_ptr, addr_size, byte_order);
+ else
+ *high = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
+ loc_ptr += addr_size;
+
+ *new_ptr = loc_ptr;
+
+ /* A base-address-selection entry. */
+ if ((*low & base_mask) == base_mask)
+ return DEBUG_LOC_BASE_ADDRESS;
+
+ /* An end-of-list entry. */
+ if (*low == 0 && *high == 0)
+ return DEBUG_LOC_END_OF_LIST;
+
+ return DEBUG_LOC_START_END;
+}
+
+/* Decode the addresses in .debug_loc.dwo entry.
+ A pointer to the next byte to examine is returned in *NEW_PTR.
+ The encoded low,high addresses are return in *LOW,*HIGH.
+ The result indicates the kind of entry found. */
+
+static enum debug_loc_kind
+decode_debug_loc_dwo_addresses (struct dwarf2_per_cu_data *per_cu,
+ const gdb_byte *loc_ptr,
+ const gdb_byte *buf_end,
+ const gdb_byte **new_ptr,
+ CORE_ADDR *low, CORE_ADDR *high,
+ enum bfd_endian byte_order)
+{
+ uint64_t low_index, high_index;
+
+ if (loc_ptr == buf_end)
+ return DEBUG_LOC_BUFFER_OVERFLOW;
+
+ switch (*loc_ptr++)
+ {
+ case DEBUG_LOC_END_OF_LIST:
+ *new_ptr = loc_ptr;
+ return DEBUG_LOC_END_OF_LIST;
+ case DEBUG_LOC_BASE_ADDRESS:
+ *low = 0;
+ loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &high_index);
+ if (loc_ptr == NULL)
+ return DEBUG_LOC_BUFFER_OVERFLOW;
+ *high = dwarf2_read_addr_index (per_cu, high_index);
+ *new_ptr = loc_ptr;
+ return DEBUG_LOC_BASE_ADDRESS;
+ case DEBUG_LOC_START_END:
+ loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &low_index);
+ if (loc_ptr == NULL)
+ return DEBUG_LOC_BUFFER_OVERFLOW;
+ *low = dwarf2_read_addr_index (per_cu, low_index);
+ loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &high_index);
+ if (loc_ptr == NULL)
+ return DEBUG_LOC_BUFFER_OVERFLOW;
+ *high = dwarf2_read_addr_index (per_cu, high_index);
+ *new_ptr = loc_ptr;
+ return DEBUG_LOC_START_END;
+ case DEBUG_LOC_START_LENGTH:
+ loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &low_index);
+ if (loc_ptr == NULL)
+ return DEBUG_LOC_BUFFER_OVERFLOW;
+ *low = dwarf2_read_addr_index (per_cu, low_index);
+ if (loc_ptr + 4 > buf_end)
+ return DEBUG_LOC_BUFFER_OVERFLOW;
+ *high = *low;
+ *high += extract_unsigned_integer (loc_ptr, 4, byte_order);
+ *new_ptr = loc_ptr + 4;
+ return DEBUG_LOC_START_LENGTH;
+ default:
+ return DEBUG_LOC_INVALID_ENTRY;
+ }
+}
+