| 781 | |
| 782 | |
| 783 | DebugBreakpoint DbgEngAdapter::AddBreakpoint(const std::uintptr_t address, unsigned long breakpoint_flags) |
| 784 | { |
| 785 | IDebugBreakpoint2* debug_breakpoint {}; |
| 786 | |
| 787 | /* attempt to read at breakpoint location to confirm its valid */ |
| 788 | /* DbgEng won't tell us if its valid until continue/go so this is a hacky fix */ |
| 789 | /* Note we cannot write to it if we are replaying TTD trace */ |
| 790 | auto val = this->ReadMemory(address, 1); |
| 791 | if (val.GetLength() != 1) |
| 792 | return {}; |
| 793 | |
| 794 | if (const auto result = |
| 795 | this->m_debugControl->AddBreakpoint2(DEBUG_BREAKPOINT_CODE, DEBUG_ANY_ID, &debug_breakpoint); |
| 796 | result != S_OK) |
| 797 | return {}; |
| 798 | |
| 799 | /* these will all work even on invalid addresses hence the previous checks */ |
| 800 | unsigned long id {}; |
| 801 | if (debug_breakpoint->GetId(&id) != S_OK) |
| 802 | return {}; |
| 803 | |
| 804 | if (debug_breakpoint->SetOffset(address) != S_OK) |
| 805 | return {}; |
| 806 | |
| 807 | if (debug_breakpoint->SetFlags(DEBUG_BREAKPOINT_ENABLED | breakpoint_flags) != S_OK) |
| 808 | return {}; |
| 809 | |
| 810 | const auto new_breakpoint = DebugBreakpoint(address, id, true); |
| 811 | this->m_debug_breakpoints.push_back(new_breakpoint); |
| 812 | |
| 813 | return new_breakpoint; |
| 814 | } |
| 815 | |
| 816 | static std::string EscapeModuleName(const std::string& name) |
| 817 | { |
nothing calls this directly
no test coverage detected