idbg-package: idbg

Description Details Author(s) See Also Examples

Description

An interactive R debugger

Details

Package: idbg
Type: Package
Version: 1.1
Date: 2012-01-16
License: GPL-2
LazyLoad: yes

Main features supported:

There are two ways to start the debugger:

The following debugger options are available:
h - help. print this message
n - next. Empty line is the same as 'n'
s - step into
o - step out
c - continue
q - quit
b - print breakpoints
b FALSE - clear all breakpoints
b <func_name> [FALSE] - set/unset a breakpoint at the first line of function
b <line_number> [FALSE] - set/unset a breakpoint at the current function
b <func_name> <line_number> [FALSE] - set/unset a breakpoint in func_name at line_number
w - print the stack
u - go up the stack
d - go down the stack
l [func_name] [nlines] - print nlines of source before and after current position
l [func_name] [nlines_back] [nlines_forward] - print source around current position
f string [func_name] - find string in function source
x expr - execute expression.
expr - Any expression that doesn't match the above options will also be executed

Author(s)

Ronen Kimchi

Maintainer: mitzpaz@gmail.com

See Also

idbg.run idbg.bp idbg.source

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 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
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
library(idbg)

bar <- function(a)
{
  bzz <- function(x)
  {
    cat("in bzz x =",x,"\n")
    return(x * 2)
  }
  
  if (a < 0)
    result <- bzz(-1)
  else
    result <- bzz(1)
  return(result)
}
foo <- function(x,y)
{
  tmp <- bar(x - y)
  return(tmp)
}  

idbg.run(foo(2,3))

## The debugger starts with displaying foo and the current location 
# function foo(x, y) 
#   0001 {
# =>0002     tmp <- bar(x - y)
#   0003     return(tmp)
#   0004 }

## Press 's' and enter at the debugger prompt to step into bar
# debug: s
# function bar(a) 
#   0001 {
# =>0002     bzz <- function(x) {
#   0003         cat("in bzz x =", x, "\n")
#   0004         return(x * 2)
#   0005     }
#   0006     if (a < 0) {
#   0007         result <- bzz(-1)
#   0008     }
#   0009     else {
#   0010         result <- bzz(1)
#   0011     }
#   0012     return(result)

## Examine the value of variable a
# debug: a
# [1] -1 
# 

## Place a breakpoint at row 6 and continue
# debug: b 6
# debug: c
# function bar(a) 
#   0001 {
#   0002     bzz <- function(x) {
#   0003         cat("in bzz x =", x, "\n")
#   0004         return(x * 2)
#   0005     }
# =>0006     if (a < 0) {
#   0007         result <- bzz(-1)
#   0008     }
#   0009     else {
#   0010         result <- bzz(1)
#   0011     }
#   0012     return(result)
#   0013 }

## Place a breakpoint in bzz and continue. This can only be done after bzz is defined
# debug: b bzz
# debug: c
# function bzz(x) 
#   0001 {
# =>0002     cat("in bzz x =", x, "\n")
#   0003     return(x * 2)
#   0004 }

## Press 'w' to print the call stack
# debug: w
#   1 foo  =>0002     tmp <- bar(x - y)
#   2 bar  =>0007         result <- bzz(-1)
# * 3 bzz  =>0002     cat("in bzz x =", x, "\n")

## Press 'u' to go up in the stack to bar
# debug: u

## Press 'l' to list the code
# debug: l
# function bar(a) 
#   0001 {
#   0002     bzz <- function(x) {
#   0003         cat("in bzz x =", x, "\n")
#   0004         return(x * 2)
#   0005     }
#   0006     if (a < 0) {
# =>0007         result <- bzz(-1)
#   0008     }
#   0009     else {
#   0010         result <- bzz(1)
#   0011     }
#   0012     return(result)
#   0013 }

## place a conditional breakpoint at row 12 of bar continue
# debug: b bar 12 result < 0

## print all breakpoints
# debug: b
#   function_name line  condition 
# 1           bar    6       TRUE 
# 2           bar   12 result < 0 
# 3           bzz    2       TRUE 
# 

## Continue running. We should stop at the conditional breakpoint
# debug: c
# in bzz x = -1 
#   0002     bzz <- function(x) {
#   0003         cat("in bzz x =", x, "\n")
#   0004         return(x * 2)
#   0005     }
#   0006     if (a < 0) {
#   0007         result <- bzz(-1)
#   0008     }
#   0009     else {
#   0010         result <- bzz(1)
#   0011     }
# =>0012     return(result)
#   0013 }
# debug: result
# [1] -2 
# 

## List the source code of foo
# debug: l foo
# function foo(x, y) 
#   0001 {
#   0002     tmp <- bar(x - y)
#   0003     return(tmp)
#   0004 }

## Press 'o' to step out of bar
# debug: o
# function foo(x, y) 
#   0001 {
#   0002     tmp <- bar(x - y)
# =>0003     return(tmp)
#   0004 }

## Print the values of x, y and x-y. Must use the 'x' command to avoid confusion with the x variable
# debug: x x
# [1] 2 
# 
# debug: x y
# [1] 3 
# 
# debug: x (x - y)
# [1] -1 
# 

## find the string cat in bar
# debug: f cat bar
# 0003         cat("in bzz x =", x, "\n") 

## Print the debugger help message
# debug: h
# h - help. print this message
# n - next. Empty line is the same as 'n'
# s - step into
# o - step out
# c - continue
# q - quit
# b - print breakpoints
# b FALSE - clear all breakpoints
# b <func_name> [FALSE] - set/unset a breakpoint at the first line of func_name
# b <line_number> [FALSE] - set/unset a breakpoint at the current function
# b <func_name> <line_number> [FALSE] - set/unset a breakpoint in func_name at line_number
# w - print the stack
# u - go up the stack
# d - go down the stack
# l [func_name] [nlines] - print nlines of source before and after current position
# l [func_name] [nlines_back] [nlines_forward] - print source around current position
# f string [func_name] - find string in function source
# x expr - execute expression.
# expr - Any expression that doesn't match the above options will also be executed

## Exit the debugger
# debug: q
# 

idbg documentation built on May 2, 2019, 6:51 p.m.