Class: Yast::Debugger

Inherits:
Object
  • Object
show all
Extended by:
Logger, UIShortcuts
Defined in:
src/ruby/yast/debugger.rb

Constant Summary

Constants included from UIShortcuts

UIShortcuts::UI_TERMS

Class Method Summary collapse

Methods included from Logger

log

Class Method Details

.installed?Boolean

is the Ruby debugger installed and can be loaded?



90
91
92
93
94
95
# File 'src/ruby/yast/debugger.rb', line 90

def installed?
  require "byebug"
  true
rescue LoadError
  false
end

.start(remote: false, port: 3344, start_client: true) ⇒ Object

Start the Ruby debugger. It handles the current UI mode and displays an user request if the debugger front-end needs to be started manually.

Examples:

Start the debugger with default settings:

require "yast/debugger"
Yast::Debugger.start

When using the debugger temporary you can use just simple:

require "byebug"
byebug


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
# File 'src/ruby/yast/debugger.rb', line 29

def start(remote: false, port: 3344, start_client: true)
  return unless load_debugger

  # do not start the server if it is already running
  if Byebug.started?
    log.warn "The debugger is already running at port #{Byebug.actual_port}"
    log.warn "Skipping the server setup"
  else
    Yast.import "UI"
    if UI.TextMode || remote || !start_client
      # in textmode or in remote mode ask the user to start
      # the debugger client manually
      UI.OpenDialog(Label(debugger_message(remote, port)))
      popup = true
    else
      # in GUI open an xterm session with the debugger
      start_gui_session(port)
    end

    # start the server and wait for connection, add an extra delay
    # if we start the front end automatically to get the server ready
    # (to avoid "Broken pipe" error)
    # FIXME: looks like a race condition inside byebug itself...
    start_server(remote, port, delay: !popup)

    UI.CloseDialog if popup
  end

  # start the debugger session
  byebug
  # Now you can inspect the current state in the debugger,
  # or use "next" to continue.
  # Use "help" command to see the available commands, see more at
  # https://github.com/deivid-rodriguez/byebug/blob/master/GUIDE.md
end

.start_from_envObject

start the Ruby debugger if "Y2DEBUGGER" environment variable is set to "1", "remote" or "manual" (the test is case insensitive, "y2debugger" variable can be also used)



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'src/ruby/yast/debugger.rb', line 68

def start_from_env
  # do not evaluate the debugger request again for each client started,
  # run the debugger evaluation only once
  return if @debugger_handled
  @debugger_handled = true

  debug = env_value
  return if debug != "1" && debug != "remote" && debug != "manual"

  # FIXME: the UI.TextMode call is used here just to force the UI
  # initialization, if it is initialized inside the start method the
  # ncurses UI segfaults :-(
  # interestengly, the Qt UI works correctly...
  Yast.import "UI"
  log.info "text mode: #{UI.TextMode}"

  log.info "Debugger set to: #{debug}"
  start(remote: debug == "remote", start_client: debug != "manual")
end