Skip to content

Commit 7b06312

Browse files
authored
update more modules to use tracing crate instead log crate (#1338)
* Test debugger failure with tracing crate Signed-off-by: Shailesh Vashishth <shavashishth@gmail.com> * move crashdump to tracing crate Signed-off-by: Shailesh Vashishth <shavashishth@gmail.com> * Move TraceContext to tracing crate Signed-off-by: Shailesh Vashishth <shavashishth@gmail.com> * move hypervisor/gdb stub to tracing crate Signed-off-by: Shailesh Vashishth <shavashishth@gmail.com> --------- Signed-off-by: Shailesh Vashishth <shavashishth@gmail.com>
1 parent 3517c0c commit 7b06312

8 files changed

Lines changed: 93 additions & 93 deletions

File tree

src/hyperlight_host/src/hypervisor/crashdump.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,10 @@ pub(crate) fn generate_crashdump(
295295
if let Ok(nbytes) = checked_core_dump(ctx, create_dump_file) {
296296
if nbytes > 0 {
297297
println!("Core dump created successfully: {}", file_path);
298-
log::error!("Core dump file: {}", file_path);
298+
tracing::error!("Core dump file: {}", file_path);
299299
}
300300
} else {
301-
log::error!("Failed to create core dump file");
301+
tracing::error!("Failed to create core dump file");
302302
}
303303

304304
Ok(())
@@ -331,7 +331,7 @@ fn core_dump_file_path(dump_dir: Option<String>) -> String {
331331
if std::path::Path::new(&dump_dir).exists() {
332332
std::path::PathBuf::from(dump_dir)
333333
} else {
334-
log::warn!(
334+
tracing::warn!(
335335
"Directory \"{}\" does not exist, falling back to temp directory",
336336
dump_dir
337337
);
@@ -366,7 +366,7 @@ fn checked_core_dump(
366366
// If the HV returned a context it means we can create a core dump
367367
// This is the case when the sandbox has been configured at runtime to allow core dumps
368368
if let Some(ctx) = ctx {
369-
log::info!("Creating core dump file...");
369+
tracing::info!("Creating core dump file...");
370370

371371
// Set up data sources for the core dump
372372
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
@@ -94,7 +94,7 @@ pub(crate) fn vcpu_stop_reason(
9494
}
9595

9696
// Log an error and provide internal debugging info
97-
log::error!(
97+
tracing::error!(
9898
r"The vCPU exited because of an unknown reason:
9999
rip: {:?}
100100
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
@@ -125,7 +125,7 @@ impl DebugMemoryAccess {
125125
let mem_offset = (gpa as usize)
126126
.checked_sub(SandboxMemoryLayout::BASE_ADDRESS)
127127
.ok_or_else(|| {
128-
log::warn!(
128+
tracing::warn!(
129129
"gpa={:#X} causes subtract with underflow: \"gpa - BASE_ADDRESS={:#X}-{:#X}\"",
130130
gpa,
131131
gpa,
@@ -138,11 +138,11 @@ impl DebugMemoryAccess {
138138
let mut region_found = false;
139139
for reg in self.guest_mmap_regions.iter() {
140140
if reg.guest_region.contains(&mem_offset) {
141-
log::debug!("Found mapped region containing {:X}: {:#?}", gpa, reg);
141+
tracing::debug!("Found mapped region containing {:X}: {:#?}", gpa, reg);
142142

143143
// Region found - calculate the offset within the region
144144
let region_offset = mem_offset.checked_sub(reg.guest_region.start).ok_or_else(|| {
145-
log::warn!(
145+
tracing::warn!(
146146
"Cannot calculate offset in memory region: mem_offset={:#X}, base={:#X}",
147147
mem_offset,
148148
reg.guest_region.start,
@@ -177,7 +177,7 @@ impl DebugMemoryAccess {
177177
} else {
178178
(&mut mgr.shared_mem, mem_offset, "snapshot")
179179
};
180-
log::debug!(
180+
tracing::debug!(
181181
"No mapped region found containing {:X}. Trying {} memory at offset {:X} ...",
182182
gpa,
183183
name,
@@ -208,7 +208,7 @@ impl DebugMemoryAccess {
208208
let mem_offset = (gpa as usize)
209209
.checked_sub(SandboxMemoryLayout::BASE_ADDRESS)
210210
.ok_or_else(|| {
211-
log::warn!(
211+
tracing::warn!(
212212
"gpa={:#X} causes subtract with underflow: \"gpa - BASE_ADDRESS={:#X}-{:#X}\"",
213213
gpa,
214214
gpa,
@@ -221,11 +221,11 @@ impl DebugMemoryAccess {
221221
let mut region_found = false;
222222
for reg in self.guest_mmap_regions.iter() {
223223
if reg.guest_region.contains(&mem_offset) {
224-
log::debug!("Found mapped region containing {:X}: {:#?}", gpa, reg);
224+
tracing::debug!("Found mapped region containing {:X}: {:#?}", gpa, reg);
225225

226226
// Region found - calculate the offset within the region
227227
let region_offset = mem_offset.checked_sub(reg.guest_region.start).ok_or_else(|| {
228-
log::warn!(
228+
tracing::warn!(
229229
"Cannot calculate offset in memory region: mem_offset={:#X}, base={:#X}",
230230
mem_offset,
231231
reg.guest_region.start,
@@ -260,7 +260,7 @@ impl DebugMemoryAccess {
260260
} else {
261261
(&mut mgr.shared_mem, mem_offset, "snapshot")
262262
};
263-
log::debug!(
263+
tracing::debug!(
264264
"No mapped region found containing {:X}. Trying {} memory at offset {:X} ...",
265265
gpa,
266266
name,
@@ -415,14 +415,14 @@ pub(crate) fn create_gdb_thread(
415415
let (gdb_conn, hyp_conn) = DebugCommChannel::unbounded();
416416
let socket = format!("localhost:{}", port);
417417

418-
log::info!("Listening on {:?}", socket);
418+
tracing::info!("Listening on {:?}", socket);
419419
let listener = TcpListener::bind(socket)?;
420420

421-
log::info!("Starting GDB thread");
421+
tracing::info!("Starting GDB thread");
422422
let _handle = thread::Builder::new()
423423
.name("GDB handler".to_string())
424424
.spawn(move || -> Result<(), GdbTargetError> {
425-
log::info!("Waiting for GDB connection ... ");
425+
tracing::info!("Waiting for GDB connection ... ");
426426
let (conn, _) = listener.accept()?;
427427

428428
let conn: Box<dyn ConnectionExt<Error = io::Error>> = Box::new(conn);
@@ -433,7 +433,7 @@ pub(crate) fn create_gdb_thread(
433433
// Waits for vCPU to stop at entrypoint breakpoint
434434
let msg = target.recv()?;
435435
if let DebugResponse::InterruptHandle(handle) = msg {
436-
log::info!("Received interrupt handle: {:?}", handle);
436+
tracing::info!("Received interrupt handle: {:?}", handle);
437437
target.set_interrupt_handle(handle);
438438
} else {
439439
return Err(GdbTargetError::UnexpectedMessage);

0 commit comments

Comments
 (0)