[3/4] gdb: Extend the trad-frame API

Message ID e3d577115aafef1b3cc48e649b792566a95eeae7.1535560591.git.andrew.burgess@embecosm.com
State New, archived
Headers

Commit Message

Andrew Burgess Aug. 29, 2018, 4:40 p.m. UTC
  Adds two new functions to the trad-frame API and update the internals
of trad-frame to use the new functions.  These functions will be used
in later commits.

gdb/ChangeLog:

	* trad-frame.h (trad_frame_set_realreg): Declare.
	(trad_frame_set_addr): Declare.
	* trad-frame.c (trad_frame_set_realreg): Define new function.
	(trad_frame_set_addr): Define new function.
	(trad_frame_set_reg_realreg): Use new function.
	(trad_frame_set_reg_addr): Use new function.
---
 gdb/ChangeLog    |  9 +++++++++
 gdb/trad-frame.c | 21 ++++++++++++++++++---
 gdb/trad-frame.h |  8 ++++++++
 3 files changed, 35 insertions(+), 3 deletions(-)
  

Comments

Tom Tromey Aug. 31, 2018, 3:02 p.m. UTC | #1
>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> Adds two new functions to the trad-frame API and update the internals
Andrew> of trad-frame to use the new functions.  These functions will be used
Andrew> in later commits.

Andrew> gdb/ChangeLog:

Andrew> 	* trad-frame.h (trad_frame_set_realreg): Declare.
Andrew> 	(trad_frame_set_addr): Declare.
Andrew> 	* trad-frame.c (trad_frame_set_realreg): Define new function.
Andrew> 	(trad_frame_set_addr): Define new function.
Andrew> 	(trad_frame_set_reg_realreg): Use new function.
Andrew> 	(trad_frame_set_reg_addr): Use new function.

IIUC this is just exposing a bit more of trad frame, so that you can
manipulate the information without having a frame cache.

This seems reasonable enough.  This is ok.

I suppose another approach would have been to just keep a trad frame
cache as a member of your new object.  But there's nothing wrong with
your chosen approach either, IMO.

Tom
  

Patch

diff --git a/gdb/trad-frame.c b/gdb/trad-frame.c
index a6e24158279..e3e48f2b7b0 100644
--- a/gdb/trad-frame.c
+++ b/gdb/trad-frame.c
@@ -105,6 +105,22 @@  trad_frame_set_value (struct trad_frame_saved_reg this_saved_regs[],
   this_saved_regs[regnum].addr = val;
 }
 
+void
+trad_frame_set_realreg (struct trad_frame_saved_reg this_saved_regs[],
+			int regnum, int realreg)
+{
+  this_saved_regs[regnum].realreg = realreg;
+  this_saved_regs[regnum].addr = -1;
+}
+
+void
+trad_frame_set_addr (struct trad_frame_saved_reg this_saved_regs[],
+		     int regnum, CORE_ADDR addr)
+{
+  this_saved_regs[regnum].realreg = regnum;
+  this_saved_regs[regnum].addr = addr;
+}
+
 void
 trad_frame_set_reg_value (struct trad_frame_cache *this_trad_cache,
 			  int regnum, LONGEST val)
@@ -118,15 +134,14 @@  void
 trad_frame_set_reg_realreg (struct trad_frame_cache *this_trad_cache,
 			    int regnum, int realreg)
 {
-  this_trad_cache->prev_regs[regnum].realreg = realreg;
-  this_trad_cache->prev_regs[regnum].addr = -1;
+  trad_frame_set_realreg (this_trad_cache->prev_regs, regnum, realreg);
 }
 
 void
 trad_frame_set_reg_addr (struct trad_frame_cache *this_trad_cache,
 			 int regnum, CORE_ADDR addr)
 {
-  this_trad_cache->prev_regs[regnum].addr = addr;
+  trad_frame_set_addr (this_trad_cache->prev_regs, regnum, addr);
 }
 
 void
diff --git a/gdb/trad-frame.h b/gdb/trad-frame.h
index f7ec43cc80c..a11a2c29c9c 100644
--- a/gdb/trad-frame.h
+++ b/gdb/trad-frame.h
@@ -88,6 +88,14 @@  struct trad_frame_saved_reg
 void trad_frame_set_value (struct trad_frame_saved_reg this_saved_regs[],
 			   int regnum, LONGEST val);
 
+/* Encode REGNUM is in REALREG in the trad-frame.  */
+void trad_frame_set_realreg (struct trad_frame_saved_reg this_saved_regs[],
+			     int regnum, int realreg);
+
+/* Encode REGNUM is at address ADDR in the trad-frame.  */
+void trad_frame_set_addr (struct trad_frame_saved_reg this_trad_cache[],
+			  int regnum, CORE_ADDR addr);
+
 /* Mark REGNUM as unknown.  */
 void trad_frame_set_unknown (struct trad_frame_saved_reg this_saved_regs[],
 			     int regnum);