首页 > 解决方案 > Why does debugging with lldb in VSCode garble chinese characters?

问题描述

I dabbled with Rust today and when I tried to print text with chinese characters using println! it renders weird characters to the VSCode debug terminal.

I thought the problem would go away after installing language pack, but no such luck. Perhaps additional configuration is needed. It seems a quirk from the VSCode side; I ran cargo run from a normal powershell terminal and it works fine.

garbled text

main.rs

fn main() -> Result<(), Box<dyn Error>> {
    println!("Test : {}", "阿拉有一只猫。&quot;);

    Ok(())
}

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug",
            "cargo": {
                "args": [
                    "build",
                    "--bin=test-app",
                    "--package=test-app"
                ],
                "filter": {
                    "name": "test-app",
                    "kind": "bin"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}"
        },
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug unit tests",
            "cargo": {
                "args": [
                    "test",
                    "--no-run",
                    "--bin=test-app",
                    "--package=test-app"
                ],
                "filter": {
                    "name": "test-app",
                    "kind": "bin"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}"
        }
    ]
}

标签: visual-studio-coderustlldbvscode-debugger

解决方案


正如@kmdreko指出的那样,该错误存在 github 问题

Beta: Use Unicode UTF-8 for worldwide language support 我尝试了在区域设置中启用选项的错误中提到的解决方法 ,问题就消失了。

当然,这不是最好的解决方案。

如果您不想为该设置翻遍整个控制面板:

  • control.exe international
  • Administrative标签
  • Change system locale按钮

区域设置


推荐阅读