gdb: reports error "No such file or directory" with a test file

2,055 views
Skip to first unread message

Archos

unread,
Jul 15, 2013, 4:43:56 AM7/15/13
to golan...@googlegroups.com
I' trying to debug a test file using gdb, but it reports an error.
My actual working directory is:~/go/src/github.com/kless/shutil/shconf

    go test -c -gcflags "-N -l"
    LANG=C gdb shconf.test

It shows the next warning:

warning: File "/usr/local/go/src/pkg/runtime/runtime-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To enable execution of this file add
    add-auto-load-safe-path /usr/local/go/src/pkg/runtime/runtime-gdb.py
line to your configuration file "/home/neo/.gdbinit".
To completely disable this security protection add
    set auto-load safe-path /
line to your configuration file "/home/neo/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
    info "(gdb)Auto-loading safe path"

Although I can continue with it.

    (gdb) source /usr/local/go/src/pkg/runtime/runtime-gdb.py
    Loading Go Runtime support.

    (gdb) list
    github.com/kless/shutil/shconf/_test/_testmain.go: No such file or directory.

How to fix it?

Alexander Sychev

unread,
Jul 15, 2013, 5:35:39 AM7/15/13
to Archos, golang-nuts
Hi,

xxxx/_test/_testmain.go is a temporary source file, it is removed after a producing of the test.
I don't think you need to read it.
Just set breakpoints in your test functions and that is it.

To avoid the warning at startup of gdb, you should add "set auto-load safe-path <your $GOROOT>/src/pkg/runtime/" in  $HOME/.gdbinit

Best regards,
  santucco



--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Best regards,
  santucco

Archos

unread,
Jul 15, 2013, 5:47:44 AM7/15/13
to golan...@googlegroups.com
I had to remove '-gcflags "-N -l"' because I could not set a breakpoint.

* * *
(gdb) b 'shconf.TestScanKeys'
Function "shconf.TestScanKeys" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y

Breakpoint 1 ('shconf.TestScanKeys') pending.
(gdb) run
Starting program: /home/neo/go/src/github.com/kless/shutil/shconf/shconf.test
* * *
At this point, I had to interrupt it, since I follow having the same issue that using "go test" directly.
The program does not exit, it remains halted.

* * *
^C
Program received signal SIGINT, Interrupt.
runtime.futex () at /usr/local/go/src/pkg/runtime/sys_linux_amd64.s:267
267        RET
* * *

But I want to know where it is halted. This is the information of "bt":

(gdb) bt
#0  runtime.futex () at /usr/local/go/src/pkg/runtime/sys_linux_amd64.s:267
#1  0x00000000004111f9 in runtime.futexsleep (addr=void, val=void, ns=void)
    at /usr/local/go/src/pkg/runtime/os_linux.c:58
#2  0x0000000000409b49 in runtime.notesleep (n=void)
    at /usr/local/go/src/pkg/runtime/lock_futex.c:125
#3  0x0000000000414b5f in stopm () at /usr/local/go/src/pkg/runtime/proc.c:795
#4  0x00000000004163f8 in exitsyscall0 (gp=void)
    at /usr/local/go/src/pkg/runtime/proc.c:1417
#5  0x0000000000420ed9 in runtime.mcall (fn=void)
    at /usr/local/go/src/pkg/runtime/asm_amd64.s:195
#6  0x00000000005c1280 in runtime.g0 ()
#7  0x0000000000420da6 in _rt0_amd64 ()
    at /usr/local/go/src/pkg/runtime/asm_amd64.s:86
#8  0x0000000000000001 in ?? ()
#9  0x00007fffffffe118 in ?? ()
#10 0x0000000000000001 in ?? ()
#11 0x00007fffffffe118 in ?? ()
#12 0x0000000000000000 in ?? ()

Alexander Sychev

unread,
Jul 15, 2013, 6:24:57 AM7/15/13
to Archos, golang-nuts
Try to use 'rb TestScanKeys', it sets breakpoints on all functions matching the regular expression 'TestScanKeys'


Archos

unread,
Jul 15, 2013, 6:49:29 AM7/15/13
to golan...@googlegroups.com
Thanks Alexander, I think that I found the issue, if the python exception showed at the end comes from
the Go code.

(gdb) rb TestScanKeys
Breakpoint 1 at 0x430b00: file /home/neo/go/src/github.com/kless/shutil/shconf/scan_test.go, line 35.
void github.com/kless/shutil/shconf.TestScanKeys(struct testing.T *);

