Skip to content

Commit 324097b

Browse files
committed
docs: copy and adapt more of Stan's usage guide docs
for now not including the C/C++ manual build docs and the tester docs, as they seem rr-backend specific
1 parent 38b3ac1 commit 324097b

File tree

7 files changed

+330
-2
lines changed

7 files changed

+330
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Run `ct --help` to see the full list of supported subcommands, but the most comm
134134
- `ct replay` - Opens a simple console-based dialog to choose what recording you want to replay.
135135
- `ct replay <program-name>` - Opens the last trace of an application.
136136
- `ct replay --id=<trace-id>` - Opens a trace by its trace id.
137-
- `ct replay --trace-folde=<trace-folder>` - Opens a trace by its trace folder.
137+
- `ct replay --trace-folder=<trace-folder>` - Opens a trace by its trace folder.
138138
1. `ct` - Launches the startup screen of the CodeTracer GUI.
139139
1. `ct help / ct --help` - Gives you a help message.
140140
1. `ct version` - Returns the current version of CodeTracer.

docs/experimental-documentation/mdbook-ct/src/SUMMARY.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44

55
# Usage guide
66

7-
- [Intro to usage guide](./usage_guide/intro_to_usage.md)
7+
- [Intro to usage guide](./usage_guide/intro_to_usage.md)
8+
- [CLI](./usage_guide/CLI.md)
9+
- [Basic GUI](./usage_guide/basic_gui.md)
10+
- [Tracepoints](./usage_guide/tracepoints.md)
11+
- [CodeTracer Shell](./usage_guide/codetracer_shell.md)
12+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## CLI
2+
3+
This page details some of the options, available to you through the `ct` CLI command.
4+
5+
### Usage
6+
7+
When you launch the CodeTracer GUI, it will offer you the option to also install the CodeTracer CLI. It provides convenient ways to create and load trace files from the command-line or to integrate CodeTracer with CI processes.
8+
9+
Run `ct --help` to see the full list of supported subcommands, but the most commonly used ones are the following:
10+
11+
`<application>` can be a source file or a project folder (depending on the language):
12+
13+
1. `ct run <application>` - Creates a recording and load it in CodeTracer with a single command.
14+
1. `ct record <application>` - Creates a trace file that can be loaded later or shared.
15+
1. `ct replay` - Launches the CodeTracer GUI with a previously recorded trace file. Common usages are:
16+
- `ct replay` - Opens a simple console-based dialog to choose what recording you want to replay.
17+
- `ct replay <program-name>` - Opens the last trace of an application.
18+
- `ct replay --id=<trace-id>` - Opens a trace by its trace id.
19+
- `ct replay --trace-folder=<trace-folder>` - Opens a trace by its trace folder.
20+
1. `ct` - Launches the startup screen of the CodeTracer GUI.
21+
1. `ct help / ct --help` - Gives you a help message.
22+
1. `ct version` - Returns the current version of CodeTracer.
23+
24+
Unlike other debuggers, where the debugger is attached to your application process, here you have to launch your application
25+
through the CodeTracer CLI with commands like `ct run` or `ct record`(or through the user interface, which is documented in the next chapter).
26+
27+
Think of debugging your application with CodeTracer as recording a video and then replaying it in order to find
28+
the information you need. This is why we use commands like `record` and `replay`.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# GUI
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Basic GUI
2+
3+
## Replay interface
4+
5+
Watch the video below to see a demonstration of some of the features of the CodeTracer replay GUI:
6+
7+
[![Video](https://img.youtube.com/vi/xZsJ55JVqmU/maxresdefault.jpg)](https://www.youtube.com/watch?v=xZsJ55JVqmU)
8+
9+
### Startup screen
10+
11+
You can open the startup screen with `ct`.
12+
13+
There you can see a list of the recent traces, and open them directly, or to open them from the filesystem
14+
using the `Open local trace` dialog. This is the graphical alternative to `ct replay`.
15+
16+
You can graphically record a new trace using the `Record new trace` dialog.
17+
This currently works only for noir projects: you should navigate to the root of the noir project folder, with the record dialog,
18+
select and press `Run`.
19+
If it is recorded correctly, it should open directly the replay interface.
20+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Codetracer Shell
2+
3+
> [!NOTE]
4+
> This feature is in its infancy, but in development. API may be subject to change!
5+
>
6+
> It's not a part of the public CodeTracer features or source code for now.
7+
8+
CodeTracer Shell is a special feature of CodeTracer that creates an environment, and optionally an interactive shell,
9+
that can be used to build applications with complex, or unorthodox build systems.
10+
11+
CodeTracer requires some additional compile flags and instrumentation functions to be built with your application.
12+
Because of this, CodeTracer only supports building from a single file. Support for multi-file projects using build systems
13+
is instead relegated to CodeTracer Shell.
14+
15+
When you execute commands in the CodeTracer Shell's interactive shell, or environment, CodeTracer Shell inserts itself into
16+
the subprocesses that are launched during the build process of your application, making building and running applications
17+
with more complex build systems easier.
18+
19+
For example, let's say you want to compile a C/C++ application using CMake. With CodeTracer Shell you can do either:
20+
```
21+
user $ ct shell
22+
(ct shell) user $ mkdir build && cd build
23+
(ct shell) user $ cmake ..
24+
(ct shell) user $ make
25+
```
26+
using the interactive shell, or the following using commands:
27+
```
28+
user $ ct shell -- bash -c "mkdir build && cd build && cmake .. && make"
29+
```
30+
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
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

Comments
 (0)