Class: Readapt::Debugger

Inherits:
Object
  • Object
show all
Includes:
Observable, Finder
Defined in:
lib/readapt/debugger.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Finder

find, which

Constructor Details

#initializeDebugger

Returns a new instance of Debugger.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/readapt/debugger.rb', line 18

def initialize
  @stack = []
  @frames = {}
  @running = false
  @attached = false
  @request = nil
  @config = {}
  @original_argv = ARGV.clone
  @original_prog = $0
  @breakpoints = {}
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



14
15
16
# File 'lib/readapt/debugger.rb', line 14

def file
  @file
end

#monitorObject (readonly)

Returns the value of attribute monitor.



12
13
14
# File 'lib/readapt/debugger.rb', line 12

def monitor
  @monitor
end

#pause_on_raise=(value) ⇒ Object (writeonly)

Sets the attribute pause_on_raise

Parameters:

  • value

    the value to set the attribute pause_on_raise to.



16
17
18
# File 'lib/readapt/debugger.rb', line 16

def pause_on_raise=(value)
  @pause_on_raise = value
end

Class Method Details

.run(&block) ⇒ Object



119
120
121
# File 'lib/readapt/debugger.rb', line 119

def self.run &block
  new.run &block
end

Instance Method Details

#attached?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/readapt/debugger.rb', line 59

def attached?
  @request == :attach
end

#clear_breakpoints(source) ⇒ Object



108
109
110
111
112
# File 'lib/readapt/debugger.rb', line 108

def clear_breakpoints source
  @breakpoints.delete_if { |_key, value|
    value.source == source
  }
end

#config(arguments, request) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/readapt/debugger.rb', line 30

def config arguments, request
  @file = Readapt.normalize_path(find(arguments['program']))
  @config = arguments
  @request = request
rescue LoadError => e
  STDERR.puts e.message
end

#disconnectObject



114
115
116
117
# File 'lib/readapt/debugger.rb', line 114

def disconnect
  shutdown if launched?
  @request = nil
end

#frame(id) ⇒ Object



51
52
53
# File 'lib/readapt/debugger.rb', line 51

def frame id
  @frames[id] || Frame::NULL_FRAME
end

#get_breakpoint(source, line) ⇒ Object



100
101
102
# File 'lib/readapt/debugger.rb', line 100

def get_breakpoint source, line
  @breakpoints["#{source}:#{line}"] || Breakpoint.new(source, line, nil, 0)
end

#launched?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/readapt/debugger.rb', line 55

def launched?
  @request == :launch
end

#output(data, category = :console) ⇒ Object



93
94
95
96
97
98
# File 'lib/readapt/debugger.rb', line 93

def output data, category = :console
  send_event('output', {
    output: data,
    category: category
  })
end

#pause_on_raise?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/readapt/debugger.rb', line 38

def pause_on_raise?
  @pause_on_raise ||= false
end

#runObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/readapt/debugger.rb', line 71

def run
  # raise RuntimeError, 'Debugger is already running' if @running
  @running = true
  send_event('process', {
    name: @file
  })
  Monitor.start @file do |snapshot|
    debug snapshot
  end
  yield if block_given?
rescue StandardError => e
  STDERR.puts "[#{e.class}] #{e.message}"
  STDERR.puts e.backtrace.join("\n")
ensure
  Monitor.stop
  @running = false
  STDOUT.flush #unless STDOUT.closed?
  STDERR.flush #unless STDERR.closed?
  changed
  send_event 'terminated', nil
end

#set_breakpoint(source, line, condition, hitcount) ⇒ Object



104
105
106
# File 'lib/readapt/debugger.rb', line 104

def set_breakpoint source, line, condition, hitcount
  @breakpoints["#{source}:#{line}"] = Breakpoint.new(source, line, condition, hitcount)
end

#startObject



63
64
65
66
67
68
69
# File 'lib/readapt/debugger.rb', line 63

def start
  ::Thread.new do
    set_program_args
    run { load @file }
    set_original_args
  end
end

#thread(id) ⇒ Readapt::Thread

Returns:



43
44
45
# File 'lib/readapt/debugger.rb', line 43

def thread id
  Thread.find(id)
end

#threadsObject



47
48
49
# File 'lib/readapt/debugger.rb', line 47

def threads
  Thread.all
end