blob: 7acbd42810cc331f8e69d5eba00729b5e1895114 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- DNB.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// Created by Greg Clayton on 3/23/07.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef __DNB_h__
15#define __DNB_h__
16
Kate Stoneb9c1b512016-09-06 20:57:50 +000017#include "DNBDefs.h"
18#include "JSONGenerator.h"
Todd Fiala75930012016-08-19 04:21:48 +000019#include "MacOSX/DarwinLog/DarwinLogEvent.h"
Jason Molenda705b1802014-06-13 02:37:02 +000020#include "MacOSX/Genealogy.h"
21#include "MacOSX/ThreadInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include <mach/thread_info.h>
Greg Clayton7b0992d2013-04-18 22:45:39 +000023#include <string>
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024
Jason Molendaa3329782014-03-29 18:54:20 +000025#define DNB_EXPORT __attribute__((visibility("default")))
26
27#ifndef CPU_TYPE_ARM64
Kate Stoneb9c1b512016-09-06 20:57:50 +000028#define CPU_TYPE_ARM64 ((cpu_type_t)12 | 0x01000000)
Jason Molendaa3329782014-03-29 18:54:20 +000029#endif
30
Kate Stoneb9c1b512016-09-06 20:57:50 +000031typedef bool (*DNBShouldCancelCallback)(void *);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
Kate Stoneb9c1b512016-09-06 20:57:50 +000033void DNBInitialize();
34void DNBTerminate();
Greg Clayton3af9ea52010-11-18 05:57:03 +000035
Kate Stoneb9c1b512016-09-06 20:57:50 +000036nub_bool_t DNBSetArchitecture(const char *arch);
Greg Clayton3c144382010-12-01 22:45:40 +000037
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038//----------------------------------------------------------------------
39// Process control
40//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +000041nub_process_t DNBProcessLaunch(
42 const char *path, char const *argv[], const char *envp[],
43 const char *working_directory, // NULL => don't change, non-NULL => set
44 // working directory for inferior to this
45 const char *stdin_path, const char *stdout_path, const char *stderr_path,
46 bool no_stdio, nub_launch_flavor_t launch_flavor, int disable_aslr,
47 const char *event_data, char *err_str, size_t err_len);
Greg Clayton6779606a2011-01-22 23:43:18 +000048
Kate Stoneb9c1b512016-09-06 20:57:50 +000049nub_process_t DNBProcessGetPIDByName(const char *name);
50nub_process_t DNBProcessAttach(nub_process_t pid, struct timespec *timeout,
51 char *err_str, size_t err_len);
52nub_process_t DNBProcessAttachByName(const char *name, struct timespec *timeout,
53 char *err_str, size_t err_len);
54nub_process_t
55DNBProcessAttachWait(const char *wait_name, nub_launch_flavor_t launch_flavor,
56 bool ignore_existing, struct timespec *timeout,
57 useconds_t interval, char *err_str, size_t err_len,
58 DNBShouldCancelCallback should_cancel = NULL,
59 void *callback_data = NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060// Resume a process with exact instructions on what to do with each thread:
61// - If no thread actions are supplied (actions is NULL or num_actions is zero),
62// then all threads are continued.
63// - If any thread actions are supplied, then each thread will do as it is told
64// by the action. A default actions for any threads that don't have an
65// explicit thread action can be made by making a thread action with a tid of
66// INVALID_NUB_THREAD. If there is no default action, those threads will
67// remain stopped.
Kate Stoneb9c1b512016-09-06 20:57:50 +000068nub_bool_t DNBProcessResume(nub_process_t pid,
69 const DNBThreadResumeAction *actions,
70 size_t num_actions) DNB_EXPORT;
71nub_bool_t DNBProcessHalt(nub_process_t pid) DNB_EXPORT;
72nub_bool_t DNBProcessDetach(nub_process_t pid) DNB_EXPORT;
73nub_bool_t DNBProcessSignal(nub_process_t pid, int signal) DNB_EXPORT;
74nub_bool_t DNBProcessInterrupt(nub_process_t pid) DNB_EXPORT;
75nub_bool_t DNBProcessKill(nub_process_t pid) DNB_EXPORT;
76nub_bool_t DNBProcessSendEvent(nub_process_t pid, const char *event) DNB_EXPORT;
77nub_size_t DNBProcessMemoryRead(nub_process_t pid, nub_addr_t addr,
78 nub_size_t size, void *buf) DNB_EXPORT;
79uint64_t DNBProcessMemoryReadInteger(nub_process_t pid, nub_addr_t addr,
80 nub_size_t integer_size,
81 uint64_t fail_value) DNB_EXPORT;
82nub_addr_t DNBProcessMemoryReadPointer(nub_process_t pid,
83 nub_addr_t addr) DNB_EXPORT;
84std::string DNBProcessMemoryReadCString(nub_process_t pid,
85 nub_addr_t addr) DNB_EXPORT;
86std::string
87DNBProcessMemoryReadCStringFixed(nub_process_t pid, nub_addr_t addr,
88 nub_size_t fixed_length) DNB_EXPORT;
89nub_size_t DNBProcessMemoryWrite(nub_process_t pid, nub_addr_t addr,
90 nub_size_t size, const void *buf) DNB_EXPORT;
91nub_addr_t DNBProcessMemoryAllocate(nub_process_t pid, nub_size_t size,
92 uint32_t permissions) DNB_EXPORT;
93nub_bool_t DNBProcessMemoryDeallocate(nub_process_t pid,
94 nub_addr_t addr) DNB_EXPORT;
95int DNBProcessMemoryRegionInfo(nub_process_t pid, nub_addr_t addr,
96 DNBRegionInfo *region_info) DNB_EXPORT;
97std::string
98DNBProcessGetProfileData(nub_process_t pid,
99 DNBProfileDataScanType scanType) DNB_EXPORT;
100nub_bool_t
101DNBProcessSetEnableAsyncProfiling(nub_process_t pid, nub_bool_t enable,
102 uint64_t interval_usec,
103 DNBProfileDataScanType scan_type) DNB_EXPORT;
Todd Fiala75930012016-08-19 04:21:48 +0000104DarwinLogEventVector DNBProcessGetAvailableDarwinLogEvents(nub_process_t pid);
105
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000106//----------------------------------------------------------------------
107// Process status
108//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +0000109nub_bool_t DNBProcessIsAlive(nub_process_t pid) DNB_EXPORT;
110nub_state_t DNBProcessGetState(nub_process_t pid) DNB_EXPORT;
111nub_bool_t DNBProcessGetExitStatus(nub_process_t pid, int *status) DNB_EXPORT;
112nub_bool_t DNBProcessSetExitStatus(nub_process_t pid, int status) DNB_EXPORT;
113const char *DNBProcessGetExitInfo(nub_process_t pid) DNB_EXPORT;
114nub_bool_t DNBProcessSetExitInfo(nub_process_t pid,
115 const char *info) DNB_EXPORT;
116nub_size_t DNBProcessGetNumThreads(nub_process_t pid) DNB_EXPORT;
117nub_thread_t DNBProcessGetCurrentThread(nub_process_t pid) DNB_EXPORT;
118nub_thread_t DNBProcessGetCurrentThreadMachPort(nub_process_t pid) DNB_EXPORT;
119nub_thread_t DNBProcessSetCurrentThread(nub_process_t pid,
120 nub_thread_t tid) DNB_EXPORT;
121nub_thread_t DNBProcessGetThreadAtIndex(nub_process_t pid,
122 nub_size_t thread_idx) DNB_EXPORT;
123nub_bool_t DNBProcessSyncThreadState(nub_process_t pid,
124 nub_thread_t tid) DNB_EXPORT;
125nub_addr_t DNBProcessGetSharedLibraryInfoAddress(nub_process_t pid) DNB_EXPORT;
126nub_bool_t DNBProcessSharedLibrariesUpdated(nub_process_t pid) DNB_EXPORT;
127nub_size_t
128DNBProcessGetSharedLibraryInfo(nub_process_t pid, nub_bool_t only_changed,
129 DNBExecutableImageInfo **image_infos) DNB_EXPORT;
130nub_bool_t DNBProcessSetNameToAddressCallback(nub_process_t pid,
131 DNBCallbackNameToAddress callback,
132 void *baton) DNB_EXPORT;
133nub_bool_t DNBProcessSetSharedLibraryInfoCallback(
134 nub_process_t pid, DNBCallbackCopyExecutableImageInfos callback,
135 void *baton) DNB_EXPORT;
136nub_addr_t DNBProcessLookupAddress(nub_process_t pid, const char *name,
137 const char *shlib) DNB_EXPORT;
138nub_size_t DNBProcessGetAvailableSTDOUT(nub_process_t pid, char *buf,
139 nub_size_t buf_size) DNB_EXPORT;
140nub_size_t DNBProcessGetAvailableSTDERR(nub_process_t pid, char *buf,
141 nub_size_t buf_size) DNB_EXPORT;
142nub_size_t DNBProcessGetAvailableProfileData(nub_process_t pid, char *buf,
143 nub_size_t buf_size) DNB_EXPORT;
144nub_size_t DNBProcessGetStopCount(nub_process_t pid) DNB_EXPORT;
145uint32_t DNBProcessGetCPUType(nub_process_t pid) DNB_EXPORT;
Jason Molenda3dc85832011-11-09 08:03:56 +0000146
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147//----------------------------------------------------------------------
148// Process executable and arguments
149//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +0000150const char *DNBProcessGetExecutablePath(nub_process_t pid);
151const char *DNBProcessGetArgumentAtIndex(nub_process_t pid, nub_size_t idx);
152nub_size_t DNBProcessGetArgumentCount(nub_process_t pid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000153
154//----------------------------------------------------------------------
155// Process events
156//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +0000157nub_event_t DNBProcessWaitForEvents(nub_process_t pid, nub_event_t event_mask,
158 bool wait_for_set,
159 struct timespec *timeout);
160void DNBProcessResetEvents(nub_process_t pid, nub_event_t event_mask);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161
162//----------------------------------------------------------------------
163// Thread functions
164//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +0000165const char *DNBThreadGetName(nub_process_t pid, nub_thread_t tid);
166nub_bool_t
167DNBThreadGetIdentifierInfo(nub_process_t pid, nub_thread_t tid,
168 thread_identifier_info_data_t *ident_info);
169nub_state_t DNBThreadGetState(nub_process_t pid, nub_thread_t tid);
170nub_bool_t DNBThreadGetRegisterValueByID(nub_process_t pid, nub_thread_t tid,
171 uint32_t set, uint32_t reg,
172 DNBRegisterValue *value);
173nub_bool_t DNBThreadSetRegisterValueByID(nub_process_t pid, nub_thread_t tid,
174 uint32_t set, uint32_t reg,
175 const DNBRegisterValue *value);
176nub_size_t DNBThreadGetRegisterContext(nub_process_t pid, nub_thread_t tid,
177 void *buf, size_t buf_len);
178nub_size_t DNBThreadSetRegisterContext(nub_process_t pid, nub_thread_t tid,
179 const void *buf, size_t buf_len);
180uint32_t DNBThreadSaveRegisterState(nub_process_t pid, nub_thread_t tid);
181nub_bool_t DNBThreadRestoreRegisterState(nub_process_t pid, nub_thread_t tid,
182 uint32_t save_id);
183nub_bool_t DNBThreadGetRegisterValueByName(nub_process_t pid, nub_thread_t tid,
184 uint32_t set, const char *name,
185 DNBRegisterValue *value);
186nub_bool_t DNBThreadGetStopReason(nub_process_t pid, nub_thread_t tid,
187 DNBThreadStopInfo *stop_info);
188const char *DNBThreadGetInfo(nub_process_t pid, nub_thread_t tid);
189Genealogy::ThreadActivitySP DNBGetGenealogyInfoForThread(nub_process_t pid,
190 nub_thread_t tid,
191 bool &timed_out);
192Genealogy::ProcessExecutableInfoSP DNBGetGenealogyImageInfo(nub_process_t pid,
193 size_t idx);
194ThreadInfo::QoS DNBGetRequestedQoSForThread(nub_process_t pid, nub_thread_t tid,
195 nub_addr_t tsd,
196 uint64_t dti_qos_class_index);
197nub_addr_t DNBGetPThreadT(nub_process_t pid, nub_thread_t tid);
198nub_addr_t DNBGetDispatchQueueT(nub_process_t pid, nub_thread_t tid);
199nub_addr_t
200DNBGetTSDAddressForThread(nub_process_t pid, nub_thread_t tid,
201 uint64_t plo_pthread_tsd_base_address_offset,
202 uint64_t plo_pthread_tsd_base_offset,
203 uint64_t plo_pthread_tsd_entry_size);
204JSONGenerator::ObjectSP DNBGetLoadedDynamicLibrariesInfos(
205 nub_process_t pid, nub_addr_t image_list_address, nub_addr_t image_count);
206JSONGenerator::ObjectSP DNBGetAllLoadedLibrariesInfos(nub_process_t pid);
207JSONGenerator::ObjectSP
208DNBGetLibrariesInfoForAddresses(nub_process_t pid,
209 std::vector<uint64_t> &macho_addresses);
210JSONGenerator::ObjectSP DNBGetSharedCacheInfo(nub_process_t pid);
Jason Molendaa2992312016-07-07 01:09:23 +0000211
Jason Molenda705b1802014-06-13 02:37:02 +0000212//
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000213//----------------------------------------------------------------------
214// Breakpoint functions
215//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +0000216nub_bool_t DNBBreakpointSet(nub_process_t pid, nub_addr_t addr, nub_size_t size,
217 nub_bool_t hardware);
218nub_bool_t DNBBreakpointClear(nub_process_t pid, nub_addr_t addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000219
220//----------------------------------------------------------------------
221// Watchpoint functions
222//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +0000223nub_bool_t DNBWatchpointSet(nub_process_t pid, nub_addr_t addr, nub_size_t size,
224 uint32_t watch_flags, nub_bool_t hardware);
225nub_bool_t DNBWatchpointClear(nub_process_t pid, nub_addr_t addr);
226uint32_t DNBWatchpointGetNumSupportedHWP(nub_process_t pid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000227
Kate Stoneb9c1b512016-09-06 20:57:50 +0000228uint32_t DNBGetRegisterCPUType();
229const DNBRegisterSetInfo *DNBGetRegisterSetInfo(nub_size_t *num_reg_sets);
230nub_bool_t DNBGetRegisterInfoByName(const char *reg_name,
231 DNBRegisterInfo *info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000232
233//----------------------------------------------------------------------
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000234// Other static nub information calls.
235//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +0000236const char *DNBStateAsString(nub_state_t state);
237nub_bool_t DNBResolveExecutablePath(const char *path, char *resolved_path,
238 size_t resolved_path_size);
239bool DNBGetOSVersionNumbers(uint64_t *major, uint64_t *minor, uint64_t *patch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000240
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000241#endif