Expression.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "Expression.h"
  7. #include <AK/MemoryStream.h>
  8. #include <sys/arch/i386/regs.h>
  9. namespace Debug::Dwarf::Expression {
  10. Value evaluate(ReadonlyBytes bytes, const PtraceRegisters& regs)
  11. {
  12. InputMemoryStream stream(bytes);
  13. while (!stream.eof()) {
  14. u8 opcode = 0;
  15. stream >> opcode;
  16. switch (static_cast<Operations>(opcode)) {
  17. case Operations::RegEbp: {
  18. ssize_t offset = 0;
  19. stream.read_LEB128_signed(offset);
  20. return Value { Type::UnsignedIntetger, regs.ebp + offset };
  21. }
  22. case Operations::FbReg: {
  23. ssize_t offset = 0;
  24. stream.read_LEB128_signed(offset);
  25. return Value { Type::UnsignedIntetger, regs.ebp + 2 * sizeof(size_t) + offset };
  26. }
  27. default:
  28. dbgln("DWARF expr addr: {}", (const void*)bytes.data());
  29. dbgln("unsupported opcode: {}", (u8)opcode);
  30. VERIFY_NOT_REACHED();
  31. }
  32. }
  33. VERIFY_NOT_REACHED();
  34. }
  35. }