google test를 사용하다가 testcase에 breakpoint를 설정했는데 그냥 실행되어 버린다.
아래는 테스트했던 예제들이다.
Makefile
SRCS = test_add.cpp
OBJS = $(SRCS:.cpp=.o)
CXX = g++
all: $(OBJS)
$(CXX) -o test_add $(OBJS) -L../gtest/mac_lib/ -lpthread -lgtest -lgtest_main
.cpp.o:
$(CXX) -isystem ../gtest/include -g -std=gnu++11 -c $<
test_app.cpp
#include <gtest/gtest.h>
static int32_t add(int32_t o1, int32_t o2) {
return (o1+o2);
}
TEST(TestAdd, ReturnsZerowWithTwoZeroOperands) {
ASSERT_EQ(0, add(0, 0));
}
googling해도 찾지 못해서 debug 정보가 없어서 그럴 것 같아서 간만에 g++ 옵션을 살펴봤다.
-glevel
Request debugging information and also use level to specify how much information. The default level is 2.
Level 0 produces no debug information at all. Thus, -g0 negates -g.
Level 1 produces minimal information, enough for making backtraces in parts of the program that you don’t plan to debug. This includes descriptions of functions and external variables, and line number tables, but no information about local variables.
Level 3 includes extra information, such as all the macro definitions present in the program. Some debuggers support macro expansion when you use -g3.
If you use multiple -g options, with or without level numbers, the last such option is the one that is effective.
google test는 testcase를 정의하는 TEST() 매크로안에서 add()함수를 실행시키고 있어 -g0 옵션으로는 찾지 못하는 것으로 보인다.
-g3옵션의 설명에 있듯이 -g3로 컴파일하면 macro같은 추가 정보를 포함하므로 call sequence를 따라갈 수 있는 것으로 보인다.
makefile에 -g3옵션을 주고 add()함수안에 breakpoint를 설정하고 gdb(lldb)를 실행하면 원하는 위치에서 멈춰있는 것을 확인할 수 있다.
댓글