moongeegee said:
Base on the gdb manu we can pass argument as gdb --args gcc -02 -c
foo.c
But how to use makefile instead of gcc
I try gdb --args make -f Makefile.test but failed.
This is a C++ language discussion group. Your post is off-topic for two
reasons: (1) You are using C, which is very different from C++, and (2)
gdb is a general-purpose debugging tool, and not an aspect of the C++
programming language.
Below is one possible (not particularly scalable) approach. You will
likely get a better answer in a more appropriate group.
$ ls
Makefile foo.c
$ cat Makefile
CC=gcc
DB=gdb
EXT=.c
CFLAGS=-ansi -pedantic
DBFLAGS=--quiet
INVOCATION=$(CC) $(CFLAGS) -o $(TARGET) $(TARGET)$(EXT)
$(TARGET): $(TARGET)$(EXT)
$(INVOCATION)
db:
$(DB) $(DBFLAGS) --args $(INVOCATION)
$ TARGET=foo make
gcc -ansi -pedantic -o foo foo.c
$ ls
Makefile foo foo.c
$ rm foo
$ TARGET=foo make db
gdb --quiet --args gcc -ansi -pedantic -o foo foo.c
Reading symbols from /export/home/jeff/opt/gcc-mine/bin/gcc...done.
Using host libthread_db library "/lib64/libthread_db.so.1".
(gdb) run
Starting program: /export/home/jeff/opt/gcc-mine/bin/gcc -ansi -pedantic
-o foo foo.c
Reading symbols from /lib64/ld-linux-x86-64.so.2...done.
Reading symbols from /lib64/libc.so.6...done.
Program exited normally.
(gdb) quit
$ ls
Makefile foo foo.c
$ ./foo
http://groups.google.com/group/gnu.g++.help/msg/013a9d6e220077ae
$