blob: afeda7310349a36174284d12bcad49638ec9c01e [file] [log] [blame]
Pavel Labath605b51b2016-02-23 13:56:30 +00001//===-- SingleStepCheck.h ------------------------------------- -*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_SingleStepCheck_H_
11#define liblldb_SingleStepCheck_H_
12
Pavel Labath72784962017-02-16 18:12:04 +000013#include <memory>
14#include <sched.h>
Pavel Labath8abd34f2017-01-25 11:19:45 +000015#include <sys/types.h>
16
Kate Stoneb9c1b512016-09-06 20:57:50 +000017namespace lldb_private {
18namespace process_linux {
Pavel Labath605b51b2016-02-23 13:56:30 +000019
Kate Stoneb9c1b512016-09-06 20:57:50 +000020// arm64 linux had a bug which prevented single-stepping and watchpoints from
Pavel Labath8abd34f2017-01-25 11:19:45 +000021// working on non-boot cpus, due to them being incorrectly initialized after
22// coming out of suspend. This issue is particularly affecting android M, which
23// uses suspend ("doze mode") quite aggressively. This code detects that
24// situation and makes single-stepping work by doing all the step operations on
Pavel Labath605b51b2016-02-23 13:56:30 +000025// the boot cpu.
26//
Kate Stoneb9c1b512016-09-06 20:57:50 +000027// The underlying issue has been fixed in android N and linux 4.4. This code can
Pavel Labath8abd34f2017-01-25 11:19:45 +000028// be removed once these systems become obsolete.
29
30#if defined(__arm64__) || defined(__aarch64__)
31class SingleStepWorkaround {
32 ::pid_t m_tid;
33 cpu_set_t m_original_set;
34
Pavel Labath72784962017-02-16 18:12:04 +000035 SingleStepWorkaround(const SingleStepWorkaround &) = delete;
36 void operator=(const SingleStepWorkaround &) = delete;
37
Pavel Labath8abd34f2017-01-25 11:19:45 +000038public:
39 SingleStepWorkaround(::pid_t tid, cpu_set_t original_set)
40 : m_tid(tid), m_original_set(original_set) {}
41 ~SingleStepWorkaround();
42
Pavel Labath72784962017-02-16 18:12:04 +000043 static std::unique_ptr<SingleStepWorkaround> Get(::pid_t tid);
Pavel Labath8abd34f2017-01-25 11:19:45 +000044};
45#else
46class SingleStepWorkaround {
47public:
Pavel Labath72784962017-02-16 18:12:04 +000048 static std::unique_ptr<SingleStepWorkaround> Get(::pid_t tid) {
49 return nullptr;
Pavel Labath8abd34f2017-01-25 11:19:45 +000050 }
51};
52#endif
53
Pavel Labath605b51b2016-02-23 13:56:30 +000054} // end namespace process_linux
55} // end namespace lldb_private
56
57#endif // #ifndef liblldb_SingleStepCheck_H_