ThreadElfCore.h revision 263363
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
18struct 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#undef si_signo
33#undef si_code
34#undef si_errno
35
36struct ELFLinuxPrStatus
37{
38    int32_t         si_signo;
39    int32_t         si_code;
40    int32_t         si_errno;
41
42    int16_t         pr_cursig;
43
44    uint64_t        pr_sigpend;
45    uint64_t        pr_sighold;
46
47    uint32_t        pr_pid;
48    uint32_t        pr_ppid;
49    uint32_t        pr_pgrp;
50    uint32_t        pr_sid;
51
52    compat_timeval  pr_utime;
53    compat_timeval  pr_stime;
54    compat_timeval  pr_cutime;
55    compat_timeval  pr_cstime;
56
57    ELFLinuxPrStatus();
58
59    bool
60    Parse(lldb_private::DataExtractor &data, lldb_private::ArchSpec &arch);
61
62    static size_t
63    GetSize(lldb_private::ArchSpec &arch)
64    {
65        switch(arch.GetCore())
66        {
67            case lldb_private::ArchSpec::eCore_x86_64_x86_64:
68                return ELFLINUXPRSTATUS64_SIZE;
69            default:
70                return 0;
71        }
72    }
73};
74
75struct ELFLinuxPrPsInfo
76{
77    char        pr_state;
78    char        pr_sname;
79    char        pr_zomb;
80    char        pr_nice;
81    uint64_t    pr_flag;
82    uint32_t    pr_uid;
83    uint32_t    pr_gid;
84    int32_t     pr_pid;
85    int32_t     pr_ppid;
86    int32_t     pr_pgrp;
87    int32_t     pr_sid;
88    char        pr_fname[16];
89    char        pr_psargs[80];
90
91    ELFLinuxPrPsInfo();
92
93    bool
94    Parse(lldb_private::DataExtractor &data, lldb_private::ArchSpec &arch);
95
96    static size_t
97    GetSize(lldb_private::ArchSpec &arch)
98    {
99        switch(arch.GetCore())
100        {
101            case lldb_private::ArchSpec::eCore_x86_64_x86_64:
102                return ELFLINUXPRPSINFO64_SIZE;
103            default:
104                return 0;
105        }
106    }
107
108};
109
110struct ThreadData
111{
112    lldb_private::DataExtractor gpregset;
113    lldb_private::DataExtractor fpregset;
114    int signo;
115    std::string name;
116};
117
118class ThreadElfCore : public lldb_private::Thread
119{
120public:
121    ThreadElfCore (lldb_private::Process &process, lldb::tid_t tid,
122                   const ThreadData &td);
123
124    virtual
125    ~ThreadElfCore ();
126
127    virtual void
128    RefreshStateAfterStop();
129
130    virtual lldb::RegisterContextSP
131    GetRegisterContext ();
132
133    virtual lldb::RegisterContextSP
134    CreateRegisterContextForFrame (lldb_private::StackFrame *frame);
135
136    virtual void
137    ClearStackFrames ();
138
139    static bool
140    ThreadIDIsValid (lldb::tid_t thread)
141    {
142        return thread != 0;
143    }
144
145    virtual const char *
146    GetName ()
147    {
148        if (m_thread_name.empty())
149            return NULL;
150        return m_thread_name.c_str();
151    }
152
153    void
154    SetName (const char *name)
155    {
156        if (name && name[0])
157            m_thread_name.assign (name);
158        else
159            m_thread_name.clear();
160    }
161
162protected:
163    //------------------------------------------------------------------
164    // Member variables.
165    //------------------------------------------------------------------
166    std::string m_thread_name;
167    lldb::RegisterContextSP m_thread_reg_ctx_sp;
168
169    int m_signo;
170
171    lldb_private::DataExtractor m_gpregset_data;
172    lldb_private::DataExtractor m_fpregset_data;
173
174    virtual bool CalculateStopInfo();
175
176};
177
178#endif  // liblldb_ThreadElfCore_h_
179