[gem5-dev] Change in gem5/gem5[master]: sim: Add a dumpSimcall mechanism to GuestABI.

2020-01-13 Thread Gabe Black (Gerrit)
Gabe Black has submitted this change. (  
https://gem5-review.googlesource.com/c/public/gem5/+/23460 )


Change subject: sim: Add a dumpSimcall mechanism to GuestABI.
..

sim: Add a dumpSimcall mechanism to GuestABI.

This dumps a signature for a simcall as if it was going to be invoked,
and can be used for debugging.

Change-Id: I6262b94ad4186bac8dc5a1469e9bb3b8ae9d34e1
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/23460
Reviewed-by: Jason Lowe-Power 
Maintainer: Jason Lowe-Power 
Tested-by: kokoro 
---
M src/sim/guest_abi.hh
M src/sim/guest_abi.test.cc
2 files changed, 82 insertions(+), 0 deletions(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/sim/guest_abi.hh b/src/sim/guest_abi.hh
index b2176a6..ff1464e 100644
--- a/src/sim/guest_abi.hh
+++ b/src/sim/guest_abi.hh
@@ -32,6 +32,7 @@

 #include 
 #include 
+#include 
 #include 

 class ThreadContext;
@@ -213,6 +214,14 @@
 }
 };

+template 
+std::ostream &
+operator << (std::ostream , const VarArgs )
+{
+os << "...";
+return os;
+}
+
 // The ABI independent hook which tells the GuestABI mechanism what to do  
with
 // a VarArgs argument. It constructs the underlying implementation which  
knows

 // about the ABI, and installs it in the VarArgs wrapper to give to the
@@ -301,6 +310,44 @@
 callFrom(tc, position, partial);
 }

+
+
+/*
+ * These functions are like the ones above, except they print the arguments
+ * a target function would be called with instead of actually calling it.
+ */
+
+// With no arguments to print, add the closing parenthesis and return.
+template 
+static void
+dumpArgsFrom(int count, std::ostream , ThreadContext *tc,
+ typename ABI::Position )
+{
+os << ")";
+}
+
+// Recursively gather arguments for target from tc until we get to the base
+// case above, and append those arguments to the string stream being
+// constructed.
+template 
+static void
+dumpArgsFrom(int count, std::ostream , ThreadContext *tc,
+ typename ABI::Position )
+{
+// Either open the parenthesis or add a comma, depending on where we  
are

+// in the argument list.
+os << (count ? ", " : "(");
+
+// Extract the next argument from the thread context.
+NextArg next = Argument::get(tc, position);
+
+// Add this argument to the list.
+os << next;
+
+// Recursively handle any remaining arguments.
+dumpArgsFrom(count + 1, os, tc, position);
+}
+
 } // namespace GuestABI


@@ -347,4 +394,32 @@
 tc, std::function(target));
 }

+
+// These functions also wrap a simulator level function. Instead of  
running the
+// function, they return a string which shows what arguments the function  
would

+// be invoked with if it were called from the given context.
+
+template 
+std::string
+dumpSimcall(std::string name, ThreadContext *tc,
+std::function target=
+std::function())
+{
+auto position = typename ABI::Position();
+std::ostringstream ss;
+
+ss << name;
+GuestABI::dumpArgsFrom(0, ss, tc, position);
+return ss.str();
+}
+
+template 
+std::string
+dumpSimcall(std::string name, ThreadContext *tc,
+Ret (*target)(ThreadContext *, Args...))
+{
+return dumpSimcall(
+name, tc, std::functionArgs...)>(target));

+}
+
 #endif // __SIM_GUEST_ABI_HH__
diff --git a/src/sim/guest_abi.test.cc b/src/sim/guest_abi.test.cc
index ee536aa..19efb7d 100644
--- a/src/sim/guest_abi.test.cc
+++ b/src/sim/guest_abi.test.cc
@@ -275,3 +275,10 @@
 EXPECT_EQ(tc.floatResult, DoubleRetValue + 2.0);
 }
 }
+
+TEST(GuestABI, dumpSimcall)
+{
+ThreadContext tc;
+std::string dump = dumpSimcall("test", , testIntVoid);
+EXPECT_EQ(dump, "test(0, 11, 2, 13, ...)");
+}

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/23460
To unsubscribe, or for help writing mail filters, visit  
https://gem5-review.googlesource.com/settings


Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I6262b94ad4186bac8dc5a1469e9bb3b8ae9d34e1
Gerrit-Change-Number: 23460
Gerrit-PatchSet: 4
Gerrit-Owner: Gabe Black 
Gerrit-Reviewer: Brandon Potter 
Gerrit-Reviewer: Gabe Black 
Gerrit-Reviewer: Giacomo Travaglini 
Gerrit-Reviewer: Jason Lowe-Power 
Gerrit-Reviewer: kokoro 
Gerrit-MessageType: merged
___
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

[gem5-dev] Change in gem5/gem5[master]: sim: Add a dumpSimcall mechanism to GuestABI.

2019-12-08 Thread Gabe Black (Gerrit)
Gabe Black has uploaded this change for review. (  
https://gem5-review.googlesource.com/c/public/gem5/+/23460 )



Change subject: sim: Add a dumpSimcall mechanism to GuestABI.
..

sim: Add a dumpSimcall mechanism to GuestABI.

This dumps a signature for a simcall as if it was going to be invoked,
and can be used for debugging.

Change-Id: I6262b94ad4186bac8dc5a1469e9bb3b8ae9d34e1
---
M src/sim/guest_abi.hh
M src/sim/guest_abi.test.cc
2 files changed, 85 insertions(+), 0 deletions(-)



diff --git a/src/sim/guest_abi.hh b/src/sim/guest_abi.hh
index b2176a6..f0a6a2d 100644
--- a/src/sim/guest_abi.hh
+++ b/src/sim/guest_abi.hh
@@ -32,6 +32,7 @@

 #include 
 #include 
+#include 
 #include 

 class ThreadContext;
@@ -213,6 +214,14 @@
 }
 };

+template 
+std::ostream &
+operator << (std::ostream , const VarArgs )
+{
+os << "...";
+return os;
+}
+
 // The ABI independent hook which tells the GuestABI mechanism what to do  
with
 // a VarArgs argument. It constructs the underlying implementation which  
knows

 // about the ABI, and installs it in the VarArgs wrapper to give to the
@@ -301,6 +310,47 @@
 callFrom(tc, position, partial);
 }

+
+
+/*
+ * These functions are like the ones above, except they print the arguments
+ * a target function would be called with instead of actually calling it.
+ */
+
+// With no arguments to print, add the closing parenthesis and return.
+template 
+static void
+dumpArgsFrom(std::ostream , ThreadContext *tc,
+ typename ABI::Position )
+{
+os << ")";
+}
+
+// Recursively gather arguments for target from tc until we get to the base
+// case above, and append those arguments to the string stream being
+// constructed.
+template 
+static void
+dumpArgsFrom(std::ostream , ThreadContext *tc,
+ typename ABI::Position )
+{
+// Either open the parenthesis or add a comma, depending on where we  
are

+// in the argument list.
+if (position == typename ABI::Position())
+os << "(";
+else
+os << ", ";
+
+// Extract the next argument from the thread context.
+NextArg next = Argument::get(tc, position);
+
+// Add this argument to the list.
+os << next;
+
+// Recursively handle any remaining arguments.
+dumpArgsFrom(os, tc, position);
+}
+
 } // namespace GuestABI


@@ -347,4 +397,32 @@
 tc, std::function(target));
 }

+
+// These functions also wrap a simulator level function. Instead of  
running the
+// function, they return a string which shows what arguments the function  
would

+// be invoked with if it were called from the given context.
+
+template 
+std::string
+dumpSimcall(std::string name, ThreadContext *tc,
+std::function target=
+std::function())
+{
+auto position = typename ABI::Position();
+std::ostringstream ss;
+
+ss << name;
+GuestABI::dumpArgsFrom(ss, tc, position);
+return ss.str();
+}
+
+template 
+std::string
+dumpSimcall(std::string name, ThreadContext *tc,
+Ret (*target)(ThreadContext *, Args...))
+{
+return dumpSimcall(
+name, tc, std::functionArgs...)>(target));

+}
+
 #endif // __SIM_GUEST_ABI_HH__
diff --git a/src/sim/guest_abi.test.cc b/src/sim/guest_abi.test.cc
index ee536aa..19efb7d 100644
--- a/src/sim/guest_abi.test.cc
+++ b/src/sim/guest_abi.test.cc
@@ -275,3 +275,10 @@
 EXPECT_EQ(tc.floatResult, DoubleRetValue + 2.0);
 }
 }
+
+TEST(GuestABI, dumpSimcall)
+{
+ThreadContext tc;
+std::string dump = dumpSimcall("test", , testIntVoid);
+EXPECT_EQ(dump, "test(0, 11, 2, 13, ...)");
+}

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/23460
To unsubscribe, or for help writing mail filters, visit  
https://gem5-review.googlesource.com/settings


Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I6262b94ad4186bac8dc5a1469e9bb3b8ae9d34e1
Gerrit-Change-Number: 23460
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black 
Gerrit-MessageType: newchange
___
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev