### Setup and Test Byebug Threading Source: https://github.com/deivid-rodriguez/byebug/blob/main/Ruby_Grant_2014_Report.md Commands to install dependencies, compile the C-extension, and execute the thread-related test suite. ```shell bundle install # Install dependencies rake compile # Compile the C-extension ruby -w -Ilib test/test_helper.rb test/commands/thread_test.rb ``` -------------------------------- ### Remote::Server#start Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Starts the server listening on the specified host and port. ```APIDOC ## Remote::Server#start(host, port) ### Description Starts the server listening on the specified address. ### Parameters - **host** (String) - Required - Host to bind to - **port** (Integer) - Required - Port to listen on ``` -------------------------------- ### Start Remote Server Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Starts the server listening on the specified host and port. ```ruby server.start(host, port) ``` -------------------------------- ### Setup remote debugging Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/configuration.md Start a remote debugging server and connect to it from another terminal. ```ruby # In your application require 'byebug' # Start listening for remote connections Byebug.spawn("0.0.0.0", 8989) Byebug.attach # From another terminal: # byebug -R 192.168.1.100:8989 ``` -------------------------------- ### CommandNotFound usage examples Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/errors.md Examples of user input triggering command not found errors. ```text # User enters invalid command byebug> invalid_cmd *** Unknown command 'invalid_cmd'. Try 'help'. # Subcommand error byebug> info invalid_subcommand *** Unknown command 'info invalid_subcommand'. Try 'help info'. ``` -------------------------------- ### Install Byebug Source: https://github.com/deivid-rodriguez/byebug/blob/main/README.md Installation commands for the Byebug gem. ```shell gem install byebug ``` ```shell bundle add byebug --group "development, test" ``` -------------------------------- ### Byebug.start_control(host, port) Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Starts the control server thread. ```APIDOC ## Byebug.start_control(host, port) ### Description Starts the control thread that handles out-of-band commands while debugging. ### Parameters - **host** (String) - Optional - Host to bind to - **port** (Integer) - Optional - Control port number (default: 8990) ``` -------------------------------- ### Configure Initialization Script Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/runner.md Get or set whether to load .byebugrc files. ```ruby runner.init_script # => Boolean runner.init_script = false ``` -------------------------------- ### runner.run Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/runner.md Starts the debugging session. ```APIDOC ## runner.run ### Description Main entry point that parses options, validates the script, runs it under debugger control, and handles the REPL. ``` -------------------------------- ### Byebug.init_file Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/byebug.md Gets or sets the initialization script filename. ```APIDOC ## Byebug.init_file ### Description Gets or sets the initialization script filename used by run_init_script. ### Method Ruby Class Method ### Parameters - **filename** (String) - Required - Name of initialization file to load (default: ".byebugrc") ``` -------------------------------- ### Byebug.start_server(host, port) Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Starts the remote debugging server thread. ```APIDOC ## Byebug.start_server(host, port) ### Description Starts the remote debugging server thread. If wait_connection is true, blocks until the first client connects. ### Parameters - **host** (String) - Optional - Host to bind to (default: nil, all interfaces) - **port** (Integer) - Optional - Port number (default: 8989) ``` -------------------------------- ### Remote::Client#start Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Connects to a remote debugger server. ```APIDOC ## Remote::Client#start(host, port) ### Description Connects to a remote debugger server. ### Parameters - **host** (String) - Optional - Remote host (default: "localhost") - **port** (Integer) - Optional - Remote port (default: 8989) ``` -------------------------------- ### Prepare for REPL entry Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/processor.md Initializes state, clears history, and runs auto-commands before starting the REPL. ```ruby processor.before_repl ``` -------------------------------- ### Start Rails Server Source: https://github.com/deivid-rodriguez/byebug/blob/main/README.md Command to launch a Rails server after adding byebug to the code. ```shell bin/rails s ``` -------------------------------- ### Configure Byebug via .byebugrc Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/configuration.md Example initialization file for setting display, history, and debugging preferences. ```bash # ~/.byebugrc # Byebug initialization file # Display settings set autolist on set fullpath on set callstyle short set listsize 15 set width 120 # History settings set autosave on set histsize 500 set histfile ~/.byebug_history # Debugging behavior set post_mortem on set stack_on_error on # Breakpoints for development break app.rb:100 break app/models/user.rb:50 if admin? # Initial display info breakpoints list ``` -------------------------------- ### Start control server thread Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Starts a thread dedicated to handling out-of-band commands during a debugging session. ```ruby Byebug.start_control(host = nil, port = PORT + 1) ``` -------------------------------- ### Get help for a specific subcommand Source: https://github.com/deivid-rodriguez/byebug/blob/main/GUIDE.md Provide the full or abbreviated subcommand name to get detailed help for that specific action. ```console (byebug) help info breakpoints Status of user-settable breakpoints. Without argument, list info about all breakpoints. With an integer argument, list info on that breakpoint. ``` ```console (byebug) help info b Status of user-settable breakpoints. Without argument, list info about all breakpoints. With an integer argument, list info on that breakpoint. ``` -------------------------------- ### Context.interface Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/context.md Gets or sets the user interface for user interaction. ```APIDOC ## Context.interface ### Description Gets or sets the user interface for user interaction. Defaults to LocalInterface. ### Parameters - **interface** (Interface) - Required - Interface for reading input and printing output ### Usage ```ruby Context.interface = LocalInterface.new ``` ``` -------------------------------- ### Breakpoint syntax error example Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/errors.md Example of a syntax error triggered by an invalid breakpoint condition. ```text byebug> break app.rb:10 if x > *** Syntax error in breakpoint condition: x > ``` -------------------------------- ### Define .byebugrc initialization file Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/configuration.md Example of a .byebugrc file containing debugger settings, breakpoints, and initial commands. ```bash # Basic settings set autolist on set autosave on set callstyle short set listsize 15 set histsize 256 # Set common breakpoints break app.rb:42 break app/models/user.rb:10 if admin? # Initial commands to run help ``` -------------------------------- ### Configure Editor Syntax Source: https://github.com/deivid-rodriguez/byebug/blob/main/GUIDE.md Example of the command-line syntax required for an editor to work with Byebug. ```bash ex +nnn file ``` -------------------------------- ### Define File Path Examples Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/types.md Illustrates relative and absolute file path formats used for source code identification. ```ruby "app.rb" # Relative "/home/user/app.rb" # Absolute "app/models/user.rb" # Relative to cwd "/usr/lib/ruby/3.3.0/lib.rb" # Standard library ``` -------------------------------- ### Breakpoint validation error examples Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/errors.md Examples of errors triggered by invalid breakpoint locations or files. ```text # Non-existent file byebug> break nonexistent.rb:10 *** break.errors.source # Line too high byebug> break app.rb:9999 *** break.errors.far_line # Invalid location byebug> break invalid_syntax *** break.errors.location ``` -------------------------------- ### Byebug.spawn Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/byebug.md Starts a remote debugging server on the specified host and port. ```APIDOC ## Byebug.spawn(host, port) ### Description Starts a remote debugging server and sets wait_connection to true, causing the program to wait for a client connection before proceeding. ### Method Ruby Class Method ### Parameters - **host** (String) - Optional - Hostname or IP to bind the debug server to (default: "localhost") - **port** (Integer) - Optional - Port number; uses PORT + 1 if nil (default: 8990) ### Return Type nil ``` -------------------------------- ### processor.process_commands Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/processor.md Starts the main REPL loop for interactive command processing. ```APIDOC ## processor.process_commands ### Description Main REPL loop for interactive command processing. Calls before_repl, enters the repl loop, and ensures after_repl cleanup. ``` -------------------------------- ### byebug Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/byebug.md Starts the debugger at the call location. ```APIDOC ## byebug ### Description Enters the debugger at the point where called in user code. Alias: debugger. ### Method Kernel Method ``` -------------------------------- ### Enter IRB from Byebug Source: https://github.com/deivid-rodriguez/byebug/blob/main/GUIDE.md Starts an IRB session within the current program state. ```console $ byebug triangle.rb [1, 10] in /path/to/triangle.rb 1: # Compute the n'th triangle number, the hard way: triangle(n) == (n*(n+1))/2 => 2: def triangle(n) 3: tri = 0 4: 0.upto(n) do |i| 5: tri += i 6: end 7: tri 8: end 9: 10: if __FILE__ == $0 (byebug) irb irb(main):001:0> (0..6).inject { |sum, i| sum += i } => 21 irb(main):002:0> exit (byebug) ``` -------------------------------- ### context.file Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/context.md Gets the file path of the current frame. ```APIDOC ## context.file ### Description Returns the source file path of the current execution frame. ### Return Type String ``` -------------------------------- ### Context.processor Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/context.md Gets or sets the command processor class. ```APIDOC ## Context.processor ### Description Gets or sets the command processor class used for handling debugger commands. ### Parameters - **processor** (Class) - Required - Processor class for handling commands ### Usage ```ruby Context.processor = CommandProcessor ``` ``` -------------------------------- ### context.location Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/context.md Gets a formatted string of current file and line. ```APIDOC ## context.location ### Description Returns a normalized string containing the file path and line number separated by a colon. ### Return Type String ``` -------------------------------- ### Starting a Byebug session Source: https://github.com/deivid-rodriguez/byebug/blob/main/GUIDE.md Initial command to launch the debugger on a specific Ruby file. ```console $ byebug /path/to/triangle.rb [1, 10] in /path/to/triangle.rb 1: # 2: # The n'th triangle number: triangle(n) = n*(n+1)/2 = 1 + 2 + ... + n 3: # => 4: def triangle(n) 5: tri = 0 6: 7: 0.upto(n) { |i| tri += i } 8: 9: tri 10: end (byebug) ``` -------------------------------- ### Start remote debugger session Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/byebug.md Spawns a remote server and attaches the debugger. ```ruby remote_byebug(host = "localhost", port = nil) ``` ```ruby class Application def initialize remote_byebug("0.0.0.0", 8989) end end ``` -------------------------------- ### Display error stack trace Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/errors.md Example output when stack_on_error is enabled. ```text byebug> print undefined_var *** /path/to/app.rb:10: NameError Exception: undefined local variable from /path/to/app.rb:10:in `block' from /usr/lib/ruby/... ``` -------------------------------- ### Byebug.attach Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/byebug.md Starts byebug and stops at the first line of user code. ```APIDOC ## Byebug.attach ### Description Starts the debugger in attached mode if not already started, then steps out to the first line of user code. ### Method Ruby Class Method ### Signature `Byebug.attach` ### Return Type nil ``` -------------------------------- ### Run Debugging Session Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/runner.md Start the debugging session, which parses options and handles the REPL. ```ruby runner.run ``` ```ruby runner = Byebug::Runner.new runner.run # Processes options, loads init script, debugs the program ``` -------------------------------- ### Start Remote Debugger Server Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/README.md Launch a remote debugging server on a specified host and port. ```ruby Byebug.spawn("0.0.0.0", 8989) ``` -------------------------------- ### Setting.help_all Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/setting.md Retrieves formatted help text for all settings. ```APIDOC ## Setting.help_all ### Description Generates a display-friendly string containing help text for all registered settings. ### Signature `Setting.help_all` ### Returns - **String** - The formatted help documentation. ``` -------------------------------- ### Configure custom initialization file via CLI and Ruby Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/configuration.md Demonstrates how to control initialization file loading via command-line flags or programmatically. ```bash # Set the init file name byebug -x app.rb # Use default .byebugrc (default) byebug --no-rc app.rb # Skip loading rc file ``` ```ruby Byebug.init_file = ".mydebuggrc" Byebug.run_init_script ``` -------------------------------- ### Spawn remote debugging server Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/byebug.md Starts a remote server and waits for a client connection. ```ruby Byebug.spawn(host = "localhost", port = nil) ``` ```ruby # In your application def initialize Byebug.spawn("0.0.0.0", 8989) Byebug.attach end # Connect with client from another terminal # byebug -R localhost:8989 ``` -------------------------------- ### Get help for a specific command Source: https://github.com/deivid-rodriguez/byebug/blob/main/GUIDE.md Provide a command name to the help command to see detailed usage instructions. ```console (byebug) help list l[ist][[-=]][ nn-mm] Lists lines of source code Lists lines forward from current line or from the place where code was last listed. If "list-" is specified, lists backwards instead. If "list=" is specified, lists from current line regardless of where code was last listed. A line range can also be specified to list specific sections of code. (byebug) ``` -------------------------------- ### Get Usage Banner Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/runner.md Retrieve the formatted usage banner string. ```ruby runner.banner # => String ``` ```ruby puts runner.banner # Output: # byebug 13.0.0 # # Usage: byebug [options] -- ``` -------------------------------- ### Regex matching example Source: https://github.com/deivid-rodriguez/byebug/blob/main/GUIDE.md A simple Ruby script demonstrating how Ruby records specific lines as stoppable points for the debugger. ```ruby "Yes it does" =~ / (Yes) \s+ it \s+ does /ix puts $1 ``` -------------------------------- ### Configure Byebug at runtime Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/configuration.md Set debugger mode, settings, and initialization file path before starting the debugger. ```ruby # Configure before starting debugger require 'byebug' # Set mode Byebug.mode = :attached # Configure settings before attaching Setting[:autosave] = true Setting[:listsize] = 20 Setting[:callstyle] = "short" # Set init file Byebug.init_file = ".mybyebugrc" # Start debugging byebug ``` -------------------------------- ### Evaluation error examples Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/errors.md Examples of runtime errors occurring during expression evaluation in the debugger. ```text # Undefined variable byebug> print undefined_var *** NameError Exception: undefined local variable or method `undefined_var' # Type error byebug> print x / "string" *** TypeError Exception: String can't be coerced into Numeric ``` -------------------------------- ### Retrieve all settings help text Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/setting.md Generate a formatted string containing help documentation for all registered settings. ```ruby Setting.help_all # => String ``` ```ruby puts Setting.help_all # Output: # List of supported settings: # # autoirb -- Invoke IRB on every stop # autolist -- Automatically list source code # autosave -- Automatically save command history # ... ``` -------------------------------- ### Execute initialization script Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/byebug.md Loads and runs the configured initialization file. ```ruby Byebug.run_init_script ``` ```ruby # .byebugrc in home directory set autolist on set callstyle short break app/controllers/users_controller.rb:10 ``` -------------------------------- ### Display Byebug help Source: https://github.com/deivid-rodriguez/byebug/blob/main/GUIDE.md Prints the available command-line options and usage instructions. ```console $ byebug --help byebug 3.5.1 Usage: byebug [options] -- -d, --debug Set $DEBUG=true -I, --include list Add paths to $LOAD_PATH -m, --[no-]post-mortem Use post-mortem mode -q, --[no-]quit Quit when script finishes -x, --[no-]rc Run byebug initialization file -s, --[no-]stop Stop when script is loaded -r, --require file Require library before script -R, --remote [host:]port Remote debug [host:]port -t, --[no-]trace Turn on line tracing -v, --version Print program version -h, --help Display this message ``` -------------------------------- ### Remote Protocol Client Responses Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Examples of command and confirmation responses sent from the client to the server. ```text step next continue ``` ```text y n ``` -------------------------------- ### Start remote debugging server thread Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Initializes the server and control thread. Blocks until a client connects if wait_connection is enabled. ```ruby Byebug.start_server(host = nil, port = PORT) ``` -------------------------------- ### remote_byebug Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/byebug.md Starts a remote debugger session. ```APIDOC ## remote_byebug(host, port) ### Description Spawns a remote debug server and attaches the debugger, waiting for a client connection. ### Method Kernel Method ### Parameters - **host** (String) - Optional - Host to bind debug server to (default: "localhost") - **port** (Integer) - Optional - Port for debug server; uses PORT if nil ``` -------------------------------- ### Method Arguments Array Examples Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/types.md Represents the structure returned by Frame#args, detailing method parameters and their types. ```ruby # def foo(x, y=10, *rest, &block) [ [:req, :x], [:opt, :y], [:rest, :rest], [:block, :block] ] # def bar(user:, admin: false, **options) [ [:keyreq, :user], [:key, :admin], [:keyrest, :options] ] ``` -------------------------------- ### Attach debugger to current process Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/byebug.md Starts the debugger and halts execution at the first line of user code. ```ruby Byebug.attach ``` ```ruby def index Byebug.attach # Debugger stops here @articles = Article.find_recent end ``` -------------------------------- ### Managing Arguments and Breakpoints Source: https://github.com/deivid-rodriguez/byebug/blob/main/GUIDE.md Shows how to restart a session with arguments, set breakpoints, and display variable values. ```console (byebug) $ARGV [] ``` ```console (byebug) restart 3 Re exec'ing: /path/to/exe/byebug /path/to/hanoi.rb 3 [1, 10] in /path/to/hanoi.rb 1: # 2: # Solves the classic Towers of Hanoi puzzle. 3: # => 4: def hanoi(n, a, b, c) 5: hanoi(n - 1, a, c, b) if n - 1 > 0 6: 7: puts "Move disk #{a} to #{b}" 8: 9: hanoi(n - 1, c, b, a) if n - 1 > 0 10: end (byebug) break 5 Created breakpoint 1 at /path/to/hanoi.rb:5 (byebug) continue Stopped by breakpoint 1 at /path/to/hanoi.rb:5 [1, 10] in /path/to/hanoi.rb 1: # 2: # Solves the classic Towers of Hanoi puzzle. 3: # 4: def hanoi(n, a, b, c) => 5: hanoi(n - 1, a, c, b) if n - 1 > 0 6: 7: puts "Move disk #{a} to #{b}" 8: 9: hanoi(n - 1, c, b, a) if n - 1 > 0 10: end (byebug) display n 1: n = 3 (byebug) display a 2: a = :a (byebug) display b 3: b = :b (byebug) undisplay 3 (byebug) continue Stopped by breakpoint 1 at /path/to/hanoi.rb:5 1: n = 2 2: a = :a [1, 10] in /path/to/hanoi.rb 1: # 2: # Solves the classic Towers of Hanoi puzzle. 3: # 4: def hanoi(n, a, b, c) => 5: hanoi(n - 1, a, c, b) if n - 1 > 0 6: 7: puts "Move disk #{a} to #{b}" 8: 9: hanoi(n - 1, c, b, a) if n - 1 > 0 10: end (byebug) c Stopped by breakpoint 1 at /path/to/hanoi.rb:5 1: n = 1 2: a = :a [1, 10] in /path/to/hanoi.rb 1: # 2: # Solves the classic Towers of Hanoi puzzle. 3: # 4: def hanoi(n, a, b, c) => 5: hanoi(n - 1, a, c, b) if n - 1 > 0 6: 7: puts "Move disk #{a} to #{b}" 8: 9: hanoi(n - 1, c, b, a) if n - 1 > 0 10: end (byebug) set nofullpath fullpath is off (byebug) where --> #0 Object.hanoi(n#Fixnum, a#Symbol, b#Symbol, c#Symbol) at .../shortpath/to/hanoi.rb:5 #1 Object.hanoi(n#Fixnum, a#Symbol, b#Symbol, c#Symbol) at .../shortpath/to/hanoi.rb:5 #2 at .../Proyectos/byebug/hanoi.rb:28 (byebug) ``` -------------------------------- ### Get setting status string Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/setting.md Retrieve a string representation of the setting's current status. ```ruby setting.to_s # => String ``` ```ruby autosave = AutosaveSetting.new autosave.value = true autosave.to_s # => "autosave is on\n" ``` -------------------------------- ### context.line Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/context.md Gets the line number of the current frame. ```APIDOC ## context.line ### Description Returns the current line number in the source file for the current frame. ### Return Type Integer ``` -------------------------------- ### Retrieve command help Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/command.md Returns the prettified help description for the command. ```ruby command.help # => String ``` ```ruby puts step_cmd.help # Output: # s[tep][ times] # # Steps into blocks or methods one or more times ``` -------------------------------- ### Get formatted method call Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/frame.md Combines method name, class, and arguments into a display string. ```ruby frame.deco_call # => String ``` ```ruby puts frame.deco_call # => "User#create(user: #, admin: true)" ``` -------------------------------- ### Byebug.start_client(host, port) Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Connects to a remote byebug server. ```APIDOC ## Byebug.start_client(host, port) ### Description Connects to a remote byebug server and starts the client loop to read prompts and send commands. ### Parameters - **host** (String) - Optional - Remote host address (default: "localhost") - **port** (Integer) - Optional - Remote port number (default: 8989) ``` -------------------------------- ### Byebug.mode Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/byebug.md Gets or sets the current debugging mode. ```APIDOC ## Byebug.mode ### Description Gets or sets the current debugging mode (:attached, :standalone, or :off). ### Method Ruby Class Method ### Parameters - **mode** (Symbol) - Required - The mode to set: :attached, :standalone, or :off ``` -------------------------------- ### Initialize Remote Client Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Creates a new client instance using the provided interface for I/O. ```ruby Remote::Client.new(interface) ``` -------------------------------- ### Byebug::Runner.new Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/runner.md Initializes a new runner instance with optional configuration settings. ```APIDOC ## Byebug::Runner.new ### Description Initializes a new instance of the Byebug runner. Accepts optional configuration parameters to control debugger behavior. ### Parameters - **stop** (boolean) - Optional - If true, stops execution at the first line. - **quit** (boolean) - Optional - If true, quits the debugger after execution. ``` -------------------------------- ### Common Byebug command-line usage Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/configuration.md Examples of various command-line flags to modify debugger behavior during script execution. ```bash # Debug a script with debugging mode on byebug -d app.rb # Debug with custom $LOAD_PATH byebug -I /path/to/lib app.rb # Enable post-mortem debugging for exceptions byebug -m app.rb # Don't quit when script finishes (return to REPL) byebug --no-quit app.rb # Skip initialization files byebug --no-rc app.rb # Don't stop at first line (let it run until breakpoint) byebug --no-stop app.rb # Require library before script byebug -r bundler/setup app.rb # Connect to remote debugger byebug -R localhost:8989 app.rb # Enable line tracing byebug -t app.rb ``` -------------------------------- ### Get Client Socket Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Retrieves the underlying TCPSocket connection. ```ruby client.socket # => TCPSocket ``` -------------------------------- ### interface.prepare_input(prompt) Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/interface.md Reads and prepares a line of input, handling empty input by repeating the previous command. ```APIDOC ## interface.prepare_input(prompt) ### Description Calls readline and handles empty input by repeating the previous command. ### Parameters - **prompt** (String) - Required - Prompt to display ### Response - **Return** (String | nil) - Returns the prepared input string or nil. ``` -------------------------------- ### Byebug.wait_connection Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Gets or sets whether to wait for client connection. ```APIDOC ## Byebug.wait_connection ### Description Gets or sets the boolean flag determining if the server waits for a client connection before proceeding. ``` -------------------------------- ### Byebug.run_init_script Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/byebug.md Runs initialization scripts from rc files. ```APIDOC ## Byebug.run_init_script ### Description Searches for the init file in $HOME and current working directory, then executes any found files. ### Method Ruby Class Method ### Return Type nil ``` -------------------------------- ### Frame Information Hash Example Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/types.md Represents the structure returned by Frame#to_hash, containing metadata about the current execution frame. ```ruby { mark: "-->", pos: " 0", call: "User#create(user: #, admin: true)", file: "app/models/user.rb", line: 42, full_path: "/home/user/app/models/user.rb" } ``` -------------------------------- ### Byebug.actual_control_port Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Gets the actual port the control server is listening on. ```APIDOC ## Byebug.actual_control_port ### Description Returns the actual port the control server is listening on. ``` -------------------------------- ### Get location information with Ruby Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/context.md Retrieve formatted strings representing the current file and line, optionally including source code content. ```ruby context.location # => "app/controllers/users.rb:42" ``` ```ruby puts context.location # => "/home/user/app.rb:10" ``` ```ruby context.full_location # => "file.rb:10 puts 'hello'" ``` ```ruby puts context.full_location # => "/app.rb:10 x = 42" ``` -------------------------------- ### Connect Remote Client Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Connects the client to a remote debugger server. Includes a usage example for establishing a connection. ```ruby client.start(host = "localhost", port = PORT) ``` ```ruby client = Remote::Client.new(interface) client.start("192.168.1.100", 8989) ``` -------------------------------- ### Byebug.actual_port Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Gets the actual port the debug server is listening on. ```APIDOC ## Byebug.actual_port ### Description Returns the actual port the debug server is listening on, which is useful when port 0 is specified and the OS assigns a random port. ``` -------------------------------- ### Initialize a new Command instance Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/command.md Creates a new instance of a command, initializing it with a processor and the user input string. ```ruby Command.new(processor, input = self.class.to_s) ``` -------------------------------- ### Get Program Filename Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/runner.md Retrieve the path of the script being debugged. ```ruby runner.program # => String ``` ```ruby # Command: byebug app.rb runner.program # => "app.rb" # Command: byebug ruby app.rb runner.program # => "app.rb" ``` -------------------------------- ### Handle script execution errors Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/errors.md Examples of error messages displayed when running scripts with syntax errors, missing files, or missing arguments. ```bash $ byebug broken.rb *** The script has incorrect syntax ``` ```bash $ byebug nonexistent.rb *** The script doesn't exist ``` ```bash $ byebug *** You must specify a program to debug Usage: byebug [options] -- ``` -------------------------------- ### Navigate Thread Execution Source: https://github.com/deivid-rodriguez/byebug/blob/main/GUIDE.md Use step and next commands to trace execution within a specific thread. ```console (byebug) s [17, 26] in /path/to/company.rb 17: 18: # 19: # An employee doing his thing 20: # 21: def employee_routine => 22: loop do 23: if @tasks.empty? 24: have_a_break(0.1) 25: else 26: work_hard(@tasks.pop) (byebug) s [18, 27] in /path/to/company.rb 18: # 19: # An employee doing his thing 20: # 21: def employee_routine 22: loop do => 23: if @tasks.empty? 24: have_a_break(0.1) 25: else 26: work_hard(@tasks.pop) 27: end (byebug) n [21, 30] in /path/to/company.rb 21: def employee_routine 22: loop do 23: if @tasks.empty? 24: have_a_break(0.1) 25: else => 26: work_hard(@tasks.pop) 27: end 28: end 29: end 30: (byebug) s [49, 58] in /path/to/company.rb 49: def show_off(result) 50: puts result 51: end 52: 53: def work_hard(task) => 54: task ** task 55: end 56: 57: def have_a_break(amount) 58: sleep amount (byebug) s [21, 30] in /path/to/company.rb 21: # 22: # An employee doing his thing 23: # 24: def employee_routine 25: loop do => 26: if @tasks.empty? 27: have_a_break(0.1) 28: else 29: work_hard(@tasks.pop) 30: end (byebug) n [22, 31] in /path/to/company.rb 22: # An employee doing his thing 23: # 24: def employee_routine 25: loop do 26: if @tasks.empty? => 27: have_a_break(0.1) 28: else 29: work_hard(@tasks.pop) 30: end 31: end (byebug) n [21, 30] in /path/to/company.rb 21: # 22: # An employee doing his thing 23: # 24: def employee_routine 25: loop do => 26: if @tasks.empty? 27: have_a_break(0.1) 28: else 29: work_hard(@tasks.pop) 30: end 31: end (byebug) ``` -------------------------------- ### context.frame Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/context.md Gets or sets the current frame in the call stack. ```APIDOC ## context.frame ### Description Gets or sets the current frame in the call stack. Frame 0 is the current execution point, and higher numbers represent caller frames. ### Parameters - **pos** (Integer) - Optional - Frame position in stack (0 = current) ### Return Type Frame ``` -------------------------------- ### Debug thread initialization and listing Source: https://github.com/deivid-rodriguez/byebug/blob/main/GUIDE.md Initial Byebug session showing how to list threads after hitting a breakpoint. ```console [1, 10] in /path/to/company.rb => 1: class Company 2: def initialize(task) 3: @tasks, @results = Queue.new, Queue.new 4: 5: @tasks.push(task) 6: end 7: 8: def run 9: manager = Thread.new { manager_routine } 10: employee = Thread.new { employee_routine } (byebug) l [11, 20] in /path/to/company.rb 11: 12: sleep 6 13: 14: go_home(manager) 15: go_home(employee) 16: end 17: 18: # 19: # An employee doing his thing 20: # (byebug) c 12 Stopped by breakpoint 1 at /path/to/company.rb:12 [7, 16] in /path/to/company.rb 7: 8: def run 9: manager = Thread.new { manager_routine } 10: employee = Thread.new { employee_routine } 11: => 12: sleep 6 13: 14: go_home(manager) 15: go_home(employee) 16: end (byebug) th l + 1 # /path/to/company.rb:12 2 # 3 # ``` -------------------------------- ### Initialize a new setting Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/setting.md Creates a new setting instance using the subclass's default value. ```ruby Setting.new ``` -------------------------------- ### CommandProcessor.new Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/processor.md Initializes a new instance of the CommandProcessor to manage the debugging session. ```APIDOC ## CommandProcessor.new ### Description Creates a new command processor instance to handle the debugging loop and command dispatching. ### Signature `CommandProcessor.new(context, interface = LocalInterface.new)` ### Parameters - **context** (Context) - Required - The execution context for the debugger. - **interface** (Interface) - Optional - The user interface for I/O, defaults to LocalInterface.new. ### Return Type CommandProcessor ### Example ```ruby context = Byebug.current_context interface = LocalInterface.new processor = CommandProcessor.new(context, interface) ``` ``` -------------------------------- ### Execute Byebug with Configuration Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/configuration.md Command to launch the debugger while loading settings and breakpoints from the configuration file. ```bash byebug -x app.rb # Load all settings and breakpoints ``` -------------------------------- ### Get Client Interface Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Retrieves the interface object used by the client. ```ruby client.interface # => Interface ``` -------------------------------- ### Set Help Flag Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/runner.md Set the help flag to print usage information. ```ruby runner.help = "--help output" ``` ```ruby runner.help = runner.option_parser.help ``` -------------------------------- ### Entry Points Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/README.md Methods to initialize and control the debugger session. ```APIDOC ## byebug ### Description Starts the debugger at the current line of code. ### Usage `byebug` ## Byebug.attach ### Description Attaches the debugger programmatically. ### Usage `Byebug.attach` ## Byebug.spawn ### Description Starts a remote debugging server. ### Parameters - **host** (String) - Required - The host address. - **port** (Integer) - Required - The port number. ### Usage `Byebug.spawn("0.0.0.0", 8989)` ``` -------------------------------- ### context.full_location Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/context.md Gets current location with source code line content. ```APIDOC ## context.full_location ### Description Returns a string including the file path, line number, and the actual source code content on that line. ### Return Type String ``` -------------------------------- ### Remote::Server.new Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Initializes a new TCP server for remote debugging. ```APIDOC ## Remote::Server.new(wait_connection, &block) ### Description Initializes a new TCP server instance for remote debugging. ### Parameters - **wait_connection** (Boolean) - Required - Block until client connects - **block** (Proc) - Optional - Block called when client connects ``` -------------------------------- ### Context.ignored_files Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/context.md Gets or sets the list of files that byebug will skip during debugging. ```APIDOC ## Context.ignored_files ### Description Returns or sets the list of files that byebug will skip during debugging. ### Parameters - **files** (Array) - Optional - List of file paths to ignore ### Usage ```ruby Context.ignored_files # => Array Context.ignored_files = ["/path/to/file"] ``` ``` -------------------------------- ### Enabling line tracing and finishing execution Source: https://github.com/deivid-rodriguez/byebug/blob/main/GUIDE.md Configure line tracing and run until the current function returns. ```console (byebug) set linetrace linetrace is on (byebug) set basename basename is on (byebug) finish 0 Tracing: triangle.rb:7 0.upto(n) { |i| tri += i } 1: tri = 0 Tracing: triangle.rb:7 0.upto(n) { |i| tri += i } 1: tri = 0 Tracing: triangle.rb:7 0.upto(n) { |i| tri += i } 1: tri = 1 Tracing: triangle.rb:7 0.upto(n) { |i| tri += i } 1: tri = 3 Tracing: triangle.rb:9 tri 1: tri = 6 1: tri = 6 [4, 13] in /home/davidr/Proyectos/byebug/triangle.rb 4: def triangle(n) 5: tri = 0 6: 7: 0.upto(n) { |i| tri += i } 8: 9: tri => 10: end 11: 12: t = triangle(3) 13: puts t (byebug) quit Really quit? (y/n) y ``` -------------------------------- ### Remote Protocol Server Messages Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Examples of messages sent from the server to the client. ```text PROMPT (byebug) ``` ```text CONFIRM Delete breakpoint? [y/n] ``` ```text Stopped by breakpoint 1 at app.rb:42 ``` -------------------------------- ### Get Server Wait Connection Flag Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Retrieves the current wait_connection configuration. ```ruby server.wait_connection # => Boolean ``` -------------------------------- ### Display project file structure Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/INDEX.md Visual representation of the documentation directory layout. ```text output/ ├── README.md (Main overview and quick start) ├── INDEX.md (This file) ├── types.md (Data types reference) ├── configuration.md (Settings, CLI, .byebugrc) ├── errors.md (Error classes and conditions) ├── helpers-reference.md (Helper modules for extensions) └── api-reference/ (Detailed API docs per class) ├── byebug.md (Module entry points) ├── context.md (Execution context) ├── frame.md (Stack frame) ├── breakpoint.md (Breakpoint management) ├── command.md (Command base class) ├── interface.md (User I/O) ├── setting.md (Configuration) ├── processor.md (Command processing) ├── runner.md (CLI runner) ├── history.md (Command history) └── remote.md (Remote debugging) ``` -------------------------------- ### Get Server Port Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Retrieves the actual port assigned to the server instance. ```ruby server.actual_port # => Integer ``` -------------------------------- ### Initialize Remote Server Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/remote.md Creates a new TCP server instance for remote debugging. ```ruby Remote::Server.new(wait_connection:, &block) ``` -------------------------------- ### Explore command subcommands Source: https://github.com/deivid-rodriguez/byebug/blob/main/GUIDE.md Use the help command on a parent command to list its available subcommands. ```console (byebug) help info info[ subcommand] Generic command for showing things about the program being debugged. -- List of "info" subcommands: -- info args -- Argument variables of current stack frame info breakpoints -- Status of user-settable breakpoints info catch -- Exceptions that can be caught in the current stack frame info display -- Expressions to display when program stops info file -- Info about a particular file read in info files -- File names and timestamps of files read in info line -- Line number and filename of current position in source file info program -- Execution status of the program ``` -------------------------------- ### Get frame display mark Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/frame.md Returns a visual indicator for the frame type. ```ruby frame.mark # => String ``` ```ruby puts frame.mark + " " + frame.deco_call # => "--> User#create(user: #)" ``` -------------------------------- ### Get frame method arguments Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/frame.md Retrieves the method arguments as an array of pairs. ```ruby frame.args # => Array<[Symbol, Object]> ``` ```ruby frame.args # => [[:req, :user], [:opt, :admin], [:rest, :tags]] ``` -------------------------------- ### Runner.new Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/runner.md Creates a new instance of the Byebug::Runner. ```APIDOC ## Runner.new(stop = true, quit = true) ### Description Creates a new runner instance to manage the debugging session. ### Parameters - **stop** (Boolean) - Optional - Stop before executing the script (default: true) - **quit** (Boolean) - Optional - Exit when script finishes (default: true) ### Return Type Runner ``` -------------------------------- ### Get frame position Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/frame.md Retrieves the integer position of the frame in the call stack. ```ruby frame.pos # => Integer ``` -------------------------------- ### Configure Byebug settings Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/errors.md Demonstrates how setting assignments behave with incompatible types and how accessing non-existent settings returns nil. ```ruby Setting[:autosave] = "yes" # Coerced to truthy value Setting[:listsize] = "abc" # String stays, but errors on use ``` ```ruby Setting[:nonexistent] # => nil (doesn't raise) ``` -------------------------------- ### Display all Byebug commands Source: https://github.com/deivid-rodriguez/byebug/blob/main/GUIDE.md Use the help command without arguments to view a list of all available debugger commands. ```console (byebug) help break -- Sets breakpoints in the source code catch -- Handles exception catchpoints condition -- Sets conditions on breakpoints continue -- Runs until program ends, hits a breakpoint or reaches a line delete -- Deletes breakpoints disable -- Disables breakpoints or displays display -- Evaluates expressions every time the debugger stops down -- Moves to a lower frame in the stack trace edit -- Edits source files enable -- Enables breakpoints or displays finish -- Runs the program until frame returns frame -- Moves to a frame in the call stack help -- Helps you using byebug history -- Shows byebug's history of commands info -- Shows information about the program being debugged interrupt -- Interrupts the program irb -- Starts an IRB session kill -- Sends a signal to the current process list -- Lists lines of source code method -- Shows methods of an object, class or module next -- Runs one or more lines of code pry -- Starts a Pry session quit -- Exits byebug restart -- Restarts the debugged program save -- Saves current byebug session to a file set -- Modifies byebug settings show -- Shows byebug settings skip -- Runs until the next breakpoint as long as it is different from the current one source -- Restores a previously saved byebug session step -- Steps into blocks or methods one or more times thread -- Commands to manipulate threads tracevar -- Enables tracing of a global variable undisplay -- Stops displaying all or some expressions when program stops untracevar -- Stops tracing a global variable up -- Moves to a higher frame in the stack trace var -- Shows variables and its values where -- Displays the backtrace ``` -------------------------------- ### processor.interface Source: https://github.com/deivid-rodriguez/byebug/blob/main/_autodocs/api-reference/processor.md Retrieves the user interface instance. ```APIDOC ## processor.interface ### Description Gets the user interface. ### Return Type Interface (read-only) ```