tatyana-krasnukha created this revision. Comments in this function didn't match code. Moved it in right place and grouped cases, that need only WriteMemoryPrivate call, at the top of the function. Applied clang-format.
Repository: rL LLVM https://reviews.llvm.org/D39967 Files: source/Target/Process.cpp
Index: source/Target/Process.cpp =================================================================== --- source/Target/Process.cpp +++ source/Target/Process.cpp @@ -129,11 +129,13 @@ nullptr, nullptr, "If true, breakpoints will be ignored during expression evaluation."}, {"unwind-on-error-in-expressions", OptionValue::eTypeBoolean, true, true, - nullptr, nullptr, "If true, errors in expression evaluation will unwind " - "the stack back to the state before the call."}, + nullptr, nullptr, + "If true, errors in expression evaluation will unwind " + "the stack back to the state before the call."}, {"python-os-plugin-path", OptionValue::eTypeFileSpec, false, true, nullptr, - nullptr, "A path to a python OS plug-in module file that contains a " - "OperatingSystemPlugIn class."}, + nullptr, + "A path to a python OS plug-in module file that contains a " + "OperatingSystemPlugIn class."}, {"stop-on-sharedlibrary-events", OptionValue::eTypeBoolean, true, false, nullptr, nullptr, "If true, stop when a shared library is loaded or unloaded."}, @@ -142,8 +144,9 @@ {"memory-cache-line-size", OptionValue::eTypeUInt64, false, 512, nullptr, nullptr, "The memory cache line size"}, {"optimization-warnings", OptionValue::eTypeBoolean, false, true, nullptr, - nullptr, "If true, warn when stopped in code that is optimized where " - "stepping and variable availability may not behave as expected."}, + nullptr, + "If true, warn when stopped in code that is optimized where " + "stepping and variable availability may not behave as expected."}, {nullptr, OptionValue::eTypeInvalid, false, 0, nullptr, nullptr, nullptr}}; enum { @@ -1203,8 +1206,7 @@ process_sp->GetStatus(*stream); process_sp->GetThreadStatus(*stream, only_threads_with_stop_reason, start_frame, num_frames, - num_frames_with_source, - stop_format); + num_frames_with_source, stop_format); if (curr_thread_stop_info_sp) { lldb::addr_t crashing_address; ValueObjectSP valobj_sp = StopInfo::GetCrashingDereference( @@ -1414,7 +1416,7 @@ lldb::pid_t pid, bool exited, int signo, // Zero for no signal int exit_status // Exit value of process if signal is zero - ) { +) { Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); if (log) log->Printf("Process::SetProcessExitStatus (pid=%" PRIu64 @@ -1741,7 +1743,8 @@ const lldb::ABISP &Process::GetABI() { if (!m_abi_sp) - m_abi_sp = ABI::FindPlugin(shared_from_this(), GetTarget().GetArchitecture()); + m_abi_sp = + ABI::FindPlugin(shared_from_this(), GetTarget().GetArchitecture()); return m_abi_sp; } @@ -2423,65 +2426,64 @@ BreakpointSiteList bp_sites_in_range; - if (m_breakpoint_site_list.FindInRange(addr, addr + size, - bp_sites_in_range)) { + if (!m_breakpoint_site_list.FindInRange(addr, addr + size, + bp_sites_in_range) || + bp_sites_in_range.IsEmpty()) { + // No breakpoint sites overlap - if (bp_sites_in_range.IsEmpty()) - return WriteMemoryPrivate(addr, buf, size, error); - else { - const uint8_t *ubuf = (const uint8_t *)buf; - uint64_t bytes_written = 0; + return WriteMemoryPrivate(addr, buf, size, error); + } - bp_sites_in_range.ForEach([this, addr, size, &bytes_written, &ubuf, - &error](BreakpointSite *bp) -> void { + const uint8_t *ubuf = (const uint8_t *)buf; + uint64_t bytes_written = 0; - if (error.Success()) { - addr_t intersect_addr; - size_t intersect_size; - size_t opcode_offset; - const bool intersects = bp->IntersectsRange( - addr, size, &intersect_addr, &intersect_size, &opcode_offset); - UNUSED_IF_ASSERT_DISABLED(intersects); - assert(intersects); - assert(addr <= intersect_addr && intersect_addr < addr + size); - assert(addr < intersect_addr + intersect_size && - intersect_addr + intersect_size <= addr + size); - assert(opcode_offset + intersect_size <= bp->GetByteSize()); + bp_sites_in_range.ForEach([this, addr, size, &bytes_written, &ubuf, + &error](BreakpointSite *bp) -> void { - // Check for bytes before this breakpoint - const addr_t curr_addr = addr + bytes_written; - if (intersect_addr > curr_addr) { - // There are some bytes before this breakpoint that we need to - // just write to memory - size_t curr_size = intersect_addr - curr_addr; - size_t curr_bytes_written = WriteMemoryPrivate( - curr_addr, ubuf + bytes_written, curr_size, error); - bytes_written += curr_bytes_written; - if (curr_bytes_written != curr_size) { - // We weren't able to write all of the requested bytes, we - // are done looping and will return the number of bytes that - // we have written so far. - if (error.Success()) - error.SetErrorToGenericError(); - } - } - // Now write any bytes that would cover up any software breakpoints - // directly into the breakpoint opcode buffer - ::memcpy(bp->GetSavedOpcodeBytes() + opcode_offset, - ubuf + bytes_written, intersect_size); - bytes_written += intersect_size; + if (error.Success()) { + addr_t intersect_addr; + size_t intersect_size; + size_t opcode_offset; + const bool intersects = bp->IntersectsRange( + addr, size, &intersect_addr, &intersect_size, &opcode_offset); + UNUSED_IF_ASSERT_DISABLED(intersects); + assert(intersects); + assert(addr <= intersect_addr && intersect_addr < addr + size); + assert(addr < intersect_addr + intersect_size && + intersect_addr + intersect_size <= addr + size); + assert(opcode_offset + intersect_size <= bp->GetByteSize()); + + // Check for bytes before this breakpoint + const addr_t curr_addr = addr + bytes_written; + if (intersect_addr > curr_addr) { + // There are some bytes before this breakpoint that we need to + // just write to memory + size_t curr_size = intersect_addr - curr_addr; + size_t curr_bytes_written = WriteMemoryPrivate( + curr_addr, ubuf + bytes_written, curr_size, error); + bytes_written += curr_bytes_written; + if (curr_bytes_written != curr_size) { + // We weren't able to write all of the requested bytes, we + // are done looping and will return zero. + if (error.Success()) + error.SetErrorToGenericError(); + + return; } - }); - - if (bytes_written < size) - WriteMemoryPrivate(addr + bytes_written, ubuf + bytes_written, - size - bytes_written, error); + } + // Now write any bytes that would cover up any software breakpoints + // directly into the breakpoint opcode buffer + ::memcpy(bp->GetSavedOpcodeBytes() + opcode_offset, ubuf + bytes_written, + intersect_size); + bytes_written += intersect_size; } - } else { - return WriteMemoryPrivate(addr, buf, size, error); - } + }); // Write any remaining bytes after the last breakpoint if we have any left + if (error.Success() && bytes_written < size) + WriteMemoryPrivate(addr + bytes_written, ubuf + bytes_written, + size - bytes_written, error); + return 0; // bytes_written; } @@ -2784,7 +2786,7 @@ system_runtime->DidLaunch(); if (!m_os_ap) - LoadOperatingSystemPlugin(false); + LoadOperatingSystemPlugin(false); // We successfully launched the process and stopped, // now it the right time to set up signal filters before resuming. @@ -4826,7 +4828,8 @@ HandleStoppedEvent(Thread &thread, const ThreadPlanSP &thread_plan_sp, RestorePlanState &restorer, const EventSP &event_sp, EventSP &event_to_broadcast_sp, - const EvaluateExpressionOptions &options, bool handle_interrupts) { + const EvaluateExpressionOptions &options, + bool handle_interrupts) { Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP | LIBLLDB_LOG_PROCESS); ThreadPlanSP plan = thread.GetCompletedPlan(); @@ -4842,7 +4845,8 @@ StopInfoSP stop_info_sp = thread.GetStopInfo(); if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonBreakpoint && stop_info_sp->ShouldNotify(event_sp.get())) { - LLDB_LOG(log, "stopped for breakpoint: {0}.", stop_info_sp->GetDescription()); + LLDB_LOG(log, "stopped for breakpoint: {0}.", + stop_info_sp->GetDescription()); if (!options.DoesIgnoreBreakpoints()) { // Restore the plan state and then force Private to false. We are going // to stop because of this plan so we need it to become a public plan or @@ -5095,9 +5099,8 @@ // event coalescing to cause us to lose OUR running event... ForceNextEventDelivery(); -// This while loop must exit out the bottom, there's cleanup that we need to do -// when we are done. -// So don't call return anywhere within it. + // This while loop must exit out the bottom, there's cleanup that we need to + // do when we are done. So don't call return anywhere within it. #ifdef LLDB_RUN_THREAD_HALT_WITH_EVENT // It's pretty much impossible to write test cases for things like: @@ -5338,12 +5341,14 @@ LLDB_LOG(log, "Running function with one thread timeout timed out."); } else - LLDB_LOG(log, "Restarting function with all threads enabled and " - "timeout: {0} timed out, abandoning execution.", + LLDB_LOG(log, + "Restarting function with all threads enabled and " + "timeout: {0} timed out, abandoning execution.", timeout); } else - LLDB_LOG(log, "Running function with timeout: {0} timed out, " - "abandoning execution.", + LLDB_LOG(log, + "Running function with timeout: {0} timed out, " + "abandoning execution.", timeout); } @@ -5762,8 +5767,7 @@ continue; } thread_sp->GetStatus(strm, start_frame, num_frames, - num_frames_with_source, - stop_format); + num_frames_with_source, stop_format); ++num_thread_infos_dumped; } else { Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); @@ -5803,14 +5807,14 @@ void Process::ClearPreResumeActions() { m_pre_resume_actions.clear(); } -void Process::ClearPreResumeAction(PreResumeActionCallback callback, void *baton) -{ - PreResumeCallbackAndBaton element(callback, baton); - auto found_iter = std::find(m_pre_resume_actions.begin(), m_pre_resume_actions.end(), element); - if (found_iter != m_pre_resume_actions.end()) - { - m_pre_resume_actions.erase(found_iter); - } +void Process::ClearPreResumeAction(PreResumeActionCallback callback, + void *baton) { + PreResumeCallbackAndBaton element(callback, baton); + auto found_iter = std::find(m_pre_resume_actions.begin(), + m_pre_resume_actions.end(), element); + if (found_iter != m_pre_resume_actions.end()) { + m_pre_resume_actions.erase(found_iter); + } } ProcessRunLock &Process::GetRunLock() {
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits