Skip to content

Commit 5176529

Browse files
committed
Expliclity call crate::debug! instead of debug! to differentiate from log::debug, and alias feature with debug_assertions
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent 79142ee commit 5176529

File tree

6 files changed

+38
-37
lines changed

6 files changed

+38
-37
lines changed

src/hyperlight_host/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ fn main() -> Result<()> {
9696
inprocess: { all(feature = "inprocess", debug_assertions) },
9797
// crashdump feature is aliased with debug_assertions to make it only available in debug-builds.
9898
crashdump: { all(feature = "crashdump", debug_assertions) },
99+
// print_debug feature is aliased with debug_assertions to make it only available in debug-builds.
100+
print_debug: { all(feature = "print_debug", debug_assertions) },
99101
}
100102

101103
write_built_file()?;

src/hyperlight_host/src/hypervisor/hyperv_linux.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::hypervisor::hypervisor_handler::HypervisorHandler;
3737
use crate::hypervisor::HyperlightExit;
3838
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
3939
use crate::mem::ptr::{GuestPtr, RawPtr};
40-
use crate::{debug, log_then_return, new_error, Result};
40+
use crate::{log_then_return, new_error, Result};
4141

4242
/// Determine whether the HyperV for Linux hypervisor API is present
4343
/// and functional.
@@ -287,7 +287,7 @@ impl Hypervisor for HypervLinuxDriver {
287287
let result = match &self.vcpu_fd.run(hv_message) {
288288
Ok(m) => match m.header.message_type {
289289
HALT_MESSAGE => {
290-
debug!("mshv - Halt Details : {:#?}", &self);
290+
crate::debug!("mshv - Halt Details : {:#?}", &self);
291291
HyperlightExit::Halt()
292292
}
293293
IO_PORT_INTERCEPT_MESSAGE => {
@@ -296,7 +296,7 @@ impl Hypervisor for HypervLinuxDriver {
296296
let rip = io_message.header.rip;
297297
let rax = io_message.rax;
298298
let instruction_length = io_message.header.instruction_length() as u64;
299-
debug!("mshv IO Details : \nPort : {}\n{:#?}", port_number, &self);
299+
crate::debug!("mshv IO Details : \nPort : {}\n{:#?}", port_number, &self);
300300
HyperlightExit::IoOut(
301301
port_number,
302302
rax.to_le_bytes().to_vec(),
@@ -307,19 +307,21 @@ impl Hypervisor for HypervLinuxDriver {
307307
UNMAPPED_GPA_MESSAGE => {
308308
let mimo_message = m.to_memory_info()?;
309309
let addr = mimo_message.guest_physical_address;
310-
debug!(
310+
crate::debug!(
311311
"mshv MMIO unmapped GPA -Details: Address: {} \n {:#?}",
312-
addr, &self
312+
addr,
313+
&self
313314
);
314315
HyperlightExit::Mmio(addr)
315316
}
316317
INVALID_GPA_ACCESS_MESSAGE => {
317318
let mimo_message = m.to_memory_info()?;
318319
let gpa = mimo_message.guest_physical_address;
319320
let access_info = MemoryRegionFlags::try_from(mimo_message)?;
320-
debug!(
321+
crate::debug!(
321322
"mshv MMIO invalid GPA access -Details: Address: {} \n {:#?}",
322-
gpa, &self
323+
gpa,
324+
&self
323325
);
324326
match self.get_memory_access_violation(
325327
gpa as usize,
@@ -331,7 +333,7 @@ impl Hypervisor for HypervLinuxDriver {
331333
}
332334
}
333335
other => {
334-
debug!("mshv Other Exit: Exit: {:#?} \n {:#?}", other, &self);
336+
crate::debug!("mshv Other Exit: Exit: {:#?} \n {:#?}", other, &self);
335337
log_then_return!("unknown Hyper-V run message type {:?}", other);
336338
}
337339
},
@@ -340,7 +342,7 @@ impl Hypervisor for HypervLinuxDriver {
340342
libc::EINTR => HyperlightExit::Cancelled(),
341343
libc::EAGAIN => HyperlightExit::Retry(),
342344
_ => {
343-
debug!("mshv Error - Details: Error: {} \n {:#?}", e, &self);
345+
crate::debug!("mshv Error - Details: Error: {} \n {:#?}", e, &self);
344346
log_then_return!("Error running VCPU {:?}", e);
345347
}
346348
},

src/hyperlight_host/src/hypervisor/kvm.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use super::{
3131
use crate::hypervisor::hypervisor_handler::HypervisorHandler;
3232
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
3333
use crate::mem::ptr::{GuestPtr, RawPtr};
34-
use crate::{debug, log_then_return, new_error, Result};
34+
use crate::{log_then_return, new_error, Result};
3535

3636
/// Return `true` if the KVM API is available, version 12, and has UserMemory capability, or `false` otherwise
3737
#[instrument(skip_all, parent = Span::current(), level = "Trace")]
@@ -271,17 +271,17 @@ impl Hypervisor for KVMDriver {
271271
let exit_reason = self.vcpu_fd.run();
272272
let result = match exit_reason {
273273
Ok(VcpuExit::Hlt) => {
274-
debug!("KVM - Halt Details : {:#?}", &self);
274+
crate::debug!("KVM - Halt Details : {:#?}", &self);
275275
HyperlightExit::Halt()
276276
}
277277
Ok(VcpuExit::IoOut(port, data)) => {
278-
// because vcpufd.run() mutably borrows self we cannot pass self to debug! macro here
279-
debug!("KVM IO Details : \nPort : {}\nData : {:?}", port, data);
278+
// because vcpufd.run() mutably borrows self we cannot pass self to crate::debug! macro here
279+
crate::debug!("KVM IO Details : \nPort : {}\nData : {:?}", port, data);
280280
// KVM does not need to set RIP or instruction length so these are set to 0
281281
HyperlightExit::IoOut(port, data.to_vec(), 0, 0)
282282
}
283283
Ok(VcpuExit::MmioRead(addr, _)) => {
284-
debug!("KVM MMIO Read -Details: Address: {} \n {:#?}", addr, &self);
284+
crate::debug!("KVM MMIO Read -Details: Address: {} \n {:#?}", addr, &self);
285285

286286
match self.get_memory_access_violation(
287287
addr as usize,
@@ -293,7 +293,7 @@ impl Hypervisor for KVMDriver {
293293
}
294294
}
295295
Ok(VcpuExit::MmioWrite(addr, _)) => {
296-
debug!("KVM MMIO Write -Details: Address: {} \n {:#?}", addr, &self);
296+
crate::debug!("KVM MMIO Write -Details: Address: {} \n {:#?}", addr, &self);
297297

298298
match self.get_memory_access_violation(
299299
addr as usize,
@@ -309,12 +309,12 @@ impl Hypervisor for KVMDriver {
309309
libc::EINTR => HyperlightExit::Cancelled(),
310310
libc::EAGAIN => HyperlightExit::Retry(),
311311
_ => {
312-
debug!("KVM Error -Details: Address: {} \n {:#?}", e, &self);
312+
crate::debug!("KVM Error -Details: Address: {} \n {:#?}", e, &self);
313313
log_then_return!("Error running VCPU {:?}", e);
314314
}
315315
},
316316
Ok(other) => {
317-
debug!("KVM Other Exit {:?}", other);
317+
crate::debug!("KVM Other Exit {:?}", other);
318318
HyperlightExit::Unknown(format!("Unexpected KVM Exit {:?}", other))
319319
}
320320
};

src/hyperlight_host/src/lib.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,14 @@ macro_rules! log_then_return {
143143
};
144144
}
145145

146+
// same as log::debug!, but will additionally print to stdout if the print_debug feature is enabled
146147
#[macro_export]
147148
macro_rules! debug {
148-
149149
($($arg:tt)+) =>
150150
{
151-
// If the print_debug feature is enabled, print the debug message to the console
152-
#[cfg(all(feature = "print_debug", debug_assertions))]
153-
{
154-
(println!($($arg)+))
155-
}
156-
157-
// Then log/trace the debug message
158-
(log::debug!($($arg)+))
151+
#[cfg(print_debug)]
152+
println!($($arg)+);
153+
log::debug!($($arg)+);
159154
}
160155
}
161156

src/hyperlight_host/src/mem/pe/pe_info.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use goblin::pe::PE;
2323
use tracing::{instrument, Span};
2424

2525
use crate::mem::pe::base_relocations;
26-
use crate::{debug, log_then_return, Result};
26+
use crate::{log_then_return, Result};
2727

2828
const IMAGE_REL_BASED_DIR64: u8 = 10;
2929
const IMAGE_REL_BASED_ABSOLUTE: u8 = 0;
@@ -106,9 +106,11 @@ impl PEInfo {
106106
let name = section.name().unwrap_or("Unknown");
107107
let virtual_size = section.virtual_size;
108108
let raw_size = section.size_of_raw_data;
109-
debug!(
109+
crate::debug!(
110110
"Section: {}, Virtual Size: {}, On-Disk Size: {}",
111-
name, virtual_size, raw_size
111+
name,
112+
virtual_size,
113+
raw_size
112114
);
113115

114116
if virtual_size > raw_size {
@@ -122,16 +124,16 @@ impl PEInfo {
122124

123125
data_section_raw_pointer = section.pointer_to_raw_data;
124126
data_section_additional_bytes = virtual_size - raw_size;
125-
debug!(
127+
crate::debug!(
126128
"Resizing the data section - Additional bytes required: {}",
127129
data_section_additional_bytes
128130
);
129-
debug!(
131+
crate::debug!(
130132
"Resizing the data section - Existing PE File Size: {} New PE File Size: {}",
131133
pe_bytes.len(),
132134
pe_bytes.len() + data_section_additional_bytes as usize,
133135
);
134-
debug!(
136+
crate::debug!(
135137
"Resizing the data section - Data Section Raw Pointer: {}",
136138
data_section_raw_pointer
137139
);
@@ -140,19 +142,19 @@ impl PEInfo {
140142
end_of_data_index =
141143
(section.pointer_to_raw_data + section.size_of_raw_data) as usize;
142144

143-
debug!("End of data index: {}", end_of_data_index);
145+
crate::debug!("End of data index: {}", end_of_data_index);
144146

145147
// the remainder of the data is the rest of the file after the .data section if any
146148

147149
let next_section = pe.sections.get(i + 1);
148150

149151
if let Some(next_section) = next_section {
150-
debug!(
152+
crate::debug!(
151153
"Start of section after data index: {}",
152154
next_section.pointer_to_raw_data
153155
);
154156
} else {
155-
debug!("No more sections after the .data section");
157+
crate::debug!("No more sections after the .data section");
156158
}
157159
} else {
158160
log_then_return!(

src/hyperlight_host/src/sandbox/uninitialized.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::sandbox::SandboxConfiguration;
3535
use crate::sandbox_state::sandbox::EvolvableSandbox;
3636
use crate::sandbox_state::transition::Noop;
3737
use crate::{
38-
debug, log_build_details, log_then_return, new_error, MultiUseSandbox, Result, SingleUseSandbox,
38+
log_build_details, log_then_return, new_error, MultiUseSandbox, Result, SingleUseSandbox,
3939
};
4040

4141
/// A preliminary `Sandbox`, not yet ready to execute guest code.
@@ -258,7 +258,7 @@ impl UninitializedSandbox {
258258
}
259259
}
260260

261-
debug!("Sandbox created: {:#?}", sandbox);
261+
crate::debug!("Sandbox created: {:#?}", sandbox);
262262

263263
Ok(sandbox)
264264
}

0 commit comments

Comments
 (0)