Skip to content

Commit e9b6efe

Browse files
Merge pull request #140 from Chia-Network/20250216-dbg-improvements
20250216 dbg improvements
2 parents ff2c77a + 58145b7 commit e9b6efe

11 files changed

+451
-100
lines changed

test/classic-arg-decode.clsp

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(mod (X)
2+
(defun F (X Y)
3+
(if X (F (- X 1) Y) Y)
4+
)
5+
6+
(F X 2)
7+
)

test/classic-arg-decode.sym

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"a63655f92a682296fe0afe6593b013f3d1ea5302438129dcd5af967af8e9b8f1":"F"}

test/launch.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
{
22
"version": "0.2.0",
33
"configurations": [
4-
{
4+
{
55
"type": "chialisp",
66
"request": "launch",
77
"name": "fact.hex",
88
"program": "project/fact.hex",
99
"args": ["(5)"]
10-
},
10+
},
1111
{
1212
"type": "chialisp",
1313
"request": "launch",
1414
"name": "fact.clsp - bad args",
1515
"program": "project/fact.clsp",
1616
"args": ["()"]
17-
},
17+
},
1818
{
1919
"type": "chialisp",
2020
"request": "launch",
2121
"name": "fact.clsp",
2222
"program": "project/fact.clsp",
2323
"args": ["(5)"]
24-
}
24+
}
2525
]
2626
}

wasm/src/dbg/handler.rs

+30-69
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::mem::swap;
66
use std::rc::Rc;
77

88
use debug_types::events::{ContinuedEvent, Event, EventBody, StoppedEvent, StoppedReason};
9-
use debug_types::requests::{InitializeRequestArguments, LaunchRequestArguments, RequestCommand};
9+
use debug_types::requests::{InitializeRequestArguments, RequestCommand};
1010
use debug_types::responses::{
1111
InitializeResponse, Response, ResponseBody, ScopesResponse, SetBreakpointsResponse,
1212
SetExceptionBreakpointsResponse, StackTraceResponse, ThreadsResponse, VariablesResponse,
@@ -20,17 +20,17 @@ use clvmr::allocator::Allocator;
2020

2121
use clvm_tools_rs::classic::clvm_tools::stages::stage_0::TRunProgram;
2222

23-
use clvm_tools_rs::compiler::cldb_hierarchy::HierarchialRunner;
2423
use clvm_tools_rs::compiler::compiler::DefaultCompilerOpts;
25-
use clvm_tools_rs::compiler::sexp::{decode_string, parse_sexp, SExp};
24+
use clvm_tools_rs::compiler::sexp::{decode_string, SExp};
2625
use clvm_tools_rs::compiler::srcloc::Srcloc;
2726

2827
use crate::dbg::compopts::DbgCompilerOpts;
29-
use crate::dbg::obj::{read_program_data, RunningDebugger, TargetDepth};
28+
use crate::dbg::obj::{ObjLaunchArgs, RunningDebugger, TargetDepth};
3029
use crate::dbg::source::{parse_srcloc, StoredScope};
3130
use crate::dbg::types::MessageHandler;
3231
use crate::interfaces::{IFileReader, ILogWriter};
3332
use crate::lsp::types::ConfigJson;
33+
3434
// Lifecycle:
3535
// (a (code... ) (c arg ...))
3636
// We encounter this and we're creating the arguments for a future call to
@@ -49,6 +49,8 @@ pub struct ExtraLaunchData {
4949
args: Option<Vec<String>>,
5050
#[serde(rename = "program")]
5151
program: Option<String>,
52+
#[serde(rename = "symbols")]
53+
symbols: Option<String>,
5254
}
5355

5456
/// Used to make some aspects of deserializing easier via serde_json easier.
@@ -59,6 +61,11 @@ pub struct RequestContainer<T> {
5961
arguments: T,
6062
}
6163

64+
pub struct LaunchArgs<'a> {
65+
proto_msg: &'a ProtocolMessage,
66+
obj_launch_args: ObjLaunchArgs<'a>,
67+
}
68+
6269
/// State diagram for the debugger.
6370
///
6471
/// Starts in PreInitialization until we get an Initialization request.
@@ -180,16 +187,6 @@ fn get_initialize_response() -> InitializeResponse {
180187
}
181188
}
182189

