Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame^] | 1 | /* Return location list entry. |
| 2 | Copyright (C) 2001, 2002 Red Hat, Inc. |
| 3 | Written by Ulrich Drepper <drepper@redhat.com>, 2001. |
| 4 | |
| 5 | This program is Open Source software; you can redistribute it and/or |
| 6 | modify it under the terms of the Open Software License version 1.0 as |
| 7 | published by the Open Source Initiative. |
| 8 | |
| 9 | You should have received a copy of the Open Software License along |
| 10 | with this program; if not, you may obtain a copy of the Open Software |
| 11 | License version 1.0 from http://www.opensource.org/licenses/osl.php or |
| 12 | by writing the Open Source Initiative c/o Lawrence Rosen, Esq., |
| 13 | 3001 King Ranch Road, Ukiah, CA 95482. */ |
| 14 | |
| 15 | #ifdef HAVE_CONFIG_H |
| 16 | # include <config.h> |
| 17 | #endif |
| 18 | |
| 19 | #include "libdwarfP.h" |
| 20 | |
| 21 | |
| 22 | int |
| 23 | dwarf_get_loclist_entry (dbg, offset, hipc_offset, lopc_offset, data, |
| 24 | entry_len, next_entry, error) |
| 25 | Dwarf_Debug dbg; |
| 26 | Dwarf_Unsigned offset; |
| 27 | Dwarf_Addr *hipc_offset; |
| 28 | Dwarf_Addr *lopc_offset; |
| 29 | Dwarf_Ptr *data; |
| 30 | Dwarf_Unsigned *entry_len; |
| 31 | Dwarf_Unsigned *next_entry; |
| 32 | Dwarf_Error *error; |
| 33 | { |
| 34 | Dwarf_Small *locp; |
| 35 | |
| 36 | /* Make sure we have room for at least two addresses. */ |
| 37 | if (unlikely (offset + 2 * dbg->cu_list->address_size |
| 38 | > dbg->sections[IDX_debug_loc].size)) |
| 39 | { |
| 40 | __libdwarf_error (dbg, error, DW_E_INVALID_DWARF); |
| 41 | return DW_DLV_ERROR; |
| 42 | } |
| 43 | |
| 44 | locp = (Dwarf_Small *) dbg->sections[IDX_debug_loc].addr + offset; |
| 45 | |
| 46 | /* Get the two values. */ |
| 47 | if (dbg->cu_list->address_size == 4) |
| 48 | { |
| 49 | *lopc_offset = read_4ubyte_unaligned (dbg, locp); |
| 50 | *hipc_offset = read_4ubyte_unaligned (dbg, locp + 4); |
| 51 | locp += 8; |
| 52 | offset += 8; |
| 53 | } |
| 54 | else |
| 55 | { |
| 56 | *lopc_offset = read_8ubyte_unaligned (dbg, locp); |
| 57 | *hipc_offset = read_8ubyte_unaligned (dbg, locp + 8); |
| 58 | locp += 16; |
| 59 | offset += 16; |
| 60 | } |
| 61 | |
| 62 | /* Does this signal the end? */ |
| 63 | if (*lopc_offset == 0 && *hipc_offset == 0) |
| 64 | return DW_DLV_OK; |
| 65 | |
| 66 | /* Make sure another 2 bytes are available for the length. */ |
| 67 | if (unlikely (offset + 2 > dbg->sections[IDX_debug_loc].size)) |
| 68 | { |
| 69 | __libdwarf_error (dbg, error, DW_E_INVALID_DWARF); |
| 70 | return DW_DLV_ERROR; |
| 71 | } |
| 72 | *entry_len = read_2ubyte_unaligned (dbg, locp); |
| 73 | locp += 2; |
| 74 | offset += 2; |
| 75 | *data = locp; |
| 76 | |
| 77 | /* Now we know how long the block is. Test whether that much |
| 78 | data is available. */ |
| 79 | if (unlikely (offset + *entry_len > dbg->sections[IDX_debug_loc].size)) |
| 80 | { |
| 81 | __libdwarf_error (dbg, error, DW_E_INVALID_DWARF); |
| 82 | return DW_DLV_ERROR; |
| 83 | } |
| 84 | |
| 85 | *next_entry = offset + *entry_len; |
| 86 | |
| 87 | return DW_DLV_OK; |
| 88 | } |