gdb 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/bin/gdb-ruby +4 -1
- data/lib/gdb/eval_context.rb +9 -1
- data/lib/gdb/gdb.rb +23 -4
- data/lib/gdb/scripts/gdbinit.py +22 -5
- data/lib/gdb/tube/tube.rb +11 -4
- data/lib/gdb/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de69fa7d5ddc398f6e0bdd176061f23bd650acba
|
4
|
+
data.tar.gz: 5d86b5bafafa5d321226633751375a3faf9513fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a534be09b10af62159decf1793bad3c977680b9885bd4de3af3c70211d6319d3fde4720e1079d26f83e57dc2518af2f8b3ac9c0f7fac7454715705069f25d43
|
7
|
+
data.tar.gz: 40b8085db8abb15a5d2564b6fc4d43c185ccf21d9fa799f93e48dbb669289a2dbdb34aaf254c963351c16ce93beacf0c7badc188e3a6afbeece41bb12cc59401
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/david942j/gdb-ruby.svg?branch=master)](https://travis-ci.org/david942j/gdb-ruby)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/gdb.svg)](https://badge.fury.io/rb/gdb)
|
2
3
|
[![Code Climate](https://codeclimate.com/github/david942j/gdb-ruby/badges/gpa.svg)](https://codeclimate.com/github/david942j/gdb-ruby)
|
3
4
|
[![Issue Count](https://codeclimate.com/github/david942j/gdb-ruby/badges/issue_count.svg)](https://codeclimate.com/github/david942j/gdb-ruby)
|
4
5
|
[![Test Coverage](https://codeclimate.com/github/david942j/gdb-ruby/badges/coverage.svg)](https://codeclimate.com/github/david942j/gdb-ruby/coverage)
|
data/bin/gdb-ruby
CHANGED
data/lib/gdb/eval_context.rb
CHANGED
@@ -3,8 +3,16 @@ require 'pry'
|
|
3
3
|
module GDB
|
4
4
|
# For evaluation ruby code in gdb.
|
5
5
|
class EvalContext
|
6
|
-
|
6
|
+
# @return [GDB::GDB] The gdb instance.
|
7
|
+
attr_reader :gdb
|
7
8
|
|
9
|
+
# Instantiate a {EvalContext} object.
|
10
|
+
#
|
11
|
+
# Each {GDB::GDB} should have exactly one {EvalContext}
|
12
|
+
# for evaluating Ruby.
|
13
|
+
#
|
14
|
+
# @param [GDB::GDB] gdb
|
15
|
+
# The gdb instance.
|
8
16
|
def initialize(gdb)
|
9
17
|
@gdb = gdb
|
10
18
|
end
|
data/lib/gdb/gdb.rb
CHANGED
@@ -13,11 +13,23 @@ module GDB
|
|
13
13
|
# Absolute path to python scripts.
|
14
14
|
SCRIPTS_PATH = File.join(__dir__, 'scripts').freeze
|
15
15
|
|
16
|
+
# To launch a gdb instance.
|
17
|
+
#
|
18
|
+
# @param [String] arguments
|
19
|
+
# The command line arguments to pass to gdb. See examples.
|
20
|
+
#
|
21
|
+
# @param [String] gdb
|
22
|
+
# Name of gdb.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# gdb = GDB::GDB.new('-q -nh bash')
|
26
|
+
# gdb = GDB::GDB.new('arm.elf', gdb: 'gdb-multiarch')
|
16
27
|
def initialize(arguments, gdb: 'gdb')
|
17
28
|
arguments = "--command=#{File.join(SCRIPTS_PATH, 'gdbinit.py')}" + ' ' + arguments # XXX
|
18
29
|
@tube = spawn(gdb + ' ' + arguments)
|
19
|
-
|
20
|
-
@
|
30
|
+
pre = @tube.readuntil('GDBRuby:')
|
31
|
+
@prompt = @tube.readuntil("\n").strip
|
32
|
+
@tube.unget(pre + @tube.readuntil(@prompt))
|
21
33
|
end
|
22
34
|
|
23
35
|
# Execute a command in gdb.
|
@@ -237,6 +249,9 @@ module GDB
|
|
237
249
|
|
238
250
|
private
|
239
251
|
|
252
|
+
# Raise {GDBError} if process is not running.
|
253
|
+
#
|
254
|
+
# @return [nil]
|
240
255
|
def check_alive!
|
241
256
|
raise GDBError, 'Process is not running' unless alive?
|
242
257
|
end
|
@@ -255,10 +270,12 @@ module GDB
|
|
255
270
|
#
|
256
271
|
# @return [String]
|
257
272
|
def output_hook(output)
|
258
|
-
|
273
|
+
idx = output.index(COMMAND_PREFIX)
|
274
|
+
return yield output.gsub(@prompt, '') if idx.nil?
|
275
|
+
yield output.slice!(0, idx)
|
259
276
|
cmd, args = output.slice(COMMAND_PREFIX.size..-1).split(' ', 2)
|
260
277
|
# only support ruby and pry now.
|
261
|
-
return output unless %w[ruby pry].include?(cmd)
|
278
|
+
return yield output unless %w[ruby pry].include?(cmd)
|
262
279
|
args = 'send(:invoke_pry)' if cmd == 'pry'
|
263
280
|
# gdb by default set tty
|
264
281
|
# hack it
|
@@ -268,6 +285,8 @@ module GDB
|
|
268
285
|
rescue StandardError, ScriptError => e
|
269
286
|
$stdout.puts("#{e.class}: #{e}")
|
270
287
|
end
|
288
|
+
@tube.puts('END')
|
289
|
+
@tube.readuntil(@prompt)
|
271
290
|
nil
|
272
291
|
end
|
273
292
|
|
data/lib/gdb/scripts/gdbinit.py
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
import gdb
|
2
|
-
|
2
|
+
|
3
|
+
import random
|
4
|
+
import string
|
5
|
+
import sys
|
3
6
|
|
4
7
|
class GDBRuby():
|
5
8
|
def __init__(self):
|
@@ -11,6 +14,7 @@ class GDBRuby():
|
|
11
14
|
gdb.execute("set print elements 0")
|
12
15
|
gdb.execute("set print pretty on")
|
13
16
|
self.hook_gdb_prompt()
|
17
|
+
print('GDBRuby:' + self.gdbruby_prompt)
|
14
18
|
|
15
19
|
'''
|
16
20
|
Hook gdb prompt
|
@@ -18,18 +22,22 @@ class GDBRuby():
|
|
18
22
|
def hook_gdb_prompt(self):
|
19
23
|
# don't hook twice
|
20
24
|
if gdb.prompt_hook == self._prompt_hook: return
|
25
|
+
self.gdbruby_prompt = self._gen_prompt()
|
21
26
|
self._original_hook = gdb.prompt_hook
|
22
27
|
gdb.prompt_hook = self._prompt_hook
|
23
28
|
|
24
|
-
|
25
|
-
gdb.prompt_hook = self._original_hook
|
29
|
+
# private
|
26
30
|
|
27
31
|
def _prompt_hook(self, current_prompt):
|
28
32
|
if self._original_hook == None:
|
29
|
-
org =
|
33
|
+
org = current_prompt.replace(self.gdbruby_prompt, '')
|
30
34
|
else:
|
31
35
|
org = self._original_hook(current_prompt)
|
32
|
-
return
|
36
|
+
return self.gdbruby_prompt + org
|
37
|
+
|
38
|
+
def _gen_prompt(self):
|
39
|
+
rnd = ''.join([random.choice(string.ascii_lowercase) for i in range(8)])
|
40
|
+
return '(gdb-ruby-%s)' % rnd
|
33
41
|
|
34
42
|
__commands__ = []
|
35
43
|
def register_command(cls):
|
@@ -46,6 +54,15 @@ class GDBRubyCommand(gdb.Command):
|
|
46
54
|
|
47
55
|
def invoke(self, args, _from_tty):
|
48
56
|
print("gdb-ruby> " + self.klass._cmdline_ + ' ' + args)
|
57
|
+
while True:
|
58
|
+
cmd = raw_input() if sys.version_info.major == 2 else input()
|
59
|
+
if cmd == 'END':
|
60
|
+
break
|
61
|
+
try:
|
62
|
+
res = gdb.execute(cmd, from_tty=True, to_string=True)
|
63
|
+
except gdb.error as e:
|
64
|
+
res = str(e)
|
65
|
+
sys.stdout.write(res + gdbruby.gdbruby_prompt)
|
49
66
|
|
50
67
|
@register_command
|
51
68
|
class RubyCommand():
|
data/lib/gdb/tube/tube.rb
CHANGED
@@ -8,8 +8,12 @@ module GDB
|
|
8
8
|
# Batch read size.
|
9
9
|
READ_SIZE = 4096
|
10
10
|
|
11
|
+
# Instantiate a {Tube::Tube} object.
|
12
|
+
#
|
11
13
|
# @param [IO] io_in
|
14
|
+
# Input.
|
12
15
|
# @param [IO] io_out
|
16
|
+
# Output.
|
13
17
|
def initialize(io_in, io_out)
|
14
18
|
@in = io_in
|
15
19
|
@out = io_out
|
@@ -66,10 +70,14 @@ module GDB
|
|
66
70
|
# Enter interactive mode.
|
67
71
|
#
|
68
72
|
# @param [Proc] output_hook
|
69
|
-
#
|
73
|
+
# String received from output would be passed into this proc.
|
74
|
+
# Only data yielded by this proc would be flushed to +$stdout+.
|
75
|
+
#
|
76
|
+
# Use <tt>lambda { |s, &block| block.call(s) }</tt> or +:tap.to_proc+ (since Ruby 2.2)
|
77
|
+
# for a do-nothing hook.
|
70
78
|
#
|
71
79
|
# @return [void]
|
72
|
-
def interact(output_hook
|
80
|
+
def interact(output_hook)
|
73
81
|
@out.ungetc(@buffer.get)
|
74
82
|
loop do
|
75
83
|
io, = IO.select([$stdin, @out])
|
@@ -77,8 +85,7 @@ module GDB
|
|
77
85
|
next unless io.include?(@out)
|
78
86
|
begin
|
79
87
|
recv = @out.readpartial(READ_SIZE)
|
80
|
-
|
81
|
-
$stdout.write(recv) if recv
|
88
|
+
output_hook.call(recv) { |str| $stdout.write(str) }
|
82
89
|
@out.ungetc(@buffer.get) unless @buffer.empty?
|
83
90
|
rescue Errno::EIO
|
84
91
|
break
|
data/lib/gdb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- david942j
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
149
|
version: '0'
|
150
150
|
requirements: []
|
151
151
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.
|
152
|
+
rubygems_version: 2.5.2
|
153
153
|
signing_key:
|
154
154
|
specification_version: 4
|
155
155
|
summary: GDB Ruby-binding and Ruby command in GDB
|