Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame^] | 1 | /* Get abbreviation record. |
| 2 | Copyright (C) 2000, 2001, 2002 Red Hat, Inc. |
| 3 | Written by Ulrich Drepper <drepper@redhat.com>, 2000. |
| 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 <dwarf.h> |
| 20 | #include <stdlib.h> |
| 21 | |
| 22 | #include <libdwarfP.h> |
| 23 | |
| 24 | |
| 25 | int |
| 26 | dwarf_get_abbrev (dbg, offset, return_abbrev, length, attr_count, error) |
| 27 | Dwarf_Debug dbg; |
| 28 | Dwarf_Unsigned offset; |
| 29 | Dwarf_Abbrev *return_abbrev; |
| 30 | Dwarf_Unsigned *length; |
| 31 | Dwarf_Unsigned *attr_count; |
| 32 | Dwarf_Error *error; |
| 33 | { |
| 34 | Dwarf_Abbrev ent; |
| 35 | Dwarf_Small *abbrevp; |
| 36 | Dwarf_Small *start_abbrevp; |
| 37 | |
| 38 | /* Address in memory. */ |
| 39 | abbrevp = (Dwarf_Small *) dbg->sections[IDX_debug_abbrev].addr + offset; |
| 40 | |
| 41 | /* Remember where we started. */ |
| 42 | start_abbrevp = abbrevp; |
| 43 | |
| 44 | if (*abbrevp != '\0') |
| 45 | { |
| 46 | /* 7.5.3 Abbreviations Tables |
| 47 | |
| 48 | [...] Each declaration begins with an unsigned LEB128 number |
| 49 | representing the abbreviation code itself. [...] The |
| 50 | abbreviation code is followed by another unsigned LEB128 |
| 51 | number that encodes the entry's tag. [...] |
| 52 | |
| 53 | [...] Following the tag encoding is a 1-byte value that |
| 54 | determines whether a debugging information entry using this |
| 55 | abbreviation has child entries or not. [...] |
| 56 | |
| 57 | [...] Finally, the child encoding is followed by a series of |
| 58 | attribute specifications. Each attribute specification |
| 59 | consists of two parts. The first part is an unsigned LEB128 |
| 60 | number representing the attribute's name. The second part is |
| 61 | an unsigned LEB128 number representing the attribute s form. */ |
| 62 | Dwarf_Word abbrev_code; |
| 63 | Dwarf_Word abbrev_tag; |
| 64 | Dwarf_Word attr_name; |
| 65 | Dwarf_Word attr_form; |
| 66 | Dwarf_Unsigned attrcnt; |
| 67 | |
| 68 | /* XXX We have no tests for crossing the section boundary here. |
| 69 | We should compare with dbg->sections[IDX_debug_abbrev].size. */ |
| 70 | get_uleb128 (abbrev_code, abbrevp); |
| 71 | get_uleb128 (abbrev_tag, abbrevp); |
| 72 | |
| 73 | /* Get memory for the result. */ |
| 74 | ent = (Dwarf_Abbrev) malloc (sizeof (struct Dwarf_Abbrev_s)); |
| 75 | if (ent == NULL) |
| 76 | { |
| 77 | __libdwarf_error (dbg, error, DW_E_NOMEM); |
| 78 | return DW_DLV_ERROR; |
| 79 | } |
| 80 | |
| 81 | ent->code = abbrev_code; |
| 82 | ent->tag = abbrev_tag; |
| 83 | ent->has_children = *abbrevp++ == DW_CHILDREN_yes; |
| 84 | ent->attrp = abbrevp; |
| 85 | ent->offset = offset; |
| 86 | |
| 87 | /* Skip over all the attributes. */ |
| 88 | attrcnt = 0; |
| 89 | do |
| 90 | { |
| 91 | get_uleb128 (attr_name, abbrevp); |
| 92 | get_uleb128 (attr_form, abbrevp); |
| 93 | } |
| 94 | while (attr_name != 0 && attr_form != 0 && ++attrcnt); |
| 95 | |
| 96 | /* Number of attributes. */ |
| 97 | *attr_count = ent->attrcnt = attrcnt; |
| 98 | |
| 99 | /* Store the actual abbreviation record. */ |
| 100 | *return_abbrev = ent; |
| 101 | } |
| 102 | else |
| 103 | /* Read over the NUL byte. */ |
| 104 | ++abbrevp; |
| 105 | |
| 106 | /* Length of the entry. */ |
| 107 | *length = abbrevp - start_abbrevp; |
| 108 | |
| 109 | /* If we come here we haven't found anything. */ |
| 110 | return DW_DLV_OK; |
| 111 | } |