in cmd/seccomp-profiler/disasm/disasm.go [70:121]
func (p *parser) Parse(objDump string) ([]Syscall, error) {
f, err := os.Open(objDump)
if err != nil {
return nil, fmt.Errorf("failed to read objdump file: %v", err)
}
defer f.Close()
var function string
var instructions []string
var syscalls []Syscall
s := bufio.NewScanner(bufio.NewReader(f))
for s.Scan() {
line := s.Text()
instructions = append(instructions, line)
// Find the start of a function.
if strings.HasPrefix(line, functionMarker) {
function = line[5:]
instructions = instructions[:0]
continue
}
syscall, err := p.parse(p, line, function, instructions)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: %v\n", err)
continue
}
if syscall == nil {
// Line was not a syscall.
continue
}
// Found a syscall. Clear the instruction stack.
instructions = instructions[:0]
name, found := p.SyscallNumbers[syscall.Num]
if !found {
fmt.Fprintf(os.Stderr, "WARN: unknown syscall %d found at %+v\n", syscall.Num, syscall)
continue
}
syscall.Caller = function
syscall.Name = name
syscalls = append(syscalls, *syscall)
}
if s.Err() != nil {
return nil, err
}
return syscalls, nil
}