diff options
author | Alan Hayward <alan.hayward@arm.com> | 2018-06-11 10:09:16 +0100 |
---|---|---|
committer | Alan Hayward <alan.hayward@arm.com> | 2018-06-11 10:09:16 +0100 |
commit | 9c861883169cb9eec4581ab6db3a1b711e79ee10 (patch) | |
tree | 24530802092757d9aaf0e0f93e0e7cae3507aa8d /gdb/gdbserver | |
parent | 953edf2b6cfe765ca7176c414e9f63aa62bdb09c (diff) | |
download | gdb-9c861883169cb9eec4581ab6db3a1b711e79ee10.zip gdb-9c861883169cb9eec4581ab6db3a1b711e79ee10.tar.gz gdb-9c861883169cb9eec4581ab6db3a1b711e79ee10.tar.bz2 |
Add reg_buffer_common
A purely virtual class containing functions from gdb/regcache.h
Both the gdb regcache structures and gdbserver regcache inherit
directly from reg_buffer_common. This will allow for common
functions which require the use of a regcache.
gdb/
* common/common-regcache.h (reg_buffer_common): New structure.
* regcache.c (reg_buffer::invalidate): Move from detached_regcache.
(reg_buffer::raw_supply): Likewise.
(reg_buffer::raw_supply_integer): Likewise.
(reg_buffer::raw_supply_zeroed): Likewise.
(reg_buffer::raw_collect): Likewise.
(reg_buffer::raw_collect_integer): Likewise.
* regcache.h (reg_buffer::invalidate): Move from detached_regcache.
(reg_buffer::raw_supply): Likewise.
(reg_buffer::raw_supply_integer): Likewise.
(reg_buffer::raw_supply_zeroed): Likewise.
(reg_buffer::raw_collect): Likewise.
(reg_buffer::raw_collect_integer): Likewise.
gdbserver/
* regcache.c (new_register_cache): Use new.
(free_register_cache): Use delete.
(register_data): Use const.
(supply_register): Move body inside regcache.
(regcache::raw_supply): New override function.
(collect_register): Move body inside regcache.
(regcache::raw_collect): New override function.
(regcache::get_register_status): New override function.
* regcache.h (struct regcache): Inherit from reg_buffer_common.
Diffstat (limited to 'gdb/gdbserver')
-rw-r--r-- | gdb/gdbserver/ChangeLog | 12 | ||||
-rw-r--r-- | gdb/gdbserver/regcache.c | 56 | ||||
-rw-r--r-- | gdb/gdbserver/regcache.h | 21 |
3 files changed, 66 insertions, 23 deletions
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 6917e68..d11ce5d 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,15 @@ +2018-06-11 Alan Hayward <alan.hayward@arm.com> + + * regcache.c (new_register_cache): Use new. + (free_register_cache): Use delete. + (register_data): Use const. + (supply_register): Move body inside regcache. + (regcache::raw_supply): New override function. + (collect_register): Move body inside regcache. + (regcache::raw_collect): New override function. + (regcache::get_register_status): New override function. + * regcache.h (struct regcache): Inherit from reg_buffer_common. + 2018-06-09 Tom Tromey <tom@tromey.com> * event-loop.c (gdb_event, gdb_event_p): Remove typedefs. Don't diff --git a/gdb/gdbserver/regcache.c b/gdb/gdbserver/regcache.c index 0718b9f..8383752 100644 --- a/gdb/gdbserver/regcache.c +++ b/gdb/gdbserver/regcache.c @@ -159,7 +159,7 @@ init_register_cache (struct regcache *regcache, struct regcache * new_register_cache (const struct target_desc *tdesc) { - struct regcache *regcache = XCNEW (struct regcache); + struct regcache *regcache = new struct regcache; gdb_assert (tdesc->registers_size != 0); @@ -174,7 +174,7 @@ free_register_cache (struct regcache *regcache) if (regcache->registers_owned) free (regcache->registers); free (regcache->register_status); - free (regcache); + delete regcache; } } @@ -300,35 +300,37 @@ regcache_register_size (const struct regcache *regcache, int n) } static unsigned char * -register_data (struct regcache *regcache, int n, int fetch) +register_data (const struct regcache *regcache, int n, int fetch) { return (regcache->registers + find_register_by_number (regcache->tdesc, n).offset / 8); } -/* Supply register N, whose contents are stored in BUF, to REGCACHE. - If BUF is NULL, the register's value is recorded as - unavailable. */ - void supply_register (struct regcache *regcache, int n, const void *buf) { + return regcache->raw_supply (n, buf); +} + +/* See common/common-regcache.h. */ + +void +regcache::raw_supply (int n, const void *buf) +{ if (buf) { - memcpy (register_data (regcache, n, 0), buf, - register_size (regcache->tdesc, n)); + memcpy (register_data (this, n, 0), buf, register_size (tdesc, n)); #ifndef IN_PROCESS_AGENT - if (regcache->register_status != NULL) - regcache->register_status[n] = REG_VALID; + if (register_status != NULL) + register_status[n] = REG_VALID; #endif } else { - memset (register_data (regcache, n, 0), 0, - register_size (regcache->tdesc, n)); + memset (register_data (this, n, 0), 0, register_size (tdesc, n)); #ifndef IN_PROCESS_AGENT - if (regcache->register_status != NULL) - regcache->register_status[n] = REG_UNAVAILABLE; + if (register_status != NULL) + register_status[n] = REG_UNAVAILABLE; #endif } } @@ -410,8 +412,15 @@ supply_register_by_name (struct regcache *regcache, void collect_register (struct regcache *regcache, int n, void *buf) { - memcpy (buf, register_data (regcache, n, 1), - register_size (regcache->tdesc, n)); + regcache->raw_collect (n, buf); +} + +/* See common/common-regcache.h. */ + +void +regcache::raw_collect (int n, void *buf) const +{ + memcpy (buf, register_data (this, n, 1), register_size (tdesc, n)); } enum register_status @@ -480,3 +489,16 @@ regcache_write_pc (struct regcache *regcache, CORE_ADDR pc) } #endif + +/* See common/common-regcache.h. */ + +enum register_status +regcache::get_register_status (int regnum) const +{ +#ifndef IN_PROCESS_AGENT + gdb_assert (regnum >= 0 && regnum < tdesc->reg_defs.size ()); + return (enum register_status) (register_status[regnum]); +#else + return REG_VALID; +#endif +} diff --git a/gdb/gdbserver/regcache.h b/gdb/gdbserver/regcache.h index 2c0df64..352c1df 100644 --- a/gdb/gdbserver/regcache.h +++ b/gdb/gdbserver/regcache.h @@ -28,23 +28,32 @@ struct target_desc; inferior; this is primarily for simplicity, as the performance benefit is minimal. */ -struct regcache +struct regcache : public reg_buffer_common { /* The regcache's target description. */ - const struct target_desc *tdesc; + const struct target_desc *tdesc = nullptr; /* Whether the REGISTERS buffer's contents are valid. If false, we haven't fetched the registers from the target yet. Not that this register cache is _not_ pass-through, unlike GDB's. Note that "valid" here is unrelated to whether the registers are available in a traceframe. For that, check REGISTER_STATUS below. */ - int registers_valid; - int registers_owned; - unsigned char *registers; + int registers_valid = 0; + int registers_owned = 0; + unsigned char *registers = nullptr; #ifndef IN_PROCESS_AGENT /* One of REG_UNAVAILBLE or REG_VALID. */ - unsigned char *register_status; + unsigned char *register_status = nullptr; #endif + + /* See common/common-regcache.h. */ + enum register_status get_register_status (int regnum) const override; + + /* See common/common-regcache.h. */ + void raw_supply (int regnum, const void *buf) override; + + /* See common/common-regcache.h. */ + void raw_collect (int regnum, void *buf) const override; }; struct regcache *init_register_cache (struct regcache *regcache, |