1 /* Get macro information.
2 Copyright (C) 2002-2009 Red Hat, Inc.
3 This file is part of elfutils.
4 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
6 This file is free software; you can redistribute it and/or modify
7 it under the terms of either
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
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
19 or both in parallel, as here.
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.
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/>. */
41 dwarf_getmacros (die, callback, arg, offset)
43 int (*callback) (Dwarf_Macro *, void *);
50 Elf_Data *d = die->cu->dbg->sectiondata[IDX_debug_macinfo];
51 if (unlikely (d == NULL) || unlikely (d->d_buf == NULL))
53 __libdw_seterrno (DWARF_E_NO_ENTRY);
59 /* Get the appropriate attribute. */
61 if (INTUSE(dwarf_attr) (die, DW_AT_macro_info, &attr) == NULL)
64 /* Offset into the .debug_macinfo section. */
66 if (INTUSE(dwarf_formudata) (&attr, &macoff) != 0)
71 if (unlikely (offset > (ptrdiff_t) d->d_size))
74 const unsigned char *readp = d->d_buf + offset;
75 const unsigned char *readendp = d->d_buf + d->d_size;
77 if (readp == readendp)
80 while (readp < readendp)
82 unsigned int opcode = *readp++;
84 unsigned int u128_2 = 0;
85 const char *str = NULL;
86 const unsigned char *endp;
90 case DW_MACINFO_define:
91 case DW_MACINFO_undef:
92 case DW_MACINFO_vendor_ext:
93 /* For the first two opcodes the parameters are
97 We can treat these cases together. */
98 get_uleb128 (u128, readp);
100 endp = memchr (readp, '\0', readendp - readp);
104 str = (char *) readp;
108 case DW_MACINFO_start_file:
109 /* The two parameters are line and file index. */
110 get_uleb128 (u128, readp);
111 get_uleb128 (u128_2, readp);
114 case DW_MACINFO_end_file:
115 /* No parameters for this one. */
120 /* Nothing more to do. */
131 mac.param2.u = u128_2;
135 if (callback (&mac, arg) != DWARF_CB_OK)
136 return readp - (const unsigned char *) d->d_buf;
139 /* If we come here the termination of the data for the CU is not
142 __libdw_seterrno (DWARF_E_INVALID_DWARF);