]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/debugserver/source/MacOSX/Genealogy.h
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / tools / debugserver / source / MacOSX / Genealogy.h
1 //===-- Activity.h -----------------------------------------------*- C++
2 //-*-===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef __Genealogy_h__
12 #define __Genealogy_h__
13
14 #include <mach/task.h>
15 #include <map>
16 #include <pthread.h>
17 #include <string>
18 #include <vector>
19
20 #include "GenealogySPI.h"
21 #include "MachThreadList.h"
22
23 class Genealogy {
24 public:
25   Genealogy();
26
27   ~Genealogy() {}
28
29   void Clear();
30
31   struct Breadcrumb {
32     uint32_t breadcrumb_id;
33     uint64_t activity_id;
34     uint64_t timestamp;
35     std::string name;
36   };
37
38   struct Activity {
39     uint64_t activity_start;
40     uint64_t activity_id;
41     uint64_t parent_id;
42     std::string activity_name;
43     std::string reason;
44   };
45
46   struct Message {
47     uint64_t timestamp;
48     uint64_t activity_id;
49     uint64_t trace_id;
50     uint64_t thread;
51     uint8_t type;                // OS_TRACE_TYPE_RELEASE, OS_TRACE_TYPE_DEBUG,
52                                  // OS_TRACE_TYPE_ERROR, OS_TRACE_TYPE_FAULT
53     uint32_t process_info_index; // index # of the image uuid/file path, 0 means
54                                  // unknown
55     std::string message;
56   };
57
58   typedef std::vector<Message> MessageList;
59   typedef std::vector<Breadcrumb> BreadcrumbList;
60   typedef std::vector<Activity> ActivityList;
61
62   struct ThreadActivity {
63     Activity current_activity;
64     MessageList messages;
65     BreadcrumbList breadcrumbs; // should be 0 or 1 breadcrumbs; no more than 1
66                                 // BC for any given activity
67   };
68
69   typedef std::shared_ptr<ThreadActivity> ThreadActivitySP;
70
71   ThreadActivitySP GetGenealogyInfoForThread(pid_t pid, nub_thread_t tid,
72                                              const MachThreadList &thread_list,
73                                              task_t task, bool &timed_out);
74
75   struct ProcessExecutableInfo {
76     std::string image_path;
77     uuid_t image_uuid;
78   };
79
80   typedef std::shared_ptr<ProcessExecutableInfo> ProcessExecutableInfoSP;
81
82   ProcessExecutableInfoSP GetProcessExecutableInfosAtIndex(size_t idx);
83
84   uint32_t AddProcessExecutableInfo(ProcessExecutableInfoSP process_exe_info);
85
86 private:
87   void GetActivities(pid_t pid, const MachThreadList &thread_list, task_t task);
88
89   // the spi we need to call into libtrace - look them up via dlsym at runtime
90   bool (*m_os_activity_diagnostic_for_pid)(pid_t pid, os_activity_t activity,
91                                            uint32_t flags,
92                                            os_diagnostic_block_t block);
93   void (*m_os_activity_iterate_processes)(
94       os_activity_process_list_t processes,
95       bool (^iterator)(os_activity_process_t process_info));
96   void (*m_os_activity_iterate_breadcrumbs)(
97       os_activity_process_t process_info,
98       bool (^iterator)(os_activity_breadcrumb_t breadcrumb));
99   void (*m_os_activity_iterate_messages)(
100       os_trace_message_list_t messages, os_activity_process_t process_info,
101       bool (^iterator)(os_trace_message_t tracemsg));
102   void (*m_os_activity_iterate_activities)(
103       os_activity_list_t activities, os_activity_process_t process_info,
104       bool (^iterator)(os_activity_entry_t activity));
105   uint8_t (*m_os_trace_get_type)(os_trace_message_t trace_msg);
106   char *(*m_os_trace_copy_formatted_message)(os_trace_message_t trace_msg);
107   os_activity_t (*m_os_activity_for_thread)(os_activity_process_t process,
108                                             uint64_t thread_id);
109   os_activity_t (*m_os_activity_for_task_thread)(task_t target,
110                                                  uint64_t thread_id);
111   os_trace_message_list_t (*m_os_activity_messages_for_thread)(
112       os_activity_process_t process, os_activity_t activity,
113       uint64_t thread_id);
114
115   std::map<nub_thread_t, ThreadActivitySP> m_thread_activities;
116   std::vector<ProcessExecutableInfoSP> m_process_executable_infos;
117   bool m_diagnosticd_call_timed_out;
118 };
119
120 #endif // __Genealogy_h__