feat(common/core): debug action index

Adds an action_index to each debug event (not all debug events
need it). This allows the debugger to partially execute a rule
including the possibility of multiple updates to context.
This commit is contained in:
Marc Durdin 2021-07-20 14:07:33 +10:00
parent 2f9d29905e
commit 4fbfd33943
5 changed files with 36 additions and 18 deletions

View file

@ -65,10 +65,15 @@ typedef struct {
*/
typedef struct {
km_kbp_cp context[DEBUG_MAX_CONTEXT];
km_kbp_cp context[DEBUG_MAX_CONTEXT]; // The context matched by the rule (? may not need this?) // TODO: rename to context_matched
void *group; // LPGROUP
void *rule; // LPKEY
uint16_t store_offsets[DEBUG_STORE_OFFSETS_SIZE]; // pairs--store, char position, terminated by 0xFFFF // TODO use a better structure here
/// Track the actions index in the actions that will be returned to
/// the debugger; the debugger uses this to determine when to
/// execute the actions when single-stepping.
uint16_t first_action;
} km_kbp_state_debug_kmx_info;
/**

View file

@ -11,7 +11,15 @@
using namespace km::kbp;
using namespace kmx;
void KMX_DebugItems::push_item(uint8_t type, uint32_t flags, LPGROUP group, LPKEY key, PKMX_WCHAR context, PKMX_WORD index_stack) {
void KMX_DebugItems::push_item(
uint8_t type,
uint32_t flags,
LPGROUP group,
LPKEY key,
PKMX_WCHAR context,
PKMX_WORD index_stack,
int first_action
) {
_items->assert_push_entry();
km_kbp_state_debug_item item = {type, flags};
item.kmx_info.rule = key;
@ -24,6 +32,8 @@ void KMX_DebugItems::push_item(uint8_t type, uint32_t flags, LPGROUP group, LPKE
}
item.kmx_info.context[DEBUG_MAX_CONTEXT-1] = 0;
item.kmx_info.group = group;
item.kmx_info.first_action = first_action;
_items->emplace_back(item);
}

View file

@ -27,7 +27,8 @@ private:
LPGROUP group = nullptr,
LPKEY key = nullptr,
PKMX_WCHAR context = nullptr,
PKMX_WORD index_stack = nullptr
PKMX_WORD index_stack = nullptr,
int first_action = 0
);
void fill_store_offsets(
km_kbp_state_debug_kmx_info *info,
@ -39,15 +40,16 @@ public:
void push_end(uint32_t flags);
void push_group_enter(LPGROUP group);
void push_group_exit(LPGROUP group, uint32_t flags);
void push_nomatch_enter(LPGROUP group);
void push_nomatch_enter(LPGROUP group, int first_action);
void push_nomatch_exit(LPGROUP group);
void push_match_enter(LPGROUP group);
void push_match_enter(LPGROUP group, int first_action);
void push_match_exit(LPGROUP group);
void push_rule_enter(
LPGROUP group,
LPKEY key,
PKMX_WCHAR context,
PKMX_WORD index_stack
PKMX_WORD index_stack,
int first_action
);
void push_rule_exit(
LPGROUP group,
@ -90,8 +92,8 @@ KMX_DebugItems::push_group_exit(LPGROUP group, uint32_t flags) {
}
inline void
KMX_DebugItems::push_nomatch_enter(LPGROUP group) {
push_item(KM_KBP_DEBUG_NOMATCH_ENTER, 0, group);
KMX_DebugItems::push_nomatch_enter(LPGROUP group, int first_action) {
push_item(KM_KBP_DEBUG_NOMATCH_ENTER, 0, group, nullptr, nullptr, nullptr, first_action);
}
inline void
@ -100,8 +102,8 @@ KMX_DebugItems::push_nomatch_exit(LPGROUP group) {
}
inline void
KMX_DebugItems::push_match_enter(LPGROUP group) {
push_item(KM_KBP_DEBUG_MATCH_ENTER, 0, group);
KMX_DebugItems::push_match_enter(LPGROUP group, int first_action) {
push_item(KM_KBP_DEBUG_MATCH_ENTER, 0, group, nullptr, nullptr, nullptr, first_action);
}
inline void
@ -114,9 +116,10 @@ KMX_DebugItems::push_rule_enter(
LPGROUP group,
LPKEY key,
PKMX_WCHAR context,
PKMX_WORD index_stack
PKMX_WORD index_stack,
int first_action
) {
push_item(KM_KBP_DEBUG_RULE_ENTER, 0, group, key, context, index_stack);
push_item(KM_KBP_DEBUG_RULE_ENTER, 0, group, key, context, index_stack, first_action);
}
inline void

View file

@ -270,7 +270,7 @@ KMX_BOOL KMX_ProcessEvent::ProcessGroup(LPGROUP gp, KMX_BOOL *pOutputKeystroke)
{
/* NoMatch rule found, and is a character key */
if(m_debug_items) {
m_debug_items->push_nomatch_enter(gp);
m_debug_items->push_nomatch_enter(gp, m_actions.Length());
}
PostString(gp->dpNoMatch, m_keyboard.Keyboard, NULL, pOutputKeystroke);
if(m_debug_items) {
@ -309,7 +309,7 @@ KMX_BOOL KMX_ProcessEvent::ProcessGroup(LPGROUP gp, KMX_BOOL *pOutputKeystroke)
m_miniContext[GLOBAL_ContextStackSize-1] = 0;
if(m_debug_items) {
m_debug_items->push_rule_enter(gp, kkp, m_miniContext, m_indexStack);
m_debug_items->push_rule_enter(gp, kkp, m_miniContext, m_indexStack, m_actions.Length());
}
/*
@ -355,7 +355,7 @@ KMX_BOOL KMX_ProcessEvent::ProcessGroup(LPGROUP gp, KMX_BOOL *pOutputKeystroke)
if(shouldProcessNomatch && gp->dpMatch && *gp->dpMatch) {
if(m_debug_items) {
m_debug_items->push_match_enter(gp);
m_debug_items->push_match_enter(gp, m_actions.Length());
}
PostString(gp->dpMatch, m_keyboard.Keyboard, NULL, pOutputKeystroke);
if(m_debug_items) {

View file

@ -77,7 +77,7 @@ bool are_store_offsets_equal(const uint16_t (&lhs)[DEBUG_STORE_OFFSETS_SIZE], co
bool operator==(km_kbp_state_debug_item const & lhs,
km_kbp_state_debug_item const & rhs)
{
auto result = (lhs.type == rhs.type && lhs.flags == rhs.flags);
auto result = (lhs.type == rhs.type && lhs.flags == rhs.flags && lhs.kmx_info.first_action == rhs.kmx_info.first_action);
if(result) {
LPGROUP lgp = static_cast<LPGROUP>(lhs.kmx_info.group), rgp = static_cast<LPGROUP>(rhs.kmx_info.group);
LPKEY lrule = static_cast<LPKEY>(lhs.kmx_info.rule), rrule = static_cast<LPKEY>(rhs.kmx_info.rule);
@ -327,9 +327,9 @@ void test_multiple_groups() {
km_kbp_state_debug_item{KM_KBP_DEBUG_RULE_ENTER, 0, {}, {u"", &gp, &kp1, {0xFFFF}}},
km_kbp_state_debug_item{KM_KBP_DEBUG_RULE_EXIT, 0, {}, {u"", &gp, &kp1, {0xFFFF}}},
km_kbp_state_debug_item{KM_KBP_DEBUG_MATCH_ENTER, 0, {}, {u"", &gp}},
km_kbp_state_debug_item{KM_KBP_DEBUG_MATCH_ENTER, 0, {}, {u"", &gp, nullptr, {}, 1}},
km_kbp_state_debug_item{KM_KBP_DEBUG_GROUP_ENTER, 0, {}, {u"", &gpa}},
km_kbp_state_debug_item{KM_KBP_DEBUG_RULE_ENTER, 0, {}, {u"a", &gpa, &kpa, {0xFFFF}}},
km_kbp_state_debug_item{KM_KBP_DEBUG_RULE_ENTER, 0, {}, {u"a", &gpa, &kpa, {0xFFFF}, 1}},
km_kbp_state_debug_item{KM_KBP_DEBUG_RULE_EXIT, 0, {}, {u"a", &gpa, &kpa, {0xFFFF}}},
km_kbp_state_debug_item{KM_KBP_DEBUG_GROUP_EXIT, 0, {}, {u"", &gpa}},
km_kbp_state_debug_item{KM_KBP_DEBUG_MATCH_EXIT, 0, {}, {u"", &gp}},