[20/26] gdbserver: make some regcache fields private

Message ID e212bf44ab32c693e1b46a696afd1666c0d090dc.1677582745.git.tankut.baris.aktemur@intel.com
State New
Headers
Series gdbserver: refactor regcache and allow gradually populating |

Commit Message

Aktemur, Tankut Baris Feb. 28, 2023, 11:28 a.m. UTC
  Some fields of the regcache struct are used for internal state
tracking.  Prevent direct access to them from outside by making them
private.
---
 gdbserver/regcache.h | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Simon Marchi Dec. 22, 2023, 3:39 a.m. UTC | #1
On 2023-02-28 06:28, Tankut Baris Aktemur via Gdb-patches wrote:
> Some fields of the regcache struct are used for internal state
> tracking.  Prevent direct access to them from outside by making them
> private.

This is a good step, but it would be nice to:

 - rename private fields to prefix them with `m_`.  When accessing
   fields that are not prefixed with `m_`, I like to use `this->`,
   otherwise it's not obvious what you are acessing.  With the prefix
   though, I don't think it's necessary, as the naming makes it obvious.
   It then makes the code a bit more concise.
 - reorder members of the class to be somewhat in standard order.  I
   don't think we have a strict rule about this, but it's typically:
   constructor, destructor, public methods, public fields, private
   methods, private fields.

I don't mind if this is done by editing the patches in this series, or
as a change on top, if it's easier.

Simon
  

Patch

diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h
index ad71a9acaec..be412bc3765 100644
--- a/gdbserver/regcache.h
+++ b/gdbserver/regcache.h
@@ -36,6 +36,8 @@  struct regcache : public reg_buffer_common
   /* Back-link to the thread to which this regcache belongs.  */
   thread_info *thread = nullptr;
 
+private:
+
   /* Whether the REGISTERS buffer's contents are fetched.  If false,
      we haven't fetched the registers from the target yet.  Note that
      this register cache is _not_ pass-through, unlike GDB's.  Also,
@@ -49,6 +51,8 @@  struct regcache : public reg_buffer_common
   /* See gdbsupport/common-regcache.h.  */
   enum register_status *register_status = nullptr;
 
+public:
+
   /* Constructors.  */
   regcache () = default;
   regcache (const target_desc *tdesc);
@@ -59,6 +63,8 @@  struct regcache : public reg_buffer_common
   virtual ~regcache ();
 #endif
 
+public:
+
   /* Init the regcache data.  */
   void initialize (const target_desc *tdesc, unsigned char *regbuf);