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
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"
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 CLIyeah, I'm testing on my side, seems like the -I argument is being ignored
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%20programDebugging | Modular Docs
Debugging Mojo programs.
True, so I don't know it there is a way to add some path
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
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 commaCongrats @artemiogr97, you just advanced to level 2!
I guess there is an equivalent environment variable for the "stable" build
hmm, there should be a more straightforward way ..
I guess so, let's wait for someone's answer 🙂
sure. thanks for your time though
Congrats @obadakhalili, you just advanced to level 1!
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.
Congrats @jokellum, you just advanced to level 1!
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:
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:
Any thoughts?Hi, I'm the debugger guy at modular and sorry for chiming it late.
Have you tried doing the following in the nightly version:
You can also do
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
Thanks for getting in touch!
I can confirm that the command line debugger:
indeed works. However, I wasn't able to get it to work with the
--vscode
flag:
Looking in the indicated log file, I find:
Congrats @Hylke, you just advanced to level 1!
@Hylke , could you share the
Mojo Nightly
logs from the VS Code Output tab? That might help us figure out what's going onHi 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:'
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)
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!
@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
This is the issue I see using mojo debugger
mojo --version
mojo 2024.8.2916 (1e9c68e6)
https://stackoverflow.com/questions/76939386/lldb-error-cannot-launch-a-out-personality-set-failed-operation-not-permitted im using this in docker though so this might be relatvant
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 ...
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
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:
@Walter Erquinigo
I have
cat /home/fastrl_mojo_user/.lldbinit
settings set target.disable-aslr false
I still get:
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
I'll be OOO for one week. I can come back to help you after that 😦