Quentin Forcioli has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/63534?usp=email )

Change subject: base,sim,ext: Adding GDB signals definition
......................................................................

base,sim,ext: Adding GDB signals definition

GDB proposes a signal definition that is not necessarily identical
to the kernel's. To not lost GDB, we need to add this definition
 (in ext/remotegdb/signals.hh) and replace the linux signals everywhere
where they where used to interact with GDB.
 (otherwise it doesn't recognize some trap reasons).

Change-Id: I2bbfee36313cc766549000cf197c23c2561ea5f9
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/63534
Reviewed-by: Jason Lowe-Power <[email protected]>
Maintainer: Andreas Sandberg <[email protected]>
Reviewed-by: Andreas Sandberg <[email protected]>
Maintainer: Jason Lowe-Power <[email protected]>
Reviewed-by: Quentin Forcioli <[email protected]>
Tested-by: kokoro <[email protected]>
---
A ext/gdbremote/signals.hh
M src/arch/power/faults.cc
M src/base/remote_gdb.cc
M src/base/remote_gdb.hh
M src/sim/faults.cc
M src/sim/system.cc
M src/sim/system.hh
M src/sim/workload.cc
M src/sim/workload.hh
9 files changed, 242 insertions(+), 36 deletions(-)

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




diff --git a/ext/gdbremote/signals.hh b/ext/gdbremote/signals.hh
new file mode 100644
index 0000000..11835e6
--- /dev/null
+++ b/ext/gdbremote/signals.hh
@@ -0,0 +1,181 @@
+//===-- Generated From GDBRemoteSignals.cpp ------------------------===//
+//
+// Part of the LLVM Project,
+// under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===---------------------------------------------------------------===//
+
+#include <stdint.h>
+
+#ifndef __BASE_GDB_SIGNALS_HH__
+#define __BASE_GDB_SIGNALS_HH__
+
+/*
+These signals definitions are produced from LLVM's
+  lldb/source/Plugins/Process/Utility/GDBRemoteSignals.cpp
+*/
+namespace gem5{
+  enum class GDBSignal : uint8_t
+  {
+    ZERO = 0, //Signal 0
+    HUP = 1, //hangup
+    INT = 2, //interrupt
+    QUIT = 3, //quit
+    ILL = 4, //illegal instruction
+    TRAP = 5, //trace trap (not reset when caught)
+    ABRT = 6, //SIGIOT
+    EMT = 7, //emulation trap
+    FPE = 8, //floating point exception
+    KILL = 9, //kill
+    BUS = 10, //bus error
+    SEGV = 11, //segmentation violation
+    SYS = 12, //invalid system call
+    PIPE = 13, //write to pipe with reading end closed
+    ALRM = 14, //alarm
+    TERM = 15, //termination requested
+    URG = 16, //urgent data on socket
+    STOP = 17, //process stop
+    TSTP = 18, //tty stop
+    CONT = 19, //process continue
+    CHLD = 20, //SIGCLD
+    TTIN = 21, //background tty read
+    TTOU = 22, //background tty write
+    IO = 23, //input/output ready/Pollable event
+    XCPU = 24, //CPU resource exceeded
+    XFSZ = 25, //file size limit exceeded
+    VTALRM = 26, //virtual time alarm
+    PROF = 27, //profiling time alarm
+    WINCH = 28, //window size changes
+    LOST = 29, //resource lost
+    USR1 = 30, //user defined signal 1
+    USR2 = 31, //user defined signal 2
+    PWR = 32, //power failure
+    POLL = 33, //pollable event
+    WIND = 34, //SIGWIND
+    PHONE = 35, //SIGPHONE
+    WAITING = 36, //process's LWPs are blocked
+    LWP = 37, //signal LWP
+    DANGER = 38, //swap space dangerously low
+    GRANT = 39, //monitor mode granted
+    RETRACT = 40, //need to relinquish monitor mode
+    MSG = 41, //monitor mode data available
+    SOUND = 42, //sound completed
+    SAK = 43, //secure attention
+    PRIO = 44, //SIGPRIO
+
+    SIG33 = 45, //real-time event 33
+    SIG34 = 46, //real-time event 34
+    SIG35 = 47, //real-time event 35
+    SIG36 = 48, //real-time event 36
+    SIG37 = 49, //real-time event 37
+    SIG38 = 50, //real-time event 38
+    SIG39 = 51, //real-time event 39
+    SIG40 = 52, //real-time event 40
+    SIG41 = 53, //real-time event 41
+    SIG42 = 54, //real-time event 42
+    SIG43 = 55, //real-time event 43
+    SIG44 = 56, //real-time event 44
+    SIG45 = 57, //real-time event 45
+    SIG46 = 58, //real-time event 46
+    SIG47 = 59, //real-time event 47
+    SIG48 = 60, //real-time event 48
+    SIG49 = 61, //real-time event 49
+    SIG50 = 62, //real-time event 50
+    SIG51 = 63, //real-time event 51
+    SIG52 = 64, //real-time event 52
+    SIG53 = 65, //real-time event 53
+    SIG54 = 66, //real-time event 54
+    SIG55 = 67, //real-time event 55
+    SIG56 = 68, //real-time event 56
+    SIG57 = 69, //real-time event 57
+    SIG58 = 70, //real-time event 58
+    SIG59 = 71, //real-time event 59
+    SIG60 = 72, //real-time event 60
+    SIG61 = 73, //real-time event 61
+    SIG62 = 74, //real-time event 62
+    SIG63 = 75, //real-time event 63
+
+    CANCEL = 76, //LWP internal signal
+
+    SIG32 = 77, //real-time event 32
+    SIG64 = 78, //real-time event 64
+    SIG65 = 79, //real-time event 65
+    SIG66 = 80, //real-time event 66
+    SIG67 = 81, //real-time event 67
+    SIG68 = 82, //real-time event 68
+    SIG69 = 83, //real-time event 69
+    SIG70 = 84, //real-time event 70
+    SIG71 = 85, //real-time event 71
+    SIG72 = 86, //real-time event 72
+    SIG73 = 87, //real-time event 73
+    SIG74 = 88, //real-time event 74
+    SIG75 = 89, //real-time event 75
+    SIG76 = 90, //real-time event 76
+    SIG77 = 91, //real-time event 77
+    SIG78 = 92, //real-time event 78
+    SIG79 = 93, //real-time event 79
+    SIG80 = 94, //real-time event 80
+    SIG81 = 95, //real-time event 81
+    SIG82 = 96, //real-time event 82
+    SIG83 = 97, //real-time event 83
+    SIG84 = 98, //real-time event 84
+    SIG85 = 99, //real-time event 85
+    SIG86 = 100, //real-time event 86
+    SIG87 = 101, //real-time event 87
+    SIG88 = 102, //real-time event 88
+    SIG89 = 103, //real-time event 89
+    SIG90 = 104, //real-time event 90
+    SIG91 = 105, //real-time event 91
+    SIG92 = 106, //real-time event 92
+    SIG93 = 107, //real-time event 93
+    SIG94 = 108, //real-time event 94
+    SIG95 = 109, //real-time event 95
+    SIG96 = 110, //real-time event 96
+    SIG97 = 111, //real-time event 97
+    SIG98 = 112, //real-time event 98
+    SIG99 = 113, //real-time event 99
+    SIG100 = 114, //real-time event 100
+    SIG101 = 115, //real-time event 101
+    SIG102 = 116, //real-time event 102
+    SIG103 = 117, //real-time event 103
+    SIG104 = 118, //real-time event 104
+    SIG105 = 119, //real-time event 105
+    SIG106 = 120, //real-time event 106
+    SIG107 = 121, //real-time event 107
+    SIG108 = 122, //real-time event 108
+    SIG109 = 123, //real-time event 109
+    SIG110 = 124, //real-time event 110
+    SIG111 = 125, //real-time event 111
+    SIG112 = 126, //real-time event 112
+    SIG113 = 127, //real-time event 113
+    SIG114 = 128, //real-time event 114
+    SIG115 = 129, //real-time event 115
+    SIG116 = 130, //real-time event 116
+    SIG117 = 131, //real-time event 117
+    SIG118 = 132, //real-time event 118
+    SIG119 = 133, //real-time event 119
+    SIG120 = 134, //real-time event 120
+    SIG121 = 135, //real-time event 121
+    SIG122 = 136, //real-time event 122
+    SIG123 = 137, //real-time event 123
+    SIG124 = 138, //real-time event 124
+    SIG125 = 139, //real-time event 125
+    SIG126 = 140, //real-time event 126
+    SIG127 = 141, //real-time event 127
+
+    INFO = 142, //information request
+    unknown = 143, //unknown signal
+
+    EXC_BAD_ACCESS = 145, //could not access memory
+    EXC_BAD_INSTRUCTION = 146, //illegal instruction/operand
+    EXC_ARITHMETIC = 147, //arithmetic exception
+    EXC_EMULATION = 148, //emulation instruction
+    EXC_SOFTWARE = 149, //software generated exception
+    EXC_BREAKPOINT = 150, //breakpoint
+
+    LIBRT = 151, //librt internal signal
+  };
+}
+#endif /* __BASE_GDB_SIGNALS_HH__ */
diff --git a/src/arch/power/faults.cc b/src/arch/power/faults.cc
index be1796e..0d8f2dd 100644
--- a/src/arch/power/faults.cc
+++ b/src/arch/power/faults.cc
@@ -42,7 +42,7 @@
 void
UnimplementedOpcodeFault::invoke(ThreadContext *tc, const StaticInstPtr &inst)
 {
-    panic_if(tc->getSystemPtr()->trapToGdb(SIGILL, tc->contextId()),
+ panic_if(tc->getSystemPtr()->trapToGdb(GDBSignal::ILL, tc->contextId()),
              "Unimplemented opcode encountered at virtual address %#x\n",
              tc->pcState().instAddr());
 }
@@ -50,14 +50,14 @@
 void
 AlignmentFault::invoke(ThreadContext *tc, const StaticInstPtr &inst)
 {
-    panic_if(!tc->getSystemPtr()->trapToGdb(SIGBUS, tc->contextId()),
+ panic_if(!tc->getSystemPtr()->trapToGdb(GDBSignal::BUS, tc->contextId()), "Alignment fault when accessing virtual address %#x\n", vaddr);
 }

 void
 TrapFault::invoke(ThreadContext *tc, const StaticInstPtr &inst)
 {
-    panic_if(tc->getSystemPtr()->trapToGdb(SIGTRAP, tc->contextId()),
+ panic_if(tc->getSystemPtr()->trapToGdb(GDBSignal::TRAP, tc->contextId()),
              "Trap encountered at virtual address %#x\n",
              tc->pcState().instAddr());
 }
diff --git a/src/base/remote_gdb.cc b/src/base/remote_gdb.cc
index c19dede..47fae75 100644
--- a/src/base/remote_gdb.cc
+++ b/src/base/remote_gdb.cc
@@ -130,7 +130,6 @@
 #include "base/remote_gdb.hh"

 #include <sys/select.h>
-#include <sys/signal.h>
 #include <sys/time.h>
 #include <unistd.h>

@@ -192,7 +191,7 @@
         DPRINTF(GDBMisc, "handling hardware breakpoint at %#x\n", pc());

         if (tc == gdb->tc)
-            gdb->trap(tc->contextId(), SIGTRAP,"");
+            gdb->trap(tc->contextId(), GDBSignal::TRAP,"");
     }
 };

@@ -549,7 +548,7 @@
 // makes sense to use POSIX errno values, because that is what the
 // gdb/remote.c functions want to return.
 void
-BaseRemoteGDB::trap(ContextID id, int signum,const std::string& stopReason)
+BaseRemoteGDB::trap(ContextID id, GDBSignal sig,const std::string& stopReason)
 {
     if (!attached)
         return;
@@ -575,10 +574,10 @@
         send("OK");
     } else {
         // Tell remote host that an exception has occurred.
-        sendTPacket(signum,id,stopReason);
+        sendTPacket(sig,id,stopReason);
     }

-    processCommands(signum);
+    processCommands(sig);
 }

 bool
@@ -613,7 +612,7 @@
     }

     if (revent & POLLIN) {
-        scheduleTrapEvent(tc->contextId(),SIGILL,0,"");
+        scheduleTrapEvent(tc->contextId(),GDBSignal::ILL,0,"");
     } else if (revent & POLLNVAL) {
         descheduleInstCommitEvent(&trapEvent);
         scheduleInstCommitEvent(&disconnectEvent, 0);
@@ -766,14 +765,14 @@
 }

 void
