mirror of
https://github.com/RKX1209/nsemu.git
synced 2024-06-15 18:57:39 -04:00
Add cpu dump function after trigerring SEGV
This commit is contained in:
parent
1e19f441d7
commit
34a21912ae
|
@ -22,21 +22,21 @@ void RunLoop() {
|
|||
|
||||
void Dump() {
|
||||
int cnt = 1;
|
||||
debug_print ("CPU Dump:\n");
|
||||
ns_print ("CPU Dump:\n");
|
||||
for (int r = 0; r < GPR_DUMMY; r++) {
|
||||
if (!X(r))
|
||||
continue;
|
||||
if (r == GPR_LR)
|
||||
debug_print ("LR:\t");
|
||||
ns_print ("LR:\t");
|
||||
else if (r == GPR_SP)
|
||||
debug_print ("SP:\t");
|
||||
ns_print ("SP:\t");
|
||||
else
|
||||
debug_print ("X%d:\t", r);
|
||||
debug_print ("0x%016lx%c", X(r), cnt % 3 == 0 ? '\n' : '\t');
|
||||
ns_print ("X%d:\t", r);
|
||||
ns_print ("0x%016lx%c", X(r), cnt % 3 == 0 ? '\n' : '\t');
|
||||
cnt++;
|
||||
}
|
||||
debug_print ("PC:\t0x%016lx\n", PC);
|
||||
debug_print ("NZCV:\t0x%016lx\n", NZCV);
|
||||
ns_print ("PC:\t0x%016lx\n", PC);
|
||||
ns_print ("NZCV:\t0x%016lx\n", NZCV);
|
||||
}
|
||||
|
||||
static uint64_t counter;
|
||||
|
|
2
Cpu.cpp
2
Cpu.cpp
|
@ -29,7 +29,7 @@ State GetState() {
|
|||
}
|
||||
|
||||
void DumpMachine() {
|
||||
ARMv8::Dump ();
|
||||
//ARMv8::Dump ();
|
||||
if (TraceOut)
|
||||
ARMv8::DumpJson (TraceOut);
|
||||
}
|
||||
|
|
19
Main.cpp
19
Main.cpp
|
@ -1,5 +1,6 @@
|
|||
/* nsemu - LGPL - Copyright 2017 rkx1209<rkx1209dev@gmail.com> */
|
||||
#include "Nsemu.hpp"
|
||||
#include <csignal>
|
||||
#include "optionparser.h"
|
||||
using namespace std;
|
||||
struct Arg : public option::Arg {
|
||||
|
@ -88,6 +89,14 @@ const option::Descriptor usage[] =
|
|||
{ 0, 0, nullptr, nullptr, nullptr, nullptr }
|
||||
};
|
||||
|
||||
static void SignalHandler(int sig, siginfo_t* sig_info, void* sig_data) {
|
||||
if(sig == SIGSEGV) {
|
||||
ns_print ("SEGV: %p\n", sig_info->si_addr );
|
||||
ARMv8::Dump();
|
||||
_Exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
Nsemu::create ();
|
||||
Nsemu *nsemu = Nsemu::get_instance ();
|
||||
|
@ -141,6 +150,16 @@ printUsage:
|
|||
goto printUsage;
|
||||
}
|
||||
}
|
||||
/* ### Register SEGV handler for debugging ### */
|
||||
struct sigaction segv_act;
|
||||
sigemptyset(&segv_act.sa_mask);
|
||||
sigaddset(&segv_act.sa_mask, SIGSEGV);
|
||||
segv_act.sa_sigaction = SignalHandler;
|
||||
segv_act.sa_flags = SA_SIGINFO|SA_RESTART|SA_ONSTACK;
|
||||
if( sigaction( SIGSEGV, &segv_act, NULL ) == -1 ){
|
||||
ns_abort ("Failed to set my signal handler.\n");
|
||||
}
|
||||
|
||||
Banner ();
|
||||
nsemu->BootUp (parse.nonOption (0));
|
||||
Nsemu::destroy ();
|
||||
|
|
Loading…
Reference in a new issue