Skip to content

Commit

Permalink
Merge 0583033 into c39b914
Browse files Browse the repository at this point in the history
  • Loading branch information
jeluard authored May 16, 2024
2 parents c39b914 + 0583033 commit 50b2c80
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ validators
**/dist
**/.nyc_output
.tmp
.vscode
.npmrc
.vscode/launch.json
.vscode/settings.json
.vscode/tasks.json

# Tests artifacts
packages/*/spec-tests*
Expand Down
2 changes: 2 additions & 0 deletions .vscode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Adapt to your needs `launch.template.json` and copy as `launch.json`.
Follow `docs/pages/tools/debugging.md` for more details.
79 changes: 79 additions & 0 deletions .vscode/launch.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "Attach",
"port": 9229,
"request": "attach",
"skipFiles": [
"<node_internals>/**"
]
},
{
"type": "node",
"request": "launch",
"name": "Beacon",
"skipFiles": [
"<node_internals>/**"
],
"smartStep": true,
"program": "${workspaceFolder}/packages/cli/bin/lodestar.js",
"args": [
"beacon"
],
"console": "integratedTerminal"
},
{
"type": "node",
"request": "launch",
"name": "Dev",
"skipFiles": [
"<node_internals>/**"
],
"smartStep": true,
"program": "${workspaceFolder}/packages/cli/bin/lodestar.js",
"args": [
"dev"
],
"console": "integratedTerminal"
},
{
"name": "Test Current File",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/.bin/vitest",
"args": [
"--run",
"${file}",
"-t",
"${input:testName}",
"--pool",
"threads",
"--poolOptions.threads.singleThread"
],
"cwd": "${workspaceFolder}/${input:packageName}",
"console": "integratedTerminal",
"skipFiles": [
"<node_internals>/**"
]
}
],
"inputs": [
{
"id": "packageName",
"type": "command",
"command": "extension.commandvariable.transform",
"args": {
"text": "${relativeFileDirname}",
"find": "^(packages/[^/]+).*",
"replace": "$1"
}
},
{
"id": "testName",
"type": "promptString",
"description": "Enter the test name to run, leave empty to run all"
}
]
}
19 changes: 19 additions & 0 deletions docs/pages/tools/debugging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: Debugging
---

The simplest way to debug is to use the provided [launch.template.json](https://github.com/ChainSafe/lodestar/blob/unstable/.vscode/launch.template.json) `configurations`. Adapt and copy them as `.vscode/launch.json`, and they will be made available in the `Run and Debug` section. Note that users probably want to adapt the arguments of the beacon [configuration](https://github.com/ChainSafe/lodestar/blob/unstable/.vscode/launch.json#L11) to match their needs.
VS Code supports debugging Workers out of the box when using those configurations.

Remote `lodestar` processes can also be debugged by leveraging [node:inspector](https://nodejs.org/api/inspector.html). Adding `--inspect` to the node CLI (e.g. `NODE_OPTIONS=--inspect ./lodestar beacon`) allows to debug the main thread. To debug a specific `Worker`, follow those steps:

- remove `--inspect` from `node` CLI
- add following code to the `worker`

```js
import inspector from "node:inspector";
inspector.open();
inspector.waitForDebugger();
```

Use VS Code or Chrome devtools to debug those processes.
2 changes: 1 addition & 1 deletion docs/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "Tools",
items: ["tools/flamegraphs", "tools/heap-dumps", "tools/core-dumps"],
items: ["tools/debugging", "tools/flamegraphs", "tools/heap-dumps", "tools/core-dumps"],
},
{
type: "category",
Expand Down

0 comments on commit 50b2c80

Please sign in to comment.