openMSX
BreakPoint.hh
Go to the documentation of this file.
1#ifndef BREAKPOINT_HH
2#define BREAKPOINT_HH
3
4#include "BreakPointBase.hh"
5#include "CommandException.hh"
6
7#include "strCat.hh"
8
9#include <cstdint>
10#include <optional>
11
12namespace openmsx {
13
14class BreakPoint final : public BreakPointBase<BreakPoint>
15{
16public:
17 static constexpr std::string_view prefix = "bp#";
18
19public:
20 [[nodiscard]] std::optional<uint16_t> getAddress() const { return address; }
21 [[nodiscard]] TclObject getAddressString() const { return addrStr; }
22 void setAddress(Interpreter& interp, const TclObject& addr) {
23 addrStr = addr;
24 evaluateAddress(interp);
25 }
26
28 try {
29 address = parseAddress(interp);
30 } catch (MSXException&) {
31 address = {};
32 }
33 }
34
35 [[nodiscard]] std::string parseAddressError(Interpreter& interp) const {
36 try {
37 parseAddress(interp);
38 return {};
39 } catch (MSXException& e) {
40 return e.getMessage();
41 }
42 }
43
44private:
45 uint16_t parseAddress(Interpreter& interp) const {
46 auto tmp = addrStr.eval(interp).getInt(interp); // may throw
47 if ((tmp < 0) || (tmp > 0xffff)) {
48 throw CommandException("address outside of range 0...0xffff");
49 }
50 return uint16_t(tmp);
51 }
52
53 TclObject addrStr;
54 std::optional<uint16_t> address; // redundant: calculated from 'addrStr'
55};
56
57} // namespace openmsx
58
59#endif
CRTP base class for CPU break and watch points.
void evaluateAddress(Interpreter &interp)
Definition BreakPoint.hh:27
static constexpr std::string_view prefix
Definition BreakPoint.hh:17
TclObject getAddressString() const
Definition BreakPoint.hh:21
std::optional< uint16_t > getAddress() const
Definition BreakPoint.hh:20
void setAddress(Interpreter &interp, const TclObject &addr)
Definition BreakPoint.hh:22
std::string parseAddressError(Interpreter &interp) const
Definition BreakPoint.hh:35
TclObject eval(Interpreter &interp) const
Definition TclObject.cc:238
int getInt(Interpreter &interp) const
Definition TclObject.cc:69
This file implemented 3 utility functions:
Definition Autofire.cc:11