From d8406230a16291a7adbac406bd1e215c531a7f12 Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Sat, 5 Jul 2025 18:20:46 -0400 Subject: [PATCH] gdb --- crates/dap_adapters/schemas/GDB.json | 88 ++++++++++++++++++++++++++ crates/dap_adapters/src/gdb.rs | 95 ++-------------------------- 2 files changed, 94 insertions(+), 89 deletions(-) create mode 100644 crates/dap_adapters/schemas/GDB.json diff --git a/crates/dap_adapters/schemas/GDB.json b/crates/dap_adapters/schemas/GDB.json new file mode 100644 index 0000000000000000000000000000000000000000..c171e78bb60a742a203d99e828828939e987e3d9 --- /dev/null +++ b/crates/dap_adapters/schemas/GDB.json @@ -0,0 +1,88 @@ +{ + "oneOf": [ + { + "allOf": [ + { + "type": "object", + "required": ["request"], + "properties": { + "request": { + "type": "string", + "enum": ["launch"], + "description": "Request to launch a new process" + } + } + }, + { + "type": "object", + "properties": { + "program": { + "type": "string", + "description": "The program to debug. This corresponds to the GDB 'file' command." + }, + "args": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Command line arguments passed to the program. These strings are provided as command-line arguments to the inferior.", + "default": [] + }, + "cwd": { + "type": "string", + "description": "Working directory for the debugged program. GDB will change its working directory to this directory." + }, + "env": { + "type": "object", + "description": "Environment variables for the debugged program. Each key is the name of an environment variable; each value is the value of that variable." + }, + "stopAtBeginningOfMainSubprogram": { + "type": "boolean", + "description": "When true, GDB will set a temporary breakpoint at the program's main procedure, like the 'start' command.", + "default": false + }, + "stopOnEntry": { + "type": "boolean", + "description": "When true, GDB will set a temporary breakpoint at the program's first instruction, like the 'starti' command.", + "default": false + } + }, + "required": ["program"] + } + ] + }, + { + "allOf": [ + { + "type": "object", + "required": ["request"], + "properties": { + "request": { + "type": "string", + "enum": ["attach"], + "description": "Request to attach to an existing process" + } + } + }, + { + "type": "object", + "properties": { + "pid": { + "type": "number", + "description": "The process ID to which GDB should attach." + }, + "program": { + "type": "string", + "description": "The program to debug (optional). This corresponds to the GDB 'file' command. In many cases, GDB can determine which program is running automatically." + }, + "target": { + "type": "string", + "description": "The target to which GDB should connect. This is passed to the 'target remote' command." + } + }, + "required": ["pid"] + } + ] + } + ] +} diff --git a/crates/dap_adapters/src/gdb.rs b/crates/dap_adapters/src/gdb.rs index a78084dd319264866fe24ce8e1fef109c1e49389..b3a2f6c30c60e3a871a2a12f815dc69016089f73 100644 --- a/crates/dap_adapters/src/gdb.rs +++ b/crates/dap_adapters/src/gdb.rs @@ -1,4 +1,4 @@ -use std::{borrow::Cow, collections::HashMap, ffi::OsStr}; +use std::{borrow::Cow, collections::HashMap, ffi::OsStr, sync::LazyLock}; use anyhow::{Context as _, Result, bail}; use async_trait::async_trait; @@ -64,94 +64,11 @@ impl DebugAdapter for GdbDebugAdapter { } fn dap_schema(&self) -> Cow<'static, serde_json::Value> { - Cow::Owned(json!({ - "oneOf": [ - { - "allOf": [ - { - "type": "object", - "required": ["request"], - "properties": { - "request": { - "type": "string", - "enum": ["launch"], - "description": "Request to launch a new process" - } - } - }, - { - "type": "object", - "properties": { - "program": { - "type": "string", - "description": "The program to debug. This corresponds to the GDB 'file' command." - }, - "args": { - "type": "array", - "items": { - "type": "string" - }, - "description": "Command line arguments passed to the program. These strings are provided as command-line arguments to the inferior.", - "default": [] - }, - "cwd": { - "type": "string", - "description": "Working directory for the debugged program. GDB will change its working directory to this directory." - }, - "env": { - "type": "object", - "description": "Environment variables for the debugged program. Each key is the name of an environment variable; each value is the value of that variable." - }, - "stopAtBeginningOfMainSubprogram": { - "type": "boolean", - "description": "When true, GDB will set a temporary breakpoint at the program's main procedure, like the 'start' command.", - "default": false - }, - "stopOnEntry": { - "type": "boolean", - "description": "When true, GDB will set a temporary breakpoint at the program's first instruction, like the 'starti' command.", - "default": false - } - }, - "required": ["program"] - } - ] - }, - { - "allOf": [ - { - "type": "object", - "required": ["request"], - "properties": { - "request": { - "type": "string", - "enum": ["attach"], - "description": "Request to attach to an existing process" - } - } - }, - { - "type": "object", - "properties": { - "pid": { - "type": "number", - "description": "The process ID to which GDB should attach." - }, - "program": { - "type": "string", - "description": "The program to debug (optional). This corresponds to the GDB 'file' command. In many cases, GDB can determine which program is running automatically." - }, - "target": { - "type": "string", - "description": "The target to which GDB should connect. This is passed to the 'target remote' command." - } - }, - "required": ["pid"] - } - ] - } - ] - })) + static SCHEMA: LazyLock = LazyLock::new(|| { + const RAW_SCHEMA: &str = include_str!("../schemas/GDB.json"); + serde_json::from_str(RAW_SCHEMA).unwrap() + }); + Cow::Borrowed(&*SCHEMA) } async fn get_binary(