libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
clues::item::PointerToScalar< INT > Class Template Reference

A pointer to an integral data type which will be filled in by the kernel. More...

#include <items.hxx>

+ Inheritance diagram for clues::item::PointerToScalar< INT >:

Public Member Functions

 PointerToScalar (const std::string_view short_name, const std::string_view long_name={}, const ItemType type=ItemType::PARAM_OUT)
 
ForeignPtr pointer () const
 
std::optional< INT > value () const
 
std::string str () const override
 Returns a human readable string representation of the item.
 
void setBase (const Base base)
 
- Public Member Functions inherited from clues::item::PointerValue
 PointerValue (const ItemType type, const std::string_view short_name, const std::string_view long_name)
 
- 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 &tracee) override
 Processes the value stored in m_val acc. to the actual item type.
 
void updateData (const Tracee &tracee) override
 Called upon exit of the system call to update possible out parameters.
 
void fetchValue (const Tracee &tracee)
 
virtual std::string scalarToString () const
 
- 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

ForeignPtr m_ptr = ForeignPtr{}
 
std::optional< INT > m_val
 
Base m_base = Base::DEC
 
- 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

template<typename INT>
class clues::item::PointerToScalar< INT >

A pointer to an integral data type which will be filled in by the kernel.

The type can also be an enum type, but the size of the underlying type must match the system call's pointed-to type.

Definition at line 208 of file items.hxx.

Constructor & Destructor Documentation

◆ PointerToScalar()

template<typename INT>
clues::item::PointerToScalar< INT >::PointerToScalar ( const std::string_view short_name,
const std::string_view long_name = {},
const ItemType type = ItemType::PARAM_OUT )
inlineexplicit

Definition at line 212 of file items.hxx.

214 {},
215 const ItemType type = ItemType::PARAM_OUT) :
216 PointerValue{type, short_name, long_name} {
217 }
A pointer to an integral data type which will be filled in by the kernel.
Definition items.hxx:209

Member Function Documentation

◆ fetchValue()

template<typename INT>
void clues::item::PointerToScalar< INT >::fetchValue ( const Tracee & tracee)
protected

Definition at line 50 of file items.cxx.

50 {
51 INT val;
52
53 m_val.reset();
54
55 if (m_ptr == ForeignPtr::NO_POINTER)
56 return;
57
58 try {
59 if (tracee.readStruct(m_ptr, val)) {
60 m_val = val;
61 }
62 } catch (const std::exception &) {
63 // probably a bad address
64 }
65}

◆ pointer()

template<typename INT>
ForeignPtr clues::item::PointerToScalar< INT >::pointer ( ) const
inline

Definition at line 219 of file items.hxx.

219 {
220 return m_ptr;
221 }

◆ processValue()

template<typename INT>
void clues::item::PointerToScalar< INT >::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.

Reimplemented in clues::item::WaitStatusItem.

Definition at line 235 of file items.hxx.

235 {
236 m_ptr = valueAs<ForeignPtr>();
237
238 if (isIn() || isInOut()) {
239 fetchValue(tracee);
240 } else {
241 m_val.reset();
242 }
243 }
OTHER valueAs() const
Helper to cast the strongly typed Word m_val to other strong enum types.

◆ scalarToString()

template<typename INT>
std::string clues::item::PointerToScalar< INT >::scalarToString ( ) const
protectedvirtual

Definition at line 77 of file items.cxx.

77 {
78 if constexpr (std::is_enum_v<INT>) {
79 return format_number(cosmos::to_integral(*m_val), m_base);
80 }
81 if constexpr (!std::is_enum_v<INT>) {
82 if constexpr (std::is_pointer_v<INT>) {
83 return format_number(reinterpret_cast<uintptr_t>(*m_val), clues::Base::HEX);
84 }
85 if constexpr (!std::is_pointer_v<INT>) {
86 return format_number(*m_val, m_base);
87 }
88 }
89}

◆ setBase()

template<typename INT>
void clues::item::PointerToScalar< INT >::setBase ( const Base base)
inline

Definition at line 229 of file items.hxx.

229 {
230 m_base = base;
231 }

◆ str()

template<typename INT>
std::string clues::item::PointerToScalar< INT >::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 68 of file items.cxx.

68 {
69 if (m_ptr == ForeignPtr::NO_POINTER) {
70 return "NULL";
71 }
72
73 return format::pointer(m_ptr, m_val ? scalarToString() : "???"s);
74}

◆ updateData()

template<typename INT>
void clues::item::PointerToScalar< INT >::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.

Reimplemented in clues::item::WaitStatusItem.

Definition at line 245 of file items.hxx.

245 {
246 if (needsUpdate()) {
247 fetchValue(tracee);
248 }
249 }
bool needsUpdate() const
Returns whether the item needs to be updated after the system call is finished.

◆ value()

template<typename INT>
std::optional< INT > clues::item::PointerToScalar< INT >::value ( ) const
inline

Definition at line 223 of file items.hxx.

223 {
224 return m_val;
225 }

Member Data Documentation

◆ m_base

template<typename INT>
Base clues::item::PointerToScalar< INT >::m_base = Base::DEC
protected

Definition at line 259 of file items.hxx.

◆ m_ptr

template<typename INT>
ForeignPtr clues::item::PointerToScalar< INT >::m_ptr = ForeignPtr{}
protected

Definition at line 257 of file items.hxx.

257{};

◆ m_val

template<typename INT>
std::optional<INT> clues::item::PointerToScalar< INT >::m_val
protected

Definition at line 258 of file items.hxx.


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