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 "gdb_tilde_expand.h"
#include "common-inferior.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 BOOL(WINAPI * winapi_DebugActiveProcessStop) (DWORD dwProcessId)
 
typedef BOOL(WINAPI * winapi_DebugSetProcessKillOnExit) (BOOL KillOnExit)
 
typedef BOOL(WINAPI * winapi_DebugBreakProcess) (HANDLE)
 
typedef BOOL(WINAPI * winapi_GenerateConsoleCtrlEvent) (DWORD, DWORD)
 
typedef BOOL(WINAPI * winapi_EnumProcessModules) (HANDLE, HMODULE *, DWORD, LPDWORD)
 
typedef BOOL(WINAPI * winapi_GetModuleInformation) (HANDLE, HMODULE, LPMODULEINFO, DWORD)
 
typedef DWORD(WINAPI * winapi_GetModuleFileNameExA) (HANDLE, HMODULE, LPSTR, DWORD)
 
typedef HANDLE(WINAPI * winapi_CreateToolhelp32Snapshot) (DWORD, DWORD)
 
typedef BOOL(WINAPI * winapi_Module32First) (HANDLE, LPMODULEENTRY32)
 
typedef BOOL(WINAPI * winapi_Module32Next) (HANDLE, LPMODULEENTRY32)
 

Functions

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 (thread_info *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 void continue_one_thread (thread_info *thread, int thread_id)
 
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 (const char *program, const std::vector< char *> &program_args)
 
static int win32_attach (unsigned long pid)
 
static void handle_output_debug_string (void)
 
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)
 
static BOOL load_psapi (void)
 
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 (thread_info *thread)
 
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)
 
static const gdb_bytewin32_sw_breakpoint_from_kind (int kind, int *size)
 
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
 
static winapi_EnumProcessModules win32_EnumProcessModules
 
static winapi_GetModuleInformation win32_GetModuleInformation
 
static winapi_GetModuleFileNameExA win32_GetModuleFileNameExA
 
static struct target_ops win32_target_ops
 

Macro Definition Documentation

◆ _T

#define _T (   x)    TEXT (x)

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

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

◆ COUNTOF

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

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

Referenced by strwinerror().

◆ GETPROCADDRESS

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

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

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

◆ NUM_REGS

#define NUM_REGS   (the_low_target.num_regs)

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

Referenced by child_fetch_inferior_registers(), and child_store_inferior_registers().

◆ OUTMSG

#define OUTMSG (   X)    do { printf X; fflush (stderr); } while (0)

◆ OUTMSG2

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

Definition at line 44 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().

◆ READ_BUFFER_LEN

#define READ_BUFFER_LEN   1024

Typedef Documentation

◆ winapi_CreateToolhelp32Snapshot

typedef HANDLE(WINAPI * winapi_CreateToolhelp32Snapshot) (DWORD, DWORD)

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

◆ winapi_DebugActiveProcessStop

typedef BOOL(WINAPI * winapi_DebugActiveProcessStop) (DWORD dwProcessId)

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

◆ winapi_DebugBreakProcess

typedef BOOL(WINAPI * winapi_DebugBreakProcess) (HANDLE)

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

◆ winapi_DebugSetProcessKillOnExit

typedef BOOL(WINAPI * winapi_DebugSetProcessKillOnExit) (BOOL KillOnExit)

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

◆ winapi_EnumProcessModules

typedef BOOL(WINAPI * winapi_EnumProcessModules) (HANDLE, HMODULE *, DWORD, LPDWORD)

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

◆ winapi_GenerateConsoleCtrlEvent

typedef BOOL(WINAPI * winapi_GenerateConsoleCtrlEvent) (DWORD, DWORD)

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

◆ winapi_GetModuleFileNameExA

typedef DWORD(WINAPI * winapi_GetModuleFileNameExA) (HANDLE, HMODULE, LPSTR, DWORD)

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

◆ winapi_GetModuleInformation

typedef BOOL(WINAPI * winapi_GetModuleInformation) (HANDLE, HMODULE, LPMODULEINFO, DWORD)

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

◆ winapi_Module32First

typedef BOOL(WINAPI * winapi_Module32First) (HANDLE, LPMODULEENTRY32)

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

