Class: Google::Cloud::Debugger::Breakpoint

Inherits:
Object
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/google/cloud/debugger/breakpoint.rb,
lib/google/cloud/debugger/breakpoint/variable.rb,
lib/google/cloud/debugger/breakpoint/evaluator.rb,
lib/google/cloud/debugger/breakpoint/stack_frame.rb,
lib/google/cloud/debugger/breakpoint/source_location.rb

Defined Under Namespace

Modules: Evaluator Classes: SourceLocation, StackFrame, Variable

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#conditionObject

Condition that triggers the breakpoint. The condition is a compound boolean expression composed using expressions in a programming language at the source location.



46
47
48
# File 'lib/google/cloud/debugger/breakpoint.rb', line 46

def condition
  @condition
end

#create_timeTime

Time this breakpoint was created by the server in seconds resolution.

Returns:

  • (Time)


75
76
77
# File 'lib/google/cloud/debugger/breakpoint.rb', line 75

def create_time
  @create_time
end

#evaluated_expressionsArray<Google::Cloud::Debugger::Breakpoint::Variable>

Values of evaluated expressions at breakpoint time. The evaluated expressions appear in exactly the same order they are listed in the expressions field. The name field holds the original expression text, the value or members field holds the result of the evaluated expression. If the expression cannot be evaluated, the status inside the Variable will indicate an error and contain the error text.



70
71
72
# File 'lib/google/cloud/debugger/breakpoint.rb', line 70

def evaluated_expressions
  @evaluated_expressions
end

#expressionsArray<String>

List of read-only expressions to evaluate at the breakpoint location. The expressions are composed using expressions in the programming language at the source location. If the breakpoint action is LOG, the evaluated expressions are included in log statements.

Returns:

  • (Array<String>)


60
61
62
# File 'lib/google/cloud/debugger/breakpoint.rb', line 60

def expressions
  @expressions
end

#final_timeTime

Time this breakpoint was finalized as seen by the server in seconds resolution.

Returns:

  • (Time)


81
82
83
# File 'lib/google/cloud/debugger/breakpoint.rb', line 81

def final_time
  @final_time
end

#idObject

Breakpoint identifier, unique in the scope of the debuggee.



30
31
32
# File 'lib/google/cloud/debugger/breakpoint.rb', line 30

def id
  @id
end

#is_final_stateBoolean Also known as: complete?

When true, indicates that this is a final result and the breakpoint state will not change from here on.

Returns:

  • (Boolean)


52
53
54
# File 'lib/google/cloud/debugger/breakpoint.rb', line 52

def is_final_state
  @is_final_state
end

#labelsHash<String, String>

A set of custom breakpoint properties, populated by the agent, to be displayed to the user.

Returns:

  • (Hash<String, String>)


118
119
120
# File 'lib/google/cloud/debugger/breakpoint.rb', line 118

def labels
  @labels
end

#locationGoogle::Cloud::Debugger::Breakpoint::SourceLocation

Breakpoint source location.



40
41
42
# File 'lib/google/cloud/debugger/breakpoint.rb', line 40

def location
  @location
end

#stack_framesArray<Google::Cloud::Debugger::Breakpoint::StackFrame>

The stack at breakpoint time.



123
124
125
# File 'lib/google/cloud/debugger/breakpoint.rb', line 123

def stack_frames
  @stack_frames
end

#statusObject

Breakpoint status.

The status includes an error flag and a human readable message. This field is usually unset. The message can be either informational or an error message. Regardless, clients should always display the text message back to the user.

Error status indicates complete failure of the breakpoint.



96
97
98
# File 'lib/google/cloud/debugger/breakpoint.rb', line 96

def status
  @status
end

#user_emailObject

E-mail address of the user that created this breakpoint



85
86
87
# File 'lib/google/cloud/debugger/breakpoint.rb', line 85

def user_email
  @user_email
end

Instance Method Details

#check_condition(binding) ⇒ Boolean

