]> sourceware.org Git - libabigail.git/commitdiff
Add ABG_ASSERT_NOT_REACHED macro
authorDodji Seketeli <dodji@redhat.com>
Fri, 22 Jul 2016 12:56:58 +0000 (14:56 +0200)
committerDodji Seketeli <dodji@redhat.com>
Tue, 26 Jul 2016 18:04:23 +0000 (20:04 +0200)
Adding this macro to abort at places where the execution flow
shouldn't take us to.  Using this is more explicit (self-documented)
than using abort.

This patch replaces the use of abort() in abg-dwarf-reader.cc.

* include/abg-tools-utils.h (ABG_ASSERT_NOT_REACHED): New macro.
* src/abg-dwarf-reader.cc (stt_to_elf_symbol_type)
(stb_to_elf_symbol_binding, get_elf_class_size_in_bytes)
(build_ir_node_from_die): Use the new ABG_ASSERT_NOT_REACHED macro
in lieu of just calling abort().

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
include/abg-tools-utils.h
src/abg-dwarf-reader.cc

index e62dda06177a25315578c6af1d0c12819e6f6064..39caae6c049a00049f0aa1da8fa173e57aae0345 100644 (file)
@@ -210,6 +210,17 @@ std::tr1::shared_ptr<char>
 make_path_absolute(const char*p);
 
 extern const char* PRIVATE_TYPES_SUPPR_SPEC_NAME;
-
 }// end namespace tools_utils
+
+/// A macro that expands to aborting the program when executed.
+///
+/// Before aborting, the macro emits informatin about the source
+/// location where it was expanded.
+#define ABG_ASSERT_NOT_REACHED \
+  do {                                                                 \
+    std::cerr << "in " << __FUNCTION__                                 \
+             << " at: " << __FILE__ << ":" << __LINE__                 \
+             << ": execution should not have reached this point!\n";   \
+      abort();                                                         \
+  } while (false)
 }//end namespace abigail
index 008c42537212eee120e4f3c54d89446dde6d6c59..8e7b36fd177021fbe1be6a37fb8b9fbc8d9b7ed2 100644 (file)
@@ -296,7 +296,7 @@ stt_to_elf_symbol_type(unsigned char stt)
     default:
       // An unknown value that probably ought to be supported?  Let's
       // abort right here rather than yielding garbage.
-      abort();
+      ABG_ASSERT_NOT_REACHED;
     }
 
   return t;
@@ -330,7 +330,7 @@ stb_to_elf_symbol_binding(unsigned char stb)
       b = elf_symbol::GNU_UNIQUE_BINDING;
       break;
     default:
-      abort();
+      ABG_ASSERT_NOT_REACHED;
     }
 
   return b;
@@ -1381,7 +1381,7 @@ get_elf_class_size_in_bytes(Elf* elf_handle)
       result = 8;
       break;
     default:
-      abort();
+      ABG_ASSERT_NOT_REACHED;
     }
 
   return result;
@@ -9185,8 +9185,7 @@ build_ir_node_from_die(read_context&      ctxt,
       break;
     case DW_TAG_subrange_type:
       /* we shouldn't get here as this part is handled by build_array_type */
-      abort();
-      break;
+      ABG_ASSERT_NOT_REACHED;
     case DW_TAG_thrown_type:
       break;
     case DW_TAG_interface_type:
@@ -9201,8 +9200,7 @@ build_ir_node_from_die(read_context&      ctxt,
     case DW_TAG_compile_unit:
       // We shouldn't reach this point b/c this should be handled by
       // build_translation_unit.
-      abort();
-      break;
+      ABG_ASSERT_NOT_REACHED;
 
     case DW_TAG_namespace:
     case DW_TAG_module:
@@ -9374,8 +9372,7 @@ build_ir_node_from_die(read_context&      ctxt,
     case DW_TAG_formal_parameter:
       // We should not read this case as it should have been dealt
       // with by build_function_decl above.
-      abort();
-      break;
+      ABG_ASSERT_NOT_REACHED;
 
     case DW_TAG_constant:
       break;
@@ -9387,7 +9384,7 @@ build_ir_node_from_die(read_context&      ctxt,
       // For now, the DIEs under these are read lazily when they are
       // referenced by a public decl DIE that is under a
       // DW_TAG_compile_unit, so we shouldn't get here.
-      abort();
+      ABG_ASSERT_NOT_REACHED;
 
       // Other declaration we don't really intend to support yet.
     case DW_TAG_dwarf_procedure:
This page took 0.117966 seconds and 5 git commands to generate.