Skip to content

Commit eeda2b1

Browse files
authored
Merge pull request lf-lang#217 from lf-lang/debugging
Added a page showing how to debug generated code
2 parents e406c8e + 5ce63a8 commit eeda2b1

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed
22.4 KB
Loading
62.4 KB
Loading
39.3 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: Debugging Generated Code
3+
description: Using VS Code to debug generated code.
4+
---
5+
6+
## Prerequisites
7+
8+
This page assumes you are using Visual Studio Code (VS Code).
9+
Lingua Franca files are compiled using CMake, so you should install Microsoft's
10+
[CMake Tools extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools).
11+
The instructions here will work with the C, Cpp, and CCpp targets.
12+
They may work with other targets as well, but will probably require additional VS Code extensions.
13+
14+
## Getting Started
15+
16+
When you run `lfc` to compile a Lingua Franca program, the generated code goes into a directory
17+
called `src-gen` that will be created next to the `src` directory that contains your `.lf` files
18+
(see [Structure of an LF project](<../writing-reactors/a-first-reactor.mdx#structure-of-an-lf-project>)).
19+
You can directly edit, compile, run, and debug the generated code using VS Code.
20+
To do this, start VS Code in the directory where the generated code is.
21+
For example, if your program is `src/Foo.lf`, the following steps will get you into the generated code:
22+
23+
```
24+
lfc src/Foo.lf
25+
cd src-gen/Foo
26+
code .
27+
```
28+
29+
The structure of the generated code depends on the target you are using, but in all cases, the project includes
30+
everything needed to build and run the code.
31+
You can use VS Code's convenient Search functionality to find your reaction bodies and set breakpoints.
32+
You can also modify the code directly and recompile it using CMake, but be careful to save any changes that you
33+
want to preserve somewhere else because the next time you run `lfc`, the `src-gen` directory will be overwritten.
34+
35+
## Running and Debugging Generated Code
36+
37+
First note that you have to ignore the built-in VS Code run and debug menu items, which are not designed to work with CMake.
38+
That is, ignore the following menu items:
39+
40+
![Wrong debug menu items](./../assets/images/debugging/wrong-debug.png)
41+
42+
If you have installed the CMake Tools extension, then you should see its icon in the left sidebar,
43+
as shown at the lower left here:
44+
45+
![CMake tools sidebar icon](./../assets/images/debugging/cmake-tools.png)
46+
47+
In the Configure menu, select the compiler to use.
48+
Above the selection is Clang for an Apple silicon Mac.
49+
Then, instead of using the menu items to build, run, and debug,
50+
use the buttons at the _bottom_ of the screen, which look like this:
51+
52+
![CMake tools build, run, and debug buttons](./../assets/images/debugging/cmake-debug.png)
53+
54+
The Build button will compile the code.
55+
To the right of that button are buttons for debugging and running the code.
56+
57+
## Debugging Federated Programs
58+
59+
For federated programs, the layout of the generated files is a bit different.
60+
If, for example, your federated program is in `src/Foo.lf` and it has a top-level reactor named `bar`,
61+
then you will find the generated code for the `bar` federate in `fed-gen/Foo/src-gen/federate__bar`.
62+
You can then run and debug that individual federate from within VS Code, but you will also have
63+
to manually run the RTI and the other federates in order for the code to start executing.

docs/sidebars.ts

+4
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ const sidebars: SidebarsConfig = {
212212
"type": "doc",
213213
"id": "developer/downloading-and-building"
214214
},
215+
{
216+
"type": "doc",
217+
"id": "developer/debugging-generated-code"
218+
},
215219
{
216220
"type": "doc",
217221
"id": "developer/regression-tests"

0 commit comments

Comments
 (0)