2014-07-01 05:05:18 +08:00
|
|
|
//===-- NativeThreadLinux.cpp --------------------------------- -*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-07-01 05:05:18 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "NativeThreadLinux.h"
|
|
|
|
|
|
|
|
#include <signal.h>
|
2015-02-03 09:51:47 +08:00
|
|
|
#include <sstream>
|
2014-07-01 05:05:18 +08:00
|
|
|
|
|
|
|
#include "NativeProcessLinux.h"
|
2015-08-24 21:25:54 +08:00
|
|
|
#include "NativeRegisterContextLinux.h"
|
Work around a stepping bug in arm64 android M
Summary:
On arm64, linux<=4.4 and Android<=M there is a bug, which prevents single-stepping from working when
the system comes back from suspend, because of incorrectly initialized CPUs. This did not really
affect Android<M, because it did not use software suspend, but it is a problem for M, which uses
suspend (doze) quite extensively. Fortunately, it seems that the first CPU is not affected by
this bug, so this commit implements a workaround by forcing the inferior to execute on the first
cpu whenever we are doing single stepping.
While inside, I have moved the implementations of Resume() and SingleStep() to the thread class
(instead of process).
Reviewers: tberghammer, ovyalov
Subscribers: aemerson, rengolin, tberghammer, danalbert, srhines, lldb-commits
Differential Revision: http://reviews.llvm.org/D17509
llvm-svn: 261636
2016-02-23 21:56:30 +08:00
|
|
|
#include "SingleStepCheck.h"
|
2014-07-01 07:51:35 +08:00
|
|
|
|
2014-09-10 04:54:56 +08:00
|
|
|
#include "lldb/Host/HostNativeThread.h"
|
Work around a stepping bug in arm64 android M
Summary:
On arm64, linux<=4.4 and Android<=M there is a bug, which prevents single-stepping from working when
the system comes back from suspend, because of incorrectly initialized CPUs. This did not really
affect Android<M, because it did not use software suspend, but it is a problem for M, which uses
suspend (doze) quite extensively. Fortunately, it seems that the first CPU is not affected by
this bug, so this commit implements a workaround by forcing the inferior to execute on the first
cpu whenever we are doing single stepping.
While inside, I have moved the implementations of Resume() and SingleStep() to the thread class
(instead of process).
Reviewers: tberghammer, ovyalov
Subscribers: aemerson, rengolin, tberghammer, danalbert, srhines, lldb-commits
Differential Revision: http://reviews.llvm.org/D17509
llvm-svn: 261636
2016-02-23 21:56:30 +08:00
|
|
|
#include "lldb/Host/linux/Ptrace.h"
|
2017-03-17 17:51:23 +08:00
|
|
|
#include "lldb/Host/linux/Support.h"
|
2015-03-20 07:28:10 +08:00
|
|
|
#include "lldb/Utility/LLDBAssert.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2018-08-07 19:07:21 +08:00
|
|
|
#include "lldb/Utility/State.h"
|
2014-07-01 05:05:18 +08:00
|
|
|
#include "lldb/lldb-enumerations.h"
|
2014-09-10 04:54:56 +08:00
|
|
|
|
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
|
2015-02-03 09:51:25 +08:00
|
|
|
#include "Plugins/Process/POSIX/CrashReason.h"
|
|
|
|
|
2015-05-11 18:03:10 +08:00
|
|
|
#include <sys/syscall.h>
|
|
|
|
// Try to define a macro to encapsulate the tgkill syscall
|
2016-09-07 04:57:50 +08:00
|
|
|
#define tgkill(pid, tid, sig) \
|
|
|
|
syscall(__NR_tgkill, static_cast<::pid_t>(pid), static_cast<::pid_t>(tid), \
|
|
|
|
sig)
|
2015-05-11 18:03:10 +08:00
|
|
|
|
2014-07-01 05:05:18 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
2015-03-31 17:52:22 +08:00
|
|
|
using namespace lldb_private::process_linux;
|
2014-07-01 05:05:18 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
namespace {
|
|
|
|
void LogThreadStopInfo(Log &log, const ThreadStopInfo &stop_info,
|
|
|
|
const char *const header) {
|
|
|
|
switch (stop_info.reason) {
|
|
|
|
case eStopReasonNone:
|
|
|
|
log.Printf("%s: %s no stop reason", __FUNCTION__, header);
|
|
|
|
return;
|
|
|
|
case eStopReasonTrace:
|
|
|
|
log.Printf("%s: %s trace, stopping signal 0x%" PRIx32, __FUNCTION__, header,
|
|
|
|
stop_info.details.signal.signo);
|
|
|
|
return;
|
|
|
|
case eStopReasonBreakpoint:
|
|
|
|
log.Printf("%s: %s breakpoint, stopping signal 0x%" PRIx32, __FUNCTION__,
|
|
|
|
header, stop_info.details.signal.signo);
|
|
|
|
return;
|
|
|
|
case eStopReasonWatchpoint:
|
|
|
|
log.Printf("%s: %s watchpoint, stopping signal 0x%" PRIx32, __FUNCTION__,
|
|
|
|
header, stop_info.details.signal.signo);
|
|
|
|
return;
|
|
|
|
case eStopReasonSignal:
|
|
|
|
log.Printf("%s: %s signal 0x%02" PRIx32, __FUNCTION__, header,
|
|
|
|
stop_info.details.signal.signo);
|
|
|
|
return;
|
|
|
|
case eStopReasonException:
|
|
|
|
log.Printf("%s: %s exception type 0x%02" PRIx64, __FUNCTION__, header,
|
|
|
|
stop_info.details.exception.type);
|
|
|
|
return;
|
|
|
|
case eStopReasonExec:
|
|
|
|
log.Printf("%s: %s exec, stopping signal 0x%" PRIx32, __FUNCTION__, header,
|
|
|
|
stop_info.details.signal.signo);
|
|
|
|
return;
|
|
|
|
case eStopReasonPlanComplete:
|
|
|
|
log.Printf("%s: %s plan complete", __FUNCTION__, header);
|
|
|
|
return;
|
|
|
|
case eStopReasonThreadExiting:
|
|
|
|
log.Printf("%s: %s thread exiting", __FUNCTION__, header);
|
|
|
|
return;
|
|
|
|
case eStopReasonInstrumentation:
|
|
|
|
log.Printf("%s: %s instrumentation", __FUNCTION__, header);
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
log.Printf("%s: %s invalid stop reason %" PRIu32, __FUNCTION__, header,
|
|
|
|
static_cast<uint32_t>(stop_info.reason));
|
|
|
|
}
|
2014-07-01 05:05:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-18 17:24:48 +08:00
|
|
|
NativeThreadLinux::NativeThreadLinux(NativeProcessLinux &process,
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::tid_t tid)
|
|
|
|
: NativeThreadProtocol(process, tid), m_state(StateType::eStateInvalid),
|
Clean up NativeRegisterContext
Summary:
This commit removes the concrete_frame_idx member from
NativeRegisterContext and related functions, which was always set to
zero and never used.
I also change the native thread class to store a NativeRegisterContext
as a unique_ptr (documenting the ownership) and make sure it is always
initialized (most of the code was already blindly dereferencing the
register context pointer, assuming it would always be present -- this
makes its treatment consistent).
Reviewers: eugene, clayborg, krytarowski
Subscribers: aemerson, sdardis, nemanjai, javed.absar, arichardson, kristof.beyls, kbarton, uweigand, alexandreyy, lldb-commits
Differential Revision: https://reviews.llvm.org/D39837
llvm-svn: 317881
2017-11-10 19:05:49 +08:00
|
|
|
m_stop_info(),
|
|
|
|
m_reg_context_up(
|
|
|
|
NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
|
|
|
|
process.GetArchitecture(), *this)),
|
|
|
|
m_stop_description() {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
std::string NativeThreadLinux::GetName() {
|
2017-03-17 17:51:23 +08:00
|
|
|
NativeProcessLinux &process = GetProcess();
|
|
|
|
|
|
|
|
auto BufferOrError = getProcFile(process.GetID(), GetID(), "comm");
|
|
|
|
if (!BufferOrError)
|
|
|
|
return "";
|
|
|
|
return BufferOrError.get()->getBuffer().rtrim('\n');
|
2014-07-01 05:05:18 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::StateType NativeThreadLinux::GetState() { return m_state; }
|
|
|
|
|
|
|
|
bool NativeThreadLinux::GetStopReason(ThreadStopInfo &stop_info,
|
|
|
|
std::string &description) {
|
|
|
|
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
|
|
|
|
|
|
|
|
description.clear();
|
|
|
|
|
|
|
|
switch (m_state) {
|
|
|
|
case eStateStopped:
|
|
|
|
case eStateCrashed:
|
|
|
|
case eStateExited:
|
|
|
|
case eStateSuspended:
|
|
|
|
case eStateUnloaded:
|
|
|
|
if (log)
|
|
|
|
LogThreadStopInfo(*log, m_stop_info, "m_stop_info in thread:");
|
|
|
|
stop_info = m_stop_info;
|
|
|
|
description = m_stop_description;
|
|
|
|
if (log)
|
|
|
|
LogThreadStopInfo(*log, stop_info, "returned stop_info:");
|
2014-07-01 05:05:18 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return true;
|
2014-07-01 05:05:18 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
case eStateInvalid:
|
|
|
|
case eStateConnected:
|
|
|
|
case eStateAttaching:
|
|
|
|
case eStateLaunching:
|
|
|
|
case eStateRunning:
|
|
|
|
case eStateStepping:
|
|
|
|
case eStateDetached:
|
|
|
|
if (log) {
|
|
|
|
log->Printf("NativeThreadLinux::%s tid %" PRIu64
|
|
|
|
" in state %s cannot answer stop reason",
|
|
|
|
__FUNCTION__, GetID(), StateAsCString(m_state));
|
2014-07-01 05:05:18 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
llvm_unreachable("unhandled StateType!");
|
2014-07-01 05:05:18 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status NativeThreadLinux::SetWatchpoint(lldb::addr_t addr, size_t size,
|
|
|
|
uint32_t watch_flags, bool hardware) {
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!hardware)
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status("not implemented");
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_state == eStateLaunching)
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status();
|
|
|
|
Status error = RemoveWatchpoint(addr);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
Clean up NativeRegisterContext
Summary:
This commit removes the concrete_frame_idx member from
NativeRegisterContext and related functions, which was always set to
zero and never used.
I also change the native thread class to store a NativeRegisterContext
as a unique_ptr (documenting the ownership) and make sure it is always
initialized (most of the code was already blindly dereferencing the
register context pointer, assuming it would always be present -- this
makes its treatment consistent).
Reviewers: eugene, clayborg, krytarowski
Subscribers: aemerson, sdardis, nemanjai, javed.absar, arichardson, kristof.beyls, kbarton, uweigand, alexandreyy, lldb-commits
Differential Revision: https://reviews.llvm.org/D39837
llvm-svn: 317881
2017-11-10 19:05:49 +08:00
|
|
|
uint32_t wp_index =
|
|
|
|
m_reg_context_up->SetHardwareWatchpoint(addr, size, watch_flags);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (wp_index == LLDB_INVALID_INDEX32)
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status("Setting hardware watchpoint failed.");
|
2016-09-07 04:57:50 +08:00
|
|
|
m_watchpoint_index_map.insert({addr, wp_index});
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status();
|
2014-07-01 05:05:18 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status NativeThreadLinux::RemoveWatchpoint(lldb::addr_t addr) {
|
2016-09-07 04:57:50 +08:00
|
|
|
auto wp = m_watchpoint_index_map.find(addr);
|
|
|
|
if (wp == m_watchpoint_index_map.end())
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status();
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t wp_index = wp->second;
|
|
|
|
m_watchpoint_index_map.erase(wp);
|
Clean up NativeRegisterContext
Summary:
This commit removes the concrete_frame_idx member from
NativeRegisterContext and related functions, which was always set to
zero and never used.
I also change the native thread class to store a NativeRegisterContext
as a unique_ptr (documenting the ownership) and make sure it is always
initialized (most of the code was already blindly dereferencing the
register context pointer, assuming it would always be present -- this
makes its treatment consistent).
Reviewers: eugene, clayborg, krytarowski
Subscribers: aemerson, sdardis, nemanjai, javed.absar, arichardson, kristof.beyls, kbarton, uweigand, alexandreyy, lldb-commits
Differential Revision: https://reviews.llvm.org/D39837
llvm-svn: 317881
2017-11-10 19:05:49 +08:00
|
|
|
if (m_reg_context_up->ClearHardwareWatchpoint(wp_index))
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status();
|
|
|
|
return Status("Clearing hardware watchpoint failed.");
|
2014-07-01 05:05:18 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status NativeThreadLinux::SetHardwareBreakpoint(lldb::addr_t addr,
|
|
|
|
size_t size) {
|
2017-02-24 21:27:31 +08:00
|
|
|
if (m_state == eStateLaunching)
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status();
|
2017-02-24 21:27:31 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error = RemoveHardwareBreakpoint(addr);
|
2017-02-24 21:27:31 +08:00
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
|
Clean up NativeRegisterContext
Summary:
This commit removes the concrete_frame_idx member from
NativeRegisterContext and related functions, which was always set to
zero and never used.
I also change the native thread class to store a NativeRegisterContext
as a unique_ptr (documenting the ownership) and make sure it is always
initialized (most of the code was already blindly dereferencing the
register context pointer, assuming it would always be present -- this
makes its treatment consistent).
Reviewers: eugene, clayborg, krytarowski
Subscribers: aemerson, sdardis, nemanjai, javed.absar, arichardson, kristof.beyls, kbarton, uweigand, alexandreyy, lldb-commits
Differential Revision: https://reviews.llvm.org/D39837
llvm-svn: 317881
2017-11-10 19:05:49 +08:00
|
|
|
uint32_t bp_index = m_reg_context_up->SetHardwareBreakpoint(addr, size);
|
2017-02-24 21:27:31 +08:00
|
|
|
|
|
|
|
if (bp_index == LLDB_INVALID_INDEX32)
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status("Setting hardware breakpoint failed.");
|
2017-02-24 21:27:31 +08:00
|
|
|
|
|
|
|
m_hw_break_index_map.insert({addr, bp_index});
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status();
|
2017-02-24 21:27:31 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status NativeThreadLinux::RemoveHardwareBreakpoint(lldb::addr_t addr) {
|
2017-02-24 21:27:31 +08:00
|
|
|
auto bp = m_hw_break_index_map.find(addr);
|
|
|
|
if (bp == m_hw_break_index_map.end())
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status();
|
2017-02-24 21:27:31 +08:00
|
|
|
|
|
|
|
uint32_t bp_index = bp->second;
|
Clean up NativeRegisterContext
Summary:
This commit removes the concrete_frame_idx member from
NativeRegisterContext and related functions, which was always set to
zero and never used.
I also change the native thread class to store a NativeRegisterContext
as a unique_ptr (documenting the ownership) and make sure it is always
initialized (most of the code was already blindly dereferencing the
register context pointer, assuming it would always be present -- this
makes its treatment consistent).
Reviewers: eugene, clayborg, krytarowski
Subscribers: aemerson, sdardis, nemanjai, javed.absar, arichardson, kristof.beyls, kbarton, uweigand, alexandreyy, lldb-commits
Differential Revision: https://reviews.llvm.org/D39837
llvm-svn: 317881
2017-11-10 19:05:49 +08:00
|
|
|
if (m_reg_context_up->ClearHardwareBreakpoint(bp_index)) {
|
2017-02-24 21:27:31 +08:00
|
|
|
m_hw_break_index_map.erase(bp);
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status();
|
2017-02-24 21:27:31 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status("Clearing hardware breakpoint failed.");
|
2017-02-24 21:27:31 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status NativeThreadLinux::Resume(uint32_t signo) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const StateType new_state = StateType::eStateRunning;
|
|
|
|
MaybeLogStateChange(new_state);
|
|
|
|
m_state = new_state;
|
Work around a stepping bug in arm64 android M
Summary:
On arm64, linux<=4.4 and Android<=M there is a bug, which prevents single-stepping from working when
the system comes back from suspend, because of incorrectly initialized CPUs. This did not really
affect Android<M, because it did not use software suspend, but it is a problem for M, which uses
suspend (doze) quite extensively. Fortunately, it seems that the first CPU is not affected by
this bug, so this commit implements a workaround by forcing the inferior to execute on the first
cpu whenever we are doing single stepping.
While inside, I have moved the implementations of Resume() and SingleStep() to the thread class
(instead of process).
Reviewers: tberghammer, ovyalov
Subscribers: aemerson, rengolin, tberghammer, danalbert, srhines, lldb-commits
Differential Revision: http://reviews.llvm.org/D17509
llvm-svn: 261636
2016-02-23 21:56:30 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_stop_info.reason = StopReason::eStopReasonNone;
|
|
|
|
m_stop_description.clear();
|
Work around a stepping bug in arm64 android M
Summary:
On arm64, linux<=4.4 and Android<=M there is a bug, which prevents single-stepping from working when
the system comes back from suspend, because of incorrectly initialized CPUs. This did not really
affect Android<M, because it did not use software suspend, but it is a problem for M, which uses
suspend (doze) quite extensively. Fortunately, it seems that the first CPU is not affected by
this bug, so this commit implements a workaround by forcing the inferior to execute on the first
cpu whenever we are doing single stepping.
While inside, I have moved the implementations of Resume() and SingleStep() to the thread class
(instead of process).
Reviewers: tberghammer, ovyalov
Subscribers: aemerson, rengolin, tberghammer, danalbert, srhines, lldb-commits
Differential Revision: http://reviews.llvm.org/D17509
llvm-svn: 261636
2016-02-23 21:56:30 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// If watchpoints have been set, but none on this thread, then this is a new
|
|
|
|
// thread. So set all existing watchpoints.
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_watchpoint_index_map.empty()) {
|
|
|
|
NativeProcessLinux &process = GetProcess();
|
Work around a stepping bug in arm64 android M
Summary:
On arm64, linux<=4.4 and Android<=M there is a bug, which prevents single-stepping from working when
the system comes back from suspend, because of incorrectly initialized CPUs. This did not really
affect Android<M, because it did not use software suspend, but it is a problem for M, which uses
suspend (doze) quite extensively. Fortunately, it seems that the first CPU is not affected by
this bug, so this commit implements a workaround by forcing the inferior to execute on the first
cpu whenever we are doing single stepping.
While inside, I have moved the implementations of Resume() and SingleStep() to the thread class
(instead of process).
Reviewers: tberghammer, ovyalov
Subscribers: aemerson, rengolin, tberghammer, danalbert, srhines, lldb-commits
Differential Revision: http://reviews.llvm.org/D17509
llvm-svn: 261636
2016-02-23 21:56:30 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const auto &watchpoint_map = process.GetWatchpointMap();
|
Clean up NativeRegisterContext
Summary:
This commit removes the concrete_frame_idx member from
NativeRegisterContext and related functions, which was always set to
zero and never used.
I also change the native thread class to store a NativeRegisterContext
as a unique_ptr (documenting the ownership) and make sure it is always
initialized (most of the code was already blindly dereferencing the
register context pointer, assuming it would always be present -- this
makes its treatment consistent).
Reviewers: eugene, clayborg, krytarowski
Subscribers: aemerson, sdardis, nemanjai, javed.absar, arichardson, kristof.beyls, kbarton, uweigand, alexandreyy, lldb-commits
Differential Revision: https://reviews.llvm.org/D39837
llvm-svn: 317881
2017-11-10 19:05:49 +08:00
|
|
|
m_reg_context_up->ClearAllHardwareWatchpoints();
|
2016-09-07 04:57:50 +08:00
|
|
|
for (const auto &pair : watchpoint_map) {
|
|
|
|
const auto &wp = pair.second;
|
|
|
|
SetWatchpoint(wp.m_addr, wp.m_size, wp.m_watch_flags, wp.m_hardware);
|
|
|
|
}
|
|
|
|
}
|
2014-07-01 05:05:18 +08:00
|
|
|
|
2017-02-24 21:27:31 +08:00
|
|
|
// Set all active hardware breakpoint on all threads.
|
|
|
|
if (m_hw_break_index_map.empty()) {
|
|
|
|
NativeProcessLinux &process = GetProcess();
|
|
|
|
|
|
|
|
const auto &hw_breakpoint_map = process.GetHardwareBreakpointMap();
|
Clean up NativeRegisterContext
Summary:
This commit removes the concrete_frame_idx member from
NativeRegisterContext and related functions, which was always set to
zero and never used.
I also change the native thread class to store a NativeRegisterContext
as a unique_ptr (documenting the ownership) and make sure it is always
initialized (most of the code was already blindly dereferencing the
register context pointer, assuming it would always be present -- this
makes its treatment consistent).
Reviewers: eugene, clayborg, krytarowski
Subscribers: aemerson, sdardis, nemanjai, javed.absar, arichardson, kristof.beyls, kbarton, uweigand, alexandreyy, lldb-commits
Differential Revision: https://reviews.llvm.org/D39837
llvm-svn: 317881
2017-11-10 19:05:49 +08:00
|
|
|
m_reg_context_up->ClearAllHardwareBreakpoints();
|
2017-02-24 21:27:31 +08:00
|
|
|
for (const auto &pair : hw_breakpoint_map) {
|
|
|
|
const auto &bp = pair.second;
|
|
|
|
SetHardwareBreakpoint(bp.m_addr, bp.m_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
intptr_t data = 0;
|
Work around a stepping bug in arm64 android M
Summary:
On arm64, linux<=4.4 and Android<=M there is a bug, which prevents single-stepping from working when
the system comes back from suspend, because of incorrectly initialized CPUs. This did not really
affect Android<M, because it did not use software suspend, but it is a problem for M, which uses
suspend (doze) quite extensively. Fortunately, it seems that the first CPU is not affected by
this bug, so this commit implements a workaround by forcing the inferior to execute on the first
cpu whenever we are doing single stepping.
While inside, I have moved the implementations of Resume() and SingleStep() to the thread class
(instead of process).
Reviewers: tberghammer, ovyalov
Subscribers: aemerson, rengolin, tberghammer, danalbert, srhines, lldb-commits
Differential Revision: http://reviews.llvm.org/D17509
llvm-svn: 261636
2016-02-23 21:56:30 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (signo != LLDB_INVALID_SIGNAL_NUMBER)
|
|
|
|
data = signo;
|
Work around a stepping bug in arm64 android M
Summary:
On arm64, linux<=4.4 and Android<=M there is a bug, which prevents single-stepping from working when
the system comes back from suspend, because of incorrectly initialized CPUs. This did not really
affect Android<M, because it did not use software suspend, but it is a problem for M, which uses
suspend (doze) quite extensively. Fortunately, it seems that the first CPU is not affected by
this bug, so this commit implements a workaround by forcing the inferior to execute on the first
cpu whenever we are doing single stepping.
While inside, I have moved the implementations of Resume() and SingleStep() to the thread class
(instead of process).
Reviewers: tberghammer, ovyalov
Subscribers: aemerson, rengolin, tberghammer, danalbert, srhines, lldb-commits
Differential Revision: http://reviews.llvm.org/D17509
llvm-svn: 261636
2016-02-23 21:56:30 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return NativeProcessLinux::PtraceWrapper(PTRACE_CONT, GetID(), nullptr,
|
|
|
|
reinterpret_cast<void *>(data));
|
|
|
|
}
|
Work around a stepping bug in arm64 android M
Summary:
On arm64, linux<=4.4 and Android<=M there is a bug, which prevents single-stepping from working when
the system comes back from suspend, because of incorrectly initialized CPUs. This did not really
affect Android<M, because it did not use software suspend, but it is a problem for M, which uses
suspend (doze) quite extensively. Fortunately, it seems that the first CPU is not affected by
this bug, so this commit implements a workaround by forcing the inferior to execute on the first
cpu whenever we are doing single stepping.
While inside, I have moved the implementations of Resume() and SingleStep() to the thread class
(instead of process).
Reviewers: tberghammer, ovyalov
Subscribers: aemerson, rengolin, tberghammer, danalbert, srhines, lldb-commits
Differential Revision: http://reviews.llvm.org/D17509
llvm-svn: 261636
2016-02-23 21:56:30 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status NativeThreadLinux::SingleStep(uint32_t signo) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const StateType new_state = StateType::eStateStepping;
|
|
|
|
MaybeLogStateChange(new_state);
|
|
|
|
m_state = new_state;
|
|
|
|
m_stop_info.reason = StopReason::eStopReasonNone;
|
2017-02-17 19:48:34 +08:00
|
|
|
|
|
|
|
if(!m_step_workaround) {
|
|
|
|
// If we already hava a workaround inplace, don't reset it. Otherwise, the
|
|
|
|
// destructor of the existing instance will run after the new instance has
|
|
|
|
// fetched the cpu mask, and the thread will end up with the wrong mask.
|
|
|
|
m_step_workaround = SingleStepWorkaround::Get(m_tid);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
intptr_t data = 0;
|
|
|
|
if (signo != LLDB_INVALID_SIGNAL_NUMBER)
|
|
|
|
data = signo;
|
|
|
|
|
|
|
|
// If hardware single-stepping is not supported, we just do a continue. The
|
2018-05-01 00:49:04 +08:00
|
|
|
// breakpoint on the next instruction has been setup in
|
|
|
|
// NativeProcessLinux::Resume.
|
2016-09-07 04:57:50 +08:00
|
|
|
return NativeProcessLinux::PtraceWrapper(
|
|
|
|
GetProcess().SupportHardwareSingleStepping() ? PTRACE_SINGLESTEP
|
|
|
|
: PTRACE_CONT,
|
|
|
|
m_tid, nullptr, reinterpret_cast<void *>(data));
|
2014-07-01 05:05:18 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void NativeThreadLinux::SetStoppedBySignal(uint32_t signo,
|
|
|
|
const siginfo_t *info) {
|
|
|
|
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
|
|
|
|
if (log)
|
|
|
|
log->Printf("NativeThreadLinux::%s called with signal 0x%02" PRIx32,
|
|
|
|
__FUNCTION__, signo);
|
|
|
|
|
|
|
|
SetStopped();
|
|
|
|
|
|
|
|
m_stop_info.reason = StopReason::eStopReasonSignal;
|
|
|
|
m_stop_info.details.signal.signo = signo;
|
|
|
|
|
|
|
|
m_stop_description.clear();
|
|
|
|
if (info) {
|
|
|
|
switch (signo) {
|
|
|
|
case SIGSEGV:
|
|
|
|
case SIGBUS:
|
|
|
|
case SIGFPE:
|
|
|
|
case SIGILL:
|
|
|
|
// In case of MIPS64 target, SI_KERNEL is generated for invalid 64bit
|
|
|
|
// address.
|
|
|
|
const auto reason =
|
|
|
|
(info->si_signo == SIGBUS && info->si_code == SI_KERNEL)
|
|
|
|
? CrashReason::eInvalidAddress
|
|
|
|
: GetCrashReason(*info);
|
2016-10-07 02:05:12 +08:00
|
|
|
m_stop_description = GetCrashReasonString(reason, *info);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
Report inferior SIGSEGV as a signal instead of an exception on linux
Summary:
Previously, we reported inferior receiving SIGSEGV (or SIGILL, SIGFPE, SIGBUS) as an "exception"
to LLDB, presumably to match OSX behaviour. Beside the fact that we were basically lying to the
user, this was also causing problems with inferiors which handle SIGSEGV by themselves, since
LLDB was unable to reinject this signal back into the inferior.
This commit changes LLGS to report SIGSEGV as a signal. This has necessitated some changes in the
test-suite, which had previously used eStopReasonException to locate threads that crashed. Now it
uses platform-specific logic, which in the case of linux searches for eStopReasonSignaled with
signal=SIGSEGV.
I have also added the ability to set the description of StopInfoUnixSignal using the description
field of the gdb-remote packet. The linux stub uses this to display additional information about
the segfault (invalid address, address access protected, etc.).
Test Plan: All tests pass on linux and osx.
Reviewers: ovyalov, clayborg, emaste
Subscribers: emaste, lldb-commits
Differential Revision: http://reviews.llvm.org/D10057
llvm-svn: 238549
2015-05-29 18:13:03 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-07-01 05:05:18 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool NativeThreadLinux::IsStopped(int *signo) {
|
|
|
|
if (!StateIsStoppedState(m_state, false))
|
|
|
|
return false;
|
2014-09-12 07:29:14 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// If we are stopped by a signal, return the signo.
|
|
|
|
if (signo && m_state == StateType::eStateStopped &&
|
|
|
|
m_stop_info.reason == StopReason::eStopReasonSignal) {
|
|
|
|
*signo = m_stop_info.details.signal.signo;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Regardless, we are stopped.
|
|
|
|
return true;
|
2014-09-12 07:29:14 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void NativeThreadLinux::SetStopped() {
|
|
|
|
if (m_state == StateType::eStateStepping)
|
2017-01-25 19:19:45 +08:00
|
|
|
m_step_workaround.reset();
|
Work around a stepping bug in arm64 android M
Summary:
On arm64, linux<=4.4 and Android<=M there is a bug, which prevents single-stepping from working when
the system comes back from suspend, because of incorrectly initialized CPUs. This did not really
affect Android<M, because it did not use software suspend, but it is a problem for M, which uses
suspend (doze) quite extensively. Fortunately, it seems that the first CPU is not affected by
this bug, so this commit implements a workaround by forcing the inferior to execute on the first
cpu whenever we are doing single stepping.
While inside, I have moved the implementations of Resume() and SingleStep() to the thread class
(instead of process).
Reviewers: tberghammer, ovyalov
Subscribers: aemerson, rengolin, tberghammer, danalbert, srhines, lldb-commits
Differential Revision: http://reviews.llvm.org/D17509
llvm-svn: 261636
2016-02-23 21:56:30 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const StateType new_state = StateType::eStateStopped;
|
|
|
|
MaybeLogStateChange(new_state);
|
|
|
|
m_state = new_state;
|
|
|
|
m_stop_description.clear();
|
Work around a stepping bug in arm64 android M
Summary:
On arm64, linux<=4.4 and Android<=M there is a bug, which prevents single-stepping from working when
the system comes back from suspend, because of incorrectly initialized CPUs. This did not really
affect Android<M, because it did not use software suspend, but it is a problem for M, which uses
suspend (doze) quite extensively. Fortunately, it seems that the first CPU is not affected by
this bug, so this commit implements a workaround by forcing the inferior to execute on the first
cpu whenever we are doing single stepping.
While inside, I have moved the implementations of Resume() and SingleStep() to the thread class
(instead of process).
Reviewers: tberghammer, ovyalov
Subscribers: aemerson, rengolin, tberghammer, danalbert, srhines, lldb-commits
Differential Revision: http://reviews.llvm.org/D17509
llvm-svn: 261636
2016-02-23 21:56:30 +08:00
|
|
|
}
|
2014-09-12 07:29:14 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void NativeThreadLinux::SetStoppedByExec() {
|
|
|
|
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
|
|
|
|
if (log)
|
|
|
|
log->Printf("NativeThreadLinux::%s()", __FUNCTION__);
|
2014-08-28 23:46:54 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SetStopped();
|
2014-08-28 23:46:54 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_stop_info.reason = StopReason::eStopReasonExec;
|
|
|
|
m_stop_info.details.signal.signo = SIGSTOP;
|
2014-08-28 23:46:54 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void NativeThreadLinux::SetStoppedByBreakpoint() {
|
|
|
|
SetStopped();
|
2014-07-01 05:05:18 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_stop_info.reason = StopReason::eStopReasonBreakpoint;
|
|
|
|
m_stop_info.details.signal.signo = SIGTRAP;
|
|
|
|
m_stop_description.clear();
|
2015-02-03 09:51:47 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void NativeThreadLinux::SetStoppedByWatchpoint(uint32_t wp_index) {
|
|
|
|
SetStopped();
|
2015-03-17 22:40:57 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldbassert(wp_index != LLDB_INVALID_INDEX32 && "wp_index cannot be invalid");
|
2015-03-17 22:40:57 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
std::ostringstream ostr;
|
Clean up NativeRegisterContext
Summary:
This commit removes the concrete_frame_idx member from
NativeRegisterContext and related functions, which was always set to
zero and never used.
I also change the native thread class to store a NativeRegisterContext
as a unique_ptr (documenting the ownership) and make sure it is always
initialized (most of the code was already blindly dereferencing the
register context pointer, assuming it would always be present -- this
makes its treatment consistent).
Reviewers: eugene, clayborg, krytarowski
Subscribers: aemerson, sdardis, nemanjai, javed.absar, arichardson, kristof.beyls, kbarton, uweigand, alexandreyy, lldb-commits
Differential Revision: https://reviews.llvm.org/D39837
llvm-svn: 317881
2017-11-10 19:05:49 +08:00
|
|
|
ostr << m_reg_context_up->GetWatchpointAddress(wp_index) << " ";
|
2016-09-07 04:57:50 +08:00
|
|
|
ostr << wp_index;
|
2015-08-13 11:44:09 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
/*
|
|
|
|
* MIPS: Last 3bits of the watchpoint address are masked by the kernel. For
|
|
|
|
* example:
|
|
|
|
* 'n' is at 0x120010d00 and 'm' is 0x120010d04. When a watchpoint is set at
|
|
|
|
* 'm', then
|
|
|
|
* watch exception is generated even when 'n' is read/written. To handle this
|
|
|
|
* case,
|
|
|
|
* find the base address of the load/store instruction and append it in the
|
|
|
|
* stop-info
|
|
|
|
* packet.
|
|
|
|
*/
|
Clean up NativeRegisterContext
Summary:
This commit removes the concrete_frame_idx member from
NativeRegisterContext and related functions, which was always set to
zero and never used.
I also change the native thread class to store a NativeRegisterContext
as a unique_ptr (documenting the ownership) and make sure it is always
initialized (most of the code was already blindly dereferencing the
register context pointer, assuming it would always be present -- this
makes its treatment consistent).
Reviewers: eugene, clayborg, krytarowski
Subscribers: aemerson, sdardis, nemanjai, javed.absar, arichardson, kristof.beyls, kbarton, uweigand, alexandreyy, lldb-commits
Differential Revision: https://reviews.llvm.org/D39837
llvm-svn: 317881
2017-11-10 19:05:49 +08:00
|
|
|
ostr << " " << m_reg_context_up->GetWatchpointHitAddress(wp_index);
|
2015-08-13 11:44:09 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_stop_description = ostr.str();
|
2015-03-17 22:40:57 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_stop_info.reason = StopReason::eStopReasonWatchpoint;
|
|
|
|
m_stop_info.details.signal.signo = SIGTRAP;
|
2014-07-01 05:05:18 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool NativeThreadLinux::IsStoppedAtBreakpoint() {
|
|
|
|
return GetState() == StateType::eStateStopped &&
|
|
|
|
m_stop_info.reason == StopReason::eStopReasonBreakpoint;
|
2015-02-03 09:51:47 +08:00
|
|
|
}
|
2014-07-01 05:05:18 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool NativeThreadLinux::IsStoppedAtWatchpoint() {
|
|
|
|
return GetState() == StateType::eStateStopped &&
|
|
|
|
m_stop_info.reason == StopReason::eStopReasonWatchpoint;
|
2014-07-01 05:05:18 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void NativeThreadLinux::SetStoppedByTrace() {
|
|
|
|
SetStopped();
|
2015-02-03 09:51:25 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_stop_info.reason = StopReason::eStopReasonTrace;
|
|
|
|
m_stop_info.details.signal.signo = SIGTRAP;
|
2015-02-03 09:51:25 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void NativeThreadLinux::SetStoppedWithNoReason() {
|
|
|
|
SetStopped();
|
2014-07-01 05:05:18 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_stop_info.reason = StopReason::eStopReasonNone;
|
|
|
|
m_stop_info.details.signal.signo = 0;
|
2014-07-01 05:05:18 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void NativeThreadLinux::SetExited() {
|
|
|
|
const StateType new_state = StateType::eStateExited;
|
|
|
|
MaybeLogStateChange(new_state);
|
|
|
|
m_state = new_state;
|
2014-07-01 05:05:18 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_stop_info.reason = StopReason::eStopReasonThreadExiting;
|
2014-07-01 05:05:18 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status NativeThreadLinux::RequestStop() {
|
2016-09-07 04:57:50 +08:00
|
|
|
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
|
2015-05-11 18:03:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
NativeProcessLinux &process = GetProcess();
|
|
|
|
|
|
|
|
lldb::pid_t pid = process.GetID();
|
|
|
|
lldb::tid_t tid = GetID();
|
2015-05-11 18:03:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("NativeThreadLinux::%s requesting thread stop(pid: %" PRIu64
|
|
|
|
", tid: %" PRIu64 ")",
|
|
|
|
__FUNCTION__, pid, tid);
|
2015-05-11 18:03:10 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status err;
|
2016-09-07 04:57:50 +08:00
|
|
|
errno = 0;
|
|
|
|
if (::tgkill(pid, tid, SIGSTOP) != 0) {
|
|
|
|
err.SetErrorToErrno();
|
2015-05-11 18:03:10 +08:00
|
|
|
if (log)
|
2016-09-07 04:57:50 +08:00
|
|
|
log->Printf("NativeThreadLinux::%s tgkill(%" PRIu64 ", %" PRIu64
|
|
|
|
", SIGSTOP) failed: %s",
|
|
|
|
__FUNCTION__, pid, tid, err.AsCString());
|
|
|
|
}
|
2015-05-11 18:03:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return err;
|
2015-05-11 18:03:10 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void NativeThreadLinux::MaybeLogStateChange(lldb::StateType new_state) {
|
|
|
|
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
|
|
|
|
// If we're not logging, we're done.
|
|
|
|
if (!log)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If this is a state change to the same state, we're done.
|
|
|
|
lldb::StateType old_state = m_state;
|
|
|
|
if (new_state == old_state)
|
|
|
|
return;
|
|
|
|
|
2017-07-18 17:24:48 +08:00
|
|
|
LLDB_LOG(log, "pid={0}, tid={1}: changing from state {2} to {3}",
|
|
|
|
m_process.GetID(), GetID(), old_state, new_state);
|
2014-07-01 05:05:18 +08:00
|
|
|
}
|
Work around a stepping bug in arm64 android M
Summary:
On arm64, linux<=4.4 and Android<=M there is a bug, which prevents single-stepping from working when
the system comes back from suspend, because of incorrectly initialized CPUs. This did not really
affect Android<M, because it did not use software suspend, but it is a problem for M, which uses
suspend (doze) quite extensively. Fortunately, it seems that the first CPU is not affected by
this bug, so this commit implements a workaround by forcing the inferior to execute on the first
cpu whenever we are doing single stepping.
While inside, I have moved the implementations of Resume() and SingleStep() to the thread class
(instead of process).
Reviewers: tberghammer, ovyalov
Subscribers: aemerson, rengolin, tberghammer, danalbert, srhines, lldb-commits
Differential Revision: http://reviews.llvm.org/D17509
llvm-svn: 261636
2016-02-23 21:56:30 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
NativeProcessLinux &NativeThreadLinux::GetProcess() {
|
2017-07-18 17:24:48 +08:00
|
|
|
return static_cast<NativeProcessLinux &>(m_process);
|
Work around a stepping bug in arm64 android M
Summary:
On arm64, linux<=4.4 and Android<=M there is a bug, which prevents single-stepping from working when
the system comes back from suspend, because of incorrectly initialized CPUs. This did not really
affect Android<M, because it did not use software suspend, but it is a problem for M, which uses
suspend (doze) quite extensively. Fortunately, it seems that the first CPU is not affected by
this bug, so this commit implements a workaround by forcing the inferior to execute on the first
cpu whenever we are doing single stepping.
While inside, I have moved the implementations of Resume() and SingleStep() to the thread class
(instead of process).
Reviewers: tberghammer, ovyalov
Subscribers: aemerson, rengolin, tberghammer, danalbert, srhines, lldb-commits
Differential Revision: http://reviews.llvm.org/D17509
llvm-svn: 261636
2016-02-23 21:56:30 +08:00
|
|
|
}
|