Update contrib.
1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 #include "codespace.h"
21 #pragma warning(push, 3) // cannot compile MSVC's STL at warning level 4
22 #pragma warning(disable: 4786 4710 4530)
25 #else //!__MSVCDOTNET__
28 #endif //__MSVCDOTNET__
34 int CodeSpace::Size() const
39 int CodeSpace::Bucket(PC) const
44 const char* CodeSpace::Name(int) const
49 CodeSpace::TOrder CodeSpace::Ordering() const
55 // class AddressCodeSpace
57 AddressCodeSpace::AddressCodeSpace(PC aBase, PC aLimit, unsigned aBucketSize, TType aType)
58 :iBase(aBase), iType(aType)
63 for (shift = 0; (aBucketSize >> shift) != 1; ++shift)
66 iBuckets = (aLimit - aBase + (1u << shift) - 1) >> shift;
69 int AddressCodeSpace::Size() const
74 int AddressCodeSpace::Bucket(PC aPc) const
78 unsigned bucket = (aPc - iBase) >> iBucketShift;
79 if (bucket < iBuckets)
85 const char* AddressCodeSpace::Name(int aBucket) const
87 if (aBucket == KOtherBucket)
88 return CodeSpace::Name(aBucket);
90 unsigned offset = ((aBucket - 1) << iBucketShift);
91 strstream s(iBuffer, sizeof(iBuffer), ios::out);
92 s << hex << setfill('0');
93 if (iType == EAbsolute)
94 s << setw(8) << iBase + offset;
96 s << "+ " << setw(4) << offset;
97 s << setfill(' ') << '\0';
101 CodeSpace::TOrder AddressCodeSpace::Ordering() const
103 return (iType == EAbsolute) ? EOrdered : ELinear;
107 // class MappedCodeSpace
109 MappedCodeSpace::MappedCodeSpace(const SymbolFile& aSymbols, MappedCodeSpace::Partition& aPartition)
111 aPartition.iCodeSpace = this;
112 aSymbols.Parse(aPartition);
115 MappedCodeSpace::MappedCodeSpace()
118 const MappedCodeSpace::Element* MappedCodeSpace::Find(PC aPc) const
120 // Find and return the element which contains this PC value
121 // If not mapped return 0
124 Map::const_iterator e = iMap.upper_bound(aPc);
126 // ignore deleted segments
127 for(;e != iMap.end() && aPc >= e->second.iBase;e++)
128 if (!e->second.iUnloaded)
133 std::pair<const char*,unsigned> MappedCodeSpace::Lookup(PC aPc) const
135 const Element* e = Find(aPc);
137 return std::pair<const char*,unsigned>(0, aPc);
138 return std::pair<const char*,unsigned>(e->iName, aPc - e->iBase);
141 int MappedCodeSpace::Size() const
143 return iMap.size() + 1;
146 int MappedCodeSpace::Bucket(PC aPc) const
148 const Element* e = Find(aPc);
149 return (e == 0) ? KOtherBucket : e->iBucket + 1;
152 const char* MappedCodeSpace::Name(int aBucket) const
154 return (aBucket == KOtherBucket) ? CodeSpace::Name(aBucket) : iNames[aBucket - 1];
157 void MappedCodeSpace::Add(PC aBase, PC aLimit, const char* aName)
160 iMap.insert(Map::value_type(aLimit, Element(aBase, aLimit, aName)));
163 void MappedCodeSpace::Done(PC aFirstPc, PC aLastPc, int aModuleId)
168 for (Map::iterator p = iMap.begin(), e = iMap.end(); p != e; ++p)
170 p->second.iBucket = iNames.size();
171 iNames.push_back(p->second.iName);
176 Map::iterator p = iMap.find(aFirstPc);
177 _ASSERT(p != iMap.end());
178 for (Map::iterator e = iMap.end(); p != e && p->first <= aLastPc; ++p)
180 if (p->second.iUnloaded)
184 NamesMap::iterator pMap = iNamesMap.find(p->second.iName);
185 if (pMap != iNamesMap.end())
186 for(;!strcmp(p->second.iName, pMap->first);pMap++)
187 if (pMap->second.iId == aModuleId)
193 p->second.iBucket = pMap->second.iIndex;
196 p->second.iBucket = iNames.size();
197 iNames.push_back(p->second.iName);
198 iNamesMap.insert(NamesMap::value_type(p->second.iName, IdNames(aModuleId, p->second.iBucket)));