Chinese Yellow Pages | Classifieds | Knowledge | Tax | IME

GDB cheatsheat

There is a good gdb cheatsheet at http://darkdust.net/files/GDB%20Cheat%20Sheet.pdf

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 https://sourceware.org/gdb/onlinedocs/gdb/Output-Formats.html 

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

run

info thread

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

print sid

x/30s sid

bt

Makefile for release and debug

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

Example:

MYCC=g++
SRCS_D = \
 src/test1.cpp \
 src/test2.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

LIBS =

all: myd 

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

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

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

%.o:%.cpp
 $(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.

 

 

References

http://darkdust.net/files/GDB%20Cheat%20Sheet.pdf

https://sourceware.org/gdb/onlinedocs/gdb/Thread_002dSpecific-Breakpoints.html

http://stackoverflow.com/questions/1079832/how-can-i-configure-my-makefile-for-debug-and-release-builds

 

Leave a Reply

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