Skip to content

Commit 181d2f4

Browse files
committed
feat: add gdb function
1 parent bdaaf77 commit 181d2f4

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ BUILD_BIN = $(BUILD_DIR)/blackhole
1111
CXX = g++
1212
CXX_LD = $(CXX)
1313

14+
-include $(OBJS:.o=.d)
15+
-include $(CONFIG_DIR)/autoconf.m
16+
1417
CXX_CFLAGS = -Wall \
15-
-MMD
18+
-MMD \
19+
$(if $(CONFIG_BASE_COMP_DEBUG),-g,)
1620
CXX_LDFLAGS = -lfmt
1721

1822
INCS_DIR = $(shell find include -type d) \
@@ -23,8 +27,6 @@ SRCS = $(shell find src -name "*.cpp")
2327
OBJS = $(SRCS:%.cpp=$(BUILD_DIR)/%.o)
2428
LIBS =
2529

26-
-include $(OBJS:.o=.d)
27-
2830
ARGS_BCH ?= ""
2931
ARGS_IMG ?= ""
3032
ARGS_LOG ?= $(BUILD_DIR)/log.txt
@@ -36,7 +38,7 @@ ARGS = --bch $(ARGS_BCH) \
3638
--ref $(ARGS_REF) \
3739
$(ARGS_OTH)
3840

39-
$(BUILD_DIR)/%.o: %.cpp
41+
$(BUILD_DIR)/%.o: %.cpp $(CONFIG_NEW)
4042
@echo + CXX $<
4143
@mkdir -p $(dir $@)
4244
@$(CXX) $(CXX_CFLAGS) $(INCS) -c -o $@ $<
@@ -51,5 +53,7 @@ config:
5153
cd config && kconfig-mconf Kconfig && ../script/gen_autoconf.sh
5254
run: $(BUILD_BIN)
5355
$(BUILD_BIN) $(ARGS)
56+
gdb: $(BUILD_BIN)
57+
gdb --args $(BUILD_BIN) $(ARGS)
5458
clean:
5559
rm -rf $(BUILD_DIR)

include/debug/log.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ class Log {
1212
template<typename args_0, typename... args_1_to_n>
1313
void printLog(const string type, const args_0 args_fmt,
1414
const args_1_to_n... args_var);
15-
void printLogAssert();
15+
template<typename args_0, typename... args_1_to_n>
16+
void printLogAssert(const bool flag, const args_0 args_fmt,
17+
const args_1_to_n... args_var);
1618
void printLogPanic();
1719
private:
1820
FILE *log_file_p;

script/gen_autoconf.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ FILE_CONFIG="$BLACKHOLE_HOME/config/.config"
44
FILE_HEADER="$BLACKHOLE_HOME/config/autoconf.h"
55
FILE_MAKEFL="$BLACKHOLE_HOME/config/autoconf.m"
66

7-
echo "/* Automatically generated file; DO NOT EDIT. */" > "$FILE_HEADER"
8-
echo "/* Kconfig configuration */" >> "$FILE_HEADER"
9-
echo "/* Automatically generated file; DO NOT EDIT. */" > "$FILE_MAKEFL"
10-
echo "/* Kconfig configuration */" >> "$FILE_MAKEFL"
7+
echo "// Automatically generated file; DO NOT EDIT." > "$FILE_HEADER"
8+
echo "// Kconfig configuration" >> "$FILE_HEADER"
9+
echo "# Automatically generated file; DO NOT EDIT." > "$FILE_MAKEFL"
10+
echo "# Kconfig configuration" >> "$FILE_MAKEFL"
1111

1212
awk '
1313
/^#/ { next }

src/debug/log.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ Log::~Log() {
99
void Log::initLog(const string log_file) {
1010
if (!log_file.empty()) {
1111
FILE *log_file_p_tmp = fopen(log_file.c_str(), "w");
12-
assert(log_file_p_tmp);
12+
// assert(log_file_p_tmp);
13+
printLogAssert(0, "hello {}\n", "world");
14+
fmt::print("111\n");
1315
log_file_p = log_file_p_tmp;
1416
}
1517
printLog("success", "[loader] [init] [log] {}\n", "finished");
18+
printLog("success", "[loader] [init] [log] {}\n", log_file);
1619
}
1720

1821
template<typename args_0, typename... args_1_to_n>
@@ -47,3 +50,13 @@ void Log::printLog(const string type, const args_0 args_fmt,
4750
args_fmt,
4851
args_var...),);
4952
}
53+
54+
template<typename args_0, typename... args_1_to_n>
55+
void Log::printLogAssert(const bool flag, const args_0 args_fmt,
56+
const args_1_to_n... args_var) {
57+
if (!flag) {
58+
printLog("failed", args_fmt, args_var...);
59+
}
60+
61+
return;
62+
}

0 commit comments

Comments
 (0)