Skip to content

Commit

Permalink
[move] Unify debugging and tracing feature flags for tracing in t…
Browse files Browse the repository at this point in the history
…he VM
  • Loading branch information
tzakian committed Oct 29, 2024
1 parent cae3212 commit 27735e0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
2 changes: 0 additions & 2 deletions external-crates/move/crates/move-vm-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ move-compiler.workspace = true
default = []
fuzzing = ["move-vm-types/fuzzing"]
failpoints = ["fail/failpoints"]
# Enable tracing and debugging also for release builds. By default, it is only enabled for debug builds.
debugging = []
testing = []
lazy_natives = []
tracing = [
Expand Down
2 changes: 1 addition & 1 deletion external-crates/move/crates/move-vm-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod tracing;
mod tracing2;

// Only include debugging functionality in debug builds
#[cfg(any(debug_assertions, feature = "debugging"))]
#[cfg(any(debug_assertions, feature = "tracing"))]
mod debug;

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion external-crates/move/crates/move-vm-runtime/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2203,7 +2203,7 @@ impl Function {
)
}

#[cfg(any(debug_assertions, feature = "debugging"))]
#[cfg(any(debug_assertions, feature = "tracing"))]
pub(crate) fn pretty_short_string(&self) -> String {
let id = &self.module;
format!(
Expand Down
24 changes: 12 additions & 12 deletions external-crates/move/crates/move-vm-runtime/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Copyright (c) The Move Contributors
// SPDX-License-Identifier: Apache-2.0

#[cfg(any(debug_assertions, feature = "debugging"))]
#[cfg(any(debug_assertions, feature = "tracing"))]
use crate::debug::DebugContext;

#[cfg(any(debug_assertions, feature = "debugging"))]
#[cfg(any(debug_assertions, feature = "tracing"))]
use ::{
move_binary_format::file_format::Bytecode,
move_vm_types::values::Locals,
Expand All @@ -20,31 +20,31 @@ use ::{
},
};

#[cfg(any(debug_assertions, feature = "debugging"))]
#[cfg(any(debug_assertions, feature = "tracing"))]
use crate::{
interpreter::Interpreter,
loader::{Function, Loader},
};

#[cfg(any(debug_assertions, feature = "debugging"))]
#[cfg(any(debug_assertions, feature = "tracing"))]
const MOVE_VM_TRACING_ENV_VAR_NAME: &str = "MOVE_VM_TRACE";

#[cfg(any(debug_assertions, feature = "debugging"))]
#[cfg(any(debug_assertions, feature = "tracing"))]
const MOVE_VM_STEPPING_ENV_VAR_NAME: &str = "MOVE_VM_STEP";

#[cfg(any(debug_assertions, feature = "debugging"))]
#[cfg(any(debug_assertions, feature = "tracing"))]
static FILE_PATH: Lazy<String> = Lazy::new(|| {
env::var(MOVE_VM_TRACING_ENV_VAR_NAME).unwrap_or_else(|_| "move_vm_trace.trace".to_string())
});

#[cfg(any(debug_assertions, feature = "debugging"))]
#[cfg(any(debug_assertions, feature = "tracing"))]
static TRACING_ENABLED: Lazy<bool> = Lazy::new(|| env::var(MOVE_VM_TRACING_ENV_VAR_NAME).is_ok());

#[cfg(any(debug_assertions, feature = "debugging"))]
#[cfg(any(debug_assertions, feature = "tracing"))]
static DEBUGGING_ENABLED: Lazy<bool> =
Lazy::new(|| env::var(MOVE_VM_STEPPING_ENV_VAR_NAME).is_ok());

#[cfg(any(debug_assertions, feature = "debugging"))]
#[cfg(any(debug_assertions, feature = "tracing"))]
static LOGGING_FILE: Lazy<Mutex<File>> = Lazy::new(|| {
Mutex::new(
OpenOptions::new()
Expand All @@ -55,11 +55,11 @@ static LOGGING_FILE: Lazy<Mutex<File>> = Lazy::new(|| {
)
});

#[cfg(any(debug_assertions, feature = "debugging"))]
#[cfg(any(debug_assertions, feature = "tracing"))]
static DEBUG_CONTEXT: Lazy<Mutex<DebugContext>> = Lazy::new(|| Mutex::new(DebugContext::new()));

// Only include in debug builds
#[cfg(any(debug_assertions, feature = "debugging"))]
#[cfg(any(debug_assertions, feature = "tracing"))]
pub(crate) fn trace(
function_desc: &Function,
locals: &Locals,
Expand Down Expand Up @@ -93,7 +93,7 @@ pub(crate) fn trace(
macro_rules! trace {
($function_desc:expr, $locals:expr, $pc:expr, $instr:tt, $resolver:expr, $interp:expr) => {
// Only include this code in debug releases
#[cfg(any(debug_assertions, feature = "debugging"))]
#[cfg(any(debug_assertions, feature = "tracing"))]
$crate::tracing::trace(
&$function_desc,
$locals,
Expand Down

0 comments on commit 27735e0

Please sign in to comment.