vadimcn / codelldb

A native debugger extension for VSCode based on LLDB
https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb
MIT License
2.43k stars 237 forks source link

Error: Could not parse JSON: "function breakdown:" at Interface.<anonymous> (/root/.vscode-server/extensions/vadimcn.vscode-lldb-1.9.2/extension.js:1:16886) #966

Closed SheldonHH closed 11 months ago

SheldonHH commented 1 year ago

OS: 5.19.0-46-generic VSCode version: Version: 1.80.0 CodeLLDB version: v1.9.2 Compiler: rustc 1.49.0-nightly (e160e5cb8 2020-10-14) Debuggee: Rust file

Reference: https://zenodo.org/record/7871547 I try to debug and create breakpoints for this command.

cargo run --release --bin unsafe-counter --  /root/lab/laertes/rewrite-workspace/bzip2/rust/c2rust-lib.rs

I can execute this function successfully and able to debugging and create breakpoints in CLion + IntelliJ Rust Plugin. But errors occur in Vscode with CodeLLDB

```bash Error: Cargo invocation failed. at t.Cargo.getCargoArtifacts (/root/.vscode-server/extensions/vadimcn.vscode-lldb-1.9.2/extension.js:1:15317) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async Object.open (/root/.vscode-server/extensions/vadimcn.vscode-lldb-1.9.2/extension.js:1:13627) Caused by: Error: Could not parse JSON: "function breakdown:" at Interface. (/root/.vscode-server/extensions/vadimcn.vscode-lldb-1.9.2/extension.js:1:16886) at Interface.emit (node:events:513:28) at Interface._onLine (node:readline:491:10) at Interface._normalWrite (node:readline:665:12) at Socket.ondata (node:readline:272:10) at Socket.emit (node:events:513:28) at addChunk (node:internal/streams/readable:315:12) at readableAddChunk (node:internal/streams/readable:289:9) at Socket.Readable.push (node:internal/streams/readable:228:10) at Pipe.onStreamRead (node:internal/stream_base_commons:190:23) Caused by: SyntaxError: Unexpected token u in JSON at position 1 at JSON.parse () at Interface. (/root/.vscode-server/extensions/vadimcn.vscode-lldb-1.9.2/extension.js:1:16865) ``` Verbose log
      

```bash
Initial debug configuration: {
  sourceLanguages: [ 'rust' ],
  type: 'lldb',
  request: 'launch',
  name: 'Launch unsafe-counter',
  'lldb.verboseLogging': true,
  cargo: {
    args: [
      'run',
      '--release',
      '--bin',
      'unsafe-counter',
      '--',
      '/root/lab/laertes/rewrite-workspace/bzip2/rust/c2rust-lib.rs'
    ],
    filter: { name: 'unsafe-counter', kind: 'bin' }
  },
  cwd: '/root/lab/unsafe-counter',
  __configurationTarget: 6
}
Error: Cargo invocation failed.
    at t.Cargo.getCargoArtifacts (/root/.vscode-server/extensions/vadimcn.vscode-lldb-1.9.2/extension.js:1:15317)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.open (/root/.vscode-server/extensions/vadimcn.vscode-lldb-1.9.2/extension.js:1:13627)
Caused by: Error: Could not parse JSON: "function breakdown:"
    at Interface. (/root/.vscode-server/extensions/vadimcn.vscode-lldb-1.9.2/extension.js:1:16886)
    at Interface.emit (node:events:513:28)
    at Interface._onLine (node:readline:491:10)
    at Interface._normalWrite (node:readline:665:12)
    at Socket.ondata (node:readline:272:10)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
Caused by: SyntaxError: Unexpected token u in JSON at position 1
    at JSON.parse ()
    at Interface. (/root/.vscode-server/extensions/vadimcn.vscode-lldb-1.9.2/extension.js:1:16865)
    at Interface.emit (node:events:513:28)
    at Interface._onLine (node:readline:491:10)
    at Interface._normalWrite (node:readline:665:12)
    at Socket.ondata (node:readline:272:10)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23
```

launch.json

{
    "version": "0.2.0",
    "configurations": [
      {
        "sourceLanguages": ["rust"],
        "type": "lldb",
        "request": "launch",
        "name": "Launch unsafe-counter",
        "cargo": {
          "args": [
            "run",
            "--release",
            "--bin",
            "unsafe-counter",
            "--",
            "/root/lab/laertes/rewrite-workspace/bzip2/rust/c2rust-lib.rs"
          ],
          "filter": {
            "name": "unsafe-counter",
            "kind": "bin"
          }
        },
        "cwd": "/root/lab/unsafe-counter"
      }
    ]
}
vadimcn commented 1 year ago

You are not supposed to run the binary with cargo, just to build it.

SheldonHH commented 1 year ago

sorry for missing leading, the debuggee is actually a Rust file under --bin folder, NOT binary file. I have edited the issue.

I didn't create the command on my own, it's actually the code and commands from Top Software Engineering Research Conference 2021 ACM on Programming Languages OOPLSA accepted article: Translating C to safer Rust

Cargo.toml under unsafe-counter folder

[package]
name = "laertes"
version = "0.1.0"
authors = ["Mehmet Emre <maemre2@gmail.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
# default features
default = ["profiling", "equality_solver"]
# profile certain operations
profiling = []
# use standard library hash instead of ahash
std_hash = []
# use equality-based reasoning instead of subset-based reasoning
equality_solver = []

# Enable debug symbols on release builds
[profile.release]
debug = 2
incremental = true  # enable incremental compilation but keep the codegen-units as the default value to still get a fast program in the end

[dependencies]
rustc_tools_util = "0.2.0"
colored = "2.0.0"
rustfix = "0.5.1"
itertools = "0.9.0"
log = "0.4"
string_cache = "0.8"
lazy_static = "1.4"
env_logger = "0.8"
ahash = "0.7.2"
clap = "2.33.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
regex = "1.5"
vadimcn commented 1 year ago

Your launch config should be something like this:

{
    "version": "0.2.0",
    "configurations": [
      {
        "sourceLanguages": ["rust"],
        "type": "lldb",
        "request": "launch",
        "name": "Launch unsafe-counter",
        "cargo": {
          "args": [ "build", "--bin", "unsafe-counter"],
          "filter": {
            "name": "unsafe-counter",
            "kind": "bin"
          }
        },
        "args": ["/root/lab/laertes/rewrite-workspace/bzip2/rust/c2rust-lib.rs"],
        "cwd": "/root/lab/unsafe-counter"
      }
    ]
}