ruby-cymbol 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/AUTHORS ADDED
@@ -0,0 +1,4 @@
1
+ ruby-cymbol de tario <rseminara@hotmail.com>
2
+
3
+
4
+
@@ -0,0 +1 @@
1
+ 0.2.0 Optimized Cymbol::resolv by using a singleton of Cymbol::Resolv
data/README ADDED
File without changes
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require 'rake/gempackagetask'
6
+
7
+ spec = Gem::Specification.new do |s|
8
+ s.name = 'ruby-cymbol'
9
+ s.version = '0.2.0'
10
+ s.author = 'Dario Seminara'
11
+ s.email = 'robertodarioseminara@gmail.com'
12
+ s.platform = Gem::Platform::RUBY
13
+ s.summary = 'Resolv libruby.so exports and debug symbols to relative offsets'
14
+ s.homepage = "http://github.com/tario/ruby-cymbol"
15
+ s.has_rdoc = true
16
+ s.extra_rdoc_files = [ 'README' ]
17
+ # s.rdoc_options << '--main' << 'README'
18
+ s.files = Dir.glob("{examples,lib,test}/**/*") +
19
+ [ 'AUTHORS', 'CHANGELOG', 'README', 'Rakefile', 'TODO' ]
20
+ end
21
+
22
+ desc 'Run tests'
23
+ task :default => [ :test ]
24
+
25
+ Rake::TestTask.new('test') do |t|
26
+ t.libs << 'test'
27
+ t.pattern = '{test}/test_*.rb'
28
+ t.verbose = true
29
+ end
30
+
31
+ desc 'Generate RDoc'
32
+ Rake::RDocTask.new :rdoc do |rd|
33
+ rd.rdoc_dir = 'doc'
34
+ rd.rdoc_files.add 'lib', 'README'
35
+ rd.main = 'README'
36
+ end
37
+
38
+ desc 'Build Gem'
39
+ Rake::GemPackageTask.new spec do |pkg|
40
+ pkg.need_tar = true
41
+ end
42
+
43
+ desc 'Clean up'
44
+ task :clean => [ :clobber_rdoc, :clobber_package ]
45
+
46
+ desc 'Clean up'
47
+ task :clobber => [ :clean ]
data/TODO ADDED
File without changes
@@ -0,0 +1,108 @@
1
+ =begin
2
+
3
+ This file is part of the http://github.com/tario/ruby-cymbol project, ruby-cymbol
4
+
5
+ Copyright (c) 2009-2010 Roberto Dario Seminara <robertodarioseminara@gmail.com>
6
+
7
+ http://github.com/tario/ruby-cymbol is free software: you can redistribute it and/or modify
8
+ it under the terms of the gnu general public license as published by
9
+ the free software foundation, either version 3 of the license, or
10
+ (at your option) any later version.
11
+
12
+ http://github.com/tario/ruby-cymbol is distributed in the hope that it will be useful,
13
+ but without any warranty; without even the implied warranty of
14
+ merchantability or fitness for a particular purpose. see the
15
+ gnu general public license for more details.
16
+
17
+ you should have received a copy of the gnu general public license
18
+ along with http://github.com/tario/ruby-cymbol. if not, see <http://www.gnu.org/licenses/>.
19
+
20
+ =end
21
+
22
+ require "ruby-cymbol/shared"
23
+ require "ruby-cymbol/objdump"
24
+ require "singleton"
25
+
26
+ module Cymbol
27
+
28
+ class SymbolNotFound < Exception
29
+
30
+ attr_accessor :symbol_name
31
+
32
+ def initialize( symbol_name_ )
33
+ self.symbol_name = symbol_name_
34
+ end
35
+ end
36
+
37
+ class ObjdumpNotFoundInSystem < Exception
38
+
39
+ end
40
+
41
+ class RubyDebugInfoNotFoundInSystem < Exception
42
+
43
+ end
44
+
45
+
46
+ def self.check
47
+ # existence of objdump
48
+ unless system("objdump -H > /dev/null")
49
+ raise ObjdumpNotFoundInSystem.new
50
+ end
51
+
52
+ shared_name = Cymbol.ruby_shared_name
53
+ debug_info_name = "/usr/lib/debug/" + shared_name
54
+ if File.exist?(debug_info_name)
55
+ shared_name = debug_info_name
56
+ end
57
+
58
+ unless shared_name =~ /debug/
59
+ raise RubyDebugInfoNotFoundInSystem.new
60
+ end
61
+
62
+ begin
63
+ Cymbol.resolv("ruby_init")
64
+ rescue SymbolNotFound
65
+ raise RubyDebugInfoNotFoundInSystem.new
66
+ end
67
+
68
+
69
+ end
70
+
71
+ class Resolv
72
+
73
+ include Singleton
74
+
75
+ def initialize
76
+ shared_name = Cymbol.ruby_shared_name
77
+
78
+ # Use debug info of libruby if exists
79
+ debug_info_name = "/usr/lib/debug/" + shared_name
80
+
81
+ if File.exist?(debug_info_name)
82
+ shared_name = debug_info_name
83
+ end
84
+
85
+ @objdump = Cymbol::Objdump.new( shared_name )
86
+ end
87
+
88
+ def resolv( symbol_name )
89
+ match_symbols = @objdump.symbols.select{|s| s.name == symbol_name }
90
+
91
+ first_symbol = match_symbols.first
92
+
93
+ unless first_symbol
94
+ raise SymbolNotFound.new(symbol_name)
95
+ end
96
+
97
+ match_symbols.first.offset
98
+ end
99
+ end
100
+
101
+ def self.resolv( symbol_name )
102
+ Cymbol::Resolv.instance.resolv( symbol_name )
103
+ end
104
+
105
+ # Check conditions at module load
106
+ Cymbol.check
107
+
108
+ end
@@ -0,0 +1,58 @@
1
+ =begin
2
+
3
+ This file is part of the http://github.com/tario/ruby-cymbol project, ruby-cymbol
4
+
5
+ Copyright (c) 2009-2010 Roberto Dario Seminara <robertodarioseminara@gmail.com>
6
+
7
+ http://github.com/tario/ruby-cymbol is free software: you can redistribute it and/or modify
8
+ it under the terms of the gnu general public license as published by
9
+ the free software foundation, either version 3 of the license, or
10
+ (at your option) any later version.
11
+
12
+ http://github.com/tario/ruby-cymbol is distributed in the hope that it will be useful,
13
+ but without any warranty; without even the implied warranty of
14
+ merchantability or fitness for a particular purpose. see the
15
+ gnu general public license for more details.
16
+
17
+ you should have received a copy of the gnu general public license
18
+ along with http://github.com/tario/ruby-cymbol. if not, see <http://www.gnu.org/licenses/>.
19
+
20
+ =end
21
+
22
+ module Cymbol
23
+ class Objdump
24
+
25
+ attr_accessor :symbols
26
+
27
+ class DebugSymbol
28
+ def initialize(name_, offset_)
29
+ @name = name_
30
+ @offset = offset_
31
+ end
32
+
33
+ def name
34
+ @name
35
+ end
36
+
37
+ def offset
38
+ @offset
39
+ end
40
+ end
41
+
42
+ def initialize(path)
43
+
44
+ self.symbols = Array.new
45
+ #build objdump command
46
+ # eclipse crash with the \x60 character :S
47
+ objdump_output = eval("\x60objdump -t #{path}\x60")
48
+
49
+ # parse objdump output
50
+ objdump_output.each_line do |line|
51
+ words = line.split(" ")
52
+ if words.size > 1 then
53
+ self.symbols << DebugSymbol.new( words[-1], words[0].to_i(16) )
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,48 @@
1
+ =begin
2
+
3
+ This file is part of the http://github.com/tario/ruby-cymbol project, ruby-cymbol
4
+
5
+ Copyright (c) 2009-2010 Roberto Dario Seminara <robertodarioseminara@gmail.com>
6
+
7
+ http://github.com/tario/ruby-cymbol is free software: you can redistribute it and/or modify
8
+ it under the terms of the gnu general public license as published by
9
+ the free software foundation, either version 3 of the license, or
10
+ (at your option) any later version.
11
+
12
+ http://github.com/tario/ruby-cymbol is distributed in the hope that it will be useful,
13
+ but without any warranty; without even the implied warranty of
14
+ merchantability or fitness for a particular purpose. see the
15
+ gnu general public license for more details.
16
+
17
+ you should have received a copy of the gnu general public license
18
+ along with http://github.com/tario/ruby-cymbol. if not, see <http://www.gnu.org/licenses/>.
19
+
20
+ =end
21
+
22
+ module Cymbol
23
+
24
+ module ModuleMethods
25
+
26
+ def proc_maps
27
+ File.open("/proc/#{$$}/maps").each_line do |line|
28
+ name = line.split(" ")[-1]
29
+ yield(name)
30
+ end
31
+ end
32
+
33
+ def ruby_shared_name
34
+ proc_maps do |shared_name|
35
+ if shared_name =~ /libruby/
36
+ return shared_name
37
+ end
38
+ end
39
+
40
+ nil
41
+ end
42
+ end
43
+
44
+ class << self
45
+ include ModuleMethods
46
+ end
47
+
48
+ end
@@ -0,0 +1,25 @@
1
+ require "test/unit"
2
+ require "ruby-cymbol"
3
+
4
+ class TestResolv < Test::Unit::TestCase
5
+ def test_resolv
6
+ # functions like rb_funcall, rb_ary_new, rb_define_module, rb_define_class must exists
7
+
8
+ ["rb_funcall", "rb_ary_new", "rb_define_module", "rb_define_class"].each do |str|
9
+ assert Cymbol.resolv(str).instance_of? Fixnum
10
+ end
11
+ end
12
+
13
+ def test_not_found
14
+ # functions like "01010101", "foo" ar NOT defined and must raise SymbolNotFound
15
+
16
+ ["010101010","foo"].each do |str|
17
+ assert_raise Cymbol::SymbolNotFound do
18
+ Cymbol.resolv(str)
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+
@@ -0,0 +1,17 @@
1
+ require "test/unit"
2
+ require "ruby-cymbol/shared"
3
+
4
+ class TestSharedRead < Test::Unit::TestCase
5
+ def test_shared
6
+ assert_not_nil Cymbol.ruby_shared_name
7
+
8
+ unless Cymbol.ruby_shared_name =~ /libruby/
9
+ flunk "The library returned by ruby_shared_name isnt libruby"
10
+ end
11
+
12
+ unless File.exist?(Cymbol.ruby_shared_name)
13
+ flunk "The library returned by ruby_shared_name doesn't exists in the system"
14
+ end
15
+
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-cymbol
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Dario Seminara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-06-20 00:00:00 -03:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: robertodarioseminara@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - lib/ruby-cymbol/shared.rb
26
+ - lib/ruby-cymbol/objdump.rb
27
+ - lib/ruby-cymbol.rb
28
+ - test/test_resolv.rb
29
+ - test/test_shared.rb
30
+ - AUTHORS
31
+ - CHANGELOG
32
+ - README
33
+ - Rakefile
34
+ - TODO
35
+ has_rdoc: true
36
+ homepage: http://github.com/tario/ruby-cymbol
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.5
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Resolv libruby.so exports and debug symbols to relative offsets
63
+ test_files: []
64
+