DNB.h revision a2f7423310044cf76d8d52aa9153b7fd8b226b49
1//===-- 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>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#define DNB_EXPORT __attribute__((visibility("default")))
25
26typedef bool (*DNBShouldCancelCallback) (void *);
27
28void            DNBInitialize ();
29void            DNBTerminate ();
30
31nub_bool_t      DNBSetArchitecture      (const char *arch);
32
33//----------------------------------------------------------------------
34// Process control
35//----------------------------------------------------------------------
36nub_process_t   DNBProcessLaunch        (const char *path,
37                                         char const *argv[],
38                                         const char *envp[],
39                                         const char *working_directory, // NULL => dont' change, non-NULL => set working directory for inferior to this
40                                         const char *stdin_path,
41                                         const char *stdout_path,
42                                         const char *stderr_path,
43                                         bool no_stdio,
44                                         nub_launch_flavor_t launch_flavor,
45                                         int disable_aslr,
46                                         char *err_str,
47                                         size_t err_len) DNB_EXPORT;
48
49nub_process_t   DNBProcessAttach        (nub_process_t pid, struct timespec *timeout, char *err_str, size_t err_len) DNB_EXPORT;
50nub_process_t   DNBProcessAttachByName  (const char *name, struct timespec *timeout, char *err_str, size_t err_len) DNB_EXPORT;
51nub_process_t   DNBProcessAttachWait    (const char *wait_name, nub_launch_flavor_t launch_flavor, struct timespec *timeout, useconds_t interval, char *err_str, size_t err_len, DNBShouldCancelCallback should_cancel = NULL, void *callback_data = NULL) DNB_EXPORT;
52// Resume a process with exact instructions on what to do with each thread:
53// - If no thread actions are supplied (actions is NULL or num_actions is zero),
54//   then all threads are continued.
55// - If any thread actions are supplied, then each thread will do as it is told
56//   by the action. A default actions for any threads that don't have an
57//   explicit thread action can be made by making a thread action with a tid of
58//   INVALID_NUB_THREAD. If there is no default action, those threads will
59//   remain stopped.
60nub_bool_t      DNBProcessResume        (nub_process_t pid, const DNBThreadResumeAction *actions, size_t num_actions) DNB_EXPORT;
61nub_bool_t      DNBProcessHalt          (nub_process_t pid) DNB_EXPORT;
62nub_bool_t      DNBProcessDetach        (nub_process_t pid) DNB_EXPORT;
63nub_bool_t      DNBProcessSignal        (nub_process_t pid, int signal) DNB_EXPORT;
64nub_bool_t      DNBProcessKill          (nub_process_t pid) DNB_EXPORT;
65nub_size_t      DNBProcessMemoryRead    (nub_process_t pid, nub_addr_t addr, nub_size_t size, void *buf) DNB_EXPORT;
66nub_size_t      DNBProcessMemoryWrite   (nub_process_t pid, nub_addr_t addr, nub_size_t size, const void *buf) DNB_EXPORT;
67nub_addr_t      DNBProcessMemoryAllocate (nub_process_t pid, nub_size_t size, uint32_t permissions) DNB_EXPORT;
68nub_bool_t      DNBProcessMemoryDeallocate (nub_process_t pid, nub_addr_t addr) DNB_EXPORT;
69//----------------------------------------------------------------------
70// Process status
71//----------------------------------------------------------------------
72nub_bool_t      DNBProcessIsAlive                       (nub_process_t pid) DNB_EXPORT;
73nub_state_t     DNBProcessGetState                      (nub_process_t pid) DNB_EXPORT;
74nub_bool_t      DNBProcessGetExitStatus                 (nub_process_t pid, int *status) DNB_EXPORT;
75nub_bool_t      DNBProcessSetExitStatus                 (nub_process_t pid, int status) DNB_EXPORT;
76nub_size_t      DNBProcessGetNumThreads                 (nub_process_t pid) DNB_EXPORT;
77nub_thread_t    DNBProcessGetCurrentThread              (nub_process_t pid) DNB_EXPORT;
78nub_thread_t    DNBProcessSetCurrentThread              (nub_process_t pid, nub_thread_t tid) DNB_EXPORT;
79nub_thread_t    DNBProcessGetThreadAtIndex              (nub_process_t pid, nub_size_t thread_idx) DNB_EXPORT;
80nub_addr_t      DNBProcessGetSharedLibraryInfoAddress   (nub_process_t pid) DNB_EXPORT;
81nub_bool_t      DNBProcessSharedLibrariesUpdated        (nub_process_t pid) DNB_EXPORT;
82nub_size_t      DNBProcessGetSharedLibraryInfo          (nub_process_t pid, nub_bool_t only_changed, DNBExecutableImageInfo **image_infos) DNB_EXPORT;
83nub_bool_t      DNBProcessSetNameToAddressCallback      (nub_process_t pid, DNBCallbackNameToAddress callback, void *baton) DNB_EXPORT;
84nub_bool_t      DNBProcessSetSharedLibraryInfoCallback  (nub_process_t pid, DNBCallbackCopyExecutableImageInfos callback, void *baton) DNB_EXPORT;
85nub_addr_t      DNBProcessLookupAddress                 (nub_process_t pid, const char *name, const char *shlib) DNB_EXPORT;
86nub_size_t      DNBProcessGetAvailableSTDOUT            (nub_process_t pid, char *buf, nub_size_t buf_size) DNB_EXPORT;
87nub_size_t      DNBProcessGetAvailableSTDERR            (nub_process_t pid, char *buf, nub_size_t buf_size) DNB_EXPORT;
88nub_size_t      DNBProcessGetStopCount                  (nub_process_t pid) DNB_EXPORT;
89uint32_t        DNBProcessGetCPUType                    (nub_process_t pid) DNB_EXPORT;
90//----------------------------------------------------------------------
91// Process executable and arguments
92//----------------------------------------------------------------------
93const char *    DNBProcessGetExecutablePath     (nub_process_t pid) DNB_EXPORT;
94const char *    DNBProcessGetArgumentAtIndex    (nub_process_t pid, nub_size_t idx) DNB_EXPORT;
95nub_size_t      DNBProcessGetArgumentCount      (nub_process_t pid) DNB_EXPORT;
96
97//----------------------------------------------------------------------
98// Process events
99//----------------------------------------------------------------------
100nub_event_t     DNBProcessWaitForEvents         (nub_process_t pid, nub_event_t event_mask, bool wait_for_set, struct timespec* timeout) DNB_EXPORT;
101void            DNBProcessResetEvents           (nub_process_t pid, nub_event_t event_mask) DNB_EXPORT;
102void            DNBProcessInterruptEvents       (nub_process_t pid) DNB_EXPORT;
103
104//----------------------------------------------------------------------
105// Thread functions
106//----------------------------------------------------------------------
107const char *    DNBThreadGetName                (nub_process_t pid, nub_thread_t tid) DNB_EXPORT;
108nub_bool_t      DNBThreadGetIdentifierInfo      (nub_process_t pid, nub_thread_t tid, thread_identifier_info_data_t *ident_info) DNB_EXPORT;
109nub_state_t     DNBThreadGetState               (nub_process_t pid, nub_thread_t tid) DNB_EXPORT;
110nub_bool_t      DNBThreadGetRegisterValueByID   (nub_process_t pid, nub_thread_t tid, uint32_t set, uint32_t reg, DNBRegisterValue *value) DNB_EXPORT;
111nub_bool_t      DNBThreadSetRegisterValueByID   (nub_process_t pid, nub_thread_t tid, uint32_t set, uint32_t reg, const DNBRegisterValue *value) DNB_EXPORT;
112nub_size_t      DNBThreadGetRegisterContext     (nub_process_t pid, nub_thread_t tid, void *buf, size_t buf_len) DNB_EXPORT;
113nub_size_t      DNBThreadSetRegisterContext     (nub_process_t pid, nub_thread_t tid, const void *buf, size_t buf_len) DNB_EXPORT;
114nub_bool_t      DNBThreadGetRegisterValueByName (nub_process_t pid, nub_thread_t tid, uint32_t set, const char *name, DNBRegisterValue *value) DNB_EXPORT;
115nub_bool_t      DNBThreadGetStopReason          (nub_process_t pid, nub_thread_t tid, DNBThreadStopInfo *stop_info) DNB_EXPORT;
116const char *    DNBThreadGetInfo                (nub_process_t pid, nub_thread_t tid) DNB_EXPORT;
117//----------------------------------------------------------------------
118// Breakpoint functions
119//----------------------------------------------------------------------
120nub_break_t     DNBBreakpointSet                (nub_process_t pid, nub_addr_t addr, nub_size_t size, nub_bool_t hardware) DNB_EXPORT;
121nub_bool_t      DNBBreakpointClear              (nub_process_t pid, nub_break_t breakID) DNB_EXPORT;
122nub_ssize_t     DNBBreakpointGetHitCount        (nub_process_t pid, nub_break_t breakID) DNB_EXPORT;
123nub_ssize_t     DNBBreakpointGetIgnoreCount     (nub_process_t pid, nub_break_t breakID) DNB_EXPORT;
124nub_bool_t      DNBBreakpointSetIgnoreCount     (nub_process_t pid, nub_break_t breakID, nub_size_t ignore_count) DNB_EXPORT;
125nub_bool_t      DNBBreakpointSetCallback        (nub_process_t pid, nub_break_t breakID, DNBCallbackBreakpointHit callback, void *baton) DNB_EXPORT;
126void            DNBBreakpointPrint              (nub_process_t pid, nub_break_t breakID) DNB_EXPORT;
127
128//----------------------------------------------------------------------
129// Watchpoint functions
130//----------------------------------------------------------------------
131nub_watch_t     DNBWatchpointSet                (nub_process_t pid, nub_addr_t addr, nub_size_t size, uint32_t watch_flags, nub_bool_t hardware) DNB_EXPORT;
132nub_bool_t      DNBWatchpointClear              (nub_process_t pid, nub_watch_t watchID) DNB_EXPORT;
133nub_ssize_t     DNBWatchpointGetHitCount        (nub_process_t pid, nub_watch_t watchID) DNB_EXPORT;
134nub_ssize_t     DNBWatchpointGetIgnoreCount     (nub_process_t pid, nub_watch_t watchID) DNB_EXPORT;
135nub_bool_t      DNBWatchpointSetIgnoreCount     (nub_process_t pid, nub_watch_t watchID, nub_size_t ignore_count) DNB_EXPORT;
136nub_bool_t      DNBWatchpointSetCallback        (nub_process_t pid, nub_watch_t watchID, DNBCallbackBreakpointHit callback, void *baton) DNB_EXPORT;
137void            DNBWatchpointPrint              (nub_process_t pid, nub_watch_t watchID) DNB_EXPORT;
138
139const DNBRegisterSetInfo *
140                DNBGetRegisterSetInfo           (nub_size_t *num_reg_sets) DNB_EXPORT;
141nub_bool_t      DNBGetRegisterInfoByName        (const char *reg_name, DNBRegisterInfo* info) DNB_EXPORT;
142
143//----------------------------------------------------------------------
144// Printf style formatting for printing values in the inferior memory
145// space and registers.
146//----------------------------------------------------------------------
147nub_size_t      DNBPrintf (nub_process_t pid, nub_thread_t tid, nub_addr_t addr, FILE *file, const char *format) DNB_EXPORT;
148
149//----------------------------------------------------------------------
150// Other static nub information calls.
151//----------------------------------------------------------------------
152const char *    DNBStateAsString (nub_state_t state) DNB_EXPORT;
153nub_bool_t      DNBResolveExecutablePath (const char *path, char *resolved_path, size_t resolved_path_size) DNB_EXPORT;
154
155#ifdef __cplusplus
156}
157#endif
158
159#endif
160