memory-tracing.cc 2.06 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/wasm/memory-tracing.h"

#include "src/utils.h"
8
#include "src/v8memory.h"
9 10 11

namespace v8 {
namespace internal {
12
namespace wasm {
13

14
void TraceMemoryOperation(ExecutionEngine engine, const MemoryTracingInfo* info,
15 16
                          int func_index, int position, uint8_t* mem_start) {
  EmbeddedVector<char, 64> value;
17 18
  auto mem_rep = static_cast<MachineRepresentation>(info->mem_rep);
  switch (mem_rep) {
19 20 21 22 23 24 25
#define TRACE_TYPE(rep, str, format, ctype1, ctype2)                     \
  case MachineRepresentation::rep:                                       \
    SNPrintF(value, str ":" format,                                      \
             ReadLittleEndianValue<ctype1>(                              \
                 reinterpret_cast<Address>(mem_start) + info->address),  \
             ReadLittleEndianValue<ctype2>(                              \
                 reinterpret_cast<Address>(mem_start) + info->address)); \
26 27 28 29 30 31 32 33 34 35 36
    break;
    TRACE_TYPE(kWord8, " i8", "%d / %02x", uint8_t, uint8_t)
    TRACE_TYPE(kWord16, "i16", "%d / %04x", uint16_t, uint16_t)
    TRACE_TYPE(kWord32, "i32", "%d / %08x", uint32_t, uint32_t)
    TRACE_TYPE(kWord64, "i64", "%" PRId64 " / %016" PRIx64, uint64_t, uint64_t)
    TRACE_TYPE(kFloat32, "f32", "%f / %08x", float, uint32_t)
    TRACE_TYPE(kFloat64, "f64", "%f / %016" PRIx64, double, uint64_t)
#undef TRACE_TYPE
    default:
      SNPrintF(value, "???");
  }
37
  const char* eng = "?";
38
  switch (engine) {
39
    case ExecutionEngine::kTurbofan:
40
      eng = "turbofan";
41
      break;
42
    case ExecutionEngine::kLiftoff:
43
      eng = "liftoff";
44 45
      break;
    case ExecutionEngine::kInterpreter:
46
      eng = "interpreter";
47 48
      break;
  }
49 50 51
  printf("%-11s func:%6d+0x%-6x%s %08x val: %s\n", eng, func_index, position,
         info->is_store ? " store to" : "load from", info->address,
         value.start());
52 53
}

54
}  // namespace wasm
55 56
}  // namespace internal
}  // namespace v8