libctf: fix some tabdamage and move some code around
authorNick Alcock <nick.alcock@oracle.com>
Thu, 18 Mar 2021 12:37:52 +0000 (12:37 +0000)
committerNick Alcock <nick.alcock@oracle.com>
Thu, 18 Mar 2021 12:37:52 +0000 (12:37 +0000)
ctf-link.c is unnecessarily confusing because ctf_link_lazy_open is
positioned near functions that have nothing to do with opening files.

Move it around, and fix some tabdamage that's crept in lately.

libctf/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

* ctf-link.c (ctf_link_lazy_open): Move up in the file, to near
ctf_link_add_ctf.
* ctf-lookup.c (ctf_lookup_symbol_idx): Repair tabdamage.
(ctf_lookup_by_sym_or_name): Likewise.
* testsuite/libctf-lookup/struct-iteration.c: Likewise.
* testsuite/libctf-regression/type-add-unnamed-struct.c: Likewise.

libctf/ChangeLog
libctf/ctf-link.c
libctf/ctf-lookup.c
libctf/testsuite/libctf-lookup/struct-iteration.c
libctf/testsuite/libctf-regression/type-add-unnamed-struct.c

index f095c3e1e30ace882fec5942052d7128d9030075..cf78d8c6abcec4f2ab435fe66d5528d21df39761 100644 (file)
@@ -1,3 +1,12 @@
+2021-03-18  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-link.c (ctf_link_lazy_open): Move up in the file, to near
+       ctf_link_add_ctf.
+       * ctf-lookup.c (ctf_lookup_symbol_idx): Repair tabdamage.
+       (ctf_lookup_by_sym_or_name): Likewise.
+       * testsuite/libctf-lookup/struct-iteration.c: Likewise.
+       * testsuite/libctf-regression/type-add-unnamed-struct.c: Likewise.
+
 2021-03-02  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-create.c (symtypetab_density): Report the symbol name as
index 5471fccd0f7eb814b834562ad6dd9649e0964cc6..cc99f818970bf698e7a1a22b82236cb7877baa0d 100644 (file)
@@ -189,6 +189,52 @@ ctf_link_add_ctf (ctf_dict_t *fp, ctf_archive_t *ctf, const char *name)
   return ctf_link_add (fp, ctf, name, NULL, 0);
 }
 
+/* Lazily open a CTF archive for linking, if not already open.
+
+   Returns the number of files contained within the opened archive (0 for none),
+   or -1 on error, as usual.  */
+static ssize_t
+ctf_link_lazy_open (ctf_dict_t *fp, ctf_link_input_t *input)
+{
+  size_t count;
+  int err;
+
+  if (input->clin_arc)
+    return ctf_archive_count (input->clin_arc);
+
+  if (input->clin_fp)
+    return 1;
+
+  /* See ctf_link_add_ctf.  */
+#if defined (PIC) || !NOBFD
+  input->clin_arc = ctf_open (input->clin_filename, NULL, &err);
+#else
+  ctf_err_warn (fp, 0, ECTF_NEEDSBFD, _("cannot open %s lazily"),
+               input->clin_filename);
+  ctf_set_errno (fp, ECTF_NEEDSBFD);
+  return -1;
+#endif
+
+  /* Having no CTF sections is not an error.  We just don't need to do
+     anything.  */
+
+  if (!input->clin_arc)
+    {
+      if (err == ECTF_NOCTFDATA)
+       return 0;
+
+      ctf_err_warn (fp, 0, err, _("opening CTF %s failed"),
+                   input->clin_filename);
+      ctf_set_errno (fp, err);
+      return -1;
+    }
+
+  if ((count = ctf_archive_count (input->clin_arc)) == 0)
+    ctf_arc_close (input->clin_arc);
+
+  return (ssize_t) count;
+}
+
 /* Return a per-CU output CTF dictionary suitable for the given CU, creating and
    interning it if need be.  */
 
@@ -461,52 +507,6 @@ ctf_link_one_variable (ctf_dict_t *fp, ctf_dict_t *in_fp, const char *name,
   return 0;
 }
 
