1

the Makefile is:

 objects = disk.o super.o inode.o namei.o open.o main.o

test : $(objects)
        cc -g -Wall -O2 -o test $(objects)

disk.o : fs.h disk.h
        cc -g -Wall -O2 -c disk.c

namei.o : fs.h
        cc -g -Wall -O2 -c namei.c 

open.o : fs.h
        cc -g -Wall -O2 -c open.c

super.o : fs.h
        cc -g -Wall -O2 -c super.c

inode.o : fs.h
        cc -g -Wall -O2 -c inode.c

main.o : fs.h disk.h sched.h
        cc -g -Wall -O2 -c main.c

.PHONY : clean
clean:
        rm edit $(objects) 

I use the "-g" , but when I debug it by gdb:

gdb test

The message is:

Reading symbols from /root/lx/filesystem/lx_filesystem/test...(no debugging symbols found)...done.
(gdb) file
No executable file now.
No symbol file now.

This is Why?
Thank you

lxgeek
  • 1,732
  • 2
  • 22
  • 33
  • 1
    Is `cc` a link to `gcc`? Besides, you shouldn't be working as `root`, if not necessary... – bash.d May 30 '13 at 08:02
  • @bash.d cc is ok when I test it . and I code in the VPS, so root maybe ok . Thank you – lxgeek May 30 '13 at 08:05
  • How did you compile the object files in the first place? if they weren't compiled with -g, you won't have debug symbols. – Entropia May 30 '13 at 08:06
  • is there any -s or -S in the link line which are trying to strip. – Dayal rai May 30 '13 at 08:06
  • @Dayalrai I have show the all makefile and I don't use '-s' in anywhere. Thank you – lxgeek May 30 '13 at 08:26
  • @Entropia " cc -g -Wall -O2 -o test $(objects)", this '-g' can't create the symbols? – lxgeek May 30 '13 at 08:27
  • 5
    is it odd you don't specify the .c files as being dependencies for your .o files? perhaps my makefile is rusty – xaxxon May 30 '13 at 08:33
  • You are only linking the compiled object files in the above Makefile. You have have compiled the source files before, there you have to specify `-g`. – Entropia May 30 '13 at 08:40
  • hi @Entropia I have updated by " cc -g -Wall -O2 -c disk.c" ,But it't not work. – lxgeek May 30 '13 at 09:41

2 Answers2

2

You need to confirm whether or not you have debug symbols in the binary. On Linux, you can run

file test
which should tell you whether the symbols have been stripped or not. Or try
nm -C test
to see a list of the symbols contained in your test binary. If you see something like
nm: test: no symbols
then that's the problem. If they haven't been stripped, then maybe your debug symbols are not gdb-style (see this question).
Community
  • 1
  • 1
Maria Boghiu
  • 483
  • 3
  • 9
1

Your Makefile is incorrect in several ways. This should work better:

objects = disk.o super.o inode.o namei.o open.o main.o
CFLAGS = -g -Wall -O2

test : $(objects)
disk.o : fs.h disk.h disk.c
namei.o : fs.h namei.c
open.o : fs.h open.c
super.o : fs.h super.c
inode.o : fs.h inode.c
main.o : fs.h disk.h sched.h main.c

.PHONY : clean
clean:
        rm test $(objects)

But that wasn't your question. This:

(gdb) file
No executable file now.

is happening because you are resetting file you want to debug to nothing. Don't do that.

You real problem is this:

Reading symbols from /root/lx/filesystem/lx_filesystem/test...(no debugging symbols found)...done.

Why no debugging symbols? If your executable was built with the Makefile you provided, it should have had debug symbols. The only logical conclusion then is that it wasn't. What likely happened is that you've modified your Makefile, but didn't re-make, and are still debugging an old executable that was built without -g.

Using the fixed Makefile, and make clean all should

  • Rebuild all your object files with -g (and you should see that they are rebuilt with -g in make output.
  • Give you an executable with debug symbols.
Employed Russian
  • 199,314
  • 34
  • 295
  • 362