CXX = g++
CXXFLAGS = -std=c++17 -g3 -O0 -Wall -Wextra -fno-omit-frame-pointer
LDFLAGS = -pthread
TARGET = test_debuggee
SOURCES = main.cpp threads.cpp memory.cpp variables.cpp
OBJECTS = $(SOURCES:.cpp=.o)
DEBUG_FLAGS = -gdwarf-4
EXTRA_FLAGS = -fno-inline -fno-optimize-sibling-calls
all: $(TARGET)
$(TARGET): $(OBJECTS)
@echo "Linking $(TARGET) with full debug information..."
$(CXX) $(CXXFLAGS) $(DEBUG_FLAGS) $(EXTRA_FLAGS) -o $(TARGET) $(OBJECTS) $(LDFLAGS)
@echo "Build complete: $(TARGET)"
@echo "Binary info:"
@file $(TARGET)
@echo "Size:"
@ls -lh $(TARGET)
%.o: %.cpp
@echo "Compiling $< with debug symbols..."
$(CXX) $(CXXFLAGS) $(DEBUG_FLAGS) $(EXTRA_FLAGS) -c $< -o $@
debug: CXXFLAGS += -DDEBUG -fno-inline-functions
debug: $(TARGET)
@echo "Debug build complete with maximum debug information"
release: CXXFLAGS = -std=c++17 -g1 -O2 -Wall -Wextra -DNDEBUG
release: clean $(TARGET)
@echo "Release build complete"
clean:
@echo "Cleaning build artifacts..."
rm -f $(OBJECTS) $(TARGET)
@echo "Clean complete"
install: $(TARGET)
@echo "Installing $(TARGET) to tests directory..."
cp $(TARGET) ../tests/
@echo "Install complete"
test-compile: $(TARGET)
@echo "Testing binary compilation and basic execution..."
./$(TARGET) --mode normal || echo "Test execution completed (may have failed intentionally)"
@echo "Compilation test complete"
verify-debug: $(TARGET)
@echo "Verifying debug symbols in $(TARGET)..."
@echo "Debug sections:"
@objdump -h $(TARGET) | grep debug || echo "Debug sections check complete"
@echo "Symbol table sample:"
@nm $(TARGET) | head -20 || echo "Symbol table check complete"
@echo "DWARF info check:"
@objdump -Wi $(TARGET) | head -20 || echo "DWARF info check complete"
test-modes: $(TARGET)
@echo "Testing different execution modes..."
@echo "=== Testing normal mode ==="
timeout 5s ./$(TARGET) --mode normal || echo "Normal mode test complete"
@echo "=== Testing step-debug mode ==="
timeout 5s ./$(TARGET) --mode step-debug || echo "Step-debug mode test complete"
@echo "=== Testing memory mode ==="
timeout 5s ./$(TARGET) --mode memory || echo "Memory mode test complete"
@echo "=== Testing threads mode ==="
timeout 5s ./$(TARGET) --mode threads || echo "Threads mode test complete"
@echo "All mode tests complete"
test-lldb: $(TARGET)
@echo "Testing LLDB compatibility..."
@which lldb > /dev/null || (echo "LLDB not found, skipping compatibility test"; exit 0)
@echo "LLDB version:"
@lldb --version || echo "LLDB version check complete"
@echo "Testing LLDB binary loading..."
@echo "quit" | lldb $(TARGET) || echo "LLDB binary loading test complete"
help:
@echo "InCode Test Debuggee Build System"
@echo ""
@echo "Targets:"
@echo " all - Build test binary with full debug information (default)"
@echo " debug - Build debug version with maximum debug info"
@echo " release - Build optimized version with minimal debug info"
@echo " clean - Remove all build artifacts"
@echo " install - Copy binary to tests directory"
@echo " test-compile - Test basic compilation and execution"
@echo " verify-debug - Verify debug symbols are present"
@echo " test-modes - Test all execution modes"
@echo " test-lldb - Test LLDB compatibility"
@echo " help - Show this help message"
@echo ""
@echo "Debug Features:"
@echo " - Full DWARF-4 debug information"
@echo " - Variable tracking enabled"
@echo " - Frame pointer preservation"
@echo " - Inlining disabled for better debugging"
@echo " - Standalone debug information"
@echo ""
@echo "Execution Modes:"
@echo " --mode normal - Standard execution with all scenarios"
@echo " --mode threads - Multi-threading scenarios"
@echo " --mode memory - Memory operation patterns"
@echo " --mode step-debug - Step-friendly execution paths"
@echo " --mode crash-segv - Controlled segmentation fault"
@echo " --mode crash-stack - Controlled stack overflow"
@echo " --mode infinite - Infinite loop for interruption testing"
.PHONY: all debug release clean install test-compile verify-debug test-modes test-lldb help
main.o: main.cpp
threads.o: threads.cpp
memory.o: memory.cpp
variables.o: variables.cpp