Skip to content

Commit c8f5786

Browse files
committed
Fix crashdump creation message print when the option is disabled for a sandbox
- Update docs to add a note about how to disable crashdumps for specific sandboxes - Commit automatically update `Cargo.lock` for rust_guests Signed-off-by: Doru Blânzeanu <[email protected]>
1 parent f9aa7f5 commit c8f5786

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

docs/how-to-debug-a-hyperlight-guest.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ To make Hyperlight dump the state of the vCPU (general purpose registers, regist
211211
This will result in a dump file being created in the temporary directory.
212212
The name and location of the dump file will be printed to the console and logged as an error message.
213213
214+
**NOTE**: By enabling the `crashdump` feature, you instruct Hyperlight to create core dump files for all sandboxes when an unhandled crash occurs.
215+
To selectively disable this feature for a specific sandbox, you can set the `guest_core_dump` field to `false` in the `SandboxConfiguration`.
216+
```rust
217+
let mut cfg = SandboxConfiguration::default();
218+
cfg.set_guest_core_dump(false); // Disable core dump for this sandbox
219+
```
220+
214221
### Inspecting the core dump
215222

216223
After the core dump has been created, to inspect the state of the guest, load the core dump file using `gdb` or `lldb`.

src/hyperlight_host/src/hypervisor/crashdump.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,6 @@ impl ReadProcessMemory for GuestMemReader {
263263
/// # Returns
264264
/// * `Result<()>`: Success or error
265265
pub(crate) fn generate_crashdump(hv: &dyn Hypervisor) -> Result<()> {
266-
log::info!("Creating core dump file...");
267-
268266
// Get crash context from hypervisor
269267
let ctx = hv
270268
.crashdump_context()
@@ -284,10 +282,16 @@ pub(crate) fn generate_crashdump(hv: &dyn Hypervisor) -> Result<()> {
284282
) as Box<dyn Write>)
285283
};
286284

287-
checked_core_dump(ctx, create_dump_file).map(|_| {
288-
println!("Core dump created successfully: {}", file_path);
289-
log::error!("Core dump file: {}", file_path);
290-
})
285+
if let Ok(nbytes) = checked_core_dump(ctx, create_dump_file) {
286+
if nbytes > 0 {
287+
println!("Core dump created successfully: {}", file_path);
288+
log::error!("Core dump file: {}", file_path);
289+
}
290+
} else {
291+
log::error!("Failed to create core dump file");
292+
}
293+
294+
Ok(())
291295
}
292296

293297
/// Computes the file path for the core dump file.
@@ -352,6 +356,8 @@ fn checked_core_dump(
352356
// If the HV returned a context it means we can create a core dump
353357
// This is the case when the sandbox has been configured at runtime to allow core dumps
354358
if let Some(ctx) = ctx {
359+
log::info!("Creating core dump file...");
360+
355361
// Set up data sources for the core dump
356362
let guest_view = GuestView::new(&ctx);
357363
let memory_reader = GuestMemReader::new(&ctx);

src/tests/rust_guests/witguest/Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)