Skip to content

Commit e7cb1a6

Browse files
authored
Add retval and array metadata to enumerators (#29)
1 parent 74ca249 commit e7cb1a6

File tree

7 files changed

+138
-25
lines changed

7 files changed

+138
-25
lines changed

.metadata/options.rsp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,15 @@ IDiaSourceFile::get_checksum::pbData=[Optional]
1212
IDiaSymbol10::get_sourceLink::pb=[Optional]
1313
IDiaSession::findChildren::parent=[Optional]
1414
IDiaSession::findFile::pCompiland=[Optional]
15+
IDiaEnumSymbols::Prev=[CanReturnMultipleSuccessValues]
16+
IDiaEnumSymbols::Next=[CanReturnMultipleSuccessValues]
17+
IDiaEnumSymbols::Prev::rgelt=[NativeArrayInfo(CountParamIndex = 0)]
18+
IDiaEnumSymbols::Next::rgelt=[NativeArrayInfo(CountParamIndex = 0)]
19+
IDiaEnumSymbolsByAddr::Prev=[CanReturnMultipleSuccessValues]
20+
IDiaEnumSymbolsByAddr::Next=[CanReturnMultipleSuccessValues]
21+
IDiaEnumSymbolsByAddr::Prev::rgelt=[NativeArrayInfo(CountParamIndex = 0)]
22+
IDiaEnumSymbolsByAddr::Next::rgelt=[NativeArrayInfo(CountParamIndex = 0)]
23+
IDiaEnumSymbolsByAddr2::PrevEx=[CanReturnMultipleSuccessValues]
24+
IDiaEnumSymbolsByAddr2::NextEx=[CanReturnMultipleSuccessValues]
25+
IDiaEnumSymbolsByAddr2::PrevEx::rgelt=[NativeArrayInfo(CountParamIndex = 1)]
26+
IDiaEnumSymbolsByAddr2::NextEx::rgelt=[NativeArrayInfo(CountParamIndex = 1)]

.windows/winmd/Microsoft.Dia.winmd

0 Bytes
Binary file not shown.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ readme = ".github/README.md"
1010
exclude = [".github", ".metadata", "docs", "tests"]
1111

1212
[workspace]
13-
members = ["crates/samples/*"]
13+
members = ["crates/samples/*", "crates/tests/*"]
1414

1515
[dependencies.windows]
1616
version = "0.59"

crates/tests/enumerators/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "test_enumerators"
3+
version = "0.0.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[dependencies.windows]
8+
version = "0.59"
9+
10+
[dependencies.microsoft-dia]
11+
path = "../../../"

crates/tests/enumerators/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
use microsoft_dia::{nsfRegularExpression, DiaSource, IDiaDataSource, IDiaSession, SymTagNull};
2+
use windows::{
3+
core::*,
4+
Win32::{
5+
Foundation::S_OK,
6+
System::Com::{CoInitializeEx, COINIT_MULTITHREADED},
7+
},
8+
};
9+
10+
fn get_test_session() -> Result<IDiaSession> {
11+
unsafe {
12+
CoInitializeEx(None, COINIT_MULTITHREADED).ok()?;
13+
let path = if cfg!(target_arch = "x86_64") {
14+
s!(
15+
r"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\DIA SDK\bin\amd64\msdia140.dll"
16+
)
17+
} else if cfg!(target_arch = "aarch64") {
18+
s!(
19+
r"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\DIA SDK\bin\arm64\msdia140.dll"
20+
)
21+
} else if cfg!(target_arch = "x86") {
22+
s!(r"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\DIA SDK\bin\msdia140.dll")
23+
} else {
24+
panic!("Unsupported target architecture");
25+
};
26+
let source: IDiaDataSource = microsoft_dia::helpers::NoRegCoCreate(path, &DiaSource)?;
27+
let executable = std::env::current_exe().unwrap();
28+
source.loadDataForExe(&HSTRING::from(executable.as_os_str()), None, None)?;
29+
source.openSession()
30+
}
31+
}
32+
33+
#[allow(dead_code)]
34+
static TEST_VALUE_01: i32 = 1;
35+
#[allow(dead_code)]
36+
static TEST_VALUE_02: i32 = 2;
37+
#[allow(dead_code)]
38+
static TEST_VALUE_03: i32 = 3;
39+
40+
#[test]
41+
fn simple_enumeration() -> Result<()> {
42+
unsafe {
43+
let session = get_test_session()?;
44+
let symbols = session.globalScope()?.findChildren(
45+
SymTagNull,
46+
w!("tests::TEST_VALUE_[0-9]+"),
47+
nsfRegularExpression.0 as u32,
48+
)?;
49+
50+
let mut found = Vec::new();
51+
for i in 0..symbols.Count()? {
52+
found.push(symbols.Item(i as u32)?.name()?);
53+
}
54+
assert_eq!(
55+
found,
56+
[
57+
"tests::TEST_VALUE_01",
58+
"tests::TEST_VALUE_02",
59+
"tests::TEST_VALUE_03",
60+
]
61+
);
62+
63+
Ok(())
64+
}
65+
}
66+
67+
#[test]
68+
fn batch_enumeration() -> Result<()> {
69+
unsafe {
70+
let session = get_test_session()?;
71+
let symbols = session.globalScope()?.findChildren(
72+
SymTagNull,
73+
w!("tests::TEST_VALUE_[0-9]+"),
74+
nsfRegularExpression.0 as u32,
75+
)?;
76+
77+
let mut found = Vec::new();
78+
let mut batch = [None, None];
79+
let mut fetched = 0;
80+
while symbols.Next(&mut batch, &mut fetched) == S_OK {
81+
found.extend(
82+
batch[0..fetched as usize]
83+
.iter()
84+
.filter_map(|s| s.as_ref()?.name().ok()),
85+
);
86+
}
87+
assert_eq!(
88+
found,
89+
[
90+
"tests::TEST_VALUE_01",
91+
"tests::TEST_VALUE_02",
92+
"tests::TEST_VALUE_03",
93+
]
94+
);
95+
96+
Ok(())
97+
}
98+
}

src/bindings.rs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7363,18 +7363,16 @@ pub mod Microsoft {
73637363
}
73647364
pub unsafe fn Next(
73657365
&self,
7366-
celt: u32,
7367-
rgelt: *mut Option<IDiaSymbol>,
7366+
rgelt: &mut [Option<IDiaSymbol>],
73687367
pceltfetched: *mut u32,
7369-
) -> windows_core::Result<()> {
7368+
) -> windows_core::HRESULT {
73707369
unsafe {
73717370
(windows_core::Interface::vtable(self).Next)(
73727371
windows_core::Interface::as_raw(self),
7373-
celt,
7374-
core::mem::transmute(rgelt),
7372+
rgelt.len().try_into().unwrap(),
7373+
core::mem::transmute(rgelt.as_ptr()),
73757374
pceltfetched as _,
73767375
)
7377-
.ok()
73787376
}
73797377
}
73807378
pub unsafe fn Skip(&self, celt: u32) -> windows_core::Result<()> {
@@ -7444,7 +7442,7 @@ pub mod Microsoft {
74447442
celt: u32,
74457443
rgelt: windows_core::OutRef<'_, IDiaSymbol>,
74467444
pceltfetched: *mut u32,
7447-
) -> windows_core::Result<()>;
7445+
) -> windows_core::HRESULT;
74487446
fn Skip(&self, celt: u32) -> windows_core::Result<()>;
74497447
fn Reset(&self) -> windows_core::Result<()>;
74507448
fn Clone(&self) -> windows_core::Result<IDiaEnumSymbols>;
@@ -7527,7 +7525,6 @@ pub mod Microsoft {
75277525
core::mem::transmute_copy(&rgelt),
75287526
core::mem::transmute_copy(&pceltfetched),
75297527
)
7530-
.into()
75317528
}
75327529
}
75337530
unsafe extern "system" fn Skip<
@@ -7643,34 +7640,30 @@ pub mod Microsoft {
76437640
}
76447641
pub unsafe fn Next(
76457642
&self,
7646-
celt: u32,
7647-
rgelt: *mut Option<IDiaSymbol>,
7643+
rgelt: &mut [Option<IDiaSymbol>],
76487644
pceltfetched: *mut u32,
7649-
) -> windows_core::Result<()> {
7645+
) -> windows_core::HRESULT {
76507646
unsafe {
76517647
(windows_core::Interface::vtable(self).Next)(
76527648
windows_core::Interface::as_raw(self),
7653-
celt,
7654-
core::mem::transmute(rgelt),
7649+
rgelt.len().try_into().unwrap(),
7650+
core::mem::transmute(rgelt.as_ptr()),
76557651
pceltfetched as _,
76567652
)
7657-
.ok()
76587653
}
76597654
}
76607655
pub unsafe fn Prev(
76617656
&self,
7662-
celt: u32,
7663-
rgelt: *mut Option<IDiaSymbol>,
7657+
rgelt: &mut [Option<IDiaSymbol>],
76647658
pceltfetched: *mut u32,
7665-
) -> windows_core::Result<()> {
7659+
) -> windows_core::HRESULT {
76667660
unsafe {
76677661
(windows_core::Interface::vtable(self).Prev)(
76687662
windows_core::Interface::as_raw(self),
7669-
celt,
7670-
core::mem::transmute(rgelt),
7663+
rgelt.len().try_into().unwrap(),
7664+
core::mem::transmute(rgelt.as_ptr()),
76717665
pceltfetched as _,
76727666
)
7673-
.ok()
76747667
}
76757668
}
76767669
pub unsafe fn Clone(&self) -> windows_core::Result<IDiaEnumSymbolsByAddr> {
@@ -7729,13 +7722,13 @@ pub mod Microsoft {
77297722
celt: u32,
77307723
rgelt: windows_core::OutRef<'_, IDiaSymbol>,
77317724
pceltfetched: *mut u32,
7732-
) -> windows_core::Result<()>;
7725+
) -> windows_core::HRESULT;
77337726
fn Prev(
77347727
&self,
77357728
celt: u32,
77367729
rgelt: windows_core::OutRef<'_, IDiaSymbol>,
77377730
pceltfetched: *mut u32,
7738-
) -> windows_core::Result<()>;
7731+
) -> windows_core::HRESULT;
77397732
fn Clone(&self) -> windows_core::Result<IDiaEnumSymbolsByAddr>;
77407733
}
77417734
impl IDiaEnumSymbolsByAddr_Vtbl {
@@ -7829,7 +7822,6 @@ pub mod Microsoft {
78297822
core::mem::transmute_copy(&rgelt),
78307823
core::mem::transmute_copy(&pceltfetched),
78317824
)
7832-
.into()
78337825
}
78347826
}
78357827
unsafe extern "system" fn Prev<
@@ -7850,7 +7842,6 @@ pub mod Microsoft {
78507842
core::mem::transmute_copy(&rgelt),
78517843
core::mem::transmute_copy(&pceltfetched),
78527844
)
7853-
.into()
78547845
}
78557846
}
78567847
unsafe extern "system" fn Clone<

0 commit comments

Comments
 (0)