◆ winapi_Module32Next

typedef BOOL(WINAPI * winapi_Module32Next) (HANDLE, LPMODULEENTRY32)

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

Function Documentation

◆ child_add_thread()

static win32_thread_info* child_add_thread ( DWORD  pid,
DWORD  tid,
HANDLE  h,
void *  tlb 
)
static

◆ child_continue()

static BOOL child_continue ( DWORD  continue_status,
int  thread_id 
)
static

◆ child_delete_thread()

static void child_delete_thread ( DWORD  pid,
DWORD  tid 
)
static

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

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

Referenced by get_child_debug_event().

◆ child_fetch_inferior_registers()

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

Definition at line 474 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().

◆ child_init_thread_list()

static void child_init_thread_list ( void  )
static

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

References delete_thread_info(), and for_each_thread().

Referenced by do_initial_child_stuff().

◆ child_store_inferior_registers()

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

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

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

Referenced by win32_store_inferior_registers().

◆ child_xfer_memory()

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

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

References current_process_handle.

Referenced by win32_read_inferior_memory(), and win32_write_inferior_memory().

◆ continue_one_thread()

static void continue_one_thread ( thread_info thread,
int  thread_id 
)
static

◆ create_process()

static BOOL create_process ( const char *  program,
char *  args,
DWORD  flags,
PROCESS_INFORMATION *  pi 
)
static

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

References _, alloca(), error(), gdb_tilde_expand(), get_inferior_cwd(), and string.

Referenced by win32_create_inferior().

◆ current_thread_ptid()

static ptid_t current_thread_ptid ( void  )
static

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

References current_ptid.

Referenced by child_fetch_inferior_registers(), and child_store_inferior_registers().

◆ debug_event_ptid()

static ptid_t debug_event_ptid ( DEBUG_EVENT *  event)
static

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

References ptid_build().

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

◆ delete_thread_info()

static void delete_thread_info ( thread_info thread)
static

◆ do_initial_child_stuff()

static void do_initial_child_stuff ( HANDLE  proch,
DWORD  pid,
int  attached 
)
static

◆ fake_breakpoint_event()

static void fake_breakpoint_event ( void  )
static

◆ get_child_debug_event()

static int get_child_debug_event ( struct target_waitstatus *  ourstatus)
static

◆ get_image_name()

static char* get_image_name ( HANDLE  h,
void *  address,
int  unicode 
)
static

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

Referenced by handle_load_dll().

◆ handle_exception()

static void handle_exception ( struct target_waitstatus *  ourstatus)
static

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

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

Referenced by get_child_debug_event().

◆ handle_load_dll()

static void handle_load_dll ( void  )
static

◆ handle_output_debug_string()

static void handle_output_debug_string ( void  )
static

◆ handle_unload_dll()

static void handle_unload_dll ( void  )
static

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

References current_event, and unloaded_dll().

Referenced by get_child_debug_event().

◆ initialize_low()

void initialize_low ( void  )

◆ load_psapi()

static BOOL load_psapi ( void  )
static

◆ strwinerror()

char* strwinerror ( DWORD  error)

◆ suspend_one_thread()

static void suspend_one_thread ( thread_info thread)
static

◆ thread_rec()

static win32_thread_info* thread_rec ( ptid_t  ptid,
int  get_context 
)
static

◆ win32_add_all_dlls()

static void win32_add_all_dlls ( void  )
static

◆ win32_add_one_solib()

static void win32_add_one_solib ( const char *  name,
CORE_ADDR  load_addr 
)
static

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

References loaded_dll(), and name.

Referenced by handle_load_dll(), and win32_add_all_dlls().

◆ win32_attach()

static int win32_attach ( unsigned long  pid)
static

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

References _T, attaching, do_initial_child_stuff(), error(), GETPROCADDRESS, and strwinerror().

◆ win32_clear_inferiors()

static void win32_clear_inferiors ( void  )
static

◆ win32_create_inferior()

static int win32_create_inferior ( const char *  program,
const std::vector< char *> &  program_args 
)
static

◆ win32_detach()

static int win32_detach ( int  pid)
static

◆ win32_fetch_inferior_registers()

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

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

References child_fetch_inferior_registers().

◆ win32_get_thread_context()

