]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Move nested functions in dwarf_entry_breakpoints.c to file scope.
authorChih-Hung Hsieh <chh@google.com>
Wed, 14 Oct 2015 19:30:11 +0000 (12:30 -0700)
committerMark Wielaard <mjw@redhat.com>
Sat, 2 Jan 2016 13:26:34 +0000 (14:26 +0100)
No nested functions to compile with clang/llvm.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
libdw/ChangeLog
libdw/dwarf_entry_breakpoints.c

index 8fd77f40866b37d4083cdffa1fc9be811d49b419..d0f1de2137b386dfe9c05e80832e220c5b3c79f9 100644 (file)
@@ -1,3 +1,8 @@
+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
index abfee73c684cd84b35d5731c1ea8f23bed134aff..c3c0f3994528885496ef6ecda45643cacdd559ab 100644 (file)
 #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));
 }