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

panic: runtime error: index out of range #215

Closed
superkkt opened this issue Aug 23, 2015 · 13 comments
Closed

panic: runtime error: index out of range #215

superkkt opened this issue Aug 23, 2015 · 13 comments
Labels
Milestone

Comments

@superkkt
Copy link

Hi,

Delve crashes when I run it and execute 'next' on the breakpoint 'main.main'. My environments are as follows:

  • Delve version: 0.7.0-alpha
  • go version go1.5 linux/amd64
  • Ubuntu 14.04.2 LTS (3.16.0-44-generic)

Here is the logs:

$ dlv debug
Type 'help' for list of commands.
(dlv) b main.main
Breakpoint 1 set at 0x406b11 for main.main ./main.go:209
(dlv) c
> main.main() ./main.go:209

   204:     pool.Add(id, trans)
   205: 
   206:     return nil
   207: }
   208: func main() {
=> 209:     runtime.GOMAXPROCS(runtime.NumCPU())
   210: 
   211:     conf := NewConfig()
   212:     if err := conf.Read(); err != nil {
   213:         fmt.Fprintf(os.Stderr, "Failed to read configurations: %v\n", err)
   214:         os.Exit(1)

(dlv) n
panic: runtime error: index out of range

goroutine 13 [running]:
github.com/derekparker/delve/dwarf/line.(*DebugLineInfo).AllPCsForFileLine(0xc820014c30, 0xc82064e000, 0x49, 0xd3, 0x0, 0x0, 0x0)
    /home/superkkt/go/src/github.com/derekparker/delve/dwarf/line/state_machine.go:81 +0x4cf
github.com/derekparker/delve/proc.(*Thread).next(0xc8205b6720, 0x406b11, 0xc8200178c0, 0xc82064e000, 0x49, 0xd1, 0x0, 0x0)
    /home/superkkt/go/src/github.com/derekparker/delve/proc/threads.go:201 +0x21e
github.com/derekparker/delve/proc.(*Thread).setNextBreakpoints(0xc8205b6720, 0x0, 0x0)
    /home/superkkt/go/src/github.com/derekparker/delve/proc/threads.go:169 +0x2b0
github.com/derekparker/delve/proc.(*Process).next(0xc820138000, 0x0, 0x0)
    /home/superkkt/go/src/github.com/derekparker/delve/proc/proc.go:281 +0x16d
github.com/derekparker/delve/proc.(*Process).(github.com/derekparker/delve/proc.next)-fm(0x0, 0x0)
    /home/superkkt/go/src/github.com/derekparker/delve/proc/proc.go:252 +0x2e
github.com/derekparker/delve/proc.(*Process).run(0xc820138000, 0xc820367870, 0x0, 0x0)
    /home/superkkt/go/src/github.com/derekparker/delve/proc/proc.go:643 +0x115
github.com/derekparker/delve/proc.(*Process).Next(0xc820138000, 0x0, 0x0)
    /home/superkkt/go/src/github.com/derekparker/delve/proc/proc.go:252 +0x45
github.com/derekparker/delve/service/debugger.(*Debugger).Command(0xc8200fee40, 0xc820625880, 0x18, 0x0, 0x0)
    /home/superkkt/go/src/github.com/derekparker/delve/service/debugger/debugger.go:241 +0x422
github.com/derekparker/delve/service/rpc.(*RPCServer).Command(0xc820102cc0, 0xc820625880, 0xc820615c40, 0x0, 0x0)
    /home/superkkt/go/src/github.com/derekparker/delve/service/rpc/server.go:96 +0x3f
reflect.Value.call(0x8f9580, 0x9d9b20, 0x13, 0x9f4f08, 0x4, 0xc820367ec8, 0x3, 0x3, 0x0, 0x0, ...)
    /usr/local/go/src/reflect/value.go:432 +0x120a
reflect.Value.Call(0x8f9580, 0x9d9b20, 0x13, 0xc820367ec8, 0x3, 0x3, 0x0, 0x0, 0x0)
    /usr/local/go/src/reflect/value.go:300 +0xb1
net/rpc.(*service).call(0xc820638500, 0xc8206384c0, 0xc820635750, 0xc820799500, 0xc8207a7ba0, 0x8359c0, 0xc820625880, 0x16, 0x835a20, 0xc820615c40, ...)
    /usr/local/go/src/net/rpc/server.go:383 +0x1c1
created by net/rpc.(*Server).ServeCodec
    /usr/local/go/src/net/rpc/server.go:477 +0x4ac

goroutine 1 [chan receive]:
net/rpc.(*Client).Call(0xc820642000, 0xc82085a1c0, 0x11, 0x8359c0, 0xc82085a1a0, 0x835a20, 0xc820858d40, 0x0, 0x0)
    /usr/local/go/src/net/rpc/client.go:315 +0xcd
github.com/derekparker/delve/service/rpc.(*RPCClient).call(0xc82063c060, 0x9f50a8, 0x7, 0x8359c0, 0xc82085a1a0, 0x835a20, 0xc820858d40, 0x0, 0x0)
    /home/superkkt/go/src/github.com/derekparker/delve/service/rpc/client.go:225 +0xb4
github.com/derekparker/delve/service/rpc.(*RPCClient).Next(0xc82063c060, 0x2, 0x0, 0x0)
    /home/superkkt/go/src/github.com/derekparker/delve/service/rpc/client.go:80 +0xc8
github.com/derekparker/delve/terminal.next(0x7f4931669d20, 0xc82063c060, 0xc8206f9a60, 0x0, 0x0, 0x0, 0x0)
    /home/superkkt/go/src/github.com/derekparker/delve/terminal/command.go:253 +0x36
github.com/derekparker/delve/terminal.(*Term).Run(0xc82063e120, 0x0, 0x0, 0x0)
    /home/superkkt/go/src/github.com/derekparker/delve/terminal/terminal.go:85 +0x917
main.execute(0x0, 0xc8200fea20, 0x1, 0x1, 0xc820104068, 0x0)
    /home/superkkt/go/src/github.com/derekparker/delve/cmd/dlv/main.go:312 +0x4e2
main.main.func3.1(0xee1968, 0x0, 0x0, 0xc820104068, 0x0)
    /home/superkkt/go/src/github.com/derekparker/delve/cmd/dlv/main.go:96 +0x42c
main.main.func3(0xc82012a4e0, 0xee1968, 0x0, 0x0)
    /home/superkkt/go/src/github.com/derekparker/delve/cmd/dlv/main.go:80 +0x3e
github.com/spf13/cobra.(*Command).execute(0xc82012a4e0, 0xee1968, 0x0, 0x0, 0x0, 0x0)
    /home/superkkt/go/src/github.com/spf13/cobra/command.go:476 +0x403
github.com/spf13/cobra.(*Command).Execute(0xc82012a000, 0x0, 0x0)
    /home/superkkt/go/src/github.com/spf13/cobra/command.go:550 +0x46a
main.main()
    /home/superkkt/go/src/github.com/derekparker/delve/cmd/dlv/main.go:271 +0xc1d

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:1696 +0x1

goroutine 5 [syscall]:
os/signal.loop()
    /usr/local/go/src/os/signal/signal_unix.go:22 +0x18
created by os/signal.init.1
    /usr/local/go/src/os/signal/signal_unix.go:28 +0x37

goroutine 18 [chan receive, locked to thread]:
github.com/derekparker/delve/proc.(*Process).handlePtraceFuncs(0xc820138000)
    /home/superkkt/go/src/github.com/derekparker/delve/proc/proc.go:655 +0xc3
created by github.com/derekparker/delve/proc.New
    /home/superkkt/go/src/github.com/derekparker/delve/proc/proc.go:65 +0x2bd

goroutine 9 [chan receive]:
github.com/derekparker/delve/terminal.(*Term).Run.func1(0xc820642240, 0xc82063e120)
    /home/superkkt/go/src/github.com/derekparker/delve/terminal/terminal.go:42 +0x6b
created by github.com/derekparker/delve/terminal.(*Term).Run
    /home/superkkt/go/src/github.com/derekparker/delve/terminal/terminal.go:48 +0x1e6

goroutine 7 [IO wait]:
net.runtime_pollWait(0x7f492fe19370, 0x72, 0xc82000e170)
    /usr/local/go/src/runtime/netpoll.go:157 +0x60
net.(*pollDesc).Wait(0xc82010f020, 0x72, 0x0, 0x0)
    /usr/local/go/src/net/fd_poll_runtime.go:73 +0x3a
net.(*pollDesc).WaitRead(0xc82010f020, 0x0, 0x0)
    /usr/local/go/src/net/fd_poll_runtime.go:78 +0x36
net.(*netFD).Read(0xc82010efc0, 0xc82065a601, 0x5ff, 0x5ff, 0x0, 0x7f493165b050, 0xc82000e170)
    /usr/local/go/src/net/fd_unix.go:232 +0x23a
net.(*conn).Read(0xc820028078, 0xc82065a601, 0x5ff, 0x5ff, 0x0, 0x0, 0x0)
    /usr/local/go/src/net/net.go:172 +0xe4
encoding/json.(*Decoder).refill(0xc82012b040, 0x0, 0x0)
    /usr/local/go/src/encoding/json/stream.go:152 +0x287
encoding/json.(*Decoder).readValue(0xc82012b040, 0x1, 0x0, 0x0)
    /usr/local/go/src/encoding/json/stream.go:128 +0x41b
encoding/json.(*Decoder).Decode(0xc82012b040, 0x9195e0, 0xc820640048, 0x0, 0x0)
    /usr/local/go/src/encoding/json/stream.go:57 +0x159
net/rpc/jsonrpc.(*clientCodec).ReadResponseHeader(0xc820640000, 0xc82063a1b0, 0x0, 0x0)
    /usr/local/go/src/net/rpc/jsonrpc/client.go:75 +0x8f
net/rpc.(*Client).input(0xc820642000)
    /usr/local/go/src/net/rpc/client.go:109 +0xbf
created by net/rpc.NewClientWithCodec
    /usr/local/go/src/net/rpc/client.go:201 +0xd2

goroutine 8 [select, locked to thread]:
runtime.gopark(0xaf2e60, 0xc8205d0f28, 0x9fc640, 0x6, 0x431b18, 0x2)
    /usr/local/go/src/runtime/proc.go:185 +0x163
runtime.selectgoImpl(0xc8205d0f28, 0x0, 0x18)
    /usr/local/go/src/runtime/select.go:392 +0xa64
runtime.selectgo(0xc8205d0f28)
    /usr/local/go/src/runtime/select.go:212 +0x12
runtime.ensureSigM.func1()
    /usr/local/go/src/runtime/signal1_unix.go:227 +0x353
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:1696 +0x1

goroutine 25 [IO wait]:
net.runtime_pollWait(0x7f492fe192b0, 0x72, 0xc82000e170)
    /usr/local/go/src/runtime/netpoll.go:157 +0x60
net.(*pollDesc).Wait(0xc82010f090, 0x72, 0x0, 0x0)
    /usr/local/go/src/net/fd_poll_runtime.go:73 +0x3a
net.(*pollDesc).WaitRead(0xc82010f090, 0x0, 0x0)
    /usr/local/go/src/net/fd_poll_runtime.go:78 +0x36
net.(*netFD).Read(0xc82010f030, 0xc82065a001, 0x5ff, 0x5ff, 0x0, 0x7f493165b050, 0xc82000e170)
    /usr/local/go/src/net/fd_unix.go:232 +0x23a
net.(*conn).Read(0xc8201040e8, 0xc82065a001, 0x5ff, 0x5ff, 0x0, 0x0, 0x0)
    /usr/local/go/src/net/net.go:172 +0xe4
encoding/json.(*Decoder).refill(0xc82000c680, 0x0, 0x0)
    /usr/local/go/src/encoding/json/stream.go:152 +0x287
encoding/json.(*Decoder).readValue(0xc82000c680, 0x1, 0x0, 0x0)
    /usr/local/go/src/encoding/json/stream.go:128 +0x41b
encoding/json.(*Decoder).Decode(0xc82000c680, 0x9196a0, 0xc82079f7c0, 0x0, 0x0)
    /usr/local/go/src/encoding/json/stream.go:57 +0x159
net/rpc/jsonrpc.(*serverCodec).ReadRequestHeader(0xc82079f7a0, 0xc8207a7860, 0x0, 0x0)
    /usr/local/go/src/net/rpc/jsonrpc/server.go:66 +0x7c
net/rpc.(*Server).readRequestHeader(0xc8206384c0, 0x7f492fe32108, 0xc82079f7a0, 0x0, 0x0, 0xc8207a7860, 0xc8206d9c00, 0x0, 0x0)
    /usr/local/go/src/net/rpc/server.go:576 +0x90
net/rpc.(*Server).readRequest(0xc8206384c0, 0x7f492fe32108, 0xc82079f7a0, 0xc8206384c0, 0xc820635750, 0xc820799500, 0x0, 0x0, 0x0, 0x0, ...)
    /usr/local/go/src/net/rpc/server.go:543 +0x8b
net/rpc.(*Server).ServeCodec(0xc8206384c0, 0x7f492fe32108, 0xc82079f7a0)
    /usr/local/go/src/net/rpc/server.go:462 +0x8c
github.com/derekparker/delve/service/rpc.(*RPCServer).Run.func1(0xc820102cc0)
    /home/superkkt/go/src/github.com/derekparker/delve/service/rpc/server.go:65 +0x485
created by github.com/derekparker/delve/service/rpc.(*RPCServer).Run
    /home/superkkt/go/src/github.com/derekparker/delve/service/rpc/server.go:66 +0x118
@derekparker derekparker added this to the 1.0 milestone Aug 23, 2015
@derekparker
Copy link
Member

Thanks, any chance I could get a copy of the source code you're debugging so I can try and reproduce locally?

@superkkt
Copy link
Author

Unfortunately, I don't have right to make it public as my company owns this program, and it does not belong to me. Please let me know if you need further information.

@mwhooker
Copy link

I can reproduce, but unfortunately can't share my code either. I modified delve to print out how big a slice it's asking for when readStringing

diff --git a/proc/variables.go b/proc/variables.go
index 4cf87ab..0469999 100644
--- a/proc/variables.go
+++ b/proc/variables.go
@@ -593,6 +593,7 @@ func (thread *Thread) readString(addr uintptr) (string, error) {
                return "", nil
        }

+       fmt.Printf("Strlen: %s\n", strlen)
        val, err = thread.readMemory(addr, strlen)
        if err != nil {
                return "", fmt.Errorf("could not read string at %#v due to %s", addr, err)

When my program breaks, I run locals, and get the following

(dlv) locals
Strlen: %!s(int=23)
Strlen: %!s(int=30)
Strlen: %!s(int=-7211301130545807457)
panic: runtime error: makeslice: len out of range

goroutine 28 [running]:
github.com/derekparker/delve/proc.(*Thread).readMemory(0xc208a4dad0, 0x4afa740b8aca0000, 0x9bec4fd43171bf9f, 0x0, 0x0, 0x0, 0x0, 0x0)
    /Users/mwhooker/dev/gowork/src/github.com/derekparker/delve/proc/threads_darwin.go:95 +0xb0
github.com/derekparker/delve/proc.(*Thread).readString(0xc208a4dad0, 0x4afa740b8aca0000, 0x0, 0x0, 0x0, 0x0)
    /Users/mwhooker/dev/gowork/src/github.com/derekparker/delve/proc/variables.go:597 +0x5ce
github.com/derekparker/delve/proc.(*Thread).extractValueInternal(0xc208a4dad0, 0x0, 0x0, 0x0, 0xc20830a540, 0x44f6500, 0xc208c58cc0, 0x4215701, 0x1, 0x0, ...)
    /Users/mwhooker/dev/gowork/src/github.com/derekparker/delve/proc/variables.go:523 +0x7c4
github.com/derekparker/delve/proc.(*Thread).extractValueInternal(0xc208a4dad0, 0x0, 0x0, 0x0, 0xc20830a540, 0x44f6500, 0xc208c380c0, 0x1, 0x0, 0x0, ...)
    /Users/mwhooker/dev/gowork/src/github.com/derekparker/delve/proc/variables.go:532 +0xa6e
github.com/derekparker/delve/proc.(*Thread).extractValueInternal(0xc208a4dad0, 0xc208377d48, 0x5, 0x1e2af8, 0xc2084f8990, 0x44dfba0, 0xc208a68bd0, 0x1, 0x0, 0x0, ...)
    /Users/mwhooker/dev/gowork/src/github.com/derekparker/delve/proc/variables.go:514 +0x16e8
github.com/derekparker/delve/proc.(*Thread).extractValue(0xc208a4dad0, 0xc208377d48, 0x5, 0x1e2af8, 0x0, 0x44dfba0, 0xc208a68bd0, 0x4d04501, 0x0, 0x0, ...)
    /Users/mwhooker/dev/gowork/src/github.com/derekparker/delve/proc/variables.go:477 +0xb8
github.com/derekparker/delve/proc.(*Thread).extractVariableFromEntry(0xc208a4dad0, 0xc208a68b40, 0x0, 0x0, 0x0)
    /Users/mwhooker/dev/gowork/src/github.com/derekparker/delve/proc/variables.go:410 +0x55f
github.com/derekparker/delve/proc.(*Thread).variablesByTag(0xc208a4dad0, 0x34, 0x0, 0x0, 0x0, 0x0, 0x0)
    /Users/mwhooker/dev/gowork/src/github.com/derekparker/delve/proc/variables.go:850 +0x238
github.com/derekparker/delve/proc.(*Thread).LocalVariables(0xc208a4dad0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /Users/mwhooker/dev/gowork/src/github.com/derekparker/delve/proc/variables.go:262 +0x5d
github.com/derekparker/delve/service/debugger.(*Debugger).LocalVariables(0xc208028f60, 0x2c03, 0x0, 0x0, 0x0, 0x0, 0x0)
    /Users/mwhooker/dev/gowork/src/github.com/derekparker/delve/service/debugger/debugger.go:378 +0x220
github.com/derekparker/delve/service/rpc.(*RPCServer).ListLocalVars(0xc20801f080, 0x0, 0x0, 0xc208b8e220, 0x0, 0x0)
    /Users/mwhooker/dev/gowork/src/github.com/derekparker/delve/service/rpc/server.go:224 +0x96
reflect.Value.call(0x44707e0, 0x45385a0, 0x13, 0x4554030, 0x4, 0xc208c37f28, 0x3, 0x3, 0x0, 0x0, ...)
    /usr/local/Cellar/go/1.4.2/libexec/src/reflect/value.go:419 +0x10e5
reflect.Value.Call(0x44707e0, 0x45385a0, 0x13, 0xc208c37f28, 0x3, 0x3, 0x0, 0x0, 0x0)
    /usr/local/Cellar/go/1.4.2/libexec/src/reflect/value.go:296 +0xbc
net/rpc.(*service).call(0xc208253d00, 0xc208253cc0, 0xc208251278, 0xc20897b100, 0xc2089aaa80, 0x43d9080, 0xc208ba31f0, 0xd4, 0x43b39a0, 0xc208b8e220, ...)
    /usr/local/Cellar/go/1.4.2/libexec/src/net/rpc/server.go:382 +0x1f7
created by net/rpc.(*Server).ServeCodec
    /usr/local/Cellar/go/1.4.2/libexec/src/net/rpc/server.go:476 +0x44a

happy to help debug more.

@Omie
Copy link
Contributor

Omie commented Aug 25, 2015

Hi

I was kind of bored so I did some investigation.
I did this investigation on Ubuntu 64 bit 3.13.0-61-generic, Go 1.5, Delve version: 0.7.0-alpha

as it turns out:
parseDebugLineInfo initiates some meta data parsing and gets buffer string upto 0x0 in parseFileEntries, which fails to get the name of the executable at times causing FileNames slice to be empty, in turn causing Index out of range when new state machine is being initialized since it tries to access FileNames[1] without bound checking

Fortunately I could reproduce this bug with my sms gateway, github.com/haxpax/gosms/dashboard, I have pushed to delve branch there, use that for debugging if required. It won't be reproduced in master branch of that project since first line in main is not blocking.

I also wrote a tiny debug program where I could not reproduce this, and later diff'ed with gosms

as it turns out, its not guaranteed that the filename will always be the first part upto first 0x0 in debug_line section.
I simply printed every section of both the binaries and looked at debug_line sections of both.
That program and both dumps are pushed to https://github.com/Omie/delve_215

I suppose we need to implement a deterministic approach to extract filename to solve this issue

I'd be happy to do it but I'll need help, some pointers as to how to do it and some cross platform testing as I only have Ubuntu available at the moment.

@derekparker
Copy link
Member

@Omie thanks for your work! I was able to reproduce this on a Linux VM with Go 1.5 using the Delve branch. I cannot reproduce on OSX, so seems to be an issue with ELF binaries. I'm going to investigate a bit more.

@derekparker
Copy link
Member

Tracking it down a bit further it seems to be a problem with CGO binaries on Linux with Go 1.5. The Go 1.5 compiler on Linux when compiling a CGO binary seems to omit the file name table in the .debug_line section.

@Omie
Copy link
Contributor

Omie commented Aug 26, 2015

spent some time more on this. Looks like it doesn't omit the file name table but prepends a lot of C stuff in header. It grew when I added stdio import.

ref: https://github.com/Omie/delve_215/raw/master/c/hello.debuglines
( formatted a little to put go files on new lines each )

couldn't find any pattern to distinguish C related part in debug_line yet

@derekparker
Copy link
Member

@Omie yeah you're right, there's multiple file directories in the elf .debug_line section, so with that in mind this is related to https://github.com/derekparker/delve/issues/143. Delves needs to be able to handle multiple file tables / directory tables.

@Omie
Copy link
Contributor

Omie commented Aug 26, 2015

@derekparker okay. I have some time that I wouldn't mind spending on this, could you share what have you thought about splitting the package? we can switch to mail if needed, address is in profile :)

@derekparker
Copy link
Member

@Omie just mailed you my thoughts on this. Thanks for your help!

@Omie
Copy link
Contributor

Omie commented Aug 26, 2015

yup! will continue there.

@Omie
Copy link
Contributor

Omie commented Aug 30, 2015

@superkkt @mwhooker could you verify now that #218 is merged?

@superkkt
Copy link
Author

Thanks. I have verified the bug is gone by #218.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants