idbg.bp

Share:

Description

Prepare a function for debugging and set a breakpoint

Usage

1
idbg.bp(func_name, line_number = NA, condition = TRUE)

Arguments

func_name

name of function

line_number

line number where to set the breakpoint

condition

a condition to evaluate for conditional breakpoint

Value

Logical. TRUE if the breakpoint was set, FALSE if it wasn't

Author(s)

Ronen Kimchi

See Also

idbg.run 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
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)
}  

## Place a breakpoint in bar
idbg.bp(bar)

## Call foo 
foo(8,9)

## The debugger should stop at bar
# 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 }

## Press 'n' to go to the next statement
# debug: n
# 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 }

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

## Place conditional breakpoints in bzz. Only one of those should break
# debug: b bzz 2 x >= 0
# debug: b bzz 3 x < 0
# ## print all breakpoints
# debug: b
#   function_name line condition 
# 1           bar    2      TRUE 
# 2           bzz    2    x >= 0 
# 3           bzz    3     x < 0 
# 

## Continue running. We should stop only in line 3 of bzz
# debug: c
# in bzz x = -1 
# function bzz(x) 
#   0001 {
#   0002     cat("in bzz x =", x, "\n")
# =>0003     return(x * 2)
#   0004 }

## Print the value of x and check that x < 0
# debug: x x
# [1] -1 
# 

## Exit the debugger
# debug: q
# 

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.