[gem5-dev] Change in gem5/gem5[develop]: sim: Trap into GDB instead of panicking on SEGV

2021-04-22 Thread Boris Shingarov (Gerrit) via gem5-dev
Boris Shingarov has submitted this change. (  
https://gem5-review.googlesource.com/c/public/gem5/+/44685 )


Change subject: sim: Trap into GDB instead of panicking on SEGV
..

sim: Trap into GDB instead of panicking on SEGV

When a segfault happens in the guest, report a SEGV trap to GDB (if
there is one attached) instead of bailing out immediately.

The obvious use-case for this, is the ability to debug guest crashes
in GDB in the standard manner.

The less-trivial use-case is for development of software in an
incomplete software stack (cf. Aarno-Engblom's "Virtual Platforms"
pp.105 et seq.)  One particular example is Ingalls-Miranda simulation of
JIT compilers, where the VM's address space may be split between the
simulated and the real machine: in this case, GDB traps facilitate the
transparent illusion of an unbroken address space.

Change-Id: I9072ed5f6474e05e9a99dc42ae5754be28121355
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/44685
Reviewed-by: Gabe Black 
Reviewed-by: Andreas Sandberg 
Maintainer: Gabe Black 
Tested-by: kokoro 
---
M src/arch/null/remote_gdb.hh
M src/sim/faults.cc
M src/sim/system.cc
M src/sim/system.hh
4 files changed, 21 insertions(+), 4 deletions(-)

Approvals:
  Andreas Sandberg: Looks good to me, approved
  Gabe Black: Looks good to me, but someone else must approve; Looks good  
to me, approved

  kokoro: Regressions pass



diff --git a/src/arch/null/remote_gdb.hh b/src/arch/null/remote_gdb.hh
index 4df9cc8..c47ca9b 100644
--- a/src/arch/null/remote_gdb.hh
+++ b/src/arch/null/remote_gdb.hh
@@ -47,6 +47,7 @@

 bool breakpoint() { return false; }
 void replaceThreadContext(ThreadContext *tc) {}
+bool trap(int type) { return true; }

 virtual ~BaseRemoteGDB() {}
 };
diff --git a/src/sim/faults.cc b/src/sim/faults.cc
index 501b5d1..e4f4ae1 100644
--- a/src/sim/faults.cc
+++ b/src/sim/faults.cc
@@ -40,6 +40,8 @@

 #include "sim/faults.hh"

+#include 
+
 #include "arch/decoder.hh"
 #include "arch/locked_mem.hh"
 #include "base/logging.hh"
@@ -94,15 +96,16 @@
 Process *p = tc->getProcessPtr();
 handled = p->fixupFault(vaddr);
 }
-panic_if(!handled, "Page table fault when accessing virtual  
address %#x",

- vaddr);
-
+panic_if(!handled &&
+ !tc->getSystemPtr()->trapToGdb(SIGSEGV, tc->contextId()),
+ "Page table fault when accessing virtual address %#x\n",  
vaddr);

 }

 void
 GenericAlignmentFault::invoke(ThreadContext *tc, const StaticInstPtr )
 {
-panic("Alignment fault when accessing virtual address %#x\n", vaddr);
+panic_if(!tc->getSystemPtr()->trapToGdb(SIGSEGV, tc->contextId()),
+ "Alignment fault when accessing virtual address %#x\n",  
vaddr);

 }

 void GenericHtmFailureFault::invoke(ThreadContext *tc,
diff --git a/src/sim/system.cc b/src/sim/system.cc
index 9fd312c..8b23f90 100644
--- a/src/sim/system.cc
+++ b/src/sim/system.cc
@@ -495,6 +495,16 @@
 lastWorkItemStarted.erase(p);
 }

