Save path even in release mode

toolchain_update
Jiajie Chen 6 years ago
parent ad2f02388c
commit 64b383b69c

@ -10,9 +10,6 @@ pub struct FileHandle {
inode: Arc<INode>,
offset: u64,
options: OpenOptions,
// for debugging
#[cfg(debug_assertions)]
path: String,
}
@ -32,32 +29,15 @@ pub enum SeekFrom {
}
impl FileHandle {
pub fn new(inode: Arc<INode>, options: OpenOptions) -> Self {
#[cfg(debug_assertions)]
return FileHandle {
inode,
offset: 0,
options,
path: String::from("unknown"),
};
#[cfg(not(debug_assertions))]
pub fn new(inode: Arc<INode>, options: OpenOptions, path: String) -> Self {
return FileHandle {
inode,
offset: 0,
options,
path,
};
}
#[cfg(debug_assertions)]
pub fn set_path(&mut self, path: &str) {
self.path = String::from(path);
}
#[cfg(not(debug_assertions))]
pub fn set_path(&mut self, _path: &str) {
unreachable!()
}
pub fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
let len = self.read_at(self.offset as usize, buf)?;
self.offset += len as u64;
@ -147,19 +127,11 @@ impl FileHandle {
impl fmt::Debug for FileHandle {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// for debugging
#[cfg(debug_assertions)]
return f
.debug_struct("FileHandle")
.field("offset", &self.offset)
.field("options", &self.options)
.field("path", &self.path)
.finish();
#[cfg(not(debug_assertions))]
return f
.debug_struct("FileHandle")
.field("offset", &self.offset)
.field("options", &self.options)
.finish();
}
}

@ -54,7 +54,7 @@ impl fmt::Debug for FileLike {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
FileLike::File(file) => write!(f, "File({:?})", file),
FileLike::Socket(_) => write!(f, "Socket(..)"),
FileLike::Socket(socket) => write!(f, "Socket({:?})", socket),
}
}
}

@ -4,6 +4,7 @@ use crate::sync::SpinNoIrqLock as Mutex;
use crate::syscall::*;
use crate::util;
use alloc::boxed::Box;
use alloc::fmt::Debug;
use alloc::sync::Arc;
use alloc::vec::Vec;
use bitflags::*;
@ -50,7 +51,7 @@ pub enum Endpoint {
}
/// Common methods that a socket must have
pub trait Socket: Send + Sync {
pub trait Socket: Send + Sync + Debug {
fn read(&self, data: &mut [u8]) -> (SysResult, Endpoint);
fn write(&self, data: &[u8], sendto_endpoint: Option<Endpoint>) -> SysResult;
fn poll(&self) -> (bool, bool, bool); // (in, out, err)

@ -255,6 +255,7 @@ impl Thread {
write: false,
append: false,
},
String::from("stdin"),
)),
);
files.insert(
@ -266,6 +267,7 @@ impl Thread {
write: true,
append: false,
},
String::from("stdout"),
)),
);
files.insert(
@ -277,6 +279,7 @@ impl Thread {
write: true,
append: false,
},
String::from("stderr"),
)),
);

@ -156,6 +156,11 @@ pub fn sys_select(
// infinity
1 << 31
};
// for debugging
if cfg!(debug_assertions) {
debug!("files before select {:#?}", proc.files);
}
drop(proc);
let begin_time_ms = crate::trap::uptime_msec();
@ -273,11 +278,10 @@ pub fn sys_openat(dir_fd: usize, path: *const u8, flags: usize, mode: usize) ->
proc.lookup_inode_at(dir_fd, &path, true)?
};
let mut file = FileHandle::new(inode, flags.to_options());
let mut file = FileHandle::new(inode, flags.to_options(), String::from(path));
// for debugging
if cfg!(debug_assertions) {
file.set_path(&path);
debug!("files before open {:#?}", proc.files);
}
@ -648,6 +652,7 @@ pub fn sys_pipe(fds: *mut u32) -> SysResult {
write: false,
append: false,
},
String::from(":pipe_r:"),
)));
let write_fd = proc.add_file(FileLike::File(FileHandle::new(
@ -657,6 +662,7 @@ pub fn sys_pipe(fds: *mut u32) -> SysResult {
write: true,
append: false,
},
String::from(":pipe_w:"),
)));
fds[0] = read_fd as u32;

Loading…
Cancel
Save