Skip to content

Commit d9caf7f

Browse files
committed
refactor: pass lang for some cases of loading values/locals
1 parent 180f1de commit d9caf7f

File tree

9 files changed

+56
-22
lines changed

9 files changed

+56
-22
lines changed

src/common/common_types/language_features/value.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type
7272
rrTicks*: int
7373
countBudget*: int
7474
minCountLimit*: int
75+
lang*: Lang
7576

7677
CtLoadLocalsResponseBody* = ref object
7778
locals*: seq[Variable]

src/db-backend/src/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ impl Replay for DbReplay {
10541054
Ok(locals)
10551055
}
10561056

1057-
fn load_value(&mut self, expression: &str) -> Result<ValueRecordWithType, Box<dyn Error>> {
1057+
fn load_value(&mut self, expression: &str, _lang: Lang) -> Result<ValueRecordWithType, Box<dyn Error>> {
10581058
// TODO: a more optimal way: cache a hashmap? or change structure?
10591059
// or again start directly loading available values matching all expressions in the same time?:
10601060
// taking a set of expressions: probably best(maybe add an additional load_values)
@@ -1066,7 +1066,7 @@ impl Replay for DbReplay {
10661066
return Err(format!("variable {expression} not found on this step").into())
10671067
}
10681068

1069-
fn load_return_value(&mut self) -> Result<ValueRecordWithType, Box<dyn Error>> {
1069+
fn load_return_value(&mut self, _lang: Lang) -> Result<ValueRecordWithType, Box<dyn Error>> {
10701070
// assumes self.load_location() has been ran, and that we have the current call key
10711071
Ok(self.to_value_record_with_type(&self.db.calls[self.call_key].return_value.clone()))
10721072
}

src/db-backend/src/flow_preloader.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1+
use std::collections::{HashMap, HashSet};
2+
use std::path::{Path, PathBuf};
3+
use std::error::Error;
4+
5+
use log::{info, warn, error};
6+
use runtime_tracing::{CallKey, Line, StepId, TypeKind, TypeRecord, TypeSpecificInfo};
7+
18
use crate::{
29
db::{Db, DbRecordEvent},
310
expr_loader::ExprLoader,
411
task::{
512
Action, BranchesTaken, CoreTrace, FlowEvent, FlowStep, FlowUpdate, FlowUpdateState, FlowUpdateStateKind,
613
FlowMode, FlowViewUpdate, Iteration, Location, Loop, LoopId, LoopIterationSteps, Position, RRTicks, StepCount, TraceKind,
714
},
15+
lang::{lang_from_context, Lang},
816
replay::Replay,
917
value::{to_ct_value, Value, ValueRecordWithType},
1018
};
11-
use log::{info, warn, error};
12-
use runtime_tracing::{CallKey, Line, StepId, TypeKind, TypeRecord, TypeSpecificInfo};
13-
use std::collections::{HashMap, HashSet};
14-
use std::path::PathBuf;
15-
use std::error::Error;
1619

1720
#[derive(Debug)]
1821
pub struct FlowPreloader {
@@ -109,6 +112,7 @@ pub struct CallFlowPreloader<'a> {
109112
diff_call_keys: HashSet<i64>, // TODO: if we add Eq, Hash it seems we can do CallKey
110113
mode: FlowMode,
111114
trace_kind: TraceKind,
115+
lang: Lang,
112116
}
113117

114118
impl<'a> CallFlowPreloader<'a> {
@@ -121,14 +125,15 @@ impl<'a> CallFlowPreloader<'a> {
121125
trace_kind: TraceKind) -> Self {
122126
CallFlowPreloader {
123127
flow_preloader,
124-
location,
128+
location: location.clone(),
125129
active_loops: vec![],
126130
last_step_id: StepId(-1),
127131
last_expr_order: vec![],
128132
diff_lines,
129133
diff_call_keys,
130134
mode,
131135
trace_kind,
136+
lang: lang_from_context(&Path::new(&location.path), trace_kind),
132137
}
133138
}
134139

@@ -190,7 +195,7 @@ impl<'a> CallFlowPreloader<'a> {
190195
// are never None, so it is safe to unwrap them.
191196
if !flow_view_update.steps.is_empty() {
192197

193-
let return_value_record = replay.load_return_value().unwrap_or(ValueRecordWithType::Error {
198+
let return_value_record = replay.load_return_value(self.lang).unwrap_or(ValueRecordWithType::Error {
194199
msg: "<return value error>".to_string(),
195200
typ: TypeRecord { kind: TypeKind::Error, lang_type: "<error>".to_string(), specific_info: TypeSpecificInfo::None },
196201
});
@@ -521,7 +526,7 @@ impl<'a> CallFlowPreloader<'a> {
521526
if let Some(var_list) = self.flow_preloader.get_var_list(line, &self.location) {
522527
info!("var_list {:?}", var_list.clone());
523528
for value_name in &var_list {
524-
if let Ok(value) = replay.load_value(value_name) {
529+
if let Ok(value) = replay.load_value(value_name, self.lang) {
525530
// if variable_map.contains_key(value_name) {
526531
let ct_value = to_ct_value(&value);
527532
flow_view_update

src/db-backend/src/lang.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
use std::path::Path;
2+
use std::ffi::OsStr;
3+
14
use num_derive::FromPrimitive;
25
use serde_repr::*;
36

7+
use crate::task::TraceKind;
8+
49
#[derive(
510
Debug,
611
Default,
@@ -36,3 +41,15 @@ pub enum Lang {
3641
PythonDb,
3742
Unknown,
3843
}
44+
45+
pub fn lang_from_context(path: &Path, trace_kind: TraceKind) -> Lang {
46+
let extension = path.extension().unwrap_or(OsStr::new("")).to_str().unwrap_or("");
47+
// for now important mostly for system langs/rr support
48+
// but still good to add all supported langs: TODO
49+
match extension {
50+
"rs" => if trace_kind == TraceKind::DB { Lang::RustWasm } else { Lang::Rust },
51+
"c" => Lang::C,
52+
"cpp" => Lang::Cpp,
53+
_ => Lang::Unknown,
54+
}
55+
}

src/db-backend/src/query.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use serde::{Deserialize, Serialize};
22

33
use crate::task::{Action, Breakpoint, CtLoadLocalsArguments, Location};
4+
use crate::lang::Lang;
45

56
#[derive(Debug, Clone, Serialize, Deserialize)]
67
#[serde(tag = "kind")]
@@ -9,11 +10,11 @@ pub enum CtRRQuery {
910
LoadLocation,
1011
Step { action: Action, forward: bool },
1112
LoadLocals { arg: CtLoadLocalsArguments },
12-
LoadReturnValue,
13-
LoadValue { expression: String },
14-
AddBreakpoint { path: String, line: i64, },
15-
DeleteBreakpoint { breakpoint: Breakpoint, },
13+
LoadReturnValue { lang: Lang },
14+
LoadValue { expression: String, lang: Lang },
15+
AddBreakpoint { path: String, line: i64 },
16+
DeleteBreakpoint { breakpoint: Breakpoint },
1617
DeleteBreakpoints,
17-
ToggleBreakpoint { breakpoint: Breakpoint, },
18+
ToggleBreakpoint { breakpoint: Breakpoint },
1819
JumpToCall { location: Location },
1920
}

src/db-backend/src/replay.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ use std::error::Error;
33

44
use crate::db::DbRecordEvent;
55
use crate::expr_loader::ExprLoader;
6+
use crate::lang::Lang;
67
use crate::task::{Action, Breakpoint, Location, ProgramEvent, CtLoadLocalsArguments, VariableWithRecord};
78
use crate::value::ValueRecordWithType;
89

10+
911
#[derive(Debug, Clone)]
1012
pub struct Events {
1113
pub events: Vec<ProgramEvent>,
@@ -19,9 +21,12 @@ pub trait Replay: std::fmt::Debug {
1921
fn load_events(&mut self) -> Result<Events, Box<dyn Error>>;
2022
fn step(&mut self, action: Action, forward: bool) -> Result<bool, Box<dyn Error>>;
2123
fn load_locals(&mut self, arg: CtLoadLocalsArguments) -> Result<Vec<VariableWithRecord>, Box<dyn Error>>;
22-
fn load_value(&mut self, expression: &str) -> Result<ValueRecordWithType, Box<dyn Error>>;
23-
// assuming currently in the right call for both trace kinds; and if rr: possibly near the return value
24-
fn load_return_value(&mut self) -> Result<ValueRecordWithType, Box<dyn Error>>;
24+
fn load_value(&mut self, expression: &str, lang: Lang) -> Result<ValueRecordWithType, Box<dyn Error>>;
25+
26+
// assuming currently the replay is stopped in the right `call`(frame) for both trace kinds;
27+
// and if rr: possibly near the return value
28+
fn load_return_value(&mut self, lang: Lang) -> Result<ValueRecordWithType, Box<dyn Error>>;
29+
2530
fn load_step_events(&mut self, step_id: StepId, exact: bool) -> Vec<DbRecordEvent>;
2631
fn jump_to(&mut self, step_id: StepId) -> Result<bool, Box<dyn Error>>;
2732
fn add_breakpoint(&mut self, path: &str, line: i64) -> Result<Breakpoint, Box<dyn Error>>;

src/db-backend/src/rr_dispatcher.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use runtime_tracing::StepId;
1313

1414
use crate::db::DbRecordEvent;
1515
use crate::expr_loader::ExprLoader;
16+
use crate::lang::Lang;
1617
use crate::paths::ct_rr_worker_socket_path;
1718
use crate::query::CtRRQuery;
1819
use crate::replay::{Events, Replay};
@@ -218,15 +219,17 @@ impl Replay for RRDispatcher {
218219
Ok(res)
219220
}
220221

221-
fn load_value(&mut self, expression: &str) -> Result<ValueRecordWithType, Box<dyn Error>> {
222+
fn load_value(&mut self, expression: &str, lang: Lang) -> Result<ValueRecordWithType, Box<dyn Error>> {
222223
self.ensure_active_stable()?;
223-
let res = serde_json::from_str::<ValueRecordWithType>(&self.stable.run_query(CtRRQuery::LoadValue { expression: expression.to_string() })?)?;
224+
let res = serde_json::from_str::<ValueRecordWithType>(&self.stable.run_query(CtRRQuery::LoadValue {
225+
expression: expression.to_string(),
226+
lang, })?)?;
224227
Ok(res)
225228
}
226229

227-
fn load_return_value(&mut self) -> Result<ValueRecordWithType, Box<dyn Error>> {
230+
fn load_return_value(&mut self, lang: Lang) -> Result<ValueRecordWithType, Box<dyn Error>> {
228231
self.ensure_active_stable()?;
229-
let res = serde_json::from_str::<ValueRecordWithType>(&self.stable.run_query(CtRRQuery::LoadReturnValue)?)?;
232+
let res = serde_json::from_str::<ValueRecordWithType>(&self.stable.run_query(CtRRQuery::LoadReturnValue { lang })?)?;
230233
Ok(res)
231234
}
232235

src/db-backend/src/task.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub struct CtLoadLocalsArguments {
2424
pub rr_ticks: i64,
2525
pub count_budget: i64,
2626
pub min_count_limit: i64,
27+
pub lang: Lang,
2728
}
2829

2930
/// response for `ct/load-locals`

src/frontend/ui/state.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ method onMove(self: StateComponent) {.async.} =
7171
rrTicks: self.rrTicks,
7272
countBudget: countBudget,
7373
minCountLimit: minCountLimit,
74+
lang: toLangFromFilename(self.location.path),
7475
)
7576
self.api.emit(CtLoadLocals, arguments)
7677
self.redraw()

0 commit comments

Comments
 (0)