blob: 9adf3ede71db0a7d638ed0e8a91598a7c430bed5 [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Helper functions for form handling.
2 Copyright (C) 2000, 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 <string.h>
21
22#include <libdwarfP.h>
23
24
25int
26internal_function
27__libdwarf_form_val_len (Dwarf_Debug dbg, Dwarf_CU_Info cu, Dwarf_Word form,
28 Dwarf_Small *valp, size_t *len, Dwarf_Error *error)
29{
30 Dwarf_Small *saved;
31 Dwarf_Word u128;
32
33 switch (form)
34 {
35 case DW_FORM_addr:
36 case DW_FORM_strp:
37 case DW_FORM_ref_addr:
38 *len = cu->address_size;
39 break;
40
41 case DW_FORM_block1:
42 *len = *valp + 1;
43 break;
44
45 case DW_FORM_block2:
46 *len = read_2ubyte_unaligned (dbg, valp) + 2;
47 break;
48
49 case DW_FORM_block4:
50 *len = read_4ubyte_unaligned (dbg, valp) + 4;
51 break;
52
53 case DW_FORM_block:
54 saved = valp;
55 get_uleb128 (u128, valp);
56 *len = u128 + (valp - saved);
57 break;
58
59 case DW_FORM_ref1:
60 case DW_FORM_data1:
61 case DW_FORM_flag:
62 *len = 1;
63 break;
64
65 case DW_FORM_data2:
66 case DW_FORM_ref2:
67 *len = 2;
68 break;
69
70 case DW_FORM_data4:
71 case DW_FORM_ref4:
72 *len = 4;
73 break;
74
75 case DW_FORM_data8:
76 case DW_FORM_ref8:
77 *len = 8;
78 break;
79
80 case DW_FORM_string:
81 *len = strlen ((char *) valp) + 1;
82 break;
83
84 case DW_FORM_sdata:
85 case DW_FORM_udata:
86 case DW_FORM_ref_udata:
87 saved = valp;
88 get_uleb128 (u128, valp);
89 *len = valp - saved;
90 break;
91
92 case DW_FORM_indirect:
93 saved = valp;
94 get_uleb128 (u128, valp);
95 if (__libdwarf_form_val_len (dbg, cu, u128, valp, len, error)
96 != DW_DLV_OK)
97 return DW_DLV_ERROR;
98 *len += valp - saved;
99 break;
100
101 default:
102 __libdwarf_error (dbg, error, DW_E_INVALID_DWARF);
103 return DW_DLV_ERROR;
104 }
105
106 return DW_DLV_OK;
107}