Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Debugging: The Science of Deduction (2014)

Debugging: The Science of Deduction (2014)

As presented at Øredev 2014

Danielle Sucher

November 05, 2014
Tweet

More Decks by Danielle Sucher

Other Decks in Technology

Transcript

  1. "People write programs without any expectation that they will be

    right the first time." ! - David Lorge Parnas
  2. NO.

  3. /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/factory_girl-4.2.0/ lib/factory_girl/attribute_assigner.rb:14:in `tap'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/factory_girl-4.2.0/ lib/factory_girl/attribute_assigner.rb:14:in `object'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/factory_girl-4.2.0/ lib/factory_girl/evaluation.rb:12:in `object'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/factory_girl-4.2.0/

    lib/factory_girl/strategy/build.rb:9:in `result'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/factory_girl-4.2.0/ lib/factory_girl/factory.rb:42:in `run'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/factory_girl-4.2.0/ lib/factory_girl/factory_runner.rb:23:in `block in run'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/activesupport-4.0.1/ lib/active_support/notifications.rb:161:in `instrument'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/factory_girl-4.2.0/ lib/factory_girl/factory_runner.rb:22:in `run'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/factory_girl-4.2.0/ lib/factory_girl/strategy_syntax_method_registrar.rb:19:in `block in define_singular_strategy_method'! /Users/stan/projects/rails4/spec/models/project_spec.rb:21:in `block (4 levels) in <top (required)>'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/rspec-core-2.14.5/ lib/rspec/core/memoized_helpers.rb:199:in `block (2 levels) in let'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/rspec-core-2.14.5/ lib/rspec/core/memoized_helpers.rb:199:in `fetch'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/rspec-core-2.14.5/ lib/rspec/core/memoized_helpers.rb:199:in `block in let'!
  4. /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/factory_girl-4.2.0/ lib/factory_girl/attribute_assigner.rb:14:in `tap'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/factory_girl-4.2.0/ lib/factory_girl/attribute_assigner.rb:14:in `object'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/factory_girl-4.2.0/ lib/factory_girl/evaluation.rb:12:in `object'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/factory_girl-4.2.0/

    lib/factory_girl/strategy/build.rb:9:in `result'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/factory_girl-4.2.0/ lib/factory_girl/factory.rb:42:in `run'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/factory_girl-4.2.0/ lib/factory_girl/factory_runner.rb:23:in `block in run'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/activesupport-4.0.1/ lib/active_support/notifications.rb:161:in `instrument'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/factory_girl-4.2.0/ lib/factory_girl/factory_runner.rb:22:in `run'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/factory_girl-4.2.0/ lib/factory_girl/strategy_syntax_method_registrar.rb:19:in `block in define_singular_strategy_method'! /Users/stan/projects/rails4/spec/models/project_spec.rb:21:in `block (4 levels) in <top (required)>'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/rspec-core-2.14.5/ lib/rspec/core/memoized_helpers.rb:199:in `block (2 levels) in let'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/rspec-core-2.14.5/ lib/rspec/core/memoized_helpers.rb:199:in `fetch'! /Users/stan/.rvm/gems/ruby-1.9.3-p448@rails4/gems/rspec-core-2.14.5/ lib/rspec/core/memoized_helpers.rb:199:in `block in let'!
  5. look for the “Caused By” Exception in thread "main" java.lang.NoClassDefFoundError:

    org/apache/commons/logging/LogFactory at org.springframework.context.support.AbstractApplicationContext.<init>( AbstractApplicationContext.java:160) at org.springframework.context.support.AbstractRefreshableApplicationContext.<init>( AbstractRefreshableApplicationContext.java:89) at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.<init>( AbstractRefreshableConfigApplicationContext.java:59) at org.springframework.context.support.AbstractXmlApplicationContext.<init>( AbstractXmlApplicationContext.java:61) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>( ClassPathXmlApplicationContext.java:136) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>( ClassPathXmlApplicationContext.java:83) at com.springinaction.knights.KnightMain.main(KnightMain.java:12) Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ... 7 more
  6. look for the “Caused By” Exception in thread "main" java.lang.NoClassDefFoundError:

    org/apache/commons/logging/LogFactory at org.springframework.context.support.AbstractApplicationContext.<init>( AbstractApplicationContext.java:160) at org.springframework.context.support.AbstractRefreshableApplicationContext.<init>( AbstractRefreshableApplicationContext.java:89) at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.<init>( AbstractRefreshableConfigApplicationContext.java:59) at org.springframework.context.support.AbstractXmlApplicationContext.<init>( AbstractXmlApplicationContext.java:61) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>( ClassPathXmlApplicationContext.java:136) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>( ClassPathXmlApplicationContext.java:83) at com.springinaction.knights.KnightMain.main(KnightMain.java:12) Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ... 7 more
  7. Refactoring and adding tests ! (or even just fixing typos)

    ! keeps you focused and improves your understanding
  8. "...what are the facts, and what is the truth that

    the facts bear out?" ! - Bertrand Russell
  9. Wave your hands around in the air ! placing pieces

    of your system in imaginary 3d space
  10. “Without a debugger, you basically have to go to the

    next step; understand what the program does.” ! - Linus Torvalds
  11. “Ideas are tested by experiment. That is the core of

    science.” ! - Zombie Richard Feynman (via xkcd)
  12. Running git bisect manually $ git bisect start $ git

    bisect good SHA $ git bisect bad HEAD
  13. The person who wrote this code may have been an

    idiot. ! Or they may have been a mad genius.
  14. But what about lines that were just copied or moved?

    $ git blame -wCCC filename ! -w ignores whitespace -C detects moved/copied lines -CCC is like -C, but tries harder
  15. $ git log -p ! Includes patches, not just commit

    messages. ! You can search with /search_string
  16. $ git log -S “test string” ! Lists only commits

    where that string was added or deleted
  17. ls - list methods on an object cd - into

    objects wtf? - backtrace show-doc - prints docs show-method - prints source whereami - no really Pry
  18. If you don’t understand the cause of the problem, it’s

    not fixed, because you can’t predict when it might come up again.