summaryrefslogtreecommitdiffstats
path: root/library/std/src/sys/unix/process/process_common.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/std/src/sys/unix/process/process_common.rs')
-rw-r--r--library/std/src/sys/unix/process/process_common.rs67
1 files changed, 60 insertions, 7 deletions
diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs
index 848adca78..afd03d79c 100644
--- a/library/std/src/sys/unix/process/process_common.rs
+++ b/library/std/src/sys/unix/process/process_common.rs
@@ -144,6 +144,7 @@ pub enum ChildStdio {
Null,
}
+#[derive(Debug)]
pub enum Stdio {
Inherit,
Null,
@@ -510,16 +511,68 @@ impl ChildStdio {
}
impl fmt::Debug for Command {
+ // show all attributes but `self.closures` which does not implement `Debug`
+ // and `self.argv` which is not useful for debugging
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- if self.program != self.args[0] {
- write!(f, "[{:?}] ", self.program)?;
- }
- write!(f, "{:?}", self.args[0])?;
+ if f.alternate() {
+ let mut debug_command = f.debug_struct("Command");
+ debug_command.field("program", &self.program).field("args", &self.args);
+ if !self.env.is_unchanged() {
+ debug_command.field("env", &self.env);
+ }
+
+ if self.cwd.is_some() {
+ debug_command.field("cwd", &self.cwd);
+ }
+ if self.uid.is_some() {
+ debug_command.field("uid", &self.uid);
+ }
+ if self.gid.is_some() {
+ debug_command.field("gid", &self.gid);
+ }
+
+ if self.groups.is_some() {
+ debug_command.field("groups", &self.groups);
+ }
+
+ if self.stdin.is_some() {
+ debug_command.field("stdin", &self.stdin);
+ }
+ if self.stdout.is_some() {
+ debug_command.field("stdout", &self.stdout);
+ }
+ if self.stderr.is_some() {
+ debug_command.field("stderr", &self.stderr);
+ }
+ if self.pgroup.is_some() {
+ debug_command.field("pgroup", &self.pgroup);
+ }
+
+ #[cfg(target_os = "linux")]
+ {
+ debug_command.field("create_pidfd", &self.create_pidfd);
+ }
- for arg in &self.args[1..] {
- write!(f, " {:?}", arg)?;
+ debug_command.finish()
+ } else {
+ if let Some(ref cwd) = self.cwd {
+ write!(f, "cd {cwd:?} && ")?;
+ }
+ for (key, value_opt) in self.get_envs() {
+ if let Some(value) = value_opt {
+ write!(f, "{}={value:?} ", key.to_string_lossy())?;
+ }
+ }
+ if self.program != self.args[0] {
+ write!(f, "[{:?}] ", self.program)?;
+ }
+ write!(f, "{:?}", self.args[0])?;
+
+ for arg in &self.args[1..] {
+ write!(f, " {:?}", arg)?;
+ }
+ Ok(())
}
- Ok(())
}
}