0
|
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 the License "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 |
#include "nonxip.h"
|
|
18 |
#include "analyse.h"
|
|
19 |
#include "obyfile.h"
|
|
20 |
#include <crtdbg.h>
|
|
21 |
#include <ctype.h>
|
|
22 |
|
|
23 |
|
|
24 |
NonXIP::NonXIP()
|
|
25 |
:iCodeSpace(0), iCurId(1), iRowBufferErrors(0), iCookBufferErrors(0), iReportMask(0)
|
|
26 |
{}
|
|
27 |
|
|
28 |
NonXIP::~NonXIP()
|
|
29 |
{
|
|
30 |
for(std::vector<SymbolFile*>::iterator it = iSymbols.begin();it != iSymbols.end();it++)
|
|
31 |
delete *it;
|
|
32 |
}
|
|
33 |
|
|
34 |
void NonXIP::AddObyNames(const char* aSegName, const char* aOrigName)
|
|
35 |
{
|
|
36 |
iNamesMap[aSegName] = OrigName(aOrigName,iCurId++);
|
|
37 |
}
|
|
38 |
|
|
39 |
void NonXIP::CreateNamesMap()
|
|
40 |
{
|
|
41 |
for(FilesVec::const_iterator it=iObyFiles.begin();it != iObyFiles.end();it++)
|
|
42 |
{
|
|
43 |
ObyFile file(it->c_str());
|
|
44 |
file.Parse(this);
|
|
45 |
}
|
|
46 |
|
|
47 |
for(FilesVec::const_iterator it_s=iSymbolFiles.begin();it_s != iSymbolFiles.end();it_s++)
|
|
48 |
{
|
|
49 |
iSymbols.push_back(new SymbolFile(it_s->c_str(), true));
|
|
50 |
}
|
|
51 |
}
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
void NonXIP::AddSegment(PC aAddress, PC aSegSize, const char *aSegName)
|
|
56 |
{
|
|
57 |
if (!iCodeSpace) return;
|
|
58 |
|
|
59 |
char buf[257];
|
|
60 |
for(char * p = buf;*aSegName;aSegName++,p++)
|
|
61 |
*p = tolower(*aSegName);
|
|
62 |
*p = '\0';
|
|
63 |
NamesMap::const_iterator it = iNamesMap.find(buf);
|
|
64 |
if (it == iNamesMap.end()) // not found
|
|
65 |
return;
|
|
66 |
|
|
67 |
const char* orig_name = it->second.iName.c_str();
|
|
68 |
|
|
69 |
if(TryUnDeleteSegment(aAddress, aSegSize, orig_name))
|
|
70 |
return;
|
|
71 |
|
|
72 |
int id = it->second.iId;
|
|
73 |
|
|
74 |
Segment seg;
|
|
75 |
seg.iSegSize = aSegSize;
|
|
76 |
seg.iName = it;
|
|
77 |
seg.iUnloaded = false;
|
|
78 |
|
|
79 |
PartitionByFunction pf(0, 0);
|
|
80 |
PartitionByDll pd(0);
|
|
81 |
MappedCodeSpace::Partition* pt;
|
|
82 |
if (Analyse::Action() == Analyse::EProfile && Analyse::Partition() == Analyse::EDll)
|
|
83 |
pt = &pd;
|
|
84 |
else
|
|
85 |
pt = &pf;
|
|
86 |
|
|
87 |
pt->iCodeSpace = iCodeSpace;
|
|
88 |
|
|
89 |
// loop on symbol files
|
|
90 |
for(std::vector<SymbolFile*>::iterator its = iSymbols.begin();its != iSymbols.end();its++)
|
|
91 |
if ((*its)->Parse(*pt, orig_name, aAddress, aSegSize, id)) // found
|
|
92 |
break;
|
|
93 |
|
|
94 |
iSegData[aAddress] = seg;
|
|
95 |
}
|
|
96 |
|
|
97 |
|
|
98 |
void NonXIP::DeleteSegment(PC aAddress)
|
|
99 |
{
|
|
100 |
if (!iCodeSpace) return;
|
|
101 |
|
|
102 |
SegData::iterator it = iSegData.find(aAddress);
|
|
103 |
if (it == iSegData.end())
|
|
104 |
return;
|
|
105 |
|
|
106 |
Segment seg(it->second);
|
|
107 |
PC high_bound = aAddress+seg.iSegSize;
|
|
108 |
|
|
109 |
// find aAddress in iCodeSpace->iMap
|
|
110 |
MappedCodeSpace::Map::iterator itm = iCodeSpace->iMap.upper_bound(aAddress);
|
|
111 |
for(;itm != iCodeSpace->iMap.end() && itm->first <= high_bound;itm++)
|
|
112 |
if (!itm->second.iUnloaded)
|
|
113 |
itm->second.iUnloaded = true;
|
|
114 |
|
|
115 |
seg.iUnloaded = true;
|
|
116 |
}
|
|
117 |
|
|
118 |
bool NonXIP::TryUnDeleteSegment(PC aAddress, PC aSegSize, const char *aSegName)
|
|
119 |
{
|
|
120 |
if (!iCodeSpace) return false;
|
|
121 |
|
|
122 |
SegData::iterator it = iSegData.find(aAddress);
|
|
123 |
if (it == iSegData.end())
|
|
124 |
return false;
|
|
125 |
|
|
126 |
Segment seg(it->second);
|
|
127 |
PC high_bound = aAddress+seg.iSegSize;
|
|
128 |
|
|
129 |
if(aSegSize != seg.iSegSize || strcmp(aSegName, seg.iName->second.iName.c_str()))
|
|
130 |
return false;
|
|
131 |
|
|
132 |
// find aAddress in iCodeSpace->iMap
|
|
133 |
MappedCodeSpace::Map::iterator itm = iCodeSpace->iMap.upper_bound(aAddress);
|
|
134 |
for(;itm != iCodeSpace->iMap.end() && itm->first <= high_bound;itm++)
|
|
135 |
if (itm->second.iUnloaded)
|
|
136 |
itm->second.iUnloaded = false;
|
|
137 |
|
|
138 |
seg.iUnloaded = false;
|
|
139 |
|
|
140 |
return true;
|
|
141 |
}
|