go-traceback.c 790 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* go-traceback.c -- stack backtrace for Go.
  2. Copyright 2012 The Go Authors. All rights reserved.
  3. Use of this source code is governed by a BSD-style
  4. license that can be found in the LICENSE file. */
  5. #include "config.h"
  6. #include "runtime.h"
  7. /* Print a stack trace for the current goroutine. */
  8. void
  9. runtime_traceback ()
  10. {
  11. Location locbuf[100];
  12. int32 c;
  13. c = runtime_callers (1, locbuf, nelem (locbuf), false);
  14. runtime_printtrace (locbuf, c, true);
  15. }
  16. void
  17. runtime_printtrace (Location *locbuf, int32 c, bool current)
  18. {
  19. int32 i;
  20. for (i = 0; i < c; ++i)
  21. {
  22. if (runtime_showframe (locbuf[i].function, current))
  23. {
  24. runtime_printf ("%S\n", locbuf[i].function);
  25. runtime_printf ("\t%S:%D\n", locbuf[i].filename,
  26. (int64) locbuf[i].lineno);
  27. }
  28. }
  29. }