Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Stack-traces/00-META.yaml
Normal file
3
Task/Stack-traces/00-META.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Stack_traces
|
||||
note: Programming environment operations
|
||||
15
Task/Stack-traces/00-TASK.txt
Normal file
15
Task/Stack-traces/00-TASK.txt
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers.
|
||||
|
||||
|
||||
;Task:
|
||||
Print out (in a manner considered suitable for the platform) the current call stack.
|
||||
|
||||
The amount of information printed for each frame on the call stack is not constrained, but should include at least the name of the function or method at that level of the stack frame.
|
||||
|
||||
You may explicitly add a call to produce the stack trace to the (example) code being instrumented for examination.
|
||||
|
||||
The task should allow the program to continue after generating the stack trace.
|
||||
|
||||
The task report here must include the trace from a sample program.
|
||||
<br><br>
|
||||
|
||||
31
Task/Stack-traces/Ada/stack-traces.ada
Normal file
31
Task/Stack-traces/Ada/stack-traces.ada
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with GNAT.Traceback;
|
||||
with GNAT.Traceback.Symbolic;
|
||||
|
||||
procedure Test_Stack_Trace is
|
||||
procedure Call_Stack is
|
||||
Trace : GNAT.Traceback.Tracebacks_Array (1..1_000);
|
||||
Length : Natural;
|
||||
begin
|
||||
GNAT.Traceback.Call_Chain (Trace, Length);
|
||||
Put_Line (GNAT.Traceback.Symbolic.Symbolic_Traceback (Trace (1..Length)));
|
||||
end Call_Stack;
|
||||
|
||||
procedure Inner (K : Integer) is
|
||||
begin
|
||||
Call_Stack;
|
||||
end Inner;
|
||||
|
||||
procedure Middle (X, Y : Integer) is
|
||||
begin
|
||||
Inner (X * Y);
|
||||
end Middle;
|
||||
|
||||
procedure Outer (A, B, C : Integer) is
|
||||
begin
|
||||
Middle (A + B, B + C);
|
||||
end Outer;
|
||||
|
||||
begin
|
||||
Outer (2,3,5);
|
||||
end Test_Stack_Trace;
|
||||
17
Task/Stack-traces/AutoHotkey/stack-traces-1.ahk
Normal file
17
Task/Stack-traces/AutoHotkey/stack-traces-1.ahk
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
f()
|
||||
return
|
||||
|
||||
f()
|
||||
{
|
||||
return g()
|
||||
}
|
||||
|
||||
g()
|
||||
{
|
||||
ListLines
|
||||
msgbox, lines recently executed
|
||||
x = local to g
|
||||
ListVars
|
||||
msgbox, variable bindings
|
||||
}
|
||||
#Persistent
|
||||
14
Task/Stack-traces/AutoHotkey/stack-traces-2.ahk
Normal file
14
Task/Stack-traces/AutoHotkey/stack-traces-2.ahk
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
001: f()
|
||||
006: Return,g()
|
||||
011: ListLines (0.05)
|
||||
012: MsgBox,lines recently executed (3.81)
|
||||
013: x = local to g
|
||||
014: ListVars
|
||||
015: MsgBox,variable bindings (3.94)
|
||||
016: }
|
||||
002: Return (181.66)
|
||||
|
||||
Global Variables (alphabetical)
|
||||
--------------------------------------------------
|
||||
0[1 of 3]: 0
|
||||
ErrorLevel[1 of 3]: 0
|
||||
25
Task/Stack-traces/C-sharp/stack-traces-1.cs
Normal file
25
Task/Stack-traces/C-sharp/stack-traces-1.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Inner()
|
||||
{
|
||||
Console.WriteLine(new StackTrace());
|
||||
}
|
||||
|
||||
static void Middle()
|
||||
{
|
||||
Inner();
|
||||
}
|
||||
|
||||
static void Outer()
|
||||
{
|
||||
Middle();
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
Outer();
|
||||
}
|
||||
}
|
||||
4
Task/Stack-traces/C-sharp/stack-traces-2.cs
Normal file
4
Task/Stack-traces/C-sharp/stack-traces-2.cs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
at Program.Inner()
|
||||
at Program.Middle()
|
||||
at Program.Outer()
|
||||
at Program.Main()
|
||||
39
Task/Stack-traces/C/stack-traces-1.c
Normal file
39
Task/Stack-traces/C/stack-traces-1.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <execinfo.h>
|
||||
|
||||
#define MAX_BT 200
|
||||
|
||||
void print_stack_trace()
|
||||
{
|
||||
void *buffer[MAX_BT];
|
||||
int n;
|
||||
|
||||
n = backtrace(buffer, MAX_BT);
|
||||
fprintf(stderr, "--- (depth %d) ---\n", n);
|
||||
backtrace_symbols_fd(buffer, n, STDERR_FILENO);
|
||||
}
|
||||
|
||||
|
||||
void inner(int k)
|
||||
{
|
||||
print_stack_trace();
|
||||
}
|
||||
|
||||
void middle(int x, int y)
|
||||
{
|
||||
inner(x*y);
|
||||
}
|
||||
|
||||
void outer(int a, int b, int c)
|
||||
{
|
||||
middle(a+b, b+c);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
outer(2,3,5);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
79
Task/Stack-traces/C/stack-traces-2.c
Normal file
79
Task/Stack-traces/C/stack-traces-2.c
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/* stack_trace.c - macros for hinting/tracing where a program crashed
|
||||
on a system _without_ any form of debugger.
|
||||
|
||||
Simple goodbye_cruel_world.c example:
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define STACK_TRACE_ON // compile in these "stack_trace" routines
|
||||
#include "stack_trace.h"
|
||||
|
||||
void goodbye_cruel_world()
|
||||
BEGIN(goodbye_cruel_world)
|
||||
print_stack_trace();
|
||||
for(;;){}
|
||||
END
|
||||
|
||||
int main()
|
||||
BEGIN(main)
|
||||
stack_trace.on = TRUE; // turn on runtime tracing
|
||||
goodbye_cruel_world();
|
||||
stack_trace.on = FALSE;
|
||||
RETURN(EXIT_SUCCESS);
|
||||
END
|
||||
|
||||
Output:
|
||||
goodbye_cruel_world.c:8: BEGIN goodbye_cruel_world[0x80486a8], stack(depth:1, size:60)
|
||||
goodbye_cruel_world.c:8: goodbye_cruel_world[0x80486a8] --- stack(depth:2, size:60) ---
|
||||
goodbye_cruel_world.c:14: main[0x80486f4] --- stack(depth:1, size:0) ---
|
||||
goodbye_cruel_world.c:8: --- (depth 2) ---
|
||||
|
||||
*/
|
||||
#ifndef _LINUX_STDDEF_H
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
typedef struct stack_trace_frame_s {
|
||||
const char *file_name;
|
||||
int file_line;
|
||||
const char *proc_name;
|
||||
void *proc_addr;
|
||||
struct stack_trace_frame_s *down, *up;
|
||||
} stack_trace_frame_t;
|
||||
|
||||
#define SKIP
|
||||
typedef enum {TRUE=1, FALSE=0} bool_t;
|
||||
|
||||
typedef struct {
|
||||
bool_t on;
|
||||
struct { const char *_begin, *_print, *_return, *_exit, *_end; } fmt;
|
||||
struct { int depth; stack_trace_frame_t *lwb, *upb; } stack;
|
||||
struct { int lwb, by, upb; const char *prefix; } indent;
|
||||
} stack_trace_t;
|
||||
|
||||
extern stack_trace_t stack_trace;
|
||||
|
||||
void stack_trace_begin(char *SKIP, stack_trace_frame_t *SKIP);
|
||||
void stack_trace_end(char *SKIP, int SKIP);
|
||||
void print_stack_trace();
|
||||
|
||||
|
||||
#ifdef STACK_TRACE_ON
|
||||
|
||||
/* Many ThanX to Steve R Bourne for inspiring the following macros ;-) */
|
||||
#define BEGIN(x) { auto stack_trace_frame_t this = {__FILE__, __LINE__, #x, &x, NULL, NULL}; \
|
||||
stack_trace_begin(stack_trace.fmt._begin, &this); {
|
||||
#define RETURN(x) { stack_trace_end(stack_trace.fmt._return, __LINE__); return(x); }
|
||||
#define EXIT(x) { stack_trace_end(stack_trace.fmt._exit, __LINE__); exit(x); }
|
||||
#define END } stack_trace_end(stack_trace.fmt._end, __LINE__); }
|
||||
|
||||
#else
|
||||
|
||||
/* Apologies to Landon Curt Noll and Larry Bassel for the following macros :-) */
|
||||
#define BEGIN(x) {
|
||||
#define RETURN(x) return(x)
|
||||
#define EXIT(x) exit(x)
|
||||
#define END }
|
||||
|
||||
#endif
|
||||
85
Task/Stack-traces/C/stack-traces-3.c
Normal file
85
Task/Stack-traces/C/stack-traces-3.c
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define STACK_TRACE_ON
|
||||
#include "stack_trace.h"
|
||||
|
||||
#define indent_fmt "%s"
|
||||
#define std_cc_diag_fmt "%s:%d: "
|
||||
#define stack_trace_diag_fmt " %s[0x%x], stack(depth:%d, size:%u)\n"
|
||||
#define stack_trace_fmt "%s:%d:\t%s[0x%x]\t--- stack(depth:%d, size:%u) ---\n"
|
||||
|
||||
stack_trace_t stack_trace = {
|
||||
FALSE, /* default: stack_trace.on == FALSE */
|
||||
{ std_cc_diag_fmt""indent_fmt"BEGIN"stack_trace_diag_fmt,
|
||||
stack_trace_fmt,
|
||||
std_cc_diag_fmt""indent_fmt"RETURN"stack_trace_diag_fmt,
|
||||
std_cc_diag_fmt""indent_fmt"EXIT"stack_trace_diag_fmt,
|
||||
std_cc_diag_fmt""indent_fmt"END"stack_trace_diag_fmt },
|
||||
{ 0, (stack_trace_frame_t*)NULL, (stack_trace_frame_t*)NULL }, /* stack */
|
||||
{ 19, 2, 20, " " } /* indent wrap */
|
||||
};
|
||||
|
||||
void stack_trace_begin(const char *fmt, stack_trace_frame_t *this){
|
||||
if(stack_trace.on){
|
||||
fprintf(stderr, fmt,
|
||||
this->file_name, this->file_line, /* file details */
|
||||
stack_trace.indent.prefix+stack_trace.indent.lwb,
|
||||
this->proc_name, this->proc_addr, /* procedure details */
|
||||
stack_trace.stack.depth, (unsigned)stack_trace.stack.lwb-(unsigned)this);
|
||||
stack_trace.indent.lwb =
|
||||
( stack_trace.indent.lwb - stack_trace.indent.by ) % stack_trace.indent.upb;
|
||||
}
|
||||
|
||||
if(!stack_trace.stack.upb){ /* this IS the stack !! */
|
||||
stack_trace.stack.lwb = stack_trace.stack.upb = this;
|
||||
} else {
|
||||
this -> down = stack_trace.stack.upb;
|
||||
stack_trace.stack.upb -> up = this;
|
||||
stack_trace.stack.upb = this;
|
||||
}
|
||||
stack_trace.stack.depth++;
|
||||
}
|
||||
|
||||
void stack_trace_end(const char *fmt, int line){
|
||||
stack_trace.stack.depth--;
|
||||
if(stack_trace.on){
|
||||
stack_trace.indent.lwb =
|
||||
( stack_trace.indent.lwb + stack_trace.indent.by ) % stack_trace.indent.upb;
|
||||
stack_trace_frame_t *this = stack_trace.stack.upb;
|
||||
fprintf(stderr, fmt,
|
||||
this->file_name, this->file_line, /* file details */
|
||||
stack_trace.indent.prefix+stack_trace.indent.lwb,
|
||||
this->proc_name, this->proc_addr, /* procedure details */
|
||||
stack_trace.stack.depth, (unsigned)stack_trace.stack.lwb-(unsigned)this);
|
||||
}
|
||||
stack_trace.stack.upb = stack_trace.stack.upb -> down;
|
||||
}
|
||||
|
||||
void print_indent(){
|
||||
if(!stack_trace.stack.upb){
|
||||
/* fprintf(stderr, "STACK_TRACE_ON not #defined during compilation\n"); */
|
||||
} else {
|
||||
stack_trace_frame_t *this = stack_trace.stack.upb;
|
||||
fprintf(stderr, std_cc_diag_fmt""indent_fmt,
|
||||
this->file_name, this->file_line, /* file details */
|
||||
stack_trace.indent.prefix+stack_trace.indent.lwb
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void print_stack_trace() {
|
||||
if(!stack_trace.stack.upb){
|
||||
/* fprintf(stderr, "STACK_TRACE_ON not #defined during compilation\n"); */
|
||||
} else {
|
||||
int depth = stack_trace.stack.depth;
|
||||
stack_trace_frame_t *this = stack_trace.stack.upb;
|
||||
for(this = stack_trace.stack.upb; this; this = this->down, depth--){
|
||||
fprintf(stderr, stack_trace.fmt._print,
|
||||
this->file_name, this->file_line, /* file details */
|
||||
this->proc_name, this->proc_addr, /* procedure details */
|
||||
depth, (unsigned)stack_trace.stack.lwb-(unsigned)this);
|
||||
}
|
||||
print_indent(); fprintf(stderr, "--- (depth %d) ---\n", stack_trace.stack.depth);
|
||||
}
|
||||
}
|
||||
29
Task/Stack-traces/C/stack-traces-4.c
Normal file
29
Task/Stack-traces/C/stack-traces-4.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define STACK_TRACE_ON /* compile in these "stack_trace" routines */
|
||||
#include "stack_trace.h"
|
||||
|
||||
void inner(int k)
|
||||
BEGIN(inner)
|
||||
print_indent(); printf("*** Now dump the stack ***\n");
|
||||
print_stack_trace();
|
||||
END
|
||||
|
||||
void middle(int x, int y)
|
||||
BEGIN(middle)
|
||||
inner(x*y);
|
||||
END
|
||||
|
||||
void outer(int a, int b, int c)
|
||||
BEGIN(outer)
|
||||
middle(a+b, b+c);
|
||||
END
|
||||
|
||||
int main()
|
||||
BEGIN(main)
|
||||
stack_trace.on = TRUE; /* turn on runtime tracing */
|
||||
outer(2,3,5);
|
||||
stack_trace.on = FALSE;
|
||||
RETURN(EXIT_SUCCESS);
|
||||
END
|
||||
2
Task/Stack-traces/Clojure/stack-traces.clj
Normal file
2
Task/Stack-traces/Clojure/stack-traces.clj
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(doall
|
||||
(map println (.dumpAllThreads (java.lang.management.ManagementFactory/getThreadMXBean) false false)))
|
||||
3
Task/Stack-traces/Common-Lisp/stack-traces-1.lisp
Normal file
3
Task/Stack-traces/Common-Lisp/stack-traces-1.lisp
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(swank-backend:call-with-debugging-environment
|
||||
(lambda ()
|
||||
(swank:backtrace 0 nil)))
|
||||
4
Task/Stack-traces/Common-Lisp/stack-traces-2.lisp
Normal file
4
Task/Stack-traces/Common-Lisp/stack-traces-2.lisp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
((0 "((LAMBDA (SWANK-BACKEND::DEBUGGER-LOOP-FN)) #<FUNCTION (LAMBDA #) {100459BBC9}>)")
|
||||
(1 "(SB-INT:SIMPLE-EVAL-IN-LEXENV (SWANK-BACKEND:CALL-WITH-DEBUGGING-ENVIRONMENT (LAMBDA () (SWANK:BACKTRACE 0 NIL))) #<NULL-LEXENV>)")
|
||||
(2 "(SWANK::EVAL-REGION \"(swank-backend:call-with-debugging-environment\\n (lambda ()\\n (swank:backtrace 0 nil)))\\n\\n\")")
|
||||
(3 "((LAMBDA ()))") ...)
|
||||
17
Task/Stack-traces/Common-Lisp/stack-traces-3.lisp
Normal file
17
Task/Stack-traces/Common-Lisp/stack-traces-3.lisp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
CL-USER> (sb-debug:backtrace 7)
|
||||
0: (SB-DEBUG::MAP-BACKTRACE
|
||||
#<CLOSURE (LAMBDA (SB-DEBUG::FRAME)) {1193EFCD}>)[:EXTERNAL]
|
||||
1: (BACKTRACE
|
||||
7
|
||||
#<TWO-WAY-STREAM
|
||||
:INPUT-STREAM #<SWANK-BACKEND::SLIME-INPUT-STREAM {120F6519}>
|
||||
:OUTPUT-STREAM #<SWANK-BACKEND::SLIME-OUTPUT-STREAM {1208F3E1}>>)
|
||||
2: (SB-INT:SIMPLE-EVAL-IN-LEXENV (BACKTRACE 7) #<NULL-LEXENV>)
|
||||
3: (SWANK::EVAL-REGION
|
||||
"(sb-debug:backtrace 7)
|
||||
")
|
||||
4: ((LAMBDA ()))
|
||||
5: (SWANK::TRACK-PACKAGE #<CLOSURE (LAMBDA ()) {1193ECBD}>)
|
||||
6: (SWANK::CALL-WITH-RETRY-RESTART
|
||||
"Retry SLIME REPL evaluation request."
|
||||
#<CLOSURE (LAMBDA ()) {1193EC4D}>)
|
||||
10
Task/Stack-traces/D/stack-traces.d
Normal file
10
Task/Stack-traces/D/stack-traces.d
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import std.stdio, core.runtime;
|
||||
|
||||
void inner() { defaultTraceHandler.writeln; }
|
||||
void middle() { inner; }
|
||||
void outer() { middle; }
|
||||
|
||||
void main() {
|
||||
outer;
|
||||
"After the stack trace.".writeln;
|
||||
}
|
||||
21
Task/Stack-traces/DWScript/stack-traces.dw
Normal file
21
Task/Stack-traces/DWScript/stack-traces.dw
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
procedure Inner;
|
||||
begin
|
||||
try
|
||||
raise Exception.Create('');
|
||||
except
|
||||
on E: Exception do
|
||||
PrintLn(E.StackTrace);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure Middle;
|
||||
begin
|
||||
Inner;
|
||||
end;
|
||||
|
||||
procedure Outer;
|
||||
begin
|
||||
Middle;
|
||||
end;
|
||||
|
||||
Outer;
|
||||
25
Task/Stack-traces/Elena/stack-traces.elena
Normal file
25
Task/Stack-traces/Elena/stack-traces.elena
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import extensions;
|
||||
|
||||
public singleton program
|
||||
{
|
||||
inner()
|
||||
{
|
||||
console.printLine(new CallStack())
|
||||
}
|
||||
|
||||
middle()
|
||||
{
|
||||
self.inner()
|
||||
}
|
||||
|
||||
outer()
|
||||
{
|
||||
self.middle()
|
||||
}
|
||||
|
||||
// program entry point
|
||||
function()
|
||||
{
|
||||
program.outer()
|
||||
}
|
||||
}
|
||||
25
Task/Stack-traces/Elixir/stack-traces.elixir
Normal file
25
Task/Stack-traces/Elixir/stack-traces.elixir
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
defmodule Stack_traces do
|
||||
def main do
|
||||
{:ok, a} = outer
|
||||
IO.inspect a
|
||||
end
|
||||
|
||||
defp outer do
|
||||
{:ok, a} = middle
|
||||
{:ok, a}
|
||||
end
|
||||
|
||||
defp middle do
|
||||
{:ok, a} = inner
|
||||
{:ok, a}
|
||||
end
|
||||
|
||||
defp inner do
|
||||
try do
|
||||
throw(42)
|
||||
catch 42 -> {:ok, :erlang.get_stacktrace}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Stack_traces.main
|
||||
18
Task/Stack-traces/Erlang/stack-traces.erl
Normal file
18
Task/Stack-traces/Erlang/stack-traces.erl
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
-module(stack_traces).
|
||||
|
||||
-export([main/0]).
|
||||
|
||||
main() ->
|
||||
{ok,A} = outer(),
|
||||
io:format("~p\n", [A]).
|
||||
|
||||
outer() ->
|
||||
{ok,A} = middle(),
|
||||
{ok,A}.
|
||||
|
||||
middle() ->
|
||||
{ok,A} = inner(),
|
||||
{ok,A}.
|
||||
|
||||
inner() ->
|
||||
try throw(42) catch 42 -> {ok,erlang:get_stacktrace()} end.
|
||||
12
Task/Stack-traces/F-Sharp/stack-traces.fs
Normal file
12
Task/Stack-traces/F-Sharp/stack-traces.fs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
open System.Diagnostics
|
||||
|
||||
type myClass() =
|
||||
member this.inner() = printfn "%A" (new StackTrace())
|
||||
member this.middle() = this.inner()
|
||||
member this.outer() = this.middle()
|
||||
|
||||
[<EntryPoint>]
|
||||
let main args =
|
||||
let that = new myClass()
|
||||
that.outer()
|
||||
0
|
||||
2
Task/Stack-traces/Factor/stack-traces.factor
Normal file
2
Task/Stack-traces/Factor/stack-traces.factor
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
USE: prettyprint
|
||||
get-callstack callstack.
|
||||
14
Task/Stack-traces/Forth/stack-traces.fth
Normal file
14
Task/Stack-traces/Forth/stack-traces.fth
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[UNDEFINED] R.S [IF]
|
||||
\ Return stack counterpart of DEPTH
|
||||
\ Note the STACK-CELLS correction is there to hide RDEPTH itself
|
||||
( -- n)
|
||||
: RDEPTH STACK-CELLS -2 [+] CELLS RP@ - ;
|
||||
|
||||
\ Return stack counterpart of .S
|
||||
\ Note the : R.S R> .. >R ; sequence is there to hide R.S itself
|
||||
( --)
|
||||
: R.S R> CR RDEPTH DUP 0> IF DUP
|
||||
BEGIN DUP WHILE R> -ROT 1- REPEAT DROP DUP
|
||||
BEGIN DUP WHILE ROT DUP . >R 1- REPEAT DROP
|
||||
THEN ." (TORS) " DROP >R ;
|
||||
[THEN]
|
||||
21
Task/Stack-traces/FreeBASIC/stack-traces.basic
Normal file
21
Task/Stack-traces/FreeBASIC/stack-traces.basic
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#include "windows.bi"
|
||||
|
||||
Private Function Fn2() As Long
|
||||
Dim frames(0 To 60) As Any Ptr
|
||||
Dim framesPtr As Any Ptr Ptr = @frames(0)
|
||||
Dim hash As DWORD
|
||||
Dim As Long caught = CaptureStackBackTrace(0, 61, framesPtr, @hash)
|
||||
Print Using "Caught & frames using stack capture"; caught
|
||||
For i As Long = 0 To caught - 1
|
||||
Print Using "&) &"; caught - i; Hex(frames(i))
|
||||
Next
|
||||
Return caught
|
||||
End Function
|
||||
|
||||
Private Sub Fn1(num As Ulong)
|
||||
Dim As Long numFn2 = Fn2()
|
||||
Print Using "Fn2 returned & with num = &"; numFn2; num
|
||||
End Sub
|
||||
|
||||
Fn1(87)
|
||||
Sleep
|
||||
14
Task/Stack-traces/Go/stack-traces.go
Normal file
14
Task/Stack-traces/Go/stack-traces.go
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func main() {
|
||||
stackTrace := make([]byte, 1024)
|
||||
n := runtime.Stack(stackTrace, true)
|
||||
stackTrace = stackTrace[:n]
|
||||
fmt.Printf("%s\n", stackTrace)
|
||||
fmt.Printf("(%d bytes)\n", len(stackTrace))
|
||||
}
|
||||
1
Task/Stack-traces/Groovy/stack-traces-1.groovy
Normal file
1
Task/Stack-traces/Groovy/stack-traces-1.groovy
Normal file
|
|
@ -0,0 +1 @@
|
|||
def rawTrace = { Thread.currentThread().stackTrace }
|
||||
14
Task/Stack-traces/Groovy/stack-traces-2.groovy
Normal file
14
Task/Stack-traces/Groovy/stack-traces-2.groovy
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
def trace = rawTrace().collect {
|
||||
def props = it.properties
|
||||
def keys = (it.properties.keySet() - (new Object().properties.keySet()))
|
||||
props.findAll{ k, v -> k in keys }
|
||||
}
|
||||
|
||||
def propNames = trace[0].keySet().sort()
|
||||
def propWidths = propNames.collect { name -> [name, trace.collect{ it[name].toString() }].flatten()*.size().max() }
|
||||
|
||||
propNames.eachWithIndex{ name, i -> printf("%-${propWidths[i]}s ", name) }; println ''
|
||||
propWidths.each{ width -> print('-' * width + ' ') }; println ''
|
||||
trace.each {
|
||||
propNames.eachWithIndex{ name, i -> printf("%-${propWidths[i]}s ", it[name].toString()) }; println ''
|
||||
}
|
||||
16
Task/Stack-traces/Groovy/stack-traces-3.groovy
Normal file
16
Task/Stack-traces/Groovy/stack-traces-3.groovy
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import Utils # for buildStackTrace
|
||||
|
||||
procedure main()
|
||||
g()
|
||||
write()
|
||||
f()
|
||||
end
|
||||
|
||||
procedure f()
|
||||
g()
|
||||
end
|
||||
|
||||
procedure g()
|
||||
# Using 1 as argument omits the trace of buildStackTrace itself
|
||||
every write("\t",!buildStackTrace(1))
|
||||
end
|
||||
22
Task/Stack-traces/Groovy/stack-traces-4.groovy
Normal file
22
Task/Stack-traces/Groovy/stack-traces-4.groovy
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#<p>
|
||||
# Compute the current stack trace. Starting at level <i>n</i> above
|
||||
# the current procedure. Here, <i>n</i> defaults to 0, which will
|
||||
# include this procedure in the stack trace.
|
||||
# <i>ce</i> defaults to ¤t.
|
||||
# <i>This only works with newer versions of Unicon!</i>
|
||||
# <[generates the stacktrace from current call back to first
|
||||
# in the co-expression]>
|
||||
#</p>
|
||||
procedure buildStackTrace(n:0, # starting distance from this call
|
||||
ce # co-expr to trace stack in [¤t]
|
||||
)
|
||||
local L
|
||||
/ce := ¤t
|
||||
L := []; n -:= 1
|
||||
while pName := image(proc(ce, n+:=1)) do {
|
||||
fName := keyword("&file",ce,n) | "no file name"
|
||||
fLine := keyword("&line",ce,n) | "no line number"
|
||||
put(L, pName||" ["||fName||":"||fLine||"]" )
|
||||
}
|
||||
return L
|
||||
end
|
||||
1
Task/Stack-traces/J/stack-traces-1.j
Normal file
1
Task/Stack-traces/J/stack-traces-1.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
13!:0]1
|
||||
1
Task/Stack-traces/J/stack-traces-2.j
Normal file
1
Task/Stack-traces/J/stack-traces-2.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
13!:13''
|
||||
14
Task/Stack-traces/J/stack-traces-3.j
Normal file
14
Task/Stack-traces/J/stack-traces-3.j
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
f=:g
|
||||
g=:13!:13 bind ''
|
||||
f 7 NB. empty stack trace because debugging has not been enabled
|
||||
13!:0]1
|
||||
f 7
|
||||
┌─┬─┬─┬─┬─────────────┬┬───┬──┬─┐
|
||||
│g│0│0│3│13!:13@(''"_)││┌─┐│ │ │
|
||||
│ │ │ │ │ │││7││ │ │
|
||||
│ │ │ │ │ ││└─┘│ │ │
|
||||
├─┼─┼─┼─┼─────────────┼┼───┼──┼─┤
|
||||
│f│0│0│3│g ││┌─┐│ │ │
|
||||
│ │ │ │ │ │││7││ │ │
|
||||
│ │ │ │ │ ││└─┘│ │ │
|
||||
└─┴─┴─┴─┴─────────────┴┴───┴──┴─┘
|
||||
11
Task/Stack-traces/Java/stack-traces-1.java
Normal file
11
Task/Stack-traces/Java/stack-traces-1.java
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
public class StackTracer {
|
||||
public static void printStackTrace() {
|
||||
StackTraceElement[] elems = Thread.currentThread().getStackTrace();
|
||||
|
||||
System.out.println("Stack trace:");
|
||||
for (int i = elems.length-1, j = 2 ; i >= 3 ; i--, j+=2) {
|
||||
System.out.printf("%" + j + "s%s.%s%n", "",
|
||||
elems[i].getClassName(), elems[i].getMethodName());
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Task/Stack-traces/Java/stack-traces-2.java
Normal file
14
Task/Stack-traces/Java/stack-traces-2.java
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
public class StackTraceDemo {
|
||||
static void inner() {
|
||||
StackTracer.printStackTrace();
|
||||
}
|
||||
static void middle() {
|
||||
inner();
|
||||
}
|
||||
static void outer() {
|
||||
middle();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
outer();
|
||||
}
|
||||
}
|
||||
5
Task/Stack-traces/JavaScript/stack-traces-1.js
Normal file
5
Task/Stack-traces/JavaScript/stack-traces-1.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
try {
|
||||
throw new Error;
|
||||
} catch(e) {
|
||||
alert(e.stack);
|
||||
}
|
||||
9
Task/Stack-traces/JavaScript/stack-traces-2.js
Normal file
9
Task/Stack-traces/JavaScript/stack-traces-2.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
function foo () {
|
||||
var stack = "Stack trace:";
|
||||
for (var f = arguments.callee // current function
|
||||
; f; f = f.caller) {
|
||||
stack += "\n" + f.name;
|
||||
}
|
||||
alert(stack);
|
||||
}
|
||||
foo();
|
||||
4
Task/Stack-traces/Julia/stack-traces.julia
Normal file
4
Task/Stack-traces/Julia/stack-traces.julia
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
f() = g()
|
||||
g() = println.(stacktrace())
|
||||
|
||||
f()
|
||||
10
Task/Stack-traces/Kotlin/stack-traces.kotlin
Normal file
10
Task/Stack-traces/Kotlin/stack-traces.kotlin
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// version 1.1.2 (stacktrace.kt which compiles to StacktraceKt.class)
|
||||
|
||||
fun myFunc() {
|
||||
println(Throwable().stackTrace.joinToString("\n"))
|
||||
}
|
||||
|
||||
fun main(args:Array<String>) {
|
||||
myFunc()
|
||||
println("\nContinuing ... ")
|
||||
}
|
||||
19
Task/Stack-traces/Lang/stack-traces.lang
Normal file
19
Task/Stack-traces/Lang/stack-traces.lang
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# fn.getStackTrace() returns a text-based stack trace
|
||||
fp.printStackTrace = () -> fn.println(fn.getStackTrace())
|
||||
|
||||
# Example
|
||||
fp.f1 = () -> {
|
||||
fn.println(F1:)
|
||||
fp.printStackTrace()
|
||||
}
|
||||
fp.f2 = () -> {
|
||||
fn.println(F2:)
|
||||
fp.printStackTrace()
|
||||
fp.f1()
|
||||
}
|
||||
fp.f2()
|
||||
|
||||
fn.combA0(fp.f2)
|
||||
|
||||
# Partially called combinator functions' names are represented as "<comb...-func(...)>"
|
||||
fn.combA(fn.combC(fn.combAE(), x), fp.f2)
|
||||
24
Task/Stack-traces/Lasso/stack-traces-1.lasso
Normal file
24
Task/Stack-traces/Lasso/stack-traces-1.lasso
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// Define our own trace method
|
||||
define trace => {
|
||||
local(gb) = givenblock
|
||||
|
||||
// Set a depth counter
|
||||
var(::_tracedepth)->isnota(::integer) ? $_tracedepth = 0
|
||||
handle => {$_tracedepth--}
|
||||
|
||||
// Only output when supplied a capture
|
||||
#gb ? stdoutnl(
|
||||
// Indent
|
||||
('\t' * $_tracedepth++) +
|
||||
|
||||
// Type + Method
|
||||
#gb->self->type + '.' + #gb->calledname +
|
||||
|
||||
// Call site file
|
||||
': ' + #gb->home->callsite_file +
|
||||
|
||||
// Line number and column number
|
||||
' (line '+#gb->home->callsite_line + ', col ' + #gb->home->callsite_col +')'
|
||||
)
|
||||
return #gb()
|
||||
}
|
||||
8
Task/Stack-traces/Lasso/stack-traces-2.lasso
Normal file
8
Task/Stack-traces/Lasso/stack-traces-2.lasso
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
define stackexample => type {
|
||||
public oncreate => trace => { return self }
|
||||
public inner => trace => { }
|
||||
public middle => trace => { .inner }
|
||||
public outer => trace => { .middle }
|
||||
}
|
||||
|
||||
stackexample->outer
|
||||
14
Task/Stack-traces/Lua/stack-traces.lua
Normal file
14
Task/Stack-traces/Lua/stack-traces.lua
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
function Inner( k )
|
||||
print( debug.traceback() )
|
||||
print "Program continues..."
|
||||
end
|
||||
|
||||
function Middle( x, y )
|
||||
Inner( x+y )
|
||||
end
|
||||
|
||||
function Outer( a, b, c )
|
||||
Middle( a*b, c )
|
||||
end
|
||||
|
||||
Outer( 2, 3, 5 )
|
||||
1
Task/Stack-traces/Mathematica/stack-traces-1.math
Normal file
1
Task/Stack-traces/Mathematica/stack-traces-1.math
Normal file
|
|
@ -0,0 +1 @@
|
|||
f[g[1, Print[Stack[]]; 2]]
|
||||
2
Task/Stack-traces/Mathematica/stack-traces-2.math
Normal file
2
Task/Stack-traces/Mathematica/stack-traces-2.math
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
{f,g,CompoundExpression,Print}
|
||||
f[g[1, 2]]
|
||||
1
Task/Stack-traces/Mathematica/stack-traces-3.math
Normal file
1
Task/Stack-traces/Mathematica/stack-traces-3.math
Normal file
|
|
@ -0,0 +1 @@
|
|||
f[g[1, Print[Stack[_]]; 2]]
|
||||
2
Task/Stack-traces/Mathematica/stack-traces-4.math
Normal file
2
Task/Stack-traces/Mathematica/stack-traces-4.math
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
{f[g[1,Print[Stack[_]];2]],g[1,Print[Stack[_]];2],Print[Stack[_]];2,Print[Stack[_]]}
|
||||
f[g[1, 2]]
|
||||
18
Task/Stack-traces/Nanoquery/stack-traces.nanoquery
Normal file
18
Task/Stack-traces/Nanoquery/stack-traces.nanoquery
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
def print_stack()
|
||||
global __calls__
|
||||
|
||||
println "stack trace:"
|
||||
for i in range(len(__calls__) - 2, 0)
|
||||
println "\t" + __calls__[i]
|
||||
end
|
||||
end
|
||||
|
||||
print_stack()
|
||||
println
|
||||
|
||||
for i in range(1, 1)
|
||||
print_stack()
|
||||
end
|
||||
|
||||
println
|
||||
println "The program would continue."
|
||||
22
Task/Stack-traces/NetRexx/stack-traces.netrexx
Normal file
22
Task/Stack-traces/NetRexx/stack-traces.netrexx
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
class RStackTraces
|
||||
method inner() static
|
||||
StackTracer.printStackTrace()
|
||||
method middle() static
|
||||
inner()
|
||||
method outer() static
|
||||
middle()
|
||||
method main(args = String[]) public static
|
||||
outer()
|
||||
|
||||
class RStackTraces.StackTracer
|
||||
method printStackTrace() public static
|
||||
elems = Thread.currentThread().getStackTrace()
|
||||
say 'Stack trace:'
|
||||
j_ = 2
|
||||
loop i_ = elems.length - 1 to 2 by -1
|
||||
say ''.left(j_) || elems[i_].getClassName()'.'elems[i_].getMethodName()
|
||||
j_ = j_ + 2
|
||||
end i_
|
||||
12
Task/Stack-traces/Nim/stack-traces.nim
Normal file
12
Task/Stack-traces/Nim/stack-traces.nim
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
proc g() =
|
||||
# Writes the current stack trace to stderr.
|
||||
writeStackTrace()
|
||||
# Or fetch the stack trace entries for the current stack trace:
|
||||
echo "----"
|
||||
for e in getStackTraceEntries():
|
||||
echo e.filename, "@", e.line, " in ", e.procname
|
||||
|
||||
proc f() =
|
||||
g()
|
||||
|
||||
f()
|
||||
8
Task/Stack-traces/OCaml/stack-traces-1.ocaml
Normal file
8
Task/Stack-traces/OCaml/stack-traces-1.ocaml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
let div a b = a / b
|
||||
|
||||
let () =
|
||||
try let _ = div 3 0 in ()
|
||||
with e ->
|
||||
prerr_endline(Printexc.to_string e);
|
||||
Printexc.print_backtrace stderr;
|
||||
;;
|
||||
5
Task/Stack-traces/OCaml/stack-traces-2.ocaml
Normal file
5
Task/Stack-traces/OCaml/stack-traces-2.ocaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
let div a b = a / b
|
||||
|
||||
let () =
|
||||
let _ = div 3 0 in ()
|
||||
;;
|
||||
9
Task/Stack-traces/Objective-C/stack-traces-1.m
Normal file
9
Task/Stack-traces/Objective-C/stack-traces-1.m
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#include <execinfo.h>
|
||||
|
||||
void *frames[128];
|
||||
int len = backtrace(frames, 128);
|
||||
char **symbols = backtrace_symbols(frames, len);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
NSLog(@"%s", symbols[i]);
|
||||
}
|
||||
free(symbols);
|
||||
4
Task/Stack-traces/Objective-C/stack-traces-2.m
Normal file
4
Task/Stack-traces/Objective-C/stack-traces-2.m
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
NSArray *symbols = [NSThread callStackSymbols];
|
||||
for (NSString *symbol in symbols) {
|
||||
NSLog(@"%@", symbol);
|
||||
}
|
||||
6
Task/Stack-traces/Oforth/stack-traces.fth
Normal file
6
Task/Stack-traces/Oforth/stack-traces.fth
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
: f1 Exception throw("An exception") ;
|
||||
Integer method: f2 self f1 ;
|
||||
: f3 f2 ;
|
||||
: f4 f3 ;
|
||||
|
||||
10 f4
|
||||
80
Task/Stack-traces/OxygenBasic/stack-traces.basic
Normal file
80
Task/Stack-traces/OxygenBasic/stack-traces.basic
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
'32bit x86
|
||||
|
||||
static string Report
|
||||
|
||||
|
||||
macro ReportStack(n)
|
||||
'===================
|
||||
|
||||
'
|
||||
scope
|
||||
'
|
||||
static sys stack[0X100],stackptr,e
|
||||
'
|
||||
'CAPTURE IMAGE OF UP TO 256 ENTRIES
|
||||
'
|
||||
'
|
||||
mov eax,n
|
||||
cmp eax,0x100
|
||||
(
|
||||
jle exit
|
||||
mov eax,0x100 'UPPER LIMIT
|
||||
)
|
||||
mov e,eax
|
||||
mov stackptr,esp
|
||||
lea edx,stack
|
||||
mov ecx,e
|
||||
mov esi,esp
|
||||
(
|
||||
mov eax,[esi]
|
||||
mov [edx],eax
|
||||
add esi,4
|
||||
add edx,4
|
||||
dec ecx
|
||||
jg repeat
|
||||
)
|
||||
sys i
|
||||
string cr=chr(13)+chr(10), tab=chr(9)
|
||||
'
|
||||
for i=1 to e
|
||||
report+=hex(stackptr+(i-1)*4,8) tab hex(i-1,2) tab hex(stack[i],8) cr
|
||||
next
|
||||
'
|
||||
end scope
|
||||
'
|
||||
end macro
|
||||
|
||||
'====
|
||||
'TEST
|
||||
'====
|
||||
|
||||
function foo()
|
||||
'=============
|
||||
|
||||
push 0x44556677
|
||||
push 0x33445566
|
||||
push 0x22334455
|
||||
push 0x11223344
|
||||
ReportStack(8)
|
||||
|
||||
end function
|
||||
|
||||
Report+="Trace inside foo
|
||||
"
|
||||
foo()
|
||||
print report
|
||||
'putfile "s.txt",Report
|
||||
|
||||
/*
|
||||
RESULT:
|
||||
|
||||
Trace inside foo
|
||||
0017FE00 00 11223344
|
||||
0017FE04 01 22334455
|
||||
0017FE08 02 33445566
|
||||
0017FE0C 03 44556677
|
||||
0017FE10 04 005EAB1C
|
||||
0017FE14 05 0017FE40
|
||||
0017FE18 06 10002D5F
|
||||
0017FE1C 07 00000000
|
||||
*/
|
||||
10
Task/Stack-traces/Oz/stack-traces-1.oz
Normal file
10
Task/Stack-traces/Oz/stack-traces-1.oz
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
declare
|
||||
proc {Test}
|
||||
_ = 1 div 0
|
||||
end
|
||||
in
|
||||
try
|
||||
{Test}
|
||||
catch E then
|
||||
{Inspect E}
|
||||
end
|
||||
15
Task/Stack-traces/Oz/stack-traces-2.oz
Normal file
15
Task/Stack-traces/Oz/stack-traces-2.oz
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
%% make sure that simple function calls are not optimized away
|
||||
\switch +controlflowinfo
|
||||
|
||||
declare
|
||||
[Debug] = {Link ['x-oz://boot/Debug']}
|
||||
|
||||
proc {F} {G} end
|
||||
|
||||
proc {G} {H} end
|
||||
|
||||
proc {H}
|
||||
{Inspect {Debug.getTaskStack {Thread.this} 100 true}}
|
||||
end
|
||||
in
|
||||
{F}
|
||||
15
Task/Stack-traces/PHP/stack-traces.php
Normal file
15
Task/Stack-traces/PHP/stack-traces.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
class StackTraceDemo {
|
||||
static function inner() {
|
||||
debug_print_backtrace();
|
||||
}
|
||||
static function middle() {
|
||||
self::inner();
|
||||
}
|
||||
static function outer() {
|
||||
self::middle();
|
||||
}
|
||||
}
|
||||
|
||||
StackTraceDemo::outer();
|
||||
?>
|
||||
7
Task/Stack-traces/PL-I/stack-traces.pli
Normal file
7
Task/Stack-traces/PL-I/stack-traces.pli
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/* The SNAP option in the ON statement is sufficient to obtain */
|
||||
/* a traceback. The SYSTEM option specifies that standard */
|
||||
/* system action is to occur, which resume execution after the */
|
||||
/* SIGNAL statement. */
|
||||
on condition(traceback) snap system;
|
||||
...
|
||||
signal condition(traceback);
|
||||
6
Task/Stack-traces/Perl/stack-traces.pl
Normal file
6
Task/Stack-traces/Perl/stack-traces.pl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
use Carp 'cluck';
|
||||
|
||||
sub g {cluck 'Hello from &g';}
|
||||
sub f {g;}
|
||||
|
||||
f;
|
||||
58
Task/Stack-traces/Phix/stack-traces-1.phix
Normal file
58
Task/Stack-traces/Phix/stack-traces-1.phix
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
(notonline)-->
|
||||
<span style="color: #008080;">constant</span> <span style="color: #000000;">W</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">machine_word</span><span style="color: #0000FF;">(),</span>
|
||||
<span style="color: #0000FF;">{</span><span style="color: #000000;">RTN</span><span style="color: #0000FF;">,</span><span style="color: #000000;">PREVEBP</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">W</span><span style="color: #0000FF;">=</span><span style="color: #000000;">4</span><span style="color: #0000FF;">?{</span><span style="color: #000000;">8</span><span style="color: #0000FF;">,</span><span style="color: #000000;">20</span><span style="color: #0000FF;">}:{</span><span style="color: #000000;">16</span><span style="color: #0000FF;">,</span><span style="color: #000000;">40</span><span style="color: #0000FF;">})</span>
|
||||
|
||||
<span style="color: #008080;">procedure</span> <span style="color: #000000;">show_stack</span><span style="color: #0000FF;">()</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">symtab</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">symtabN</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">rtn</span>
|
||||
<span style="color: #004080;">atom</span> <span style="color: #000000;">prev_ebp</span>
|
||||
|
||||
#ilASM{
|
||||
[32]
|
||||
lea edi,[symtab]
|
||||
call :%opGetST -- [edi]=symtab (ie our local:=the real symtab)
|
||||
mov edi,[ebp+20] -- prev_ebp
|
||||
mov eax,[edi+8] -- calling routine no
|
||||
mov [rtn],eax
|
||||
mov eax,edi
|
||||
lea edi,[prev_ebp]
|
||||
call :%pStoreMint
|
||||
[64]
|
||||
lea rdi,[symtab]
|
||||
call :%opGetST -- [rdi]=symtab (ie our local:=the real symtab)
|
||||
mov rdi,[rbp+40] -- prev_ebp
|
||||
mov rax,[rdi+16] -- calling routine no
|
||||
mov [rtn],rax
|
||||
mov rax,rdi
|
||||
lea rdi,[prev_ebp]
|
||||
call :%pStoreMint
|
||||
[]
|
||||
}
|
||||
<span style="color: #008080;">while</span> <span style="color: #000000;">rtn</span><span style="color: #0000FF;">!=</span><span style="color: #000000;">21</span> <span style="color: #008080;">do</span> <span style="color: #000080;font-style:italic;">-- (T_maintls, main top level routine, always present)</span>
|
||||
<span style="color: #000000;">symtabN</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">symtab</span><span style="color: #0000FF;">[</span><span style="color: #000000;">rtn</span><span style="color: #0000FF;">]</span>
|
||||
<span style="color: #0000FF;">?</span><span style="color: #000000;">symtabN</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
|
||||
<span style="color: #000000;">prev_ebp</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">peekNS</span><span style="color: #0000FF;">(</span><span style="color: #000000;">prev_ebp</span><span style="color: #0000FF;">+</span><span style="color: #000000;">PREVEBP</span><span style="color: #0000FF;">,</span><span style="color: #000000;">W</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000000;">rtn</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">peekNS</span><span style="color: #0000FF;">(</span><span style="color: #000000;">prev_ebp</span><span style="color: #0000FF;">+</span><span style="color: #000000;">RTN</span><span style="color: #0000FF;">,</span><span style="color: #000000;">W</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
|
||||
|
||||
<span style="color: #008080;">procedure</span> <span style="color: #000000;">three</span><span style="color: #0000FF;">(</span><span style="color: #004080;">bool</span> <span style="color: #000000;">die</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">die</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #0000FF;">?</span><span style="color: #000000;">9</span><span style="color: #0000FF;">/</span><span style="color: #000000;">0</span>
|
||||
<span style="color: #008080;">else</span>
|
||||
<span style="color: #000000;">show_stack</span><span style="color: #0000FF;">()</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
|
||||
|
||||
<span style="color: #008080;">procedure</span> <span style="color: #000000;">two</span><span style="color: #0000FF;">(</span><span style="color: #004080;">bool</span> <span style="color: #000000;">die</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000000;">three</span><span style="color: #0000FF;">(</span><span style="color: #000000;">die</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
|
||||
|
||||
<span style="color: #008080;">procedure</span> <span style="color: #000000;">one</span><span style="color: #0000FF;">(</span><span style="color: #004080;">bool</span> <span style="color: #000000;">die</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000000;">two</span><span style="color: #0000FF;">(</span><span style="color: #000000;">die</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
|
||||
|
||||
<span style="color: #000000;">one</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">routine_id</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"dummy"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- see note below</span>
|
||||
<span style="color: #000000;">one</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
|
||||
<!--
|
||||
3
Task/Stack-traces/Phix/stack-traces-2.phix
Normal file
3
Task/Stack-traces/Phix/stack-traces-2.phix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
-->
|
||||
<span style="color: #008080;">trace</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
|
||||
<!--
|
||||
36
Task/Stack-traces/PicoLisp/stack-traces-1.l
Normal file
36
Task/Stack-traces/PicoLisp/stack-traces-1.l
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
(off "Stack")
|
||||
|
||||
(de $$ "Prg"
|
||||
(let "Stack" (cons (cons (car "Prg") (env)) "Stack") # Build stack frame
|
||||
(set "Stack"
|
||||
(delq (asoq '"Stack" (car "Stack")) # Remove self-created entries
|
||||
(delq (asoq '"Prg" (car "Stack"))
|
||||
(car "Stack") ) ) )
|
||||
(run (cdr "Prg")) ) ) # Run body
|
||||
|
||||
(de stackAll (Excl)
|
||||
(let *Dbg NIL
|
||||
(for "X" (all)
|
||||
(or
|
||||
(memq "X" Excl)
|
||||
(memq "X" '($$ @ @@ @@@))
|
||||
(= `(char "*") (char "X"))
|
||||
(cond
|
||||
((= `(char "+") (char "X"))
|
||||
(for "Y" (pair (val "X"))
|
||||
(and
|
||||
(pair "Y")
|
||||
(fun? (cdr "Y"))
|
||||
(unless (== '$$ (caaddr "Y"))
|
||||
(con (cdr "Y")
|
||||
(list
|
||||
(cons '$$ (cons (car "Y" "X") (cddr "Y"))) ) ) ) ) ) )
|
||||
((pair (getd "X"))
|
||||
(let "Y" @
|
||||
(unless (== '$$ (caadr "Y"))
|
||||
(con "Y"
|
||||
(list (cons '$$ "X" (cdr "Y"))) ) ) ) ) ) ) ) ) )
|
||||
|
||||
(de dumpStack ()
|
||||
(more (reverse (cdr "Stack")))
|
||||
T )
|
||||
9
Task/Stack-traces/PicoLisp/stack-traces-2.l
Normal file
9
Task/Stack-traces/PicoLisp/stack-traces-2.l
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(de foo (A B)
|
||||
(let C 3
|
||||
(bar (inc 'A) (inc 'B) (inc 'C)) ) )
|
||||
|
||||
(de bar (A D E)
|
||||
(let (A 7 B 8 C 9)
|
||||
(! println A B C) ) ) # Set a breakpoint before (println A B C)
|
||||
|
||||
(stackAll)
|
||||
17
Task/Stack-traces/PureBasic/stack-traces.basic
Normal file
17
Task/Stack-traces/PureBasic/stack-traces.basic
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
Procedure Three()
|
||||
a=7
|
||||
ShowCallstack()
|
||||
CallDebugger
|
||||
EndProcedure
|
||||
|
||||
Procedure Two()
|
||||
a=4
|
||||
Three()
|
||||
EndProcedure
|
||||
|
||||
Procedure One()
|
||||
a=2
|
||||
Two()
|
||||
EndProcedure
|
||||
|
||||
One()
|
||||
6
Task/Stack-traces/Python/stack-traces.py
Normal file
6
Task/Stack-traces/Python/stack-traces.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import traceback
|
||||
|
||||
def f(): return g()
|
||||
def g(): traceback.print_stack()
|
||||
|
||||
f()
|
||||
10
Task/Stack-traces/R/stack-traces-1.r
Normal file
10
Task/Stack-traces/R/stack-traces-1.r
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
foo <- function()
|
||||
{
|
||||
bar <- function()
|
||||
{
|
||||
sys.calls()
|
||||
}
|
||||
bar()
|
||||
}
|
||||
|
||||
foo()
|
||||
2
Task/Stack-traces/R/stack-traces-2.r
Normal file
2
Task/Stack-traces/R/stack-traces-2.r
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
trace("foo", recover)
|
||||
foo()
|
||||
30
Task/Stack-traces/REXX/stack-traces-1.rexx
Normal file
30
Task/Stack-traces/REXX/stack-traces-1.rexx
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* call stack */
|
||||
say 'Call A'
|
||||
call A '123'
|
||||
say result
|
||||
exit 0
|
||||
|
||||
A:
|
||||
say 'Call B'
|
||||
call B '456'
|
||||
say result
|
||||
return ARG(1)
|
||||
|
||||
B:
|
||||
say 'Call C'
|
||||
call C '789'
|
||||
say result
|
||||
return ARG(1)
|
||||
|
||||
C:
|
||||
call callstack
|
||||
return ARG(1)
|
||||
|
||||
callstack: procedure
|
||||
getcallstack(cs.)
|
||||
say 'Dump call stack with' cs.0 'items'
|
||||
do i = 1 to cs.0
|
||||
parse var cs.i line func
|
||||
say format(line, 3) ':' left(func, 9) ': source "' || sourceline(line) || '"'
|
||||
end
|
||||
return cs.0
|
||||
4
Task/Stack-traces/REXX/stack-traces-2.rexx
Normal file
4
Task/Stack-traces/REXX/stack-traces-2.rexx
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
C:
|
||||
signal noname
|
||||
call callstack
|
||||
return ARG(1)
|
||||
17
Task/Stack-traces/Racket/stack-traces.rkt
Normal file
17
Task/Stack-traces/Racket/stack-traces.rkt
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#lang racket
|
||||
|
||||
;; To see these calls we do two things: mutate the binding to prevent
|
||||
;; Racket from inlining the value; use a (void) call at the end so the
|
||||
;; calls are not tail calls (which will otherwise not show on the
|
||||
;; stack).
|
||||
(define foo #f)
|
||||
(set! foo (λ() (bar) (void)))
|
||||
(define bar #f)
|
||||
(set! bar (λ() (show-stacktrace) (void)))
|
||||
|
||||
(define (show-stacktrace)
|
||||
(for ([s (continuation-mark-set->context (current-continuation-marks))]
|
||||
[i (in-naturals)])
|
||||
;; show just the names, not the full source information
|
||||
(when (car s) (printf "~s: ~s\n" i (car s)))))
|
||||
(foo)
|
||||
3
Task/Stack-traces/Raku/stack-traces.raku
Normal file
3
Task/Stack-traces/Raku/stack-traces.raku
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
sub g { say Backtrace.new.concise }
|
||||
sub f { g }
|
||||
sub MAIN { f }
|
||||
1
Task/Stack-traces/Raven/stack-traces.raven
Normal file
1
Task/Stack-traces/Raven/stack-traces.raven
Normal file
|
|
@ -0,0 +1 @@
|
|||
[1 2 3 4] 42 { 'a' 1 'b' 2 'c' 3 } 34.1234 ( -1 -2 -3 ) "The quick brown fox" FILE dump
|
||||
14
Task/Stack-traces/Ruby/stack-traces-1.rb
Normal file
14
Task/Stack-traces/Ruby/stack-traces-1.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
def outer(a,b,c)
|
||||
middle a+b, b+c
|
||||
end
|
||||
|
||||
def middle(d,e)
|
||||
inner d+e
|
||||
end
|
||||
|
||||
def inner(f)
|
||||
puts caller(0)
|
||||
puts "continuing... my arg is #{f}"
|
||||
end
|
||||
|
||||
outer 2,3,5
|
||||
19
Task/Stack-traces/Ruby/stack-traces-2.rb
Normal file
19
Task/Stack-traces/Ruby/stack-traces-2.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
def outer(a,b,c)
|
||||
middle a+b, b+c
|
||||
end
|
||||
|
||||
def middle(d,e)
|
||||
inner d+e
|
||||
end
|
||||
|
||||
def inner(f)
|
||||
raise
|
||||
puts "this will not be printed"
|
||||
end
|
||||
|
||||
begin
|
||||
outer 2,3,5
|
||||
rescue Exception => e
|
||||
puts e.backtrace
|
||||
end
|
||||
puts "continuing after the rescue..."
|
||||
1
Task/Stack-traces/Ruby/stack-traces-3.rb
Normal file
1
Task/Stack-traces/Ruby/stack-traces-3.rb
Normal file
|
|
@ -0,0 +1 @@
|
|||
p Thread.current.backtrace
|
||||
3
Task/Stack-traces/Scala/stack-traces.scala
Normal file
3
Task/Stack-traces/Scala/stack-traces.scala
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def callStack = try { error("exception") } catch { case ex => ex.getStackTrace drop 2 }
|
||||
|
||||
def printStackTrace = callStack drop 1 /* don't print ourselves! */ foreach println
|
||||
8
Task/Stack-traces/Slate/stack-traces-1.slate
Normal file
8
Task/Stack-traces/Slate/stack-traces-1.slate
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
slate[1]> d@(Debugger traits) printCurrentStack &limit: limit &stream: out &showLocation: showLocation
|
||||
[
|
||||
d clone `>> [baseFramePointer: (d interpreter framePointerOf: #printCurrentStack).
|
||||
buildFrames.
|
||||
printBacktrace &limit: limit &stream: out &showLocation: showLocation ]
|
||||
].
|
||||
Defining function 'printCurrentStack' on: 'Debugger traits'
|
||||
[printCurrentStack &limit: &stream: &showLocation:]
|
||||
14
Task/Stack-traces/Slate/stack-traces-2.slate
Normal file
14
Task/Stack-traces/Slate/stack-traces-2.slate
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
slate[2]> Debugger printCurrentStack.
|
||||
Backtrace (method @ source):
|
||||
frame: 0 [printCurrentStack &limit: &stream: &showLocation:] @ stdin:0
|
||||
frame: 1 [evaluateIn: &optionals:] @ src/mobius/syntax.slate:180
|
||||
frame: 2 [(arity: 0)] @ src/lib/repl.slate:155
|
||||
frame: 3 [on:do:] @ src/core/condition.slate:43
|
||||
frame: 4 [(arity: 0)] @ src/lib/repl.slate:147
|
||||
frame: 5 [handlingCases:] @ src/core/condition.slate:64
|
||||
frame: 6 [interpretHook:] @ src/lib/repl.slate:42
|
||||
frame: 7 [(arity: 0)] @ src/lib/repl.slate:139
|
||||
frame: 8 [enter] @ src/lib/repl.slate:135
|
||||
frame: 9 [start &resource:] @ src/lib/repl.slate:185
|
||||
frame: 10 [start] @ src/mobius/prelude.slate:38
|
||||
Nil
|
||||
15
Task/Stack-traces/Smalltalk/stack-traces.st
Normal file
15
Task/Stack-traces/Smalltalk/stack-traces.st
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
Object subclass: Container [
|
||||
Container class >> outer: a and: b and: c [
|
||||
self middle: (a+b) and: (b+c)
|
||||
]
|
||||
Container class >> middle: x and: y [
|
||||
self inner: (x*y)
|
||||
]
|
||||
Container class >> inner: k [
|
||||
Smalltalk backtrace
|
||||
]
|
||||
].
|
||||
|
||||
Container outer: 2 and: 3 and: 5.
|
||||
|
||||
'Anyway, we continue with it' displayNl.
|
||||
6
Task/Stack-traces/Tcl/stack-traces-1.tcl
Normal file
6
Task/Stack-traces/Tcl/stack-traces-1.tcl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
proc printStackTrace {} {
|
||||
puts "Stack trace:"
|
||||
for {set i 1} {$i < [info level]} {incr i} {
|
||||
puts [string repeat " " $i][info level $i]
|
||||
}
|
||||
}
|
||||
10
Task/Stack-traces/Tcl/stack-traces-2.tcl
Normal file
10
Task/Stack-traces/Tcl/stack-traces-2.tcl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
proc outer {a b c} {
|
||||
middle [expr {$a+$b}] [expr {$b+$c}]
|
||||
}
|
||||
proc middle {x y} {
|
||||
inner [expr {$x*$y}]
|
||||
}
|
||||
proc inner k {
|
||||
printStackTrace
|
||||
}
|
||||
outer 2 3 5
|
||||
9
Task/Stack-traces/Wren/stack-traces.wren
Normal file
9
Task/Stack-traces/Wren/stack-traces.wren
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
var func2 = Fn.new {
|
||||
Fiber.abort("Forced error.")
|
||||
}
|
||||
|
||||
var func1 = Fn.new {
|
||||
func2.call()
|
||||
}
|
||||
|
||||
func1.call()
|
||||
2
Task/Stack-traces/Zkl/stack-traces.zkl
Normal file
2
Task/Stack-traces/Zkl/stack-traces.zkl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fcn f{println("F");vm.stackTrace().println()} fcn g{println("G")}
|
||||
f();g();
|
||||
Loading…
Add table
Add a link
Reference in a new issue