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

Base class for file descriptor system call items. More...

#include <fs.hxx>

+ Inheritance diagram for clues::item::FileDescriptor:

Public Member Functions

 FileDescriptor (const ItemType type=ItemType::PARAM_IN, const AtSemantics at_semantics=AtSemantics{false}, const std::string_view short_name="fd", const std::string_view long_name="file descriptor")
 
std::string str () const override
 Returns a human readable string representation of the item.
 
auto fd () const
 
const std::optional< FDInfo > & info () const
 Returns optional extended file descriptor metadata.
 
- Public Member Functions inherited from clues::SystemCallItem
 SystemCallItem (const ItemType type, const std::string_view short_name={}, const std::string_view long_name={})
 Constructs a new SystemCallItem.
 
auto type () const
 
bool isIn () const
 
bool isOut () const
 
bool isInOut () const
 
bool isReturnValue () const
 
void fill (const Tracee &proc, const Word word)
 Fills the item from the given register data.
 
bool needsUpdate () const
 Returns whether the item needs to be updated after the system call is finished.
 
std::string_view shortName () const
 Returns the friendly short name for this item.
 
std::string_view longName () const
 Returns the friendly long name for this item, if available, else the short name.
 
auto hasLongName () const
 
bool isZero () const
 Returns whether the parameter is set to 0 / NULL.
 
Word value () const
 Returns the currently stored raw value of the item.
 
template<typename OTHER>
OTHER valueAs () const
 Helper to cast the strongly typed Word m_val to other strong enum types.
 
ForeignPtr asPtr () const
 
Flags flags () const
 
bool deferFill () const
 

Protected Member Functions

void processValue (const Tracee &) override
 Processes the value stored in m_val acc. to the actual item type.
 
- Protected Member Functions inherited from clues::SystemCallItem
virtual void updateData (const Tracee &t)
 Called upon exit of the system call to update possible out parameters.
 
void setSystemCall (const SystemCall &sc)
 Sets the system call context this item is a part of.
 

Protected Attributes

cosmos::FileNum m_fd
 
std::optional< FDInfom_info
 filled if FormatFlag::FD_INFO is set.
 
const AtSemantics m_at_semantics = AtSemantics{false}
 
- Protected Attributes inherited from clues::SystemCallItem
const SystemCallm_call = nullptr
 The system call context this item part of.
 
const ItemType m_type
 The type of item.
 
std::string_view m_short_name
 A human readable short name for the item, should be one word only.
 
std::string_view m_long_name
 A human readable longer name for the item.
 
Word m_val
 The raw register value for the item.
 
Flags m_flags
 Flags influencing the processing of the item.
 

Additional Inherited Members

- Public Types inherited from clues::SystemCallItem
enum class  Flag { DEFER_FILL = 1 << 0 }
 
using Flags = cosmos::BitMask<Flag>
 

Detailed Description

Base class for file descriptor system call items.

Definition at line 27 of file fs.hxx.

Constructor & Destructor Documentation

◆ FileDescriptor()

clues::item::FileDescriptor::FileDescriptor ( const ItemType type = ItemType::PARAM_IN,
const AtSemantics at_semantics = AtSemantics{false},
const std::string_view short_name = "fd",
const std::string_view long_name = "file descriptor" )
inlineexplicit
Parameters
[in]at_semanticsIf set then the file descriptor is considered to be part of an *at() type system call i.e. the special file descriptor AT_FDCWD can occur.

Definition at line 38 of file fs.hxx.

39 {false},
40 const std::string_view short_name = "fd",
41 const std::string_view long_name = "file descriptor") :
42 SystemCallItem{type, short_name, long_name},
43 m_at_semantics{at_semantics} {
44 }
SystemCallItem(const ItemType type, const std::string_view short_name={}, const std::string_view long_name={})
Constructs a new SystemCallItem.

Member Function Documentation

◆ fd()

auto clues::item::FileDescriptor::fd ( ) const
inline

Definition at line 48 of file fs.hxx.

48 {
49 return m_fd;
50 }

◆ info()

const std::optional< FDInfo > & clues::item::FileDescriptor::info ( ) const
inline

Returns optional extended file descriptor metadata.

This data is available if FormatFlag::FD_INFO is set at the Engine object associated with this system call item.

Definition at line 57 of file fs.hxx.

57 {
58 return m_info;
59 }
std::optional< FDInfo > m_info
filled if FormatFlag::FD_INFO is set.
Definition fs.hxx:69

◆ processValue()

void clues::item::FileDescriptor::processValue ( const Tracee & )
overrideprotectedvirtual

Processes the value stored in m_val acc. to the actual item type.

This function is called for all parameter types upon entry to a system call, and for ItemType::RETVAL upon exit from a system call.

For parameters of ItemType::PARAM_OUT this callback can be used to reset any stored data to be filled in later when updateData() is called.

Reimplemented from clues::SystemCallItem.

Definition at line 39 of file fs.cxx.

39 {
41
42 if (proc.engine().formatFlags()[Engine::FormatFlag::FD_INFO]) {
43 m_info.reset();
44
45 const auto &map = proc.fdInfoMap();
46
47 if (auto it = map.find(m_fd); it != map.end()) {
48 m_info = it->second;
49 }
50 }
51}
@ FD_INFO
print detailed file descriptor information
Definition Engine.hxx:50
OTHER valueAs() const
Helper to cast the strongly typed Word m_val to other strong enum types.

◆ str()

std::string clues::item::FileDescriptor::str ( ) const
overridevirtual

Returns a human readable string representation of the item.

This member function should be specialized in derived classes to output the item's data in a fashion suitable for the concrete item type.

Reimplemented from clues::SystemCallItem.

Definition at line 26 of file fs.cxx.

26 {
27 if (m_at_semantics && m_fd == cosmos::FileNum::AT_CWD)
28 return "AT_FDCWD";
29
30 auto ret = std::to_string(cosmos::to_integral(m_fd));
31
32 if (m_info) {
33 ret += format::fd_info(*m_info);
34 }
35
36 return ret;
37}

Member Data Documentation

◆ m_at_semantics

const AtSemantics clues::item::FileDescriptor::m_at_semantics = AtSemantics{false}
protected

Definition at line 71 of file fs.hxx.

71{false};

◆ m_fd

cosmos::FileNum clues::item::FileDescriptor::m_fd
protected

Definition at line 67 of file fs.hxx.

◆ m_info

std::optional<FDInfo> clues::item::FileDescriptor::m_info
protected

filled if FormatFlag::FD_INFO is set.

Definition at line 69 of file fs.hxx.


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