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

arm64 core, the regs command get the wrong SP after nil pointer dereference #3591

Open
fragrans1024 opened this issue Nov 30, 2023 · 6 comments

Comments

@fragrans1024
Copy link

  1. What version of Delve are you using (dlv version)?
Delve Debugger
Version: 1.21.2
Build: $Id: 98f8ab2662d926245917ade2f2bb38277315c7fc $
  1. What version of Go are you using? (go version)?
    go version go1.20.10 linux/arm64

  2. What operating system and processor architecture are you using?

cat /etc/redhat-release
CentOS Linux release 7.9.2009 (AltArch)
  1. What did you do?
package main

func main() {
	map_value := make(map[string]*int)

	var value_1 int = 1
	var value_2 int = 2
	map_value["a"] = &value_1
	map_value["b"] = &value_2

	mod_map(map_value)
}

func mod_map(map_value map[string]*int) {
	p_value := map_value["c"]
	*p_value = 3
}
step 1: Compile the demo.go with debug information (go build -gcflags=all="-N -l" demo.go)
step 2: export GOTRACEBACK=crash, then run the executable file. Now wen can get the coredump file and the information of the program.
step 3: Compare the information of the program and dlv coredump information.
  1. What did you expect to see?
    When dlv core demo core_demo_xx,we expect to get the right SP for the coredump function.
    SP=0x4000192dc0 is printed for the function mod_map which contains nil pointer dereference.
    The following is the inforamtion of the program. The inforamtion contain the SP for each frame stack.
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x68bc0]

goroutine 1 [running]:
panic({0x760c0, 0xd1300})
        /home/wsl/go/go1.20.10/src/runtime/panic.go:987 +0x354 fp=0x4000192d60 sp=0x4000192ca0 pc=0x3ee44
runtime.panicmem()
        /home/wsl/go/go1.20.10/src/runtime/panic.go:260 +0x48 fp=0x4000192d80 sp=0x4000192d60 pc=0x3da78
runtime.sigpanic()
        /home/wsl/go/go1.20.10/src/runtime/signal_unix.go:841 +0x1e0 fp=0x4000192db0 sp=0x4000192d80 pc=0x533f0
main.mod_map(0x4000160668)
        /home/wsl/demo2/demo_2.go:16 +0x40 fp=0x4000192e00 sp=0x4000192dc0 pc=0x68bc0
main.main()
        /home/wsl/demo2/demo_2.go:11 +0x158 fp=0x4000192f70 sp=0x4000192e00 pc=0x68b68
runtime.main()
        /home/wsl/go/go1.20.10/src/runtime/proc.go:250 +0x1d4 fp=0x4000192fd0 sp=0x4000192f70 pc=0x41584
runtime.goexit()
        /home/wsl/go/go1.20.10/src/runtime/asm_arm64.s:1172 +0x4 fp=0x4000192fd0 sp=0x4000192fd0 pc=0x66584
  1. What did you see instead?
    Dlv get the wrong SP information for the function mod_map which contains nil pointer dereference.
    Dlv get he wrong SP = 0x4000192db0. The right SP is 0x4000192dc0.
    We guess the wrong SP is the root cuase of the problem that the print commands for input parameter and local variable is wrong.
Type 'help' for list of commands.
(dlv) bt
 0  0x00000000000673d8 in runtime.raise
    at /home/wsl/go/go1.20.10/src/runtime/sys_linux_arm64.s:158
 1  0x0000000000053474 in runtime.dieFromSignal
    at /home/wsl/go/go1.20.10/src/runtime/signal_unix.go:883
 2  0x000000000005395c in runtime.sigfwdgo
    at /home/wsl/go/go1.20.10/src/runtime/signal_unix.go:1096
 3  0x00000000000526ac in runtime.sigtrampgo
    at /home/wsl/go/go1.20.10/src/runtime/signal_unix.go:432
 4  0x00000000000673d8 in runtime.raise
    at /home/wsl/go/go1.20.10/src/runtime/sys_linux_arm64.s:157
 5  0x0000000000053474 in runtime.dieFromSignal
    at /home/wsl/go/go1.20.10/src/runtime/signal_unix.go:883
 6  0x00000000000535e4 in runtime.crash
    at /home/wsl/go/go1.20.10/src/runtime/signal_unix.go:975
 7  0x000000000003f5a0 in runtime.fatalpanic
    at /home/wsl/go/go1.20.10/src/runtime/panic.go:1172
 8  0x000000000003ee44 in runtime.gopanic
    at /home/wsl/go/go1.20.10/src/runtime/panic.go:987
 9  0x000000000003da78 in runtime.panicmem
    at /home/wsl/go/go1.20.10/src/runtime/panic.go:260
10  0x00000000000533f0 in runtime.sigpanic
    at /home/wsl/go/go1.20.10/src/runtime/signal_unix.go:841
11  0x0000000000068bc0 in main.mod_map
    at ./demo_2.go:15
12  0x0000000000068bc0 in main.mod_map
    at ./demo_2.go:15
13  0x0000000000068bb8 in main.mod_map
    at ./demo_2.go:15
14  0x0000000000000000 in ???
    at :0
    error: NULL address
(truncated)
(dlv) frame 11
> runtime.raise() /home/wsl/go/go1.20.10/src/runtime/sys_linux_arm64.s:158 (PC: 0x673d8)
Warning: debugging optimized function
Frame 11: ./demo_2.go:15 (PC: 68bc0)
    10:
    11:         mod_map(map_value)
    12: }
    13:
    14: func mod_map(map_value map[string]*int) {
=>  15:         p_value := map_value["c"]
    16:         *p_value = 3
    17: }
(dlv) regs
 PC = 0x0000000000068bc0
 SP = 0x0000004000192db0
X29 = 0x00000040001605f8
X30 = 0x0000000000068bc0
@aarzilli
Copy link
Member

There was a change fixing a similar bug recently, #3559, did you try building delve from master?

@aarzilli
Copy link
Member

PS. clone the repository and run make build.

@fragrans1024
Copy link
Author

fragrans1024 commented Dec 1, 2023

I have rebuild delve from the master. The problem still exists.
GO111MODULE=off
We use the following command to rebuild dlv.
go install github.com/go-delve/delve/cmd/dlv

@aarzilli
Copy link
Member

aarzilli commented Dec 1, 2023

I'm not sure what that command does anymore, try it with make build and post the output of dlv version.

@fragrans1024
Copy link
Author

fragrans1024 commented Dec 1, 2023

That command still works, because we try to add some log in the file.
Use that command rebuild dlv, and can get the log added.

I will try with make build.

@fragrans1024
Copy link
Author

[root@localhost delve]# make build
go build -ldflags "-extldflags -static" "-ldflags=-X main.Build=15142ac3d6e14406779c7ab6c5e41e9acd76323a" github.com/go-delve/delve/cmd/dlv
[root@localhost delve]# ./dlv version
Delve Debugger
Version: 1.21.2
Build: 15142ac3d6e14406779c7ab6c5e41e9acd76323a

We rebuild delve with make build, and the probelm still exists.

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

No branches or pull requests

2 participants