No nested functions to compile with clang/llvm.

Signed-off-by: Chih-Hung Hsieh <c...@google.com>
---
 libdw/ChangeLog                 |   5 ++
 libdw/dwarf_entry_breakpoints.c | 110 +++++++++++++++++++++-------------------
 2 files changed, 64 insertions(+), 51 deletions(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 39c49aa..b91c8c7 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,8 @@
+2015-10-14  Chih-Hung Hsieh  <c...@google.com>
+
+       * dwarf_entry_breakpoints.c (dwarf_entry_breakpoints): Move recursive
+       functions 'add_bkpt', 'entrypc_bkpt', and 'search_range' to file scope.
+
 2015-10-09  Josh Stone  <jist...@redhat.com>
 
        * dwarf_begin.c (dwarf_begin): Replace stat64 and fstat64 with stat
diff --git a/libdw/dwarf_entry_breakpoints.c b/libdw/dwarf_entry_breakpoints.c
index abfee73..c3c0f39 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));
 }
-- 
2.6.0.rc2.230.g3dd15c0

Reply via email to