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/validator.rb,
lib/google/cloud/debugger/breakpoint/stack_frame.rb,
lib/google/cloud/debugger/breakpoint/status_message.rb,
lib/google/cloud/debugger/breakpoint/variable_table.rb,
lib/google/cloud/debugger/breakpoint/source_location.rb

Overview

Breakpoint

Abstract class that represents a breakpoint, which can be set and triggered in a debuggee application. Maps to gRPC struct Devtools::Clouddebugger::V2::Breakpoint.

Direct Known Subclasses

Logpoint, Snappoint

Defined Under Namespace

Modules: Evaluator, Validator Classes: SourceLocation, StackFrame, StatusMessage, Variable, VariableTable

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)


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

def action
  @action
end

#app_rootString

Absolute path to the debuggee Ruby application root directory.

Returns:

  • (String)


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

def app_root
  @app_root
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.



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

def condition
  @condition
end

#create_timeTime

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

Returns:

  • (Time)


106
107
108
# File 'lib/google/cloud/debugger/breakpoint.rb', line 106

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.



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

def evaluated_expressions
  @evaluated_expressions
end

#evaluated_log_messageObject

The evaluated log message when action is LOG.



66
67
68
# File 'lib/google/cloud/debugger/breakpoint.rb', line 66

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


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

def expressions
  @expressions
end

#final_timeTime

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

Returns:

  • (Time)


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

def final_time
  @final_time
end

#idObject

Breakpoint identifier, unique in the scope of the debuggee.



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

def id
  @id
end

#is_final_stateBoolean

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

Returns:

  • (Boolean)


83
84
85
# File 'lib/google/cloud/debugger/breakpoint.rb', line 83

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


148
149
150
# File 'lib/google/cloud/debugger/breakpoint.rb', line 148

def labels
  @labels
end

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

Breakpoint source location.



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

def location
  @location
end

#log_levelObject

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



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

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.



58
59
60
# File 'lib/google/cloud/debugger/breakpoint.rb', line 58

def log_message_format
  @log_message_format
end

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

The stack at breakpoint time.



153
154
155
# File 'lib/google/cloud/debugger/breakpoint.rb', line 153

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.



127
128
129
# File 'lib/google/cloud/debugger/breakpoint.rb', line 127

def status
  @status
end

#user_emailObject

E-mail address of the user that created this breakpoint



116
117
118
# File 'lib/google/cloud/debugger/breakpoint.rb', line 116

def user_email
  @user_email
end

#variable_tableObject

The variable_table exists to aid with computation, memory and network traffic optimization. It enables storing a variable once and reference it from multiple variables, including variables stored in the variable_table itself. For example, the same this object, which may appear at many levels of the stack, can have all of its data stored once in this table. The stack frame variables then would hold only a reference to it.

The variable var_table_index field is an index into this repeated field. The stored objects are nameless and get their name from the referencing variable. The effective variable is a merge of the referencing variable and the referenced variable.



142
143
144
# File 'lib/google/cloud/debugger/breakpoint.rb', line 142

def variable_table
  @variable_table
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 or there isn't a condition; otherwise false. Set breakpoint to error state if exception happens.

Parameters:

  • binding (Binding)

    A Ruby Binding object

Returns:

  • (Boolean)

    True if condition evalutes to true or there isn't a condition. False if condition evaluates to false or error raised during evaluation.



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/google/cloud/debugger/breakpoint.rb', line 303

def check_condition binding
  return true if condition.nil? || condition.empty?
  condition_result =
    Evaluator.readonly_eval_expression binding, condition

  if condition_result.is_a?(Exception) &&
     condition_result.instance_variable_get(:@mutation_cause)
    set_error_state "Error: #{condition_result.message}",
                    refers_to: StatusMessage::BREAKPOINT_CONDITION

    return false
  end


  condition_result ? true : false
rescue => e
  set_error_state "Error: #{e.message}",
                  refers_to: StatusMessage::BREAKPOINT_CONDITION
  false
end

#completeObject

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



246
247
248
249
250
251
252
253
# File 'lib/google/cloud/debugger/breakpoint.rb', line 246

def complete
  synchronize do
    return if complete?

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

#complete?Boolean

Check if the breakpoint has been evaluated or set to a final error state.

Returns:

  • (Boolean)


258
259
260
# File 'lib/google/cloud/debugger/breakpoint.rb', line 258

def complete?
  is_final_state ? true : false
end

#eql?(other) ⇒ Boolean

Check if two breakpoints are equal to each other

Returns:

  • (Boolean)


326
327
328
329
330
# File 'lib/google/cloud/debugger/breakpoint.rb', line 326

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

#full_pathObject

Get full absolute file path by combining the relative file path with application root directory path.



389
390
391
392
393
394
395
# File 'lib/google/cloud/debugger/breakpoint.rb', line 389

def full_path
  if app_root.nil? || app_root.empty?
    path
  else
    File.join app_root, path
  end
end

#lineInteger

Get the line number of this breakpoint

Examples:

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

Returns:

  • (Integer)

    The line number for this breakpoint



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

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

#pathString

Get the file path of this breakpoint

Examples:

breakpoint =
  Google::Cloud::Debugger::Breakpoint.new nil, "path/to/file.rb"
breakpoint.path #=> "path/to/file.rb"

Returns:

  • (String)

    The file path for this breakpoint



278
279
280
# File 'lib/google/cloud/debugger/breakpoint.rb', line 278

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

#set_error_state(message, refers_to: StatusMessage::UNSPECIFIED, is_final: true) ⇒ Google::Cloud::Debugger::Breakpoint::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:

  • message (String)

    The error message

  • refers_to (Symbol)

    Enum that specifies what the error refers to. Defaults :UNSPECIFIED. See StatusMessage class for list of possible values

  • is_final (Boolean)

    Marks the breakpoint as final if true. Defaults true.

Returns:



373
374
375
376
377
378
379
380
381
382
383
384
# File 'lib/google/cloud/debugger/breakpoint.rb', line 373

def set_error_state message, refers_to: StatusMessage::UNSPECIFIED,
                    is_final: true
  @status = StatusMessage.new.tap do |s|
    s.is_error = true
    s.refers_to = refers_to
    s.description = message
  end

  complete if is_final

  @status
end

#valid?Boolean

Check if the breakpoint is valid or not. Invoke validation function if breakpoint hasn't been finallized yet.

Returns:

  • (Boolean)


265
266
267
268
269
# File 'lib/google/cloud/debugger/breakpoint.rb', line 265

def valid?
  Validator.validate self unless complete?

  status && status.is_error ? false : true
end