Class: Yast::Debugger

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

Overview

Interface to a Ruby debugger (byebug)

Y2DEBUGGER environment variable (or install boot option)

  • 1: start the debugger when YaST starts; in GUI, run an xterm with the debugger client; in TUI, tell the user to run the debugger client
  • manual: like "1" but always tell the user instead of starting the client
  • remote: tell the user to connect from a remote machine. INSECURE!
  • 0: do not start the debugger, don't even ask if an exception is raised

See also https://yastgithubio.readthedocs.io/en/latest/debugging/

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?

Returns:

  • (Boolean)

    true if the debugger is present



107
108
109
110
111
112
# File 'src/ruby/yast/debugger.rb', line 107

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

Parameters:

  • remote (Boolean) (defaults to: false)

    if set to true the server is accesible from network. By default the debugger can connect only from the local machine, not from the network. If you need remote debugging then enable it. WARNING: There is no authentication, everybody can connect to the debugger! Use only in a trusted network as this is actually a backdoor to the system! For secure connection use SSH and start the debugger locally after connecting via SSH.

  • port (Integer) (defaults to: 3344)

    the port number where the debugger server will listen to

  • start_client (Boolean) (defaults to: true)

    autostart the debugger client (ignored in remote debugging)



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
66
67
68
69
70
71
72
73
74
75
# File 'src/ruby/yast/debugger.rb', line 41

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)



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'src/ruby/yast/debugger.rb', line 80

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

.unwanted?Boolean

Returns Is the debugger explicitly unwanted even if available.

Returns:

  • (Boolean)

    Is the debugger explicitly unwanted even if available



101
102
103
# File 'src/ruby/yast/debugger.rb', line 101

def unwanted?
  env_value == "0"
end