diff options
| author | Florent Revest <revest@chromium.org> | 2023-06-08 17:56:49 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2023-06-09 17:56:11 +0200 |
| commit | 49519f067f7fc9bfbf869e6851a4d398a9f7863f (patch) | |
| tree | aaab672be53e832a098f8797fad2cdebadf67cf6 /pkg/csource/csource.go | |
| parent | f6c9fc7b5ee92530706841871ae962f2300f4f26 (diff) | |
pkg/csource: annotate syscall() args with their names
This annotates syscall arguments so they are easier to read without
having to pull out the syscall's man page. E.g:
syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul,
/*prot=*/0ul, ...
Signed-off-by: Florent Revest <revest@chromium.org>
Diffstat (limited to 'pkg/csource/csource.go')
| -rw-r--r-- | pkg/csource/csource.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go index 0c9f78e71..54cf2fa39 100644 --- a/pkg/csource/csource.go +++ b/pkg/csource/csource.go @@ -351,25 +351,27 @@ func (ctx *context) fmtCallBody(call prog.ExecCall) string { } funcName = fmt.Sprintf("((intptr_t(*)(%v))CAST(%v))", args, callName) } - for _, arg := range call.Args { + for i, arg := range call.Args { switch arg := arg.(type) { case prog.ExecArgConst: if arg.Format != prog.FormatNative && arg.Format != prog.FormatBigEndian { panic("string format in syscall argument") } + com := ctx.argComment(call.Meta.Args[i], arg) suf := ctx.literalSuffix(arg, native) - argsStrs = append(argsStrs, handleBigEndian(arg, ctx.constArgToStr(arg, suf))) + argsStrs = append(argsStrs, com+handleBigEndian(arg, ctx.constArgToStr(arg, suf))) case prog.ExecArgResult: if arg.Format != prog.FormatNative && arg.Format != prog.FormatBigEndian { panic("string format in syscall argument") } + com := ctx.argComment(call.Meta.Args[i], arg) val := ctx.resultArgToStr(arg) if native && ctx.target.PtrSize == 4 { // syscall accepts args as ellipsis, resources are uint64 // and take 2 slots without the cast, which would be wrong. val = "(intptr_t)" + val } - argsStrs = append(argsStrs, val) + argsStrs = append(argsStrs, com+val) default: panic(fmt.Sprintf("unknown arg type: %+v", arg)) } @@ -499,6 +501,10 @@ func (ctx *context) copyout(w *bytes.Buffer, call prog.ExecCall, resCopyout bool } } +func (ctx *context) argComment(field prog.Field, arg prog.ExecArg) string { + return "/*" + field.Name + "=" + "*/" +} + func (ctx *context) constArgToStr(arg prog.ExecArgConst, suffix string) string { mask := (uint64(1) << (arg.Size * 8)) - 1 v := arg.Value & mask |
