thread_snapshot_linux.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright 2017 The Crashpad Authors. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef CRASHPAD_SNAPSHOT_LINUX_THREAD_SNAPSHOT_LINUX_H_
  15. #define CRASHPAD_SNAPSHOT_LINUX_THREAD_SNAPSHOT_LINUX_H_
  16. #include <stdint.h>
  17. #include "build/build_config.h"
  18. #include "snapshot/cpu_context.h"
  19. #include "snapshot/linux/process_reader_linux.h"
  20. #include "snapshot/memory_snapshot.h"
  21. #include "snapshot/memory_snapshot_generic.h"
  22. #include "snapshot/thread_snapshot.h"
  23. #include "util/misc/initialization_state_dcheck.h"
  24. namespace crashpad {
  25. namespace internal {
  26. //! \brief A ThreadSnapshot of a thread on a Linux system.
  27. class ThreadSnapshotLinux final : public ThreadSnapshot {
  28. public:
  29. ThreadSnapshotLinux();
  30. ThreadSnapshotLinux(const ThreadSnapshotLinux&) = delete;
  31. ThreadSnapshotLinux& operator=(const ThreadSnapshotLinux&) = delete;
  32. ~ThreadSnapshotLinux() override;
  33. //! \brief Initializes the object.
  34. //!
  35. //! \param[in] process_reader A ProcessReaderLinux for the process containing
  36. //! the thread.
  37. //! \param[in] thread The thread within the ProcessReaderLinux for
  38. //! which the snapshot should be created.
  39. //!
  40. //! \return `true` if the snapshot could be created, `false` otherwise with
  41. //! a message logged.
  42. bool Initialize(
  43. ProcessReaderLinux* process_reader,
  44. const ProcessReaderLinux::Thread& thread,
  45. uint32_t* gather_indirectly_referenced_memory_bytes_remaining);
  46. // ThreadSnapshot:
  47. const CPUContext* Context() const override;
  48. const MemorySnapshot* Stack() const override;
  49. uint64_t ThreadID() const override;
  50. std::string ThreadName() const override;
  51. int SuspendCount() const override;
  52. int Priority() const override;
  53. uint64_t ThreadSpecificDataAddress() const override;
  54. std::vector<const MemorySnapshot*> ExtraMemory() const override;
  55. private:
  56. union {
  57. #if defined(ARCH_CPU_X86_FAMILY)
  58. CPUContextX86 x86;
  59. CPUContextX86_64 x86_64;
  60. #elif defined(ARCH_CPU_ARM_FAMILY)
  61. CPUContextARM arm;
  62. CPUContextARM64 arm64;
  63. #elif defined(ARCH_CPU_MIPS_FAMILY)
  64. CPUContextMIPS mipsel;
  65. CPUContextMIPS64 mips64;
  66. #elif defined(ARCH_CPU_RISCV_FAMILY)
  67. CPUContextRISCV riscv;
  68. CPUContextRISCV64 riscv64;
  69. #else
  70. #error Port.
  71. #endif // ARCH_CPU_X86_FAMILY
  72. } context_union_;
  73. CPUContext context_;
  74. MemorySnapshotGeneric stack_;
  75. LinuxVMAddress thread_specific_data_address_;
  76. std::string thread_name_;
  77. pid_t thread_id_;
  78. int priority_;
  79. InitializationStateDcheck initialized_;
  80. std::vector<std::unique_ptr<MemorySnapshotGeneric>> pointed_to_memory_;
  81. };
  82. } // namespace internal
  83. } // namespace crashpad
  84. #endif // CRASHPAD_SNAPSHOT_LINUX_THREAD_SNAPSHOT_LINUX_H_