2012-12-27 30 views
1

我在Emacs中編寫Ruby,但我的Emacs技能其實很低。我可以做的是使用M-x rinari-test打開項目,TDD,或者使用M-x run-ruby在第二個窗口中播放劣質的Ruby。現在我想開始使用StdLib中的調試器。我能夠從IRB召喚它說:如何在Emacs中使用Ruby調試器?

require 'debug' 

當我進入一個提示

(rdb:1) 

但我的性向結束。我甚至不知道如何進入文件。打字'幫助'帶來了一個屏幕截圖,但它並沒有幫助我最終開始調試我的馬車寶石。在線上,每個人都會寫關於諸如「rdebug」或「ruby-debug」之類的東西,或者我首先不想使用的東西,其次,作爲一個麻瓜,我無法安裝到我的Debian上。請幫忙!!!

回答

2

您確實需要嘗試在調試器中讀取help的輸出。它很好地解釋了這些命令。

例如,對於實踐中,嘗試此命令行,不是一個編輯/ IDE中:

ruby -rdebug -e 'p 1' 
h 

Ruby的調試器將輸出幫助摘要:

Debugger help v.-0.002b 
Commands 
    b[reak] [file:|class:]<line|method> 
    b[reak] [class.]<line|method> 
          set breakpoint to some position 
    wat[ch] <expression>  set watchpoint to some expression 
    cat[ch] (<exception>|off) set catchpoint to an exception 
    b[reak]     list breakpoints 
    cat[ch]     show catchpoint 
    del[ete][ nnn]    delete some or all breakpoints 
    disp[lay] <expression>  add expression into display expression list 
    undisp[lay][ nnn]   delete one particular or all display expressions 
    c[ont]      run until program ends or hit breakpoint 
    s[tep][ nnn]    step (into methods) one line or till line nnn 
    n[ext][ nnn]    go over one line or till line nnn 
    w[here]     display frames 
    f[rame]     alias for where 
    l[ist][ (-|nn-mm)]   list program, - lists backwards 
          nn-mm lists given lines 
    up[ nn]     move to higher frame 
    down[ nn]     move to lower frame 
    fin[ish]     return to outer frame 
    tr[ace] (on|off)   set trace mode of current thread 
    tr[ace] (on|off) all  set trace mode of all threads 
    q[uit]      exit from debugger 
    v[ar] g[lobal]    show global variables 
    v[ar] l[ocal]    show local variables 
    v[ar] i[nstance] <object> show instance variables of object 
    v[ar] c[onst] <object>  show constants of object 
    m[ethod] i[nstance] <obj> show methods of object 
    m[ethod] <class|module> show instance methods of class or module 
    th[read] l[ist]   list all threads 
    th[read] c[ur[rent]]  show current thread 
    th[read] [sw[itch]] <nnn> switch thread context to nnn 
    th[read] stop <nnn>  stop thread nnn 
    th[read] resume <nnn>  resume thread nnn 
    p expression    evaluate expression and print its value 
    h[elp]      print this help 
    <everything else>   evaluate 

的重要命令首先是s,n,cbq

  • s steps into a method。
  • n通過一個方法的步驟。
  • c number運行(繼續),直到您到達行number
  • b number在行number上設置斷點。設置斷點後,使用c繼續運行,直到執行該行。
  • q退出調試器。

我個人使用的是debugger寶石。其他人使用PRY,這與IRB類似,但具有類似調試器的擴展。

瞭解如何使用調試器是一項很好的技能。有些問題可以使用調試器快速追蹤,因爲您可以交互式地查看變量包含的內容,或者有條件地循環直到變量包含特定值,因此嘗試使用puts語句需要更長的時間。

+0

太好了。我能夠重複你建議的步驟。現在這是我的問題:在同一個目錄下,有一個包含我的bug程序的文件'sy.rb'。我如何進入第一線? –

+0

明白了。讓我自己去。 –