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

#actionSymbol

Action to take when a breakpoint is hit. Either :CAPTURE or :LOG.

Returns:

  • (Symbol)


35
36
37
# File 'lib/google/cloud/debugger/breakpoint.rb', line 35

def action
  @action
end

#conditionObject

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



62
63
64
# File 'lib/google/cloud/debugger/breakpoint.rb', line 62

def condition
  @condition
end

#create_timeTime

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

Returns:

  • (Time)


91
92
93
# File 'lib/google/cloud/debugger/breakpoint.rb', line 91

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.



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

def evaluated_expressions
  @evaluated_expressions
end

#evaluated_log_messageObject

The evaluated log message when action is LOG.



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

def evaluated_log_message
  @evaluated_log_message
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>)


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

def expressions
  @expressions
end

#final_timeTime

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

Returns:

  • (Time)


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

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)


68
69
70
# File 'lib/google/cloud/debugger/breakpoint.rb', line 68

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>)


134
135
136
# File 'lib/google/cloud/debugger/breakpoint.rb', line 134

def labels
  @labels
end

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

Breakpoint source location.



56
57
58
# File 'lib/google/cloud/debugger/breakpoint.rb', line 56

def location
  @location
end

#log_levelObject

Indicates the severity of the log. Only relevant when action is LOG.



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

def log_level
  @log_level
end

#log_message_formatObject

Only relevant when action is LOG. Defines the message to log when the breakpoint hits. The message may include parameter placeholders $0, $1, etc. These placeholders are replaced with the evaluated value of the appropriate expression. Expressions not referenced in logMessageFormat are not logged.



43
44
45
# File 'lib/google/cloud/debugger/breakpoint.rb', line 43

def log_message_format
  @log_message_format
end

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

The stack at breakpoint time.



139
140
141
# File 'lib/google/cloud/debugger/breakpoint.rb', line 139

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.



112
113
114
# File 'lib/google/cloud/debugger/breakpoint.rb', line 112

def status
  @status
end

#user_emailObject

E-mail address of the user that created this breakpoint



101
102
103
# File 'lib/google/cloud/debugger/breakpoint.rb', line 101

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.



254
255
256
257
258
259
260
261
262
263
# File 'lib/google/cloud/debugger/breakpoint.rb', line 254

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.



214
215
216
217
218
219
220
221
# File 'lib/google/cloud/debugger/breakpoint.rb', line 214

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)


289
290
291
292
293
# File 'lib/google/cloud/debugger/breakpoint.rb', line 289

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

#evaluate(call_stack_bindings) ⇒ Boolean

Evaluate the breakpoint unless it's already marked as completed. Store evaluted results in @evaluated_expressions, @stack_frames, and @evaluated_log_message, depends on the action of breakpoint. Mark breakpoint complete if successfully evaluated a breakpoint with :CAPTURE action.

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.



278
279
280
281
282
283
284
285
# File 'lib/google/cloud/debugger/breakpoint.rb', line 278

def evaluate call_stack_bindings
  case action
  when :CAPTURE
    evaluate_snapshot_point call_stack_bindings
  when :LOG
    evaluate_logpoint call_stack_bindings[0]
  end
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



241
242
243
# File 'lib/google/cloud/debugger/breakpoint.rb', line 241

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



231
232
233
# File 'lib/google/cloud/debugger/breakpoint.rb', line 231

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:



335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/google/cloud/debugger/breakpoint.rb', line 335

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