Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
[simgrid.git] / src / mc / inspect / mc_dwarf.cpp
index 553ec19..094635d 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008-2022. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2008-2023. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -13,7 +13,7 @@
 #include "src/mc/inspect/Variable.hpp"
 #include "src/mc/inspect/mc_dwarf.hpp"
 #include "src/mc/mc_private.hpp"
-#include "src/mc/remote/RemoteProcess.hpp"
+#include "src/mc/sosp/RemoteProcessMemory.hpp"
 
 #include <algorithm>
 #include <array>
@@ -510,13 +510,13 @@ static simgrid::mc::Type MC_dwarf_die_to_type(simgrid::mc::ObjectInformation* in
 {
   simgrid::mc::Type type;
   type.type          = dwarf_tag(die);
-  type.name          = std::string();
+  type.name          = "";
   type.element_count = -1;
 
   // Global Offset
   type.id = dwarf_dieoffset(die);
 
-  const char* prefix = "";
+  const char* prefix;
   switch (type.type) {
     case DW_TAG_structure_type:
       prefix = "struct ";
@@ -677,7 +677,7 @@ static std::unique_ptr<simgrid::mc::Variable> MC_die_to_variable(simgrid::mc::Ob
   }
 
   if (ns && variable->global)
-    variable->name = std::string(ns) + "::" + variable->name;
+    variable->name.insert(0, std::string(ns) + "::");
 
   // The current code needs a variable name,
   // generate a fake one:
@@ -869,7 +869,7 @@ static void read_dwarf_info(simgrid::mc::ObjectInformation* info, Dwarf* dwarf)
  *  @param  elf libelf handle for an ELF file
  *  @return build-id for this ELF file (or an empty vector if none is found)
  */
-static std::vector<char> get_build_id(Elf* elf)
+static std::vector<std::byte> get_build_id(Elf* elf)
 {
 #ifdef __linux
   // Summary: the GNU build ID is stored in a ("GNU, NT_GNU_BUILD_ID) note
@@ -898,30 +898,28 @@ static std::vector<char> get_build_id(Elf* elf)
       // A build ID note is identified by the pair ("GNU", NT_GNU_BUILD_ID)
       // (a namespace and a type within this namespace):
       if (nhdr.n_type == NT_GNU_BUILD_ID && nhdr.n_namesz == sizeof("GNU") &&
-          memcmp((char*)data->d_buf + name_pos, "GNU", sizeof("GNU")) == 0) {
+          memcmp(static_cast<std::byte*>(data->d_buf) + name_pos, "GNU", sizeof("GNU")) == 0) {
         XBT_DEBUG("Found GNU/NT_GNU_BUILD_ID note");
-        char* start = (char*)data->d_buf + desc_pos;
-        char* end   = start + nhdr.n_descsz;
-        return std::vector<char>(start, end);
+        std::byte* start = static_cast<std::byte*>(data->d_buf) + desc_pos;
+        std::byte* end   = start + nhdr.n_descsz;
+        return std::vector<std::byte>(start, end);
       }
     }
   }
 #endif
-  return std::vector<char>();
+  return std::vector<std::byte>();
 }
 
 /** Binary data to hexadecimal */
-static inline std::array<char, 2> to_hex(std::uint8_t byte)
+static inline std::array<char, 2> to_hex(std::byte 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]}};
+  return {hexdigits[std::to_integer<unsigned>(byte >> 4)], hexdigits[std::to_integer<unsigned>(byte & std::byte{0xF})]};
 }
 
 /** Binary data to hexadecimal */
-static std::string to_hex(const char* data, std::size_t count)
+static std::string to_hex(const std::byte* data, std::size_t count)
 {
   std::string res;
   res.resize(2 * count);
@@ -931,7 +929,7 @@ static std::string to_hex(const char* data, std::size_t count)
 }
 
 /** Binary data to hexadecimal */
-static std::string to_hex(std::vector<char> const& data)
+static std::string to_hex(std::vector<std::byte> const& data)
 {
   return to_hex(data.data(), data.size());
 }
@@ -949,7 +947,7 @@ static constexpr auto debug_paths = {
  */
 // Example:
 // /usr/lib/debug/.build-id/0b/dc77f1c29aea2b14ff5acd9a19ab3175ffdeae.debug
-static int find_by_build_id(std::vector<char> id)
+static int find_by_build_id(std::vector<std::byte> id)
 {
   std::string filename;
   std::string hex = to_hex(id);
@@ -1005,7 +1003,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.
-  if (std::vector<char> build_id = get_build_id(elf); not build_id.empty()) {
+  if (std::vector<std::byte> build_id = get_build_id(elf); not build_id.empty()) {
     elf_end(elf);
     close(fd);
 
@@ -1149,7 +1147,7 @@ std::shared_ptr<ObjectInformation> createObjectInformation(std::vector<xbt::VmMa
 
 /*************************************************************************/
 
-void postProcessObjectInformation(const RemoteProcess* process, ObjectInformation* info)
+void postProcessObjectInformation(const RemoteProcessMemory* process, ObjectInformation* info)
 {
   for (auto& [_, t] : info->types) {
     Type* type    = &t;