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>, inode: Arc<INode>,
offset: u64, offset: u64,
options: OpenOptions, options: OpenOptions,
// for debugging
#[cfg(debug_assertions)]
path: String, path: String,
} }
@ -32,32 +29,15 @@ pub enum SeekFrom {
} }
impl FileHandle { impl FileHandle {
pub fn new(inode: Arc<INode>, options: OpenOptions) -> Self { pub fn new(inode: Arc<INode>, options: OpenOptions, path: String) -> Self {
#[cfg(debug_assertions)]
return FileHandle {
inode,
offset: 0,
options,
path: String::from("unknown"),
};
#[cfg(not(debug_assertions))]
return FileHandle { return FileHandle {
inode, inode,
offset: 0, offset: 0,
options, 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> { pub fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
let len = self.read_at(self.offset as usize, buf)?; let len = self.read_at(self.offset as usize, buf)?;
self.offset += len as u64; self.offset += len as u64;
@ -147,19 +127,11 @@ impl FileHandle {
impl fmt::Debug for FileHandle { impl fmt::Debug for FileHandle {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// for debugging
#[cfg(debug_assertions)]
return f return f
.debug_struct("FileHandle") .debug_struct("FileHandle")
.field("offset", &self.offset) .field("offset", &self.offset)
.field("options", &self.options) .field("options", &self.options)
.field("path", &self.path) .field("path", &self.path)
.finish(); .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 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self { match self {
FileLike::File(file) => write!(f, "File({:?})", file), 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::syscall::*;
use crate::util; use crate::util;
use alloc::boxed::Box; use alloc::boxed::Box;
use alloc::fmt::Debug;
use alloc::sync::Arc; use alloc::sync::Arc;
use alloc::vec::Vec; use alloc::vec::Vec;
use bitflags::*; use bitflags::*;
@ -50,7 +51,7 @@ pub enum Endpoint {
} }
/// Common methods that a socket must have /// 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 read(&self, data: &mut [u8]) -> (SysResult, Endpoint);
fn write(&self, data: &[u8], sendto_endpoint: Option<Endpoint>) -> SysResult; fn write(&self, data: &[u8], sendto_endpoint: Option<Endpoint>) -> SysResult;
fn poll(&self) -> (bool, bool, bool); // (in, out, err) fn poll(&self) -> (bool, bool, bool); // (in, out, err)

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

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

Loading…
Cancel
Save