|
| 1 | +## What are tracepoints? |
| 2 | + |
| 3 | +Tracepoints are a type of breakpoint that allows you to run arbitrary code every time this breakpoint is hit. In most |
| 4 | +debuggers that support tracepoints they allow for efficient debugging of complex scenarios, like really deep recursion, |
| 5 | +or complex control flow. |
| 6 | + |
| 7 | +In CodeTracer, however, they can also unlock a number of strategies for additional debugging, specifically in the realm |
| 8 | +of hotspot debugging. |
| 9 | + |
| 10 | +## Tracepoints usage guide |
| 11 | + |
| 12 | +From the GUI: |
| 13 | + |
| 14 | +1. Right-click on a line |
| 15 | +1. Click on "Add tracepoint" |
| 16 | +1. The tracepoints popup should appear |
| 17 | +1. Write your tracepoint code in the text editor in the tracepoints popup |
| 18 | +1. Press "CTRL + Enter" to run the trace |
| 19 | +1. After running the trace, the output of your tracepoint will be listed in the tracepoint popup, and in the event log |
| 20 | + |
| 21 | +From the TUI: Coming soon! |
| 22 | + |
| 23 | +From the REPL: Coming soon! |
| 24 | + |
| 25 | +## Tracepoints language |
| 26 | + |
| 27 | +### Syntax |
| 28 | + |
| 29 | +The syntax of the language is similar to Noir/Rust (and therefore most C-like languages). However it doesn't use semicolons. |
| 30 | + |
| 31 | +In the future it is possible to add language-specific features or dialects of the tracepoint language. |
| 32 | + |
| 33 | +#### Literals |
| 34 | + |
| 35 | +Integer (`1`, `23`, `12`), Float (`1.23`, `.234`, `123.`), Bool (`true`, `false`) and String (`"some text"`) literals |
| 36 | +are supported. |
| 37 | + |
| 38 | +### `log()` |
| 39 | + |
| 40 | +The `log()` statement is used to evaluate the argument expression and add it as output from the current tracepoint. |
| 41 | +The `log()` statement suppors multiple values that are comma-separated: `log(v1, v2, v3)`. |
| 42 | + |
| 43 | +#### Example |
| 44 | + |
| 45 | +```rs |
| 46 | +fn test() { |
| 47 | + let mut sum = 0; |
| 48 | + |
| 49 | + for i in 0..3 { |
| 50 | + sum += i; |
| 51 | + -------------------------------------------------------------------------------- |
| 52 | + | log("I'm in the loop", i) |
| 53 | + | |
| 54 | + -------------------------------------------------------------------------------- |
| 55 | + // Output: |
| 56 | + -------------------------------------------------------------------------------- |
| 57 | + | "I'm in the loop" i=0 |
| 58 | + | "I'm in the loop" i=1 |
| 59 | + | "I'm in the loop" i=2 |
| 60 | + -------------------------------------------------------------------------------- |
| 61 | + } |
| 62 | +``` |
| 63 | + |
| 64 | + |
| 65 | +### Accessing variables |
| 66 | + |
| 67 | +The tracepoint for has access to all the variables, that are defined when the line on which the tracepoint is added is |
| 68 | +evaluated. You can reference them just by using their names in the expressions. |
| 69 | + |
| 70 | +#### Example |
| 71 | + |
| 72 | +```rs |
| 73 | +fn add(a: i32, b: i32) -> i32 { |
| 74 | + a + b |
| 75 | + -------------------------------------------------------------------------------- |
| 76 | + | log(a) |
| 77 | + | log(b) |
| 78 | + -------------------------------------------------------------------------------- |
| 79 | + // Output: |
| 80 | + -------------------------------------------------------------------------------- |
| 81 | + | a=3 b=5 |
| 82 | + -------------------------------------------------------------------------------- |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +### Comparison |
| 87 | + |
| 88 | +#### `==` and `!=` |
| 89 | + |
| 90 | +Two values are considered eqial iff their types are the same and their values are the same. **Exception** to this rule is |
| 91 | +comparing **Int** and **Float**, which are compared by their values, despite them being different type. |
| 92 | + |
| 93 | +#### `<`, `>`, `<=`, `>=` |
| 94 | + |
| 95 | +These operators work **only with numerical values** (e.g Int and Float). If at least one of the values is of non-numerical |
| 96 | +type, then an Error is raised. |
| 97 | + |
| 98 | +#### Example |
| 99 | + |
| 100 | +| Expression | Value | |
| 101 | +| ---------- | ----- | |
| 102 | +| 1 == 1 | true | |
| 103 | +| 1 != 1 | false | |
| 104 | +| 1 == 2 | false | |
| 105 | +| 1 != 2 | true | |
| 106 | +| "banana" == "banana" | true | |
| 107 | +| "banana" != "banana" | false | |
| 108 | +| "banana" == "apple" | false | |
| 109 | +| "banana" != "apple" | true | |
| 110 | +| "banana" == 1 | false | |
| 111 | +| "banana" != 1 | true | |
| 112 | +| | | |
| 113 | +| **1.0 == 1** | **true** | |
| 114 | +| **1.0 != 1** | **false** | |
| 115 | +| **2.0 == 1** | **false** | |
| 116 | +| **2.0 != 1** | **true** | |
| 117 | +| **"1" == 1** | **false** | |
| 118 | +| **"1" != 1** | **true** | |
| 119 | +| | | |
| 120 | +| 1 < 2 | true | |
| 121 | +| 1 <= 2 | true | |
| 122 | +| 1 > 2 | false | |
| 123 | +| 1 >= 2 | false | |
| 124 | +| 1 < 2.2 | true | |
| 125 | +| 1.1 <= 2 | true | |
| 126 | +| 1 > 2.2 | false | |
| 127 | +| 1.1 >= 2 | false | |
| 128 | +| | | |
| 129 | +| **1 < "2"** | **ERROR** | |
| 130 | +| **"0" < 1** | **ERROR** | |
| 131 | +| **"1" >= "2"** | **ERROR** | |
| 132 | + |
| 133 | + |
| 134 | +### Arithmetic operations |
| 135 | + |
| 136 | +The supported arithmetic operations are addition (`+`), subtraction (`-`), multiplication (`*`), division (`/`) and |
| 137 | +remainder (`%`). They work only with numerical types (Int and Float). |
| 138 | + |
| 139 | +When both arguments are Integer values, then the result is an Integer (for `/` the result is rounded toward 0). If at |
| 140 | +least one of the arguments is a Float, then the result is a Float. |
| 141 | + |
| 142 | +#### Example |
| 143 | +| Expression | Value | |
| 144 | +| ---------- | ----- | |
| 145 | +| 2 + 3 | 5 | |
| 146 | +| 2 + 3.0 | 5.0 | |
| 147 | +| 2.2 + 3.3 | 5.5 | |
| 148 | +| 2 - 3 | -1 | |
| 149 | +| 2 - 3.0 | -1.0 | |
| 150 | +| 2.2 - 3.3 | -1.1 | |
| 151 | +| 2 * 3 | 6 | |
| 152 | +| 2 * 3.0 | 6.0 | |
| 153 | +| 2.2 * 3.3 | 7.26 | |
| 154 | +| **7 / 3** | **2** | |
| 155 | +| 7 / 3.0 | 2.3333333 | |
| 156 | +| 7.7 / 3.3 | 2.3333333 | |
| 157 | +| 7 % 3 | 1 | |
| 158 | +| 7 % 3.0 | 1.0 | |
| 159 | +| 7.7 % 3.3 | 1.1 | |
| 160 | + |
| 161 | + |
| 162 | +### Conditional branching (`if`-`else`) |
| 163 | + |
| 164 | +The tracepoint language also supports conditional evaluation and branching. If the condition expression doesn't |
| 165 | +evaluate to a boolean value, then an error is raised. |
| 166 | + |
| 167 | +#### Example |
| 168 | + |
| 169 | +```rs |
| 170 | +fn test() { |
| 171 | + let mut sum = 0; |
| 172 | + |
| 173 | + for i in 0..4 { |
| 174 | + sum += i; |
| 175 | + -------------------------------------------------------------------------------- |
| 176 | + | log(i) |
| 177 | + | if i % 2 == 0 { |
| 178 | + | log("even") |
| 179 | + | } else if i % 3 == 0 { |
| 180 | + | log("div 3") |
| 181 | + | } else { |
| 182 | + | log("odd") |
| 183 | + | } |
| 184 | + -------------------------------------------------------------------------------- |
| 185 | + // Output: |
| 186 | + -------------------------------------------------------------------------------- |
| 187 | + | i=0 even |
| 188 | + | i=1 odd |
| 189 | + | i=2 even |
| 190 | + | i=3 div 3 |
| 191 | + -------------------------------------------------------------------------------- |
| 192 | + } |
| 193 | +} |
| 194 | +``` |
| 195 | + |
| 196 | +### Array indexing |
| 197 | + |
| 198 | +If a value is an array, you can index it using the `[]` operators. Indices are 0-based. |
| 199 | + |
| 200 | +#### Example |
| 201 | + |
| 202 | +```rs |
| 203 | +fn arr(a: i32, b: i32) -> i32 { |
| 204 | + let a = [1, 2, 3, 4, 5]; |
| 205 | + let b = a[2]; |
| 206 | + -------------------------------------------------------------------------------- |
| 207 | + | log(a) |
| 208 | + | log(a[0]) |
| 209 | + | log(a[1]) |
| 210 | + | log(a[4]) |
| 211 | + -------------------------------------------------------------------------------- |
| 212 | + // Output: |
| 213 | + -------------------------------------------------------------------------------- |
| 214 | + | a=[1, 2, 3, 4, 5] a[0]=1 a[1]=2 a[4]=5 |
| 215 | + -------------------------------------------------------------------------------- |
| 216 | +} |
| 217 | +``` |
| 218 | + |
| 219 | +### Errors |
| 220 | + |
| 221 | +When an error occurs, the evaluation of the tracepoint stops. |
| 222 | + |
| 223 | +#### Example |
| 224 | +```rs |
| 225 | +fn arr(a: i32, b: i32) -> i32 { |
| 226 | + let a = [1, 2, 3, 4, 5]; |
| 227 | + let b = a[2]; |
| 228 | + -------------------------------------------------------------------------------- |
| 229 | + | log(a[0]) |
| 230 | + | if a[1] { // This will cause error |
| 231 | + | log("banana") |
| 232 | + | } |
| 233 | + | log(a[2]) // This won't be evaluated |
| 234 | + -------------------------------------------------------------------------------- |
| 235 | + // Output: |
| 236 | + -------------------------------------------------------------------------------- |
| 237 | + | a[0]=1 Error=Non-boolean value on conditional jump |
| 238 | + -------------------------------------------------------------------------------- |
| 239 | +} |
| 240 | +``` |
| 241 | + |
| 242 | +### Rust-specific extensions |
| 243 | + |
| 244 | +We have some language-specific extensions in mind, but nothing concrete yet. |
0 commit comments