blob: c70ede989d579c29eda7b7df358ec6ee5032c514 [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
17#include "DNBDefs.h"
18#include <mach/thread_info.h>
Greg Clayton7b0992d2013-04-18 22:45:39 +000019#include <string>
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021typedef bool (*DNBShouldCancelCallback) (void *);
22
Greg Clayton3af9ea52010-11-18 05:57:03 +000023void DNBInitialize ();
24void DNBTerminate ();
25
Greg Clayton3c144382010-12-01 22:45:40 +000026nub_bool_t DNBSetArchitecture (const char *arch);
27
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028//----------------------------------------------------------------------
29// Process control
30//----------------------------------------------------------------------
Greg Clayton6779606a2011-01-22 23:43:18 +000031nub_process_t DNBProcessLaunch (const char *path,
32 char const *argv[],
33 const char *envp[],
34 const char *working_directory, // NULL => dont' change, non-NULL => set working directory for inferior to this
35 const char *stdin_path,
36 const char *stdout_path,
37 const char *stderr_path,
38 bool no_stdio,
39 nub_launch_flavor_t launch_flavor,
40 int disable_aslr,
41 char *err_str,
Greg Claytonf74cf862013-11-13 23:28:31 +000042 size_t err_len);
Greg Clayton6779606a2011-01-22 23:43:18 +000043
Greg Claytonf74cf862013-11-13 23:28:31 +000044nub_process_t DNBProcessAttach (nub_process_t pid, struct timespec *timeout, char *err_str, size_t err_len);
45nub_process_t DNBProcessAttachByName (const char *name, struct timespec *timeout, char *err_str, size_t err_len);
46nub_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 +000047// Resume a process with exact instructions on what to do with each thread:
48// - If no thread actions are supplied (actions is NULL or num_actions is zero),
49// then all threads are continued.
50// - If any thread actions are supplied, then each thread will do as it is told
51// by the action. A default actions for any threads that don't have an
52// explicit thread action can be made by making a thread action with a tid of
53// INVALID_NUB_THREAD. If there is no default action, those threads will
54// remain stopped.
Greg Claytonf74cf862013-11-13 23:28:31 +000055nub_bool_t DNBProcessResume (nub_process_t pid, const DNBThreadResumeAction *actions, size_t num_actions);
56nub_bool_t DNBProcessHalt (nub_process_t pid);
57nub_bool_t DNBProcessDetach (nub_process_t pid);
58nub_bool_t DNBProcessSignal (nub_process_t pid, int signal);
59nub_bool_t DNBProcessKill (nub_process_t pid);
60nub_size_t DNBProcessMemoryRead (nub_process_t pid, nub_addr_t addr, nub_size_t size, void *buf);
61nub_size_t DNBProcessMemoryWrite (nub_process_t pid, nub_addr_t addr, nub_size_t size, const void *buf);
62nub_addr_t DNBProcessMemoryAllocate (nub_process_t pid, nub_size_t size, uint32_t permissions);
63nub_bool_t DNBProcessMemoryDeallocate (nub_process_t pid, nub_addr_t addr);
64int DNBProcessMemoryRegionInfo (nub_process_t pid, nub_addr_t addr, DNBRegionInfo *region_info);
65std::string DNBProcessGetProfileData (nub_process_t pid, DNBProfileDataScanType scanType);
66nub_bool_t DNBProcessSetEnableAsyncProfiling (nub_process_t pid, nub_bool_t enable, uint64_t interval_usec, DNBProfileDataScanType scan_type);
Jason Molenda3dc85832011-11-09 08:03:56 +000067
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068//----------------------------------------------------------------------
69// Process status
70//----------------------------------------------------------------------
Greg Claytonf74cf862013-11-13 23:28:31 +000071nub_bool_t DNBProcessIsAlive (nub_process_t pid);
72nub_state_t DNBProcessGetState (nub_process_t pid);
73nub_bool_t DNBProcessGetExitStatus (nub_process_t pid, int *status);
74nub_bool_t DNBProcessSetExitStatus (nub_process_t pid, int status);
75nub_size_t DNBProcessGetNumThreads (nub_process_t pid);
76nub_thread_t DNBProcessGetCurrentThread (nub_process_t pid);
77nub_thread_t DNBProcessGetCurrentThreadMachPort (nub_process_t pid);
78nub_thread_t DNBProcessSetCurrentThread (nub_process_t pid, nub_thread_t tid);
79nub_thread_t DNBProcessGetThreadAtIndex (nub_process_t pid, nub_size_t thread_idx);
80nub_bool_t DNBProcessSyncThreadState (nub_process_t pid, nub_thread_t tid);
81nub_addr_t DNBProcessGetSharedLibraryInfoAddress (nub_process_t pid);
82nub_bool_t DNBProcessSharedLibrariesUpdated (nub_process_t pid);
83nub_size_t DNBProcessGetSharedLibraryInfo (nub_process_t pid, nub_bool_t only_changed, DNBExecutableImageInfo **image_infos);
84nub_bool_t DNBProcessSetNameToAddressCallback (nub_process_t pid, DNBCallbackNameToAddress callback, void *baton);
85nub_bool_t DNBProcessSetSharedLibraryInfoCallback (nub_process_t pid, DNBCallbackCopyExecutableImageInfos callback, void *baton);
86nub_addr_t DNBProcessLookupAddress (nub_process_t pid, const char *name, const char *shlib);
87nub_size_t DNBProcessGetAvailableSTDOUT (nub_process_t pid, char *buf, nub_size_t buf_size);
88nub_size_t DNBProcessGetAvailableSTDERR (nub_process_t pid, char *buf, nub_size_t buf_size);
89nub_size_t DNBProcessGetAvailableProfileData (nub_process_t pid, char *buf, nub_size_t buf_size);
90nub_size_t DNBProcessGetStopCount (nub_process_t pid);
91uint32_t DNBProcessGetCPUType (nub_process_t pid);
Jason Molenda3dc85832011-11-09 08:03:56 +000092
Chris Lattner30fdc8d2010-06-08 16:52:24 +000093//----------------------------------------------------------------------
94// Process executable and arguments
95//----------------------------------------------------------------------
Greg Claytonf74cf862013-11-13 23:28:31 +000096const char * DNBProcessGetExecutablePath (nub_process_t pid);
97const char * DNBProcessGetArgumentAtIndex (nub_process_t pid, nub_size_t idx);
98nub_size_t DNBProcessGetArgumentCount (nub_process_t pid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000099
100//----------------------------------------------------------------------
101// Process events
102//----------------------------------------------------------------------
Greg Claytonf74cf862013-11-13 23:28:31 +0000103nub_event_t DNBProcessWaitForEvents (nub_process_t pid, nub_event_t event_mask, bool wait_for_set, struct timespec* timeout);
104void DNBProcessResetEvents (nub_process_t pid, nub_event_t event_mask);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000105
106//----------------------------------------------------------------------
107// Thread functions
108//----------------------------------------------------------------------
Greg Claytonf74cf862013-11-13 23:28:31 +0000109const char * DNBThreadGetName (nub_process_t pid, nub_thread_t tid);
110nub_bool_t DNBThreadGetIdentifierInfo (nub_process_t pid, nub_thread_t tid, thread_identifier_info_data_t *ident_info);
111nub_state_t DNBThreadGetState (nub_process_t pid, nub_thread_t tid);
112nub_bool_t DNBThreadGetRegisterValueByID (nub_process_t pid, nub_thread_t tid, uint32_t set, uint32_t reg, DNBRegisterValue *value);
113nub_bool_t DNBThreadSetRegisterValueByID (nub_process_t pid, nub_thread_t tid, uint32_t set, uint32_t reg, const DNBRegisterValue *value);
114nub_size_t DNBThreadGetRegisterContext (nub_process_t pid, nub_thread_t tid, void *buf, size_t buf_len);
115nub_size_t DNBThreadSetRegisterContext (nub_process_t pid, nub_thread_t tid, const void *buf, size_t buf_len);
116uint32_t DNBThreadSaveRegisterState (nub_process_t pid, nub_thread_t tid);
117nub_bool_t DNBThreadRestoreRegisterState (nub_process_t pid, nub_thread_t tid, uint32_t save_id);
118nub_bool_t DNBThreadGetRegisterValueByName (nub_process_t pid, nub_thread_t tid, uint32_t set, const char *name, DNBRegisterValue *value);
119nub_bool_t DNBThreadGetStopReason (nub_process_t pid, nub_thread_t tid, DNBThreadStopInfo *stop_info);
120const char * DNBThreadGetInfo (nub_process_t pid, nub_thread_t tid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000121//----------------------------------------------------------------------
122// Breakpoint functions
123//----------------------------------------------------------------------
Greg Claytonf74cf862013-11-13 23:28:31 +0000124nub_bool_t DNBBreakpointSet (nub_process_t pid, nub_addr_t addr, nub_size_t size, nub_bool_t hardware);
125nub_bool_t DNBBreakpointClear (nub_process_t pid, nub_addr_t addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000126
127//----------------------------------------------------------------------
128// Watchpoint functions
129//----------------------------------------------------------------------
Greg Claytonf74cf862013-11-13 23:28:31 +0000130nub_bool_t DNBWatchpointSet (nub_process_t pid, nub_addr_t addr, nub_size_t size, uint32_t watch_flags, nub_bool_t hardware);
131nub_bool_t DNBWatchpointClear (nub_process_t pid, nub_addr_t addr);
132uint32_t DNBWatchpointGetNumSupportedHWP (nub_process_t pid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000133
134const DNBRegisterSetInfo *
Greg Claytonf74cf862013-11-13 23:28:31 +0000135 DNBGetRegisterSetInfo (nub_size_t *num_reg_sets);
136nub_bool_t DNBGetRegisterInfoByName (const char *reg_name, DNBRegisterInfo* info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000137
138//----------------------------------------------------------------------
139// Printf style formatting for printing values in the inferior memory
140// space and registers.
141//----------------------------------------------------------------------
Greg Claytonf74cf862013-11-13 23:28:31 +0000142nub_size_t DNBPrintf (nub_process_t pid, nub_thread_t tid, nub_addr_t addr, FILE *file, const char *format);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000143
144//----------------------------------------------------------------------
145// Other static nub information calls.
146//----------------------------------------------------------------------
Greg Claytonf74cf862013-11-13 23:28:31 +0000147const char * DNBStateAsString (nub_state_t state);
148nub_bool_t DNBResolveExecutablePath (const char *path, char *resolved_path, size_t resolved_path_size);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000149
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000150#endif