proc: fix reading of empty strings in core files
Every time we read an empty string we accidentally issue a read for 0 bytes at address 0, this is fine for real memory but the core file reader doesn't like it. Fixes an issue reported on the mailing list.
This commit is contained in:
parent
bef0d05d16
commit
cd5203e305
8
_fixtures/coreemptystring.go
Normal file
8
_fixtures/coreemptystring.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
s := ""
|
||||||
|
t := "test"
|
||||||
|
panic("panic!!!")
|
||||||
|
println(s, t)
|
||||||
|
}
|
@ -18,6 +18,14 @@ import (
|
|||||||
"github.com/derekparker/delve/pkg/proc/test"
|
"github.com/derekparker/delve/pkg/proc/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func assertNoError(err error, t testing.TB, s string) {
|
||||||
|
if err != nil {
|
||||||
|
_, file, line, _ := runtime.Caller(1)
|
||||||
|
fname := filepath.Base(file)
|
||||||
|
t.Fatalf("failed assertion at %s:%d: %s - %s\n", fname, line, s, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSplicedReader(t *testing.T) {
|
func TestSplicedReader(t *testing.T) {
|
||||||
data := []byte{}
|
data := []byte{}
|
||||||
data2 := []byte{}
|
data2 := []byte{}
|
||||||
@ -297,3 +305,40 @@ func TestCoreFpRegisters(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCoreWithEmptyString(t *testing.T) {
|
||||||
|
if runtime.GOOS != "linux" || runtime.GOARCH != "amd64" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p := withCoreFile(t, "coreemptystring", "")
|
||||||
|
|
||||||
|
gs, err := proc.GoroutinesInfo(p)
|
||||||
|
assertNoError(err, t, "GoroutinesInfo")
|
||||||
|
|
||||||
|
var mainFrame *proc.Stackframe
|
||||||
|
mainSearch:
|
||||||
|
for _, g := range gs {
|
||||||
|
stack, err := g.Stacktrace(10)
|
||||||
|
assertNoError(err, t, "Stacktrace()")
|
||||||
|
for _, frame := range stack {
|
||||||
|
if frame.Current.Fn != nil && frame.Current.Fn.Name == "main.main" {
|
||||||
|
mainFrame = &frame
|
||||||
|
break mainSearch
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if mainFrame == nil {
|
||||||
|
t.Fatal("could not find main.main frame")
|
||||||
|
}
|
||||||
|
|
||||||
|
scope := proc.FrameToScope(p.BinInfo(), p.CurrentThread(), nil, *mainFrame)
|
||||||
|
v1, err := scope.EvalVariable("t", proc.LoadConfig{true, 1, 64, 64, -1})
|
||||||
|
assertNoError(err, t, "EvalVariable(t)")
|
||||||
|
assertNoError(v1.Unreadable, t, "unreadable variable 't'")
|
||||||
|
t.Logf("t = %#v\n", v1)
|
||||||
|
v2, err := scope.EvalVariable("s", proc.LoadConfig{true, 1, 64, 64, -1})
|
||||||
|
assertNoError(err, t, "EvalVariable(s)")
|
||||||
|
assertNoError(v2.Unreadable, t, "unreadable variable 's'")
|
||||||
|
t.Logf("s = %#v\n", v2)
|
||||||
|
}
|
||||||
|
@ -992,6 +992,10 @@ func readStringInfo(mem MemoryReadWriter, arch Arch, addr uintptr) (uintptr, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readStringValue(mem MemoryReadWriter, addr uintptr, strlen int64, cfg LoadConfig) (string, error) {
|
func readStringValue(mem MemoryReadWriter, addr uintptr, strlen int64, cfg LoadConfig) (string, error) {
|
||||||
|
if strlen == 0 {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
count := strlen
|
count := strlen
|
||||||
if count > int64(cfg.MaxStringLen) {
|
if count > int64(cfg.MaxStringLen) {
|
||||||
count = int64(cfg.MaxStringLen)
|
count = int64(cfg.MaxStringLen)
|
||||||
|
Loading…
Reference in New Issue
Block a user