Debug print macro and makefile changes related to asm/size
This commit is contained in:
parent
ec6cc83bd1
commit
d5922a0091
2 changed files with 23 additions and 8 deletions
8
Makefile
8
Makefile
|
@ -10,6 +10,9 @@ ifeq ($(RELEASE), 1)
|
||||||
CFLAGS += -fno-exceptions -fno-asynchronous-unwind-tables -fno-ident
|
CFLAGS += -fno-exceptions -fno-asynchronous-unwind-tables -fno-ident
|
||||||
CFLAGS += -fno-unwind-tables -fno-stack-protector -fno-plt -fno-pic
|
CFLAGS += -fno-unwind-tables -fno-stack-protector -fno-plt -fno-pic
|
||||||
CFLAGS += -O3 -std=c99 -march=native -mtune=native -fomit-frame-pointer
|
CFLAGS += -O3 -std=c99 -march=native -mtune=native -fomit-frame-pointer
|
||||||
|
else
|
||||||
|
CFLAGS += -g -O0 -std=c99 -march=native -mtune=native
|
||||||
|
CFLAGS += -DDEBUG
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Include debug flags
|
# Include debug flags
|
||||||
|
@ -29,7 +32,6 @@ all: $(OBJECTS)
|
||||||
%.s: %.c $(C_HEADERS)
|
%.s: %.c $(C_HEADERS)
|
||||||
@echo "CC $<"
|
@echo "CC $<"
|
||||||
@$(CC) $(CFLAGS) -S -masm=intel $<
|
@$(CC) $(CFLAGS) -S -masm=intel $<
|
||||||
wc -l $@
|
|
||||||
|
|
||||||
driver: $(OBJECTS)
|
driver: $(OBJECTS)
|
||||||
@$(CC) $(CFLAGS) $^ -o $@
|
@$(CC) $(CFLAGS) $^ -o $@
|
||||||
|
@ -40,7 +42,9 @@ run: driver
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJECTS) $(ASMS) driver
|
rm -f $(OBJECTS) $(ASMS) driver
|
||||||
|
|
||||||
asm: $(ASMS)
|
asm: $(ASMS) $(OBJECTS)
|
||||||
|
wc -l $(ASMS)
|
||||||
|
size $(OBJECTS)
|
||||||
|
|
||||||
format:
|
format:
|
||||||
clang-format -i $(C_SOURCES) $(C_HEADERS)
|
clang-format -i $(C_SOURCES) $(C_HEADERS)
|
||||||
|
|
23
ringbuf.c
23
ringbuf.c
|
@ -6,6 +6,12 @@
|
||||||
|
|
||||||
#include "ringbuf.h"
|
#include "ringbuf.h"
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define DEBUG_PRINT(fmt, ...) printf(fmt, __VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define DEBUG_PRINT(fmt, ...)
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_init(struct RingBuf *rb, rb_size_t capacity, ALLOC_T malloc_fn,
|
rb_init(struct RingBuf *rb, rb_size_t capacity, ALLOC_T malloc_fn,
|
||||||
rb_size_t struct_size)
|
rb_size_t struct_size)
|
||||||
|
@ -19,13 +25,16 @@ rb_init(struct RingBuf *rb, rb_size_t capacity, ALLOC_T malloc_fn,
|
||||||
rb->read_head = rb->buffer;
|
rb->read_head = rb->buffer;
|
||||||
|
|
||||||
// Read from buffer at max position to force a segfault if theres an issue
|
// Read from buffer at max position to force a segfault if theres an issue
|
||||||
printf("Reading from buffer at position %d\n",
|
DEBUG_PRINT("Reading from buffer at position %d\n",
|
||||||
rb->capacity * rb->struct_size);
|
rb->capacity * rb->struct_size);
|
||||||
void *top = rb->buffer + (rb->capacity * rb->struct_size);
|
void *top = rb->buffer + (rb->capacity * rb->struct_size);
|
||||||
printf("Buffer top successfully read at virtual address: %p\n", &top);
|
DEBUG_PRINT("Buffer top successfully read at virtual address: %p\n", &top);
|
||||||
|
|
||||||
printf("Initialized ring buffer. Capacit: %d, struct_size: %d, total: %d\n",
|
DEBUG_PRINT(
|
||||||
rb->capacity, rb->struct_size, rb->capacity * rb->struct_size);
|
"Initialized ring buffer. Capacit: %d, struct_size: %d, total: %d\n",
|
||||||
|
rb->capacity, rb->struct_size, rb->capacity * rb->struct_size);
|
||||||
|
|
||||||
|
DEBUG_PRINT("Size of RB: %lu\n", sizeof(struct RingBuf));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -42,6 +51,7 @@ rb_push_back(struct RingBuf *rb, const void *item, MEMCPY_T memcpy_fn)
|
||||||
|
|
||||||
memcpy_fn(rb->write_head, item, rb->struct_size);
|
memcpy_fn(rb->write_head, item, rb->struct_size);
|
||||||
|
|
||||||
|
// Advance the write head
|
||||||
rb->write_head = (char *)rb->write_head + rb->struct_size;
|
rb->write_head = (char *)rb->write_head + rb->struct_size;
|
||||||
|
|
||||||
if(rb->write_head == rb->buffer_end)
|
if(rb->write_head == rb->buffer_end)
|
||||||
|
@ -58,7 +68,8 @@ rb_pop_front(struct RingBuf *rb, void *item)
|
||||||
return Empty;
|
return Empty;
|
||||||
|
|
||||||
memcpy(item, rb->read_head, rb->struct_size);
|
memcpy(item, rb->read_head, rb->struct_size);
|
||||||
|
|
||||||
|
// Advance the read head
|
||||||
rb->read_head = (char *)rb->read_head + rb->struct_size;
|
rb->read_head = (char *)rb->read_head + rb->struct_size;
|
||||||
|
|
||||||
if(rb->read_head == rb->buffer_end)
|
if(rb->read_head == rb->buffer_end)
|
||||||
|
|
Loading…
Reference in a new issue