M
Modular•9mo ago
obadakhalili

Debugging Issue with Mojo's VSCode Debugger

I have a file ./foo/bar.mojo that imports a package in ./, so to run it I have to use the CLI path argument (-I) as follows: mojo build -I . ./foo/bar.mojo. The problem occurs when I try to debug the file with Mojo's VSCode debugger, getting the error message unable to locate module 'x', the same error message that throws if I try to run bar.mojo without the path argument, so it seems like the problem is that I have to specify the path argument for the debugger too. I tried to update the launch file configuration by setting the args property to "args": ["-I", "../"], which does show up in the final command but still doesn't work throwing the same error message.
29 Replies
artemiogr97
artemiogr97•9mo ago
I guess you need to add "." Instead of "..", normally in vscode relative paths are resolved from your working dir The offer option is to set the working dir to be "./foo"
obadakhalili
obadakhaliliOP•9mo ago
I have actually tried "." too but it didin't work. the other option, "./foo", didn't work as well there is the possibility that it isn't taking the -I argument in the first place, as this is a different binary with different CLI
artemiogr97
artemiogr97•9mo ago
yeah, I'm testing on my side, seems like the -I argument is being ignored
obadakhalili
obadakhaliliOP•9mo ago
actually, it shouldn't work. re-reading the docs, the args property defines the set of arguments passed to your Mojo program you are trying to debug https://docs.modular.com/mojo/tools/debugging#:~:text=Any%20command%2Dline%20arguments%20to%20be%20passed%20to%20the%20program
Debugging | Modular Docs
Debugging Mojo programs.
artemiogr97
artemiogr97•9mo ago
True, so I don't know it there is a way to add some path
obadakhalili
obadakhaliliOP•9mo ago
there must be because what I'm actually trying to do is debug one of Basalt's (https://github.com/basalt-org/basalt) examples. so I think it is safe to assume that its team found a way to do this
artemiogr97
artemiogr97•9mo ago
If you are using the nightly build I guess you can do what is mentioned here https://discord.com/channels/1087530497313357884/1226262582629892106 Basically you have the variable environment variable MODULAR_MOJO_NIGHTLY_IMPORT_PATH in which you can define all your import paths separated by a comma
ModularBot
ModularBot•9mo ago
Congrats @artemiogr97, you just advanced to level 2!
artemiogr97
artemiogr97•9mo ago
I guess there is an equivalent environment variable for the "stable" build
obadakhalili
obadakhaliliOP•9mo ago
hmm, there should be a more straightforward way ..
artemiogr97
artemiogr97•9mo ago
I guess so, let's wait for someone's answer 🙂
obadakhalili
obadakhaliliOP•9mo ago
sure. thanks for your time though
ModularBot
ModularBot•9mo ago
Congrats @obadakhalili, you just advanced to level 1!
Josiah
Josiah•9mo ago
Stumbled on here also. Kind of looking for a PYTHON_PATHS env var. I'm also trying to use basalt as a thirdparty package with vscode. The launch.json doesnt work for me either Its nice they have a package API to transport stuff, but since mojo is super young, and the packages are super new, being able to import them in "develop" mode would be valuable.
ModularBot
ModularBot•9mo ago
Congrats @jokellum, you just advanced to level 1!
Hylke
Hylke•4mo ago
I am actually having the same problem. I rely on the -I ./ argument to run mojo -I ./ module/my-file.mojo. I tried setting the variable in launch.json in vs code as suggested:
{
"configurations": [
{
...
"env": [
"MODULAR_MOJO_NIGHTLY_IMPORT_PATH=${workspaceFolder}/path/to/."
],
...
}
]
}
{
"configurations": [
{
...
"env": [
"MODULAR_MOJO_NIGHTLY_IMPORT_PATH=${workspaceFolder}/path/to/."
],
...
}
]
}
But without success, I didn't get the debugger to work. Incidentally, the environment variable trick also doesn't work manually directly from the command line:
export MODULAR_MOJO_NIGHTLY_IMPORT_PATH=/absolute/path/to/."
mojo module/my-file.mojo
export MODULAR_MOJO_NIGHTLY_IMPORT_PATH=/absolute/path/to/."
mojo module/my-file.mojo
Any thoughts?
Walter Erquinigo
Walter Erquinigo•4mo ago
Hi, I'm the debugger guy at modular and sorry for chiming it late. Have you tried doing the following in the nightly version:
mojo debug -I ... ./my/file.mojo
mojo debug -I ... ./my/file.mojo
You can also do
mojo debug --vscode -I ... ./my/file.mojo
mojo debug --vscode -I ... ./my/file.mojo
and that will launch the session on vscode @Hylke FYI In any case, tomorrow I'll work on a few changes that will make this easier to do
Hylke
Hylke•4mo ago
Thanks for getting in touch! I can confirm that the command line debugger:
mojo debug --vscode -I . './my/file.🔥'
mojo debug --vscode -I . './my/file.🔥'
indeed works. However, I wasn't able to get it to work with the --vscode flag:
$ mojo debug --vscode -I . './my/file.:fire:'
[INFO] Additional logs can be found in /tmp/mojo-debug-rpc-logs-7a3828.txt. Please include them when reporting bugs.

mojo: error: couldn't connect to any VSCode windows. You might need to restart the IDE or file a bug.
$ mojo debug --vscode -I . './my/file.:fire:'
[INFO] Additional logs can be found in /tmp/mojo-debug-rpc-logs-7a3828.txt. Please include them when reporting bugs.

mojo: error: couldn't connect to any VSCode windows. You might need to restart the IDE or file a bug.
Looking in the indicated log file, I find:
Error: can't connect to the RPC server with port 12355: Connection refused.
Error: can't connect to the RPC server with port 12355: Connection refused.
ModularBot
ModularBot•4mo ago
Congrats @Hylke, you just advanced to level 1!
Walter Erquinigo
Walter Erquinigo•4mo ago
@Hylke , could you share the Mojo Nightly logs from the VS Code Output tab? That might help us figure out what's going on
No description
Hylke
Hylke•4mo ago
Hi Walter, Thanks for your prompt response. I only have the tab Mojo; no Mojo (Nightly) tab like in your screenshot. At any rate, attached are the contents. Note that no additional output appears when I run mojo debug --vscode -I . './my/file.:fire:'
Walter Erquinigo
Walter Erquinigo•4mo ago
I see. That means that you are using the stable mojo extension. If you are using the nightly SDK, then you should juse the nightly extension from https://marketplace.visualstudio.com/items?itemName=modular-mojotools.vscode-mojo-nightly Every fix that we may do in the extension will be reflected in the nightly version. The stable version is updated probably every 3 months
Mojo 🔥 (nightly) - Visual Studio Marketplace
Extension for Visual Studio Code - Mojo language support (nightly)
Hylke
Hylke•4mo ago
Oh wow, that actually worked! The mojo debugger in vscode is pretty cool. 🤩 Thanks you so much for the pointers and keep up the good work!
Josiah
Josiah•4mo ago
@Hylke is this the current official way to run the Mojo debugger using VS code? Tried using the mojo docs, and it just doesn't work, I get a personality set error. Using the --vscode looks much simpler at least, and I'm on nightly so I'll try this out tried it, same issue
Josiah
Josiah•4mo ago
This is the issue I see using mojo debugger mojo --version mojo 2024.8.2916 (1e9c68e6)
No description
Josiah
Josiah•4mo ago
Stack Overflow
lldb error: Cannot launch a.out: personality set failed: Operation ...
The problem's description is the same to LLDB SBProcess stuck on launching Ubuntu 18.04. Whenever I Launch a target the process gets stuck in the launching state and will never launch. I've tried ...
Walter Erquinigo
Walter Erquinigo•4mo ago
If you have personality set failed, we can get await with a trick. If you want a solution that works in both VSCode and the terminal, you can create an .lldbinit file in your home directory (e.g. $USER/.lldbinit), and add this single line there
settings set target.disable-aslr false
settings set target.disable-aslr false
That should prevent LLDB from using the personality syscall that disables address space layout randomization, which ends up using the personality syscall. If that works, I'll probably add a --disable-aslr flag to mojo debug for convenience. The JSON debug config in VS Code already has a flag for this (disableASLR), although I really don't like writing .json configs. About this, I'm making a change that will appear in the nightly version that will make this easier:
[vscode] Add a way to set the build and run args for mojo files

The VS Code Mojo Debugger now has a buildArgs JSON debug configuration
setting that can be used in conjunction with mojoFile to define the build
arguments when compiling the Mojo file.

The VS Code extension now supports a Configure Build and Run Args command
that helps set the build and run args for actions file Run Mojo File and
Debug Mojo File. A corresponding button appears in Run and Debug selector
in the top right corner of a Mojo File.
END_PUBLIC
[vscode] Add a way to set the build and run args for mojo files

The VS Code Mojo Debugger now has a buildArgs JSON debug configuration
setting that can be used in conjunction with mojoFile to define the build
arguments when compiling the Mojo file.

The VS Code extension now supports a Configure Build and Run Args command
that helps set the build and run args for actions file Run Mojo File and
Debug Mojo File. A corresponding button appears in Run and Debug selector
in the top right corner of a Mojo File.
END_PUBLIC
Josiah
Josiah•4mo ago
@Walter Erquinigo I have cat /home/fastrl_mojo_user/.lldbinit settings set target.disable-aslr false I still get:
mojo debug --vscode -I . tests/samples/test_hello_world.mojo
[INFO] Additional logs can be found in /tmp/mojo-debug-rpc-logs-280557.txt. Please include them when reporting bugs.

Active VS Code windows:
0: [VSCode] test_hello_world.mojo
Last activity identified 5 seconds ago, pid=328, port=12355

Only one VS Code window was found. The debug session will be launched in this window automatically.

mojo: error: RPC Server response:
Error: Unable to start the debug session
mojo debug --vscode -I . tests/samples/test_hello_world.mojo
[INFO] Additional logs can be found in /tmp/mojo-debug-rpc-logs-280557.txt. Please include them when reporting bugs.

Active VS Code windows:
0: [VSCode] test_hello_world.mojo
Last activity identified 5 seconds ago, pid=328, port=12355

Only one VS Code window was found. The debug session will be launched in this window automatically.

mojo: error: RPC Server response:
Error: Unable to start the debug session
When I use mojo-lldb and do settings show I see target.disable-aslr (boolean) = false . Using mojo-lldb mojo looks like it kind of works, but it doesn't like it when I include -I . as part of settings set -- target.run-args "-I . tests/samples/test_hello_world.mojo". This is also sort of clunky even if it worked. Actually when I do mojo debug -I . tests/samples/test_hello_world.mojo and settings show, I also see this target.disable-aslr (boolean) = false If I do --vscode it shows the personality set error again, doesn't let me view settings show
Walter Erquinigo
Walter Erquinigo•4mo ago
I'll be OOO for one week. I can come back to help you after that 😦
Want results from more Discord servers?
Add your server