如何找fmt.Println函数的系统调用

然后我通过 go tool compile -S main.go

不是很懂汇编,但是我看ppt里系统调用下面一行都有 SYSCALL 的指令,这边没有
我本意想找一下fmt.Println()系统调用,然后看https://chromium.googlesource.com/chromiumos/docs/+/master/constants/syscalls.md#x86_64-64_bit 这里的表来对照一下
23
收起
正在回答
2回答
看一下我下面贴的调试流程~
最后是 syscall.Write
Xargin
2021-06-08 21:49:23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | ~ ❯❯❯ dlv debug print.goType 'help' for list of commands.(dlv) b main.mainBreakpoint 1 set at 0x10c622f for main.main() ./print.go:5(dlv) c> main.main() ./print.go:5 (hits goroutine(1):1 total:1) (PC: 0x10c622f) 1: package main 2: 3: import "fmt" 4:=> 5: func main() { 6: fmt.Println("hello world") 7: }(dlv) n> main.main() ./print.go:6 (PC: 0x10c623d) 1: package main 2: 3: import "fmt" 4: 5: func main() {=> 6: fmt.Println("hello world") 7: }(dlv) s> fmt.Println() /usr/local/go/src/fmt/print.go:273 (PC: 0x10c03c3) 268: } 269: 270: // Println formats using the default formats for its operands and writes to standard output. 271: // Spaces are always added between operands and a newline is appended. 272: // It returns the number of bytes written and any write error encountered.=> 273: func Println(a ...interface{}) (n int, err error) { 274: return Fprintln(os.Stdout, a...) 275: } 276: 277: // Sprintln formats using the default formats for its operands and returns the resulting string. 278: // Spaces are always added between operands and a newline is appended.(dlv) s> fmt.Println() /usr/local/go/src/fmt/print.go:274 (PC: 0x10c03e8) 269: 270: // Println formats using the default formats for its operands and writes to standard output. 271: // Spaces are always added between operands and a newline is appended. 272: // It returns the number of bytes written and any write error encountered. 273: func Println(a ...interface{}) (n int, err error) {=> 274: return Fprintln(os.Stdout, a...) 275: } 276: 277: // Sprintln formats using the default formats for its operands and returns the resulting string. 278: // Spaces are always added between operands and a newline is appended. 279: func Sprintln(a ...interface{}) string {(dlv) s> fmt.Fprintln() /usr/local/go/src/fmt/print.go:262 (PC: 0x10c0283)=> 262: func Fprintln(w io.Writer, a ...interface{}) (n int, err error) { 263: p := newPrinter() 264: p.doPrintln(a) 265: n, err = w.Write(p.buf) 266: p.free() 267: return(dlv) n> fmt.Fprintln() /usr/local/go/src/fmt/print.go:263 (PC: 0x10c02a8) 262: func Fprintln(w io.Writer, a ...interface{}) (n int, err error) {=> 263: p := newPrinter() 264: p.doPrintln(a) 265: n, err = w.Write(p.buf) 266: p.free() 267: return 268: }(dlv) n> fmt.Fprintln() /usr/local/go/src/fmt/print.go:264 (PC: 0x10c02b6) 262: func Fprintln(w io.Writer, a ...interface{}) (n int, err error) { 263: p := newPrinter()=> 264: p.doPrintln(a) 265: n, err = w.Write(p.buf) 266: p.free() 267: return 268: } 269:(dlv) n> fmt.Fprintln() /usr/local/go/src/fmt/print.go:265 (PC: 0x10c02e6). 262: func Fprintln(w io.Writer, a ...interface{}) (n int, err error) { 263: p := newPrinter() 264: p.doPrintln(a)=> 265: n, err = w.Write(p.buf) 266: p.free() 267: return 268: } 269: 270: // Println formats using the default formats for its operands and writes to standard output.(dlv) s> os.(*File).Write() /usr/local/go/src/os/file.go:149 (PC: 0x10b74c3) 144: } 145: 146: // Write writes len(b) bytes to the File. 147: // It returns the number of bytes written and an error, if any. 148: // Write returns a non-nil error when n != len(b).=> 149: func (f *File) Write(b []byte) (n int, err error) { 150: if err := f.checkValid("write"); err != nil { 151: return 0, err 152: } 153: n, e := f.write(b) 154: if n < 0 {(dlv) bt0 0x00000000010b74c3 in os.(*File).Write at /usr/local/go/src/os/file.go:1491 0x00000000010c033a in fmt.Fprintln at /usr/local/go/src/fmt/print.go:2652 0x00000000010c0433 in fmt.Println at /usr/local/go/src/fmt/print.go:2743 0x00000000010c629f in main.main at ./print.go:64 0x0000000001036598 in runtime.main at /usr/local/go/src/runtime/proc.go:2035 0x0000000001064211 in runtime.goexit at /usr/local/go/src/runtime/asm_amd64.s:1373(dlv) n> os.(*File).Write() /usr/local/go/src/os/file.go:150 (PC: 0x10b74e8) 145: 146: // Write writes len(b) bytes to the File. 147: // It returns the number of bytes written and an error, if any. 148: // Write returns a non-nil error when n != len(b). 149: func (f *File) Write(b []byte) (n int, err error) {=> 150: if err := f.checkValid("write"); err != nil { 151: return 0, err 152: } 153: n, e := f.write(b) 154: if n < 0 { 155: n = 0(dlv) n> os.(*File).Write() /usr/local/go/src/os/file.go:153 (PC: 0x10b7559) 148: // Write returns a non-nil error when n != len(b). 149: func (f *File) Write(b []byte) (n int, err error) { 150: if err := f.checkValid("write"); err != nil { 151: return 0, err 152: }=> 153: n, e := f.write(b) 154: if n < 0 { 155: n = 0 156: } 157: if n != len(b) { 158: err = io.ErrShortWrite(dlv) s> os.(*File).write() /usr/local/go/src/os/file_unix.go:279 (PC: 0x10b8ab3) 274: return n, err 275: } 276: 277: // write writes len(b) bytes to the File. 278: // It returns the number of bytes written and an error, if any.=> 279: func (f *File) write(b []byte) (n int, err error) { 280: n, err = f.pfd.Write(b) 281: runtime.KeepAlive(f) 282: return n, err 283: } 284:(dlv) n> os.(*File).write() /usr/local/go/src/os/file_unix.go:280 (PC: 0x10b8ad8) 275: } 276: 277: // write writes len(b) bytes to the File. 278: // It returns the number of bytes written and an error, if any. 279: func (f *File) write(b []byte) (n int, err error) {=> 280: n, err = f.pfd.Write(b) 281: runtime.KeepAlive(f) 282: return n, err 283: } 284: 285: // pwrite writes len(b) bytes to the File starting at byte offset off.(dlv) s> internal/poll.(*FD).Write() /usr/local/go/src/internal/poll/fd_unix.go:254 (PC: 0x10b4d8b) 249: return n, oobn, flags, sa, err 250: } 251: } 252: 253: // Write implements io.Writer.=> 254: func (fd *FD) Write(p []byte) (int, error) { 255: if err := fd.writeLock(); err != nil { 256: return 0, err 257: } 258: defer fd.writeUnlock() 259: if err := fd.pd.prepareWrite(fd.isFile); err != nil {(dlv) n> internal/poll.(*FD).Write() /usr/local/go/src/internal/poll/fd_unix.go:255 (PC: 0x10b4db9) 250: } 251: } 252: 253: // Write implements io.Writer. 254: func (fd *FD) Write(p []byte) (int, error) {=> 255: if err := fd.writeLock(); err != nil { 256: return 0, err 257: } 258: defer fd.writeUnlock() 259: if err := fd.pd.prepareWrite(fd.isFile); err != nil { 260: return 0, err(dlv) n> internal/poll.(*FD).Write() /usr/local/go/src/internal/poll/fd_unix.go:258 (PC: 0x10b4e2d) 253: // Write implements io.Writer. 254: func (fd *FD) Write(p []byte) (int, error) { 255: if err := fd.writeLock(); err != nil { 256: return 0, err 257: }=> 258: defer fd.writeUnlock() 259: if err := fd.pd.prepareWrite(fd.isFile); err != nil { 260: return 0, err 261: } 262: var nn int 263: for {(dlv) n> internal/poll.(*FD).Write() /usr/local/go/src/internal/poll/fd_unix.go:259 (PC: 0x10b4e6c) 254: func (fd *FD) Write(p []byte) (int, error) { 255: if err := fd.writeLock(); err != nil { 256: return 0, err 257: } 258: defer fd.writeUnlock()=> 259: if err := fd.pd.prepareWrite(fd.isFile); err != nil { 260: return 0, err 261: } 262: var nn int 263: for { 264: max := len(p)(dlv) n> internal/poll.(*FD).Write() /usr/local/go/src/internal/poll/fd_unix.go:262 (PC: 0x10b4f11) 257: } 258: defer fd.writeUnlock() 259: if err := fd.pd.prepareWrite(fd.isFile); err != nil { 260: return 0, err 261: }=> 262: var nn int 263: for { 264: max := len(p) 265: if fd.IsStream && max-nn > maxRW { 266: max = nn + maxRW 267: }(dlv) n> internal/poll.(*FD).Write() /usr/local/go/src/internal/poll/fd_unix.go:263 (PC: 0x10b4f1a) 258: defer fd.writeUnlock() 259: if err := fd.pd.prepareWrite(fd.isFile); err != nil { 260: return 0, err 261: } 262: var nn int=> 263: for { 264: max := len(p) 265: if fd.IsStream && max-nn > maxRW { 266: max = nn + maxRW 267: } 268: n, err := syscall.Write(fd.Sysfd, p[nn:max])(dlv) n> internal/poll.(*FD).Write() /usr/local/go/src/internal/poll/fd_unix.go:264 (PC: 0x10b4f1c) 259: if err := fd.pd.prepareWrite(fd.isFile); err != nil { 260: return 0, err 261: } 262: var nn int 263: for {=> 264: max := len(p) 265: if fd.IsStream && max-nn > maxRW { 266: max = nn + maxRW 267: } 268: n, err := syscall.Write(fd.Sysfd, p[nn:max]) 269: if n > 0 {(dlv) n> internal/poll.(*FD).Write() /usr/local/go/src/internal/poll/fd_unix.go:265 (PC: 0x10b4f2b) 260: return 0, err 261: } 262: var nn int 263: for { 264: max := len(p)=> 265: if fd.IsStream && max-nn > maxRW { 266: max = nn + maxRW 267: } 268: n, err := syscall.Write(fd.Sysfd, p[nn:max]) 269: if n > 0 { 270: nn += n(dlv) n> internal/poll.(*FD).Write() /usr/local/go/src/internal/poll/fd_unix.go:268 (PC: 0x10b52aa) 263: for { 264: max := len(p) 265: if fd.IsStream && max-nn > maxRW { 266: max = nn + maxRW 267: }=> 268: n, err := syscall.Write(fd.Sysfd, p[nn:max]) 269: if n > 0 { 270: nn += n 271: } 272: if nn == len(p) { 273: return nn, err(dlv) |
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