bool WModelIndex::isAncestor(const Wt::WModelIndex& i1, const Wt::WModelIndex& i2) { if (!i1.isValid()) return false; for (Wt::WModelIndex p = i1.parent(); p.isValid(); p = p.parent()) { if (p == i2) return true; } return !i2.isValid(); }
virtual int columnCount(const Wt::WModelIndex& parent = Wt::WModelIndex()) const { if (!parent.isValid()) return 6; else return 0; }
virtual int rowCount(const Wt::WModelIndex& parent = Wt::WModelIndex()) const { if (!parent.isValid()) return rows_; else return 0; }
virtual int rowCount(const Wt::WModelIndex& parent = Wt::WModelIndex()) const { if (!parent.isValid()) return _friends.size() ; else return 0; }
virtual int rowCount(const Wt::WModelIndex& parent = Wt::WModelIndex()) const { RsStackMutex mtx(_mtx) ; if (!parent.isValid()) return _searchResults.size() ; else return 0; }
boost::any InstructionListModel::data(const Wt::WModelIndex &index, int role) const { ASSERT_require(index.isValid()); ASSERT_require(index.row()>=0 && (size_t)index.row() < insns_.size()); SgAsmInstruction *insn = insns_[index.row()]; if (Wt::DisplayRole == role) { switch (index.column()) { case C_ADDR: { return Wt::WString(StringUtility::addrToString(insn->get_address())); } case C_BYTES: { std::string s; for (size_t i=0; i<insn->get_raw_bytes().size(); ++i) { uint8_t byte = insn->get_raw_bytes()[i]; char buf[32]; sprintf(buf, "%02x", byte); s += std::string(i?" ":"") + buf; } return Wt::WString(s); } case C_CHARS: { std::string s; for (size_t i=0; i<insn->get_raw_bytes().size(); ++i) { char ch = insn->get_raw_bytes()[i]; s += std::string(i?" ":"") + (isgraph(ch) ? std::string(1, ch) : std::string(" ")); } return Wt::WString(s); } case C_STACKDELTA: { int64_t delta = insn->get_stackDelta(); if (delta == SgAsmInstruction::INVALID_STACK_DELTA) return Wt::WString(""); std::string s = (delta >= 0 ? "+" : "") + boost::lexical_cast<std::string>(delta); return Wt::WString(s); } case C_NAME: { return Wt::WString(unparseMnemonic(insn)); } case C_ARGS: { std::string s; const RegisterDictionary *regs = ctx_.partitioner.instructionProvider().registerDictionary(); const SgAsmExpressionPtrList &operands = insn->get_operandList()->get_operands(); for (size_t i=0; i<operands.size(); ++i) s += (i?", ":"") + unparseExpression(operands[i], NULL, regs); return Wt::WString(s); } case C_COMMENT: { return Wt::WString(insn->get_comment()); } default: ASSERT_not_reachable("invalid column number"); } } return boost::any(); }
Sawyer::Optional<rose_addr_t> HexDumpModel::cellAddress(const Wt::WModelIndex &idx) const { if (!idx.isValid()) return Sawyer::Nothing(); size_t column = idx.column(); size_t row = idx.row(); if (column >= bytesColumn && column < bytesColumn + bytesPerRow) return cellAddress(row, column - bytesColumn); if (column >= asciiColumn && column < asciiColumn + bytesPerRow) return cellAddress(row, column - asciiColumn); return Sawyer::Nothing(); }
boost::any HexDumpModel::data(const Wt::WModelIndex &index, int role) const { ASSERT_require(index.isValid()); ASSERT_require(index.row() >= 0); // Why signed when a valid row is non-negative? size_t row = index.row(); ASSERT_require(row < nRows_); ASSERT_require(index.column() >= 0); // Why signed when a valid column is non-negative? size_t column = index.column(); ASSERT_require(column < endColumn); if (role == Wt::DisplayRole) { if (column == addressColumn) { rose_addr_t va = 0; if (rowAddress(row).assignTo(va)) return Wt::WString(StringUtility::addrToString(va)); return Wt::WString(""); } else if (column >= bytesColumn && column < bytesColumn + bytesPerRow) { uint8_t byte = 0; if (readByte(cellAddress(row, column-bytesColumn)).assignTo(byte) && byte!=0) { char buf[8]; sprintf(buf, "%02x", (unsigned)byte); return Wt::WString(buf); } return Wt::WString(""); } else if (column >= asciiColumn && column < asciiColumn + bytesPerRow) { uint8_t byte = 0; std::string s; if (readByte(cellAddress(row, column-asciiColumn)).assignTo(byte)) s = charToString(byte); return Wt::WString(s); } else if (column == sep1Column || column == sep2Column) { return Wt::WString(""); } else { ASSERT_not_reachable("this column needs data"); } } else if (role == Wt::ToolTipRole) { MemoryMap::ConstNodeIterator mmNode = memoryMap_->nodes().end(); rose_addr_t va = 0; if (column == addressColumn) { mmNode = rowSegment(row); va = cellAddress(row, 0).orElse(0); } else if (column >= bytesColumn && column < bytesColumn + bytesPerRow && cellAddress(row, column-bytesColumn).assignTo(va)) { mmNode = memoryMap_->at(va).findNode(); } else if (column >= asciiColumn && column < asciiColumn + bytesPerRow && cellAddress(row, column-asciiColumn).assignTo(va)) { mmNode = memoryMap_->at(va).findNode(); } if (mmNode != memoryMap_->nodes().end()) { const AddressInterval &interval = mmNode->key(); const MemoryMap::Segment &segment = mmNode->value(); std::string tip = StringUtility::htmlEscape(segment.name()); if (interval.isContaining(va)) tip += "+" + StringUtility::addrToString(va-interval.least()); return Wt::WString(tip); } } else if (role == Wt::StyleClassRole) { if (column==sep1Column || column==sep2Column || !rowAddress(row)) { return Wt::WString("hexdump_unmapped"); } else if (column >= bytesColumn && column < bytesColumn + bytesPerRow && !cellAddress(row, column-bytesColumn)) { return Wt::WString("hexdump_unmapped"); } else if (column >= asciiColumn && column < asciiColumn + bytesPerRow) { if (!cellAddress(row, column-asciiColumn)) { return Wt::WString("hexdump_unmapped"); } else if (charToString(*readByte(cellAddress(row, column-asciiColumn))).empty()) { return Wt::WString("hexdump_nochar"); } } else if (column == addressColumn) { MemoryMap::ConstNodeIterator mmIter = rowSegment(row); ASSERT_require(mmIter != memoryMap_->nodes().end()); // would have been caught above unsigned a = mmIter->value().accessibility(); std::string style; if (0!=(a & MemoryMap::READABLE)) style += "r"; if (0!=(a & MemoryMap::WRITABLE)) style += "w"; if (0!=(a & MemoryMap::EXECUTABLE)) style += "x"; if (style.empty()) style = "none"; return Wt::WString("hexdump_addr_" + style); } else if (row % 2) { return Wt::WString("hexdump_oddrow"); } else { return Wt::WString("hexdump_evenrow"); } } return boost::any(); }
int HexDumpModel::columnCount(const Wt::WModelIndex &parent) const { return parent.isValid() ? 0 : endColumn; }
int InstructionListModel::columnCount(const Wt::WModelIndex &parent) const { return parent.isValid() ? 0 : C_NCOLS; }
int InstructionListModel::rowCount(const Wt::WModelIndex &parent) const { return parent.isValid() ? 0 : insns_.size(); }