| Pavel Labath | 605b51b | 2016-02-23 13:56:30 +0000 | [diff] [blame] | 1 | //===-- 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 Labath | 7278496 | 2017-02-16 18:12:04 +0000 | [diff] [blame] | 13 | #include <memory> |
| 14 | #include <sched.h> |
| Pavel Labath | 8abd34f | 2017-01-25 11:19:45 +0000 | [diff] [blame] | 15 | #include <sys/types.h> |
| 16 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 17 | namespace lldb_private { |
| 18 | namespace process_linux { |
| Pavel Labath | 605b51b | 2016-02-23 13:56:30 +0000 | [diff] [blame] | 19 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 20 | // arm64 linux had a bug which prevented single-stepping and watchpoints from |
| Pavel Labath | 8abd34f | 2017-01-25 11:19:45 +0000 | [diff] [blame] | 21 | // 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 Labath | 605b51b | 2016-02-23 13:56:30 +0000 | [diff] [blame] | 25 | // the boot cpu. |
| 26 | // |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 27 | // The underlying issue has been fixed in android N and linux 4.4. This code can |
| Pavel Labath | 8abd34f | 2017-01-25 11:19:45 +0000 | [diff] [blame] | 28 | // be removed once these systems become obsolete. |
| 29 | |
| 30 | #if defined(__arm64__) || defined(__aarch64__) |
| 31 | class SingleStepWorkaround { |
| 32 | ::pid_t m_tid; |
| 33 | cpu_set_t m_original_set; |
| 34 | |
| Pavel Labath | 7278496 | 2017-02-16 18:12:04 +0000 | [diff] [blame] | 35 | SingleStepWorkaround(const SingleStepWorkaround &) = delete; |
| 36 | void operator=(const SingleStepWorkaround &) = delete; |
| 37 | |
| Pavel Labath | 8abd34f | 2017-01-25 11:19:45 +0000 | [diff] [blame] | 38 | public: |
| 39 | SingleStepWorkaround(::pid_t tid, cpu_set_t original_set) |
| 40 | : m_tid(tid), m_original_set(original_set) {} |
| 41 | ~SingleStepWorkaround(); |
| 42 | |
| Pavel Labath | 7278496 | 2017-02-16 18:12:04 +0000 | [diff] [blame] | 43 | static std::unique_ptr<SingleStepWorkaround> Get(::pid_t tid); |
| Pavel Labath | 8abd34f | 2017-01-25 11:19:45 +0000 | [diff] [blame] | 44 | }; |
| 45 | #else |
| 46 | class SingleStepWorkaround { |
| 47 | public: |
| Pavel Labath | 7278496 | 2017-02-16 18:12:04 +0000 | [diff] [blame] | 48 | static std::unique_ptr<SingleStepWorkaround> Get(::pid_t tid) { |
| 49 | return nullptr; |
| Pavel Labath | 8abd34f | 2017-01-25 11:19:45 +0000 | [diff] [blame] | 50 | } |
| 51 | }; |
| 52 | #endif |
| 53 | |
| Pavel Labath | 605b51b | 2016-02-23 13:56:30 +0000 | [diff] [blame] | 54 | } // end namespace process_linux |
| 55 | } // end namespace lldb_private |
| 56 | |
| 57 | #endif // #ifndef liblldb_SingleStepCheck_H_ |