2020-05-04 12:14:39 +03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-05-04 12:14:39 +03:00
|
|
|
*/
|
2021-05-15 00:27:09 +01:00
|
|
|
|
2020-05-04 12:14:39 +03:00
|
|
|
#include "Expression.h"
|
2020-08-05 10:55:36 +02:00
|
|
|
|
2020-09-01 11:43:32 +02:00
|
|
|
#include <AK/MemoryStream.h>
|
2020-05-04 12:14:39 +03:00
|
|
|
#include <sys/arch/i386/regs.h>
|
|
|
|
|
|
2020-08-25 04:33:07 +01:00
|
|
|
namespace Debug::Dwarf::Expression {
|
2020-05-04 12:14:39 +03:00
|
|
|
|
2020-08-05 10:55:36 +02:00
|
|
|
Value evaluate(ReadonlyBytes bytes, const PtraceRegisters& regs)
|
2020-05-04 12:14:39 +03:00
|
|
|
{
|
2020-08-05 10:55:36 +02:00
|
|
|
InputMemoryStream stream(bytes);
|
2020-05-04 12:14:39 +03:00
|
|
|
|
2020-08-05 10:55:36 +02:00
|
|
|
while (!stream.eof()) {
|
2020-05-04 12:14:39 +03:00
|
|
|
u8 opcode = 0;
|
|
|
|
|
stream >> opcode;
|
|
|
|
|
|
|
|
|
|
switch (static_cast<Operations>(opcode)) {
|
|
|
|
|
case Operations::RegEbp: {
|
2020-05-23 15:27:33 +02:00
|
|
|
ssize_t offset = 0;
|
2020-05-04 12:14:39 +03:00
|
|
|
stream.read_LEB128_signed(offset);
|
|
|
|
|
return Value { Type::UnsignedIntetger, regs.ebp + offset };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case Operations::FbReg: {
|
2020-05-23 15:27:33 +02:00
|
|
|
ssize_t offset = 0;
|
2020-05-04 12:14:39 +03:00
|
|
|
stream.read_LEB128_signed(offset);
|
|
|
|
|
return Value { Type::UnsignedIntetger, regs.ebp + 2 * sizeof(size_t) + offset };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
2021-01-09 15:07:10 +01:00
|
|
|
dbgln("DWARF expr addr: {}", (const void*)bytes.data());
|
|
|
|
|
dbgln("unsupported opcode: {}", (u8)opcode);
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY_NOT_REACHED();
|
2020-05-04 12:14:39 +03:00
|
|
|
}
|
|
|
|
|
}
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY_NOT_REACHED();
|
2020-05-04 12:14:39 +03:00
|
|
|
}
|
|
|
|
|
|
2020-08-05 10:55:36 +02:00
|
|
|
}
|