summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-08-28 13:48:29 -0700
committerOri Bernstein <ori@eigenstate.org>2016-08-28 13:48:29 -0700
commitb2ca8481f37bccdd0488cf7de05ea79cd17ae5ed (patch)
treee7ad5d9e305b5ca5e96ab1ebe19d6f30ae8a3035
parentf0eabb72719d366449d6456a5843793c9b0d62ab (diff)
downloadmc-b2ca8481f37bccdd0488cf7de05ea79cd17ae5ed.tar.gz
Add std.backtrace()
-rw-r--r--lib/std/backtrace+x64.myr26
-rw-r--r--lib/std/bld.sub6
-rw-r--r--lib/std/getbp+plan9-x64.s3
-rw-r--r--lib/std/getbp+posixy-x64.s6
4 files changed, 41 insertions, 0 deletions
diff --git a/lib/std/backtrace+x64.myr b/lib/std/backtrace+x64.myr
new file mode 100644
index 0000000..61d6625
--- /dev/null
+++ b/lib/std/backtrace+x64.myr
@@ -0,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
+}
+
diff --git a/lib/std/bld.sub b/lib/std/bld.sub
index 6f7173c..efd8645 100644
--- a/lib/std/bld.sub
+++ b/lib/std/bld.sub
@@ -84,6 +84,12 @@ lib std {inc=.} =
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
diff --git a/lib/std/getbp+plan9-x64.s b/lib/std/getbp+plan9-x64.s
new file mode 100644
index 0000000..441a9ea
--- /dev/null
+++ b/lib/std/getbp+plan9-x64.s
@@ -0,0 +1,3 @@
+TEXT std$getbp+0(SB),$0
+ MOVQ BP,AX
+ RET
diff --git a/lib/std/getbp+posixy-x64.s b/lib/std/getbp+posixy-x64.s
new file mode 100644
index 0000000..1c8fdfc
--- /dev/null
+++ b/lib/std/getbp+posixy-x64.s
@@ -0,0 +1,6 @@
+.globl std$getbp
+.globl _std$getbp
+std$getbp:
+_std$getbp:
+ movq %rbp,%rax
+ ret