Puppet Function: debug::break
- Defined in:
-
lib/puppet/functions/debug/break.rb
- Function type:
- Ruby 4.x API
Overview
debug::break(Optional[Hash] $options) ⇒ Any
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/puppet/functions/debug/break.rb', line 10
Puppet::Functions.create_function(:'debug::break', Puppet::Functions::InternalFunction) do
def initialize(scope, loader)
super
@debugger_stack_count = 0
end
dispatch :break do
scope_param
optional_param 'Hash', :options
end
def break(scope, options = {})
if $stdout.isatty
options = options.merge({:scope => scope})
pid = fork do
options = options.inject({}){|data,(k,v)| data[k.to_sym] = v; data}
options[:source_file], options[:source_line] = stacktrace.last
@debugger_stack_count = @debugger_stack_count + 1
@debugger_stack_count = @debugger_stack_count + 1 if options[:source_file] =~ /puppet_debugger_input/
options[:quiet] = true if @debugger_stack_count > 1
::PuppetDebugger::Cli.start_without_stdin(options)
end
Process.wait(pid)
@debugger_stack_count = @debugger_stack_count + 1
else
Puppet.warning 'debug::breakpoint(): refusing to start the debugger on a daemonized master'
end
end
def stacktrace
result = caller().reduce([]) do |memo, loc|
if loc =~ /\A(.*\.pp)?:([0-9]+):in\s(.*)/
memo << [$1.nil? ? :code : $1, $2.to_i]
end
memo
end.reverse
end
end
|