| 1 |
// Copyright 2015 Ted Mielczarek. See the COPYRIGHT |
| 2 |
// file at the top-level directory of this distribution. |
| 3 |
|
| 4 |
use crate::*; |
| 5 |
use minidump::format::CONTEXT_X86; |
| 6 |
use minidump::system_info::{Cpu, Os}; |
| 7 |
use std::collections::HashMap; |
| 8 |
use test_assembler::*; |
| 9 |
|
| 10 |
struct TestFixture { |
| 11 |
pub raw: CONTEXT_X86, |
| 12 |
pub modules: MinidumpModuleList, |
| 13 |
pub symbols: HashMap<String, String>, |
| 14 |
} |
| 15 |
|
| 16 |
impl TestFixture { |
| 17 |
pub fn new() -> TestFixture { |
| 18 |
TestFixture { |
| 19 |
raw: CONTEXT_X86::default(), |
| 20 |
// Give the two modules reasonable standard locations and names |
| 21 |
// for tests to play with. |
| 22 |
modules: MinidumpModuleList::from_modules(vec![ |
| 23 |
MinidumpModule::new(0x40000000, 0x10000, "module1"), |
| 24 |
MinidumpModule::new(0x50000000, 0x10000, "module2"), |
| 25 |
]), |
| 26 |
symbols: HashMap::new(), |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
pub async fn walk_stack(&self, stack: Section) -> CallStack { |
| 31 |
let context = MinidumpContext { |
| 32 |
raw: MinidumpRawContext::X86(self.raw.clone()), |
| 33 |
valid: MinidumpContextValidity::All, |
| 34 |
}; |
| 35 |
let base = stack.start().value().unwrap(); |
| 36 |
let size = stack.size(); |
| 37 |
let stack = stack.get_contents().unwrap(); |
| 38 |
let stack_memory = MinidumpMemory { |
| 39 |
desc: Default::default(), |
| 40 |
base_address: base, |
| 41 |
size, |
| 42 |
bytes: &stack, |
| 43 |
endian: scroll::LE, |
| 44 |
}; |
| 45 |
let system_info = SystemInfo { |
| 46 |
os: Os::Windows, |
| 47 |
os_version: None, |
| 48 |
os_build: None, |
| 49 |
cpu: Cpu::X86, |
| 50 |
cpu_info: None, |
| 51 |
cpu_microcode_version: None, |
| 52 |
cpu_count: 1, |
| 53 |
}; |
| 54 |
let symbolizer = Symbolizer::new(string_symbol_supplier(self.symbols.clone())); |
| 55 |
let mut stack = CallStack::with_context(context); |
| 56 |
|
| 57 |
walk_stack( |
| 58 |
0, |
| 59 |
(), |
| 60 |
&mut stack, |
| 61 |
Some(UnifiedMemory::Memory(&stack_memory)), |
| 62 |
&self.modules, |
| 63 |
&system_info, |
| 64 |
&symbolizer, |
| 65 |
) |
| 66 |
.await; |
| 67 |
|
| 68 |
stack |
| 69 |
} |
| 70 |
|
| 71 |
pub fn add_symbols(&mut self, name: String, symbols: String) { |
| 72 |
self.symbols.insert(name, symbols); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
#[tokio::test] |
| 77 |
async fn test_simple() { |
| 78 |
let mut f = TestFixture::new(); |
| 79 |
let mut stack = Section::new(); |
| 80 |
stack.start().set_const(0x80000000); |
| 81 |
stack = stack.D32(0).D32(0); // end-of-stack marker |
| 82 |
f.raw.eip = 0x40000200; |
| 83 |
f.raw.ebp = 0x80000000; |
| 84 |
let s = f.walk_stack(stack).await; |
| 85 |
assert_eq!(s.frames.len(), 1); |
| 86 |
let f = &s.frames[0]; |
| 87 |
let m = f.module.as_ref().unwrap(); |
| 88 |
assert_eq!(m.code_file(), "module1"); |
| 89 |
} |
| 90 |
|
| 91 |
// Walk a traditional frame. A traditional frame saves the caller's |
| 92 |
// %ebp just below the return address, and has its own %ebp pointing |
| 93 |
// at the saved %ebp. |
| 94 |
#[tokio::test] |
| 95 |
async fn test_traditional() { |
| 96 |
let mut f = TestFixture::new(); |
| 97 |
let frame0_ebp = Label::new(); |
| 98 |
let frame1_ebp = Label::new(); |
| 99 |
let mut stack = Section::new(); |
| 100 |
stack.start().set_const(0x80000000); |
| 101 |
stack = stack |
| 102 |
.append_repeated(12, 0) // frame 0: space |
| 103 |
.mark(&frame0_ebp) // frame 0 %ebp points here |
| 104 |
.D32(&frame1_ebp) // frame 0: saved %ebp |
| 105 |
.D32(0x40008679) // frame 0: resume address |
| 106 |
.append_repeated(8, 0) // frame 1: space |
| 107 |
.mark(&frame1_ebp) // frame 1 %ebp points here |
| 108 |
.D32(0) // frame 1: saved %ebp (stack end) |
| 109 |
.D32(0); // frame 1: return address (stack end) |
| 110 |
f.raw.eip = 0x4000c7a5; |
| 111 |
f.raw.esp = stack.start().value().unwrap() as u32; |
| 112 |
f.raw.ebp = frame0_ebp.value().unwrap() as u32; |
| 113 |
let s = f.walk_stack(stack).await; |
| 114 |
assert_eq!(s.frames.len(), 2); |
| 115 |
{ |
| 116 |
let f0 = &s.frames[0]; |
| 117 |
assert_eq!(f0.trust, FrameTrust::Context); |
| 118 |
assert_eq!(f0.context.valid, MinidumpContextValidity::All); |
| 119 |
assert_eq!(f0.instruction, 0x4000c7a5); |
| 120 |
assert_eq!(f0.resume_address, 0x4000c7a5); |
| 121 |
// eip |
| 122 |
// ebp |
| 123 |
} |
| 124 |
{ |
| 125 |
let f1 = &s.frames[1]; |
| 126 |
assert_eq!(f1.trust, FrameTrust::FramePointer); |
| 127 |
// ContextValidity |
| 128 |
assert_eq!(f1.instruction, 0x40008678); |
| 129 |
assert_eq!(f1.resume_address, 0x40008679); |
| 130 |
// eip |
| 131 |
// ebp |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
// Walk a traditional frame, but use a bogus %ebp value, forcing a scan |
| 136 |
// of the stack for something that looks like a return address. |
| 137 |
#[tokio::test] |
| 138 |
async fn test_traditional_scan() { |
| 139 |
let mut f = TestFixture::new(); |
| 140 |
let frame1_esp = Label::new(); |
| 141 |
let frame1_ebp = Label::new(); |
| 142 |
let mut stack = Section::new(); |
| 143 |
let stack_start = 0x80000000; |
| 144 |
stack.start().set_const(stack_start); |
| 145 |
stack = stack |
| 146 |
// frame 0 |
| 147 |
.D32(0xf065dc76) // locals area: |
| 148 |
.D32(0x46ee2167) // garbage that doesn't look like |
| 149 |
.D32(0xbab023ec) // a return address |
| 150 |
.D32(&frame1_ebp) // saved %ebp (%ebp fails to point here, forcing scan) |
| 151 |
.D32(0x4000129d) // return address |
| 152 |
// frame 1 |
| 153 |
.mark(&frame1_esp) |
| 154 |
.append_repeated(8, 0) // space |
| 155 |
.mark(&frame1_ebp) // %ebp points here |
| 156 |
.D32(0) // saved %ebp (stack end) |
| 157 |
.D32(0); // return address (stack end) |
| 158 |
|
| 159 |
f.raw.eip = 0x4000f49d; |
| 160 |
f.raw.esp = stack.start().value().unwrap() as u32; |
| 161 |
// Make the frame pointer bogus, to make the stackwalker scan the stack |
| 162 |
// for something that looks like a return address. |
| 163 |
f.raw.ebp = 0xd43eed6e; |
| 164 |
|
| 165 |
let s = f.walk_stack(stack).await; |
| 166 |
assert_eq!(s.frames.len(), 2); |
| 167 |
|
| 168 |
{ |
| 169 |
// To avoid reusing locals by mistake |
| 170 |
let f0 = &s.frames[0]; |
| 171 |
assert_eq!(f0.trust, FrameTrust::Context); |
| 172 |
assert_eq!(f0.context.valid, MinidumpContextValidity::All); |
| 173 |
assert_eq!(f0.instruction, 0x4000f49d); |
| 174 |
assert_eq!(f0.resume_address, 0x4000f49d); |
| 175 |
|
| 176 |
if let MinidumpRawContext::X86(ctx) = &f0.context.raw { |
| 177 |
assert_eq!(ctx.eip, 0x4000f49d); |
| 178 |
assert_eq!(ctx.esp, stack_start as u32); |
| 179 |
assert_eq!(ctx.ebp, 0xd43eed6e); |
| 180 |
} else { |
| 181 |
unreachable!(); |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
{ |
| 186 |
// To avoid reusing locals by mistake |
| 187 |
let f1 = &s.frames[1]; |
| 188 |
assert_eq!(f1.trust, FrameTrust::Scan); |
| 189 |
if let MinidumpContextValidity::Some(ref which) = f1.context.valid { |
| 190 |
assert!(which.contains("eip")); |
| 191 |
assert!(which.contains("esp")); |
| 192 |
assert!(which.contains("ebp")); |
| 193 |
} else { |
| 194 |
unreachable!(); |
| 195 |
} |
| 196 |
assert_eq!(f1.instruction + 1, 0x4000129d); |
| 197 |
assert_eq!(f1.resume_address, 0x4000129d); |
| 198 |
|
| 199 |
if let MinidumpRawContext::X86(ctx) = &f1.context.raw { |
| 200 |
assert_eq!(ctx.eip, 0x4000129d); |
| 201 |
assert_eq!(ctx.esp, frame1_esp.value().unwrap() as u32); |
| 202 |
assert_eq!(ctx.ebp, frame1_ebp.value().unwrap() as u32); |
| 203 |
} else { |
| 204 |
unreachable!(); |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
// Force scanning for a return address a long way down the stack |
| 210 |
#[tokio::test] |
| 211 |
async fn test_traditional_scan_long_way() { |
| 212 |
let mut f = TestFixture::new(); |
| 213 |
let frame1_esp = Label::new(); |
| 214 |
let frame1_ebp = Label::new(); |
| 215 |
let mut stack = Section::new(); |
| 216 |
let stack_start = 0x80000000; |
| 217 |
stack.start().set_const(stack_start); |
| 218 |
|
| 219 |
stack = stack |
| 220 |
// frame 0 |
| 221 |
.D32(0xf065dc76) // locals area: |
| 222 |
.D32(0x46ee2167) // garbage that doesn't look like |
| 223 |
.D32(0xbab023ec) // a return address |
| 224 |
.append_repeated(20 * 4, 0) // a bunch of space |
| 225 |
.D32(&frame1_ebp) // saved %ebp (%ebp fails to point here, forcing scan) |
| 226 |
.D32(0x4000129d) // return address |
| 227 |
// frame 1 |
| 228 |
.mark(&frame1_esp) |
| 229 |
.append_repeated(8, 0) // space |
| 230 |
.mark(&frame1_ebp) // %ebp points here |
| 231 |
.D32(0) // saved %ebp (stack end) |
| 232 |
.D32(0); // return address (stack end) |
| 233 |
|
| 234 |
f.raw.eip = 0x4000f49d; |
| 235 |
f.raw.esp = stack.start().value().unwrap() as u32; |
| 236 |
// Make the frame pointer bogus, to make the stackwalker scan the stack |
| 237 |
// for something that looks like a return address. |
| 238 |
f.raw.ebp = 0xd43eed6e; |
| 239 |
|
| 240 |
let s = f.walk_stack(stack).await; |
| 241 |
assert_eq!(s.frames.len(), 2); |
| 242 |
|
| 243 |
{ |
| 244 |
// To avoid reusing locals by mistake |
| 245 |
let f0 = &s.frames[0]; |
| 246 |
assert_eq!(f0.trust, FrameTrust::Context); |
| 247 |
assert_eq!(f0.context.valid, MinidumpContextValidity::All); |
| 248 |
assert_eq!(f0.instruction, 0x4000f49d); |
| 249 |
|
| 250 |
if let MinidumpRawContext::X86(ctx) = &f0.context.raw { |
| 251 |
assert_eq!(ctx.eip, 0x4000f49d); |
| 252 |
assert_eq!(ctx.esp, stack_start as u32); |
| 253 |
assert_eq!(ctx.ebp, 0xd43eed6e); |
| 254 |
} else { |
| 255 |
unreachable!(); |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
{ |
| 260 |
// To avoid reusing locals by mistake |
| 261 |
let f1 = &s.frames[1]; |
| 262 |
assert_eq!(f1.trust, FrameTrust::Scan); |
| 263 |
if let MinidumpContextValidity::Some(ref which) = f1.context.valid { |
| 264 |
assert!(which.contains("eip")); |
| 265 |
assert!(which.contains("esp")); |
| 266 |
assert!(which.contains("ebp")); |
| 267 |
} else { |
| 268 |
unreachable!(); |
| 269 |
} |
| 270 |
assert_eq!(f1.instruction + 1, 0x4000129d); |
| 271 |
|
| 272 |
if let MinidumpRawContext::X86(ctx) = &f1.context.raw { |
| 273 |
assert_eq!(ctx.eip, 0x4000129d); |
| 274 |
assert_eq!(ctx.esp, frame1_esp.value().unwrap() as u32); |
| 275 |
assert_eq!(ctx.ebp, frame1_ebp.value().unwrap() as u32); |
| 276 |
} else { |
| 277 |
unreachable!(); |
| 278 |
} |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
const CALLEE_SAVE_REGS: &[&str] = &["eip", "esp", "ebp", "ebx", "edi", "esi"]; |
| 283 |
|
| 284 |
fn init_cfi_state() -> (TestFixture, Section, CONTEXT_X86, MinidumpContextValidity) { |
| 285 |
let mut f = TestFixture::new(); |
| 286 |
let symbols = [ |
| 287 |
// The youngest frame's function. |
| 288 |
"FUNC 4000 1000 10 enchiridion\n", |
| 289 |
// Initially, just a return address. |
| 290 |
"STACK CFI INIT 4000 100 .cfa: $esp 4 + .ra: .cfa 4 - ^\n", |
| 291 |
// Push %ebx. |
| 292 |
"STACK CFI 4001 .cfa: $esp 8 + $ebx: .cfa 8 - ^\n", |
| 293 |
// Move %esi into %ebx. Weird, but permitted. |
| 294 |
"STACK CFI 4002 $esi: $ebx\n", |
| 295 |
// Allocate frame space, and save %edi. |
| 296 |
"STACK CFI 4003 .cfa: $esp 20 + $edi: .cfa 16 - ^\n", |
| 297 |
// Put the return address in %edi. |
| 298 |
"STACK CFI 4005 .ra: $edi\n", |
| 299 |
// Save %ebp, and use it as a frame pointer. |
| 300 |
"STACK CFI 4006 .cfa: $ebp 8 + $ebp: .cfa 12 - ^\n", |
| 301 |
// The calling function. |
| 302 |
"FUNC 5000 1000 10 epictetus\n", |
| 303 |
// Mark it as end of stack. |
| 304 |
"STACK CFI INIT 5000 1000 .cfa: $esp .ra 0\n", |
| 305 |
]; |
| 306 |
f.add_symbols(String::from("module1"), symbols.concat()); |
| 307 |
|
| 308 |
f.raw.set_register("esp", 0x80000000); |
| 309 |
f.raw.set_register("eip", 0x40005510); |
| 310 |
f.raw.set_register("ebp", 0xc0d4aab9); |
| 311 |
f.raw.set_register("ebx", 0x60f20ce6); |
| 312 |
f.raw.set_register("esi", 0x53d1379d); |
| 313 |
f.raw.set_register("edi", 0xafbae234); |
| 314 |
|
| 315 |
let raw_valid = MinidumpContextValidity::All; |
| 316 |
|
| 317 |
let expected = f.raw.clone(); |
| 318 |
let expected_regs = CALLEE_SAVE_REGS; |
| 319 |
let expected_valid = MinidumpContextValidity::Some(expected_regs.iter().copied().collect()); |
| 320 |
|
| 321 |
let stack = Section::new(); |
| 322 |
stack |
| 323 |
.start() |
| 324 |
.set_const(f.raw.get_register("esp", &raw_valid).unwrap() as u64); |
| 325 |
|
| 326 |
(f, stack, expected, expected_valid) |
| 327 |
} |
| 328 |
|
| 329 |
async fn check_cfi( |
| 330 |
f: TestFixture, |
| 331 |
stack: Section, |
| 332 |
expected: CONTEXT_X86, |
| 333 |
expected_valid: MinidumpContextValidity, |
| 334 |
) { |
| 335 |
let s = f.walk_stack(stack).await; |
| 336 |
assert_eq!(s.frames.len(), 2); |
| 337 |
|
| 338 |
{ |
| 339 |
// Frame 0 |
| 340 |
let frame = &s.frames[0]; |
| 341 |
assert_eq!(frame.trust, FrameTrust::Context); |
| 342 |
assert_eq!(frame.context.valid, MinidumpContextValidity::All); |
| 343 |
} |
| 344 |
|
| 345 |
{ |
| 346 |
// Frame 1 |
| 347 |
if let MinidumpContextValidity::Some(ref expected_regs) = expected_valid { |
| 348 |
let frame = &s.frames[1]; |
| 349 |
let valid = &frame.context.valid; |
| 350 |
assert_eq!(frame.trust, FrameTrust::CallFrameInfo); |
| 351 |
if let MinidumpContextValidity::Some(ref which) = valid { |
| 352 |
assert_eq!(which.len(), expected_regs.len()); |
| 353 |
} else { |
| 354 |
unreachable!(); |
| 355 |
} |
| 356 |
|
| 357 |
if let MinidumpRawContext::X86(ctx) = &frame.context.raw { |
| 358 |
for reg in expected_regs { |
| 359 |
assert_eq!( |
| 360 |
ctx.get_register(reg, valid), |
| 361 |
expected.get_register(reg, &expected_valid), |
| 362 |
"{reg} registers didn't match!" |
| 363 |
); |
| 364 |
} |
| 365 |
return; |
| 366 |
} |
| 367 |
} |
| 368 |
} |
| 369 |
unreachable!(); |
| 370 |
} |
| 371 |
|
| 372 |
#[tokio::test] |
| 373 |
async fn test_cfi_at_4000() { |
| 374 |
let (mut f, mut stack, mut expected, expected_valid) = init_cfi_state(); |
| 375 |
|
| 376 |
let frame1_rsp = Label::new(); |
| 377 |
stack = stack |
| 378 |
.D32(0x40005510) // return address |
| 379 |
.mark(&frame1_rsp) |
| 380 |
.append_repeated(0, 1000); |
| 381 |
|
| 382 |
expected.set_register("esp", frame1_rsp.value().unwrap() as u32); |
| 383 |
f.raw.set_register("eip", 0x40004000); |
| 384 |
|
| 385 |
check_cfi(f, stack, expected, expected_valid).await; |
| 386 |
} |
| 387 |
|
| 388 |
#[tokio::test] |
| 389 |
async fn test_cfi_at_4001() { |
| 390 |
let (mut f, mut stack, mut expected, expected_valid) = init_cfi_state(); |
| 391 |
|
| 392 |
let frame1_rsp = Label::new(); |
| 393 |
stack = stack |
| 394 |
.D32(0x60f20ce6) // saved %ebx |
| 395 |
.D32(0x40005510) // return address |
| 396 |
.mark(&frame1_rsp) |
| 397 |
.append_repeated(0, 1000); |
| 398 |
|
| 399 |
expected.set_register("esp", frame1_rsp.value().unwrap() as u32); |
| 400 |
f.raw.set_register("eip", 0x40004001); |
| 401 |
f.raw.set_register("ebx", 0x91aa9a8b); |
| 402 |
|
| 403 |
check_cfi(f, stack, expected, expected_valid).await; |
| 404 |
} |
| 405 |
|
| 406 |
#[tokio::test] |
| 407 |
async fn test_cfi_at_4002() { |
| 408 |
let (mut f, mut stack, mut expected, expected_valid) = init_cfi_state(); |
| 409 |
|
| 410 |
let frame1_rsp = Label::new(); |
| 411 |
stack = stack |
| 412 |
.D32(0x60f20ce6) // saved %ebx |
| 413 |
.D32(0x40005510) // return address |
| 414 |
.mark(&frame1_rsp) |
| 415 |
.append_repeated(0, 1000); |
| 416 |
|
| 417 |
expected.set_register("esp", frame1_rsp.value().unwrap() as u32); |
| 418 |
f.raw.set_register("eip", 0x40004002); |
| 419 |
f.raw.set_register("ebx", 0x53d1379d); |
| 420 |
f.raw.set_register("esi", 0xa5c790ed); |
| 421 |
|
| 422 |
check_cfi(f, stack, expected, expected_valid).await; |
| 423 |
} |
| 424 |
|
| 425 |
#[tokio::test] |
| 426 |
async fn test_cfi_at_4003() { |
| 427 |
let (mut f, mut stack, mut expected, expected_valid) = init_cfi_state(); |
| 428 |
|
| 429 |
let frame1_rsp = Label::new(); |
| 430 |
stack = stack |
| 431 |
.D32(0x56ec3db7) // garbage |
| 432 |
.D32(0xafbae234) // saved %edi |
| 433 |
.D32(0x53d67131) // garbage |
| 434 |
.D32(0x60f20ce6) // saved %ebx |
| 435 |
.D32(0x40005510) // return address |
| 436 |
.mark(&frame1_rsp) |
| 437 |
.append_repeated(0, 1000); |
| 438 |
|
| 439 |
expected.set_register("esp", frame1_rsp.value().unwrap() as u32); |
| 440 |
f.raw.set_register("eip", 0x40004003); |
| 441 |
f.raw.set_register("ebx", 0x53d1379d); |
| 442 |
f.raw.set_register("esi", 0xa97f229d); |
| 443 |
f.raw.set_register("edi", 0xb05cc997); |
| 444 |
|
| 445 |
check_cfi(f, stack, expected, expected_valid).await; |
| 446 |
} |
| 447 |
|
| 448 |
#[tokio::test] |
| 449 |
async fn test_cfi_at_4004() { |
| 450 |
// Should be the same as 4003 |
| 451 |
let (mut f, mut stack, mut expected, expected_valid) = init_cfi_state(); |
| 452 |
|
| 453 |
let frame1_rsp = Label::new(); |
| 454 |
stack = stack |
| 455 |
.D32(0x56ec3db7) // garbage |
| 456 |
.D32(0xafbae234) // saved %edi |
| 457 |
.D32(0x53d67131) // garbage |
| 458 |
.D32(0x60f20ce6) // saved %ebx |
| 459 |
.D32(0x40005510) // return address |
| 460 |
.mark(&frame1_rsp) |
| 461 |
.append_repeated(0, 1000); |
| 462 |
|
| 463 |
expected.set_register("esp", frame1_rsp.value().unwrap() as u32); |
| 464 |
f.raw.set_register("eip", 0x40004004); |
| 465 |
f.raw.set_register("ebx", 0x53d1379d); |
| 466 |
f.raw.set_register("esi", 0xa97f229d); |
| 467 |
f.raw.set_register("edi", 0xb05cc997); |
| 468 |
|
| 469 |
check_cfi(f, stack, expected, expected_valid).await; |
| 470 |
} |
| 471 |
|
| 472 |
#[tokio::test] |
| 473 |
async fn test_cfi_at_4005() { |
| 474 |
let (mut f, mut stack, mut expected, expected_valid) = init_cfi_state(); |
| 475 |
|
| 476 |
let frame1_rsp = Label::new(); |
| 477 |
stack = stack |
| 478 |
.D32(0xe29782c2) // garbage |
| 479 |
.D32(0xafbae234) // saved %edi |
| 480 |
.D32(0x5ba29ce9) // garbage |
| 481 |
.D32(0x60f20ce6) // saved %ebx |
| 482 |
.D32(0x8036cc02) // garbage |
| 483 |
.mark(&frame1_rsp) |
| 484 |
.append_repeated(0, 1000); |
| 485 |
|
| 486 |
expected.set_register("esp", frame1_rsp.value().unwrap() as u32); |
| 487 |
f.raw.set_register("eip", 0x40004005); |
| 488 |
f.raw.set_register("ebx", 0x53d1379d); |
| 489 |
f.raw.set_register("esi", 0x0fb7dc4e); |
| 490 |
f.raw.set_register("edi", 0x40005510); |
| 491 |
|
| 492 |
check_cfi(f, stack, expected, expected_valid).await; |
| 493 |
} |
| 494 |
|
| 495 |
#[tokio::test] |
| 496 |
async fn test_cfi_at_4006() { |
| 497 |
let (mut f, mut stack, mut expected, expected_valid) = init_cfi_state(); |
| 498 |
|
| 499 |
let frame0_ebp = Label::new(); |
| 500 |
let frame1_rsp = Label::new(); |
| 501 |
stack = stack |
| 502 |
.D32(0xdcdd25cd) // garbage |
| 503 |
.D32(0xafbae234) // saved %edi |
| 504 |
.D32(0xc0d4aab9) // saved %ebp |
| 505 |
.mark(&frame0_ebp) // frame pointer points here |
| 506 |
.D32(0x60f20ce6) // saved %ebx |
| 507 |
.D32(0x8036cc02) // garbage |
| 508 |
.mark(&frame1_rsp) |
| 509 |
.append_repeated(0, 1000); |
| 510 |
|
| 511 |
expected.set_register("esp", frame1_rsp.value().unwrap() as u32); |
| 512 |
f.raw |
| 513 |
.set_register("ebp", frame0_ebp.value().unwrap() as u32); |
| 514 |
f.raw.set_register("eip", 0x40004006); |
| 515 |
f.raw.set_register("ebx", 0x53d1379d); |
| 516 |
f.raw.set_register("esi", 0x743833c9); |
| 517 |
f.raw.set_register("edi", 0x40005510); |
| 518 |
|
| 519 |
check_cfi(f, stack, expected, expected_valid).await; |
| 520 |
} |
| 521 |
|
| 522 |
// Totally basic STACK WIN frame data, no weird stuff. |
| 523 |
#[tokio::test] |
| 524 |
async fn test_stack_win_frame_data_basic() { |
| 525 |
let mut f = TestFixture::new(); |
| 526 |
let symbols = [ |
| 527 |
"STACK WIN 4 aa85 176 0 0 4 10 4 0 1", |
| 528 |
" $T2 $esp .cbSavedRegs + =", |
| 529 |
" $T0 .raSearchStart =", |
| 530 |
" $eip $T0 ^ =", |
| 531 |
" $esp $T0 4 + =", |
| 532 |
" $ebx $T2 4 - ^ =", |
| 533 |
" $edi $T2 8 - ^ =", |
| 534 |
" $esi $T2 12 - ^ =", |
| 535 |
" $ebp $T2 16 - ^ =\n", |
| 536 |
]; |
| 537 |
f.add_symbols(String::from("module1"), symbols.concat()); |
| 538 |
|
| 539 |
let frame1_esp = Label::new(); |
| 540 |
let frame1_ebp = Label::new(); |
| 541 |
|
| 542 |
let mut stack = Section::new(); |
| 543 |
let stack_start = 0x80000000; |
| 544 |
stack.start().set_const(stack_start); |
| 545 |
|
| 546 |
stack = stack |
| 547 |
// frame 0 |
| 548 |
.D32(&frame1_ebp) // saved regs: %ebp |
| 549 |
.D32(0xa7120d1a) // %esi |
| 550 |
.D32(0x630891be) // %edi |
| 551 |
.D32(0x9068a878) // %ebx |
| 552 |
.D32(0xa08ea45f) // locals: unused |
| 553 |
.D32(0x40001350) // return address |
| 554 |
// frame 1 |
| 555 |
.mark(&frame1_esp) |
| 556 |
.append_repeated(0, 12) // empty space |
| 557 |
.mark(&frame1_ebp) |
| 558 |
.D32(0) // saved %ebp (stack end) |
| 559 |
.D32(0); // saved %eip (stack end) |
| 560 |
|
| 561 |
f.raw.set_register("eip", 0x4000aa85); |
| 562 |
f.raw |
| 563 |
.set_register("esp", stack.start().value().unwrap() as u32); |
| 564 |
f.raw.set_register("ebp", 0xf052c1de); |
| 565 |
|
| 566 |
let s = f.walk_stack(stack).await; |
| 567 |
assert_eq!(s.frames.len(), 2); |
| 568 |
|
| 569 |
{ |
| 570 |
let f0 = &s.frames[0]; |
| 571 |
assert_eq!(f0.trust, FrameTrust::Context); |
| 572 |
assert_eq!(f0.context.valid, MinidumpContextValidity::All); |
| 573 |
assert_eq!(f0.instruction, 0x4000aa85); |
| 574 |
|
| 575 |
if let MinidumpRawContext::X86(ctx) = &f0.context.raw { |
| 576 |
assert_eq!(ctx.eip, 0x4000aa85); |
| 577 |
assert_eq!(ctx.esp, stack_start as u32); |
| 578 |
assert_eq!(ctx.ebp, 0xf052c1de); |
| 579 |
} else { |
| 580 |
unreachable!(); |
| 581 |
} |
| 582 |
} |
| 583 |
|
| 584 |
{ |
| 585 |
let f1 = &s.frames[1]; |
| 586 |
assert_eq!(f1.trust, FrameTrust::CallFrameInfo); |
| 587 |
if let MinidumpContextValidity::Some(ref which) = f1.context.valid { |
| 588 |
assert!(which.contains("eip")); |
| 589 |
assert!(which.contains("esp")); |
| 590 |
assert!(which.contains("ebp")); |
| 591 |
assert!(which.contains("ebx")); |
| 592 |
assert!(which.contains("esi")); |
| 593 |
assert!(which.contains("edi")); |
| 594 |
} else { |
| 595 |
unreachable!(); |
| 596 |
} |
| 597 |
assert_eq!(f1.instruction + 1, 0x40001350); |
| 598 |
|
| 599 |
if let MinidumpRawContext::X86(ctx) = &f1.context.raw { |
| 600 |
assert_eq!(ctx.eip, 0x40001350); |
| 601 |
assert_eq!(ctx.esp, frame1_esp.value().unwrap() as u32); |
| 602 |
assert_eq!(ctx.ebp, frame1_ebp.value().unwrap() as u32); |
| 603 |
assert_eq!(ctx.ebx, 0x9068a878); |
| 604 |
assert_eq!(ctx.esi, 0xa7120d1a); |
| 605 |
assert_eq!(ctx.edi, 0x630891be); |
| 606 |
} else { |
| 607 |
unreachable!(); |
| 608 |
} |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
// Totally basic STACK WIN frame data, no weird stuff. |
| 613 |
#[tokio::test] |
| 614 |
async fn test_stack_win_frame_data_overlapping() { |
| 615 |
// Same as frame_data_basic but there are extra entries which technically overlap |
| 616 |
// with this one, but in a way that is easily disambiguated by preferring the |
| 617 |
// one with the higher base address. This happens frequently in real symbol files. |
| 618 |
let mut f = TestFixture::new(); |
| 619 |
let symbols = [ |
| 620 |
// Entry that covers the "whole" function (junk!) |
| 621 |
"STACK WIN 4 aa80 181 0 0 4 10 4 0 1", |
| 622 |
" $eip .raSearchStart =\n", |
| 623 |
// More precise (still junk!) |
| 624 |
"STACK WIN 4 aa84 177 0 0 4 10 4 0 1", |
| 625 |
" $eip .raSearchStart =\n", |
| 626 |
// This is the one we want!!! |
| 627 |
"STACK WIN 4 aa85 176 0 0 4 10 4 0 1", |
| 628 |
" $T2 $esp .cbSavedRegs + =", |
| 629 |
" $T0 .raSearchStart =", |
| 630 |
" $eip $T0 ^ =", |
| 631 |
" $esp $T0 4 + =", |
| 632 |
" $ebx $T2 4 - ^ =", |
| 633 |
" $edi $T2 8 - ^ =", |
| 634 |
" $esi $T2 12 - ^ =", |
| 635 |
" $ebp $T2 16 - ^ =\n", |
| 636 |
// An even more precise one but past the address we care about (junk!) |
| 637 |
"STACK WIN 4 aa86 175 0 0 4 10 4 0 1", |
| 638 |
" $eip .raSearchStart =\n", |
| 639 |
]; |
| 640 |
f.add_symbols(String::from("module1"), symbols.concat()); |
| 641 |
|
| 642 |
let frame1_esp = Label::new(); |
| 643 |
let frame1_ebp = Label::new(); |
| 644 |
|
| 645 |
let mut stack = Section::new(); |
| 646 |
let stack_start = 0x80000000; |
| 647 |
stack.start().set_const(stack_start); |
| 648 |
|
| 649 |
stack = stack |
| 650 |
// frame 0 |
| 651 |
.D32(&frame1_ebp) // saved regs: %ebp |
| 652 |
.D32(0xa7120d1a) // %esi |
| 653 |
.D32(0x630891be) // %edi |
| 654 |
.D32(0x9068a878) // %ebx |
| 655 |
.D32(0xa08ea45f) // locals: unused |
| 656 |
.D32(0x40001350) // return address |
| 657 |
// frame 1 |
| 658 |
.mark(&frame1_esp) |
| 659 |
.append_repeated(0, 12) // empty space |
| 660 |
.mark(&frame1_ebp) |
| 661 |
.D32(0) // saved %ebp (stack end) |
| 662 |
.D32(0); // saved %eip (stack end) |
| 663 |
|
| 664 |
f.raw.set_register("eip", 0x4000aa85); |
| 665 |
f.raw |
| 666 |
.set_register("esp", stack.start().value().unwrap() as u32); |
| 667 |
f.raw.set_register("ebp", 0xf052c1de); |
| 668 |
|
| 669 |
let s = f.walk_stack(stack).await; |
| 670 |
assert_eq!(s.frames.len(), 2); |
| 671 |
|
| 672 |
{ |
| 673 |
let f0 = &s.frames[0]; |
| 674 |
assert_eq!(f0.trust, FrameTrust::Context); |
| 675 |
assert_eq!(f0.context.valid, MinidumpContextValidity::All); |
| 676 |
assert_eq!(f0.instruction, 0x4000aa85); |
| 677 |
|
| 678 |
if let MinidumpRawContext::X86(ctx) = &f0.context.raw { |
| 679 |
assert_eq!(ctx.eip, 0x4000aa85); |
| 680 |
assert_eq!(ctx.esp, stack_start as u32); |
| 681 |
assert_eq!(ctx.ebp, 0xf052c1de); |
| 682 |
} else { |
| 683 |
unreachable!(); |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
{ |
| 688 |
let f1 = &s.frames[1]; |
| 689 |
assert_eq!(f1.trust, FrameTrust::CallFrameInfo); |
| 690 |
if let MinidumpContextValidity::Some(ref which) = f1.context.valid { |
| 691 |
assert!(which.contains("eip")); |
| 692 |
assert!(which.contains("esp")); |
| 693 |
assert!(which.contains("ebp")); |
| 694 |
assert!(which.contains("ebx")); |
| 695 |
assert!(which.contains("esi")); |
| 696 |
assert!(which.contains("edi")); |
| 697 |
} else { |
| 698 |
unreachable!(); |
| 699 |
} |
| 700 |
assert_eq!(f1.instruction + 1, 0x40001350); |
| 701 |
|
| 702 |
if let MinidumpRawContext::X86(ctx) = &f1.context.raw { |
| 703 |
assert_eq!(ctx.eip, 0x40001350); |
| 704 |
assert_eq!(ctx.esp, frame1_esp.value().unwrap() as u32); |
| 705 |
assert_eq!(ctx.ebp, frame1_ebp.value().unwrap() as u32); |
| 706 |
assert_eq!(ctx.ebx, 0x9068a878); |
| 707 |
assert_eq!(ctx.esi, 0xa7120d1a); |
| 708 |
assert_eq!(ctx.edi, 0x630891be); |
| 709 |
} else { |
| 710 |
unreachable!(); |
| 711 |
} |
| 712 |
} |
| 713 |
} |
| 714 |
|
| 715 |
// Testing that grand_callee_parameter_size is properly computed. |
| 716 |
#[tokio::test] |
| 717 |
async fn test_stack_win_frame_data_parameter_size() { |
| 718 |
let mut f = TestFixture::new(); |
| 719 |
|
| 720 |
let module1_symbols = ["FUNC 1000 100 c module1::wheedle\n"]; |
| 721 |
|
| 722 |
let module2_symbols = [ |
| 723 |
// Note bogus parameter size in FUNC record; the stack walker |
| 724 |
// should prefer the STACK WIN record, and see '4' below. |
| 725 |
"FUNC aa85 176 beef module2::whine\n", |
| 726 |
"STACK WIN 4 aa85 176 0 0 4 10 4 0 1", |
| 727 |
" $T2 $esp .cbLocals + .cbSavedRegs + =", |
| 728 |
" $T0 .raSearchStart =", |
| 729 |
" $eip $T0 ^ =", |
| 730 |
" $esp $T0 4 + =", |
| 731 |
" $ebp $T0 20 - ^ =", |
| 732 |
" $ebx $T0 8 - ^ =\n", |
| 733 |
]; |
| 734 |
f.add_symbols(String::from("module1"), module1_symbols.concat()); |
| 735 |
f.add_symbols(String::from("module2"), module2_symbols.concat()); |
| 736 |
|
| 737 |
let frame0_esp = Label::new(); |
| 738 |
let frame0_ebp = Label::new(); |
| 739 |
let frame1_esp = Label::new(); |
| 740 |
let frame2_esp = Label::new(); |
| 741 |
let frame2_ebp = Label::new(); |
| 742 |
|
| 743 |
let mut stack = Section::new(); |
| 744 |
let stack_start = 0x80000000; |
| 745 |
stack.start().set_const(stack_start); |
| 746 |
|
| 747 |
stack = stack |
| 748 |
// frame 0, in module1::wheedle. Traditional frame. |
| 749 |
.mark(&frame0_esp) |
| 750 |
.append_repeated(0, 16) // frame space |
| 751 |
.mark(&frame0_ebp) |
| 752 |
.D32(0x6fa902e0) // saved %ebp. Not a frame pointer. |
| 753 |
.D32(0x5000aa95) // return address, in module2::whine |
| 754 |
// frame 1, in module2::whine. FrameData frame. |
| 755 |
.mark(&frame1_esp) |
| 756 |
.D32(0xbaa0cb7a) // argument 3 passed to module1::wheedle |
| 757 |
.D32(0xbdc92f9f) // argument 2 |
| 758 |
.D32(0x0b1d8442) // argument 1 |
| 759 |
.D32(&frame2_ebp) // saved %ebp |
| 760 |
.D32(0xb1b90a15) // unused |
| 761 |
.D32(0xf18e072d) // unused |
| 762 |
.D32(0x2558c7f3) // saved %ebx |
| 763 |
.D32(0x0365e25e) // unused |
| 764 |
.D32(0x2a179e38) // return address; $T0 points here |
| 765 |
// frame 2, in no module |
| 766 |
.mark(&frame2_esp) |
| 767 |
.append_repeated(0, 12) // empty space |
| 768 |
.mark(&frame2_ebp) |
| 769 |
.D32(0) // saved %ebp (stack end) |
| 770 |
.D32(0); // saved %eip (stack end) |
| 771 |
|
| 772 |
f.raw.set_register("eip", 0x40001004); |
| 773 |
f.raw |
| 774 |
.set_register("esp", stack.start().value().unwrap() as u32); |
| 775 |
f.raw |
| 776 |
.set_register("ebp", frame0_ebp.value().unwrap() as u32); |
| 777 |
|
| 778 |
let s = f.walk_stack(stack).await; |
| 779 |
assert_eq!(s.frames.len(), 3); |
| 780 |
|
| 781 |
{ |
| 782 |
let f0 = &s.frames[0]; |
| 783 |
assert_eq!(f0.trust, FrameTrust::Context); |
| 784 |
assert_eq!(f0.context.valid, MinidumpContextValidity::All); |
| 785 |
assert_eq!(f0.instruction, 0x40001004); |
| 786 |
|
| 787 |
if let MinidumpRawContext::X86(ctx) = &f0.context.raw { |
| 788 |
assert_eq!(ctx.eip, 0x40001004); |
| 789 |
assert_eq!(ctx.esp, frame0_esp.value().unwrap() as u32); |
| 790 |
assert_eq!(ctx.ebp, frame0_ebp.value().unwrap() as u32); |
| 791 |
} else { |
| 792 |
unreachable!(); |
| 793 |
} |
| 794 |
} |
| 795 |
|
| 796 |
{ |
| 797 |
let f1 = &s.frames[1]; |
| 798 |
assert_eq!(f1.trust, FrameTrust::FramePointer); |
| 799 |
if let MinidumpContextValidity::Some(ref which) = f1.context.valid { |
| 800 |
assert!(which.contains("eip")); |
| 801 |
assert!(which.contains("esp")); |
| 802 |
assert!(which.contains("ebp")); |
| 803 |
} else { |
| 804 |
unreachable!(); |
| 805 |
} |
| 806 |
assert_eq!(f1.instruction + 1, 0x5000aa95); |
| 807 |
|
| 808 |
if let MinidumpRawContext::X86(ctx) = &f1.context.raw { |
| 809 |
assert_eq!(ctx.eip, 0x5000aa95); |
| 810 |
assert_eq!(ctx.esp, frame1_esp.value().unwrap() as u32); |
| 811 |
assert_eq!(ctx.ebp, 0x6fa902e0); |
| 812 |
} else { |
| 813 |
unreachable!(); |
| 814 |
} |
| 815 |
} |
| 816 |
|
| 817 |
{ |
| 818 |
let f2 = &s.frames[2]; |
| 819 |
assert_eq!(f2.trust, FrameTrust::CallFrameInfo); |
| 820 |
if let MinidumpContextValidity::Some(ref which) = f2.context.valid { |
| 821 |
assert!(which.contains("eip")); |
| 822 |
assert!(which.contains("esp")); |
| 823 |
assert!(which.contains("ebp")); |
| 824 |
assert!(which.contains("ebx")); |
| 825 |
} else { |
| 826 |
unreachable!(); |
| 827 |
} |
| 828 |
assert_eq!(f2.instruction + 1, 0x2a179e38); |
| 829 |
|
| 830 |
if let MinidumpRawContext::X86(ctx) = &f2.context.raw { |
| 831 |
assert_eq!(ctx.eip, 0x2a179e38); |
| 832 |
assert_eq!(ctx.esp, frame2_esp.value().unwrap() as u32); |
| 833 |
assert_eq!(ctx.ebp, frame2_ebp.value().unwrap() as u32); |
| 834 |
assert_eq!(ctx.ebx, 0x2558c7f3); |
| 835 |
} else { |
| 836 |
unreachable!(); |
| 837 |
} |
| 838 |
} |
| 839 |
} |
| 840 |
|
| 841 |
#[tokio::test] |
| 842 |
async fn test_frame_pointer_overflow() { |
| 843 |
// Make sure we don't explode when trying frame pointer analysis on a value |
| 844 |
// that will overflow. |
| 845 |
|
| 846 |
type Pointer = u32; |
| 847 |
let stack_max: Pointer = Pointer::MAX; |
| 848 |
let stack_size: Pointer = 1000; |
| 849 |
let bad_frame_ptr: Pointer = stack_max; |
| 850 |
|
| 851 |
let mut f = TestFixture::new(); |
| 852 |
let mut stack = Section::new(); |
| 853 |
let stack_start: Pointer = stack_max - stack_size; |
| 854 |
stack.start().set_const(stack_start as u64); |
| 855 |
|
| 856 |
stack = stack |
| 857 |
// frame 0 |
| 858 |
.append_repeated(0, stack_size as usize); // junk, not important to the test |
| 859 |
|
| 860 |
f.raw.eip = 0x7a100000; |
| 861 |
f.raw.ebp = bad_frame_ptr; |
| 862 |
f.raw.esp = stack.start().value().unwrap() as Pointer; |
| 863 |
|
| 864 |
let s = f.walk_stack(stack).await; |
| 865 |
assert_eq!(s.frames.len(), 1); |
| 866 |
|
| 867 |
// As long as we don't panic, we're good! |
| 868 |
} |
| 869 |
|
| 870 |
#[tokio::test] |
| 871 |
async fn test_frame_pointer_overflow_nonsense_32bit_stack() { |
| 872 |
// same as test_frame_pointer_overflow, but we're going to abuse the fact |
| 873 |
// that rust-minidump prefers representing things in 64-bit to create |
| 874 |
// impossible stack addresses that overflow 32-bit integers but appear |
| 875 |
// valid in 64-bit. By doing this memory reads will "succeed" but |
| 876 |
// pointer math done in the native pointer width will overflow and |
| 877 |
// everything will be sad. |
| 878 |
|
| 879 |
type Pointer = u32; |
| 880 |
let pointer_size: u64 = std::mem::size_of::<Pointer>() as u64; |
| 881 |
let stack_max: u64 = Pointer::MAX as u64 + pointer_size * 2; |
| 882 |
let stack_size: u64 = 1000; |
| 883 |
let bad_frame_ptr: u64 = Pointer::MAX as u64 - pointer_size; |
| 884 |
|
| 885 |
let mut f = TestFixture::new(); |
| 886 |
let mut stack = Section::new(); |
| 887 |
let stack_start: u64 = stack_max - stack_size; |
| 888 |
stack.start().set_const(stack_start); |
| 889 |
|
| 890 |
stack = stack |
| 891 |
// frame 0 |
| 892 |
.append_repeated(0, 1000); // junk, not important to the test |
| 893 |
|
| 894 |
f.raw.eip = 0x7a100000; |
| 895 |
f.raw.ebp = bad_frame_ptr as u32; |
| 896 |
f.raw.esp = stack.start().value().unwrap() as Pointer; |
| 897 |
|
| 898 |
let s = f.walk_stack(stack).await; |
| 899 |
assert_eq!(s.frames.len(), 1); |
| 900 |
|
| 901 |
// As long as we don't panic, we're good! |
| 902 |
} |
| 903 |
|
| 904 |
#[tokio::test] |
| 905 |
async fn test_frame_pointer_barely_no_overflow() { |
| 906 |
// This is test_tradition but with the all the values pushed |
| 907 |
// as close to the upper memory boundary as possible, to confirm that |
| 908 |
// our code doesn't randomly overflow *AND* isn't overzealous in |
| 909 |
// its overflow guards. |
| 910 |
|
| 911 |
let mut f = TestFixture::new(); |
| 912 |
let mut stack = Section::new(); |
| 913 |
|
| 914 |
type Pointer = u32; |
| 915 |
let pointer_size: Pointer = std::mem::size_of::<Pointer>() as Pointer; |
| 916 |
let stack_max: Pointer = Pointer::MAX; |
| 917 |
let stack_size: Pointer = pointer_size * 3; |
| 918 |
|
| 919 |
let stack_start: Pointer = stack_max - stack_size; |
| 920 |
let return_address: Pointer = 0x7b302000; |
| 921 |
stack.start().set_const(stack_start as u64); |
| 922 |
|
| 923 |
let frame0_fp = Label::new(); |
| 924 |
let frame1_sp = Label::new(); |
| 925 |
let frame1_fp = Label::new(); |
| 926 |
|
| 927 |
stack = stack |
| 928 |
// frame 0 |
| 929 |
.mark(&frame0_fp) |
| 930 |
.D32(&frame1_fp) // caller-pushed %rbp |
| 931 |
.D32(return_address) // actual return address |
| 932 |
// frame 1 |
| 933 |
.mark(&frame1_sp) |
| 934 |
.mark(&frame1_fp) // end of stack |
| 935 |
.D32(0); |
| 936 |
|
| 937 |
f.raw.eip = 0x7a100000; |
| 938 |
f.raw.ebp = frame0_fp.value().unwrap() as Pointer; |
| 939 |
f.raw.esp = stack.start().value().unwrap() as Pointer; |
| 940 |
|
| 941 |
let s = f.walk_stack(stack).await; |
| 942 |
assert_eq!(s.frames.len(), 2); |
| 943 |
|
| 944 |
{ |
| 945 |
// To avoid reusing locals by mistake |
| 946 |
let f0 = &s.frames[0]; |
| 947 |
assert_eq!(f0.trust, FrameTrust::Context); |
| 948 |
assert_eq!(f0.context.valid, MinidumpContextValidity::All); |
| 949 |
if let MinidumpRawContext::X86(ctx) = &f0.context.raw { |
| 950 |
assert_eq!(ctx.ebp, frame0_fp.value().unwrap() as Pointer); |
| 951 |
} else { |
| 952 |
unreachable!(); |
| 953 |
} |
| 954 |
} |
| 955 |
|
| 956 |
{ |
| 957 |
// To avoid reusing locals by mistake |
| 958 |
let f1 = &s.frames[1]; |
| 959 |
assert_eq!(f1.trust, FrameTrust::FramePointer); |
| 960 |
if let MinidumpContextValidity::Some(ref which) = f1.context.valid { |
| 961 |
assert!(which.contains("eip")); |
| 962 |
assert!(which.contains("esp")); |
| 963 |
assert!(which.contains("ebp")); |
| 964 |
} else { |
| 965 |
unreachable!(); |
| 966 |
} |
| 967 |
if let MinidumpRawContext::X86(ctx) = &f1.context.raw { |
| 968 |
assert_eq!(ctx.eip, return_address); |
| 969 |
assert_eq!(ctx.esp, frame1_sp.value().unwrap() as Pointer); |
| 970 |
assert_eq!(ctx.ebp, frame1_fp.value().unwrap() as Pointer); |
| 971 |
} else { |
| 972 |
unreachable!(); |
| 973 |
} |
| 974 |
} |
| 975 |
} |