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

c-string style system call data. More...

#include <strings.hxx>

+ Inheritance diagram for clues::item::StringData:

Public Member Functions

 StringData (const std::string_view short_name="string", const std::string_view long_name={}, const ItemType type=ItemType::PARAM_IN)
 
std::string str () const override
 Returns a human readable string representation of the item.
 
const std::optional< std::string > & data () const
 Returns the unmodified string data.
 
- 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 &proc) override
 Processes the value stored in m_val acc. to the actual item type.
 
void updateData (const Tracee &proc) override
 Called upon exit of the system call to update possible out parameters.
 
void fetch (const Tracee &)
 
- Protected Member Functions inherited from clues::SystemCallItem
void setSystemCall (const SystemCall &sc)
 Sets the system call context this item is a part of.
 

Protected Attributes

std::optional< std::string > m_str
 
- 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

c-string style system call data.

Definition at line 10 of file strings.hxx.

Constructor & Destructor Documentation

◆ StringData()

clues::item::StringData::StringData ( const std::string_view short_name = "string",
const std::string_view long_name = {},
const ItemType type = ItemType::PARAM_IN )
inlineexplicit

Definition at line 13 of file strings.hxx.

15 {},
16 const ItemType type = ItemType::PARAM_IN) :
17 SystemCallItem{type, short_name, long_name} {
18 }
SystemCallItem(const ItemType type, const std::string_view short_name={}, const std::string_view long_name={})
Constructs a new SystemCallItem.
ItemType
Basic type of a SystemCallItem.
@ PARAM_IN
An input parameter to the system call.

Member Function Documentation

◆ data()

const std::optional< std::string > & clues::item::StringData::data ( ) const
inline

Returns the unmodified string data.

Definition at line 23 of file strings.hxx.

23 {
24 return m_str;
25 }

◆ fetch()

void clues::item::StringData::fetch ( const Tracee & proc)
protected

Definition at line 20 of file strings.cxx.

20 {
21 m_str.emplace(std::string{});
22 // fetch the string from the Tracee's address space.
23 try {
24 proc.readString(asPtr(), *m_str);
25 } catch (...) {
26 m_str.reset();
27 }
28}

◆ processValue()

void clues::item::StringData::processValue ( const Tracee & )
inlineoverrideprotectedvirtual

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 29 of file strings.hxx.

29 {
30 if (!this->isOut()) {
31 fetch(proc);
32 }
33 }

◆ str()

std::string clues::item::StringData::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 10 of file strings.cxx.

10 {
11 if (!m_str) {
12 return "<invalid>";
13 } else if (m_str->empty()) {
14 return "\"\"";
15 } else {
16 return cosmos::sprintf("\"%s\"", m_str->c_str());
17 }
18}

◆ updateData()

void clues::item::StringData::updateData ( const Tracee & t)
inlineoverrideprotectedvirtual

Called upon exit of the system call to update possible out parameters.

This function is called for parameters of ItemType::PARAM_OUT and ItemType::PARAM_IN_OUT upon system call exit to update the data from the values returned from the system call.

The default implementation calls processValue() to allow to share the same data processing code for input and output for item types that support both.

This function is called regardless of system call success or error, so it can happen that there is no valid data returned by the kernel or pointers in userspace are broken. Implementations should take this into consideration when operating on the data.

Reimplemented from clues::SystemCallItem.

Definition at line 35 of file strings.hxx.

35 {
36 fetch(proc);
37 }

Member Data Documentation

◆ m_str

std::optional<std::string> clues::item::StringData::m_str
protected

Definition at line 44 of file strings.hxx.


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