1 //===-- ThreadElfCore.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_ThreadElfCore_h_ 11 #define liblldb_ThreadElfCore_h_ 12 13 #include <string> 14 15 #include "lldb/Target/Thread.h" 16 #include "lldb/Core/DataExtractor.h" 17 18 struct compat_timeval 19 { 20 int64_t tv_sec; 21 int32_t tv_usec; 22 }; 23 24 // PRSTATUS structure's size differs based on architecture. 25 // Currently parsing done only for x86-64 architecture by 26 // simply reading data from the buffer. 27 // The following macros are used to specify the size. 28 // Calculating size using sizeof() wont work because of padding. 29 #define ELFLINUXPRSTATUS64_SIZE (112) 30 #define ELFLINUXPRPSINFO64_SIZE (132) 31 32 struct ELFLinuxPrStatus 33 { 34 int32_t si_signo; 35 int32_t si_code; 36 int32_t si_errno; 37 38 int16_t pr_cursig; 39 40 uint64_t pr_sigpend; 41 uint64_t pr_sighold; 42 43 uint32_t pr_pid; 44 uint32_t pr_ppid; 45 uint32_t pr_pgrp; 46 uint32_t pr_sid; 47 48 compat_timeval pr_utime; 49 compat_timeval pr_stime; 50 compat_timeval pr_cutime; 51 compat_timeval pr_cstime; 52 53 ELFLinuxPrStatus(); 54 55 bool 56 Parse(lldb_private::DataExtractor &data, lldb_private::ArchSpec &arch); 57 58 static size_t GetSizeELFLinuxPrStatus59 GetSize(lldb_private::ArchSpec &arch) 60 { 61 switch(arch.GetCore()) 62 { 63 case lldb_private::ArchSpec::eCore_x86_64_x86_64: 64 return ELFLINUXPRSTATUS64_SIZE; 65 default: 66 return 0; 67 } 68 } 69 }; 70 71 struct ELFLinuxPrPsInfo 72 { 73 char pr_state; 74 char pr_sname; 75 char pr_zomb; 76 char pr_nice; 77 uint64_t pr_flag; 78 uint32_t pr_uid; 79 uint32_t pr_gid; 80 int32_t pr_pid; 81 int32_t pr_ppid; 82 int32_t pr_pgrp; 83 int32_t pr_sid; 84 char pr_fname[16]; 85 char pr_psargs[80]; 86 87 ELFLinuxPrPsInfo(); 88 89 bool 90 Parse(lldb_private::DataExtractor &data, lldb_private::ArchSpec &arch); 91 92 static size_t GetSizeELFLinuxPrPsInfo93 GetSize(lldb_private::ArchSpec &arch) 94 { 95 switch(arch.GetCore()) 96 { 97 case lldb_private::ArchSpec::eCore_x86_64_x86_64: 98 return ELFLINUXPRPSINFO64_SIZE; 99 default: 100 return 0; 101 } 102 } 103 104 }; 105 106 struct ThreadData 107 { 108 lldb_private::DataExtractor gpregset; 109 lldb_private::DataExtractor fpregset; 110 int signo; 111 std::string name; 112 }; 113 114 class ThreadElfCore : public lldb_private::Thread 115 { 116 public: 117 ThreadElfCore (lldb_private::Process &process, lldb::tid_t tid, 118 const ThreadData &td); 119 120 virtual 121 ~ThreadElfCore (); 122 123 virtual void 124 RefreshStateAfterStop(); 125 126 virtual lldb::RegisterContextSP 127 GetRegisterContext (); 128 129 virtual lldb::RegisterContextSP 130 CreateRegisterContextForFrame (lldb_private::StackFrame *frame); 131 132 virtual void 133 ClearStackFrames (); 134 135 static bool ThreadIDIsValid(lldb::tid_t thread)136 ThreadIDIsValid (lldb::tid_t thread) 137 { 138 return thread != 0; 139 } 140 141 virtual const char * GetName()142 GetName () 143 { 144 if (m_thread_name.empty()) 145 return NULL; 146 return m_thread_name.c_str(); 147 } 148 149 void SetName(const char * name)150 SetName (const char *name) 151 { 152 if (name && name[0]) 153 m_thread_name.assign (name); 154 else 155 m_thread_name.clear(); 156 } 157 158 protected: 159 //------------------------------------------------------------------ 160 // Member variables. 161 //------------------------------------------------------------------ 162 std::string m_thread_name; 163 lldb::RegisterContextSP m_thread_reg_ctx_sp; 164 165 int m_signo; 166 167 lldb_private::DataExtractor m_gpregset_data; 168 lldb_private::DataExtractor m_fpregset_data; 169 170 virtual bool CalculateStopInfo(); 171 172 }; 173 174 #endif // liblldb_ThreadElfCore_h_ 175