(gdb) run
Starting program: /home/neo/go/src/github.com/kless/shutil/shconf/shconf.test
[New LWP 7737]
[Switching to LWP 7737]

Breakpoint 1, github.com/kless/shutil/shconf.TestScanKeys (t=0xc20007c000)
    at /home/neo/go/src/github.com/kless/shutil/shconf/scan_test.go:35
35    func TestScanKeys(t *testing.T) {
(gdb) info locals
found = false
atEOF = false
n = 0
v = ""
test = {in = "", key = "", value = ""}
~r0 = 0x0
k = ""
s = 0x2300000000
Python Exception <type 'exceptions.UnicodeEncodeError'> 'ascii' codec can't encode character u'\u01c0' in position 34: ordinal not in range(128):
s·2 =

Alexander Sychev

unread,
Jul 15, 2013, 7:00:52 AM7/15/13
to Archos, golang-nuts
I think the problem is when you start gdb with 'LANG=C'. I guess Python use standard runtime of libc  to work with locales. You should try to leave your current locale instead of using 'C' - locale. I hope your current locale is UTF-8 :-)
Anyway you can try to inspect variables directly without Python's extentions.

Archos

unread,
Jul 15, 2013, 7:06:41 AM7/15/13
to golan...@googlegroups.com
You are right, the issue was due to use 'LANG=C'

Archos

unread,
Jul 15, 2013, 7:33:46 AM7/15/13
to golan...@googlegroups.com
I've tried but I could not debug it. This is my GDB session:

$ gdb shconf.test

(gdb) rb TestScanKeys
(gdb) run

and start to run every line:

(gdb) n
(gdb) [Return]*

Until that it remains halted; I have to press ^C.
But now, I have not information from code being run:

(gdb) info locals
No locales.

Any help?

Alexander Sychev

unread,
Jul 15, 2013, 7:58:18 AM7/15/13
to Archos, golang-nuts
Try to compile with " -gcflags '-N -l' " the entire project. I used to compile my project " go build -gcflags '-N -l' " and then " go test -c " for debug purposes and it works fine.

Archos

unread,
Jul 15, 2013, 8:10:02 AM7/15/13
to golan...@googlegroups.com
Thanks Alexander but I follow getting the same result.

Does anybody could install this program to try to debug it?

go get github.com/kless/shutil/shconf
cd github.com/kless/shutil/shconf

Alexander Sychev

unread,
Jul 15, 2013, 9:08:23 AM7/15/13
to Archos, golang-nuts
You have a bug in scan.go:40
for thisRune, _, err = s.buf.ReadRune();; unicode.IsSpace(thisRune) {

You set initial value of thisRune, but you won't read a next rune from s.buf.
For the second test the first value of thisRune is a space and the cycle is never finished.

Maybe it should be:

for thisRune, _, err = s.buf.ReadRune(); unicode.IsSpace(thisRune); thisRune, _, err = s.buf.ReadRune() { 

?

Alexander Sychev

unread,
Jul 15, 2013, 9:16:15 AM7/15/13
to Archos, golang-nuts
BTW, I have run commands this way, and I could debug quite well:
santucco@santucco ~ $ go get github.com/kless/shutil/shconf
santucco@santucco ~ $ cd $GOPATH/github.com/kless/shutil/shconf
santucco@santucco ~/work/go/src/github.com/kless/shutil/shconf $ go build -gcflags '-N -l'
santucco@santucco ~/work/go/src/github.com/kless/shutil/shconf $ go test -c
santucco@santucco ~/work/go/src/github.com/kless/shutil/shconf $ ls
scan.go  scan_test.go  shconf.go  shconf.test  shconf_test.go
santucco@santucco ~/work/go/src/github.com/kless/shutil/shconf $ gdb ./shconf.test 
--
Best regards,
  santucco

Archos

unread,
Jul 15, 2013, 9:17:15 AM7/15/13
to golan...@googlegroups.com
Thanks again!
Could you write the GDB session (commands used) to trace until the issue? (if you used gdb)

Alexander Sychev

unread,
Jul 15, 2013, 10:55:42 AM7/15/13
to Archos, golang-nuts
Done. The trace is in an attached file
I have build test with " -gcflags '-N -l' " too.

trace.txt
Reply all
Reply to author
Forward
0 new messages