ref: b2ca8481f37bccdd0488cf7de05ea79cd17ae5ed
parent: f0eabb72719d366449d6456a5843793c9b0d62ab
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Aug 28 09:48:29 EDT 2016
Add std.backtrace()
--- /dev/null
+++ b/lib/std/backtrace+x64.myr
@@ -1,0 +1,26 @@
+use "types"
+use "fmt"
+
+pkg std =
+ const backtrace : (pc : void#[:] -> std.size)
+;;
+
+type stackrec = struct
+ next : stackrec#
+ pc : void#
+;;
+
+extern const getbp : (-> stackrec#)
+const backtrace = {pc
+ var bp, i, len
+
+ i = 0
+ len = pc.len
+ bp = getbp()
+ while bp != (0 : stackrec#) && i < len
+ pc[i++] = bp.pc
+ bp = bp.next
+ ;;
+ -> i
+}
+
--- a/lib/std/bld.sub
+++ b/lib/std/bld.sub
@@ -84,6 +84,12 @@
memops-impl+posixy-x64.s
memops-impl+plan9-x64.s
+
+ # arch specific files
+ backtrace+x64.myr
+ getbp+posixy-x64.s
+ getbp+plan9-x64.s
+
# platform specific files
dial+plan9.myr
dial+posixy.myr
--- /dev/null
+++ b/lib/std/getbp+plan9-x64.s
@@ -1,0 +1,3 @@
+TEXT std$getbp+0(SB),$0
+ MOVQ BP,AX
+ RET
--- /dev/null
+++ b/lib/std/getbp+posixy-x64.s
@@ -1,0 +1,6 @@
+.globl std$getbp
+.globl _std$getbp
+std$getbp:
+_std$getbp:
+ movq %rbp,%rax
+ ret