1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32utils/analyse/nonxip.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,141 @@
1.4 +/*
1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +#include "nonxip.h"
1.21 +#include "analyse.h"
1.22 +#include "obyfile.h"
1.23 +#include <crtdbg.h>
1.24 +#include <ctype.h>
1.25 +
1.26 +
1.27 +NonXIP::NonXIP()
1.28 + :iCodeSpace(0), iCurId(1), iRowBufferErrors(0), iCookBufferErrors(0), iReportMask(0)
1.29 + {}
1.30 +
1.31 +NonXIP::~NonXIP()
1.32 + {
1.33 + for(std::vector<SymbolFile*>::iterator it = iSymbols.begin();it != iSymbols.end();it++)
1.34 + delete *it;
1.35 + }
1.36 +
1.37 +void NonXIP::AddObyNames(const char* aSegName, const char* aOrigName)
1.38 + {
1.39 + iNamesMap[aSegName] = OrigName(aOrigName,iCurId++);
1.40 + }
1.41 +
1.42 +void NonXIP::CreateNamesMap()
1.43 + {
1.44 + for(FilesVec::const_iterator it=iObyFiles.begin();it != iObyFiles.end();it++)
1.45 + {
1.46 + ObyFile file(it->c_str());
1.47 + file.Parse(this);
1.48 + }
1.49 +
1.50 + for(FilesVec::const_iterator it_s=iSymbolFiles.begin();it_s != iSymbolFiles.end();it_s++)
1.51 + {
1.52 + iSymbols.push_back(new SymbolFile(it_s->c_str(), true));
1.53 + }
1.54 + }
1.55 +
1.56 +
1.57 +
1.58 +void NonXIP::AddSegment(PC aAddress, PC aSegSize, const char *aSegName)
1.59 + {
1.60 + if (!iCodeSpace) return;
1.61 +
1.62 + char buf[257];
1.63 + for(char * p = buf;*aSegName;aSegName++,p++)
1.64 + *p = tolower(*aSegName);
1.65 + *p = '\0';
1.66 + NamesMap::const_iterator it = iNamesMap.find(buf);
1.67 + if (it == iNamesMap.end()) // not found
1.68 + return;
1.69 +
1.70 + const char* orig_name = it->second.iName.c_str();
1.71 +
1.72 + if(TryUnDeleteSegment(aAddress, aSegSize, orig_name))
1.73 + return;
1.74 +
1.75 + int id = it->second.iId;
1.76 +
1.77 + Segment seg;
1.78 + seg.iSegSize = aSegSize;
1.79 + seg.iName = it;
1.80 + seg.iUnloaded = false;
1.81 +
1.82 + PartitionByFunction pf(0, 0);
1.83 + PartitionByDll pd(0);
1.84 + MappedCodeSpace::Partition* pt;
1.85 + if (Analyse::Action() == Analyse::EProfile && Analyse::Partition() == Analyse::EDll)
1.86 + pt = &pd;
1.87 + else
1.88 + pt = &pf;
1.89 +
1.90 + pt->iCodeSpace = iCodeSpace;
1.91 +
1.92 + // loop on symbol files
1.93 + for(std::vector<SymbolFile*>::iterator its = iSymbols.begin();its != iSymbols.end();its++)
1.94 + if ((*its)->Parse(*pt, orig_name, aAddress, aSegSize, id)) // found
1.95 + break;
1.96 +
1.97 + iSegData[aAddress] = seg;
1.98 + }
1.99 +
1.100 +
1.101 +void NonXIP::DeleteSegment(PC aAddress)
1.102 + {
1.103 + if (!iCodeSpace) return;
1.104 +
1.105 + SegData::iterator it = iSegData.find(aAddress);
1.106 + if (it == iSegData.end())
1.107 + return;
1.108 +
1.109 + Segment seg(it->second);
1.110 + PC high_bound = aAddress+seg.iSegSize;
1.111 +
1.112 + // find aAddress in iCodeSpace->iMap
1.113 + MappedCodeSpace::Map::iterator itm = iCodeSpace->iMap.upper_bound(aAddress);
1.114 + for(;itm != iCodeSpace->iMap.end() && itm->first <= high_bound;itm++)
1.115 + if (!itm->second.iUnloaded)
1.116 + itm->second.iUnloaded = true;
1.117 +
1.118 + seg.iUnloaded = true;
1.119 + }
1.120 +
1.121 +bool NonXIP::TryUnDeleteSegment(PC aAddress, PC aSegSize, const char *aSegName)
1.122 + {
1.123 + if (!iCodeSpace) return false;
1.124 +
1.125 + SegData::iterator it = iSegData.find(aAddress);
1.126 + if (it == iSegData.end())
1.127 + return false;
1.128 +
1.129 + Segment seg(it->second);
1.130 + PC high_bound = aAddress+seg.iSegSize;
1.131 +
1.132 + if(aSegSize != seg.iSegSize || strcmp(aSegName, seg.iName->second.iName.c_str()))
1.133 + return false;
1.134 +
1.135 + // find aAddress in iCodeSpace->iMap
1.136 + MappedCodeSpace::Map::iterator itm = iCodeSpace->iMap.upper_bound(aAddress);
1.137 + for(;itm != iCodeSpace->iMap.end() && itm->first <= high_bound;itm++)
1.138 + if (itm->second.iUnloaded)
1.139 + itm->second.iUnloaded = false;
1.140 +
1.141 + seg.iUnloaded = false;
1.142 +
1.143 + return true;
1.144 + }