diff --git a/Makefile b/Makefile index 1099cb2..7d891b3 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ $(PROJECT)-release: $(OBJ) strip $@ -$(PROJECT)-debug: CXXFLAGS = -O0 -g -Wall -pedantic --std=gnu++20 $(addprefix -I,$(INCLUDE)) -fno-exceptions -felide-constructors +$(PROJECT)-debug: CXXFLAGS = -DDEBUG -O0 -g -Wall -pedantic --std=gnu++20 $(addprefix -I,$(INCLUDE)) -fno-exceptions -felide-constructors $(PROJECT)-debug: LDFLAGS = -lfmt $(PROJECT)-debug: $(OBJ) $(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS) diff --git a/include/span.hpp b/include/span.hpp index 24de972..dae4baa 100644 --- a/include/span.hpp +++ b/include/span.hpp @@ -20,14 +20,14 @@ namespace hv inline T& operator[](std::size_t index) { #ifdef DEBUG - if (index>=len) throw "tried to index out of bounds of array"; + if (index>=len) std::terminate(); // "tried to index out of bounds of array"; #endif return ptr[index]; } inline const T& operator[](std::size_t index) const { #ifdef DEBUG - if (index>=len) throw "tried to index out of bounds of array"; + if (index>=len) std::terminate(); // "tried to index out of bounds of array"; #endif return ptr[index]; } @@ -35,12 +35,12 @@ namespace hv inline span slice(std::size_t off, std::size_t len) { len = std::min(this->len, len); - if(len+off>=len || len < off) throw "tried to index out of bounds of array"; + if(len+off>=len || len < off) std::terminate(); // "tried to index out of bounds of array"; return span(ptr+off, len-off); } inline span slice(std::size_t off) { - if(len+off>=len || len < off) throw "tried to index out of bounds of array"; + if(len+off>=len || len < off) std::terminate(); // "tried to index out of bounds of array"; return span(ptr+off, len-off); } diff --git a/src/hex.cpp b/src/hex.cpp index b1bc65e..4e099bc 100644 --- a/src/hex.cpp +++ b/src/hex.cpp @@ -59,6 +59,12 @@ inline void hex02(std::uint8_t byte, char buffer[2]) buffer[1] =hex_map[byte][1]; } +template +inline __attribute((always_inline)) void print_exact(const char* ar) +{ + fwrite(ar, 1, N, stdout); +} + template inline __attribute__((always_inline)) void print_exact(const char (&ar)[N]) { @@ -69,10 +75,12 @@ namespace hv { void print_screen(const span memory, unsigned long offset) { #ifndef FIXED_ROW_SIZE -#define S (const char*) +#define S (2+ROW_SZ) +#define P_EX(n, buf) fwrite(buf, 1, n, stdout) int ROW_SZ = 24; #else #define S +#define P_EX(n, buf) print_exact(buf) #endif fmt::print("0x{:016x} ", offset); char hxbuf[3]; @@ -85,7 +93,7 @@ namespace hv { hxbuf[2] = ' '; for(;i