Evaluate the breakpoint's condition expression against a given binding object. Returns true if the condition expression evalutes to true; false if error happens or the expression evaluates to false.

Parameters:

  • binding (Binding)

    A Ruby Binding object

Returns:

  • (Boolean)

    True if condition evalutes to true, false if condition evaluates to false or error raised during evaluation.



234
235
236
237
238
239
240
241
242
243
# File 'lib/google/cloud/debugger/breakpoint.rb', line 234

def check_condition binding
  return true if condition.nil? || condition.empty?
  begin
    Evaluator.eval_condition binding, condition
  rescue
    set_error_state "Unable to evaluate condition",
                    refers_to: :BREAKPOINT_CONDITION
    false
  end
end

#completeObject

Marks a breakpoint as complete if this breakpoint isn't completed already. Set @is_final_state to true and set @final_time.



194
195
196
197
198
199
200
201
# File 'lib/google/cloud/debugger/breakpoint.rb', line 194

def complete
  synchronize do
    return if complete?

    @is_final_state = true
    @final_time = Time.now
  end
end

#eql?(other) ⇒ Boolean

Check if two breakpoints are equal to each other

Returns:

  • (Boolean)


282
283
284
285
286
# File 'lib/google/cloud/debugger/breakpoint.rb', line 282

def eql? other
  id == other.id &&
    path == other.path &&
    line == other.line
end

#eval_call_stack(call_stack_bindings) ⇒ Boolean

Evaluate the breakpoint unless it's already marked as completed. Use "@stack_frames" and "@evaluated_expressions" instance variables to store the result snapshot. Set breakpoint to complete when done.

Parameters:

  • call_stack_bindings (Array<Binding>)

    An array of Ruby Binding objects, from the call stack that leads to the triggering of the breakpoints.

Returns:

  • (Boolean)

    True if evaluated successfully; false otherwise.



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/google/cloud/debugger/breakpoint.rb', line 256

def eval_call_stack call_stack_bindings
  synchronize do
    return false if complete?

    top_frame_binding = call_stack_bindings[0]

    # Abort evaluation if breakpoint condition isn't met
    return false unless check_condition top_frame_binding

    begin
      @stack_frames = Evaluator.eval_call_stack call_stack_bindings
      unless expressions.empty?
        @evaluated_expressions =
          Evaluator.eval_expressions top_frame_binding, @expressions
      end
    rescue
      return false
    end

    complete
  end
  true
end

#lineInteger

Get the line number of this breakpoint

Examples:

breakpoint = Breakpoint.new nil, "path/to/file.rb", 11
breakpoint.line #=> 11

Returns:

  • (Integer)

    The line number for this breakpoint



221
222
223
# File 'lib/google/cloud/debugger/breakpoint.rb', line 221

def line
  location.nil? ? nil : location.line
end

#pathString

Get the file path of this breakpoint

Examples:

breakpoint = Breakpoint.new nil, "path/to/file.rb"
breakpoint.path #=> "path/to/file.rb"

Returns:

  • (String)

    The file path for this breakpoint



211
212
213
# File 'lib/google/cloud/debugger/breakpoint.rb', line 211

def path
  location.nil? ? nil : location.path
end

#set_error_state(message, refers_to: :UNSPECIFIED, is_final: true) ⇒ Google::Devtools::Clouddebugger::V2::StatusMessage

Set breakpoint to an error state, which initializes the @status instance variable with the error message. Also mark this breakpoint as completed if is_final is true.

Parameters:

Returns:



328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/google/cloud/debugger/breakpoint.rb', line 328

def set_error_state message, refers_to: :UNSPECIFIED, is_final: true
  description = Google::Devtools::Clouddebugger::V2::FormatMessage.new(
    format: message
  )
  @status = Google::Devtools::Clouddebugger::V2::StatusMessage.new(
    is_error: true,
    refers_to: refers_to,
    description: description
  )

  complete if is_final

  @status
end