1 #ifndef _library__memorywatch__hpp__included__
2 #define _library__memorywatch__hpp__included__
4 #include "mathexpr.hpp"
14 * Read memory operator.
16 struct memread_oper
: public mathexpr::operinfo
27 * Evaluate the operator.
29 * Note: The first promise is for the address.
31 void evaluate(mathexpr::value target
, std::vector
<std::function
<mathexpr::value()>> promises
);
33 unsigned bytes
; //Number of bytes to read.
34 bool signed_flag
; //Is signed?
35 bool float_flag
; //Is float?
36 int endianess
; //Endianess (-1 => little, 0 => host, 1 => Big).
37 uint64_t scale_div
; //Scale divisor.
38 uint64_t addr_base
; //Address base.
39 uint64_t addr_size
; //Address size (0 => All).
40 memory_space
* mspace
; //Memory space to read.
44 * Memory watch item printer.
46 struct item_printer
: public GC::item
51 virtual ~item_printer();
53 * Show the watched value.
55 virtual void show(const std::string
& iname
, const std::string
& val
) = 0;
59 virtual void reset() = 0;
72 * Parameter t: The type of the result.
74 item(mathexpr::typeinfo
& t
)
75 : expr(GC::obj_tag(), &t
)
79 * Get the value as string.
81 std::string
get_value();
83 * Print the value to specified printer.
85 * Parameter iname: The name of the watch.
87 void show(const std::string
& iname
);
89 GC::pointer
<item_printer
> printer
; //Printer to use.
90 GC::pointer
<mathexpr::mathexpr
> expr
; //Expression to watch.
91 std::string format
; //Formatting to use.
95 * A set of memory watches.
104 * Call reset on all items and their printers in the set.
108 * Call reset and then show on all items in the set.
112 * Get the longest name (by UTF-8 length) in the set.
114 * Returns: The longest nontrivial name, or "" if none.
116 const std::string
& get_longest_name()
118 return get_longest_name(set::utflength_rate
);
121 * Get the longest name (by arbitrary function) in the set.
123 * Parameter rate: Get length for name function.
124 * Returns: The longest nontrivial name, or "" if none.
126 const std::string
& get_longest_name(std::function
<size_t(const std::string
& n
)> rate
);
128 * Get the set of memory watch names.
130 std::set
<std::string
> names_set();
132 * Get specified memory watch item.
134 * Parameter name: The name of the item.
136 * Throws std::runtime_error: No such item in set.
138 item
& get(const std::string
& name
);
140 * Get specified memory watch item (without throwing).
142 * Parameter name: The name of the item.
143 * Returns: The item, or NULL if no such item exists.
145 item
* get_soft(const std::string
& name
);
147 * Create a new memory watch item.
149 * Parameter name: The name of the new item.
150 * Parameter item: The new item. All fields are shallow-copied.
152 item
* create(const std::string
& name
, item
& item
);
154 * Destroy a memory watch item.
156 * Parameter name: The name of the item to destroy.
158 void destroy(const std::string
& name
);
160 * Call routine for all roots.
162 void foreach(std::function
<void(item
& item
)> cb
);
164 * Swap set with another.
166 void swap(set
& s
) throw();
168 static size_t utflength_rate(const std::string
& s
);
169 std::map
<std::string
, item
> roots
;