Wolfgang Thallergcc16 merge934c3885 months agoHistory
1281 lines · 29.5 KB · C++
RawDownload
/* Copyright (C) 2021-2026 Free Software Foundation, Inc.   Contributed by Oracle.    This file is part of GNU Binutils.    This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 3, or (at your option)   any later version.    This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.    You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, 51 Franklin Street - Fifth Floor, Boston,   MA 02110-1301, USA.  */ #include "config.h"#include <assert.h>#include "CallStack.h"#include "DbeSession.h"#include "DbeView.h"#include "DataObject.h"#include "Exp_Layout.h"#include "Experiment.h"#include "Module.h"#include "LoadObject.h"#include "Expression.h"#include "Function.h"#include "Histable.h"#include "Sample.h"#include "Table.h" ////////////////////////////////////////////////////////////  class Expression::Context static const uint64_t INDXOBJ_EXPGRID_SHIFT = 60;static const uint64_t INDXOBJ_EXPID_SHIFT   = 32; Expression::Context::Context (DbeView *_dbev, Experiment *_exp){  dbev = _dbev;  exp = _exp;  dview = NULL;  eventId = 0;} Expression::Context::Context (DbeView *_dbev, Experiment *_exp,			      DataView *_dview, long _eventId){  dbev = _dbev;  exp = _exp;  dview = _dview;  eventId = _eventId;} ////////////////////////////////////////////////////////////  class ExpressionExpression::Expression (OpCode _op, uint64_t _v){  op = _op;  v = Value (_v);  arg0 = NULL;  arg1 = NULL;} Expression::Expression (OpCode _op, const Expression *_arg0,			const Expression *_arg1){  op = _op;  v = Value ();  arg0 = NULL;  arg1 = NULL;  if (_arg0)    arg0 = _arg0->copy ();  if (_arg1)    arg1 = _arg1->copy ();} Expression::~Expression (){  delete arg0;  delete arg1;} Expression::Expression (const Expression &rhs){  op = rhs.op;  arg0 = NULL;  arg1 = NULL;  v = Value (rhs.v);  if (rhs.arg0)    {      arg0 = rhs.arg0->copy ();      if (v.next)	{	  assert (arg0 && v.next == &(rhs.arg0->v));	  v.next = &(arg0->v);	}    }  if (rhs.arg1)    arg1 = rhs.arg1->copy ();} Expression::Expression (const Expression *rhs){  arg0 = NULL;  arg1 = NULL;  copy (rhs);} voidExpression::copy (const Expression *rhs){  op = rhs->op;  delete arg0;  delete arg1;  arg0 = NULL;  arg1 = NULL;  v = Value (rhs->v);  if (rhs->arg0)    {      arg0 = rhs->arg0->copy ();      if (v.next)	{	  assert (arg0 && v.next == &(rhs->arg0->v));	  v.next = &(arg0->v);	}    }  if (rhs->arg1)    arg1 = rhs->arg1->copy ();} Expression &Expression::operator= (const Expression &rhs){  if (this == &rhs)    return *this;  copy (&rhs);  return *this;} boolExpression::getVal (int propId, Context *ctx){  v.val = 0;  v.next = NULL;  int origPropId = propId;  switch (propId)    {    default:      {	if (!ctx->dview)	  return false;	PropDescr *propDscr = ctx->dview->getProp (propId);	if (!propDscr)	  return false;	switch (propDscr->vtype)	  {	  case TYPE_INT32:	    v.val = ctx->dview->getIntValue (propId, ctx->eventId);	    break;	  case TYPE_UINT32:	    v.val = (uint32_t) ctx->dview->getIntValue (propId, ctx->eventId); //prevent sign extension	    break;	  case TYPE_INT64:	  case TYPE_UINT64:	    v.val = ctx->dview->getLongValue (propId, ctx->eventId);	    break;	  case TYPE_OBJ:	    // YM: not sure if we should allow this	    v.val = (long long) ctx->dview->getObjValue (propId, ctx->eventId);	    break;	  case TYPE_STRING:	  case TYPE_DOUBLE:	  default:	    return false; // Weird, programming error?	  }	break;      }    case PROP_FREQ_MHZ:      if (ctx->exp && ctx->exp->clock)	v.val = ctx->exp->clock;      else	return false;      break;    case PROP_PID:      if (ctx->exp == NULL)	return false;      v.val = ctx->exp->getPID ();      break;    case PROP_EXPID:      if (ctx->exp == NULL)	return false;      v.val = ctx->exp->getUserExpId ();      break;    case PROP_EXPID_CMP:      if (ctx->exp == NULL)	return false;      else	{	  Experiment *exp = ctx->exp;	  if (ctx->dbev && ctx->dbev->comparingExperiments ())	    exp = (Experiment *) exp->get_compare_obj ();	  v.val = exp->getUserExpId ();	}      break;    case PROP_EXPGRID:      if (ctx->exp == NULL)	return false;      v.val = ctx->exp->groupId;      break;    case PROP_NTICK_USEC:      if (ctx->exp == NULL)	return false;      if (ctx->dview && ctx->dview->getProp (PROP_NTICK))	v.val = ctx->dview->getIntValue (PROP_NTICK, ctx->eventId)		* ctx->exp->get_params ()->ptimer_usec;      else	return false;      break;    case PROP_ATSTAMP:    case PROP_ETSTAMP:      if (ctx->exp == NULL)	return false;      if (ctx->dview && ctx->dview->getProp (PROP_TSTAMP))	v.val = ctx->dview->getLongValue (PROP_TSTAMP, ctx->eventId);      else	return false;      if (propId == PROP_ATSTAMP)	break; // absolute time, no adjustments      // propId==PROP_ETSTAMP      // calculate relative time from start of this experiment      v.val -= ctx->exp->getStartTime ();      break;    case PROP_TSTAMP:    case PROP_TSTAMP_LO:    case PROP_TSTAMP_HI:      {	if (ctx->exp == NULL)	  return false;	if (!(ctx->dview && ctx->dview->getProp (PROP_TSTAMP)))	  return false;	hrtime_t tstamp = ctx->dview->getLongValue (PROP_TSTAMP, ctx->eventId);	// compute relative time from start of founder experiment	v.val = tstamp - ctx->exp->getStartTime ()		+ ctx->exp->getRelativeStartTime ();	if (propId == PROP_TSTAMP)	  break;	if (ctx->dview->getProp (PROP_EVT_TIME))	  {	    hrtime_t delta = ctx->dview->getLongValue (PROP_EVT_TIME, ctx->eventId);	    if (propId == PROP_TSTAMP_LO)	      {		if (delta > 0)		  { // positive delta means TSTAMP is at end		    // TSTAMP_LO = TSTAMP-delta		    v.val -= delta;		    break;		  }		break;	      }	    else	      { // PROP_TSTAMP_HI		if (delta < 0)		  { // negative delta means TSTAMP is at start		    // TSTAMP_HI = TSTAMP+(-delta)		    v.val -= delta;		    break;		  }		break;	      }	  }	else if (ctx->dview->getProp (PROP_TSTAMP2))	  {	    if (propId == PROP_TSTAMP_HI)	      {		hrtime_t tstamp2 = ctx->dview->getLongValue (PROP_TSTAMP2,							     ctx->eventId);		if (tstamp2 == 0)		  break; // if not initialized, event does not have duration		if (tstamp2 == MAX_TIME)		  tstamp2 = ctx->exp->getLastEvent ();		hrtime_t delta = tstamp2 - tstamp;		if (delta >= 0)		  {		    v.val += delta;		    break;		  }		break; // weird, delta should not be negative	      }	    break; // PROP_TSTAMP_LO, no modification needed	  }	break; // should never be hit      }    case PROP_IOHEAPBYTES:      {	propId = PROP_IONBYTE;	if (ctx->dview == NULL)	  return false;	if (!ctx->dview->getProp (propId))	  { // has property?	    propId = PROP_HSIZE;	    if (!ctx->dview->getProp (propId))	      return false;	  }	v.val = ctx->dview->getLongValue (propId, ctx->eventId);	break;      }    case PROP_SAMPLE_MAP:      {	if (ctx->exp == NULL)	  return false;	if (ctx->dview == NULL)	  return false;	if (ctx->dview->getProp (PROP_SAMPLE))	  v.val = ctx->dview->getIntValue (PROP_SAMPLE, ctx->eventId);	else	  { // does not have property, convert to time.	    uint64_t tstamp;	    tstamp = ctx->dview->getLongValue (PROP_TSTAMP, ctx->eventId);	    Sample *sample = ctx->exp->map_event_to_Sample (tstamp);	    v.val = sample ? sample->get_number () : -1;	  }	break;      }    case PROP_GCEVENT_MAP:      {	if (ctx->exp == NULL)	  return false;	if (ctx->dview == NULL)	  return false;	if (ctx->dview->getProp (PROP_GCEVENT))	  v.val = ctx->dview->getIntValue (PROP_GCEVENT, ctx->eventId);	else	  { // does not have property, convert to time.	    uint64_t tstamp;	    tstamp = ctx->dview->getLongValue (PROP_TSTAMP, ctx->eventId);	    GCEvent *gcevent = ctx->exp->map_event_to_GCEvent (tstamp);	    v.val = gcevent ? gcevent->id : 0;	  }	break;      }    case PROP_LEAF:      {	if (ctx->dview == NULL)	  return false;	VMode vmode = ctx->dbev ? ctx->dbev->get_view_mode () : VMODE_USER;	int prop_id;	if (vmode == VMODE_MACHINE)	  prop_id = PROP_MSTACK;	else if (vmode == VMODE_EXPERT)	  prop_id = PROP_XSTACK;	else	  prop_id = PROP_USTACK;	if (!ctx->dview->getProp (prop_id))	  return false;	Histable *obj = CallStack::getStackPC (ctx->dview->getObjValue (prop_id, ctx->eventId), 0);	Function *func = (Function*) obj->convertto (Histable::FUNCTION);	v.val = func->id; // LEAF	break;      }    case PROP_STACKID:      {	VMode vmode = ctx->dbev ? ctx->dbev->get_view_mode () : VMODE_USER;	if (vmode == VMODE_MACHINE)	  propId = PROP_MSTACK;	else if (vmode == VMODE_EXPERT)	  propId = PROP_XSTACK;	else	  propId = PROP_USTACK;	if (ctx->dview == NULL)	  return false;	if (!ctx->dview->getProp (propId))	  return false;	v.val = (long) ctx->dview->getObjValue (propId, ctx->eventId);	break;      }    case PROP_STACKL:    case PROP_STACKI:    case PROP_STACK:      {	VMode vmode = ctx->dbev ? ctx->dbev->get_view_mode () : VMODE_USER;	if (vmode == VMODE_MACHINE)	  propId = PROP_MSTACK;	else if (vmode == VMODE_EXPERT)	  propId = PROP_XSTACK;	else	  propId = PROP_USTACK;      }      // no break;    case PROP_MSTACKL:    case PROP_XSTACKL:    case PROP_USTACKL:    case PROP_MSTACKI:    case PROP_XSTACKI:    case PROP_USTACKI:      switch (propId)	{	case PROP_MSTACKL:	case PROP_MSTACKI:	  propId = PROP_MSTACK;	  break;	case PROP_XSTACKL:	case PROP_XSTACKI:	  propId = PROP_XSTACK;	  break;	case PROP_USTACKL:	case PROP_USTACKI:	  propId = PROP_USTACK;	  break;	default:	  break;	}      // no break;    case PROP_MSTACK:    case PROP_XSTACK:    case PROP_USTACK:      {	if (ctx->dview == NULL)	  return false;	if (!ctx->dview->getProp (propId))	  return false;	bool hide_mode = !ctx->dbev->isShowAll ()		|| ctx->dbev->isFilterHideMode ();	Expression *cur = this;	for (CallStackNode *stack = (CallStackNode *)		ctx->dview->getObjValue (propId, ctx->eventId);		stack; stack = stack->get_ancestor ())	  {	    Histable *hist = stack->get_instr ();	    if (origPropId == PROP_STACK || origPropId == PROP_MSTACK		|| origPropId == PROP_XSTACK || origPropId == PROP_USTACK)	      {		cur->v.val = hist->convertto (Histable::FUNCTION)->id;		cur->v.fn = cur->v.val;	      }	    else if (origPropId == PROP_STACKL || origPropId == PROP_MSTACKL		    || origPropId == PROP_XSTACKL || origPropId == PROP_USTACKL)	      {		cur->v.val = hist->convertto (Histable::LINE)->id;		if (hide_mode)		  cur->v.fn = hist->convertto (Histable::FUNCTION)->id;		else		  cur->v.fn = 0;	      }	    else if (origPropId == PROP_STACKI || origPropId == PROP_MSTACKI		    || origPropId == PROP_XSTACKI || origPropId == PROP_USTACKI)	      {		cur->v.val = hist->convertto (Histable::INSTR)->id;		if (hide_mode)		  cur->v.fn = hist->convertto (Histable::FUNCTION)->id;		else		  cur->v.fn = 0;	      }	    if (cur->arg1 == NULL)	      cur->arg1 = new Expression (OP_NONE, (uint64_t) 0);	    if (stack->get_ancestor () == NULL)	      {		if (origPropId == PROP_STACKL || origPropId == PROP_MSTACKL		    || origPropId == PROP_XSTACKL || origPropId == PROP_USTACKL		    || origPropId == PROP_STACKI || origPropId == PROP_MSTACKI		    || origPropId == PROP_XSTACKI || origPropId == PROP_USTACKI)		  {		    cur->v.next = NULL;		    continue;		  }	      }	    cur->v.next = &cur->arg1->v;	    cur = cur->arg1;	  }	if (origPropId == PROP_STACK || origPropId == PROP_MSTACK	    || origPropId == PROP_XSTACK || origPropId == PROP_USTACK)	  {	    cur->v.val = dbeSession->get_Total_Function ()->id;	    cur->v.fn = cur->v.val;	    cur->v.next = NULL;	  }	break;      }    case PROP_DOBJ:      {	if (ctx->dview == NULL)	  return false;	if (!ctx->dview->getProp (PROP_DOBJ))	  return false;	DataObject *dobj = (DataObject*)		ctx->dview->getObjValue (PROP_DOBJ, ctx->eventId);	if (dobj != NULL)	  {	    Expression *cur = this;	    for (;;)	      {		cur->v.val = dobj->id;		dobj = dobj->parent;		if (dobj == NULL)		  break;

Lines 1–500 of 1281.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t