GDBserver
Macros | Typedefs | Functions | Variables
win32-low.c File Reference
#include "server.h"
#include "regcache.h"
#include "gdb/fileio.h"
#include "mem-break.h"
#include "win32-low.h"
#include "gdbthread.h"
#include "dll.h"
#include "hostio.h"
#include <windows.h>
#include <winnt.h>
#include <imagehlp.h>
#include <tlhelp32.h>
#include <psapi.h>
#include <process.h>
#include <sys/cygwin.h>

Go to the source code of this file.

Macros

#define OUTMSG(X)   do { printf X; fflush (stderr); } while (0)
 
#define OUTMSG2(X)
 
#define _T(x)   TEXT (x)
 
#define COUNTOF(STR)   (sizeof (STR) / sizeof ((STR)[0]))
 
#define GETPROCADDRESS(DLL, PROC)   ((winapi_ ## PROC) GetProcAddress (DLL, #PROC))
 
#define NUM_REGS   (the_low_target.num_regs)
 
#define READ_BUFFER_LEN   1024
 

Typedefs

typedef HMODULE DWORD
 
typedef HMODULE LPDWORD
 

Functions

typedef BOOL (WINAPI *winapi_DebugActiveProcessStop)(DWORD dwProcessId)
 
static ptid_t win32_wait (ptid_t ptid, struct target_waitstatus *ourstatus, int options)
 
static void win32_resume (struct thread_resume *resume_info, size_t n)
 
static void win32_add_all_dlls (void)
 
static ptid_t current_thread_ptid (void)
 
static ptid_t debug_event_ptid (DEBUG_EVENT *event)
 
static void win32_get_thread_context (win32_thread_info *th)
 
static void win32_set_thread_context (win32_thread_info *th)
 
static void win32_prepare_to_resume (win32_thread_info *th)
 
void win32_require_context (win32_thread_info *th)
 
static win32_thread_infothread_rec (ptid_t ptid, int get_context)
 
static win32_thread_infochild_add_thread (DWORD pid, DWORD tid, HANDLE h, void *tlb)
 
static void delete_thread_info (struct inferior_list_entry *thread)
 
static void child_delete_thread (DWORD pid, DWORD tid)
 
static int win32_supports_z_point_type (char z_type)
 
static int win32_insert_point (enum raw_bkpt_type type, CORE_ADDR addr, int size, struct raw_breakpoint *bp)
 
static int win32_remove_point (enum raw_bkpt_type type, CORE_ADDR addr, int size, struct raw_breakpoint *bp)
 
static int win32_stopped_by_watchpoint (void)
 
static CORE_ADDR win32_stopped_data_address (void)
 
static int child_xfer_memory (CORE_ADDR memaddr, char *our, int len, int write, struct target_ops *target)
 
static void child_init_thread_list (void)
 
static void do_initial_child_stuff (HANDLE proch, DWORD pid, int attached)
 
static int continue_one_thread (struct inferior_list_entry *this_thread, void *id_ptr)
 
static BOOL child_continue (DWORD continue_status, int thread_id)
 
static void child_fetch_inferior_registers (struct regcache *regcache, int r)
 
static void child_store_inferior_registers (struct regcache *regcache, int r)
 
char * strwinerror (DWORD error)
 
static BOOL create_process (const char *program, char *args, DWORD flags, PROCESS_INFORMATION *pi)
 
static int win32_create_inferior (char *program, char **program_args)
 
static int win32_attach (unsigned long pid)
 
static void handle_output_debug_string (struct target_waitstatus *ourstatus)
 
static void win32_clear_inferiors (void)
 
static int win32_kill (int pid)
 
static int win32_detach (int pid)
 
static void win32_mourn (struct process_info *process)
 
static void win32_join (int pid)
 
static int win32_thread_alive (ptid_t ptid)
 
static void win32_add_one_solib (const char *name, CORE_ADDR load_addr)
 
static char * get_image_name (HANDLE h, void *address, int unicode)
 
typedef DWORD (WINAPI *winapi_GetModuleFileNameExA)(HANDLE
 
static BOOL load_psapi (void)
 
typedef HANDLE (WINAPI *winapi_CreateToolhelp32Snapshot)(DWORD
 
static void handle_load_dll (void)
 
static void handle_unload_dll (void)
 
static void handle_exception (struct target_waitstatus *ourstatus)
 
static void suspend_one_thread (struct inferior_list_entry *entry)
 
static void fake_breakpoint_event (void)
 
static int get_child_debug_event (struct target_waitstatus *ourstatus)
 
static void win32_fetch_inferior_registers (struct regcache *regcache, int regno)
 
static void win32_store_inferior_registers (struct regcache *regcache, int regno)
 
static int win32_read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
 
static int win32_write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
 
static void win32_request_interrupt (void)
 
static int win32_get_tib_address (ptid_t ptid, CORE_ADDR *addr)
 
void initialize_low (void)
 

Variables

int using_threads = 1
 
static int attaching = 0
 
static HANDLE current_process_handle = NULL
 
static DWORD current_process_id = 0
 
static DWORD main_thread_id = 0
 
static enum gdb_signal last_sig = GDB_SIGNAL_0
 
static DEBUG_EVENT current_event
 
static struct target_waitstatus cached_status
 
static int soft_interrupt_requested = 0
 
static int faked_breakpoint = 0
 
const struct target_descwin32_tdesc
 
static int child_initialization_done = 0
 
typedef HMODULE
 
typedef LPMODULEINFO
 
typedef LPSTR
 
static winapi_EnumProcessModules win32_EnumProcessModules
 
static winapi_GetModuleInformation win32_GetModuleInformation
 
static winapi_GetModuleFileNameExA win32_GetModuleFileNameExA
 
typedef LPMODULEENTRY32
 
static struct target_ops win32_target_ops
 

Macro Definition Documentation

#define _T (   x)    TEXT (x)

Definition at line 53 of file win32-low.c.

Referenced by win32_attach(), win32_detach(), and win32_request_interrupt().

#define COUNTOF (   STR)    (sizeof (STR) / sizeof ((STR)[0]))

Definition at line 57 of file win32-low.c.

Referenced by strwinerror().

#define GETPROCADDRESS (   DLL,
  PROC 
)    ((winapi_ ## PROC) GetProcAddress (DLL, #PROC))

Definition at line 64 of file win32-low.c.

Referenced by load_psapi(), win32_attach(), win32_detach(), and win32_request_interrupt().

#define NUM_REGS   (the_low_target.num_regs)

Definition at line 95 of file win32-low.c.

Referenced by child_fetch_inferior_registers(), and child_store_inferior_registers().

#define OUTMSG (   X)    do { printf X; fflush (stderr); } while (0)
#define OUTMSG2 (   X)
Value:
do \
{ \
{ \
printf X; \
fflush (stderr); \
} \
} while (0)
int debug_threads
Definition: debug.c:24

Definition at line 42 of file win32-low.c.

Referenced by fake_breakpoint_event(), get_child_debug_event(), handle_exception(), handle_output_debug_string(), win32_create_inferior(), and win32_wait().

#define READ_BUFFER_LEN   1024

Typedef Documentation

typedef DWORD

Definition at line 1097 of file win32-low.c.

typedef HMODULE LPDWORD

Definition at line 1097 of file win32-low.c.

Function Documentation

typedef BOOL ( WINAPI *  winapi_DebugActiveProcessStop)
static win32_thread_info* child_add_thread ( DWORD  pid,
DWORD  tid,
HANDLE  h,
void *  tlb 
)
static
static BOOL child_continue ( DWORD  continue_status,
int  thread_id 
)
static
static void child_delete_thread ( DWORD  pid,
DWORD  tid 
)
static
static void child_fetch_inferior_registers ( struct regcache regcache,
int  r 
)
static

Definition at line 480 of file win32-low.c.

References current_thread_ptid(), NUM_REGS, the_low_target, and thread_rec().

Referenced by win32_fetch_inferior_registers(), and win32_wait().

static void child_init_thread_list ( void  )
static

Definition at line 345 of file win32-low.c.

References all_threads, delete_thread_info(), and for_each_inferior().

Referenced by do_initial_child_stuff().

static void child_store_inferior_registers ( struct regcache regcache,
int  r 
)
static

Definition at line 494 of file win32-low.c.

References current_thread_ptid(), NUM_REGS, the_low_target, and thread_rec().

Referenced by win32_store_inferior_registers().

static int child_xfer_memory ( CORE_ADDR  memaddr,
char *  our,
int  len,
int  write,
struct target_ops target 
)
static

Definition at line 313 of file win32-low.c.

References BOOL(), and current_process_handle.

Referenced by win32_read_inferior_memory(), and win32_write_inferior_memory().

static int continue_one_thread ( struct inferior_list_entry this_thread,
void *  id_ptr 
)
static
static BOOL create_process ( const char *  program,
char *  args,
DWORD  flags,
PROCESS_INFORMATION *  pi 
)
static

Definition at line 561 of file win32-low.c.

References alloca(), and BOOL().

Referenced by win32_create_inferior().

static ptid_t current_thread_ptid ( void  )
static

Definition at line 112 of file win32-low.c.

References current_ptid.

Referenced by child_fetch_inferior_registers(), and child_store_inferior_registers().

static ptid_t debug_event_ptid ( DEBUG_EVENT *  event)
static

Definition at line 119 of file win32-low.c.

References ptid_build().

Referenced by get_child_debug_event(), win32_resume(), and win32_wait().

static void delete_thread_info ( struct inferior_list_entry thread)
static
static void do_initial_child_stuff ( HANDLE  proch,
DWORD  pid,
int  attached 
)
static
typedef DWORD ( WINAPI *  winapi_GetModuleFileNameExA)
static void fake_breakpoint_event ( void  )
static
static int get_child_debug_event ( struct target_waitstatus *  ourstatus)
static
static char* get_image_name ( HANDLE  h,
void *  address,
int  unicode 
)
static

Definition at line 1049 of file win32-low.c.

References alloca().

Referenced by handle_load_dll().

typedef HANDLE ( WINAPI *  winapi_CreateToolhelp32Snapshot)
static void handle_exception ( struct target_waitstatus *  ourstatus)
static

Definition at line 1236 of file win32-low.c.

References check_breakpoints(), current_event, last_sig, OUTMSG2, and phex_nz().

Referenced by get_child_debug_event().

static void handle_load_dll ( void  )
static
static void handle_output_debug_string ( struct target_waitstatus *  ourstatus)
static
static void handle_unload_dll ( void  )
static

Definition at line 1223 of file win32-low.c.

References current_event, and unloaded_dll().

Referenced by get_child_debug_event().

void initialize_low ( void  )
static BOOL load_psapi ( void  )
static

Definition at line 1109 of file win32-low.c.

References GETPROCADDRESS.

Referenced by win32_add_all_dlls().

char* strwinerror ( DWORD  error)
static void suspend_one_thread ( struct inferior_list_entry entry)
static
static win32_thread_info* thread_rec ( ptid_t  ptid,
int  get_context 
)
static
static void win32_add_all_dlls ( void  )
static
static void win32_add_one_solib ( const char *  name,
CORE_ADDR  load_addr 
)
static

Definition at line 988 of file win32-low.c.

References HANDLE(), and loaded_dll().

Referenced by handle_load_dll(), and win32_add_all_dlls().

static int win32_attach ( unsigned long  pid)
static
static void win32_clear_inferiors ( void  )
static
static int win32_create_inferior ( char *  program,
char **  program_args 
)
static
static int win32_detach ( int  pid)
static
static void win32_fetch_inferior_registers ( struct regcache regcache,
int  regno 
)
static

Definition at line 1646 of file win32-low.c.

References child_fetch_inferior_registers().

static void win32_get_thread_context ( win32_thread_info th)
static

Definition at line 127 of file win32-low.c.

References win32_thread_info::context, and the_low_target.

Referenced by win32_require_context().

static int win32_get_tib_address ( ptid_t  ptid,
CORE_ADDR addr 
)
static

Definition at line 1775 of file win32-low.c.

References win32_thread_info::thread_local_base, and thread_rec().

static int win32_insert_point ( enum raw_bkpt_type  type,
CORE_ADDR  addr,
int  size,
struct raw_breakpoint bp 
)
static

Definition at line 271 of file win32-low.c.

References linux_target_ops::insert_point, and the_low_target.

static void win32_join ( int  pid)
static

Definition at line 880 of file win32-low.c.

References HANDLE().

static int win32_kill ( int  pid)
static
static void win32_mourn ( struct process_info process)
static

Definition at line 873 of file win32-low.c.

References remove_process().

static void win32_prepare_to_resume ( win32_thread_info th)
static

Definition at line 160 of file win32-low.c.

References linux_target_ops::prepare_to_resume, and the_low_target.

Referenced by continue_one_thread(), and win32_resume().

static int win32_read_inferior_memory ( CORE_ADDR  memaddr,
unsigned char *  myaddr,
int  len 
)
static

Definition at line 1663 of file win32-low.c.

References child_xfer_memory().

static int win32_remove_point ( enum raw_bkpt_type  type,
CORE_ADDR  addr,
int  size,
struct raw_breakpoint bp 
)
static

Definition at line 282 of file win32-low.c.

References linux_target_ops::remove_point, and the_low_target.

static void win32_request_interrupt ( void  )
static
void win32_require_context ( win32_thread_info th)
static void win32_resume ( struct thread_resume resume_info,
size_t  n 
)
static
static void win32_set_thread_context ( win32_thread_info th)
static

Definition at line 139 of file win32-low.c.

References win32_thread_info::context, and win32_thread_info::h.

Referenced by continue_one_thread(), and win32_resume().

static int win32_stopped_by_watchpoint ( void  )
static

Definition at line 293 of file win32-low.c.

References linux_target_ops::stopped_by_watchpoint, and the_low_target.

static CORE_ADDR win32_stopped_data_address ( void  )
static

Definition at line 302 of file win32-low.c.

References linux_target_ops::stopped_data_address, and the_low_target.

static void win32_store_inferior_registers ( struct regcache regcache,
int  regno 
)
static

Definition at line 1654 of file win32-low.c.

References child_store_inferior_registers().

static int win32_supports_z_point_type ( char  z_type)
static

Definition at line 264 of file win32-low.c.

References linux_target_ops::supports_z_point_type, and the_low_target.

static int win32_thread_alive ( ptid_t  ptid)
static

Definition at line 892 of file win32-low.c.

References all_threads, and find_inferior_id().

static ptid_t win32_wait ( ptid_t  ptid,
struct target_waitstatus *  ourstatus,
int  options 
)
static
static int win32_write_inferior_memory ( CORE_ADDR  memaddr,
const unsigned char *  myaddr,
int  len 
)
static

Definition at line 1673 of file win32-low.c.

References child_xfer_memory().

Variable Documentation

int attaching = 0
static

Definition at line 71 of file win32-low.c.

Referenced by get_child_debug_event(), win32_attach(), and win32_create_inferior().

struct target_waitstatus cached_status
static

Definition at line 83 of file win32-low.c.

Referenced by do_initial_child_stuff(), and win32_wait().

int child_initialization_done = 0
static

Definition at line 352 of file win32-low.c.

Referenced by do_initial_child_stuff(), and get_child_debug_event().

DEBUG_EVENT current_event
static
HANDLE current_process_handle = NULL
static
DWORD current_process_id = 0
static
int faked_breakpoint = 0
static

Definition at line 91 of file win32-low.c.

Referenced by child_continue(), do_initial_child_stuff(), and fake_breakpoint_event().

typedef HMODULE

Definition at line 1099 of file win32-low.c.

Referenced by win32_add_all_dlls(), win32_attach(), and win32_detach().

enum gdb_signal last_sig = GDB_SIGNAL_0
static
typedef LPMODULEENTRY32

Definition at line 1191 of file win32-low.c.

typedef LPMODULEINFO

Definition at line 1099 of file win32-low.c.

typedef LPSTR

Definition at line 1101 of file win32-low.c.

DWORD main_thread_id = 0
static
int soft_interrupt_requested = 0
static
int using_threads = 1

Definition at line 68 of file win32-low.c.

Referenced by prepare_resume_reply().

winapi_EnumProcessModules win32_EnumProcessModules
static

Definition at line 1104 of file win32-low.c.

winapi_GetModuleFileNameExA win32_GetModuleFileNameExA
static

Definition at line 1106 of file win32-low.c.

winapi_GetModuleInformation win32_GetModuleInformation
static

Definition at line 1105 of file win32-low.c.

Definition at line 1786 of file win32-low.c.

const struct target_desc* win32_tdesc

Definition at line 93 of file win32-low.c.

Referenced by arm_arch_setup(), do_initial_child_stuff(), and i386_arch_setup().