Branch data Line data Source code
1 : : /* Return signed constant represented by attribute.
2 : : Copyright (C) 2003, 2005 Red Hat, Inc.
3 : : This file is part of elfutils.
4 : : Written by Ulrich Drepper <drepper@redhat.com>, 2003.
5 : :
6 : : This file is free software; you can redistribute it and/or modify
7 : : it under the terms of either
8 : :
9 : : * the GNU Lesser General Public License as published by the Free
10 : : Software Foundation; either version 3 of the License, or (at
11 : : your option) any later version
12 : :
13 : : or
14 : :
15 : : * the GNU General Public License as published by the Free
16 : : Software Foundation; either version 2 of the License, or (at
17 : : your option) any later version
18 : :
19 : : or both in parallel, as here.
20 : :
21 : : elfutils is distributed in the hope that it will be useful, but
22 : : WITHOUT ANY WARRANTY; without even the implied warranty of
23 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 : : General Public License for more details.
25 : :
26 : : You should have received copies of the GNU General Public License and
27 : : the GNU Lesser General Public License along with this program. If
28 : : not, see <http://www.gnu.org/licenses/>. */
29 : :
30 : : #ifdef HAVE_CONFIG_H
31 : : # include <config.h>
32 : : #endif
33 : :
34 : : #include <dwarf.h>
35 : : #include "libdwP.h"
36 : :
37 : :
38 : : int
39 : 28 : dwarf_formsdata (attr, return_sval)
40 : : Dwarf_Attribute *attr;
41 : : Dwarf_Sword *return_sval;
42 : : {
43 [ + - ]: 28 : if (attr == NULL)
44 : : return -1;
45 : :
46 : : const unsigned char *datap;
47 : :
48 [ + + - - : 28 : switch (attr->form)
- - - ]
49 : : {
50 : : case DW_FORM_data1:
51 : 25 : *return_sval = *attr->valp;
52 : 25 : break;
53 : :
54 : : case DW_FORM_data2:
55 [ - + ][ # # ]: 3 : *return_sval = read_2ubyte_unaligned (attr->cu->dbg, attr->valp);
56 : 3 : break;
57 : :
58 : : case DW_FORM_data4:
59 [ # # ][ # # ]: 0 : *return_sval = read_4ubyte_unaligned (attr->cu->dbg, attr->valp);
60 : 0 : break;
61 : :
62 : : case DW_FORM_data8:
63 [ # # ][ # # ]: 0 : *return_sval = read_8ubyte_unaligned (attr->cu->dbg, attr->valp);
64 : 0 : break;
65 : :
66 : : case DW_FORM_sdata:
67 : 0 : datap = attr->valp;
68 [ # # ]: 0 : get_sleb128 (*return_sval, datap);
69 : : break;
70 : :
71 : : case DW_FORM_udata:
72 : 0 : datap = attr->valp;
73 [ # # ]: 0 : get_uleb128 (*return_sval, datap);
74 : : break;
75 : :
76 : : default:
77 : 28 : __libdw_seterrno (DWARF_E_NO_CONSTANT);
78 : : return -1;
79 : : }
80 : :
81 : : return 0;
82 : : }
83 : : INTDEF(dwarf_formsdata)
|