crashanalysercmd/Libraries/File Formats/Plugins/XmlFilePlugin/FileFormat/CXmlRegisterStorage.cs
changeset 2 0c91f0baec58
equal deleted inserted replaced
1:7a31f7298d8f 2:0c91f0baec58
       
     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 * The class CCrashInfoRegisterStorage is part of CrashAnalyser CrashInfoFile plugin.
       
    16 * Temporary container for arm register list information conversion from
       
    17 * CrashAnalyser data to CrashInfoFile document.
       
    18 * Reads register info from CIRegisterList structures and outputs formatted
       
    19 * CrashInfo file rows.
       
    20 * 
       
    21 */
       
    22 
       
    23 using System;
       
    24 using System.Collections.Generic;
       
    25 using System.Text;
       
    26 using CrashItemLib.Crash.Registers;
       
    27 
       
    28 namespace XmlFilePlugin.PluginImplementations.FileFormat
       
    29 {
       
    30     internal class CXmlRegisterStorage
       
    31     {
       
    32         #region Constructors
       
    33         public CXmlRegisterStorage()           
       
    34 		{
       
    35         
       
    36 		}
       
    37 		#endregion
       
    38 
       
    39         public void ReadRegisterData(CIRegisterList aRegList)
       
    40         {
       
    41             //If long enough reglist starts with R0, it is assumed to be the "basic" register list (R0-R15)
       
    42             if (aRegList.Count > 15 && aRegList[0].Type == SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_00)
       
    43             {
       
    44                 iBasicRegs.Name = aRegList.Name;
       
    45                 foreach (CIRegister register in aRegList)
       
    46                 {
       
    47                     string regName = GetRegisterName(register);      
       
    48 
       
    49                     CCrasInfoRegisterItem regItem = new CCrasInfoRegisterItem(regName, register.Value);
       
    50 
       
    51                     if (register.Symbol != null && CXmlFileUtilities.IsSymbolSerializable(register.Symbol))
       
    52                     {                        
       
    53                         regItem.Symbol = register.Symbol.Name;
       
    54                     }
       
    55 
       
    56                     iBasicRegs.Registers.Add(regItem);
       
    57 
       
    58                     //Check if this is PC and save it separately
       
    59                     if (register.Type == SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_PC)
       
    60                     {
       
    61                         iProgramCounter.Value = register.Value;
       
    62                         iProgramCounter.Symbol = register.Symbol.Name;
       
    63                     }
       
    64                 }
       
    65             }
       
    66             else //all other registers as their own list
       
    67             {
       
    68                 CCrashInfoRegisterList regs = new CCrashInfoRegisterList();
       
    69                 regs.Name = aRegList.Name;
       
    70                 bool hasRealData = false;
       
    71                 foreach (CIRegister register in aRegList)
       
    72                 {
       
    73                     string regName = GetRegisterName(register);
       
    74                     CCrasInfoRegisterItem regItem = new CCrasInfoRegisterItem(regName, register.Value);
       
    75                     if (register.Symbol != null && CXmlFileUtilities.IsSymbolSerializable(register.Symbol))
       
    76                     {
       
    77                         regItem.Symbol = register.Symbol.Name;
       
    78                     }
       
    79 
       
    80                     regs.Registers.Add(regItem);
       
    81 
       
    82                     if (register.Value != 0)
       
    83                     {
       
    84                         hasRealData = true;
       
    85                     }
       
    86                 }
       
    87 
       
    88                 if (hasRealData)
       
    89                 {
       
    90                     iOtherRegLists.Add(regs);
       
    91                 }
       
    92             }
       
    93         }
       
    94         // Return CrashInfo compatible register name - R0-R15 in short numeric form, other as they are 
       
    95         public static string GetRegisterName(CIRegister aRegister)
       
    96         {
       
    97             string ret = aRegister.Name;
       
    98             //
       
    99             switch (aRegister.Type)
       
   100             {
       
   101                 case SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_00:
       
   102                     ret = "R0";
       
   103                     break;
       
   104                 case SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_01:
       
   105                     ret = "R1";
       
   106                     break;
       
   107                 case SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_02:
       
   108                     ret = "R2";
       
   109                     break;
       
   110                 case SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_03:
       
   111                     ret = "R3";
       
   112                     break;
       
   113                 case SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_04:
       
   114                     ret = "R4";
       
   115                     break;
       
   116                 case SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_05:
       
   117                     ret = "R5";
       
   118                     break;
       
   119                 case SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_06:
       
   120                     ret = "R6";
       
   121                     break;
       
   122                 case SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_07:
       
   123                     ret = "R7";
       
   124                     break;
       
   125                 case SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_08:
       
   126                     ret = "R8";
       
   127                     break;
       
   128                 case SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_09:
       
   129                     ret = "R9";
       
   130                     break;
       
   131                 case SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_10:
       
   132                     ret = "R10";
       
   133                     break;
       
   134                 case SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_11:
       
   135                     ret = "R11";
       
   136                     break;
       
   137                 case SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_12:
       
   138                     ret = "R12";
       
   139                     break;
       
   140                 case SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_SP:
       
   141                     ret = "R13";
       
   142                     break;
       
   143                 case SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_LR:
       
   144                     ret = "R14";
       
   145                     break;
       
   146                 case SymbianStructuresLib.Arm.Registers.TArmRegisterType.EArmReg_PC:
       
   147                     ret = "R15";
       
   148                     break;
       
   149                 default:
       
   150                     break;
       
   151             }
       
   152             //
       
   153             return ret;
       
   154         }
       
   155 
       
   156         #region Getters
       
   157         internal CCrashInfoRegisterList BasicRegs()
       
   158         {
       
   159             return iBasicRegs;
       
   160         }
       
   161 
       
   162         internal List<CCrashInfoRegisterList> OtherRegLists()
       
   163         {
       
   164             return iOtherRegLists;
       
   165         }
       
   166 
       
   167         internal CCrasInfoRegisterItem ProgramCounter()
       
   168         {
       
   169             return iProgramCounter;
       
   170         }
       
   171 
       
   172         #endregion
       
   173 
       
   174 
       
   175         #region Data Members
       
   176         private CCrashInfoRegisterList iBasicRegs = new CCrashInfoRegisterList(); //R0-R15
       
   177         private List<CCrashInfoRegisterList> iOtherRegLists = new List<CCrashInfoRegisterList>(); //Other registers
       
   178         private CCrasInfoRegisterItem iProgramCounter = new CCrasInfoRegisterItem("PC");
       
   179 
       
   180         #endregion
       
   181 
       
   182         #region Nested Classes
       
   183         internal class CCrashInfoRegisterList
       
   184         {
       
   185             #region Constructors
       
   186             public CCrashInfoRegisterList()
       
   187             {
       
   188 
       
   189             }
       
   190             #endregion
       
   191 
       
   192             public string ToPrettyString()
       
   193             {
       
   194                 System.Text.StringBuilder output = new System.Text.StringBuilder();
       
   195 
       
   196                 if (iRegisters.Count > 0)
       
   197                 {
       
   198                     output.AppendLine(iName);
       
   199                     foreach (CCrasInfoRegisterItem reg in iRegisters)
       
   200                     {
       
   201                         if (reg.Symbol != string.Empty)
       
   202                         {
       
   203                             output.AppendLine(reg.Name + " 0x" + reg.Value.ToString("X8") + " " + reg.Symbol);
       
   204                         }
       
   205                         else
       
   206                         {
       
   207                             output.AppendLine(reg.Name + " 0x" + reg.Value.ToString("X8"));
       
   208                         }
       
   209                     }
       
   210                 }
       
   211                 return output.ToString();
       
   212             }
       
   213 
       
   214 
       
   215             public override string ToString()
       
   216             {
       
   217                 string output = "";
       
   218                 if (iRegisters.Count > 0)
       
   219                 {
       
   220                     output += iName;
       
   221                     foreach (CCrasInfoRegisterItem reg in iRegisters)
       
   222                     {
       
   223                         output += XmlConsts.Kxml_separator;
       
   224                         output += reg.Name;
       
   225                         output += XmlConsts.Kxml_separator;
       
   226                         output += reg.Value;
       
   227                         if (reg.Symbol != string.Empty)
       
   228                         {
       
   229                             output += ":";
       
   230                             output += reg.Symbol;
       
   231                         }
       
   232                     }
       
   233                 }
       
   234                 return output; 
       
   235             }
       
   236 
       
   237             #region Properties
       
   238             public List<CCrasInfoRegisterItem> Registers
       
   239             {
       
   240                 get { return iRegisters; }
       
   241                 set { iRegisters = value; }
       
   242             }
       
   243             public string Name
       
   244             {
       
   245                 get { return iName; }
       
   246                 set { iName = value; }
       
   247             }
       
   248 
       
   249             #endregion
       
   250 
       
   251             private List<CCrasInfoRegisterItem> iRegisters = new List<CCrasInfoRegisterItem>();            
       
   252             private string iName;
       
   253 
       
   254            
       
   255         }
       
   256 
       
   257         internal class CCrasInfoRegisterItem
       
   258         {
       
   259             #region Constructors
       
   260             public CCrasInfoRegisterItem(string aName)
       
   261             {
       
   262                 iName = aName;
       
   263             }
       
   264 
       
   265             public CCrasInfoRegisterItem(string aName, uint aValue)
       
   266             {
       
   267                 iName = aName;
       
   268                 iValue = aValue;
       
   269             }
       
   270 
       
   271             #endregion
       
   272 
       
   273             #region Properties
       
   274             public string Name
       
   275             {
       
   276                 get { return iName; }
       
   277                 set { iName = value; }
       
   278             }
       
   279 
       
   280             public uint Value
       
   281             {
       
   282                 get { return iValue; }
       
   283                 set { iValue = value; }
       
   284             }
       
   285 
       
   286             public string Symbol
       
   287             {
       
   288                 get { return iSymbol; }
       
   289                 set { iSymbol = value; }
       
   290             }
       
   291 
       
   292             #endregion
       
   293 
       
   294 
       
   295             #region Data Members
       
   296 
       
   297             private uint iValue = 0;
       
   298             private string iName = string.Empty;
       
   299             private string iSymbol = string.Empty;
       
   300 
       
   301             #endregion
       
   302         }
       
   303 
       
   304         #endregion
       
   305 
       
   306 
       
   307 
       
   308 
       
   309 
       
   310     }
       
   311 
       
   312     
       
   313 }