Chinese Yellow Pages | Classifieds | Knowledge | Tax | IME

GDB cheatsheat

There is a good gdb cheatsheet at

The output format for print, x is missing  there, somehow I think it is useful to add the output formats:

x,d,u,o,t,a,f,s,z,r please see 

How do we usually run gdb commands

normally we compile the source code with  CPPFLAG -g ( please no -O, otherwise some code are optimized out )

then gdb yourbinary

# set logging on 
# set args --config_file config.ini > ./tmp.log
# run
# or run --config_file config.ini > ./tmp.log  # run/set args can could not set additional paramater
set args your_pass_args for your binary


info thread

break somefile:1223 thread 28 if sid > 19 ( or ==)

print sid

x/30s sid


Makefile for release and debug

You can use Target-specific Variable Values to configure debug/release build using makefile


SRCS_D = \
 src/test1.cpp \

# set the variable OBJECTS to be the same as SOURCES, 
# except wherever the pattern .cpp appears in a words of SOURCES, 
# its replaced by .o
OBJS_D := $(SRCS_D:.cpp=.o)

CPPFLAGS = -O3 -I../some_libs/include

LDFLAGS_D = -pthread -s


all: myd 

# this will overwrite CPPFLAG etc
debug: CPPFLAGS =-DDEBUG -g -I../libs/include
debug: LDFLAGS_D = -pthread
debug: all

 @rm -f myd
 @rm -f src/*.o

myd: $(OBJS_D) ../libs/lib11++.a ../libs/lib11.a 
 $(CXX) $(LDFLAGS_D) -o $@ $^ -lsomeofmylib

 $(MYCC) -std=c++11 $(CPPFLAGS) -c -o $@ $<

$(CXX) is implicit variable in GNU Make, $(MYCC) defined in all Makefile.

Thus, ‘make debug’ will have extra flags like -DDEBUG and -g where as ‘make’ will not.





Leave a Reply

Your email address will not be published. Required fields are marked *