From 380ca6c3548b8a9f32bc90ea0ed62a5849cb8497 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Wed, 8 May 2024 01:28:40 +0200 Subject: [PATCH 01/12] docs: added debugging section --- .vscode/launch.json | 25 +++++++++++++++++++++++++ docs/pages/tools/debugging.md | 17 +++++++++++++++++ docs/sidebars.ts | 2 +- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000000..dd90d4bd80f9 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,25 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Beacon", + "skipFiles": ["/**"], + "smartStep": true, + "program": "${workspaceFolder}/packages/cli/bin/lodestar.js", + "args": ["beacon"], + "console": "integratedTerminal" + }, + { + "type": "node", + "request": "launch", + "name": "Dev", + "skipFiles": ["/**"], + "smartStep": true, + "program": "${workspaceFolder}/packages/cli/bin/lodestar.js", + "args": ["dev"], + "console": "integratedTerminal" + } + ] + } \ No newline at end of file diff --git a/docs/pages/tools/debugging.md b/docs/pages/tools/debugging.md index e69de29bb2d1..c4e90cf9d389 100644 --- a/docs/pages/tools/debugging.md +++ b/docs/pages/tools/debugging.md @@ -0,0 +1,17 @@ +--- +title: Debugging +--- + +The simplest way to debug is to use the provided [launch.json](../../../.vscode/launch.json) `configurations`, made available in the `Run and Debug` section. Those configurations will start new `node` processes. +VSCode 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(); +``` diff --git a/docs/sidebars.ts b/docs/sidebars.ts index 068325d946f1..c33dd65c3d0b 100644 --- a/docs/sidebars.ts +++ b/docs/sidebars.ts @@ -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", From e46675037e8f2e100d9ec25365f20ee0e712b277 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Wed, 8 May 2024 01:37:25 +0200 Subject: [PATCH 02/12] chore: spell checks --- docs/pages/tools/debugging.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/tools/debugging.md b/docs/pages/tools/debugging.md index c4e90cf9d389..0b53fa5f0bcf 100644 --- a/docs/pages/tools/debugging.md +++ b/docs/pages/tools/debugging.md @@ -3,7 +3,7 @@ title: Debugging --- The simplest way to debug is to use the provided [launch.json](../../../.vscode/launch.json) `configurations`, made available in the `Run and Debug` section. Those configurations will start new `node` processes. -VSCode supports debugging Workers out of the box when using those configurations. +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: From 2602805130c7d3ed3c2ec64aae1288ba4cc5e9e9 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Wed, 8 May 2024 11:43:08 +0200 Subject: [PATCH 03/12] chore: added extra docs --- docs/pages/tools/debugging.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/tools/debugging.md b/docs/pages/tools/debugging.md index 0b53fa5f0bcf..c9de4d9540d2 100644 --- a/docs/pages/tools/debugging.md +++ b/docs/pages/tools/debugging.md @@ -2,7 +2,7 @@ title: Debugging --- -The simplest way to debug is to use the provided [launch.json](../../../.vscode/launch.json) `configurations`, made available in the `Run and Debug` section. Those configurations will start new `node` processes. +The simplest way to debug is to use the provided [launch.json](https://github.com/ChainSafe/lodestar/blob/unstable/.vscode/launch.json) `configurations`, made available in the `Run and Debug` section. Those configurations will start new `node` processes. 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: From c377cdb5bd74cda5d527d4892444a61d3ab78132 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Thu, 9 May 2024 09:21:10 +0200 Subject: [PATCH 04/12] chore: address comments --- .vscode/README.md | 2 ++ .vscode/{launch.json => launch.template.json} | 0 2 files changed, 2 insertions(+) create mode 100644 .vscode/README.md rename .vscode/{launch.json => launch.template.json} (100%) diff --git a/.vscode/README.md b/.vscode/README.md new file mode 100644 index 000000000000..5ca0d2ca43be --- /dev/null +++ b/.vscode/README.md @@ -0,0 +1,2 @@ +Adapat to your needs `laucnh.template.json` and copy as `launch.json`. +Follow `docs/pages/tools/debugging.md` for more details. \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.template.json similarity index 100% rename from .vscode/launch.json rename to .vscode/launch.template.json From 9f46933b4660b62552ac12c0a6622e507bf619c3 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Thu, 9 May 2024 15:36:58 +0200 Subject: [PATCH 05/12] chore: added extra configuration --- .vscode/launch.template.json | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.vscode/launch.template.json b/.vscode/launch.template.json index dd90d4bd80f9..664d2023e647 100644 --- a/.vscode/launch.template.json +++ b/.vscode/launch.template.json @@ -20,6 +20,33 @@ "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}"], + "cwd": "${workspaceFolder}/${input:packageName}", + "console": "integratedTerminal", + "skipFiles": ["/**"] + } + ], + "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" } ] } \ No newline at end of file From bba30ded4b776fde6cca29a42cf46b18541ffda4 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Thu, 9 May 2024 15:37:24 +0200 Subject: [PATCH 06/12] chore: updated docs --- docs/pages/tools/debugging.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/pages/tools/debugging.md b/docs/pages/tools/debugging.md index c9de4d9540d2..751576327db4 100644 --- a/docs/pages/tools/debugging.md +++ b/docs/pages/tools/debugging.md @@ -2,7 +2,7 @@ title: Debugging --- -The simplest way to debug is to use the provided [launch.json](https://github.com/ChainSafe/lodestar/blob/unstable/.vscode/launch.json) `configurations`, made available in the `Run and Debug` section. Those configurations will start new `node` processes. 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. +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: @@ -15,3 +15,5 @@ import inspector from "node:inspector"; inspector.open(); inspector.waitForDebugger(); ``` + +Use VS Code or Chrome devtools to debug those processes. \ No newline at end of file From f9ca5b3a9fe677bd694d960dfe192efb2a758be0 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Fri, 10 May 2024 19:48:56 +0200 Subject: [PATCH 07/12] chore: added extra configuration --- .vscode/launch.template.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.vscode/launch.template.json b/.vscode/launch.template.json index 664d2023e647..3f844d449512 100644 --- a/.vscode/launch.template.json +++ b/.vscode/launch.template.json @@ -1,6 +1,13 @@ { "version": "0.2.0", "configurations": [ + { + "type": "node", + "name": "Attach", + "port": 9229, + "request": "attach", + "skipFiles": ["/**"] + }, { "type": "node", "request": "launch", From c16011634f835384d9202b9191f845b56303b11c Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Fri, 10 May 2024 21:41:39 +0200 Subject: [PATCH 08/12] chore: fix lint --- docs/pages/tools/debugging.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/tools/debugging.md b/docs/pages/tools/debugging.md index 751576327db4..ab884dd1b5e5 100644 --- a/docs/pages/tools/debugging.md +++ b/docs/pages/tools/debugging.md @@ -16,4 +16,4 @@ inspector.open(); inspector.waitForDebugger(); ``` -Use VS Code or Chrome devtools to debug those processes. \ No newline at end of file +Use VS Code or Chrome devtools to debug those processes. From b15ac9cc570960bc861857781594803f92b4215a Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Fri, 10 May 2024 22:01:38 +0200 Subject: [PATCH 09/12] chore: fix typos --- .vscode/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/README.md b/.vscode/README.md index 5ca0d2ca43be..0e7781ad11b1 100644 --- a/.vscode/README.md +++ b/.vscode/README.md @@ -1,2 +1,2 @@ -Adapat to your needs `laucnh.template.json` and copy as `launch.json`. -Follow `docs/pages/tools/debugging.md` for more details. \ No newline at end of file +Adapt to your needs `launch.template.json` and copy as `launch.json`. +Follow `docs/pages/tools/debugging.md` for more details. From 68b4875943f5e9f02afad0506469acd80ef9d184 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Fri, 10 May 2024 23:23:21 +0200 Subject: [PATCH 10/12] chore: .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 775f46f6f235..2b80cec97416 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,6 @@ validators **/dist **/.nyc_output .tmp -.vscode .npmrc # Tests artifacts From e507beae1270afb65bc5e22721f2c2fd74fb1210 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Sat, 11 May 2024 09:49:16 +0200 Subject: [PATCH 11/12] chore: address comments --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 2b80cec97416..a6d12b02445b 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,9 @@ validators **/.nyc_output .tmp .npmrc +.vscode/launch.json +.vscode/settings.json +.vscode/tasks.json # Tests artifacts packages/*/spec-tests* From 058303325218f57053a9db007b120197420a1ef2 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Thu, 16 May 2024 14:58:03 +0300 Subject: [PATCH 12/12] chore: address comments --- .vscode/launch.template.json | 134 ++++++++++++++++++++--------------- 1 file changed, 77 insertions(+), 57 deletions(-) diff --git a/.vscode/launch.template.json b/.vscode/launch.template.json index 3f844d449512..7f8c7a70484c 100644 --- a/.vscode/launch.template.json +++ b/.vscode/launch.template.json @@ -1,59 +1,79 @@ { - "version": "0.2.0", - "configurations": [ - { - "type": "node", - "name": "Attach", - "port": 9229, - "request": "attach", - "skipFiles": ["/**"] - }, - { - "type": "node", - "request": "launch", - "name": "Beacon", - "skipFiles": ["/**"], - "smartStep": true, - "program": "${workspaceFolder}/packages/cli/bin/lodestar.js", - "args": ["beacon"], - "console": "integratedTerminal" - }, - { - "type": "node", - "request": "launch", - "name": "Dev", - "skipFiles": ["/**"], - "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}"], - "cwd": "${workspaceFolder}/${input:packageName}", - "console": "integratedTerminal", - "skipFiles": ["/**"] + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "name": "Attach", + "port": 9229, + "request": "attach", + "skipFiles": [ + "/**" + ] + }, + { + "type": "node", + "request": "launch", + "name": "Beacon", + "skipFiles": [ + "/**" + ], + "smartStep": true, + "program": "${workspaceFolder}/packages/cli/bin/lodestar.js", + "args": [ + "beacon" + ], + "console": "integratedTerminal" + }, + { + "type": "node", + "request": "launch", + "name": "Dev", + "skipFiles": [ + "/**" + ], + "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": [ + "/**" + ] + } + ], + "inputs": [ + { + "id": "packageName", + "type": "command", + "command": "extension.commandvariable.transform", + "args": { + "text": "${relativeFileDirname}", + "find": "^(packages/[^/]+).*", + "replace": "$1" } - ], - "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" - } - ] - } \ No newline at end of file + }, + { + "id": "testName", + "type": "promptString", + "description": "Enter the test name to run, leave empty to run all" + } + ] +} \ No newline at end of file