⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vglogview.cpp

📁 Linux平台下的内核及程序调试器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
      for (; !e.isNull(); e = e.nextSibling().toElement() ) {         VgElement elem = (VgElement&)e;         last_item = new VgOutputItem( this, last_item, elem );         last_item->setText( e.text() );      }      e = exInfo.firstChild().toElement();      for (; !e.isNull(); e = e.nextSibling().toElement() ) {         VgElement elem = (VgElement&)e;         last_item = new VgOutputItem( this, last_item, elem );         last_item->setText( e.text() );      }   }   VgOutputItem::setOpen( open );}/**********************************************************************//* PreambleItem   - preamble   - lines: as text lines*/PreambleItem::PreambleItem( VgOutputItem* parent,                            QListViewItem* after,                            VgPreamble preamble )   : VgOutputItem( parent, after, preamble ){   setExpandable( true );   setText( "Preamble" );}void PreambleItem::setOpen( bool open ){   if ( open && childCount() == 0 ) {      VgOutputItem* last_item = 0;      QDomElement e = elem.firstChild().toElement();      for (; !e.isNull(); e = e.nextSibling().toElement() ) {         VgElement elem = (VgElement&)e;         last_item = new VgOutputItem( this, last_item, elem );         last_item->setText( e.text() );      }    }   VgOutputItem::setOpen( open );}/**********************************************************************//* ErrorItem   - error   - stack   - frames   - src: as clickable item   - auxwhat: as text line   - auxstack   - (as stack)*/ErrorItem::ErrorItem( VgOutputItem* parent, QListViewItem* after,                      VgError err )   : VgOutputItem( parent, after, err ){   err_tmplt  = "%1 [%2]: %3";   QString what = err.getFirstElem( "what" ).text();   QString kind = err.getFirstElem( "kind" ).text();   QString acnym = errorAcronym( kind );   if ( err.isLeak() ) {      setText( acnym + ": " + what );   } else {      setText( err_tmplt.arg(acnym).arg(1).arg(what) );   }   setExpandable( true );}void ErrorItem::updateCount( QString count ){   if (!isLeak() && !count.isEmpty()) {      QString what = elem.getFirstElem( "what" ).text();      QString kind = elem.getFirstElem( "kind" ).text();      QString acnym = errorAcronym( kind );      setText( err_tmplt.arg(acnym).arg(count).arg(what) );   }}void ErrorItem::setOpen( bool open ){   if ( open && childCount() == 0 ) {      VgOutputItem* after = this;          /* main stack */      VgElement main_stack = elem.getFirstElem( "stack" );      VgOutputItem* stack_item1 = new StackItem( this, after, main_stack );      stack_item1->setOpen( true );      after = stack_item1;      /* aux what */      VgElement aux_what = elem.getFirstElem( "auxwhat" );      if ( ! aux_what.isNull() ) {         VgOutputItem* aux_item = new VgOutputItem( this, after, aux_what );         aux_item->setText( aux_what.text() );         after = aux_item;      }      /* aux stack */      QDomElement aux_stack = aux_what.nextSibling().toElement();      if ( ! aux_stack.isNull() ) {         VgElement auxstack = (VgElement&)aux_stack;         new StackItem( this, after, auxstack );      }      /* J sez there may be more than two stacks in the future .. */      vk_assert( aux_stack.nextSibling().isNull() );   }   VgOutputItem::setOpen( open );}/* returns an acronym for a given error::kind */QString ErrorItem::errorAcronym( QString kind ){   AcronymMap::Iterator it = acronymMap.find( kind );   if ( it == acronymMap.end() )      return "???";   return it.data(); }/**********************************************************************//* StackItem */StackItem::StackItem( VgOutputItem* parent, QListViewItem* after,                       VgElement stck )   : VgOutputItem( parent, after, stck ){   setText( "stack" );   setExpandable( true );}void StackItem::setOpen( bool open ){   if ( open && childCount() == 0 ) {      VgOutputItem* after = this;      QDomElement e = elem.firstChild().toElement();      for (; !e.isNull(); e = e.nextSibling().toElement() ) {         VgFrame frame = (VgFrame&)e;         after = new FrameItem( this, after, frame );         after->setOpen( false );      }   }   VgOutputItem::setOpen( open );}/**********************************************************************//* FrameItem */FrameItem::FrameItem( VgOutputItem* parent, QListViewItem* after,                      VgFrame frm )   : VgOutputItem( parent, after, frm ){   /* check what perms the user has w.r.t. this file */   QDomNodeList frame_details = frm.childNodes();   QDomElement srcdir  = frame_details.item( 3 ).toElement();   QDomElement srcfile = frame_details.item( 4 ).toElement();   if (!srcdir.isNull() && !srcfile.isNull()) {      QString path = srcdir.text() + "/" + srcfile.text();      QFileInfo fi( path );      if ( fi.exists() && fi.isFile() && !fi.isSymLink() ) {         isReadable  = fi.isReadable();         isWriteable = fi.isWritable();      }   }   setText( frm.describe_IP() );   setExpandable( isReadable || isWriteable );}void FrameItem::setOpen( bool open ){   if ( open && childCount() == 0 && isReadable ) {      QDomNodeList frame_details = elem.childNodes();      QDomElement srcdir  = frame_details.item( 3 ).toElement();      QDomElement srcfile = frame_details.item( 4 ).toElement();      QDomElement line    = frame_details.item( 5 ).toElement();      if (srcdir.isNull() || srcfile.isNull())         return;      QString path = srcdir.text() + "/" + srcfile.text();      VgElement srcline = (VgElement&)line;      /* create the item for the src lines */      SrcItem* src_item = new SrcItem( this, srcline, path );      src_item->setOpen( true );   }   VgOutputItem::setOpen( open );}#include "vk_config.h"/**********************************************************************//* SrcItem */SrcItem::SrcItem( VgOutputItem* parent, VgElement line, QString path )   : VgOutputItem( parent, line ) {    /* --- setup text --- */   int target_line = line.text().toInt();   if (target_line < 0) target_line = 0;   /* num lines to show above / below the target line */   int n_lines = vkConfig->rdInt( "src-lines", "valkyrie" );   /* figure out where to start showing src lines */   int top_line = 1;   if ( target_line > n_lines+1 )      top_line = target_line - n_lines;   int bot_line = target_line + n_lines;   int current_line = 1;   QFile file( path );   if ( !file.open( IO_ReadOnly ) )      return;   /* TODO: faster to set file pos using QFile::at(offset) */   QString src_lines;   QTextStream stream( &file );   while ( !stream.atEnd() && ( current_line <= bot_line ) ) {      if ( current_line < top_line )         stream.readLine();      /* skip lines to top_line */      else         src_lines += "  " + stream.readLine() + "\n";      current_line++;   }   file.close();   src_lines.truncate( src_lines.length()-1 ); /* remove last newline */   /* --- setup item --- */   isReadable  = parent->isReadable;   isWriteable = parent->isWriteable;   pix = 0;   if ( isWriteable ) {      setPixmap( write_xpm );   } else if ( isReadable ) {      setPixmap( read_xpm );   }   setMultiLinesEnabled( true );   setText( src_lines );}SrcItem::~SrcItem() {   if ( pix ) {      delete pix;      pix = 0;   }}void SrcItem::paintCell( QPainter* p, const QColorGroup& cg,                         int col, int width, int align ) {   QColor bg( 240, 240, 240 );    // very pale gray   QColorGroup cgrp( cg );        // copy the original   cgrp.setColor( QColorGroup::Base, bg );   QListViewItem::paintCell( p, cgrp, col, width, align );}void SrcItem::setPixmap( const char* pix_xpm[] ) {   pix = new QPixmap( pix_xpm );   setup();   widthChanged( 0 );   invalidateHeight();   repaint();}const QPixmap* SrcItem::pixmap( int i ) const { return ( i ) ? 0 : pix; }/**********************************************************************//* SuppCountsItem   - suppcounts   - pairs: as text line*/SuppCountsItem::SuppCountsItem( VgOutputItem* parent,                                QListViewItem* after,                                VgSuppCounts sc )   : VgOutputItem( parent, after, sc ){   setExpandable( true );   setText( "Suppressed errors" );}void SuppCountsItem::setOpen( bool open ){   if ( open && childCount() == 0 ) {      VgOutputItem* child_item = 0;      QDomNodeList pairs = elem.childNodes();      QDomElement e = pairs.item(0).toElement();      for (; !e.isNull(); e = e.nextSibling().toElement() ) {         VgElement pair = (VgElement&)e;         QString count = pair.firstChild().toElement().text();         QString name  = pair.lastChild().toElement().text();         QString supp_str = QString("%1:  " + name).arg( count, 4 );         child_item = new VgOutputItem( this, child_item, pair );         child_item->setText( supp_str );      }   }   VgOutputItem::setOpen( open );}/**********************************************************************//*  VgLogView: inherits VgLog*/VgLogView::VgLogView( QListView* lv )   : lview(lv), lastChild( 0 ){ }VgLogView::~VgLogView(){ }/* Reimplements VgLog::appendNode() to populate log and listview */bool VgLogView::appendNode( QDomNode node ){   /* populate log */   if ( ! VgLog::appendNode( node ) )      return false;   QDomElement e  = node.toElement();   VgElement elem = (VgElement&)e;   /* populate listview */   switch ( elem.elemType() ) {   case VgElement::STATUS: {      VgStatus status = (VgStatus&)elem;      VgStatus::StateType state = status.state();      if (state == VgStatus::RUNNING) {         VgElement exe =            args().getFirstElem( "argv" ).getFirstElem( "exe" );         topStatus = new TopStatusItem( lview, status, exe, protocol().text() );         topStatus->setOpen( true );         lastChild = new InfoItem( topStatus, docroot() );         lastChild = new PreambleItem( topStatus, lastChild, preamble() );      } else {         /* update topStatus */         topStatus->updateStatus( status );      }      break;   }   case VgElement::ERROR: {      VgError err = (VgError&)elem;      lastChild = new ErrorItem( topStatus, lastChild, err );      if (err.isLeak()) {         /* update topStatus */         topStatus->updateLeakCounts( err );      }      break;   }   case VgElement::SUPPCOUNTS: {      VgSuppCounts sc = (VgSuppCounts&)elem;      lastChild = new SuppCountsItem( topStatus, lastChild, sc );      break;   }   case VgElement::ERRORCOUNTS: {      VgErrCounts ec = (VgErrCounts&)elem;      /* update topStatus */      topStatus->updateErrorCounts( ec );      /* update all non-leak errors */      updateErrorItems( ec );      break;   }   default:      break;   }   return true;}/* iterate over all errors in the listview, looking for a match on   error->unique with ecounts->pairList->unique.  if we find a match,   update the error's num_times value */void VgLogView::updateErrorItems( VgErrCounts ec ){   VgOutputItem* item = (VgOutputItem*)topStatus->firstChild();   while ( item ) {      if ( item->elem.elemType() == VgElement::ERROR ) {         ErrorItem* err_item = (ErrorItem*)item;         VgError err = *((VgError*)&err_item->elem);         if ( ! err.isLeak() ) {            QString count = ec.getCount( err ).text();            err_item->updateCount( count );         }      }      item = item->nextSibling();   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -