Skip to content

Commit 008dc16

Browse files
committed
refactor(debugger): add Member and ArrayItem structures instead of VariableIR as structure members and array items representation
1 parent 6711ffa commit 008dc16

File tree

11 files changed

+1770
-1301
lines changed

11 files changed

+1770
-1301
lines changed

src/debugger/variable/mod.rs

Lines changed: 424 additions & 291 deletions
Large diffs are not rendered by default.

src/debugger/variable/render.rs

Lines changed: 36 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::debugger::debugee::dwarf::r#type::TypeIdentity;
2-
use crate::debugger::variable::SpecializedVariableIR;
3-
use crate::debugger::variable::VariableIR;
2+
use crate::debugger::variable::{ArrayItem, VariableIR};
3+
use crate::debugger::variable::{Member, SpecializedVariableIR};
44
use nix::errno::Errno;
55
use nix::libc;
66
use nix::sys::time::TimeSpec;
@@ -13,29 +13,21 @@ use std::time::Duration;
1313

1414
pub enum ValueLayout<'a> {
1515
PreRendered(Cow<'a, str>),
16-
Referential {
17-
addr: *const (),
18-
},
16+
Referential(*const ()),
1917
Wrapped(&'a VariableIR),
20-
Structure {
21-
members: &'a [VariableIR],
22-
},
23-
List {
24-
members: &'a [VariableIR],
25-
indexed: bool,
26-
},
18+
Structure(&'a [Member]),
19+
IndexedList(&'a [ArrayItem]),
20+
NonIndexedList(&'a [VariableIR]),
2721
Map(&'a [(VariableIR, VariableIR)]),
2822
}
2923

3024
impl<'a> Debug for ValueLayout<'a> {
3125
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
3226
match self {
3327
ValueLayout::PreRendered(s) => f.debug_tuple("PreRendered").field(s).finish(),
34-
ValueLayout::Referential { addr, .. } => {
35-
f.debug_tuple("Referential").field(addr).finish()
36-
}
28+
ValueLayout::Referential(addr) => f.debug_tuple("Referential").field(addr).finish(),
3729
ValueLayout::Wrapped(v) => f.debug_tuple("Wrapped").field(v).finish(),
38-
ValueLayout::Structure { members } => {
30+
ValueLayout::Structure(members) => {
3931
f.debug_struct("Nested").field("members", members).finish()
4032
}
4133
ValueLayout::Map(kvs) => {
@@ -45,24 +37,28 @@ impl<'a> Debug for ValueLayout<'a> {
4537
}
4638
list.finish()
4739
}
48-
ValueLayout::List { members, indexed } => f
49-
.debug_struct("List")
50-
.field("members", members)
51-
.field("indexed", indexed)
52-
.finish(),
40+
ValueLayout::IndexedList(items) => {
41+
f.debug_struct("List").field("items", items).finish()
42+
}
43+
ValueLayout::NonIndexedList(items) => {
44+
f.debug_struct("List").field("items", items).finish()
45+
}
5346
}
5447
}
5548
}
5649

5750
pub trait RenderRepr {
58-
fn name(&self) -> String;
51+
fn name(&self) -> Option<String>;
5952
fn r#type(&self) -> &TypeIdentity;
6053
fn value(&self) -> Option<ValueLayout>;
6154
}
6255

6356
impl RenderRepr for VariableIR {
64-
fn name(&self) -> String {
65-
self.identity().to_string()
57+
fn name(&self) -> Option<String> {
58+
self.identity()
59+
.name
60+
.is_some()
61+
.then(|| self.identity().to_string())
6662
}
6763

6864
fn r#type(&self) -> &TypeIdentity {
@@ -102,9 +98,8 @@ impl RenderRepr for VariableIR {
10298
SpecializedVariableIR::Instant(_) => &original.type_ident,
10399
},
104100
VariableIR::Specialized { original, .. } => &original.type_ident,
105-
106101
VariableIR::Subroutine(_) => {
107-
// currently this line is unreachable cause dereference fn pointer is forbidden
102+
// currently this line is unreachable because dereference of fn pointer is forbidden
108103
&UNKNOWN_TYPE
109104
}
110105
VariableIR::CModifiedVariable(v) => &v.type_ident,
@@ -116,30 +111,25 @@ impl RenderRepr for VariableIR {
116111
VariableIR::Scalar(scalar) => {
117112
ValueLayout::PreRendered(Cow::Owned(scalar.value.as_ref()?.to_string()))
118113
}
119-
VariableIR::Struct(r#struct) => ValueLayout::Structure {
120-
members: r#struct.members.as_ref(),
121-
},
122-
VariableIR::Array(array) => ValueLayout::List {
123-
members: array.items.as_deref()?,
124-
indexed: true,
125-
},
114+
VariableIR::Struct(r#struct) => ValueLayout::Structure(r#struct.members.as_ref()),
115+
VariableIR::Array(array) => ValueLayout::IndexedList(array.items.as_deref()?),
126116
VariableIR::CEnum(r#enum) => {
127117
ValueLayout::PreRendered(Cow::Borrowed(r#enum.value.as_ref()?))
128118
}
129-
VariableIR::RustEnum(r#enum) => ValueLayout::Wrapped(r#enum.value.as_ref()?),
119+
VariableIR::RustEnum(r#enum) => {
120+
let enum_val = &r#enum.value.as_ref()?.value;
121+
ValueLayout::Wrapped(enum_val)
122+
}
130123
VariableIR::Pointer(pointer) => {
131124
let ptr = pointer.value?;
132-
ValueLayout::Referential { addr: ptr }
125+
ValueLayout::Referential(ptr)
133126
}
134127
VariableIR::Specialized {
135128
value: Some(spec_val),
136129
..
137130
} => match spec_val {
138131
SpecializedVariableIR::Vector(vec) | SpecializedVariableIR::VecDeque(vec) => {
139-
ValueLayout::List {
140-
members: vec.structure.members.as_ref(),
141-
indexed: true,
142-
}
132+
ValueLayout::Structure(vec.structure.members.as_ref())
143133
}
144134
SpecializedVariableIR::String(string) => {
145135
ValueLayout::PreRendered(Cow::Borrowed(&string.value))
@@ -152,21 +142,15 @@ impl RenderRepr for VariableIR {
152142
Some(tls_inner_val) => tls_inner_val.value()?,
153143
},
154144
SpecializedVariableIR::HashMap(map) => ValueLayout::Map(&map.kv_items),
155-
SpecializedVariableIR::HashSet(set) => ValueLayout::List {
156-
members: &set.items,
157-
indexed: false,
158-
},
145+
SpecializedVariableIR::HashSet(set) => ValueLayout::NonIndexedList(&set.items),
159146
SpecializedVariableIR::BTreeMap(map) => ValueLayout::Map(&map.kv_items),
160-
SpecializedVariableIR::BTreeSet(set) => ValueLayout::List {
161-
members: &set.items,
162-
indexed: false,
163-
},
147+
SpecializedVariableIR::BTreeSet(set) => ValueLayout::NonIndexedList(&set.items),
164148
SpecializedVariableIR::Cell(cell) | SpecializedVariableIR::RefCell(cell) => {
165149
cell.value()?
166150
}
167151
SpecializedVariableIR::Rc(ptr) | SpecializedVariableIR::Arc(ptr) => {
168152
let ptr = ptr.value?;
169-
ValueLayout::Referential { addr: ptr }
153+
ValueLayout::Referential(ptr)
170154
}
171155
SpecializedVariableIR::Uuid(bytes) => {
172156
let uuid = uuid::Uuid::from_slice(bytes).expect("infallible");
@@ -192,11 +176,11 @@ impl RenderRepr for VariableIR {
192176
ValueLayout::PreRendered(Cow::Owned(render))
193177
}
194178
},
195-
VariableIR::Specialized { original, .. } => ValueLayout::Structure {
196-
members: original.members.as_ref(),
197-
},
179+
VariableIR::Specialized { original, .. } => {
180+
ValueLayout::Structure(original.members.as_ref())
181+
}
198182
VariableIR::Subroutine(_) => {
199-
// currently this line is unreachable a cause dereference fn pointer is forbidden
183+
// currently this line is unreachable because dereference of fn pointer is forbidden
200184
return None;
201185
}
202186
VariableIR::CModifiedVariable(v) => ValueLayout::Wrapped(v.value.as_ref()?),

0 commit comments

Comments
 (0)