[PATCH 35/59] libctf, dump: migrate towards dumping errors rather than truncation

Nick Alcock nick.alcock@oracle.com
Tue Jun 30 23:31:22 GMT 2020


If we get an error emitting a single type, variable, or label, right now
we emit the error into the ctf_dprintf stream and propagate the error
all the way up the stack, causing the entire output to be silently
truncated (unless libctf debugging is on).

Instead, emit an error and keep going.  (This makes sense for this use
case: if you're dumping types and a type is corrupted, you want to
know!)

Not all instances of this are fixed in this commit, only ones associated
with type formatting: more fixes will come.

libctf/
	* ctf-dump.c (ctf_dump_format_type): Emit a warning.
	(ctf_dump_label): Swallow errors from ctf_dump_format_type.
	(ctf_dump_objts): Likewise.
	(ctf_dump_var): Likewise.
	(ctf_dump_type): Do not emit a duplicate message.  Move to
	ctf_err_warning, and swallow all errors.
---
 libctf/ctf-dump.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libctf/ctf-dump.c b/libctf/ctf-dump.c
index 08d79f36d83..55aa496e8b7 100644
--- a/libctf/ctf-dump.c
+++ b/libctf/ctf-dump.c
@@ -169,6 +169,8 @@ ctf_dump_format_type (ctf_file_t *fp, ctf_id_t id, int flag)
  oom:
   ctf_set_errno (fp, errno);
  err:
+  ctf_err_warn (fp, 1, "Cannot format name dumping type 0x%lx: %s", id,
+		ctf_errmsg (ctf_errno (fp)));
   free (buf);
   free (str);
   free (bit);
@@ -318,7 +320,7 @@ ctf_dump_label (const char *name, const ctf_lblinfo_t *info,
 				       CTF_ADD_ROOT)) == NULL)
     {
       free (str);
-      return -1;			/* errno is set for us.  */
+      return 0;				/* Swallow the error.  */
     }
 
   str = str_append (str, typestr);
@@ -375,7 +377,7 @@ ctf_dump_objts (ctf_file_t *fp, ctf_dump_state_t *state)
 					   CTF_ADD_ROOT)) == NULL)
 	{
 	  free (str);
-	  return -1;			/* errno is set for us.  */
+	  return 0;			/* Swallow the error.  */
 	}
 
       str = str_append (str, typestr);
@@ -495,7 +497,7 @@ ctf_dump_var (const char *name, ctf_id_t type, void *arg)
 				       CTF_ADD_ROOT)) == NULL)
     {
       free (str);
-      return -1;			/* errno is set for us.  */
+      return 0;			/* Swallow the error.  */
     }
 
   str = str_append (str, typestr);
@@ -579,10 +581,7 @@ ctf_dump_type (ctf_id_t id, int flag, void *arg)
   size_t len;
 
   if ((str = ctf_dump_format_type (state->cds_fp, id, flag)) == NULL)
-    {
-      err = "format type";
-      goto err;
-    }
+    goto err_nomsg;		/* Error already logged for us.  */
 
   str = str_append (str, "\n");
   if ((ctf_type_visit (state->cds_fp, id, ctf_dump_member, &membstate)) < 0)
@@ -605,10 +604,11 @@ ctf_dump_type (ctf_id_t id, int flag, void *arg)
   return 0;
 
  err:
-  ctf_dprintf ("Cannot %s dumping type 0x%lx: %s\n", err, id,
-	       ctf_errmsg (ctf_errno (state->cds_fp)));
+  ctf_err_warn (state->cds_fp, 1, "Cannot %s dumping type 0x%lx: %s",
+		err, id, ctf_errmsg (ctf_errno (state->cds_fp)));
+ err_nomsg:
   free (str);
-  return -1;				/* errno is set for us.  */
+  return 0;				/* Swallow the error.  */
 }
 
 /* Dump the string table into the cds_items.  */
-- 
2.27.0.247.g3dff7de930



More information about the Binutils mailing list