1 /* Find entry breakpoint locations for a function.
2 Copyright (C) 2005-2009 Red Hat, Inc.
3 This file is part of elfutils.
5 This file is free software; you can redistribute it and/or modify
6 it under the terms of either
8 * the GNU Lesser General Public License as published by the Free
9 Software Foundation; either version 3 of the License, or (at
10 your option) any later version
14 * the GNU General Public License as published by the Free
15 Software Foundation; either version 2 of the License, or (at
16 your option) any later version
18 or both in parallel, as here.
20 elfutils is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received copies of the GNU General Public License and
26 the GNU Lesser General Public License along with this program. If
27 not, see <http://www.gnu.org/licenses/>. */
38 dwarf_entry_breakpoints (die, bkpts)
45 /* Add one breakpoint location to the result vector. */
46 inline int add_bkpt (Dwarf_Addr pc)
48 Dwarf_Addr *newlist = realloc (*bkpts, ++nbkpts * sizeof newlist[0]);
53 __libdw_seterrno (DWARF_E_NOMEM);
56 newlist[nbkpts - 1] = pc;
61 /* Fallback result, break at the entrypc/lowpc value. */
62 inline int entrypc_bkpt (void)
65 return INTUSE(dwarf_entrypc) (die, &pc) < 0 ? -1 : add_bkpt (pc);
68 /* Fetch the CU's line records to look for this DIE's addresses. */
69 Dwarf_Die cudie = CUDIE (die->cu);
72 if (INTUSE(dwarf_getsrclines) (&cudie, &lines, &nlines) < 0)
74 int error = INTUSE (dwarf_errno) ();
75 if (error == 0) /* CU has no DW_AT_stmt_list. */
76 return entrypc_bkpt ();
77 __libdw_seterrno (error);
81 /* Search a contiguous PC range for prologue-end markers.
82 If DWARF, look for proper markers.
83 Failing that, if ADHOC, look for the ad hoc convention. */
84 inline int search_range (Dwarf_Addr low, Dwarf_Addr high,
85 bool dwarf, bool adhoc)
87 size_t l = 0, u = nlines;
90 size_t idx = (l + u) / 2;
91 if (lines->info[idx].addr < low)
93 else if (lines->info[idx].addr > low)
95 else if (lines->info[idx].end_sequence)
106 for (size_t i = l; i < u && lines->info[i].addr < high; ++i)
107 if (lines->info[i].prologue_end
108 && add_bkpt (lines->info[i].addr) < 0)
110 if (adhoc && nbkpts == 0)
111 while (++l < nlines && lines->info[l].addr < high)
112 if (!lines->info[l].end_sequence)
113 return add_bkpt (lines->info[l].addr);
116 __libdw_seterrno (DWARF_E_INVALID_DWARF);
120 /* Search each contiguous address range for DWARF prologue_end markers. */
125 ptrdiff_t offset = INTUSE(dwarf_ranges) (die, 0, &base, &begin, &end);
129 /* Most often there is a single contiguous PC range for the DIE. */
131 return search_range (begin, end, true, true) ?: entrypc_bkpt ();
133 Dwarf_Addr lowpc = (Dwarf_Addr) -1l;
134 Dwarf_Addr highpc = (Dwarf_Addr) -1l;
137 /* We have an address range entry. */
138 if (search_range (begin, end, true, false) < 0)
147 offset = INTUSE(dwarf_ranges) (die, offset, &base, &begin, &end);
150 /* If we didn't find any proper DWARF markers, then look in the
151 lowest-addressed range for an ad hoc marker. Failing that,
152 fall back to just using the entrypc value. */
154 ?: (lowpc == (Dwarf_Addr) -1l ? 0
155 : search_range (lowpc, highpc, false, true))