diff options
| -rw-r--r-- | tools/standalone_miri/debug.hpp | 2 | ||||
| -rw-r--r-- | tools/standalone_miri/main.cpp | 4 | ||||
| -rw-r--r-- | tools/standalone_miri/miri.cpp | 4 | ||||
| -rw-r--r-- | tools/standalone_miri/module_tree.cpp | 2 | ||||
| -rw-r--r-- | tools/standalone_miri/value.cpp | 20 | ||||
| -rw-r--r-- | tools/standalone_miri/value.hpp | 4 | 
6 files changed, 25 insertions, 11 deletions
| diff --git a/tools/standalone_miri/debug.hpp b/tools/standalone_miri/debug.hpp index 4b8d7aa9..5f1dd038 100644 --- a/tools/standalone_miri/debug.hpp +++ b/tools/standalone_miri/debug.hpp @@ -112,3 +112,5 @@ struct DebugExceptionError:  #define LOG_TODO(strm) do { DebugSink::get(__FUNCTION__,__FILE__,__LINE__,DebugLevel::Bug) << "TODO: " << strm; throw DebugExceptionTodo{}; } while(0)  #define LOG_BUG(strm) do { DebugSink::get(__FUNCTION__,__FILE__,__LINE__,DebugLevel::Bug) << "BUG: " << strm; abort(); } while(0)  #define LOG_ASSERT(cnd,strm) do { if( !(cnd) ) { LOG_BUG("Assertion failure: " #cnd " - " << strm); } } while(0) + +#define FMT_STRING(...) (dynamic_cast<::std::stringstream&>(::std::stringstream() << __VA_ARGS__).str()) diff --git a/tools/standalone_miri/main.cpp b/tools/standalone_miri/main.cpp index ed9b9267..c603d5f1 100644 --- a/tools/standalone_miri/main.cpp +++ b/tools/standalone_miri/main.cpp @@ -72,7 +72,7 @@ int main(int argc, const char* argv[])      }      // Create argc/argv based on input arguments -    auto argv_alloc = Allocation::new_alloc((1 + opts.args.size()) * POINTER_SIZE); +    auto argv_alloc = Allocation::new_alloc((1 + opts.args.size()) * POINTER_SIZE, "argv");      argv_alloc->write_usize(0 * POINTER_SIZE, 0);      argv_alloc->relocations.push_back({ 0 * POINTER_SIZE, RelocationPtr::new_ffi(FFIPointer::new_const_bytes(opts.infile.c_str(), opts.infile.size() + 1)) });      for(size_t i = 0; i < opts.args.size(); i ++) @@ -80,7 +80,7 @@ int main(int argc, const char* argv[])          argv_alloc->write_usize((1 + i) * POINTER_SIZE, 0);          argv_alloc->relocations.push_back({ (1 + i) * POINTER_SIZE, RelocationPtr::new_ffi(FFIPointer::new_const_bytes(opts.args[0], ::std::strlen(opts.args[0]) + 1)) });      } -     +      // Construct argc/argv values      auto val_argc = Value::new_isize(1 + opts.args.size());      auto argv_ty = ::HIR::TypeRef(RawType::I8).wrap(TypeWrapper::Ty::Pointer, 0 ).wrap(TypeWrapper::Ty::Pointer, 0); diff --git a/tools/standalone_miri/miri.cpp b/tools/standalone_miri/miri.cpp index 3714ed56..3d28c542 100644 --- a/tools/standalone_miri/miri.cpp +++ b/tools/standalone_miri/miri.cpp @@ -575,7 +575,7 @@ bool InterpreterThread::step_one(Value& out_thread_result)      assert( !this->m_stack.empty() );      assert( !this->m_stack.back().cb );      auto& cur_frame = this->m_stack.back(); -    TRACE_FUNCTION_R(cur_frame.fcn.my_path, ""); +    TRACE_FUNCTION_R(cur_frame.fcn.my_path << " BB" << cur_frame.bb_idx << "/" << cur_frame.stmt_idx, "");      const auto& bb = cur_frame.fcn.m_mir.blocks.at( cur_frame.bb_idx );      const size_t    MAX_STACK_DEPTH = 40; @@ -1613,7 +1613,7 @@ bool InterpreterThread::call_extern(Value& rv, const ::std::string& link_name, c          auto rty = ::HIR::TypeRef(RawType::Unit).wrap( TypeWrapper::Ty::Pointer, 0 );          // TODO: Use the alignment when making an allocation? -        rv = Value::new_pointer(rty, 0, RelocationPtr::new_alloc(Allocation::new_alloc(size))); +        rv = Value::new_pointer(rty, 0, RelocationPtr::new_alloc(Allocation::new_alloc(size, "__rust_alloc")));      }      else if( link_name == "__rust_reallocate" || link_name == "__rust_realloc" )      { diff --git a/tools/standalone_miri/module_tree.cpp b/tools/standalone_miri/module_tree.cpp index 82bbbf3f..29b822de 100644 --- a/tools/standalone_miri/module_tree.cpp +++ b/tools/standalone_miri/module_tree.cpp @@ -153,7 +153,7 @@ bool Parser::parse_one()                  {                      auto reloc_str = ::std::move(lex.consume().strval); -                    auto a = Allocation::new_alloc( reloc_str.size() ); +                    auto a = Allocation::new_alloc( reloc_str.size(), FMT_STRING("static " << p) );                      //a.alloc().set_tag();                      a->write_bytes(0, reloc_str.data(), reloc_str.size());                      s.val.allocation->relocations.push_back({ ofs, /*size,*/ RelocationPtr::new_alloc(::std::move(a)) }); diff --git a/tools/standalone_miri/value.cpp b/tools/standalone_miri/value.cpp index 0b3aa988..3a479bce 100644 --- a/tools/standalone_miri/value.cpp +++ b/tools/standalone_miri/value.cpp @@ -45,9 +45,10 @@ bool FfiLayout::is_valid_read(size_t o, size_t s) const      return true;  } -AllocationHandle Allocation::new_alloc(size_t size) +AllocationHandle Allocation::new_alloc(size_t size, ::std::string tag)  {      Allocation* rv = new Allocation(); +    rv->m_tag = ::std::move(tag);      rv->refcount = 1;      rv->data.resize( (size + 8-1) / 8 );    // QWORDS      rv->mask.resize( (size + 8-1) / 8 );    // bitmap bytes @@ -318,6 +319,11 @@ void Allocation::check_bytes_valid(size_t ofs, size_t size) const          }      }  } +::std::ostream& operator<<(::std::ostream& os, const Allocation* x) +{ +    os << static_cast<const void*>(x) << " A(" << x->tag() << ")"; +    return os; +}  void Allocation::mark_bytes_valid(size_t ofs, size_t size)  {      assert( ofs+size <= this->mask.size() * 8 ); @@ -345,7 +351,7 @@ Value Allocation::read_value(size_t ofs, size_t size) const      }      if( has_reloc || size > sizeof(rv.direct_data.data) )      { -        rv.allocation = Allocation::new_alloc(size); +        rv.allocation = Allocation::new_alloc(size, FMT_STRING("Allocation::read_value(" << ofs << "," << size << ")"));          rv.write_bytes(0, this->data_ptr() + ofs, size); @@ -595,14 +601,14 @@ Value::Value(::HIR::TypeRef ty)      // Fallback: Make a new allocation      //LOG_TRACE(" Creating allocation for " << ty); -    this->allocation = Allocation::new_alloc(size); +    this->allocation = Allocation::new_alloc(size, FMT_STRING(ty));  }  Value Value::with_size(size_t size, bool have_allocation)  {      Value   rv;      if(have_allocation)      { -        rv.allocation = Allocation::new_alloc(size); +        rv.allocation = Allocation::new_alloc(size, FMT_STRING("with_size(" << size << ")"));      }      else      { @@ -662,7 +668,7 @@ Value Value::new_i32(int32_t v) {  void Value::create_allocation()  {      assert(!this->allocation); -    this->allocation = Allocation::new_alloc(this->direct_data.size); +    this->allocation = Allocation::new_alloc(this->direct_data.size, "create_allocation");      if( this->direct_data.size > 0 )          this->allocation->mask[0] = this->direct_data.mask[0];      if( this->direct_data.size > 8 ) @@ -862,6 +868,8 @@ extern ::std::ostream& operator<<(::std::ostream& os, const ValueRef& v)          case RelocationPtr::Ty::Allocation: {              const auto& alloc = alloc_ptr.alloc(); +            os << "A(" << alloc.tag() << ")@" << v.m_offset << "+" << v.m_size << " "; +              auto flags = os.flags();              os << ::std::hex;              for(size_t i = v.m_offset; i < ::std::min(alloc.size(), v.m_offset + v.m_size); i++) @@ -915,6 +923,8 @@ extern ::std::ostream& operator<<(::std::ostream& os, const ValueRef& v)      {          const auto& alloc = *v.m_value->allocation; +        os << "A(" << alloc.tag() << ")@" << v.m_offset << "+" << v.m_size << " "; +          auto flags = os.flags();          os << ::std::hex;          for(size_t i = v.m_offset; i < ::std::min(alloc.size(), v.m_offset + v.m_size); i++) diff --git a/tools/standalone_miri/value.hpp b/tools/standalone_miri/value.hpp index e45759a7..8db17f03 100644 --- a/tools/standalone_miri/value.hpp +++ b/tools/standalone_miri/value.hpp @@ -243,16 +243,18 @@ class Allocation:      public ValueCommonWrite  {      friend class AllocationHandle; +    ::std::string   m_tag;      size_t  refcount;      // TODO: Read-only flag?      bool is_freed = false;  public:      virtual ~Allocation() {} -    static AllocationHandle new_alloc(size_t size); +    static AllocationHandle new_alloc(size_t size, ::std::string tag);      const uint8_t* data_ptr() const { return reinterpret_cast<const uint8_t*>(this->data.data()); }            uint8_t* data_ptr()       { return reinterpret_cast<      uint8_t*>(this->data.data()); }      size_t size() const { return this->data.size() * 8; } +    const ::std::string& tag() const { return m_tag; }      ::std::vector<uint64_t> data;      ::std::vector<uint8_t> mask; | 
