Skip to content

Commit

Permalink
Add a feature named enable-console-log.
Browse files Browse the repository at this point in the history
This feature can be enable to print log messages to console in
addition to storing them in the log buffer.
Enable this feature by default for debug builds.

Signed-off-by: Vasant Karasulli <[email protected]>
  • Loading branch information
vsntk18 committed Jul 11, 2023
1 parent 7218638 commit 5af0ce1
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
# ld to work, so build all the objects without performing the
# final linking step.
- name: Build
run: make FEATURES="default,enable-gdb" stage1/stage1.o stage1/reset.o
run: make FEATURES="default-debug,enable-gdb" stage1/stage1.o stage1/reset.o

- name: Run tests
run: make test
Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ packit = { git = "https://github.com/coconut-svsm/packit", version = "0.1.0" }
[build-dependencies]

[features]
default = ["enable-stacktrace"]
default-release = ["enable-stacktrace"]
default-debug = ["enable-stacktrace", "enable-console-log"]
enable-stacktrace = []
enable-gdb = ["dep:gdbstub", "dep:gdbstub_arch"]
enable-console-log = []
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
FEATURES ?= "default"
CARGO_ARGS = --features ${FEATURES}

ifdef RELEASE
TARGET_PATH="release"
FEATURES ?= "default-release"
CARGO_ARGS = --features ${FEATURES}
CARGO_ARGS += --release
else
TARGET_PATH="debug"
FEATURES ?= "default-debug"
CARGO_ARGS = --features ${FEATURES}
endif


Expand Down
14 changes: 14 additions & 0 deletions src/cpu/line_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Copyright (c) 2022-2023 SUSE LLC
//
// Author: Vasant Karasulli <[email protected]>
#[cfg(feature = "enable-console-log")]
use crate::console::_print;

use crate::cpu::percpu::this_cpu_mut;
use crate::log_buffer::LB;
Expand Down Expand Up @@ -74,18 +76,30 @@ impl log::Log for BufferLogger {
line_buf
.write_fmt(format_args!("[{}] {}: {}\n", comp, lvl, rec_args))
.unwrap();
#[cfg(feature = "enable-console-log")]
{
_print(format_args!("[{}] {}: {}\n", comp, lvl, rec_args));
}
}

log::Level::Info => {
line_buf
.write_fmt(format_args!("[{}] {}\n", comp, rec_args))
.unwrap();
#[cfg(feature = "enable-console-log")]
{
_print(format_args!("[{}] {}\n", comp, rec_args));
}
}

log::Level::Debug | log::Level::Trace => {
line_buf
.write_fmt(format_args!("[{}/{}] {} {}\n", comp, target, lvl, rec_args))
.unwrap();
#[cfg(feature = "enable-console-log")]
{
_print(format_args!("[{}/{}] {} {}\n", comp, target, lvl, rec_args));
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/stage2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ fn setup_env() {
WRITER.lock().set(&mut CONSOLE_SERIAL);
}

init_console();
#[cfg(feature = "enable-console-log")]
{
init_console();
}

install_buffer_logger("Stage2");

Expand Down
6 changes: 5 additions & 1 deletion src/svsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,11 @@ pub extern "C" fn svsm_start(li: &KernelLaunchInfo, mi: &MigrateInfo) {
WRITER.lock().set(&mut CONSOLE_SERIAL);
}

init_console();
#[cfg(feature = "enable-console-log")]
{
init_console();
}

install_buffer_logger("SVSM");

log::info!("COCONUT Secure Virtual Machine Service Module (SVSM)");
Expand Down

0 comments on commit 5af0ce1

Please sign in to comment.