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