#include "memory_map.hpp"
+// abort with a message if `expr' is false
+#define CHECK(expr) \
+ if (not(expr)) { \
+ fprintf(stderr, "CHECK FAILED: %s:%d: %s\n", __FILE__, __LINE__, #expr); \
+ abort(); \
+ } else \
+ ((void)0)
+
+#define DEBUG_PRINT(...) \
+ if (false) { \
+ fprintf(stderr, __VA_ARGS__); \
+ } else \
+ ((void)0)
+
namespace simgrid {
namespace xbt {
if (dladdr(reinterpret_cast<void*>(address), &dlinfo))
memreg.pathname = dlinfo.dli_fname;
-#if 0 /* 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());
-#endif
+ 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;
char *endptr;
memreg.start_addr = std::strtoull(tok, &endptr, 16);
/* Make sure that the entire string was an hex number */
- if (*endptr != '\0')
- abort();
+ CHECK(*endptr == '\0');
tok = strtok_r(nullptr, "-", &saveptr);
- if (tok == nullptr)
- abort();
+ CHECK(tok != nullptr);
memreg.end_addr = std::strtoull(tok, &endptr, 16);
/* Make sure that the entire string was an hex number */
- if (*endptr != '\0')
- abort();
+ CHECK(*endptr == '\0');
/* Get the permissions flags */
- if (std::strlen(lfields[1]) < 4)
- abort();
+ CHECK(std::strlen(lfields[1]) >= 4);
memreg.prot = 0;
for (i = 0; i < 3; i++){
/* Get the offset value */
memreg.offset = std::strtoull(lfields[2], &endptr, 16);
/* Make sure that the entire string was an hex number */
- if (*endptr != '\0')
- abort();
+ CHECK(*endptr == '\0');
/* Get the device major:minor bytes */
tok = strtok_r(lfields[3], ":", &saveptr);
- if (tok == nullptr)
- abort();
+ CHECK(tok != nullptr);
memreg.dev_major = (char) strtoul(tok, &endptr, 16);
/* Make sure that the entire string was an hex number */
- if (*endptr != '\0')
- abort();
+ CHECK(*endptr == '\0');
tok = strtok_r(nullptr, ":", &saveptr);
- if (tok == nullptr)
- abort();
+ CHECK(tok != nullptr);
memreg.dev_minor = (char) std::strtoul(tok, &endptr, 16);
/* Make sure that the entire string was an hex number */
- if (*endptr != '\0')
- abort();
+ CHECK(*endptr == '\0');
/* Get the inode number and make sure that the entire string was a long int */
memreg.inode = strtoul(lfields[4], &endptr, 10);
- if (*endptr != '\0')
- abort();
+ CHECK(*endptr == '\0');
/* And finally get the pathname */
if (lfields[5])
/* Create space for a new map region in the region's array and copy the */
/* parsed stuff from the temporal memreg variable */
- // 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));
}