183-
struct LaunchArgs<'a> {
184-
proto_msg: &'a ProtocolMessage,
185-
name: &'a str,
186-
init_args: &'a InitializeRequestArguments,
187-
launch_request: &'a LaunchRequestArguments,
188-
program: &'a str,
189-
args_for_program: &'a [String],
190-
stop_on_entry: bool,
191-
}
192-
193190
impl Debugger {
194191
fn get_source_loc(&self, running: &RunningDebugger, name: &str) -> Option<Srcloc> {
195192
let get_helper_loc = |name: &str| {
@@ -249,64 +246,22 @@ impl Debugger {
249246
let mut allocator = Allocator::new();
250247
let mut seq_nr = self.msg_seq;
251248
let config = self.read_chialisp_json()?;
252-
let read_in_file = self.fs.read_content(launch_args.program)?;
253-
let def_opts = Rc::new(DefaultCompilerOpts::new(&launch_args.name));
249+
let def_opts = Rc::new(DefaultCompilerOpts::new(&launch_args.obj_launch_args.name));
254250
let opts = Rc::new(DbgCompilerOpts::new(
255251
def_opts,
256252
self.log.clone(),
257253
self.fs.clone(),
258254
&config.include_paths,
259255
));
260-
let mut launch_data = read_program_data(
256+
let debugger = RunningDebugger::create(
257+
&mut allocator,
261258
self.fs.clone(),
262259
self.log.clone(),
263-
&mut allocator,
260+
self.runner.clone(),
264261
opts.clone(),
265-
launch_args.init_args,
266-
launch_args.launch_request,
267-
launch_args.program,
268-
read_in_file.as_bytes(),
262+
&launch_args.obj_launch_args,
269263
)?;
270-
271-
if !launch_args.args_for_program.is_empty() {
272-
let parsed_argv0 = parse_sexp(
273-
Srcloc::start("*args*"),
274-
launch_args.args_for_program[0].bytes(),
275-
)
276-
.map_err(|(l, e)| format!("{l}: {e}"))?;
277-
if !parsed_argv0.is_empty() {
278-
launch_data.arguments = parsed_argv0[0].clone();
279-
}
280-
}
281-
282-
let symbol_rc = Rc::new(launch_data.symbols);
283-
284-
let run = HierarchialRunner::new(
285-
self.runner.clone(),
286-
self.prim_map.clone(),
287-
Some(launch_args.name.to_string()),
288-
Rc::new(launch_data.program_lines),
289-
symbol_rc.clone(),
290-
launch_data.program,
291-
launch_data.arguments,
292-
);
293-
let state = State::Launched(RunningDebugger {
294-
initialized: launch_args.init_args.clone(),
295-
launch_info: launch_args.launch_request.clone(),
296-
running: !launch_args.stop_on_entry,
297-
run,
298-
opts,
299-
output_stack: Vec::new(),
300-
stopped_reason: None,
301-
target_depth: None,
302-
result: None,
303-
source_file: launch_data.source_file,
304-
compiled: launch_data.compiled,
305-
breakpoints: HashMap::new(),
306-
next_bp_id: 1,
307-
at_breakpoint: None,
308-
symbols: symbol_rc,
309-
});
264+
let state = State::Launched(debugger);
310265

311266
seq_nr += 1;
312267
let mut out_messages = vec![ProtocolMessage {
@@ -320,7 +275,7 @@ impl Debugger {
320275
}];
321276

322277
// Signal that we're paused if stop on entry.
323-
if launch_args.stop_on_entry {
278+
if launch_args.obj_launch_args.stop_on_entry {
324279
seq_nr += 1;
325280
out_messages.push(ProtocolMessage {
326281
seq: self.msg_seq,
@@ -402,19 +357,25 @@ impl MessageHandler<ProtocolMessage> for Debugger {
402357
.as_ref()
403358
.and_then(|l| l.arguments.args.clone())
404359
.unwrap_or(vec![]);
360+
let symbols = launch_extra
361+
.as_ref()
362+
.and_then(|l| l.arguments.symbols.clone())
363+
.unwrap_or("".to_string());
405364
if let Some(name) = &l.name {
406365
let program = launch_extra
407366
.and_then(|l| l.arguments.program)
408367
.unwrap_or(name.clone());
409368

410369
let (new_seq, new_state, out_msgs) = self.launch(LaunchArgs {
411370
proto_msg: pm,
412-
name,
413-
init_args: &i,
414-
launch_request: l,
415-
program: &program,
416-
args_for_program: &args,
417-
stop_on_entry,
371+
obj_launch_args: ObjLaunchArgs {
372+
init_args: &i,
373+
name,
374+
program: &program,
375+
args_for_program: &args,
376+
symbols: &symbols,
377+
stop_on_entry,
378+
},
418379
})?;
419380
self.msg_seq = new_seq;
420381
self.state = new_state;

0 commit comments

Comments
 (0)