2016-04-15 95 views
-1

我希望使用gdb来调试程序。当我使用b lib.c:FUNCTION设置断点在lib.c,GDB忽略断点:如何使用GDB调试依赖文件?

Breakpoint 1 at 0x8048d03: file lib.c, line 120. 
(gdb) run 
Starting program: /home/jharvard/Dropbox/project/macro_main 
usage: output file in rows of INT, INT, A or D 
i.e. ./macro_main in/data_1 
[Inferior 1 (process 14766) exited with code 01] 

我觉得有可能是一些错误的Makefile文件。我该如何解决它?

CC?=gcc 
CFLAGS+= -g -Wall 
LDFLAGS= 
LIBS = -lm 

macro_main: macro_main.o lsm.o lib.o level.o 
    $(CC) $(LDFLAGS) -o [email protected] $^ $(LIBS) 

%.o: %.c 
    $(CC) $(CFLAGS) -c -o [email protected] $^ 

clean: 
    rm -rf *.o macro_main 

编辑:下面是我得到的。可疑票据是Make breakpoint pending on future shared library load? (y or [n]) y。这似乎表明在Makefile中没有正确链接。

me (~/Dropbox/project): make 
make: Warning: File `Makefile' has modification time 1.7e+06 s in the future 
clang -Wall -c -o macro_main.o macro_main.c 
clang -Wall -c -o lsm.o lsm.c 
clang -Wall -c -o lib.o lib.c 
clang -Wall -c -o level.o level.c 
gcc -o macro_main macro_main.o lsm.o lib.o level.o -lm 
make: warning: Clock skew detected. Your build may be incomplete. 
me (~/Dropbox/project): gdb ./macro_main in/data_1 
Reading symbols from ./macro_main...(no debugging symbols found)...done. 
"/home/me/Dropbox/project/in/data_1" is not a core dump: File format not recognized 
(gdb) b main 
Breakpoint 1 at 0x8048685 
(gdb) run 
Starting program: /home/me/Dropbox/project/macro_main 

Breakpoint 1, 0x08048685 in main() 
(gdb) b lib.c:lsm_merge 
No source file named lib.c. 
Make breakpoint pending on future shared library load? (y or [n]) y 

Breakpoint 2 (lib.c:lsm_merge) pending. 

(gdb) continue 
Continuing. 
usage: output file in rows of INT, INT, A or D 
i.e. ./macro_main in/data_1 
[Inferior 1 (process 16156) exited with code 01] 
+1

确定程序不断调用该函数? – immibis

+0

gdb如何需要依赖文件?这会造成像Scons这样的构建工具的麻烦,甚至不需要它们。 – Olaf

+0

是的,当我运行'./macro_main in/data_1'时,它在函数中运行'printf'的内容。 – Pippi

回答

0

最后,以下为我工作:

CFLAGS = -std=c99 -Wall -g -ggdb -O0 
LIBS = -lm 

macro_main: macro_main.o lsm.o lib.o level.o 
    gcc $(CFLAGS) -o [email protected] $^ $(LIBS) 


macro_main.o: macro_main.c 
    gcc $(CFLAGS) -c macro_main.c 

lsm.o: lsm.c 
    gcc $(CFLAGS) -c lsm.c 

lib.o: lib.c 
    gcc $(CFLAGS) -c lib.c 

level.o: level.c 
    gcc $(CFLAGS) -c level.c 

clean: 
    rm -rf *.o macro_main