static void win32_get_thread_context ( win32_thread_info th)
static

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

References win32_thread_info::context, memset(), and the_low_target.

Referenced by win32_require_context().

◆ win32_get_tib_address()

static int win32_get_tib_address ( ptid_t  ptid,
CORE_ADDR addr 
)
static

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

References win32_thread_info::thread_local_base, and thread_rec().

◆ win32_insert_point()

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

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

References linux_target_ops::insert_point, and the_low_target.

◆ win32_join()

static void win32_join ( int  pid)
static

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

◆ win32_kill()

static int win32_kill ( int  pid)
static

◆ win32_mourn()

static void win32_mourn ( struct process_info process)
static

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

References remove_process().

◆ win32_prepare_to_resume()

static void win32_prepare_to_resume ( win32_thread_info th)
static

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

References linux_target_ops::prepare_to_resume, and the_low_target.

Referenced by continue_one_thread(), and win32_resume().

◆ win32_read_inferior_memory()

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

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

References child_xfer_memory().

◆ win32_remove_point()

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

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

References linux_target_ops::remove_point, and the_low_target.

◆ win32_request_interrupt()

static void win32_request_interrupt ( void  )
static

◆ win32_require_context()

void win32_require_context ( win32_thread_info th)

◆ win32_resume()

static void win32_resume ( struct thread_resume resume_info,
size_t  n 
)
static

◆ win32_set_thread_context()

static void win32_set_thread_context ( win32_thread_info th)
static

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

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

Referenced by continue_one_thread(), and win32_resume().

◆ win32_stopped_by_watchpoint()

static int win32_stopped_by_watchpoint ( void  )
static

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

References linux_target_ops::stopped_by_watchpoint, and the_low_target.

◆ win32_stopped_data_address()

static CORE_ADDR win32_stopped_data_address ( void  )
static

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

References linux_target_ops::stopped_data_address, and the_low_target.

◆ win32_store_inferior_registers()

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

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

References child_store_inferior_registers().

◆ win32_supports_z_point_type()

static int win32_supports_z_point_type ( char  z_type)
static

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

References linux_target_ops::supports_z_point_type, and the_low_target.

◆ win32_sw_breakpoint_from_kind()

static const gdb_byte* win32_sw_breakpoint_from_kind ( int  kind,
int *  size 
)
static

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

References the_low_target.

◆ win32_thread_alive()

static int win32_thread_alive ( ptid_t  ptid)
static

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

References find_thread_ptid().

◆ win32_wait()

static ptid_t win32_wait ( ptid_t  ptid,
struct target_waitstatus *  ourstatus,
int  options 
)
static

◆ win32_write_inferior_memory()

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

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

References child_xfer_memory().

Variable Documentation

◆ attaching

int attaching = 0
static

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

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

◆ cached_status

struct target_waitstatus cached_status
static

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

Referenced by do_initial_child_stuff(), and win32_wait().

◆ child_initialization_done

int child_initialization_done = 0
static

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

Referenced by do_initial_child_stuff(), and get_child_debug_event().

◆ current_event

DEBUG_EVENT current_event
static

◆ current_process_handle

HANDLE current_process_handle = NULL
static

◆ current_process_id

DWORD current_process_id = 0
static

◆ faked_breakpoint

int faked_breakpoint = 0
static

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

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

◆ last_sig

enum gdb_signal last_sig = GDB_SIGNAL_0
static

◆ main_thread_id

DWORD main_thread_id = 0
static

◆ soft_interrupt_requested

int soft_interrupt_requested = 0
static

◆ using_threads

int using_threads = 1

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

Referenced by prepare_resume_reply().

◆ win32_EnumProcessModules

winapi_EnumProcessModules win32_EnumProcessModules
static

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

Referenced by load_psapi().

◆ win32_GetModuleFileNameExA

winapi_GetModuleFileNameExA win32_GetModuleFileNameExA
static

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

Referenced by load_psapi(), and win32_add_all_dlls().

◆ win32_GetModuleInformation

winapi_GetModuleInformation win32_GetModuleInformation
static

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

Referenced by load_psapi(), and win32_add_all_dlls().

◆ win32_target_ops

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

◆ win32_tdesc

const struct target_desc* win32_tdesc

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

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