Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: TestGdbPython nil pointer dereference #13887

Closed
quinte17 opened this issue Jan 9, 2016 · 9 comments
Closed

runtime: TestGdbPython nil pointer dereference #13887

quinte17 opened this issue Jan 9, 2016 · 9 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Testing An issue that has been verified to require only test changes, not just a test failure.
Milestone

Comments

@quinte17
Copy link

quinte17 commented Jan 9, 2016

Sometimes this error occurs. (1 out of 100?)

ok      cmd/vet 2.415s

##### GOMAXPROCS=2 runtime -cpu=1,2,4
--- FAIL: TestGdbPython (0.51s)
    runtime-gdb_test.go:42: gdb version 7.7
    runtime-gdb_test.go:167: goroutine 2 bt failed: Python Exception <class 'gdb.MemoryError'> Cannot access memory at address 0x0: 
        Error occurred in Python command: Cannot access memory at address 0x0
FAIL
FAIL    runtime 23.308s
2016/01/09 10:08:45 Failed: exit status 1
@bradfitz
Copy link
Contributor

Which OS and version? And which version of Go?

We need more information.

@bradfitz bradfitz added this to the Unplanned milestone Jan 21, 2016
@ianlancetaylor ianlancetaylor changed the title runtime TestGdbPython Nullpointer runtime: TestGdbPython nil pointer dereference Jan 21, 2016
@ianlancetaylor
Copy link
Contributor

Also, which version of gdb?

@quinte17
Copy link
Author

Ubuntu 14.04.3 LTS Kernel 3.19
gcc --version: gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
gdb --version: GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
go was around 505fa7b42338f0aba7e4235acbc8274a20f3c1f0

i don't have the exact go version around anymore.

@quinte17
Copy link
Author

quinte17 commented Feb 1, 2016

##### GOMAXPROCS=2 runtime -cpu=1,2,4
--- FAIL: TestGdbPython (0.51s)
    runtime-gdb_test.go:42: gdb version 7.7
    runtime-gdb_test.go:167: goroutine 2 bt failed: Python Exception <class 'gdb.MemoryError'> Cannot access memory at address 0x0: 
        Error occurred in Python command: Cannot access memory at address 0x0
FAIL
FAIL    runtime 21.330s
2016/01/31 22:11:47 Failed: exit status 1
$ go version
go version devel +af15bee Fri Jan 29 18:29:10 2016 +0000 linux/amd64

error is still there (after hours of running)

@bradfitz
Copy link
Contributor

@bradfitz bradfitz modified the milestones: Go1.8Maybe, Unplanned Sep 17, 2016
@bradfitz bradfitz added Testing An issue that has been verified to require only test changes, not just a test failure. help wanted labels Sep 17, 2016
@ALTree
Copy link
Member

ALTree commented Sep 17, 2016

The author of the failing test (the one that runs goroutine 2 bt), noted in the commit message that the test should be run with

goroutine 2 [...], since goroutine 1 has its stack pointer set to 0 for some reason

He opened an issue about this, #10468, where he wrote:

This only occurs for goroutine #1, and causes a Python exception. As far as I can tell, it is because for goroutine 1, pc is valid but sp is 0x0

He's correct in that the cause of the Python exception is the sp having value 0x0, but it's not true that this only occurs in goroutine 1. Take for example:

package main

import (
    "fmt"
    "sync"
)

func main() {
    var wg sync.WaitGroup
    wg.Add(1)
    go func() {
        fmt.Println("hi")
        wg.Done()
    }()
    wg.Wait()

    fmt.Println("hello")
}
$ gdb ./test
[...]
(gdb) b 14
(gdb) r
(gdb) info goroutines
  1 waiting  runtime.gopark
  2 waiting  runtime.gopark
  17 waiting  runtime.gopark
  18 waiting  runtime.gopark
* 19 running  main.main.func1

bt works on goroutine 1, but it fails with goroutine 19 (the running one):

(gdb) goroutine 19 bt
#0  main.main.func1 (&wg=<error reading variable: Cannot access memory at address 0x8>)
    at /home/alberto/prova.go:13
Backtrace stopped: Cannot access memory at address 0x0

which has a 0x0 stackpointer.

Maybe the gdb-test is failing because it sometimes happens that the test is run while the tested goroutine (2) is running?

Unfortunately I wasn't able to observe the python exception with my gdb 7.11 (not even changing the test to backtrace on goroutine 1, which is usually running, causes an exception to be raised), so I can't really go on with my investigation : )

@quentinmit quentinmit added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 11, 2016
@rsc rsc modified the milestones: Go1.9, Go1.8Maybe Nov 11, 2016
@aclements
Copy link
Member

The most recent occurrence of this on the dashboard:

2017-05-25T01:55:18-a9d8d4d/linux-386-387:

--- FAIL: TestGdbPythonCgo (1.77s)
	runtime-gdb_test.go:55: gdb version 7.7
	runtime-gdb_test.go:218: goroutine 2 bt failed: Traceback (most recent call last):
		  File "/tmp/workdir/go/src/runtime/runtime-gdb.py", line 453, in invoke
		    gdb.parse_and_eval('$sp = {0}'.format(str(sp)))
		gdb.MemoryError: Cannot access memory at address 0x0
		Error occurred in Python command: Cannot access memory at address 0x0
FAIL
FAIL	runtime

This has the stack trace in it.

The exact place this is happening is a little strange, but my guess is that the MemoryError is a secondary effect of GDB updating its frame cache when $sp is set to (presumably) 0.

@aclements
Copy link
Member

Maybe the gdb-test is failing because it sometimes happens that the test is run while the tested goroutine (2) is running?

That's certainly possible. The test main doesn't do much, so it's certainly possible that some of these other goroutines are still getting off the ground and haven't parked yet. Indeed, when they're running runtime.gogo sets sched.sp to 0 to avoid having a stale value around.

Really, gdb shouldn't be using gp.sched for a running goroutine. It should get the pc and sp from the M the goroutine is running on. I've got some code to do this already. I'll see if I can adapt it.

@aclements aclements self-assigned this Jun 7, 2017
@gopherbot
Copy link

CL https://golang.org/cl/45031 mentions this issue.

@golang golang locked and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Testing An issue that has been verified to require only test changes, not just a test failure.
Projects
None yet
Development

No branches or pull requests

8 participants