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.
8 //static Lock debuglock;
10 static void go_vprintf(const char*, va_list);
12 // write to goroutine-local buffer if diverting output,
13 // or else standard error.
15 gwrite(const void *v
, int32 n
)
19 if(g
== nil
|| g
->writebuf
== nil
) {
20 runtime_write(2, v
, n
);
29 runtime_memmove(g
->writebuf
, v
, n
);
35 runtime_dump(byte
*p
, int32 n
)
40 runtime_printpointer((byte
*)(uintptr
)(p
[i
]>>4));
41 runtime_printpointer((byte
*)(uintptr
)(p
[i
]&0xf));
52 runtime_prints(const char *s
)
54 gwrite(s
, runtime_findnull((const byte
*)s
));
58 runtime_printf(const char *s
, ...)
67 // Very simple printf. Only for debugging prints.
68 // Do not add to this without checking with Rob.
70 go_vprintf(const char *s
, va_list va
)
74 //runtime_lock(&debuglock);
85 runtime_printslice(va_arg(va
, Slice
));
88 runtime_printint(va_arg(va
, int32
));
91 runtime_printint(va_arg(va
, int64
));
94 runtime_printeface(va_arg(va
, Eface
));
97 runtime_printfloat(va_arg(va
, float64
));
100 runtime_printcomplex(va_arg(va
, __complex
double));
103 runtime_printiface(va_arg(va
, Iface
));
106 runtime_printpointer(va_arg(va
, void*));
109 runtime_prints(va_arg(va
, char*));
112 runtime_printstring(va_arg(va
, String
));
115 runtime_printbool(va_arg(va
, int));
118 runtime_printuint(va_arg(va
, uint64
));
121 runtime_printhex(va_arg(va
, uint32
));
124 runtime_printhex(va_arg(va
, uint64
));
132 //runtime_unlock(&debuglock);
136 runtime_printpc(void *p
__attribute__ ((unused
)))
138 runtime_prints("PC=");
139 runtime_printhex((uint64
)(uintptr
)runtime_getcallerpc(p
));
143 runtime_printbool(_Bool v
)
153 runtime_printfloat(double v
)
159 if(runtime_isNaN(v
)) {
163 if(runtime_isInf(v
, 1)) {
167 if(runtime_isInf(v
, -1)) {
172 n
= 7; // digits printed
204 // format +d.dddd+edd
224 buf
[n
+4] = (e
/100) + '0';
225 buf
[n
+5] = (e
/10)%10 + '0';
226 buf
[n
+6] = (e
%10) + '0';
231 runtime_printcomplex(__complex
double v
)
234 runtime_printfloat(__builtin_creal(v
));
235 runtime_printfloat(__builtin_cimag(v
));
240 runtime_printuint(uint64 v
)
245 for(i
=nelem(buf
)-1; i
>0; i
--) {
251 gwrite(buf
+i
, nelem(buf
)-i
);
255 runtime_printint(int64 v
)
261 runtime_printuint(v
);
265 runtime_printhex(uint64 v
)
267 static const char *dig
= "0123456789abcdef";
273 buf
[--i
] = dig
[v
%16];
278 gwrite(buf
+i
, nelem(buf
)-i
);
282 runtime_printpointer(void *p
)
284 runtime_printhex((uint64
)(uintptr
)p
);
288 runtime_printstring(String v
)
290 // extern uint32 runtime_maxstring;
292 // if(v.len > runtime_maxstring) {
293 // gwrite("[invalid string]", 16);
297 gwrite(v
.__data
, v
.__length
);
301 __go_print_space(void)