Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Misc simplifications.
[simgrid.git] / src / mc / inspect / mc_dwarf.cpp
index a6d44f92548aab942a25070537519109a505bb94..83444e45b6d55d24ccaa7ee0fbd1e303deb10066 100644 (file)
@@ -15,6 +15,8 @@
 #include "src/mc/mc_private.hpp"
 #include "src/mc/remote/RemoteSimulation.hpp"
 
+#include <algorithm>
+#include <array>
 #include <cinttypes>
 #include <cstdint>
 #include <cstdlib>
@@ -302,7 +304,7 @@ static uint64_t MC_dwarf_attr_integrate_uint(Dwarf_Die* die, int attribute, uint
 static bool MC_dwarf_attr_flag(Dwarf_Die* die, int attribute, bool integrate)
 {
   Dwarf_Attribute attr;
-  if ((integrate ? dwarf_attr_integrate(die, attribute, &attr) : dwarf_attr(die, attribute, &attr)) == 0)
+  if ((integrate ? dwarf_attr_integrate(die, attribute, &attr) : dwarf_attr(die, attribute, &attr)) == nullptr)
     return false;
 
   bool result;
@@ -380,7 +382,7 @@ static uint64_t MC_dwarf_subrange_element_count(Dwarf_Die* die, Dwarf_Die* unit)
   return upper_bound - lower_bound + 1;
 }
 
-/** @brief Finds the number of elements in a array type (DW_TAG_array_type)
+/** @brief Finds the number of elements in an array type (DW_TAG_array_type)
  *
  *  The compilation unit might be needed because the default lower
  *  bound depends on the language of the compilation unit.
@@ -961,11 +963,11 @@ static std::vector<char> get_build_id(Elf* elf)
   return std::vector<char>();
 }
 
-static char hexdigits[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
-
 /** Binary data to hexadecimal */
 static inline std::array<char, 2> to_hex(std::uint8_t byte)
 {
+  constexpr std::array<char, 16> hexdigits{
+      {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}};
   // Horrid double braces!
   // Apparently, this is needed in C++11 (not in C++14).
   return {{hexdigits[byte >> 4], hexdigits[byte & 0xF]}};
@@ -976,11 +978,8 @@ static std::string to_hex(const char* data, std::size_t count)
 {
   std::string res;
   res.resize(2 * count);
-  for (std::size_t i = 0; i < count; i++) {
-    std::array<char, 2> hex_byte = to_hex(data[i]);
-    for (int j = 0; j < 2; ++j)
-      res[2 * i + j] = hex_byte[j];
-  }
+  for (std::size_t i = 0; i < count; i++)
+    std::copy_n(cbegin(to_hex(data[i])), 2, &res[2 * i]);
   return res;
 }
 
@@ -991,7 +990,7 @@ static std::string to_hex(std::vector<char> const& data)
 }
 
 /** Base directories for external debug files */
-static const char* debug_paths[] = {
+static constexpr auto debug_paths = {
     "/usr/lib/debug/",
     "/usr/local/lib/debug/",
 };
@@ -1017,7 +1016,7 @@ static std::string find_by_build_id(std::vector<char> id)
       return filename;
     }
   }
-  XBT_DEBUG("Not debuf info found for build ID %s\n", hex.data());
+  XBT_DEBUG("No debug info found for build ID %s\n", hex.data());
   return std::string();
 }