all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
6
Task/Stack-traces/0DESCRIPTION
Normal file
6
Task/Stack-traces/0DESCRIPTION
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
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.
|
||||
|
||||
This task calls for you to 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 clear=all>
|
||||
2
Task/Stack-traces/1META.yaml
Normal file
2
Task/Stack-traces/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: Programming environment operations
|
||||
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; use GNAT.Traceback;
|
||||
with GNAT.Traceback.Symbolic; use GNAT.Traceback.Symbolic;
|
||||
|
||||
procedure Test_Stack_Trace is
|
||||
procedure Call_Stack is
|
||||
Trace : Tracebacks_Array (1..1_000);
|
||||
Length : Natural;
|
||||
begin
|
||||
Call_Chain (Trace, Length);
|
||||
Put_Line (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
|
||||
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
|
||||
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}>)
|
||||
22
Task/Stack-traces/D/stack-traces.d
Normal file
22
Task/Stack-traces/D/stack-traces.d
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import std.stdio;
|
||||
|
||||
void inner() {
|
||||
try
|
||||
throw new Exception(null);
|
||||
catch (Exception e)
|
||||
writeln(e);
|
||||
|
||||
writeln("running");
|
||||
}
|
||||
|
||||
void middle() {
|
||||
inner();
|
||||
}
|
||||
|
||||
void outer() {
|
||||
middle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
outer();
|
||||
}
|
||||
21
Task/Stack-traces/DWScript/stack-traces.dwscript
Normal file
21
Task/Stack-traces/DWScript/stack-traces.dwscript
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;
|
||||
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]
|
||||
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/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// to print it to standard error
|
||||
debug.PrintStack()
|
||||
// alternately to get it in a variable:
|
||||
stackTrace := debug.Stack()
|
||||
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();
|
||||
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]]
|
||||
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_
|
||||
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);
|
||||
}
|
||||
80
Task/Stack-traces/OxygenBasic/stack-traces.oxy
Normal file
80
Task/Stack-traces/OxygenBasic/stack-traces.oxy
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);
|
||||
3
Task/Stack-traces/Perl-6/stack-traces.pl6
Normal file
3
Task/Stack-traces/Perl-6/stack-traces.pl6
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
sub g { say Backtrace.new.concise }
|
||||
sub f { g }
|
||||
sub MAIN { f }
|
||||
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;
|
||||
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.purebasic
Normal file
17
Task/Stack-traces/PureBasic/stack-traces.purebasic
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()
|
||||
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..."
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue