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 <power.jg@gmail.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Reviewed-by: Quentin Forcioli <quentin.forcioli@telecom-paris.fr>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Quentin Forcioli
2022-08-18 12:26:12 +02:00
parent da12e96507
commit 7230a3e7f0
9 changed files with 220 additions and 36 deletions

181
ext/gdbremote/signals.hh Normal file
View File

@@ -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__ */

View File

@@ -42,7 +42,7 @@ namespace PowerISA
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 @@ UnimplementedOpcodeFault::invoke(ThreadContext *tc, const StaticInstPtr &inst)
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());
}

View File

@@ -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 @@ class HardBreakpoint : public PCEvent
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 @@ BaseRemoteGDB::selectThreadContext(ContextID id)
// 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 @@ BaseRemoteGDB::trap(ContextID id, int signum,const std::string& stopReason)
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 @@ BaseRemoteGDB::incomingData(int revent)
}
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 @@ BaseRemoteGDB::send(const char *bp)
}
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 @@ BaseRemoteGDB::singleStep()
{
if (!singleStepEvent.scheduled())
scheduleInstCommitEvent(&singleStepEvent, 1);
trap(tc->contextId(), SIGTRAP);
trap(tc->contextId(), GDBSignal::TRAP);
}
void
@@ -951,18 +950,20 @@ BaseRemoteGDB::removeHardBreak(Addr addr, size_t kind)
}
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 @@ BaseRemoteGDB::sendOPacket(const std::string message){
}
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 @@ BaseRemoteGDB::cmdSetThread(GdbCommand::Context &ctx)
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 {

View File

@@ -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 @@ class BaseRemoteGDB
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 @@ class BaseRemoteGDB
* 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 BaseRemoteGDB
class TrapEvent : public Event
{
protected:
int _type;
GDBSignal _type;
ContextID _id;
std::string _stopReason;
BaseRemoteGDB *gdb;
@@ -289,7 +289,7 @@ class BaseRemoteGDB
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 @@ class BaseRemoteGDB
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 @@ class BaseRemoteGDB
{
const GdbCommand *cmd;
char cmdByte;
int type;
GDBSignal type;
char *data;
int len;
};
@@ -363,7 +364,7 @@ class BaseRemoteGDB
{
const GdbMultiLetterCommand *cmd;
std::string cmdTxt;
int type;
GDBSignal type;
char *data;
int len;
};

View File

@@ -100,14 +100,14 @@ GenericPageTableFault::invoke(ThreadContext *tc, const StaticInstPtr &inst)
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);
}

View File

@@ -391,7 +391,7 @@ System::workItemEnd(uint32_t tid, uint32_t workid)
}
bool
System::trapToGdb(int signal, ContextID ctx_id) const
System::trapToGdb(GDBSignal signal, ContextID ctx_id) const
{
return workload->trapToGdb(signal, ctx_id);
}

View File

@@ -554,7 +554,7 @@ class System : public SimObject, public PCEventScope
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:
/**

View File

@@ -72,7 +72,7 @@ Workload::replaceThreadContext(ThreadContext *tc)
}
bool
Workload::trapToGdb(int signal, ContextID ctx_id)
Workload::trapToGdb(GDBSignal signal, ContextID ctx_id)
{
if (gdb && gdb->isAttached()) {
gdb->trap(ctx_id, signal);

View File

@@ -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 @@ class Workload : public SimObject
// 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);