1

I have a source file testcc.c which just print a "Hello, World", I compile it with cc as below

cc -g -o testcc testcc.c

it works fine when I run it. now I want to debug it with gdb with the following command.

gdb testcc

I can see the output from gdb.

GDB is free software and you are welcome to distribute copies of it under certain conditions; type "show copying" to see the conditions. There is absolutely no warranty for GDB; type "show warranty" for details. GDB 4.16 (sparc-sun-solaris2.6), Copyright 1996 Free Software Foundation, Inc...

But, When I try to set a breakpoint at line 5, I got the following message

(gdb) break 5
Breakpoint 1 at 0x10814: file /home/users/xxx/C, line 5.
(gdb)

The problem is /home/users/xxx/C is my current working directory, not the source file!

Then, I try to use the file:line-number options

(gdb) break testcc.c:5
No source file named testcc.c.

So, I include the full path for the file name as below

(gdb) break /home/users/xxx/testcc.c:5
No source file named /home/users/xxx/testcc.c.

I am confused, the file is there, why gdb can not find it? I also try to specify the directory to search for source files when starting gdb

gdb -d /home/users/xxx/C testcc

it still not work, what's the problem?

zdd
  • 8,258
  • 8
  • 46
  • 75
  • Is `/home/users/xxx/C` a real directory or have you mounted a Windows file system on your Solaris system ? – Paul R Nov 14 '12 at 09:24
  • Do you see the message "Reading symbols from /path/to/your/cc/file...done." on startup? Also, GDB seems to be at version 7.4.1 on my Linux box, so 4.16 looks reeeaaally old to me... Finally, just to be sure, try gdb ./testcc (there might be another testcc in the path) – Sjlver Nov 14 '12 at 09:32
  • Try grabbing a more recent version of GDB from http://www.sunfreeware.com/. I suspect your `gdb`, version 4.16 (sparc-sun-solaris2.6), is having trouble with the debugging information generated by your copy of `gcc`. – scottt Nov 14 '12 at 10:24
  • @Paul R, that's a real directory. – zdd Nov 14 '12 at 10:31
  • @Sjlver, I didn't see that message, I have tried gdb ./testcc, it doesn't work either. – zdd Nov 14 '12 at 10:32
  • @scott, I am not using gcc, I use cc, will try new version of gdb. – zdd Nov 15 '12 at 01:45

1 Answers1

2

After struggle for a whole day, I finally find that we should use dbx to debug program compiled by Sun cc compiler. here is the link said this.

http://www.cs.cmu.edu/~gilpin/tutorial/

zdd
  • 8,258
  • 8
  • 46
  • 75