+bool
+System::trapToGdb(int signal, ContextID ctx_id) const
+{
+auto *gdb = threads.thread(ctx_id).gdb;
+if (!gdb)
+return false;
+gdb->trap(signal);
+return true;
+}
+
 void
 System::printSystems()
 {
diff --git a/src/sim/system.hh b/src/sim/system.hh
index 6613217..acdb316 100644
--- a/src/sim/system.hh
+++ b/src/sim/system.hh
@@ -561,6 +561,9 @@

 void workItemEnd(uint32_t tid, uint32_t workid);

+/* Returns whether we successfully trapped into GDB. */
+bool trapToGdb(int signal, ContextID ctx_id) const;
+
   protected:
 /**
  * Range for memory-mapped m5 pseudo ops. The range will be

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


Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I9072ed5f6474e05e9a99dc42ae5754be28121355
Gerrit-Change-Number: 44685
Gerrit-PatchSet: 4
Gerrit-Owner: Boris Shingarov 
Gerrit-Reviewer: Andreas Sandberg 
Gerrit-Reviewer: Boris Shingarov 
Gerrit-Reviewer: Gabe Black 
Gerrit-Reviewer: Gabe Black 
Gerrit-Reviewer: Giacomo Travaglini 
Gerrit-Reviewer: Jason Lowe-Power 
Gerrit-Reviewer: Jason Lowe-Power 
Gerrit-Reviewer: kokoro 
Gerrit-MessageType: merged
___
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

[gem5-dev] Change in gem5/gem5[develop]: sim: Trap into GDB instead of panicking on SEGV

2021-04-20 Thread Boris Shingarov (Gerrit) via gem5-dev
Boris Shingarov has uploaded this change for review. (  
https://gem5-review.googlesource.com/c/public/gem5/+/44685 )



Change subject: sim: Trap into GDB instead of panicking on SEGV
..

sim: Trap into GDB instead of panicking on SEGV

When a segfault happens in the guest, report a SEGV trap to GDB (if
there is one attached) instead of bailing out immediately.

The obvious use-case for this, is the ability to debug guest crashes
in GDB in the standard manner.

The less-trivial use-case is for development of software in an
incomplete software stack (cf. Aarno-Engblom's "Virtual Platforms"
pp.105 et seq.)  One particular example is Ingalls-Miranda simulation of
JIT compilers, where the VM's address space may be split between the
simulated and the real machine: in this case, GDB traps facilitate the
transparent illusion of an unbroken address space.

Change-Id: I9072ed5f6474e05e9a99dc42ae5754be28121355
---
M src/sim/faults.cc
M src/sim/system.cc
M src/sim/system.hh
3 files changed, 21 insertions(+), 4 deletions(-)



diff --git a/src/sim/faults.cc b/src/sim/faults.cc
index 501b5d1..13de0fc 100644
--- a/src/sim/faults.cc
+++ b/src/sim/faults.cc
@@ -40,6 +40,8 @@

 #include "sim/faults.hh"

+#include 
+
 #include "arch/decoder.hh"
 #include "arch/locked_mem.hh"
 #include "base/logging.hh"
@@ -94,15 +96,16 @@
 Process *p = tc->getProcessPtr();
 handled = p->fixupFault(vaddr);
 }
-panic_if(!handled, "Page table fault when accessing virtual  
address %#x",

- vaddr);
-
+if (handled) return;
+panic_if(tc->getSystemPtr()->trap_to_gdb(SIGSEGV),
+ "Page table fault when accessing virtual address %#x\n",  
vaddr);

 }

 void
 GenericAlignmentFault::invoke(ThreadContext *tc, const StaticInstPtr )
 {
-panic("Alignment fault when accessing virtual address %#x\n", vaddr);
+panic_if(tc->getSystemPtr()->trap_to_gdb(SIGSEGV),
+ "Alignment fault when accessing virtual address %#x\n",  
vaddr);

 }

 void GenericHtmFailureFault::invoke(ThreadContext *tc,
diff --git a/src/sim/system.cc b/src/sim/system.cc
index 9fd312c..e8f881a 100644
--- a/src/sim/system.cc
+++ b/src/sim/system.cc
@@ -495,6 +495,18 @@
 lastWorkItemStarted.erase(p);
 }

+bool
+System::trap_to_gdb(int signal) const
+{
+if (!threads.size())
+return true; /* true if we failed, so caller needs to panic  */
+auto *gdb = threads.thread(0).gdb;
+if (!gdb)
+return true;
+gdb->trap(signal);
+return false;
+}
+
 void
 System::printSystems()
 {
diff --git a/src/sim/system.hh b/src/sim/system.hh
index 6613217..fe02349 100644
--- a/src/sim/system.hh
+++ b/src/sim/system.hh
@@ -561,6 +561,8 @@

 void workItemEnd(uint32_t tid, uint32_t workid);

+bool trap_to_gdb(int signal) const;
+
   protected:
 /**
  * Range for memory-mapped m5 pseudo ops. The range will be

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


Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I9072ed5f6474e05e9a99dc42ae5754be28121355
Gerrit-Change-Number: 44685
Gerrit-PatchSet: 1
Gerrit-Owner: Boris Shingarov 
Gerrit-MessageType: newchange
___
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s