txt: ## 01-debugging.md
  Debugging
  
  Modules and applications used to debug Raku programs
  
  # [Core debugging features](#Debugging "go to top of document")[§](#Core_debugging_features "direct link")
  
  ## [The `trace` pragma](#Debugging "go to top of document")[§](#The_trace_pragma "direct link")
  
  The `trace` pragma causes the program to print out step-by-step which lines get executed:
  
  ```raku
  use trace;
  sub foo { say "hi" }
  foo;
  # OUTPUT:
  # 2 (/tmp/script.raku line 2)
  # sub foo { say "hi" }
  # 5 (/tmp/script.raku line 3)
  # foo
  # 3 (/tmp/script.raku line 2)
  # say "hi"
  # hi
  ```
  
  # [Dumper function (`dd`)](#Debugging "go to top of document")[§](#Dumper_function_(dd) "direct link")
  
  [[1]](#fn1)
  
  The *Tiny Data Dumper*: This function takes the input list of variables and `note`s them (on `$*ERR`) in an easy to read format, along with the `name` of the variable. For example, this prints to the standard error stream the variables passed as arguments:
  
  ```raku
  my $a = 42;
  my %hash = "a" => 1, "b" => 2, "c" => 3;
  
  dd %hash, $a;
  #`( OUTPUT:
      Hash %hash = {:a(1), :b(2), :c(3)}
      Int $a = 42
  )
  
  ```
  
  Please note that `dd` will ignore named parameters. You can use a [`Capture`](/type/Capture) or [`Array`](/type/Array) to force it to dump everything passed to it.
  
  ```raku
  dd \((:a(1), :b(2)), :c(3));
  dd [(:a(1), :b(2)), :c(3)];
  
  ```
  
  If you don't specify any parameters at all, it will just print the type and name of the current subroutine / method to the standard error stream:
  
  ```raku
  sub a { dd }; a   # OUTPUT: «sub a()␤»
  
  ```
  
  This can be handy as a cheap trace function.
  
  ## [Using backtraces](#Debugging "go to top of document")[§](#Using_backtraces "direct link")
  
  The [`Backtrace`](/type/Backtrace) class gets the current call stack, and can return it as a string:
  
  ```raku
  my $trace = Backtrace.new;
  sub inner { say ~Backtrace.new; }
  sub outer { inner; }
  outer;
  
  # OUTPUT:
  # raku /tmp/script.raku
  #   in sub inner at /tmp/script.raku line 2
  #   in sub outer at /tmp/script.raku line 3
  #   in block <unit> at /tmp/script.raku line 4
  ```
  
  ## [Environment variables](#Debugging "go to top of document")[§](#Environment_variables "direct link")
  
  See [Raku Environment Variables](https://github.com/rakudo/rakudo/wiki/dev-env-vars) and [Running rakudo from the command line](https://github.com/rakudo/rakudo/wiki/Running-rakudo-from-the-command-line) for more information.
  
  # [Ecosystem debugging modules](#Debugging "go to top of document")[§](#Ecosystem_debugging_modules "direct link")
  
  There are at least two useful debuggers and two tracers available for Rakudo (the Raku compiler). For more information on these modules, please refer to their documentation.
  
  Historically other modules have existed and others are likely to be written in the future. Please check the [Raku Modules](https://raku.land/) website for more modules like these.
  
  ## [`Debugger::UI::CommandLine`](https://raku.land/github:jnthn/Debugger::UI::CommandLine)[§](#Debugger::UI::CommandLine "direct link")
  
  A command-line debugger frontend for Rakudo. This module installs the `raku-debug-m` command-line utility, and is bundled with the Rakudo Star distributions. Please check [its repository](https://github.com/jnthn/rakudo-debugger) for instructions and a tutorial.
  
  ## [`Grammar::Debugger`](https://raku.land/github:jnthn/Grammar::Debugger) (and `Grammar::Tracer` in the same distribution)[§](#Grammar::Debugger_(and_Grammar::Tracer_in_the_same_distribution) "direct link")
  
  Simple tracing and debugging support for Raku grammars.
  
  ## [`Trait::Traced`](https://raku.land/cpan:KAIEPI/Trait::Traced)[§](#Trait::Traced "direct link")
  
  This provides the `is traced` trait, which automatically traces usage of features of whatever the trait is applied to. What features of whatever the trace is applied to get traced and how traces are handled are customizable. Refer to its documentation for more information on how this works.
  
  1 [[↑]](#fnret1) This routine is a Rakudo-specific debugging feature and not standard Raku.
  