-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
132 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use microsoft_dia::{NameSearchOptions, SymTagData}; | ||
use windows_core::*; | ||
|
||
use crate::common::get_test_session; | ||
|
||
#[allow(dead_code)] | ||
static TEST_DATA: u32 = 42; | ||
|
||
#[test] | ||
fn symbol_properties() -> Result<()> { | ||
unsafe { | ||
let session = get_test_session()?; | ||
let symbol = session | ||
.globalScope()? | ||
.findChildren( | ||
SymTagData, | ||
w!("main::basic::TEST_DATA"), | ||
NameSearchOptions::default().0 as u32, | ||
)? | ||
.Item(0)?; | ||
|
||
assert_eq!(symbol.unalignedType()?, false); | ||
assert_eq!(symbol.constType()?, false); | ||
assert_eq!(symbol.volatileType()?, false); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use microsoft_dia::{DiaSource, IDiaDataSource, IDiaSession}; | ||
use windows_core::*; | ||
|
||
pub fn get_test_session() -> Result<IDiaSession> { | ||
unsafe { | ||
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use crate::common::get_test_session; | ||
use microsoft_dia::{nsfRegularExpression, SymTagNull}; | ||
use windows::Win32::Foundation::S_OK; | ||
use windows_core::*; | ||
|
||
#[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!("main::enumerators::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()?); | ||
} | ||
|
||
found.sort_by(|a, b| a.cmp(b)); | ||
assert_eq!( | ||
found, | ||
[ | ||
"main::enumerators::TEST_VALUE_01", | ||
"main::enumerators::TEST_VALUE_02", | ||
"main::enumerators::TEST_VALUE_03", | ||
] | ||
); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[test] | ||
fn batch_enumeration() -> Result<()> { | ||
unsafe { | ||
let session = get_test_session()?; | ||
let symbols = session.globalScope()?.findChildren( | ||
SymTagNull, | ||
w!("main::enumerators::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()), | ||
); | ||
} | ||
|
||
found.sort_by(|a, b| a.cmp(b)); | ||
assert_eq!( | ||
found, | ||
[ | ||
"main::enumerators::TEST_VALUE_01", | ||
"main::enumerators::TEST_VALUE_02", | ||
"main::enumerators::TEST_VALUE_03", | ||
] | ||
); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
mod common; | ||
|
||
mod basic; | ||
mod enumerators; |