libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
clues::ErrnoResult Class Reference

An errno system call result. More...

#include <ErrnoResult.hxx>

Public Member Functions

 ErrnoResult (const cosmos::Errno code)
 
std::string str () const
 
std::optional< cosmos::Errno > errorCode () const
 
std::optional< KernelErrnokernelErrorCode () const
 
bool hasErrorCode () const
 
bool hasKernelErrorCode () const
 

Protected Attributes

std::optional< cosmos::Errno > m_errno
 
std::optional< KernelErrnom_kernel_errno
 

Detailed Description

An errno system call result.

When a system call fails then the kernel provides a dedicated errno result via PTRACE_GET_SYSCALL_INFO. This type wraps the information provided by the kernel.

During tracing error codes can appear that aren't usually visible in user space. These are modeled via the dedicated KernelErrno type. For this reason only std::optional returns are provided.

Definition at line 24 of file ErrnoResult.hxx.

Constructor & Destructor Documentation

◆ ErrnoResult()

clues::ErrnoResult::ErrnoResult ( const cosmos::Errno code)
explicit

Definition at line 11 of file ErrnoResult.cxx.

11 {
12 const auto kernel_code = KernelErrno{cosmos::to_integral(code)};
13
14 if (kernel_code >= KernelErrno::RESTART_SYS &&
15 kernel_code <= KernelErrno::RESTART_RESTARTBLOCK) {
16 m_kernel_errno = kernel_code;
17 } else {
18 m_errno = code;
19 }
20}
KernelErrno
Errno values that can appear in tracing context.
Definition types.hxx:49

Member Function Documentation

◆ errorCode()

std::optional< cosmos::Errno > clues::ErrnoResult::errorCode ( ) const
inline

Definition at line 31 of file ErrnoResult.hxx.

31 {
32 return m_errno;
33 }

◆ hasErrorCode()

bool clues::ErrnoResult::hasErrorCode ( ) const
inline

Definition at line 39 of file ErrnoResult.hxx.

39 {
40 return m_errno != std::nullopt;
41 }

◆ hasKernelErrorCode()

bool clues::ErrnoResult::hasKernelErrorCode ( ) const
inline

Definition at line 43 of file ErrnoResult.hxx.

43 {
44 return m_kernel_errno != std::nullopt;
45 }

◆ kernelErrorCode()

std::optional< KernelErrno > clues::ErrnoResult::kernelErrorCode ( ) const
inline

Definition at line 35 of file ErrnoResult.hxx.

35 {
36 return m_kernel_errno;
37 }

◆ str()

std::string clues::ErrnoResult::str ( ) const

Definition at line 22 of file ErrnoResult.cxx.

22 {
23
24 if (m_errno) {
25 const auto code = *m_errno;
26 return cosmos::sprintf("%d (%s)",
27 cosmos::to_integral(code), get_errno_label(code));
28 } else {
29 const auto code = *m_kernel_errno;
30 return cosmos::sprintf("%d (%s)",
31 cosmos::to_integral(code), get_kernel_errno_label(code));
32 }
33}
const char * get_errno_label(const cosmos::Errno err)
Returns a short errno label like ENOENT for the given errno integer.
Definition utils.cxx:29
const char * get_kernel_errno_label(const KernelErrno err)
Returns a short errno label for extended KernelErrno codes.
Definition utils.cxx:37

Member Data Documentation

◆ m_errno

std::optional<cosmos::Errno> clues::ErrnoResult::m_errno
protected

Definition at line 49 of file ErrnoResult.hxx.

◆ m_kernel_errno

std::optional<KernelErrno> clues::ErrnoResult::m_kernel_errno
protected

Definition at line 50 of file ErrnoResult.hxx.


The documentation for this class was generated from the following files: