blob: 3e928e663d70ff346093e0abafcd1e77065cd512 [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
Todd Fiala75930012016-08-19 04:21:48 +000017#include "MacOSX/DarwinLog/DarwinLogEvent.h"
Jason Molenda705b1802014-06-13 02:37:02 +000018#include "MacOSX/Genealogy.h"
19#include "MacOSX/ThreadInfo.h"
Jason Molenda20ee21b2015-07-10 23:15:22 +000020#include "JSONGenerator.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021#include "DNBDefs.h"
22#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
28#define CPU_TYPE_ARM64 ((cpu_type_t) 12 | 0x01000000)
29#endif
30
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031typedef bool (*DNBShouldCancelCallback) (void *);
32
Greg Clayton3af9ea52010-11-18 05:57:03 +000033void DNBInitialize ();
34void DNBTerminate ();
35
Greg Clayton3c144382010-12-01 22:45:40 +000036nub_bool_t DNBSetArchitecture (const char *arch);
37
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038//----------------------------------------------------------------------
39// Process control
40//----------------------------------------------------------------------
Greg Clayton6779606a2011-01-22 23:43:18 +000041nub_process_t DNBProcessLaunch (const char *path,
42 char const *argv[],
43 const char *envp[],
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +000044 const char *working_directory, // NULL => don't change, non-NULL => set working directory for inferior to this
Greg Clayton6779606a2011-01-22 23:43:18 +000045 const char *stdin_path,
46 const char *stdout_path,
47 const char *stderr_path,
48 bool no_stdio,
49 nub_launch_flavor_t launch_flavor,
Jason Molendaa3329782014-03-29 18:54:20 +000050 int disable_aslr,
51 const char *event_data,
Greg Clayton6779606a2011-01-22 23:43:18 +000052 char *err_str,
Greg Claytonf74cf862013-11-13 23:28:31 +000053 size_t err_len);
Greg Clayton6779606a2011-01-22 23:43:18 +000054
Jason Molenda752e1e82015-07-29 01:42:16 +000055nub_process_t DNBProcessGetPIDByName (const char *name);
Greg Claytonf74cf862013-11-13 23:28:31 +000056nub_process_t DNBProcessAttach (nub_process_t pid, struct timespec *timeout, char *err_str, size_t err_len);
57nub_process_t DNBProcessAttachByName (const char *name, struct timespec *timeout, char *err_str, size_t err_len);
58nub_process_t DNBProcessAttachWait (const char *wait_name, nub_launch_flavor_t launch_flavor, bool ignore_existing, struct timespec *timeout, useconds_t interval, char *err_str, size_t err_len, DNBShouldCancelCallback should_cancel = NULL, void *callback_data = NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059// Resume a process with exact instructions on what to do with each thread:
60// - If no thread actions are supplied (actions is NULL or num_actions is zero),
61// then all threads are continued.
62// - If any thread actions are supplied, then each thread will do as it is told
63// by the action. A default actions for any threads that don't have an
64// explicit thread action can be made by making a thread action with a tid of
65// INVALID_NUB_THREAD. If there is no default action, those threads will
66// remain stopped.
Jason Molendaa3329782014-03-29 18:54:20 +000067nub_bool_t DNBProcessResume (nub_process_t pid, const DNBThreadResumeAction *actions, size_t num_actions) DNB_EXPORT;
68nub_bool_t DNBProcessHalt (nub_process_t pid) DNB_EXPORT;
69nub_bool_t DNBProcessDetach (nub_process_t pid) DNB_EXPORT;
70nub_bool_t DNBProcessSignal (nub_process_t pid, int signal) DNB_EXPORT;
Greg Clayton4296c222014-04-24 19:54:32 +000071nub_bool_t DNBProcessInterrupt (nub_process_t pid) DNB_EXPORT;
Jason Molendaa3329782014-03-29 18:54:20 +000072nub_bool_t DNBProcessKill (nub_process_t pid) DNB_EXPORT;
73nub_bool_t DNBProcessSendEvent (nub_process_t pid, const char *event) DNB_EXPORT;
74nub_size_t DNBProcessMemoryRead (nub_process_t pid, nub_addr_t addr, nub_size_t size, void *buf) DNB_EXPORT;
Greg Clayton0b90be12015-06-23 21:27:50 +000075uint64_t DNBProcessMemoryReadInteger (nub_process_t pid, nub_addr_t addr, nub_size_t integer_size, uint64_t fail_value) DNB_EXPORT;
76nub_addr_t DNBProcessMemoryReadPointer (nub_process_t pid, nub_addr_t addr) DNB_EXPORT;
77std::string DNBProcessMemoryReadCString (nub_process_t pid, nub_addr_t addr) DNB_EXPORT;
78std::string DNBProcessMemoryReadCStringFixed (nub_process_t pid, nub_addr_t addr, nub_size_t fixed_length) DNB_EXPORT;
Jason Molendaa3329782014-03-29 18:54:20 +000079nub_size_t DNBProcessMemoryWrite (nub_process_t pid, nub_addr_t addr, nub_size_t size, const void *buf) DNB_EXPORT;
80nub_addr_t DNBProcessMemoryAllocate (nub_process_t pid, nub_size_t size, uint32_t permissions) DNB_EXPORT;
81nub_bool_t DNBProcessMemoryDeallocate (nub_process_t pid, nub_addr_t addr) DNB_EXPORT;
82int DNBProcessMemoryRegionInfo (nub_process_t pid, nub_addr_t addr, DNBRegionInfo *region_info) DNB_EXPORT;
83std::string DNBProcessGetProfileData (nub_process_t pid, DNBProfileDataScanType scanType) DNB_EXPORT;
84nub_bool_t DNBProcessSetEnableAsyncProfiling (nub_process_t pid, nub_bool_t enable, uint64_t interval_usec, DNBProfileDataScanType scan_type) DNB_EXPORT;
Todd Fiala75930012016-08-19 04:21:48 +000085DarwinLogEventVector DNBProcessGetAvailableDarwinLogEvents(nub_process_t pid);
86
Jason Molenda3dc85832011-11-09 08:03:56 +000087
Chris Lattner30fdc8d2010-06-08 16:52:24 +000088//----------------------------------------------------------------------
89// Process status
90//----------------------------------------------------------------------
Jason Molendaa3329782014-03-29 18:54:20 +000091nub_bool_t DNBProcessIsAlive (nub_process_t pid) DNB_EXPORT;
92nub_state_t DNBProcessGetState (nub_process_t pid) DNB_EXPORT;
93nub_bool_t DNBProcessGetExitStatus (nub_process_t pid, int *status) DNB_EXPORT;
94nub_bool_t DNBProcessSetExitStatus (nub_process_t pid, int status) DNB_EXPORT;
95const char * DNBProcessGetExitInfo (nub_process_t pid) DNB_EXPORT;
96nub_bool_t DNBProcessSetExitInfo (nub_process_t pid, const char *info) DNB_EXPORT;
97nub_size_t DNBProcessGetNumThreads (nub_process_t pid) DNB_EXPORT;
98nub_thread_t DNBProcessGetCurrentThread (nub_process_t pid) DNB_EXPORT;
99nub_thread_t DNBProcessGetCurrentThreadMachPort (nub_process_t pid) DNB_EXPORT;
100nub_thread_t DNBProcessSetCurrentThread (nub_process_t pid, nub_thread_t tid) DNB_EXPORT;
101nub_thread_t DNBProcessGetThreadAtIndex (nub_process_t pid, nub_size_t thread_idx) DNB_EXPORT;
102nub_bool_t DNBProcessSyncThreadState (nub_process_t pid, nub_thread_t tid) DNB_EXPORT;
103nub_addr_t DNBProcessGetSharedLibraryInfoAddress (nub_process_t pid) DNB_EXPORT;
104nub_bool_t DNBProcessSharedLibrariesUpdated (nub_process_t pid) DNB_EXPORT;
105nub_size_t DNBProcessGetSharedLibraryInfo (nub_process_t pid, nub_bool_t only_changed, DNBExecutableImageInfo **image_infos) DNB_EXPORT;
106nub_bool_t DNBProcessSetNameToAddressCallback (nub_process_t pid, DNBCallbackNameToAddress callback, void *baton) DNB_EXPORT;
107nub_bool_t DNBProcessSetSharedLibraryInfoCallback (nub_process_t pid, DNBCallbackCopyExecutableImageInfos callback, void *baton) DNB_EXPORT;
108nub_addr_t DNBProcessLookupAddress (nub_process_t pid, const char *name, const char *shlib) DNB_EXPORT;
109nub_size_t DNBProcessGetAvailableSTDOUT (nub_process_t pid, char *buf, nub_size_t buf_size) DNB_EXPORT;
110nub_size_t DNBProcessGetAvailableSTDERR (nub_process_t pid, char *buf, nub_size_t buf_size) DNB_EXPORT;
111nub_size_t DNBProcessGetAvailableProfileData (nub_process_t pid, char *buf, nub_size_t buf_size) DNB_EXPORT;
112nub_size_t DNBProcessGetStopCount (nub_process_t pid) DNB_EXPORT;
113uint32_t DNBProcessGetCPUType (nub_process_t pid) DNB_EXPORT;
Jason Molenda3dc85832011-11-09 08:03:56 +0000114
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115//----------------------------------------------------------------------
116// Process executable and arguments
117//----------------------------------------------------------------------
Greg Claytonf74cf862013-11-13 23:28:31 +0000118const char * DNBProcessGetExecutablePath (nub_process_t pid);
119const char * DNBProcessGetArgumentAtIndex (nub_process_t pid, nub_size_t idx);
120nub_size_t DNBProcessGetArgumentCount (nub_process_t pid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000121
122//----------------------------------------------------------------------
123// Process events
124//----------------------------------------------------------------------
Greg Claytonf74cf862013-11-13 23:28:31 +0000125nub_event_t DNBProcessWaitForEvents (nub_process_t pid, nub_event_t event_mask, bool wait_for_set, struct timespec* timeout);
126void DNBProcessResetEvents (nub_process_t pid, nub_event_t event_mask);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000127
128//----------------------------------------------------------------------
129// Thread functions
130//----------------------------------------------------------------------
Greg Claytonf74cf862013-11-13 23:28:31 +0000131const char * DNBThreadGetName (nub_process_t pid, nub_thread_t tid);
132nub_bool_t DNBThreadGetIdentifierInfo (nub_process_t pid, nub_thread_t tid, thread_identifier_info_data_t *ident_info);
133nub_state_t DNBThreadGetState (nub_process_t pid, nub_thread_t tid);
134nub_bool_t DNBThreadGetRegisterValueByID (nub_process_t pid, nub_thread_t tid, uint32_t set, uint32_t reg, DNBRegisterValue *value);
135nub_bool_t DNBThreadSetRegisterValueByID (nub_process_t pid, nub_thread_t tid, uint32_t set, uint32_t reg, const DNBRegisterValue *value);
136nub_size_t DNBThreadGetRegisterContext (nub_process_t pid, nub_thread_t tid, void *buf, size_t buf_len);
137nub_size_t DNBThreadSetRegisterContext (nub_process_t pid, nub_thread_t tid, const void *buf, size_t buf_len);
138uint32_t DNBThreadSaveRegisterState (nub_process_t pid, nub_thread_t tid);
139nub_bool_t DNBThreadRestoreRegisterState (nub_process_t pid, nub_thread_t tid, uint32_t save_id);
140nub_bool_t DNBThreadGetRegisterValueByName (nub_process_t pid, nub_thread_t tid, uint32_t set, const char *name, DNBRegisterValue *value);
141nub_bool_t DNBThreadGetStopReason (nub_process_t pid, nub_thread_t tid, DNBThreadStopInfo *stop_info);
142const char * DNBThreadGetInfo (nub_process_t pid, nub_thread_t tid);
Jason Molenda705b1802014-06-13 02:37:02 +0000143Genealogy::ThreadActivitySP DNBGetGenealogyInfoForThread (nub_process_t pid, nub_thread_t tid, bool &timed_out);
144Genealogy::ProcessExecutableInfoSP DNBGetGenealogyImageInfo (nub_process_t pid, size_t idx);
145ThreadInfo::QoS DNBGetRequestedQoSForThread (nub_process_t pid, nub_thread_t tid, nub_addr_t tsd, uint64_t dti_qos_class_index);
146nub_addr_t DNBGetPThreadT (nub_process_t pid, nub_thread_t tid);
147nub_addr_t DNBGetDispatchQueueT (nub_process_t pid, nub_thread_t tid);
148nub_addr_t DNBGetTSDAddressForThread (nub_process_t pid, nub_thread_t tid, uint64_t plo_pthread_tsd_base_address_offset, uint64_t plo_pthread_tsd_base_offset, uint64_t plo_pthread_tsd_entry_size);
Jason Molenda20ee21b2015-07-10 23:15:22 +0000149JSONGenerator::ObjectSP DNBGetLoadedDynamicLibrariesInfos (nub_process_t pid, nub_addr_t image_list_address, nub_addr_t image_count);
Jason Molendaa2992312016-07-07 01:09:23 +0000150JSONGenerator::ObjectSP DNBGetAllLoadedLibrariesInfos (nub_process_t pid);
151JSONGenerator::ObjectSP DNBGetLibrariesInfoForAddresses (nub_process_t pid, std::vector<uint64_t> &macho_addresses);
152JSONGenerator::ObjectSP DNBGetSharedCacheInfo (nub_process_t pid);
153
Jason Molenda705b1802014-06-13 02:37:02 +0000154//
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000155//----------------------------------------------------------------------
156// Breakpoint functions
157//----------------------------------------------------------------------
Greg Claytonf74cf862013-11-13 23:28:31 +0000158nub_bool_t DNBBreakpointSet (nub_process_t pid, nub_addr_t addr, nub_size_t size, nub_bool_t hardware);
159nub_bool_t DNBBreakpointClear (nub_process_t pid, nub_addr_t addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160
161//----------------------------------------------------------------------
162// Watchpoint functions
163//----------------------------------------------------------------------
Greg Claytonf74cf862013-11-13 23:28:31 +0000164nub_bool_t DNBWatchpointSet (nub_process_t pid, nub_addr_t addr, nub_size_t size, uint32_t watch_flags, nub_bool_t hardware);
165nub_bool_t DNBWatchpointClear (nub_process_t pid, nub_addr_t addr);
166uint32_t DNBWatchpointGetNumSupportedHWP (nub_process_t pid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000167
Greg Claytond04f0ed2015-05-26 18:00:51 +0000168uint32_t DNBGetRegisterCPUType ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000169const DNBRegisterSetInfo *
Greg Claytonf74cf862013-11-13 23:28:31 +0000170 DNBGetRegisterSetInfo (nub_size_t *num_reg_sets);
171nub_bool_t DNBGetRegisterInfoByName (const char *reg_name, DNBRegisterInfo* info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000172
173//----------------------------------------------------------------------
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000174// Other static nub information calls.
175//----------------------------------------------------------------------
Greg Claytonf74cf862013-11-13 23:28:31 +0000176const char * DNBStateAsString (nub_state_t state);
177nub_bool_t DNBResolveExecutablePath (const char *path, char *resolved_path, size_t resolved_path_size);
Jason Molenda6acc86c2015-08-12 03:27:33 +0000178bool DNBGetOSVersionNumbers (uint64_t *major, uint64_t *minor, uint64_t *patch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000179
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000180#endif