Skip to content

Commit 8fe82c4

Browse files
Copilotjsturtevant
andcommitted
Replace remaining log macros with tracing equivalents in host code
Co-authored-by: jsturtevant <648372+jsturtevant@users.noreply.github.com>
1 parent ddb80db commit 8fe82c4

File tree

12 files changed

+121
-112
lines changed

12 files changed

+121
-112
lines changed

src/hyperlight_host/src/hypervisor/crashdump.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,10 @@ pub(crate) fn generate_crashdump(hv: &HyperlightVm) -> Result<()> {
285285
if let Ok(nbytes) = checked_core_dump(ctx, create_dump_file) {
286286
if nbytes > 0 {
287287
println!("Core dump created successfully: {}", file_path);
288-
log::error!("Core dump file: {}", file_path);
288+
tracing::error!("Core dump file: {}", file_path);
289289
}
290290
} else {
291-
log::error!("Failed to create core dump file");
291+
tracing::error!("Failed to create core dump file");
292292
}
293293

294294
Ok(())
@@ -321,7 +321,7 @@ fn core_dump_file_path(dump_dir: Option<String>) -> String {
321321
if std::path::Path::new(&dump_dir).exists() {
322322
std::path::PathBuf::from(dump_dir)
323323
} else {
324-
log::warn!(
324+
tracing::warn!(
325325
"Directory \"{}\" does not exist, falling back to temp directory",
326326
dump_dir
327327
);
@@ -356,7 +356,7 @@ fn checked_core_dump(
356356
// If the HV returned a context it means we can create a core dump
357357
// This is the case when the sandbox has been configured at runtime to allow core dumps
358358
if let Some(ctx) = ctx {
359-
log::info!("Creating core dump file...");
359+
tracing::info!("Creating core dump file...");
360360

361361
// Set up data sources for the core dump
362362
let guest_view = GuestView::new(&ctx);

src/hyperlight_host/src/hypervisor/gdb/arch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub(crate) fn vcpu_stop_reason(
8585
}
8686

8787
// Log an error and provide internal debugging info
88-
log::error!(
88+
tracing::error!(
8989
r"The vCPU exited because of an unknown reason:
9090
rip: {:?}
9191
dr6: {:?}

src/hyperlight_host/src/hypervisor/gdb/event_loop.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl run_blocking::BlockingEventLoop for GdbBlockingEventLoop {
5454
loop {
5555
match target.try_recv() {
5656
Ok(DebugResponse::VcpuStopped(stop_reason)) => {
57-
log::debug!("VcpuStopped with reason {:?}", stop_reason);
57+
tracing::debug!("VcpuStopped with reason {:?}", stop_reason);
5858

5959
// Resume execution if unknown reason for stop
6060
let stop_response = match stop_reason {
@@ -73,7 +73,7 @@ impl run_blocking::BlockingEventLoop for GdbBlockingEventLoop {
7373
signal: Signal(signals::SIGSEGV as u8),
7474
},
7575
VcpuStopReason::Unknown => {
76-
log::warn!("Unknown stop reason received");
76+
tracing::warn!("Unknown stop reason received");
7777

7878
// Marking as a SwBreak so the gdb inspect where/why it stopped
7979
BaseStopReason::SwBreak(())
@@ -83,7 +83,7 @@ impl run_blocking::BlockingEventLoop for GdbBlockingEventLoop {
8383
return Ok(run_blocking::Event::TargetStopped(stop_response));
8484
}
8585
Ok(msg) => {
86-
log::error!("Unexpected message received {:?}", msg);
86+
tracing::error!("Unexpected message received {:?}", msg);
8787
}
8888
Err(crossbeam_channel::TryRecvError::Empty) => (),
8989
Err(crossbeam_channel::TryRecvError::Disconnected) => {
@@ -112,13 +112,13 @@ impl run_blocking::BlockingEventLoop for GdbBlockingEventLoop {
112112
fn on_interrupt(
113113
target: &mut Self::Target,
114114
) -> Result<Option<Self::StopReason>, <Self::Target as gdbstub::target::Target>::Error> {
115-
log::info!("Received interrupt from GDB client - sending signal to target thread");
115+
tracing::info!("Received interrupt from GDB client - sending signal to target thread");
116116

117117
// Send a signal to the target thread to interrupt it
118118
let res = target.interrupt_vcpu();
119119

120120
if !res {
121-
log::error!("Failed to send signal to target thread");
121+
tracing::error!("Failed to send signal to target thread");
122122
return Err(GdbTargetError::SendSignalError);
123123
}
124124

@@ -133,21 +133,21 @@ pub(crate) fn event_loop_thread(
133133
match debugger.run_blocking::<GdbBlockingEventLoop>(target) {
134134
Ok(disconnect_reason) => match disconnect_reason {
135135
DisconnectReason::Disconnect => {
136-
log::info!("Gdb client disconnected");
136+
tracing::info!("Gdb client disconnected");
137137
if let Err(e) = target.disable_debug() {
138-
log::error!("Cannot disable debugging: {:?}", e);
138+
tracing::error!("Cannot disable debugging: {:?}", e);
139139
}
140140
}
141141
DisconnectReason::TargetExited(_) => {
142-
log::info!("Guest finalized execution and disconnected");
142+
tracing::info!("Guest finalized execution and disconnected");
143143
}
144144
DisconnectReason::TargetTerminated(sig) => {
145-
log::info!("Gdb target terminated with signal {}", sig)
145+
tracing::info!("Gdb target terminated with signal {}", sig)
146146
}
147-
DisconnectReason::Kill => log::info!("Gdb sent a kill command"),
147+
DisconnectReason::Kill => tracing::info!("Gdb sent a kill command"),
148148
},
149149
Err(e) => {
150-
log::error!("fatal error encountered: {e:?}");
150+
tracing::error!("fatal error encountered: {e:?}");
151151
}
152152
}
153153
}

src/hyperlight_host/src/hypervisor/gdb/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl DebugMemoryAccess {
100100
let mem_offset = (gpa as usize)
101101
.checked_sub(SandboxMemoryLayout::BASE_ADDRESS)
102102
.ok_or_else(|| {
103-
log::warn!(
103+
tracing::warn!(
104104
"gpa={:#X} causes subtract with underflow: \"gpa - BASE_ADDRESS={:#X}-{:#X}\"",
105105
gpa,
106106
gpa,
@@ -113,11 +113,11 @@ impl DebugMemoryAccess {
113113
let mut region_found = false;
114114
for reg in self.guest_mmap_regions.iter() {
115115
if reg.guest_region.contains(&mem_offset) {
116-
log::debug!("Found mapped region containing {:X}: {:#?}", gpa, reg);
116+
tracing::debug!("Found mapped region containing {:X}: {:#?}", gpa, reg);
117117

118118
// Region found - calculate the offset within the region
119119
let region_offset = mem_offset.checked_sub(reg.guest_region.start).ok_or_else(|| {
120-
log::warn!(
120+
tracing::warn!(
121121
"Cannot calculate offset in memory region: mem_offset={:#X}, base={:#X}",
122122
mem_offset,
123123
reg.guest_region.start,
@@ -136,7 +136,7 @@ impl DebugMemoryAccess {
136136
}
137137

138138
if !region_found {
139-
log::debug!(
139+
tracing::debug!(
140140
"No mapped region found containing {:X}. Trying shared memory ...",
141141
gpa
142142
);
@@ -165,7 +165,7 @@ impl DebugMemoryAccess {
165165
let mem_offset = (gpa as usize)
166166
.checked_sub(SandboxMemoryLayout::BASE_ADDRESS)
167167
.ok_or_else(|| {
168-
log::warn!(
168+
tracing::warn!(
169169
"gpa={:#X} causes subtract with underflow: \"gpa - BASE_ADDRESS={:#X}-{:#X}\"",
170170
gpa,
171171
gpa,
@@ -178,11 +178,11 @@ impl DebugMemoryAccess {
178178
let mut region_found = false;
179179
for reg in self.guest_mmap_regions.iter() {
180180
if reg.guest_region.contains(&mem_offset) {
181-
log::debug!("Found mapped region containing {:X}: {:#?}", gpa, reg);
181+
tracing::debug!("Found mapped region containing {:X}: {:#?}", gpa, reg);
182182

183183
// Region found - calculate the offset within the region
184184
let region_offset = mem_offset.checked_sub(reg.guest_region.start).ok_or_else(|| {
185-
log::warn!(
185+
tracing::warn!(
186186
"Cannot calculate offset in memory region: mem_offset={:#X}, base={:#X}",
187187
mem_offset,
188188
reg.guest_region.start,
@@ -204,7 +204,7 @@ impl DebugMemoryAccess {
204204
}
205205

206206
if !region_found {
207-
log::debug!(
207+
tracing::debug!(
208208
"No mapped region found containing {:X}. Trying shared memory at offset {:X} ...",
209209
gpa,
210210
mem_offset
@@ -344,14 +344,14 @@ pub(crate) fn create_gdb_thread(
344344
let (gdb_conn, hyp_conn) = DebugCommChannel::unbounded();
345345
let socket = format!("localhost:{}", port);
346346

347-
log::info!("Listening on {:?}", socket);
347+
tracing::info!("Listening on {:?}", socket);
348348
let listener = TcpListener::bind(socket)?;
349349

350-
log::info!("Starting GDB thread");
350+
tracing::info!("Starting GDB thread");
351351
let _handle = thread::Builder::new()
352352
.name("GDB handler".to_string())
353353
.spawn(move || -> Result<(), GdbTargetError> {
354-
log::info!("Waiting for GDB connection ... ");
354+
tracing::info!("Waiting for GDB connection ... ");
355355
let (conn, _) = listener.accept()?;
356356

357357
let conn: Box<dyn ConnectionExt<Error = io::Error>> = Box::new(conn);
@@ -362,7 +362,7 @@ pub(crate) fn create_gdb_thread(
362362
// Waits for vCPU to stop at entrypoint breakpoint
363363
let msg = target.recv()?;
364364
if let DebugResponse::InterruptHandle(handle) = msg {
365-
log::info!("Received interrupt handle: {:?}", handle);
365+
tracing::info!("Received interrupt handle: {:?}", handle);
366366
target.set_interrupt_handle(handle);
367367
} else {
368368
return Err(GdbTargetError::UnexpectedMessage);

0 commit comments

Comments
 (0)