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
regcache.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 __REGCACHE_H__
20 #define __REGCACHE_H__
21 
22 /*
23  * A simple register cache. Most usable in combination with an arch
24  * (and maybe arch_config) structs describing an architecture.
25  */
26 
27 #include "config.h"
28 #include "common.h"
29 #include <glib.h>
30 
31 #define REGCACHE_DIRTY (1 << 0)
32 #define REGCACHE_VALID (1 << 1)
33 #define REGCACHE_ALLOC (1 << 2)
34 
35 struct regcache {
36  struct arch *arch;
37 
38  /*
39  * The caller of regcache_init_reg and regcache_init_done has loaded
40  * all the registers it can. This may NOT mean that
41  * @valid == arch_regcount(@arch) -- IN FACT, it is here
42  * deliberately so that some targets can declare that they have
43  * loaded as many registers as they ever can -- the others just
44  * aren't supported by the target backend. That's one case, anyway.
45  */
47  /*
48  * A global valid count; increment when init_reg|init_reg_len called
49  * on a non-valid reg.
50  */
51  int valid;
52  /* A global dirty bit; has anything been written? */
53  int dirty;
54 
55  /*
56  * If values are larger than sizeof(void *), they point to memory
57  * that is the specified size of the register in struct arch. It
58  * helps that sizeof(void *) === sizeof(REGVAL) on any host platform
59  * we'll be compiled on, doh!
60  *
61  * This should be length arch->regcount.
62  */
65 
66  /*
67  * Flags:
68  */
69  int flags_len;
70  uint8_t *flags;
71 };
72 
73 struct regcache *regcache_create(struct arch *arch);
74 void regcache_destroy(struct regcache *regcache);
75 
76 int regcache_copy_all(struct regcache *sregcache,struct regcache *dregcache);
77 int regcache_copy_dirty(struct regcache *sregcache,struct regcache *dregcache);
78 void regcache_zero(struct regcache *regcache);
81 
82 int regcache_init_reg(struct regcache *regcache,REG reg,REGVAL regval);
84 int regcache_isdirty_reg_range(struct regcache *regcache,REG start,REG end);
85 int regcache_isdirty_reg(struct regcache *regcache,REG reg);
87 int regcache_write_reg(struct regcache *regcache,REG reg,REGVAL regval);
88 int regcache_read_reg(struct regcache *regcache,REG reg,REGVAL *regval);
89 int regcache_read_reg_ifdirty(struct regcache *regcache,REG reg,REGVAL *regval);
90 
92  void *regdata,unsigned int reglen);
94  void *regdata,unsigned int reglen);
96  void **regdata,unsigned int *reglen);
97 
98 GHashTable *regcache_copy_registers(struct regcache *regcache);
99 
100 /*
101  * snprintfs the current register values to a string. It prints each
102  * register as a key-value pair; only printing the valid ones unless
103  * @flags includes REGCACHE_PRINT_DEFAULTS. It tries to grab
104  * register-printing info from regcache->arch; otherwise it will just
105  * dump them all as hex values.
106  */
107 #define REGCACHE_PRINT_DEFAULTS (1 << 0)
108 #define REGCACHE_PRINT_PADDING (1 << 1)
109 //#define REGCACHE_PRINT_LEADSEP (1 << 2)
110 int regcache_snprintf(struct regcache *regcache,char *buf,int bufsiz,
111  int detail,char *sep,char *kvsep,int flags);
112 
113 //#define regcache_foreach_dirty(regcache,regno)
114 // for (int _i = 0; _i < (regcache)->flags_len; ++_i
115 
116 
117 #endif /* __REGCACHE_H__ */
int regcache_isdirty_reg_range(struct regcache *regcache, REG start, REG end)
Definition: regcache.c:212
struct arch * arch
Definition: regcache.h:36
GHashTable * regcache_copy_registers(struct regcache *regcache)
Definition: regcache.c:422
void regcache_mark_flushed(struct regcache *regcache)
Definition: regcache.c:118
int dirty
Definition: regcache.h:53
int regcache_init_done(struct regcache *regcache)
Definition: regcache.c:189
int regcache_write_reg(struct regcache *regcache, REG reg, REGVAL regval)
Definition: regcache.c:240
int regcache_write_reg_len(struct regcache *regcache, REG reg, void *regdata, unsigned int reglen)
Definition: regcache.c:359
int valid
Definition: regcache.h:51
int values_len
Definition: regcache.h:64
int regcache_init_reg(struct regcache *regcache, REG reg, REGVAL regval)
Definition: regcache.c:153
int regcache_copy_all(struct regcache *sregcache, struct regcache *dregcache)
Definition: regcache.c:58
void regcache_invalidate(struct regcache *regcache)
Definition: regcache.c:127
void regcache_zero(struct regcache *regcache)
Definition: regcache.c:101
int regcache_read_reg_ifdirty(struct regcache *regcache, REG reg, REGVAL *regval)
Definition: regcache.c:299
int regcache_init_reg_len(struct regcache *regcache, REG reg, void *regdata, unsigned int reglen)
Definition: regcache.c:323
int flags_len
Definition: regcache.h:69
uint8_t * flags
Definition: regcache.h:70
REGVAL * values
Definition: regcache.h:63
int regcache_read_reg(struct regcache *regcache, REG reg, REGVAL *regval)
Definition: regcache.c:271
int done_loading
Definition: regcache.h:46
void regcache_destroy(struct regcache *regcache)
Definition: regcache.c:42
uint32_t REGVAL
Definition: common.h:66
int regcache_isdirty_reg(struct regcache *regcache, REG reg)
Definition: regcache.c:202
int8_t REG
Definition: common.h:93
Definition: arch.h:116
int regcache_read_reg_len(struct regcache *regcache, REG reg, void **regdata, unsigned int *reglen)
Definition: regcache.c:396
struct regcache * regcache_create(struct arch *arch)
Definition: regcache.c:29
int regcache_snprintf(struct regcache *regcache, char *buf, int bufsiz, int detail, char *sep, char *kvsep, int flags)
Definition: regcache.c:459
int regcache_copy_dirty(struct regcache *sregcache, struct regcache *dregcache)
Definition: regcache.c:75
int regcache_isdirty(struct regcache *regcache)
Definition: regcache.c:236