-/* Lazily open a CTF archive for linking, if not already open.
-
-   Returns the number of files contained within the opened archive (0 for none),
-   or -1 on error, as usual.  */
-static ssize_t
-ctf_link_lazy_open (ctf_dict_t *fp, ctf_link_input_t *input)
-{
-  size_t count;
-  int err;
-
-  if (input->clin_arc)
-    return ctf_archive_count (input->clin_arc);
-
-  if (input->clin_fp)
-    return 1;
-
-  /* See ctf_link_add_ctf.  */
-#if defined (PIC) || !NOBFD
-  input->clin_arc = ctf_open (input->clin_filename, NULL, &err);
-#else
-  ctf_err_warn (fp, 0, ECTF_NEEDSBFD, _("cannot open %s lazily"),
-               input->clin_filename);
-  ctf_set_errno (fp, ECTF_NEEDSBFD);
-  return -1;
-#endif
-
-  /* Having no CTF sections is not an error.  We just don't need to do
-     anything.  */
-
-  if (!input->clin_arc)
-    {
-      if (err == ECTF_NOCTFDATA)
-       return 0;
-
-      ctf_err_warn (fp, 0, err, _("opening CTF %s failed"),
-                   input->clin_filename);
-      ctf_set_errno (fp, err);
-      return -1;
-    }
-
-  if ((count = ctf_archive_count (input->clin_arc)) == 0)
-    ctf_arc_close (input->clin_arc);
-
-  return (ssize_t) count;
-}
-
 typedef struct link_sort_inputs_cb_arg
 {
   int is_cu_mapped;
index 6e17e5f4c54e6e7c5658e61dfce8cc48f75a5a4c..2e78cf492763af348d8a48d59e9353086aaaf10a 100644 (file)
@@ -592,9 +592,9 @@ ctf_lookup_symbol_idx (ctf_dict_t *fp, const char *symname)
                                       cache->ctf_symhash_latest) < 0)
                goto oom;
            if (strcmp (sym.st_name, symname) == 0)
-              return cache->ctf_symhash_latest++;
-          }
-          break;
+             return cache->ctf_symhash_latest++;
+         }
+         break;
        case sizeof (Elf32_Sym):
          {
            Elf32_Sym *symp = (Elf32_Sym *) sp->cts_data;
@@ -607,8 +607,8 @@ ctf_lookup_symbol_idx (ctf_dict_t *fp, const char *symname)
                                       cache->ctf_symhash_latest) < 0)
                goto oom;
            if (strcmp (sym.st_name, symname) == 0)
-              return cache->ctf_symhash_latest++;
-          }
+             return cache->ctf_symhash_latest++;
+         }
          break;
        default:
          ctf_set_errno (fp, ECTF_SYMTAB);
@@ -902,7 +902,7 @@ ctf_lookup_by_sym_or_name (ctf_dict_t *fp, unsigned long symidx,
          if (symidx > fp->ctf_dynsymmax)
            goto try_parent;
 
-          sym = fp->ctf_dynsymidx[symidx];
+         sym = fp->ctf_dynsymidx[symidx];
          err = ECTF_NOTYPEDAT;
          if (!sym || (sym->st_shndx != STT_OBJECT && sym->st_shndx != STT_FUNC))
            goto try_parent;
index 080edfadca40510b262baf9cd9aac0f731992c1e..005aba124d4c7b6c44568185656d88adc8a4b414 100644 (file)
@@ -4,13 +4,13 @@
 
 static int
 print_struct (const char *name, ctf_id_t membtype, unsigned long offset,
-              void *fp_)
+             void *fp_)
 {
   ctf_dict_t *fp = (ctf_dict_t *) fp_;
   char *type_name = ctf_type_aname (fp, membtype);
 
   printf ("iter test: %s, offset %lx, has type %lx/%s\n",
-          name, offset, membtype, type_name);
+         name, offset, membtype, type_name);
   free (type_name);
 
   return 0;
@@ -54,7 +54,7 @@ main (int argc, char *argv[])
       char *type_name = ctf_type_aname (fp, membtype);
 
       printf ("next test: %s, offset %lx, has type %lx/%s\n",
-              name, offset, membtype, type_name);
+             name, offset, membtype, type_name);
       free (type_name);
     }
   if (ctf_errno (fp) != ECTF_NEXT_END)
index 98be257991ab4e4b3d7702a380aa89481828e261..43c3934add4e48cd3aeb3a0c1406d9f0266562c0 100644 (file)
@@ -47,7 +47,7 @@ main (int argc, char *argv[])
   for (walk = membs; *walk != NULL; walk++)
     {
       if (ctf_member_info (dyn, newtype, *walk, &mi) < 0)
-        goto lookup_err;
+       goto lookup_err;
       printf ("Looked up %s, type %lx, offset %lx\n", *walk, (long) mi.ctm_type, mi.ctm_offset);
     }