Skip to content

Commit

Permalink
Add retval and array metadata to enumerators (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
riverar authored Jan 10, 2025
1 parent 74ca249 commit e7cb1a6
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 25 deletions.
12 changes: 12 additions & 0 deletions .metadata/options.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ IDiaSourceFile::get_checksum::pbData=[Optional]
IDiaSymbol10::get_sourceLink::pb=[Optional]
IDiaSession::findChildren::parent=[Optional]
IDiaSession::findFile::pCompiland=[Optional]
IDiaEnumSymbols::Prev=[CanReturnMultipleSuccessValues]
IDiaEnumSymbols::Next=[CanReturnMultipleSuccessValues]
IDiaEnumSymbols::Prev::rgelt=[NativeArrayInfo(CountParamIndex = 0)]
IDiaEnumSymbols::Next::rgelt=[NativeArrayInfo(CountParamIndex = 0)]
IDiaEnumSymbolsByAddr::Prev=[CanReturnMultipleSuccessValues]
IDiaEnumSymbolsByAddr::Next=[CanReturnMultipleSuccessValues]
IDiaEnumSymbolsByAddr::Prev::rgelt=[NativeArrayInfo(CountParamIndex = 0)]
IDiaEnumSymbolsByAddr::Next::rgelt=[NativeArrayInfo(CountParamIndex = 0)]
IDiaEnumSymbolsByAddr2::PrevEx=[CanReturnMultipleSuccessValues]
IDiaEnumSymbolsByAddr2::NextEx=[CanReturnMultipleSuccessValues]
IDiaEnumSymbolsByAddr2::PrevEx::rgelt=[NativeArrayInfo(CountParamIndex = 1)]
IDiaEnumSymbolsByAddr2::NextEx::rgelt=[NativeArrayInfo(CountParamIndex = 1)]
Binary file modified .windows/winmd/Microsoft.Dia.winmd
Binary file not shown.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ readme = ".github/README.md"
exclude = [".github", ".metadata", "docs", "tests"]

[workspace]
members = ["crates/samples/*"]
members = ["crates/samples/*", "crates/tests/*"]

[dependencies.windows]
version = "0.59"
Expand Down
11 changes: 11 additions & 0 deletions crates/tests/enumerators/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "test_enumerators"
version = "0.0.0"
edition = "2021"
publish = false

[dependencies.windows]
version = "0.59"

[dependencies.microsoft-dia]
path = "../../../"
1 change: 1 addition & 0 deletions crates/tests/enumerators/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

98 changes: 98 additions & 0 deletions crates/tests/enumerators/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
use microsoft_dia::{nsfRegularExpression, DiaSource, IDiaDataSource, IDiaSession, SymTagNull};
use windows::{
core::*,
Win32::{
Foundation::S_OK,
System::Com::{CoInitializeEx, COINIT_MULTITHREADED},
},
};

fn get_test_session() -> Result<IDiaSession> {
unsafe {
CoInitializeEx(None, COINIT_MULTITHREADED).ok()?;
let path = if cfg!(target_arch = "x86_64") {
s!(
r"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\DIA SDK\bin\amd64\msdia140.dll"
)
} else if cfg!(target_arch = "aarch64") {
s!(
r"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\DIA SDK\bin\arm64\msdia140.dll"
)
} else if cfg!(target_arch = "x86") {
s!(r"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\DIA SDK\bin\msdia140.dll")
} else {
panic!("Unsupported target architecture");
};
let source: IDiaDataSource = microsoft_dia::helpers::NoRegCoCreate(path, &DiaSource)?;
let executable = std::env::current_exe().unwrap();
source.loadDataForExe(&HSTRING::from(executable.as_os_str()), None, None)?;
source.openSession()
}
}

#[allow(dead_code)]
static TEST_VALUE_01: i32 = 1;
#[allow(dead_code)]
static TEST_VALUE_02: i32 = 2;
#[allow(dead_code)]
static TEST_VALUE_03: i32 = 3;

#[test]
fn simple_enumeration() -> Result<()> {
unsafe {
let session = get_test_session()?;
let symbols = session.globalScope()?.findChildren(
SymTagNull,
w!("tests::TEST_VALUE_[0-9]+"),
nsfRegularExpression.0 as u32,
)?;

let mut found = Vec::new();
for i in 0..symbols.Count()? {
found.push(symbols.Item(i as u32)?.name()?);
}
assert_eq!(
found,
[
"tests::TEST_VALUE_01",
"tests::TEST_VALUE_02",
"tests::TEST_VALUE_03",
]
);

Ok(())
}
}

#[test]
fn batch_enumeration() -> Result<()> {
unsafe {
let session = get_test_session()?;
let symbols = session.globalScope()?.findChildren(
SymTagNull,
w!("tests::TEST_VALUE_[0-9]+"),
nsfRegularExpression.0 as u32,
)?;

let mut found = Vec::new();
let mut batch = [None, None];
let mut fetched = 0;
while symbols.Next(&mut batch, &mut fetched) == S_OK {
found.extend(
batch[0..fetched as usize]
.iter()
.filter_map(|s| s.as_ref()?.name().ok()),
);
}
assert_eq!(
found,
[
"tests::TEST_VALUE_01",
"tests::TEST_VALUE_02",
"tests::TEST_VALUE_03",
]
);

Ok(())
}
}
39 changes: 15 additions & 24 deletions src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7363,18 +7363,16 @@ pub mod Microsoft {
}
pub unsafe fn Next(
&self,
celt: u32,
rgelt: *mut Option<IDiaSymbol>,
rgelt: &mut [Option<IDiaSymbol>],
pceltfetched: *mut u32,
) -> windows_core::Result<()> {
) -> windows_core::HRESULT {
unsafe {
(windows_core::Interface::vtable(self).Next)(
windows_core::Interface::as_raw(self),
celt,
core::mem::transmute(rgelt),
rgelt.len().try_into().unwrap(),
core::mem::transmute(rgelt.as_ptr()),
pceltfetched as _,
)
.ok()
}
}
pub unsafe fn Skip(&self, celt: u32) -> windows_core::Result<()> {
Expand Down Expand Up @@ -7444,7 +7442,7 @@ pub mod Microsoft {
celt: u32,
rgelt: windows_core::OutRef<'_, IDiaSymbol>,
pceltfetched: *mut u32,
) -> windows_core::Result<()>;
) -> windows_core::HRESULT;
fn Skip(&self, celt: u32) -> windows_core::Result<()>;
fn Reset(&self) -> windows_core::Result<()>;
fn Clone(&self) -> windows_core::Result<IDiaEnumSymbols>;
Expand Down Expand Up @@ -7527,7 +7525,6 @@ pub mod Microsoft {
core::mem::transmute_copy(&rgelt),
core::mem::transmute_copy(&pceltfetched),
)
.into()
}
}
unsafe extern "system" fn Skip<
Expand Down Expand Up @@ -7643,34 +7640,30 @@ pub mod Microsoft {
}
pub unsafe fn Next(
&self,
celt: u32,
rgelt: *mut Option<IDiaSymbol>,
rgelt: &mut [Option<IDiaSymbol>],
pceltfetched: *mut u32,
) -> windows_core::Result<()> {
) -> windows_core::HRESULT {
unsafe {
(windows_core::Interface::vtable(self).Next)(
windows_core::Interface::as_raw(self),
celt,
core::mem::transmute(rgelt),
rgelt.len().try_into().unwrap(),
core::mem::transmute(rgelt.as_ptr()),
pceltfetched as _,
)
.ok()
}
}
pub unsafe fn Prev(
&self,
celt: u32,
rgelt: *mut Option<IDiaSymbol>,
rgelt: &mut [Option<IDiaSymbol>],
pceltfetched: *mut u32,
) -> windows_core::Result<()> {
) -> windows_core::HRESULT {
unsafe {
(windows_core::Interface::vtable(self).Prev)(
windows_core::Interface::as_raw(self),
celt,
core::mem::transmute(rgelt),
rgelt.len().try_into().unwrap(),
core::mem::transmute(rgelt.as_ptr()),
pceltfetched as _,
)
.ok()
}
}
pub unsafe fn Clone(&self) -> windows_core::Result<IDiaEnumSymbolsByAddr> {
Expand Down Expand Up @@ -7729,13 +7722,13 @@ pub mod Microsoft {
celt: u32,
rgelt: windows_core::OutRef<'_, IDiaSymbol>,
pceltfetched: *mut u32,
) -> windows_core::Result<()>;
) -> windows_core::HRESULT;
fn Prev(
&self,
celt: u32,
rgelt: windows_core::OutRef<'_, IDiaSymbol>,
pceltfetched: *mut u32,
) -> windows_core::Result<()>;
) -> windows_core::HRESULT;
fn Clone(&self) -> windows_core::Result<IDiaEnumSymbolsByAddr>;
}
impl IDiaEnumSymbolsByAddr_Vtbl {
Expand Down Expand Up @@ -7829,7 +7822,6 @@ pub mod Microsoft {
core::mem::transmute_copy(&rgelt),
core::mem::transmute_copy(&pceltfetched),
)
.into()
}
}
unsafe extern "system" fn Prev<
Expand All @@ -7850,7 +7842,6 @@ pub mod Microsoft {
core::mem::transmute_copy(&rgelt),
core::mem::transmute_copy(&pceltfetched),
)
.into()
}
}
unsafe extern "system" fn Clone<
Expand Down

0 comments on commit e7cb1a6

Please sign in to comment.