-BaseRemoteGDB::processCommands(int signum)
+BaseRemoteGDB::processCommands(GDBSignal sig)
 {
     // Stick frame regs into our reg cache.
     regCachePtr = gdbRegs();
     regCachePtr->getRegs(tc);

     GdbCommand::Context cmd_ctx;
-    cmd_ctx.type = signum;
+    cmd_ctx.type = sig;
     std::vector<char> data;

     for (;;) {
@@ -882,7 +881,7 @@
 {
     if (!singleStepEvent.scheduled())
         scheduleInstCommitEvent(&singleStepEvent, 1);
-    trap(tc->contextId(), SIGTRAP);
+    trap(tc->contextId(), GDBSignal::TRAP);
 }

 void
@@ -951,18 +950,20 @@
 }

 void
-BaseRemoteGDB::sendTPacket(int errnum, ContextID id,
+BaseRemoteGDB::sendTPacket(GDBSignal sig, ContextID id,
     const std::string& stopReason)
 {
     if (!stopReason.empty()){
-        send("T%02xcore:%x;thread:%x;%s;",errnum,id + 1,id + 1,stopReason);
+        send("T%02xcore:%x;thread:%x;%s;",
+            (uint8_t)sig,id + 1,id + 1,stopReason);
     }else{
-        send("T%02xcore:%x;thread:%x;",errnum,id + 1,id + 1);
+        send("T%02xcore:%x;thread:%x;",
+            (uint8_t)sig,id + 1,id + 1);
     }
 }
 void
-BaseRemoteGDB::sendSPacket(int errnum){
-       send("S%02x",errnum);
+BaseRemoteGDB::sendSPacket(GDBSignal sig){
+       send("S%02x",(uint8_t)sig);
 }
 void
 BaseRemoteGDB::sendOPacket(const std::string message){
@@ -970,12 +971,12 @@
 }

 void
-BaseRemoteGDB::scheduleTrapEvent(ContextID id,int type,int delta,
+BaseRemoteGDB::scheduleTrapEvent(ContextID id,GDBSignal sig,int delta,
     std::string stopReason){
     ThreadContext* _tc = threads[id];
     panic_if(_tc == nullptr, "Unknown context id :%i",id);
     trapEvent.id(id);
-    trapEvent.type(type);
+    trapEvent.type(sig);
     trapEvent.stopReason(stopReason);
     if (!trapEvent.scheduled())
         scheduleInstCommitEvent(&trapEvent,delta,_tc);
@@ -1171,7 +1172,7 @@
                 throw CmdError("E04");
             // Line up on an instruction boundary in the new thread.
             threadSwitching = true;
-            scheduleTrapEvent(tid,0,0,"");
+            scheduleTrapEvent(tid,GDBSignal::ZERO,0,"");
             return false;
         }
     } else {
diff --git a/src/base/remote_gdb.hh b/src/base/remote_gdb.hh
index 4da1dcc..c23b4ac 100644
--- a/src/base/remote_gdb.hh
+++ b/src/base/remote_gdb.hh
@@ -42,7 +42,6 @@
 #ifndef __REMOTE_GDB_HH__
 #define __REMOTE_GDB_HH__

-#include <sys/signal.h>

 #include <cstdint>
 #include <exception>
@@ -56,6 +55,7 @@
 #include "base/socket.hh"
 #include "base/types.hh"
 #include "cpu/pc_event.hh"
+#include "gdbremote/signals.hh"
 #include "sim/debug.hh"
 #include "sim/eventq.hh"

@@ -171,10 +171,10 @@
     void replaceThreadContext(ThreadContext *_tc);
     bool selectThreadContext(ContextID id);

-    void trap(ContextID id, int signum,const std::string& stopReason="");
+ void trap(ContextID id, GDBSignal sig,const std::string& stopReason="");
     bool sendMessage(std::string message);
     //schedule a trap event with these properties
-    void scheduleTrapEvent(ContextID id,int type, int delta,
+    void scheduleTrapEvent(ContextID id,GDBSignal type, int delta,
       std::string stopReason);
     /** @} */ // end of api_remote_gdb

@@ -259,7 +259,7 @@
      * or SW trap), 'signum' is the signal value reported back to GDB
      * in "S" packet (this is done in trap()).
      */
-    void processCommands(int signum=0);
+    void processCommands(GDBSignal sig=GDBSignal::ZERO);

     /*
      * Simulator side debugger state.
@@ -280,7 +280,7 @@
     class TrapEvent : public Event
     {
       protected:
-        int _type;
+        GDBSignal _type;
         ContextID _id;
         std::string _stopReason;
         BaseRemoteGDB *gdb;
@@ -289,7 +289,7 @@
         TrapEvent(BaseRemoteGDB *g) : gdb(g)
         {}

-        void type(int t) { _type = t; }
+        void type(GDBSignal t) { _type = t; }
         void stopReason(std::string s) {_stopReason = s; }
         void id(ContextID id) { _id = id; }
          void process() { gdb->trap(_id, _type,_stopReason); }
@@ -327,8 +327,9 @@
     void insertHardBreak(Addr addr, size_t kind);
     void removeHardBreak(Addr addr, size_t kind);

- void sendTPacket(int errnum, ContextID id,const std::string& stopReason);
-    void sendSPacket(int errnum);
+    void sendTPacket(GDBSignal sig, ContextID id,
+      const std::string& stopReason);
+    void sendSPacket(GDBSignal sig);
     //The OPacket allow to send string to be displayed by the remote GDB
     void sendOPacket(const std::string message);
     /*
@@ -341,7 +342,7 @@
         {
             const GdbCommand *cmd;
             char cmdByte;
-            int type;
+            GDBSignal type;
             char *data;
             int len;
         };
@@ -363,7 +364,7 @@
         {
             const GdbMultiLetterCommand *cmd;
             std::string cmdTxt;
-            int type;
+            GDBSignal type;
             char *data;
             int len;
         };
diff --git a/src/sim/faults.cc b/src/sim/faults.cc
index c0a7d76..3049b3b 100644
--- a/src/sim/faults.cc
+++ b/src/sim/faults.cc
@@ -100,14 +100,14 @@
         handled = p->fixupFault(vaddr);
     }
     panic_if(!handled &&
-                 !tc->getSystemPtr()->trapToGdb(SIGSEGV, tc->contextId()),
+ !tc->getSystemPtr()->trapToGdb(GDBSignal::SEGV, tc->contextId()), "Page table fault when accessing virtual address %#x\n", vaddr);
 }

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

diff --git a/src/sim/system.cc b/src/sim/system.cc
index 5f67c4d..ee6c70a 100644
--- a/src/sim/system.cc
+++ b/src/sim/system.cc
@@ -391,7 +391,7 @@
 }

 bool
-System::trapToGdb(int signal, ContextID ctx_id) const
+System::trapToGdb(GDBSignal signal, ContextID ctx_id) const
 {
     return workload->trapToGdb(signal, ctx_id);
 }
diff --git a/src/sim/system.hh b/src/sim/system.hh
index 7738d56..d691fb8 100644
--- a/src/sim/system.hh
+++ b/src/sim/system.hh
@@ -554,7 +554,7 @@
     void workItemEnd(uint32_t tid, uint32_t workid);

     /* Returns whether we successfully trapped into GDB. */
-    bool trapToGdb(int signal, ContextID ctx_id) const;
+    bool trapToGdb(GDBSignal signal, ContextID ctx_id) const;

   protected:
     /**
diff --git a/src/sim/workload.cc b/src/sim/workload.cc
index ca51bbd..ceb1029 100644
--- a/src/sim/workload.cc
+++ b/src/sim/workload.cc
@@ -72,7 +72,7 @@
 }

 bool
-Workload::trapToGdb(int signal, ContextID ctx_id)
+Workload::trapToGdb(GDBSignal signal, ContextID ctx_id)
 {
     if (gdb && gdb->isAttached()) {
         gdb->trap(ctx_id, signal);
diff --git a/src/sim/workload.hh b/src/sim/workload.hh
index f9bb8db..1012937 100644
--- a/src/sim/workload.hh
+++ b/src/sim/workload.hh
@@ -34,6 +34,7 @@
 #include "base/loader/object_file.hh"
 #include "base/loader/symtab.hh"
 #include "enums/ByteOrder.hh"
+#include "gdbremote/signals.hh"
 #include "params/StubWorkload.hh"
 #include "params/Workload.hh"
 #include "sim/sim_object.hh"
@@ -91,7 +92,7 @@

// Once trapping into GDB is no longer a special case routed through the
     // system object, this helper can be removed.
-    bool trapToGdb(int signal, ContextID ctx_id);
+    bool trapToGdb(GDBSignal sig, ContextID ctx_id);
     bool sendToGdb(std::string msg);

     virtual void registerThreadContext(ThreadContext *tc);

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/63534?usp=email 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: I2bbfee36313cc766549000cf197c23c2561ea5f9
Gerrit-Change-Number: 63534
Gerrit-PatchSet: 13
Gerrit-Owner: Quentin Forcioli <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Bobby Bruce <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Quentin Forcioli <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to