I need help printing values in the VSCode debugger. I cannot print the actual value in the debugging window, how do I print the string representation of some variable?
Which debugger extension are you using?
println!() and dbg!() won't work no matter what debugger you use. Gdb only parses a subset of rust which doesn't include macros and lldb doesn't have any support for rust expressions at all. Instead you have to write C. Additionally neither debugger is capable of calling the debug impl of a type as DWARF debuginfo doesn't have a way to express trait methods and trait methods are only codegened when actually called anyway and a debugger can't compile additional rust functions. As such the only printing that can be done of values in a debugger is through the debuginfo and pretty printers, which ?other_exprs
and ?literal_exprs
should already do.
Which debugger extension are you using?
lldb from VSCode
As such the only printing that can be done of values in a debugger is through the debuginfo and pretty printers, which
?other_exprs
and?literal_exprs
should already do.
But this isn't very intuitive as I cannot see the actual content of the variable. Is there some other way to call the debug impl? Also, I cannot call any functions in the debugger and it just says syntax error.
You mean the CodeLLDB extension?
That is an LLDB issue.
You can define a #[no_mangle] extern "C"
function in your code which takes an &Vec<u8>
(or whichever type you want to print) and then formats it and writes this to a file. You should then be able to run this function from the debugger?
Did you try to call functions or methods? The later won't work as LLDB doesn't have builtin Rust support.
You might also want to try the Native Debug extension which also has GDB support. GDB has much better Rust support. For printing Vec's specifically you will need to tell it to load the Rust pretty printers. I don't have any experience with this extension myself, but try setting the gdbpath option to the absolute path of the rust-gdb script.