diff --git a/printer/printer.go b/printer/printer.go index 13dc7fe..5e7456c 100644 --- a/printer/printer.go +++ b/printer/printer.go @@ -16,6 +16,7 @@ type Printer struct { argProgress int extraNewLine bool multiline bool + inSyscall bool } func New(w io.Writer) *Printer { @@ -82,8 +83,11 @@ func (p *Printer) PrintProcessExit(i int) { if i != 0 { colour = ColourRed } + if p.inSyscall { + p.PrintDim(" = ?\n") + } if p.multiline { p.Print("\n") } - p.PrintColour(colour, "\nProcess exited with status %d\n", i) + p.PrintColour(colour, "Process exited with status %d\n", i) } diff --git a/printer/signal.go b/printer/signal.go index 178643c..818c470 100644 --- a/printer/signal.go +++ b/printer/signal.go @@ -5,16 +5,47 @@ import ( "syscall" ) +var signals = map[syscall.Signal]string{ + syscall.SIGABRT: "SIGABRT", + syscall.SIGALRM: "SIGALRM", + syscall.SIGBUS: "SIGBUS", + syscall.SIGCHLD: "SIGCHLD", + syscall.SIGCONT: "SIGCONT", + syscall.SIGFPE: "SIGFPE", + syscall.SIGHUP: "SIGHUP", + syscall.SIGILL: "SIGILL", + syscall.SIGINT: "SIGINT", + syscall.SIGIO: "SIGIO", + syscall.SIGKILL: "SIGKILL", + syscall.SIGPIPE: "SIGPIPE", + syscall.SIGPROF: "SIGPROF", + syscall.SIGPWR: "SIGPWR", + syscall.SIGQUIT: "SIGQUIT", + syscall.SIGSEGV: "SIGSEGV", + syscall.SIGSTKFLT: "SIGSTKFLT", + syscall.SIGSTOP: "SIGSTOP", + syscall.SIGSYS: "SIGSYS", + syscall.SIGTERM: "SIGTERM", + syscall.SIGTRAP: "SIGTRAP", + syscall.SIGTSTP: "SIGTSTP", + syscall.SIGTTIN: "SIGTTIN", + syscall.SIGTTOU: "SIGTTOU", + syscall.SIGURG: "SIGURG", + syscall.SIGUSR1: "SIGUSR1", + syscall.SIGUSR2: "SIGUSR2", + syscall.SIGVTALRM: "SIGVTALRM", + syscall.SIGWINCH: "SIGWINCH", + syscall.SIGXCPU: "SIGXCPU", + syscall.SIGXFSZ: "SIGXFSZ", +} + func (p *Printer) PrintSignal(signal syscall.Signal) { p.PrintColour(ColourYellow, "--> SIGNAL: %s <--\n", signalToString(signal)) } func signalToString(signal syscall.Signal) string { - switch signal { - // TODO: more signals - case syscall.SIGURG: - return "SIGURG" - default: - return fmt.Sprintf("signal %d", signal) + if str, ok := signals[signal]; ok { + return str } + return fmt.Sprintf("%d", signal) } diff --git a/printer/syscall.go b/printer/syscall.go index 90721cc..9353678 100644 --- a/printer/syscall.go +++ b/printer/syscall.go @@ -11,6 +11,7 @@ func (p *Printer) PrintSyscallEnter(syscall *tracer.Syscall) { p.PrintColour(ColourDefault, syscall.Name()) } p.printRemainingArgs(syscall, false) + p.inSyscall = true } func (p *Printer) PrintSyscallExit(syscall *tracer.Syscall) { @@ -22,6 +23,7 @@ func (p *Printer) PrintSyscallExit(syscall *tracer.Syscall) { if p.extraNewLine { p.Print("\n") } + p.inSyscall = false } func (p *Printer) printRemainingArgs(syscall *tracer.Syscall, exit bool) { diff --git a/tracer/args.go b/tracer/args.go index e8746c6..c2a6aae 100644 --- a/tracer/args.go +++ b/tracer/args.go @@ -22,25 +22,6 @@ const ( type ReturnMetadata ArgMetadata -type ArgType int - -const ( - ArgTypeUnknown ArgType = iota - ArgTypeData - ArgTypeInt - ArgTypeStat - ArgTypeLong - ArgTypeAddress - ArgTypeUnsignedInt - ArgTypeUnsignedLong - ArgTypePollFdArray - ArgTypeObject - ArgTypeErrorCode - ArgTypeSigAction - ArgTypeIovecArray - ArgTypeIntArray -) - type Arg struct { name string t ArgType diff --git a/tracer/sys_amd64.go b/tracer/sys_amd64.go index 363bd9b..2e08cac 100644 --- a/tracer/sys_amd64.go +++ b/tracer/sys_amd64.go @@ -566,6 +566,9 @@ var ( }, unix.SYS_OPENAT: { Name: "openat", + ReturnValue: ReturnMetadata{ + Type: ArgTypeInt, + }, Args: []ArgMetadata{ { Name: "dfd", @@ -592,6 +595,9 @@ var ( }, unix.SYS_NEWFSTATAT: { Name: "newfstatat", + ReturnValue: ReturnMetadata{ + Type: ArgTypeErrorCode, + }, Args: []ArgMetadata{ { Name: "dfd", @@ -616,6 +622,9 @@ var ( }, unix.SYS_EXIT: { Name: "exit", + ReturnValue: ReturnMetadata{ + Type: ArgTypeErrorCode, + }, Args: []ArgMetadata{ { Name: "status", @@ -625,6 +634,9 @@ var ( }, unix.SYS_EXIT_GROUP: { Name: "exit_group", + ReturnValue: ReturnMetadata{ + Type: ArgTypeErrorCode, + }, Args: []ArgMetadata{ { Name: "status", diff --git a/tracer/types.go b/tracer/types.go index dc9f8d7..15d786d 100644 --- a/tracer/types.go +++ b/tracer/types.go @@ -5,6 +5,25 @@ import ( "sync" ) +type ArgType int + +const ( + ArgTypeUnknown ArgType = iota + ArgTypeData + ArgTypeInt + ArgTypeStat + ArgTypeLong + ArgTypeAddress + ArgTypeUnsignedInt + ArgTypeUnsignedLong + ArgTypePollFdArray + ArgTypeObject + ArgTypeErrorCode + ArgTypeSigAction + ArgTypeIovecArray + ArgTypeIntArray +) + type typeHandler func(arg *Arg, metadata ArgMetadata, raw uintptr, next uintptr, ret uintptr, pid int) error var typesRegistry = map[ArgType]typeHandler{} @@ -25,5 +44,5 @@ func handleType(arg *Arg, metadata ArgMetadata, raw uintptr, next uintptr, ret u if h, ok := typesRegistry[metadata.Type]; ok { return h(arg, metadata, raw, next, ret, pid) } - return fmt.Errorf("no handler registered for type %d", metadata.Type) + return nil }