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

proc: improve Rosetta check #3810

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pkg/proc/gdbserial/gdbserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ func (p *gdbProcess) Listen(listener net.Listener, path, cmdline string, pid int
return p.Connect(conn, path, cmdline, pid, debugInfoDirs, stopReason)
case status := <-p.waitChan:
listener.Close()
if err := checkRosettaExpensive(); err != nil {
return nil, err
}
return nil, fmt.Errorf("stub exited while waiting for connection: %v", status)
}
}
Expand All @@ -310,6 +313,9 @@ func (p *gdbProcess) Dial(addr string, path, cmdline string, pid int, debugInfoD
}
select {
case status := <-p.waitChan:
if err := checkRosettaExpensive(); err != nil {
return nil, err
}
return nil, fmt.Errorf("stub exited while attempting to connect: %v", status)
default:
}
Expand Down Expand Up @@ -2228,3 +2234,25 @@ func machTargetExcToError(sig uint8) error {
}
return nil
}

func checkRosettaExpensive() error {
if runtime.GOOS != "darwin" {
return nil
}
if runtime.GOARCH != "arm64" {
return nil
}

// Additionally check the output of 'uname -m' if it's x86_64 it means that
// the shell we are running on is being emulated by Rosetta even though our
// process isn't. In this condition debugserver will crash.
out, err := exec.Command("uname", "-m").Output()
if err != nil {
return nil
}
s := strings.TrimSpace(string(out))
if s == "x86_64" {
return errors.New("can not run under Rosetta, check that the terminal/shell in use is right for your CPU architecture")
}
return nil
}