1 #ifndef _library__memorywatch__hpp__included__
2 #define _library__memorywatch__hpp__included__
4 #include "mathexpr.hpp"
15 * Read memory operator.
17 struct memread_oper
: public mathexpr::operinfo
28 * Evaluate the operator.
30 * Note: The first promise is for the address.
32 void evaluate(mathexpr::value target
, std::vector
<std::function
<mathexpr::value()>> promises
);
34 unsigned bytes
; //Number of bytes to read.
35 bool signed_flag
; //Is signed?
36 bool float_flag
; //Is float?
37 int endianess
; //Endianess (-1 => little, 0 => host, 1 => Big).
38 uint64_t scale_div
; //Scale divisor.
39 uint64_t addr_base
; //Address base.
40 uint64_t addr_size
; //Address size (0 => All).
41 memory_space
* mspace
; //Memory space to read.
45 * Memory watch item printer.
47 struct item_printer
: public GC::item
52 virtual ~item_printer();
54 * Show the watched value.
56 virtual void show(const std::string
& iname
, const std::string
& val
) = 0;
60 virtual void reset() = 0;
73 * Parameter t: The type of the result.
75 item(mathexpr::typeinfo
& t
)
76 : expr(GC::obj_tag(), &t
)
80 * Get the value as string.
82 std::string
get_value();
84 * Print the value to specified printer.
86 * Parameter iname: The name of the watch.
88 void show(const std::string
& iname
);
90 GC::pointer
<item_printer
> printer
; //Printer to use.
91 GC::pointer
<mathexpr::mathexpr
> expr
; //Expression to watch.
92 std::string format
; //Formatting to use.
96 * A set of memory watches.
105 * Call reset on all items and their printers in the set.
109 * Call reset and then show on all items in the set.
113 * Get the longest name (by UTF-8 length) in the set.
115 * Returns: The longest nontrivial name, or "" if none.
117 const std::string
& get_longest_name()
119 return get_longest_name(set::utflength_rate
);
122 * Get the longest name (by arbitrary function) in the set.
124 * Parameter rate: Get length for name function.
125 * Returns: The longest nontrivial name, or "" if none.
127 const std::string
& get_longest_name(std::function
<size_t(const std::string
& n
)> rate
);
129 * Get the set of memory watch names.
131 std::set
<std::string
> names_set();
133 * Get specified memory watch item.
135 * Parameter name: The name of the item.
137 * Throws std::runtime_error: No such item in set.
139 item
& get(const std::string
& name
);
141 * Get specified memory watch item (without throwing).
143 * Parameter name: The name of the item.
144 * Returns: The item, or NULL if no such item exists.
146 item
* get_soft(const std::string
& name
);
148 * Create a new memory watch item.
150 * Parameter name: The name of the new item.
151 * Parameter item: The new item. All fields are shallow-copied.
153 item
* create(const std::string
& name
, item
& item
);
155 * Destroy a memory watch item.
157 * Parameter name: The name of the item to destroy.
159 void destroy(const std::string
& name
);
161 * Call routine for all roots.
163 void foreach(std::function
<void(item
& item
)> cb
);
165 * Swap set with another.
167 void swap(set
& s
) throw();
169 static size_t utflength_rate(const std::string
& s
);
170 std::map
<std::string
, item
> roots
;