diff --git a/common/core/desktop/include/keyman/keyboardprocessor_debug.h b/common/core/desktop/include/keyman/keyboardprocessor_debug.h index 2b434b93f5..1b74384b6b 100644 --- a/common/core/desktop/include/keyman/keyboardprocessor_debug.h +++ b/common/core/desktop/include/keyman/keyboardprocessor_debug.h @@ -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; /** diff --git a/common/core/desktop/src/kmx/kmx_debugger.cpp b/common/core/desktop/src/kmx/kmx_debugger.cpp index b1fa05e388..76ffa1ced0 100644 --- a/common/core/desktop/src/kmx/kmx_debugger.cpp +++ b/common/core/desktop/src/kmx/kmx_debugger.cpp @@ -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); } diff --git a/common/core/desktop/src/kmx/kmx_debugger.h b/common/core/desktop/src/kmx/kmx_debugger.h index daddb3463a..e18b394f67 100644 --- a/common/core/desktop/src/kmx/kmx_debugger.h +++ b/common/core/desktop/src/kmx/kmx_debugger.h @@ -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 diff --git a/common/core/desktop/src/kmx/kmx_processevent.cpp b/common/core/desktop/src/kmx/kmx_processevent.cpp index b599e481de..656963639b 100644 --- a/common/core/desktop/src/kmx/kmx_processevent.cpp +++ b/common/core/desktop/src/kmx/kmx_processevent.cpp @@ -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) { diff --git a/common/core/desktop/tests/unit/kmnkbd/debug_api.cpp b/common/core/desktop/tests/unit/kmnkbd/debug_api.cpp index 8f4297b432..f38f38b199 100644 --- a/common/core/desktop/tests/unit/kmnkbd/debug_api.cpp +++ b/common/core/desktop/tests/unit/kmnkbd/debug_api.cpp @@ -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(lhs.kmx_info.group), rgp = static_cast(rhs.kmx_info.group); LPKEY lrule = static_cast(lhs.kmx_info.rule), rrule = static_cast(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}},