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.
9 //static Lock debuglock;
11 static void go_vprintf(const char*, va_list);
13 // write to goroutine-local buffer if diverting output,
14 // or else standard error.
16 gwrite(const void *v
, int32 n
)
20 if(g
== nil
|| g
->writebuf
== nil
) {
21 // Avoid -D_FORTIFY_SOURCE problems.
22 int rv
__attribute__((unused
));
24 rv
= runtime_write(2, v
, n
);
33 runtime_memmove(g
->writebuf
, v
, n
);
39 runtime_dump(byte
*p
, int32 n
)
44 runtime_printpointer((byte
*)(uintptr
)(p
[i
]>>4));
45 runtime_printpointer((byte
*)(uintptr
)(p
[i
]&0xf));
56 runtime_prints(const char *s
)
58 gwrite(s
, runtime_findnull((const byte
*)s
));
62 runtime_printf(const char *s
, ...)
71 // Very simple printf. Only for debugging prints.
72 // Do not add to this without checking with Rob.
74 go_vprintf(const char *s
, va_list va
)
78 //runtime_lock(&debuglock);
89 runtime_printslice(va_arg(va
, Slice
));
92 runtime_printint(va_arg(va
, int32
));
95 runtime_printint(va_arg(va
, int64
));
98 runtime_printeface(va_arg(va
, Eface
));
101 runtime_printfloat(va_arg(va
, float64
));
104 runtime_printcomplex(va_arg(va
, __complex
double));
107 runtime_printiface(va_arg(va
, Iface
));
110 runtime_printpointer(va_arg(va
, void*));
113 runtime_prints(va_arg(va
, char*));
116 runtime_printstring(va_arg(va
, String
));
119 runtime_printbool(va_arg(va
, int));
122 runtime_printuint(va_arg(va
, uint64
));
125 runtime_printhex(va_arg(va
, uint32
));
128 runtime_printhex(va_arg(va
, uint64
));
136 //runtime_unlock(&debuglock);
140 runtime_printpc(void *p
__attribute__ ((unused
)))
142 runtime_prints("PC=");
143 runtime_printhex((uint64
)(uintptr
)runtime_getcallerpc(p
));
147 runtime_printbool(_Bool v
)
157 runtime_printfloat(double v
)
167 i
= __builtin_isinf_sign(v
);
177 n
= 7; // digits printed
209 // format +d.dddd+edd
229 buf
[n
+4] = (e
/100) + '0';
230 buf
[n
+5] = (e
/10)%10 + '0';
231 buf
[n
+6] = (e
%10) + '0';
236 runtime_printcomplex(__complex
double v
)
239 runtime_printfloat(__builtin_creal(v
));
240 runtime_printfloat(__builtin_cimag(v
));
245 runtime_printuint(uint64 v
)
250 for(i
=nelem(buf
)-1; i
>0; i
--) {
256 gwrite(buf
+i
, nelem(buf
)-i
);
260 runtime_printint(int64 v
)
266 runtime_printuint(v
);
270 runtime_printhex(uint64 v
)
272 static const char *dig
= "0123456789abcdef";
278 buf
[--i
] = dig
[v
%16];
283 gwrite(buf
+i
, nelem(buf
)-i
);
287 runtime_printpointer(void *p
)
289 runtime_printhex((uint64
)(uintptr
)p
);
293 runtime_printstring(String v
)
295 // extern uint32 runtime_maxstring;
297 // if(v.len > runtime_maxstring) {
298 // gwrite("[string too long]", 17);
302 gwrite(v
.str
, v
.len
);
306 __go_print_space(void)