Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Redundant initializations.
[simgrid.git] / src / mc / inspect / mc_dwarf.cpp
index b9bee29..44ad73e 100644 (file)
@@ -103,8 +103,7 @@ static void MC_dwarf_handle_variable_die(simgrid::mc::ObjectInformation* info, D
  */
 static std::uint64_t MC_dwarf_at_type(Dwarf_Die* die);
 
-namespace simgrid {
-namespace dwarf {
+namespace simgrid::dwarf {
 
 enum class TagClass { Unknown, Type, Subprogram, Variable, Scope, Namespace };
 
@@ -204,8 +203,7 @@ inline XBT_PRIVATE const char* tagname(Dwarf_Die* die)
   return tagname(dwarf_tag(die));
 }
 
-} // namespace dwarf
-} // namespace simgrid
+} // namespace simgrid::dwarf
 
 // ***** Attributes
 
@@ -518,7 +516,7 @@ static simgrid::mc::Type MC_dwarf_die_to_type(simgrid::mc::ObjectInformation* in
   // Global Offset
   type.id = dwarf_dieoffset(die);
 
-  const char* prefix = "";
+  const char* prefix;
   switch (type.type) {
     case DW_TAG_structure_type:
       prefix = "struct ";
@@ -842,11 +840,9 @@ static void MC_dwarf_handle_die(simgrid::mc::ObjectInformation* info, Dwarf_Die*
 
 static Elf64_Half get_type(Elf* elf)
 {
-  const Elf64_Ehdr* ehdr64 = elf64_getehdr(elf);
-  if (ehdr64)
+  if (const Elf64_Ehdr* ehdr64 = elf64_getehdr(elf))
     return ehdr64->e_type;
-  const Elf32_Ehdr* ehdr32 = elf32_getehdr(elf);
-  if (ehdr32)
+  if (const Elf32_Ehdr* ehdr32 = elf32_getehdr(elf))
     return ehdr32->e_type;
   xbt_die("Could not get ELF heeader");
 }
@@ -859,8 +855,7 @@ static void read_dwarf_info(simgrid::mc::ObjectInformation* info, Dwarf* dwarf)
   size_t length;
 
   while (dwarf_nextcu(dwarf, offset, &next_offset, &length, nullptr, nullptr, nullptr) == 0) {
-    Dwarf_Die unit_die;
-    if (dwarf_offdie(dwarf, offset + length, &unit_die) != nullptr)
+    if (Dwarf_Die unit_die; dwarf_offdie(dwarf, offset + length, &unit_die) != nullptr)
       MC_dwarf_handle_children(info, &unit_die, &unit_die, nullptr, nullptr);
     offset = next_offset;
   }
@@ -963,8 +958,7 @@ static int find_by_build_id(std::vector<char> id)
     filename = std::string(debug_path) + ".build-id/" + to_hex(id.data(), 1) + '/' +
                to_hex(id.data() + 1, id.size() - 1) + ".debug";
     XBT_DEBUG("Checking debug file: %s", filename.c_str());
-    int fd = open(filename.c_str(), O_RDONLY);
-    if (fd != -1) {
+    if (int fd = open(filename.c_str(), O_RDONLY); fd != -1) {
       XBT_DEBUG("Found debug file: %s\n", hex.c_str());
       return fd;
     }
@@ -990,20 +984,17 @@ static void MC_load_dwarf(simgrid::mc::ObjectInformation* info)
   xbt_assert(elf != nullptr && elf_kind(elf) == ELF_K_ELF, "%s is not an ELF file", info->file_name.c_str());
 
   // Remember if this is a `ET_EXEC` (fixed location) or `ET_DYN`:
-  Elf64_Half type = get_type(elf);
-  if (type == ET_EXEC)
+  if (get_type(elf) == ET_EXEC)
     info->flags |= simgrid::mc::ObjectInformation::Executable;
 
   // Read DWARF debug information in the file:
-  Dwarf* dwarf = dwarf_begin_elf(elf, DWARF_C_READ, nullptr);
-  if (dwarf != nullptr) {
+  if (Dwarf* dwarf = dwarf_begin_elf(elf, DWARF_C_READ, nullptr)) {
     read_dwarf_info(info, dwarf);
     dwarf_end(dwarf);
     elf_end(elf);
     close(fd);
     return;
   }
-  dwarf_end(dwarf);
 
   // If there was no DWARF in the file, try to find it in a separate file.
   // Different methods might be used to store the DWARF information:
@@ -1014,8 +1005,7 @@ static void MC_load_dwarf(simgrid::mc::ObjectInformation* info)
 
   // Try with NT_GNU_BUILD_ID: we find the build ID in the ELF file and then
   // use this ID to find the file in some known locations in the filesystem.
-  std::vector<char> build_id = get_build_id(elf);
-  if (not build_id.empty()) {
+  if (std::vector<char> build_id = get_build_id(elf); not build_id.empty()) {
     elf_end(elf);
     close(fd);
 
@@ -1028,7 +1018,7 @@ static void MC_load_dwarf(simgrid::mc::ObjectInformation* info)
 
     // Load the DWARF info from this file:
     XBT_DEBUG("Load DWARF for %s", info->file_name.c_str());
-    dwarf = dwarf_begin(fd, DWARF_C_READ);
+    Dwarf* dwarf = dwarf_begin(fd, DWARF_C_READ);
     xbt_assert(dwarf != nullptr, "No DWARF info for %s", info->file_name.c_str());
     read_dwarf_info(info, dwarf);
     dwarf_end(dwarf);
@@ -1117,8 +1107,7 @@ static simgrid::mc::Type* MC_resolve_type(simgrid::mc::ObjectInformation* info,
 
   // Try to find a more complete description of the type:
   // We need to fix in order to support C++.
-  simgrid::mc::Type** subtype = simgrid::util::find_map_ptr(info->full_types_by_name, type->name);
-  if (subtype)
+  if (simgrid::mc::Type** subtype = simgrid::util::find_map_ptr(info->full_types_by_name, type->name))
     type = *subtype;
   return type;
 }
@@ -1133,8 +1122,7 @@ static void MC_post_process_types(simgrid::mc::ObjectInformation* info)
   }
 }
 
-namespace simgrid {
-namespace mc {
+namespace simgrid::mc {
 
 void ObjectInformation::ensure_dwarf_loaded()
 {
@@ -1187,11 +1175,9 @@ void postProcessObjectInformation(const RemoteProcess* process, ObjectInformatio
   }
 }
 
-} // namespace mc
-} // namespace simgrid
+} // namespace simgrid::mc
 
-namespace simgrid {
-namespace dwarf {
+namespace simgrid::dwarf {
 
 /** Convert a DWARF register into a libunwind register
  *
@@ -1220,5 +1206,4 @@ int dwarf_register_to_libunwind(int dwarf_register)
 #endif
 }
 
-} // namespace dwarf
-} // namespace simgrid
+} // namespace simgrid::dwarf