1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 11:24:58 +00:00
serenity/Userland/Libraries/LibDebug/Dwarf/Expression.cpp
Ali Mohammad Pur 6d64b13a1b LibDebug+Everywhere: Avoid void* -> FlatPtr -> void* dance
And limit the `void*` to the functions that interface the system (i.e.
ptrace wrappers).
This generally makes the code less riddled with casts.
2022-01-28 22:51:27 +00:00

47 lines
1.1 KiB
C++

/*
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "Expression.h"
#include <AK/Format.h>
#include <AK/MemoryStream.h>
#include <sys/arch/i386/regs.h>
namespace Debug::Dwarf::Expression {
Value evaluate(ReadonlyBytes bytes, [[maybe_unused]] PtraceRegisters const& regs)
{
InputMemoryStream stream(bytes);
while (!stream.eof()) {
u8 opcode = 0;
stream >> opcode;
switch (static_cast<Operations>(opcode)) {
#if ARCH(I386)
case Operations::RegEbp: {
ssize_t offset = 0;
stream.read_LEB128_signed(offset);
return Value { Type::UnsignedInteger, { regs.ebp + offset } };
}
case Operations::FbReg: {
ssize_t offset = 0;
stream.read_LEB128_signed(offset);
return Value { Type::UnsignedInteger, { regs.ebp + 2 * sizeof(size_t) + offset } };
}
#endif
default:
dbgln("DWARF expr addr: {:p}", bytes.data());
dbgln("unsupported opcode: {}", opcode);
VERIFY_NOT_REACHED();
}
}
VERIFY_NOT_REACHED();
}
}