GDB没有返回有用的回溯

时间:2017-07-03 17:00:10

标签: c++ macos c++11 debugging gdb

我一直在编写游戏引擎。我一直在取得很大的进步,除非我需要调试任何东西。当我运行GDB时,我通常会得到这样的堆栈跟踪:

Thread 2 received signal SIGABRT, Aborted.
0x00007fffb73f9d42 in ?? ()
(gdb) bt
#0  0x00007fffb73f9d42 in ?? ()
#1  0x00007fffb74e75bf in ?? ()
#2  0x00007fff5fbfafd0 in ?? ()
#3  0x000003075fbfb110 in ?? ()
#4  0x00007fff5fbfafd0 in ?? ()
#5  0x00007fffb5edbc2f in ?? ()
#6  0x00007fff5fbfafe0 in ?? ()
#7  0x00007fffb735f420 in ?? ()
#8  0xffffffff5fbfb110 in ?? ()
#9  0x0000000000000030 in ?? ()
#10 0x00007fffffffffdf in ?? ()
#11 0x00007fffc01c1a20 in ?? ()
#12 0x00007fff5fbfb100 in ?? ()
#13 0x00007fffb5eb584a in ?? ()
#14 0x0000000000000000 in ?? ()

这使得进行任何调试变得非常困难。我在macOS Sierra上,这是我的Makefile:

OUT_FILE := game

OUT_DIR := out
INC_DIR := src
SRC_DIR := src
OBJ_DIR := obj/native

C := gcc
CXX := g++
LINKER := g++
INC_DIRS := -I$(INC_DIR)
C_FLAGS = \
    -Wall \
    -D NATIVE \
    -pedantic \
    -g

CXX_FLAGS = \
    -std=c++11 \
    -std=c++14 \
    -Wall \
    -D NATIVE \
    -pedantic \
    -D DRAW_FPS \
    -D DRAW_COLLISION \
    -gdwarf \
    -g
    #-Wextra \
    #-Wshadow \

EXEC_FLAGS =
LIBS := -I /Library/Frameworks/SDL2.framework/Headers -I /Library/Frameworks/SDL2_image.framework/Headers -I /Library/Frameworks/SDL2_ttf.framework/Headers -framework SDL2 -framework SDL2_image -framework SDL2_ttf

SRC_FILES := $(shell find $(SRC_DIR) -name '*.cpp' -o -name '*.c')
OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRC_FILES))
OBJ_FILES := $(patsubst $(SRC_DIR)/%.c,   $(OBJ_DIR)/%.o, $(OBJ_FILES))
DEPFILES := $(patsubst  $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.d, $(SRC_FILES))
DEPFILES := $(patsubst  $(SRC_DIR)/%.c,   $(OBJ_DIR)/%.d, $(DEPFILES))

$(OUT_FILE): $(OBJ_FILES)
    $(LINKER) $(CXX_FLAGS) $(EXEC_FLAGS) $^ $(LIBS) -o $@

clean:
    rm -rf $(OBJ_DIR) $(OUT_FILE)

list:
    @echo "$(SRC_FILES)"
    @echo "$(OBJ_FILES)"

depends:
    rm -rf $(OBJ_DIR)/*.d
    $(MAKE) $(DEPFILES)

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
    @mkdir -p $(@D)
    $(C) $(C_FLAGS) $(INC_DIRS) -c $< -o $@

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
    @mkdir -p $(@D)
    $(CXX) $(CXX_FLAGS) $(INC_DIRS) -c $< -o $@

$(OBJ_DIR)/%.d: $(SRC_DIR)/%.cpp
    @mkdir -p $(@D)
    $(CXX) $(CXX_FLAGS) $(INC_DIRS) -MM $< | tr '\n\r\\' ' ' | sed -e 's%^%$@ %' -e 's% % $(OBJ_DIR)/%' > $@

-include $(DEPFILES)

有谁知道我错过了什么?

1 个答案:

答案 0 :(得分:0)

  1. 尝试添加-ggdb以进行更多调试
  2. 使用valgrind找出损坏堆栈的位置。很明显,你在堆栈中破坏了一些内存。