callstack 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/README.rdoc +66 -0
- data/callstack.gemspec +22 -0
- data/ext/CallStack.c +49 -0
- data/ext/extconf.rb +5 -0
- metadata +62 -0
data/CHANGELOG
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
= Callstack
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
Callstack is a simple gem that bundles a C extension to provide better stack traces on Ruby 1.8.
|
6
|
+
Based on: http://eigenclass.org/hiki.rb?ruby+backtrace+data
|
7
|
+
|
8
|
+
== Installation
|
9
|
+
|
10
|
+
sudo gem install dtsato-callstack --source http://gems.github.com
|
11
|
+
|
12
|
+
== Dependencies
|
13
|
+
|
14
|
+
* Ruby 1.8
|
15
|
+
* C compiler
|
16
|
+
|
17
|
+
== Usage
|
18
|
+
|
19
|
+
To get the call stack trace, simply require use the +callstack+ method, as such:
|
20
|
+
|
21
|
+
require 'rubygems'
|
22
|
+
require 'callstack'
|
23
|
+
|
24
|
+
def foo; bar end
|
25
|
+
def bar; p callstack end
|
26
|
+
|
27
|
+
class Moo
|
28
|
+
def initialize
|
29
|
+
foo
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Moo.new
|
34
|
+
|
35
|
+
This will output the following stack:
|
36
|
+
|
37
|
+
[[Object, :bar, "example.rb", 5], [Object, :foo, "example.rb", 4], [Moo, :initialize, "example.rb", 9], [nil, nil, "example.rb", 13]]
|
38
|
+
|
39
|
+
The +callstack+ method also accepts an optional integer argument that specifies the desired depth of the stack call trace. Using +callstack(2)+ on the previous example would output:
|
40
|
+
|
41
|
+
[[Object, :bar, "example.rb", 5], [Object, :foo, "example.rb", 4]]
|
42
|
+
|
43
|
+
== Git
|
44
|
+
|
45
|
+
Public clone URL: git://github.com/dtsato/callstack.git
|
46
|
+
|
47
|
+
== License
|
48
|
+
|
49
|
+
Copyright (c) 2008 dtsato.com, Danilo Sato
|
50
|
+
|
51
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
52
|
+
of this software and associated documentation files (the "Software"), to
|
53
|
+
deal in the Software without restriction, including without limitation the
|
54
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
55
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
56
|
+
furnished to do so, subject to the following conditions:
|
57
|
+
|
58
|
+
The above copyright notice and this permission notice shall be included in
|
59
|
+
all copies or substantial portions of the Software.
|
60
|
+
|
61
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
62
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
63
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
64
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
65
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
66
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/callstack.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
GEMSPEC =Gem::Specification.new do |s|
|
2
|
+
s.name = 'callstack'
|
3
|
+
s.version = '0.0.2'
|
4
|
+
s.date = "2008-11-14"
|
5
|
+
s.rubyforge_project = "callstack"
|
6
|
+
s.platform = Gem::Platform::RUBY
|
7
|
+
s.summary, s.description = 'A simple extension to add better stack traces to Ruby 1.8 (based on http://eigenclass.org/hiki.rb?ruby+backtrace+data)'
|
8
|
+
s.authors = 'Danilo Sato'
|
9
|
+
s.email = 'danilo@dtsato.com'
|
10
|
+
s.homepage = 'http://github.com/dtsato/callstack'
|
11
|
+
s.has_rdoc = true
|
12
|
+
s.rdoc_options += ['--quiet', '--title', 'Callstack', '--main', 'README.rdoc', '--inline-source']
|
13
|
+
s.extra_rdoc_files = ['README.rdoc']
|
14
|
+
s.extensions << 'ext/extconf.rb'
|
15
|
+
s.files = [
|
16
|
+
"README.rdoc",
|
17
|
+
"CHANGELOG",
|
18
|
+
"callstack.gemspec",
|
19
|
+
"ext/extconf.rb",
|
20
|
+
"ext/CallStack.c"
|
21
|
+
]
|
22
|
+
end
|
data/ext/CallStack.c
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include "env.h"
|
3
|
+
#include "node.h"
|
4
|
+
|
5
|
+
static VALUE
|
6
|
+
custom_callstack(int argc, VALUE *args, VALUE self)
|
7
|
+
{
|
8
|
+
struct FRAME *frame = ruby_frame;
|
9
|
+
VALUE ary;
|
10
|
+
NODE *n;
|
11
|
+
VALUE level;
|
12
|
+
VALUE klass;
|
13
|
+
int depth = argc > 0 ? NUM2INT(args[0]) : -1;
|
14
|
+
|
15
|
+
ary = rb_ary_new();
|
16
|
+
if (frame->last_func == ID_ALLOCATOR) {
|
17
|
+
frame = frame->prev;
|
18
|
+
}
|
19
|
+
for (; frame && (n = frame->node); frame = frame->prev) {
|
20
|
+
if (frame->prev && frame->prev->last_func) {
|
21
|
+
if (frame->prev->node == n) continue;
|
22
|
+
level = rb_ary_new();
|
23
|
+
klass = frame->prev->last_class ? frame->prev->last_class : Qnil;
|
24
|
+
if(TYPE(klass) == T_ICLASS) {
|
25
|
+
klass = CLASS_OF(klass);
|
26
|
+
}
|
27
|
+
rb_ary_push(level, klass);
|
28
|
+
rb_ary_push(level, ID2SYM(frame->prev->last_func));
|
29
|
+
rb_ary_push(level, rb_str_new2(n->nd_file));
|
30
|
+
rb_ary_push(level, INT2NUM(nd_line(n)));
|
31
|
+
}
|
32
|
+
else {
|
33
|
+
level = rb_ary_new();
|
34
|
+
rb_ary_push(level, Qnil);
|
35
|
+
rb_ary_push(level, Qnil);
|
36
|
+
rb_ary_push(level, rb_str_new2(n->nd_file));
|
37
|
+
rb_ary_push(level, INT2NUM(nd_line(n)));
|
38
|
+
}
|
39
|
+
rb_ary_push(ary, level);
|
40
|
+
if(--depth == 0)
|
41
|
+
break;
|
42
|
+
}
|
43
|
+
|
44
|
+
return ary;
|
45
|
+
}
|
46
|
+
|
47
|
+
void Init_callstack() {
|
48
|
+
rb_define_method(rb_cObject, "callstack", custom_callstack, -1);
|
49
|
+
}
|
data/ext/extconf.rb
ADDED
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: callstack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Danilo Sato
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-14 00:00:00 +00:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: danilo@dtsato.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions:
|
21
|
+
- ext/extconf.rb
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- CHANGELOG
|
27
|
+
- callstack.gemspec
|
28
|
+
- ext/extconf.rb
|
29
|
+
- ext/CallStack.c
|
30
|
+
has_rdoc: true
|
31
|
+
homepage: http://github.com/dtsato/callstack
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options:
|
34
|
+
- --quiet
|
35
|
+
- --title
|
36
|
+
- Callstack
|
37
|
+
- --main
|
38
|
+
- README.rdoc
|
39
|
+
- --inline-source
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project: callstack
|
57
|
+
rubygems_version: 1.3.1
|
58
|
+
signing_key:
|
59
|
+
specification_version: 2
|
60
|
+
summary: A simple extension to add better stack traces to Ruby 1.8 (based on http://eigenclass.org/hiki.rb?ruby+backtrace+data)
|
61
|
+
test_files: []
|
62
|
+
|