crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianUtils/BasicTypes/SymAddressWithKnownBits.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 using System;
       
    18 using System.Collections.Generic;
       
    19 using System.Text;
       
    20 
       
    21 namespace SymbianUtils.BasicTypes
       
    22 {
       
    23     public class SymAddressWithKnownBits : SymAddress
       
    24     {
       
    25         #region Constructors
       
    26         public SymAddressWithKnownBits()
       
    27             : this( 0 )
       
    28         {
       
    29         }
       
    30 
       
    31         public SymAddressWithKnownBits( uint aAddress )
       
    32             : base( aAddress )
       
    33         {
       
    34         }
       
    35         #endregion
       
    36 
       
    37         #region API
       
    38         public void SetKnownAddressBits( uint aAddress, int aNumberOfValidBits )
       
    39         {
       
    40             // First build a bit mask of all the bits which we want to keep
       
    41             // from the currently maintained address.
       
    42             uint mask = 0;
       
    43             for ( int i = 31; i >= aNumberOfValidBits; i-- )
       
    44             {
       
    45                 mask |= (uint) ( 1u << i );
       
    46             }
       
    47 
       
    48             // aNumberOfValidBits = 0xe
       
    49             // mask is 0xffffc000
       
    50             // base.Address is 0x802e20ac
       
    51 
       
    52             // 11111111 11111111 11000000 00000000 = mask
       
    53             // 10000000 00101110 01100110 10101100
       
    54             // 10000000 00101110 01000000 00000000
       
    55 
       
    56             // Next, we want to apply that mask to the current address
       
    57             // in order to prepare for the new values. 
       
    58             //
       
    59             // I.e. preserve any bits we know but aren't changing, and then
       
    60             // clear all other bits that we're about to set below.
       
    61             base.Address &= mask;
       
    62 
       
    63             // Now we can merge in the new bits
       
    64             base.Address |= aAddress;
       
    65 
       
    66             // Save how many valid bits of the address we currently have for debugging
       
    67             // purposes
       
    68             iKnownBits = Math.Max( iKnownBits, aNumberOfValidBits );
       
    69             System.Diagnostics.Debug.Assert( iKnownBits >= 0 && iKnownBits <= 32 );
       
    70         }
       
    71         #endregion
       
    72 
       
    73         #region Properties
       
    74         public int KnownBits
       
    75         {
       
    76             get { return iKnownBits; }
       
    77             set { iKnownBits = value; }
       
    78         }
       
    79 
       
    80         public bool IsKnown
       
    81         {
       
    82             get { return iKnownBits == 32; }
       
    83         }
       
    84 
       
    85         public bool IsPartial
       
    86         {
       
    87             get { return iKnownBits > 0; }
       
    88         }
       
    89 
       
    90         public bool IsUnknown
       
    91         {
       
    92             get { return iKnownBits == 0; }
       
    93         }
       
    94 
       
    95         public override string AddressBinary
       
    96         {
       
    97             get
       
    98             {
       
    99                 string ret = SymBitUtils.BeautifyBits( base.Address, iKnownBits );
       
   100                 return ret;
       
   101             }
       
   102         }
       
   103 
       
   104         public override string AddressHex
       
   105         {
       
   106             get
       
   107             {
       
   108                 // Work out how many nibbles we have
       
   109                 int validNibbles = 0;
       
   110                 for ( ; validNibbles < iKnownBits; validNibbles += 4 )
       
   111                 {
       
   112                 }
       
   113                 validNibbles /= 4; // Convert bits to nibbles
       
   114                 int invalidNibbles = 8 - validNibbles;
       
   115 
       
   116                 StringBuilder text = new StringBuilder();
       
   117                 text.Append( string.Empty.PadLeft( invalidNibbles, '?' ) );
       
   118                 text.Append( base.Address.ToString( string.Format( "x{0}", validNibbles ) ) );
       
   119                 text.Length = Math.Min( 8, text.Length );
       
   120                 return text.ToString();
       
   121             }
       
   122         }
       
   123         #endregion
       
   124 
       
   125         #region Operators
       
   126         public static implicit operator uint( SymAddressWithKnownBits aAddress )
       
   127         {
       
   128             return aAddress.Address;
       
   129         }
       
   130         #endregion
       
   131 
       
   132         #region Internal methods
       
   133         #endregion
       
   134 
       
   135         #region Data members
       
   136         private int iKnownBits = 0;
       
   137         #endregion
       
   138     }
       
   139 }