提交 86120a3b 编写于 作者: A aarzilli 提交者: Derek Parker

proc/gdbserial: do not run rr when perf_event_paranoid > 1

On newer kernels when /proc/sys/kernel/perf_event_paranoid is > 1 rr
will crash with SIGABRT. Return an error instead of letting this
happen.
上级 2925c031
......@@ -8,6 +8,7 @@ import (
"io/ioutil"
"os"
"os/exec"
"strconv"
"strings"
"unicode"
)
......@@ -15,8 +16,8 @@ import (
// Record uses rr to record the execution of the specified program and
// returns the trace directory's path.
func Record(cmd []string, wd string, quiet bool) (tracedir string, err error) {
if _, err := exec.LookPath("rr"); err != nil {
return "", &ErrBackendUnavailable{}
if err := checkRRAvailabe(); err != nil {
return "", err
}
rfd, wfd, err := os.Pipe()
......@@ -53,8 +54,8 @@ func Record(cmd []string, wd string, quiet bool) (tracedir string, err error) {
// Replay starts an instance of rr in replay mode, with the specified trace
// directory, and connects to it.
func Replay(tracedir string, quiet bool) (*Process, error) {
if _, err := exec.LookPath("rr"); err != nil {
return nil, &ErrBackendUnavailable{}
if err := checkRRAvailabe(); err != nil {
return nil, err
}
rrcmd := exec.Command("rr", "replay", "--dbgport=0", tracedir)
......@@ -90,6 +91,33 @@ func Replay(tracedir string, quiet bool) (*Process, error) {
return p, nil
}
// ErrPerfEventParanoid is the error returned by Reply and Record if
// /proc/sys/kernel/perf_event_paranoid is greater than 1.
type ErrPerfEventParanoid struct {
actual int
}
func (err ErrPerfEventParanoid) Error() string {
return fmt.Sprintf("rr needs /proc/sys/kernel/perf_event_paranoid <= 1, but it is %d", err.actual)
}
func checkRRAvailabe() error {
if _, err := exec.LookPath("rr"); err != nil {
return &ErrBackendUnavailable{}
}
// Check that /proc/sys/kernel/perf_event_paranoid doesn't exist or is <= 1.
buf, err := ioutil.ReadFile("/proc/sys/kernel/perf_event_paranoid")
if err == nil {
perfEventParanoid, _ := strconv.Atoi(strings.TrimSpace(string(buf)))
if perfEventParanoid > 1 {
return ErrPerfEventParanoid{perfEventParanoid}
}
}
return nil
}
type rrInit struct {
port string
exe string
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册