Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define a macro for debug messages.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 23 Jul 2021 08:44:27 +0000 (10:44 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 23 Jul 2021 11:00:41 +0000 (13:00 +0200)
src/xbt/memory_map.cpp

index b3ea8b1..fccfac8 100644 (file)
   } else                                                                                                               \
     ((void)0)
 
+#define DEBUG_PRINT(...)                                                                                               \
+  if (false) {                                                                                                         \
+    fprintf(stderr, __VA_ARGS__);                                                                                      \
+  } else                                                                                                               \
+    ((void)0)
+
 namespace simgrid {
 namespace xbt {
 
@@ -155,10 +161,9 @@ std::vector<VmMap> get_memory_map(pid_t pid)
     if (dladdr(reinterpret_cast<void*>(address), &dlinfo))
       memreg.pathname = dlinfo.dli_fname;
 
-    if (false) // debug
-      std::fprintf(stderr, "Region: %016" PRIx64 "-%016" PRIx64 " | %c%c%c | %s\n", memreg.start_addr, memreg.end_addr,
-                   (memreg.prot & PROT_READ) ? 'r' : '-', (memreg.prot & PROT_WRITE) ? 'w' : '-',
-                   (memreg.prot & PROT_EXEC) ? 'x' : '-', memreg.pathname.c_str());
+    DEBUG_PRINT("Region: %016" PRIx64 "-%016" PRIx64 " | %c%c%c | %s\n", memreg.start_addr, memreg.end_addr,
+                (memreg.prot & PROT_READ) ? 'r' : '-', (memreg.prot & PROT_WRITE) ? 'w' : '-',
+                (memreg.prot & PROT_EXEC) ? 'x' : '-', memreg.pathname.c_str());
 
     ret.push_back(std::move(memreg));
     address += size;
@@ -289,8 +294,7 @@ std::vector<VmMap> get_memory_map(pid_t pid)
 
     /* Create space for a new map region in the region's array and copy the */
     /* parsed stuff from the temporal memreg variable */
-    if (false) // debug
-      std::fprintf(stderr, "Found region for %s\n", not memreg.pathname.empty() ? memreg.pathname.c_str() : "(null)");
+    DEBUG_PRINT("Found region for \"%s\"\n", memreg.pathname.c_str());
 
     ret.push_back(std::move(memreg));
   }