1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 //static Lock debuglock;
12 static void go_vprintf(const char*, va_list);
14 // write to goroutine-local buffer if diverting output,
15 // or else standard error.
17 gwrite(const void *v
, intgo n
)
21 if(g
== nil
|| g
->writebuf
== nil
) {
22 // Avoid -D_FORTIFY_SOURCE problems.
23 int rv
__attribute__((unused
));
25 rv
= runtime_write(2, v
, n
);
34 runtime_memmove(g
->writebuf
, v
, n
);
40 runtime_dump(byte
*p
, int32 n
)
45 runtime_printpointer((byte
*)(uintptr
)(p
[i
]>>4));
46 runtime_printpointer((byte
*)(uintptr
)(p
[i
]&0xf));
57 runtime_prints(const char *s
)
59 gwrite(s
, runtime_findnull((const byte
*)s
));
63 runtime_printf(const char *s
, ...)
72 // Very simple printf. Only for debugging prints.
73 // Do not add to this without checking with Rob.
75 go_vprintf(const char *s
, va_list va
)
79 //runtime_lock(&debuglock);
90 runtime_printslice(va_arg(va
, Slice
));
93 runtime_printbyte(va_arg(va
, int32
));
96 runtime_printint(va_arg(va
, int32
));
99 runtime_printint(va_arg(va
, int64
));
102 runtime_printeface(va_arg(va
, Eface
));
105 runtime_printfloat(va_arg(va
, float64
));
108 runtime_printcomplex(va_arg(va
, __complex
double));
111 runtime_printiface(va_arg(va
, Iface
));
114 runtime_printpointer(va_arg(va
, void*));
117 runtime_prints(va_arg(va
, char*));
120 runtime_printstring(va_arg(va
, String
));
123 runtime_printbool(va_arg(va
, int));
126 runtime_printuint(va_arg(va
, uint64
));
129 runtime_printhex(va_arg(va
, uint32
));
132 runtime_printhex(va_arg(va
, uint64
));
140 //runtime_unlock(&debuglock);
144 runtime_printpc(void *p
__attribute__ ((unused
)))
146 runtime_prints("PC=");
147 runtime_printhex((uint64
)(uintptr
)runtime_getcallerpc(p
));
151 runtime_printbool(_Bool v
)
161 runtime_printbyte(int8 c
)
167 runtime_printfloat(double v
)
177 i
= __builtin_isinf_sign(v
);
187 n
= 7; // digits printed
219 // format +d.dddd+edd
239 buf
[n
+4] = (e
/100) + '0';
240 buf
[n
+5] = (e
/10)%10 + '0';
241 buf
[n
+6] = (e
%10) + '0';
246 runtime_printcomplex(__complex
double v
)
249 runtime_printfloat(__builtin_creal(v
));
250 runtime_printfloat(__builtin_cimag(v
));
255 runtime_printuint(uint64 v
)
260 for(i
=nelem(buf
)-1; i
>0; i
--) {
266 gwrite(buf
+i
, nelem(buf
)-i
);
270 runtime_printint(int64 v
)
276 runtime_printuint(v
);
280 runtime_printhex(uint64 v
)
282 static const char *dig
= "0123456789abcdef";
288 buf
[--i
] = dig
[v
%16];
293 gwrite(buf
+i
, nelem(buf
)-i
);
297 runtime_printpointer(void *p
)
299 runtime_printhex((uint64
)(uintptr
)p
);
303 runtime_printstring(String v
)
305 // if(v.len > runtime_maxstring) {
306 // gwrite("[string too long]", 17);
310 gwrite(v
.str
, v
.len
);
314 __go_print_space(void)