Stackdb
Stackdb is a stackable, multi-target and -level source debugger and memory forensics library.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
target_gdb.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 The University of Utah
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef __TARGET_GDB_H__
20 #define __TARGET_GDB_H__
21 
22 #include "config.h"
23 
24 #include "common.h"
25 #include "target.h"
26 #include "target_arch_x86.h"
27 #include "evloop.h"
28 
29 #include "target_gdb_rsp.h"
30 
31 #include <argp.h>
32 #include <glib.h>
33 
34 extern struct target_ops gdb_ops;
35 extern struct argp gdb_argp;
36 extern char *gdb_argp_header;
37 
38 struct gdb_spec {
39  unsigned int do_stdio:1,
40  do_udp:1,
41  do_unix:1,
43  is_qemu:1,
44  is_kvm:1;
45 
46  /* Max memcache limit, in bytes. Backends must honor this! */
47  unsigned long int memcache_mmap_size;
48 
49  char *devfile;
50  char *sockfile;
51  char *hostname;
52  int port;
53 
56  /*
57  * NB: might have to extend this if we have VMs with > 4GB RAM; QEMU
58  * splits the allocation into below 4GB and above 4GB; don't know if
59  * they get mmap'd to the same file with the mem-path option.
60  */
62 
64 
66 };
67 
69  //vcpu_guest_context_t context;
70 
71  //vcpu_guest_context_t alt_context;
72 
73  /* XXX: can we debug a 32-bit target on a 64-bit host? If yes, how
74  * we use this might have to change.
75  */
76  unsigned long dr[8];
77 };
78 
79 struct gdb_state {
80  int fd;
81  int wfd;
82  char *sockfile;
83 
84  unsigned int need_interrupt:1,
85  writing:1,
86  need_ack:1,
88  vcont:1,
89  vcont_c:1,
90  vcont_C:1,
91  vcont_s:1,
92  vcont_S:1,
93  vcont_t:1,
94  vcont_r:1,
95  machine_valid:1,
96  stepping:1;
97 
98  unsigned int max_stub_packet_size;
99 
100  GHashTable *stubfeatures;
101 
102  char *ibuf;
103  unsigned int ibuf_alen;
104  unsigned int ibuf_len;
105 
106  char *obuf;
107  unsigned int obuf_len;
108  /*
109  * Whatever sent the last message might want to handle a response;
110  * this is that handler; its private data; and its final return code.
111  */
115 
117 
118  struct regcache *machine;
119 
120  char *ostype;
121 
122  /* If we have an OS personality, try to load this from it. */
124 
125  int valid;
126 
127  /* The most recent set of paging flags. */
129 
130  /* Which hops are we using? */
132  void *hops_priv;
133 
135 };
136 
137 struct target *gdb_instantiate(struct target_spec *spec,
138  struct evloop *evloop);
139 struct gdb_spec *gdb_build_spec(void);
140 void gdb_free_spec(struct gdb_spec *xspec);
141 int gdb_spec_to_argv(struct target_spec *spec,int *argc,char ***argv);
142 
143 /*
144  * We support several different memory backends for Xen VMs.
145  */
147  int (*init)(struct target *target);
148  int (*attach)(struct target *target);
151  int (*handle_pause)(struct target *target);
152  int (*load_machine)(struct target *target,struct regcache *regcache);
153  int (*addr_v2p)(struct target *target,tid_t tid,ADDR pgd,
154  ADDR vaddr,ADDR *paddr);
155  unsigned char *(*read_phys)(struct target *target,ADDR paddr,
156  unsigned long length,unsigned char *buf);
157  unsigned long (*write_phys)(struct target *target,ADDR paddr,
158  unsigned long length,unsigned char *buf);
159  unsigned char *(*read_tid)(struct target *target,tid_t tid,ADDR pgd,ADDR addr,
160  unsigned long target_length,unsigned char *buf);
161  unsigned long (*write_tid)(struct target *target,tid_t tid,ADDR pgd,ADDR addr,
162  unsigned long length,unsigned char *buf);
163  int (*fini)(struct target *target);
164 };
165 
166 #endif /* __TARGET_GDB_H__ */
unsigned int obuf_len
Definition: target_gdb.h:107
unsigned int max_stub_packet_size
Definition: target_gdb.h:98
gdb_rsp_handler_t handler
Definition: target_gdb.h:112
int qemu_qmp_port
Definition: target_gdb.h:55
unsigned int writing
Definition: target_gdb.h:84
char * ibuf
Definition: target_gdb.h:102
unsigned int do_unix
Definition: target_gdb.h:39
unsigned int vcont_S
Definition: target_gdb.h:84
struct target_ops gdb_ops
Definition: target_gdb.c:195
char * sockfile
Definition: target_gdb.h:82
int32_t tid_t
Definition: common.h:36
char * hostname
Definition: target_gdb.h:51
unsigned int vcont
Definition: target_gdb.h:84
void * handler_data
Definition: target_gdb.h:113
ADDR kernel_start_addr
Definition: target_gdb.h:123
int gdb_spec_to_argv(struct target_spec *spec, int *argc, char ***argv)
Definition: target_gdb.c:331
unsigned long int memcache_mmap_size
Definition: target_gdb.h:47
unsigned int need_interrupt
Definition: target_gdb.h:84
unsigned long(* write_tid)(struct target *target, tid_t tid, ADDR pgd, ADDR addr, unsigned long length, unsigned char *buf)
Definition: target_gdb.h:161
char * qemu_mem_path
Definition: target_gdb.h:61
unsigned long(* write_phys)(struct target *target, ADDR paddr, unsigned long length, unsigned char *buf)
Definition: target_gdb.h:157
unsigned int vcont_r
Definition: target_gdb.h:84
arch_x86_v2p_flags_t v2p_flags
Definition: target_gdb.h:128
arch_x86_v2p_flags_t
unsigned int stepping
Definition: target_gdb.h:84
unsigned int ibuf_alen
Definition: target_gdb.h:103
char * devfile
Definition: target_gdb.h:49
char * qemu_qmp_hostname
Definition: target_gdb.h:54
Definition: evloop.h:66
char * obuf
Definition: target_gdb.h:106
unsigned int vcont_s
Definition: target_gdb.h:84
int(* addr_v2p)(struct target *target, tid_t tid, ADDR pgd, ADDR vaddr, ADDR *paddr)
Definition: target_gdb.h:153
char * ostype
Definition: target_gdb.h:120
int(* load_machine)(struct target *target, struct regcache *regcache)
Definition: target_gdb.h:152
struct target * gdb_instantiate(struct target_spec *spec, struct evloop *evloop)
Definition: target_gdb.c:594
int evloop_fd
Definition: target_gdb.h:134
char * main_filename
Definition: target_gdb.h:63
struct gdb_spec * gdb_build_spec(void)
Definition: target_gdb.c:574
unsigned int vcont_C
Definition: target_gdb.h:84
unsigned int clear_mem_caches_each_exception
Definition: target_gdb.h:39
unsigned int do_stdio
Definition: target_gdb.h:39
void * hops_priv
Definition: target_gdb.h:132
unsigned int is_qemu
Definition: target_gdb.h:39
gdb_rsp_handler_ret_t
unsigned int do_udp
Definition: target_gdb.h:39
gdb_rsp_handler_ret_t(* gdb_rsp_handler_t)(struct target *target, char *data, unsigned int len, void *handler_data)
gdb_rsp_handler_ret_t handler_ret
Definition: target_gdb.h:114
unsigned int vcont_t
Definition: target_gdb.h:84
char * gdb_argp_header
Definition: target_gdb.c:568
unsigned int rsp_status_valid
Definition: target_gdb.h:84
int(* handle_exception_ours)(struct target *target)
Definition: target_gdb.h:150
unsigned int machine_valid
Definition: target_gdb.h:84
int(* attach)(struct target *target)
Definition: target_gdb.h:148
unsigned int is_kvm
Definition: target_gdb.h:39
unsigned int need_ack
Definition: target_gdb.h:84
struct gdb_rsp_stop_status last_stop_status
Definition: target_gdb.h:116
char * qemu_libvirt_domain
Definition: target_gdb.h:65
void gdb_free_spec(struct gdb_spec *xspec)
Definition: target_gdb.c:583
uint32_t ADDR
Definition: common.h:64
unsigned int ibuf_len
Definition: target_gdb.h:104
int port
Definition: target_gdb.h:52
unsigned long dr[8]
Definition: target_gdb.h:76
int(* handle_pause)(struct target *target)
Definition: target_gdb.h:151
struct gdb_helper_ops * hops
Definition: target_gdb.h:131
struct target_spec * spec
Definition: target_api.h:2605
struct regcache * machine
Definition: target_gdb.h:118
int(* handle_exception_any)(struct target *target)
Definition: target_gdb.h:149
int(* init)(struct target *target)
Definition: target_gdb.h:147
char * sockfile
Definition: target_gdb.h:50
int(* fini)(struct target *target)
Definition: target_gdb.h:163
struct argp gdb_argp
Definition: target_gdb.c:565
GHashTable * stubfeatures
Definition: target_gdb.h:100
unsigned int vcont_c
Definition: target_gdb.h:84