summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChih-Hung Hsieh <chh@google.com>2015-10-14 12:30:11 -0700
committerMark Wielaard <mjw@redhat.com>2016-01-02 14:26:34 +0100
commite0b020fd1bdff5c503b31e8de9f5c2b3a50707e5 (patch)
tree705bdbc435a40491767942698bb671c9ab75927e
parent454a82803be4694d40942c533bc0b2485d9e264d (diff)
downloadelfutils-e0b020fd1bdff5c503b31e8de9f5c2b3a50707e5.tar.gz
Move nested functions in dwarf_entry_breakpoints.c to file scope.
No nested functions to compile with clang/llvm. Signed-off-by: Chih-Hung Hsieh <chh@google.com>
-rw-r--r--libdw/ChangeLog5
-rw-r--r--libdw/dwarf_entry_breakpoints.c110
2 files changed, 64 insertions, 51 deletions
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 8fd77f40..d0f1de21 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,10 @@
2015-10-14 Chih-Hung Hsieh <chh@google.com>
+ * dwarf_entry_breakpoints.c (dwarf_entry_breakpoints): Move recursive
+ functions 'add_bkpt', 'entrypc_bkpt', and 'search_range' to file scope.
+
+2015-10-14 Chih-Hung Hsieh <chh@google.com>
+
* libdw_visit_scopes.c (__libdw_visit_scopes): Move recursive nested
function 'walk_children' to file scope; inline 'recurse' at its call
site.
diff --git a/libdw/dwarf_entry_breakpoints.c b/libdw/dwarf_entry_breakpoints.c
index abfee73c..c3c0f399 100644
--- a/libdw/dwarf_entry_breakpoints.c
+++ b/libdw/dwarf_entry_breakpoints.c
@@ -34,54 +34,40 @@
#include <stdlib.h>
-int
-dwarf_entry_breakpoints (Dwarf_Die *die, Dwarf_Addr **bkpts)
+/* Add one breakpoint location to the result vector. */
+static inline int
+add_bkpt (Dwarf_Addr pc, Dwarf_Addr **bkpts, int *pnbkpts)
{
- int nbkpts = 0;
- *bkpts = NULL;
-
- /* Add one breakpoint location to the result vector. */
- inline int add_bkpt (Dwarf_Addr pc)
- {
- Dwarf_Addr *newlist = realloc (*bkpts, ++nbkpts * sizeof newlist[0]);
- if (newlist == NULL)
- {
- free (*bkpts);
- *bkpts = NULL;
- __libdw_seterrno (DWARF_E_NOMEM);
- return -1;
- }
- newlist[nbkpts - 1] = pc;
- *bkpts = newlist;
- return nbkpts;
- }
-
- /* Fallback result, break at the entrypc/lowpc value. */
- inline int entrypc_bkpt (void)
+ Dwarf_Addr *newlist = realloc (*bkpts, ++(*pnbkpts) * sizeof newlist[0]);
+ if (newlist == NULL)
{
- Dwarf_Addr pc;
- return INTUSE(dwarf_entrypc) (die, &pc) < 0 ? -1 : add_bkpt (pc);
- }
-
- /* Fetch the CU's line records to look for this DIE's addresses. */
- Dwarf_Die cudie = CUDIE (die->cu);
- Dwarf_Lines *lines;
- size_t nlines;
- if (INTUSE(dwarf_getsrclines) (&cudie, &lines, &nlines) < 0)
- {
- int error = INTUSE (dwarf_errno) ();
- if (error == 0) /* CU has no DW_AT_stmt_list. */
- return entrypc_bkpt ();
- __libdw_seterrno (error);
+ free (*bkpts);
+ *bkpts = NULL;
+ __libdw_seterrno (DWARF_E_NOMEM);
return -1;
}
+ newlist[*pnbkpts - 1] = pc;
+ *bkpts = newlist;
+ return *pnbkpts;
+}
- /* Search a contiguous PC range for prologue-end markers.
- If DWARF, look for proper markers.
- Failing that, if ADHOC, look for the ad hoc convention. */
- inline int search_range (Dwarf_Addr low, Dwarf_Addr high,
- bool dwarf, bool adhoc)
- {
+/* Fallback result, break at the entrypc/lowpc value. */
+static inline int
+entrypc_bkpt (Dwarf_Die *die, Dwarf_Addr **bkpts, int *pnbkpts)
+{
+ Dwarf_Addr pc;
+ return INTUSE(dwarf_entrypc) (die, &pc) < 0 ? -1 : add_bkpt (pc, bkpts, pnbkpts);
+}
+
+/* Search a contiguous PC range for prologue-end markers.
+ If DWARF, look for proper markers.
+ Failing that, if ADHOC, look for the ad hoc convention. */
+static inline int
+search_range (Dwarf_Addr low, Dwarf_Addr high,
+ bool dwarf, bool adhoc,
+ Dwarf_Lines *lines, size_t nlines,
+ Dwarf_Addr **bkpts, int *pnbkpts)
+{
size_t l = 0, u = nlines;
while (l < u)
{
@@ -103,16 +89,35 @@ dwarf_entry_breakpoints (Dwarf_Die *die, Dwarf_Addr **bkpts)
if (dwarf)
for (size_t i = l; i < u && lines->info[i].addr < high; ++i)
if (lines->info[i].prologue_end
- && add_bkpt (lines->info[i].addr) < 0)
+ && add_bkpt (lines->info[i].addr, bkpts, pnbkpts) < 0)
return -1;
- if (adhoc && nbkpts == 0)
+ if (adhoc && *pnbkpts == 0)
while (++l < nlines && lines->info[l].addr < high)
if (!lines->info[l].end_sequence)
- return add_bkpt (lines->info[l].addr);
- return nbkpts;
+ return add_bkpt (lines->info[l].addr, bkpts, pnbkpts);
+ return *pnbkpts;
}
__libdw_seterrno (DWARF_E_INVALID_DWARF);
return -1;
+}
+
+int
+dwarf_entry_breakpoints (Dwarf_Die *die, Dwarf_Addr **bkpts)
+{
+ int nbkpts = 0;
+ *bkpts = NULL;
+
+ /* Fetch the CU's line records to look for this DIE's addresses. */
+ Dwarf_Die cudie = CUDIE (die->cu);
+ Dwarf_Lines *lines;
+ size_t nlines;
+ if (INTUSE(dwarf_getsrclines) (&cudie, &lines, &nlines) < 0)
+ {
+ int error = INTUSE (dwarf_errno) ();
+ if (error == 0) /* CU has no DW_AT_stmt_list. */
+ return entrypc_bkpt (die, bkpts, &nbkpts);
+ __libdw_seterrno (error);
+ return -1;
}
/* Search each contiguous address range for DWARF prologue_end markers. */
@@ -126,14 +131,16 @@ dwarf_entry_breakpoints (Dwarf_Die *die, Dwarf_Addr **bkpts)
/* Most often there is a single contiguous PC range for the DIE. */
if (offset == 1)
- return search_range (begin, end, true, true) ?: entrypc_bkpt ();
+ return search_range (begin, end, true, true, lines, nlines, bkpts, &nbkpts)
+ ?: entrypc_bkpt (die, bkpts, &nbkpts);
Dwarf_Addr lowpc = (Dwarf_Addr) -1l;
Dwarf_Addr highpc = (Dwarf_Addr) -1l;
while (offset > 0)
{
/* We have an address range entry. */
- if (search_range (begin, end, true, false) < 0)
+ if (search_range (begin, end, true, false,
+ lines, nlines, bkpts, &nbkpts) < 0)
return -1;
if (begin < lowpc)
@@ -150,6 +157,7 @@ dwarf_entry_breakpoints (Dwarf_Die *die, Dwarf_Addr **bkpts)
fall back to just using the entrypc value. */
return (nbkpts
?: (lowpc == (Dwarf_Addr) -1l ? 0
- : search_range (lowpc, highpc, false, true))
- ?: entrypc_bkpt ());
+ : search_range (lowpc, highpc, false, true,
+ lines, nlines, bkpts, &nbkpts))
+ ?: entrypc_bkpt (die, bkpts, &nbkpts));
}