Commit e3c2236c authored by hjk's avatar hjk
Browse files

Debugger: Remove guessing of register size



GDB does not report register sizes using the MI protocol, so sizes were
infered from the register name. This is fragile, better use
"maintenance print raw-registers" which reports the sizes and even
if not part of the official interface, is unlikely to change.

Change-Id: If7c7182751a496084a351aaef3a97dcdac6c500b
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
parent 2ad602bb
......@@ -3557,7 +3557,9 @@ void GdbEngine::reloadRegisters()
if (true) {
if (!m_registerNamesListed) {
postCommand("-data-list-register-names", NoFlags, CB(handleRegisterListNames));
// The MI version does not give register size.
// postCommand("-data-list-register-names", NoFlags, CB(handleRegisterListNames));
postCommand("maintenance print raw-registers", NoFlags, CB(handleRegisterListing));
m_registerNamesListed = true;
}
// Can cause i386-linux-nat.c:571: internal-error: Got request
......@@ -3638,15 +3640,47 @@ void GdbEngine::handleRegisterListNames(const DebuggerResponse &response)
}
GdbMi names = response.data["register-names"];
m_registerNames.clear();
m_registers.clear();
int gdbRegisterNumber = 0;
foreach (const GdbMi &item, names.children()) {
if (!item.data().isEmpty())
m_registerNames[gdbRegisterNumber] = item.data();
if (!item.data().isEmpty()) {
Register reg;
reg.name = item.data();
m_registers[gdbRegisterNumber] = reg;
}
++gdbRegisterNumber;
}
}
void GdbEngine::handleRegisterListing(const DebuggerResponse &response)
{
if (response.resultClass != ResultDone) {
m_registerNamesListed = false;
return;
}
// &"maintenance print raw-registers\n"
// >~" Name Nr Rel Offset Size Type Raw value\n"
// >~" rax 0 0 0 8 int64_t 0x0000000000000005\n"
// >~" rip 16 16 128 8 *1 0x000000000040232a\n"
// >~" '' 145 145 536 0 int0_t <invalid>\n"
m_registers.clear();
QList<QByteArray> lines = response.consoleStreamOutput.split('\n');
for (int i = 1; i < lines.size(); ++i) {
QStringList parts = QString::fromLatin1(lines.at(i))
.split(QLatin1Char(' '), QString::SkipEmptyParts);
if (parts.size() < 7)
continue;
int gdbRegisterNumber = parts.at(1).toInt();
Register reg;
reg.name = parts.at(0).toLatin1();
reg.size = parts.at(4).toInt();
reg.reportedType = parts.at(5).toLatin1();
m_registers[gdbRegisterNumber] = reg;
}
}
void GdbEngine::handleRegisterListValues(const DebuggerResponse &response)
{
if (response.resultClass != ResultDone)
......@@ -3656,9 +3690,8 @@ void GdbEngine::handleRegisterListValues(const DebuggerResponse &response)
// 24^done,register-values=[{number="0",value="0xf423f"},...]
const GdbMi values = response.data["register-values"];
foreach (const GdbMi &item, values.children()) {
Register reg;
const int number = item["number"].toInt();
reg.name = m_registerNames[number];
Register reg = m_registers[number];
QByteArray data = item["value"].data();
if (data.startsWith("0x")) {
reg.value = data;
......
......@@ -34,6 +34,7 @@
#include <debugger/debuggerengine.h>
#include <debugger/breakhandler.h>
#include <debugger/registerhandler.h>
#include <debugger/watchhandler.h>
#include <debugger/watchutils.h>
#include <debugger/debuggertooltipmanager.h>
......@@ -327,9 +328,10 @@ private: ////////// View & Data Stuff //////////
Q_SLOT void reloadRegisters();
void setRegisterValue(const QByteArray &name, const QString &value);
void handleRegisterListNames(const DebuggerResponse &response);
void handleRegisterListing(const DebuggerResponse &response);
void handleRegisterListValues(const DebuggerResponse &response);
void handleMaintPrintRegisters(const DebuggerResponse &response);
QHash<int, QByteArray> m_registerNames; // Map GDB register numbers to indices
QHash<int, Register> m_registers; // Map GDB register numbers to indices
//
// Disassembler specific stuff
......
......@@ -42,214 +42,22 @@ namespace Internal {
//
//////////////////////////////////////////////////////////////////
static struct RegisterNameAndType
{
const char *name;
RegisterKind kind;
int size;
} theNameAndType[] = {
// ARM
{ "r0", IntegerRegister, 4 },
{ "r1", IntegerRegister, 4 },
{ "r2", IntegerRegister, 4 },
{ "r3", IntegerRegister, 4 },
{ "r4", IntegerRegister, 4 },
{ "r5", IntegerRegister, 4 },
{ "r6", IntegerRegister, 4 },
{ "r7", IntegerRegister, 4 },
{ "r8", IntegerRegister, 4 },
{ "r9", IntegerRegister, 4 },
{ "r10", IntegerRegister, 4 },
{ "r11", IntegerRegister, 4 },
{ "r12", IntegerRegister, 4 },
{ "sp", IntegerRegister, 4 },
{ "lr", IntegerRegister, 4 },
{ "pc", IntegerRegister, 4 },
{ "cpsr", FlagRegister, 4 },
{ "d0", IntegerRegister, 8 },
{ "d1", IntegerRegister, 8 },
{ "d2", IntegerRegister, 8 },
{ "d3", IntegerRegister, 8 },
{ "d4", IntegerRegister, 8 },
{ "d5", IntegerRegister, 8 },
{ "d6", IntegerRegister, 8 },
{ "d7", IntegerRegister, 8 },
{ "d8", IntegerRegister, 8 },
{ "d9", IntegerRegister, 8 },
{ "d10", IntegerRegister, 8 },
{ "d11", IntegerRegister, 8 },
{ "d12", IntegerRegister, 8 },
{ "d13", IntegerRegister, 8 },
{ "d14", IntegerRegister, 8 },
{ "d15", IntegerRegister, 8 },
{ "d16", IntegerRegister, 8 },
{ "d17", IntegerRegister, 8 },
{ "d18", IntegerRegister, 8 },
{ "d19", IntegerRegister, 8 },
{ "d20", IntegerRegister, 8 },
{ "d21", IntegerRegister, 8 },
{ "d22", IntegerRegister, 8 },
{ "d23", IntegerRegister, 8 },
{ "d24", IntegerRegister, 8 },
{ "d25", IntegerRegister, 8 },
{ "d26", IntegerRegister, 8 },
{ "d27", IntegerRegister, 8 },
{ "d28", IntegerRegister, 8 },
{ "d29", IntegerRegister, 8 },
{ "d30", IntegerRegister, 8 },
{ "d31", IntegerRegister, 8 },
{ "fpscr", FlagRegister, 4 },
{ "s0", IntegerRegister, 4 },
{ "s1", IntegerRegister, 4 },
{ "s2", IntegerRegister, 4 },
{ "s3", IntegerRegister, 4 },
{ "s4", IntegerRegister, 4 },
{ "s5", IntegerRegister, 4 },
{ "s6", IntegerRegister, 4 },
{ "s7", IntegerRegister, 4 },
{ "s8", IntegerRegister, 4 },
{ "s9", IntegerRegister, 4 },
{ "s10", IntegerRegister, 4 },
{ "s11", IntegerRegister, 4 },
{ "s12", IntegerRegister, 4 },
{ "s13", IntegerRegister, 4 },
{ "s14", IntegerRegister, 4 },
{ "s15", IntegerRegister, 4 },
{ "s16", IntegerRegister, 4 },
{ "s17", IntegerRegister, 4 },
{ "s18", IntegerRegister, 4 },
{ "s19", IntegerRegister, 4 },
{ "s20", IntegerRegister, 4 },
{ "s21", IntegerRegister, 4 },
{ "s22", IntegerRegister, 4 },
{ "s23", IntegerRegister, 4 },
{ "s24", IntegerRegister, 4 },
{ "s25", IntegerRegister, 4 },
{ "s26", IntegerRegister, 4 },
{ "s27", IntegerRegister, 4 },
{ "s28", IntegerRegister, 4 },
{ "s29", IntegerRegister, 4 },
{ "s30", IntegerRegister, 4 },
{ "s31", IntegerRegister, 4 },
{ "q0", IntegerRegister, 16 },
{ "q1", IntegerRegister, 16 },
{ "q2", IntegerRegister, 16 },
{ "q3", IntegerRegister, 16 },
{ "q4", IntegerRegister, 16 },
{ "q5", IntegerRegister, 16 },
{ "q6", IntegerRegister, 16 },
{ "q7", IntegerRegister, 16 },
{ "q8", IntegerRegister, 16 },
{ "q9", IntegerRegister, 16 },
{ "q10", IntegerRegister, 16 },
{ "q11", IntegerRegister, 16 },
{ "q12", IntegerRegister, 16 },
{ "q13", IntegerRegister, 16 },
{ "q14", IntegerRegister, 16 },
{ "q15", IntegerRegister, 16 },
// Intel
{ "eax", IntegerRegister, 4 },
{ "ecx", IntegerRegister, 4 },
{ "edx", IntegerRegister, 4 },
{ "ebx", IntegerRegister, 4 },
{ "esp", IntegerRegister, 4 },
{ "ebp", IntegerRegister, 4 },
{ "esi", IntegerRegister, 4 },
{ "edi", IntegerRegister, 4 },
{ "eip", IntegerRegister, 4 },
{ "rax", IntegerRegister, 8 },
{ "rcx", IntegerRegister, 8 },
{ "rdx", IntegerRegister, 8 },
{ "rbx", IntegerRegister, 8 },
{ "rsp", IntegerRegister, 8 },
{ "rbp", IntegerRegister, 8 },
{ "rsi", IntegerRegister, 8 },
{ "rdi", IntegerRegister, 8 },
{ "rip", IntegerRegister, 8 },
{ "eflags", FlagRegister, 4 },
{ "cs", IntegerRegister, 2 },
{ "ss", IntegerRegister, 2 },
{ "ds", IntegerRegister, 2 },
{ "es", IntegerRegister, 2 },
{ "fs", IntegerRegister, 2 },
{ "gs", IntegerRegister, 2 },
{ "st0", FloatRegister, 10 },
{ "st1", FloatRegister, 10 },
{ "st2", FloatRegister, 10 },
{ "st3", FloatRegister, 10 },
{ "st4", FloatRegister, 10 },
{ "st5", FloatRegister, 10 },
{ "st6", FloatRegister, 10 },
{ "st7", FloatRegister, 10 },
{ "fctrl", FlagRegister, 4 },
{ "fstat", FlagRegister, 4 },
{ "ftag", FlagRegister, 4 },
{ "fiseg", FlagRegister, 4 },
{ "fioff", FlagRegister, 4 },
{ "foseg", FlagRegister, 4 },
{ "fooff", FlagRegister, 4 },
{ "fop", FlagRegister, 4 },
{ "mxcsr", FlagRegister, 4 },
{ "orig_eax", IntegerRegister, 4 },
{ "al", IntegerRegister, 1 },
{ "cl", IntegerRegister, 1 },
{ "dl", IntegerRegister, 1 },
{ "bl", IntegerRegister, 1 },
{ "ah", IntegerRegister, 1 },
{ "ch", IntegerRegister, 1 },
{ "dh", IntegerRegister, 1 },
{ "bh", IntegerRegister, 1 },
{ "ax", IntegerRegister, 2 },
{ "cx", IntegerRegister, 2 },
{ "dx", IntegerRegister, 2 },
{ "bx", IntegerRegister, 2 },
{ "bp", IntegerRegister, 2 },
{ "si", IntegerRegister, 2 },
{ "di", IntegerRegister, 2 }
};
//////////////////////////////////////////////////////////////////
//
// RegisterValue
//
//////////////////////////////////////////////////////////////////
// FIXME: This should not really be needed. Instead the guessing, if any,
// should done by the engines.
static void fixup(Register *reg, RegisterKind kind, int size)
{
reg->kind = kind;
if (!reg->size)
reg->size = size;
}
void Register::guessMissingData()
{
if (name.startsWith("xmm")) {
fixup(this, VectorRegister, 16);
return;
}
for (int i = 0; i != sizeof(theNameAndType) / sizeof(theNameAndType[0]); ++i) {
if (theNameAndType[i].name == name) {
fixup(this, theNameAndType[i].kind, theNameAndType[i].size);
return;
}
}
if (reportedType == "int")
fixup(this, IntegerRegister, 4);
kind = IntegerRegister;
else if (reportedType == "float")
fixup(this, IntegerRegister, 8);
kind = FloatRegister;
else if (reportedType == "_i387_ext")
fixup(this, IntegerRegister, 10);
kind = FloatRegister;
else if (reportedType == "*1" || reportedType == "long")
fixup(this, IntegerRegister, 0);
kind = IntegerRegister;
else if (reportedType.contains("vec"))
fixup(this, VectorRegister, 0);
kind = VectorRegister;
else if (reportedType.startsWith("int"))
fixup(this, IntegerRegister, 0);
kind = IntegerRegister;
else if (name.startsWith("xmm") || name.startsWith("ymm"))
kind = VectorRegister;
}
static QString subTypeName(RegisterKind kind, int size, RegisterFormat format)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment