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