tools/elf4rom/src/dwarfmanager.h
changeset 34 92d87f2e53c2
equal deleted inserted replaced
33:1af5c1be89f8 34:92d87f2e53c2
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, either version 3 of the License, or
       
     8 * (at your option) any later version.
       
     9 *
       
    10 * This program is distributed in the hope that it will be useful,
       
    11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13 * GNU Lesser General Public License for more details.
       
    14 * 
       
    15 * You should have received a copy of the GNU Lesser General Public License
       
    16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
       
    17 */
       
    18 
       
    19 #ifndef DWARFMANAGER_H_
       
    20 #define DWARFMANAGER_H_
       
    21 
       
    22 #include <vector>
       
    23 #include <map>
       
    24 #include <string>
       
    25 #include <libelf.h>
       
    26 
       
    27 #include "dwarfdefs.h"
       
    28 #include "dwarf.h"
       
    29 #include "defs.h"
       
    30 #include "filefragment.h"
       
    31 #include "romdetails.h"
       
    32 #include "elfsectionmanager.h"
       
    33 
       
    34 using namespace std;
       
    35 
       
    36 class FileShdrPair {
       
    37 public:
       
    38 	FileShdrPair(XIPFileDetails & aXIPFileDetails, Elf32_Shdr * aShdr):
       
    39 		iXIPFileDetails(aXIPFileDetails),
       
    40 		iShdr(*aShdr)
       
    41 	{}
       
    42 	FileShdrPair & FileShdrPair::operator=(const FileShdrPair & aFileShdrPair) {
       
    43 		iXIPFileDetails = aFileShdrPair.iXIPFileDetails;
       
    44 		iShdr = aFileShdrPair.iShdr;
       
    45 		return *this;
       
    46 	}
       
    47 
       
    48 	FileShdrPair::FileShdrPair(const FileShdrPair &aFileShdrPair):
       
    49 		iXIPFileDetails(aFileShdrPair.iXIPFileDetails),
       
    50 		iShdr(aFileShdrPair.iShdr)
       
    51 	{}
       
    52 	
       
    53 	XIPFileDetails & iXIPFileDetails;
       
    54 	Elf32_Shdr iShdr;
       
    55 };
       
    56 
       
    57 typedef std::vector<FileShdrPair> FileShdrList;
       
    58 
       
    59 void EditLocationExpression (Dwarf_Byte_Ptr data, 
       
    60 							 unsigned int pointer_size, 
       
    61 							 unsigned long length, 
       
    62 							 FileShdrPair & aPair);
       
    63 class DwarfManager;
       
    64 
       
    65 class DwarfSectionManager : public FileFragmentOwner {
       
    66 public:
       
    67 	DwarfSectionManager(ElfSectionManager & aElfSectionManager, 
       
    68 						DwarfManager & aDwarfManager, 
       
    69 						const string & aName, 
       
    70 						RomDetails * aRomDetails):
       
    71 		iElfSectionManager(aElfSectionManager),
       
    72 		iDwarfManager(aDwarfManager),
       
    73 		iSectionName(aName),
       
    74 		iSizeValid(false),
       
    75 		iSize(0),
       
    76 		iData(NULL),
       
    77 		iRomDetails(aRomDetails)
       
    78 	{}
       
    79 	
       
    80 	virtual ~DwarfSectionManager() {
       
    81 		iFileShdrList.clear();
       
    82 	}
       
    83 	
       
    84 	// The FileFragmentOwner protocol
       
    85 	virtual void DeleteFileFragmentData(){
       
    86 		if (iData) {
       
    87 			Dwarf_Byte_Ptr d = iData;
       
    88 			iData = NULL;
       
    89 			delete [] d;
       
    90 		}
       
    91 	}
       
    92 
       
    93 	virtual void AddSection(XIPFileDetails & aXIPFileDetails, Elf32_Shdr * aShdr);
       
    94 	virtual void SetupSection();
       
    95 	const string & GetSectionName() { return iSectionName; }
       
    96 	virtual Dwarf_Byte_Ptr GetSectionData(FileShdrPair & aPair);
       
    97 		
       
    98 
       
    99 	
       
   100 	// LEB decoding
       
   101 	// Leb128 decoding used by all Dwarf section managers (potentially)
       
   102 	// TODO could get rid of LEB macros and define as inline functions.
       
   103 #define DECODE_ULEB128(v,p,n) \
       
   104 		Dwarf_Word v = DwarfSectionManager::DecodeUnsignedLeb128(p, n);\
       
   105 		p += n;
       
   106 #define ULEB128(p,n) \
       
   107 		DwarfSectionManager::DecodeUnsignedLeb128(p, n);\
       
   108 		p += n;
       
   109 	static Dwarf_Unsigned DecodeUnsignedLeb128(Dwarf_Byte_Ptr leb128, size_t & leb128_length);
       
   110 #define DECODE_SLEB128(v,p,n) \
       
   111 		Dwarf_Word v = DwarfSectionManager::DecodeSignedLeb128(p, n);\
       
   112 		p += n;
       
   113 #define SLEB128(p,n) \
       
   114 		DwarfSectionManager::DecodeSignedLeb128(p, n);\
       
   115 		p += n;
       
   116 	static Dwarf_Signed DecodeSignedLeb128(Dwarf_Byte_Ptr leb128, size_t & leb128_length);
       
   117 	
       
   118 private:
       
   119 	// Don't want one of these to be copied
       
   120 	DwarfSectionManager(const DwarfSectionManager & aDwarfSectionManager);
       
   121 	
       
   122 	DwarfSectionManager & operator=(const DwarfSectionManager & aDwarfSectionManager);
       
   123 protected:
       
   124 
       
   125 	virtual Dwarf_Byte_Ptr GetData(){ return iData; }
       
   126 	virtual void SetData(Dwarf_Byte_Ptr data) { iData = data; }
       
   127 	
       
   128 	size_t CheckNewOffset(size_t base, size_t offset){
       
   129 		const Dwarf_Off limit = 0xfffffff0ul;
       
   130 		Dwarf_Off newOffset = base + offset;
       
   131 		if (newOffset >= limit) {
       
   132 			cerr << "Error: cannot support transition from 32 to 64 bit offsets\n";
       
   133 			exit(EXIT_FAILURE);
       
   134 		}
       
   135 		return (size_t)newOffset;
       
   136 	}
       
   137 	
       
   138 protected:
       
   139 	ElfSectionManager & iElfSectionManager;
       
   140 	DwarfManager & iDwarfManager;
       
   141 	FileShdrList iFileShdrList;
       
   142 	const string iSectionName;
       
   143 	bool iSizeValid;
       
   144 	size_t iSize;
       
   145 	Dwarf_Byte_Ptr iData;
       
   146 	RomDetails * iRomDetails;
       
   147 };
       
   148 
       
   149 class DwarfConcatenatedSectionManager : public DwarfSectionManager {
       
   150 public:
       
   151 	DwarfConcatenatedSectionManager(ElfSectionManager & aElfSectionManager, 
       
   152 									DwarfManager & aDwarfManager, 
       
   153 									const string & aName, 
       
   154 									RomDetails * aRomDetails):
       
   155 		DwarfSectionManager(aElfSectionManager, 
       
   156 							aDwarfManager, 
       
   157 							aName, 
       
   158 							aRomDetails)
       
   159 	{}
       
   160 	
       
   161 	// The FileFragmentOwner protocol
       
   162 	virtual void GetFileFragmentData(FileFragmentData & aFileFragmentData );
       
   163 	virtual size_t Size();
       
   164 	
       
   165 	virtual void ConcatenateData();
       
   166 	virtual void ProcessSection(FileShdrPair & aPair);
       
   167 	virtual void ProcessSection(FileShdrPair & aPair, Dwarf_Byte_Ptr start, Dwarf_Byte_Ptr end){};
       
   168 	
       
   169 	// Concatenated section protocol
       
   170 	virtual void SetSectionOffset(PathName & aPathName, size_t aOffset);
       
   171 	virtual void InitOffsetMap();
       
   172 	virtual size_t GetSectionOffset(PathName & aPathName);
       
   173 	virtual void SetSectionSize(PathName & aPathName, size_t aSize);
       
   174 	virtual size_t GetSectionSize(PathName & aPathName);
       
   175 	
       
   176 	Dwarf_Byte_Ptr GetSection(PathName & aPathName);
       
   177 	
       
   178 protected:
       
   179 	typedef std::map<PathName, size_t> PathNameSectionOffsetMap;
       
   180 	PathNameSectionOffsetMap iPathNameSectionOffsetMap;
       
   181 	PathNameSectionOffsetMap iPathNameSectionSizeMap;
       
   182 
       
   183 
       
   184 };
       
   185 
       
   186 class DwarfFragmentedSectionManager : public DwarfConcatenatedSectionManager {
       
   187 public:
       
   188 	DwarfFragmentedSectionManager(ElfSectionManager & aElfSectionManager, 
       
   189 									DwarfManager & aDwarfManager, 
       
   190 									const string & aName, 
       
   191 									RomDetails * aRomDetails):
       
   192 		DwarfConcatenatedSectionManager(aElfSectionManager, 
       
   193 										aDwarfManager, 
       
   194 										aName, 
       
   195 										aRomDetails),
       
   196 		iInitialTraceMessage(true)
       
   197 	{}
       
   198 	
       
   199 	// Override the method of setting up the section
       
   200 	virtual void SetupSection();
       
   201 
       
   202 	// The FileFragmentOwner protocol
       
   203 	virtual void GetFileFragmentData(FileFragmentData & aFileFragmentData );
       
   204 	//virtual size_t Size();
       
   205 	
       
   206 	virtual void ConcatenateData();
       
   207 	
       
   208 	void ProcessSection(FileShdrPair & aPair, Dwarf_Byte_Ptr & aData);
       
   209 	virtual void ProcessSection(FileShdrPair & aPair, Dwarf_Byte_Ptr start, Dwarf_Byte_Ptr end) = 0;
       
   210 	
       
   211 private:
       
   212 	bool iInitialTraceMessage;
       
   213 
       
   214 };
       
   215 
       
   216 class DebugAbbrevAttrForm {
       
   217 public:
       
   218 	DebugAbbrevAttrForm():
       
   219 			iAttr(0),
       
   220 			iForm(0)
       
   221 		{}
       
   222 	DebugAbbrevAttrForm(Dwarf_Half a, Dwarf_Half f):
       
   223 		iAttr(a),
       
   224 		iForm(f)
       
   225 	{}
       
   226 	Dwarf_Half iAttr;
       
   227 	Dwarf_Half iForm;
       
   228 };
       
   229 
       
   230 class DebugAbbrev {
       
   231 public:
       
   232 	DebugAbbrev():
       
   233 		iCode(0),
       
   234 		iTag(0),
       
   235 		iCount(0),
       
   236 		iRaw(NULL),
       
   237 		iParsed(NULL)
       
   238 		{}
       
   239 	DebugAbbrev(Dwarf_Unsigned c, Dwarf_Unsigned t, size_t n, Dwarf_Byte_Ptr r, DebugAbbrevAttrForm * p):
       
   240 			iCode(c),
       
   241 			iTag(t),
       
   242 			iCount(n),
       
   243 			iRaw(r),
       
   244 			iParsed(p)
       
   245 			{}
       
   246 	DebugAbbrev & operator=(const DebugAbbrev & aDebugAbbrev){
       
   247 		iCode = aDebugAbbrev.iCode;
       
   248 		iTag = aDebugAbbrev.iTag;
       
   249 		iCount = aDebugAbbrev.iCount;
       
   250 		iRaw = aDebugAbbrev.iRaw;
       
   251 		iParsed = aDebugAbbrev.iParsed;
       
   252 		return *this;
       
   253 	}
       
   254 	
       
   255 	DebugAbbrev(const DebugAbbrev & aDebugAbbrev){
       
   256 		*this = aDebugAbbrev;
       
   257 	}
       
   258 	
       
   259 	void Destroy(){
       
   260 		if (iParsed){
       
   261 			DebugAbbrevAttrForm * d = iParsed;
       
   262 			iParsed = NULL;
       
   263 			delete [] d;
       
   264 		}
       
   265 	}
       
   266 #if 0
       
   267 	// can't have default dtor do anything until and unless we prevent iParsed getting deleted
       
   268 	// whenever the class is copied in STL containers.
       
   269 	~DebugAbbrev(){
       
   270 		if (iParsed){
       
   271 			DebugAbbrevAttrForm * d = iParsed;
       
   272 			iParsed = NULL;
       
   273 			delete [] d;
       
   274 		}
       
   275 	}
       
   276 #endif
       
   277 	Dwarf_Unsigned iCode;
       
   278 	Dwarf_Unsigned iTag;
       
   279 	size_t iCount;
       
   280 	Dwarf_Byte_Ptr iRaw;
       
   281 	DebugAbbrevAttrForm * iParsed;
       
   282 };
       
   283 
       
   284 class InfoContext {
       
   285 private:
       
   286 	typedef std::map<Dwarf_Word, DebugAbbrev> AbbrevMap;
       
   287 	class AbbrevMapEntry {
       
   288 	public:
       
   289 		AbbrevMapEntry():
       
   290 					iCursor(NULL),
       
   291 					iMap(NULL)
       
   292 				{}
       
   293 		AbbrevMapEntry(Dwarf_Byte_Ptr c, AbbrevMap * m):
       
   294 			iCursor(c),
       
   295 			iMap(m)
       
   296 		{}
       
   297 		Dwarf_Byte_Ptr iCursor;
       
   298 		AbbrevMap * iMap;
       
   299 	};
       
   300 	typedef std::map<Uint32, AbbrevMapEntry> AbbrevOffsetMap;
       
   301 
       
   302 public:
       
   303 	InfoContext():
       
   304 		iContextValid(false),
       
   305 		iSectionStart(NULL),
       
   306 		iSectionEnd(NULL),
       
   307 		iSectionOffset(0),
       
   308 		// this is an invalid offset for 32 bit dwarf
       
   309 		// and will trigger the right behaviour in SetAbbrevOffset
       
   310 		// when called from Init
       
   311 		iAbbrevOffset(0xffffffff), 
       
   312 		
       
   313 		iAbbrevMapEntry(NULL, NULL)
       
   314 	{
       
   315 		//ClearMap();
       
   316 	}
       
   317 	~InfoContext(){
       
   318 		Reset();
       
   319 	}
       
   320 	void Init(Dwarf_Byte_Ptr s, Dwarf_Byte_Ptr e, size_t o){
       
   321 		iSectionStart = s;
       
   322 		iSectionEnd = e;
       
   323 		iSectionOffset = o;
       
   324 		//ClearMap();
       
   325 		iContextValid = true;
       
   326 		SetAbbrevOffset(0);
       
   327 	}
       
   328 	void Reset(){
       
   329 		iContextValid = false;
       
   330 		iSectionStart = iSectionEnd = NULL;
       
   331 		iSectionOffset = 0;
       
   332 		iAbbrevOffset = 0xffffffff;
       
   333 		ClearMap();
       
   334 	}
       
   335 	void ClearMap() {
       
   336 		for (AbbrevOffsetMap::iterator i = iMap.begin(); i != iMap.end(); i++){
       
   337 			AbbrevMap::iterator e = i->second.iMap->end();
       
   338 			for (AbbrevMap::iterator b = i->second.iMap->begin(); b != e; b++){
       
   339 				b->second.Destroy();
       
   340 			}
       
   341 			i->second.iMap->clear();
       
   342 		}
       
   343 		iMap.clear();
       
   344 	}
       
   345 	size_t GetSectionOffset(){ return iSectionOffset; }
       
   346 	
       
   347 	void SetAbbrevOffset(size_t offset);
       
   348 	
       
   349 	DebugAbbrev & GetAbbrev(Dwarf_Word aCode);
       
   350 	DebugAbbrev & FindAbbrev(Dwarf_Word aCode);
       
   351 
       
   352 	bool iContextValid;
       
   353 	Dwarf_Byte_Ptr iSectionStart;
       
   354 	Dwarf_Byte_Ptr iSectionEnd;
       
   355 	size_t iSectionOffset;
       
   356 	size_t iAbbrevOffset;
       
   357 	AbbrevMapEntry iAbbrevMapEntry;
       
   358 	AbbrevOffsetMap iMap;
       
   359 };
       
   360 
       
   361 class DwarfAbbrevManager : public DwarfConcatenatedSectionManager {
       
   362 public:
       
   363 	DwarfAbbrevManager(ElfSectionManager & aElfSectionManager, 
       
   364 					   DwarfManager & aDwarfManager, 
       
   365 					   RomDetails * aRomDetails):
       
   366 		DwarfConcatenatedSectionManager(aElfSectionManager, 
       
   367 										aDwarfManager, 
       
   368 										iAbbrevSectionName, 
       
   369 										aRomDetails)
       
   370 	{}
       
   371 	
       
   372 	// we might need to hang onto this after its been written to file
       
   373 	virtual void DeleteFileFragmentData(){}
       
   374 
       
   375 	void StartContext(PathName & aName);
       
   376 	void EndContext();
       
   377 	void SetContextAbbrevOffset(Uint32 offset);
       
   378 	size_t GetContextSectionOffset();
       
   379 	
       
   380 	DebugAbbrev & GetAbbrev(Dwarf_Word aCode);
       
   381 private:
       
   382 	static const string iAbbrevSectionName;
       
   383 	InfoContext iInfoContext;
       
   384 
       
   385 };
       
   386 
       
   387 class DwarfMacinfoManager : public DwarfFragmentedSectionManager {
       
   388 public:
       
   389 	DwarfMacinfoManager(ElfSectionManager & aElfSectionManager, 
       
   390 						DwarfManager & aDwarfManager, 
       
   391 						RomDetails * aRomDetails):
       
   392 		DwarfFragmentedSectionManager(aElfSectionManager, 
       
   393 									  aDwarfManager, 
       
   394 									  iMacinfoSectionName, 
       
   395 									  aRomDetails)
       
   396 	{}
       
   397 	virtual void ProcessSection(FileShdrPair & aPair, Dwarf_Byte_Ptr start, Dwarf_Byte_Ptr end){};
       
   398 
       
   399 private:
       
   400 	
       
   401 	static const string iMacinfoSectionName;	
       
   402 };
       
   403 
       
   404 //class DwarfInfoManager : public DwarfConcatenatedSectionManager {
       
   405 class DwarfInfoManager : public DwarfFragmentedSectionManager {
       
   406 public:
       
   407 	DwarfInfoManager(ElfSectionManager & aElfSectionManager, 
       
   408 					 DwarfManager & aDwarfManager, 
       
   409 					 DwarfAbbrevManager & aDwarfAbbrevManager, 
       
   410 					 DwarfMacinfoManager & aDwarfMacinfoManager, 
       
   411 					 RomDetails * aRomDetails):
       
   412 		DwarfFragmentedSectionManager(aElfSectionManager, 
       
   413 										aDwarfManager, 
       
   414 										iInfoSectionName, 
       
   415 										aRomDetails),
       
   416 		iDwarfAbbrevManager(aDwarfAbbrevManager),
       
   417 		iDwarfMacinfoManager(aDwarfMacinfoManager),
       
   418 		iAddressSize(4),
       
   419 		iLocalLength(0)
       
   420 	{}
       
   421 	
       
   422 	virtual void ProcessSection(FileShdrPair & aPair, Dwarf_Byte_Ptr start, Dwarf_Byte_Ptr end);
       
   423 	
       
   424 	size_t GetPointerSize() { return iAddressSize; }
       
   425 	
       
   426 private:
       
   427 	Dwarf_Byte_Ptr ProcessCU(FileShdrPair & aPair, Dwarf_Byte_Ptr s, Dwarf_Byte_Ptr e);
       
   428 	Dwarf_Byte_Ptr ProcessDIE(FileShdrPair & aPair, Dwarf_Byte_Ptr s, Dwarf_Byte_Ptr e);
       
   429 	
       
   430 	typedef Dwarf_Byte_Ptr (*InfoEditFn)(DwarfInfoManager&, Dwarf_Byte_Ptr, Dwarf_Half,FileShdrPair & aPair);
       
   431 	
       
   432 #define DECLARE_INFO_EDIT_FN(name)static Dwarf_Byte_Ptr name(DwarfInfoManager& aManager, \
       
   433 													Dwarf_Byte_Ptr aPtr, \
       
   434 													Dwarf_Half aForm, \
       
   435 													FileShdrPair & aPair)
       
   436 	DECLARE_INFO_EDIT_FN(DefaultInfoEditFn);
       
   437 	DECLARE_INFO_EDIT_FN(ErrorInfoEditFn);
       
   438 	DECLARE_INFO_EDIT_FN(InfoEditAddress);
       
   439 	DECLARE_INFO_EDIT_FN(InfoEditLinePtr);
       
   440 	DECLARE_INFO_EDIT_FN(InfoEditLocListPtr);
       
   441 	DECLARE_INFO_EDIT_FN(InfoEditLocExpr);
       
   442 	DECLARE_INFO_EDIT_FN(InfoEditMacInfoPtr);
       
   443 	DECLARE_INFO_EDIT_FN(InfoEditRangeListPtr);
       
   444 	DECLARE_INFO_EDIT_FN(InfoEditString);
       
   445 	DECLARE_INFO_EDIT_FN(InfoEditReference);
       
   446 	DECLARE_INFO_EDIT_FN(InfoEditTrampoline);
       
   447 	
       
   448 	size_t SizeOfDieValue(Dwarf_Half aForm, Dwarf_Byte_Ptr aPtr);	
       
   449 
       
   450 private:
       
   451 	static const string iInfoSectionName;
       
   452 	DwarfAbbrevManager & iDwarfAbbrevManager;
       
   453 	DwarfMacinfoManager & iDwarfMacinfoManager;
       
   454 	static InfoEditFn iInfoEditFn[];
       
   455 	
       
   456 	size_t iAddressSize;
       
   457 	size_t iLocalLength;
       
   458 };
       
   459 
       
   460 class DwarfFrameManager : public DwarfFragmentedSectionManager {
       
   461 public:
       
   462 	DwarfFrameManager(ElfSectionManager & aElfSectionManager, 
       
   463 					  DwarfManager & aDwarfManager, 
       
   464 					  RomDetails * aRomDetails):
       
   465 		DwarfFragmentedSectionManager(aElfSectionManager, 
       
   466 									  aDwarfManager, 
       
   467 									  iFrameSectionName, 
       
   468 									  aRomDetails)
       
   469 	{}
       
   470 
       
   471 	virtual void ProcessSection(FileShdrPair & aPair, Dwarf_Byte_Ptr start, Dwarf_Byte_Ptr end);
       
   472 
       
   473 private:
       
   474 	typedef std::map<Dwarf_Byte_Ptr, Dwarf_Ubyte> CiePtrEncodingMap;
       
   475 	typedef std::map<Dwarf_Byte_Ptr, size_t> CieAugmentationMap;
       
   476 
       
   477 	static const string iFrameSectionName;	
       
   478 };
       
   479 
       
   480 class DwarfLineManager : public DwarfFragmentedSectionManager {
       
   481 public:
       
   482 	DwarfLineManager(ElfSectionManager & aElfSectionManager, 
       
   483 					 DwarfManager & aDwarfManager, 
       
   484 					 DwarfInfoManager & aDwarfInfoManager, 
       
   485 					 RomDetails * aRomDetails):
       
   486 		DwarfFragmentedSectionManager(aElfSectionManager, 
       
   487 									  aDwarfManager, 
       
   488 									  iLineSectionName, 
       
   489 									  aRomDetails),
       
   490 		iDwarfInfoManager(aDwarfInfoManager)
       
   491 	{}
       
   492 	
       
   493 	virtual void ProcessSection(FileShdrPair & aPair, Dwarf_Byte_Ptr start, Dwarf_Byte_Ptr end);
       
   494 	
       
   495 private:
       
   496 	DwarfInfoManager & iDwarfInfoManager;
       
   497 
       
   498 	static const string iLineSectionName;	
       
   499 };
       
   500 
       
   501 class DwarfLocManager : public DwarfFragmentedSectionManager {
       
   502 public:
       
   503 	DwarfLocManager(ElfSectionManager & aElfSectionManager, 
       
   504 					DwarfManager & aDwarfManager, 
       
   505 					DwarfInfoManager & aDwarfInfoManager, 
       
   506 					RomDetails * aRomDetails):
       
   507 		DwarfFragmentedSectionManager(aElfSectionManager, 
       
   508 									  aDwarfManager, 
       
   509 									  iLocSectionName,
       
   510 									  aRomDetails),
       
   511 		iDwarfInfoManager(aDwarfInfoManager)
       
   512 	{}
       
   513 	
       
   514 	virtual void ProcessSection(FileShdrPair & aPair, Dwarf_Byte_Ptr start, Dwarf_Byte_Ptr end);
       
   515 
       
   516 private:
       
   517 	DwarfInfoManager & iDwarfInfoManager;
       
   518 	
       
   519 	static const string iLocSectionName;
       
   520 };
       
   521 
       
   522 class DwarfNameManager : public DwarfFragmentedSectionManager {
       
   523 public:
       
   524 	DwarfNameManager(ElfSectionManager & aElfSectionManager, 
       
   525 					 DwarfManager & aDwarfManager, 
       
   526 					 const string & aName, 
       
   527 					 DwarfInfoManager & aDwarfInfoManager, 
       
   528 					 RomDetails * aRomDetails):
       
   529 		DwarfFragmentedSectionManager(aElfSectionManager, 
       
   530 									  aDwarfManager, 
       
   531 									  aName, 
       
   532 									  aRomDetails),
       
   533 		iDwarfInfoManager(aDwarfInfoManager)
       
   534 	{}
       
   535 	
       
   536 	virtual void ProcessSection(FileShdrPair & aPair, Dwarf_Byte_Ptr start, Dwarf_Byte_Ptr end);
       
   537 
       
   538 protected:
       
   539 	DwarfInfoManager & iDwarfInfoManager;
       
   540 };
       
   541 
       
   542 class DwarfPubnamesManager : public DwarfNameManager {
       
   543 public:
       
   544 	DwarfPubnamesManager(ElfSectionManager & aElfSectionManager, 
       
   545 						 DwarfManager & aDwarfManager, 
       
   546 						 DwarfInfoManager & aDwarfInfoManager, 
       
   547 						 RomDetails * aRomDetails):
       
   548 		DwarfNameManager(aElfSectionManager, 
       
   549 						 aDwarfManager, 
       
   550 						 iPubnamesSectionName, 
       
   551 						 aDwarfInfoManager, 
       
   552 						 aRomDetails)
       
   553 	{}
       
   554 	
       
   555 private:
       
   556 	static const string iPubnamesSectionName;	
       
   557 };
       
   558 
       
   559 class DwarfPubtypesManager : public DwarfNameManager {
       
   560 public:
       
   561 	DwarfPubtypesManager(ElfSectionManager & aElfSectionManager, 
       
   562 						 DwarfManager & aDwarfManager, 
       
   563 						 DwarfInfoManager & aDwarfInfoManager, 
       
   564 						 RomDetails * aRomDetails):
       
   565 		DwarfNameManager(aElfSectionManager, 
       
   566 						 aDwarfManager, 
       
   567 						 iPubtypesSectionName, 
       
   568 						 aDwarfInfoManager, 
       
   569 						 aRomDetails)
       
   570 	{}
       
   571 	
       
   572 private:
       
   573 	static const string iPubtypesSectionName;	
       
   574 };
       
   575 
       
   576 class DwarfArangesManager : public DwarfFragmentedSectionManager {
       
   577 public:
       
   578 	DwarfArangesManager(ElfSectionManager & aElfSectionManager, 
       
   579 						DwarfManager & aDwarfManager, 
       
   580 						DwarfInfoManager & aDwarfInfoManager, 
       
   581 						RomDetails * aRomDetails):
       
   582 		DwarfFragmentedSectionManager(aElfSectionManager, 
       
   583 									  aDwarfManager, 
       
   584 									  iArangesSectionName, 
       
   585 									  aRomDetails),
       
   586 		iDwarfInfoManager(aDwarfInfoManager)
       
   587 	{}
       
   588 	
       
   589 	virtual void ProcessSection(FileShdrPair & aPair, Dwarf_Byte_Ptr start, Dwarf_Byte_Ptr end);
       
   590 
       
   591 private:
       
   592 	DwarfInfoManager & iDwarfInfoManager;
       
   593 
       
   594 	static const string iArangesSectionName;	
       
   595 };
       
   596 
       
   597 
       
   598 class DwarfRangesManager : public DwarfFragmentedSectionManager {
       
   599 public:
       
   600 	DwarfRangesManager(ElfSectionManager & aElfSectionManager, 
       
   601 					   DwarfManager & aDwarfManager, 
       
   602 					   DwarfInfoManager & aDwarfInfoManager, 
       
   603 					   RomDetails * aRomDetails):
       
   604 		DwarfFragmentedSectionManager(aElfSectionManager, 
       
   605 									  aDwarfManager, 
       
   606 									  iRangesSectionName, 
       
   607 									  aRomDetails),
       
   608 		iDwarfInfoManager(aDwarfInfoManager)
       
   609 	{}
       
   610 
       
   611 	virtual void ProcessSection(FileShdrPair & aPair, Dwarf_Byte_Ptr start, Dwarf_Byte_Ptr end);
       
   612 
       
   613 private:
       
   614 	DwarfInfoManager & iDwarfInfoManager;
       
   615 
       
   616 	static const string iRangesSectionName;	
       
   617 };
       
   618 
       
   619 class DwarfStrManager : public DwarfFragmentedSectionManager {
       
   620 public:
       
   621 	DwarfStrManager(ElfSectionManager & aElfSectionManager, 
       
   622 					DwarfManager & aDwarfManager, 
       
   623 					RomDetails * aRomDetails):
       
   624 		DwarfFragmentedSectionManager(aElfSectionManager, 
       
   625 									  aDwarfManager, 
       
   626 									  iStrSectionName, 
       
   627 									  aRomDetails)
       
   628 	{}
       
   629 	
       
   630 	virtual void ProcessSection(FileShdrPair & aPair, Dwarf_Byte_Ptr start, Dwarf_Byte_Ptr end){};
       
   631 
       
   632 private:
       
   633 	static const string iStrSectionName;	
       
   634 };
       
   635 
       
   636 class DwarfManager {
       
   637 public:
       
   638 	DwarfManager(ElfSectionManager & aElfSectionManager, 
       
   639 				RomDetails * aRomDetails, 
       
   640 				OutputFile & aOutputFile):
       
   641 		iDwarfAbbrevManager(aElfSectionManager, *this, aRomDetails),
       
   642 		iDwarfFrameManager(aElfSectionManager, *this, aRomDetails),
       
   643 		iDwarfMacinfoManager(aElfSectionManager, *this, aRomDetails),
       
   644 		iDwarfInfoManager(aElfSectionManager, *this, iDwarfAbbrevManager, iDwarfMacinfoManager, aRomDetails),
       
   645 		iDwarfLineManager(aElfSectionManager, *this, iDwarfInfoManager, aRomDetails),
       
   646 		iDwarfLocManager(aElfSectionManager, *this, iDwarfInfoManager, aRomDetails),
       
   647 		iDwarfPubnamesManager(aElfSectionManager, *this, iDwarfInfoManager, aRomDetails),
       
   648 		iDwarfPubtypesManager(aElfSectionManager, *this, iDwarfInfoManager, aRomDetails),
       
   649 		iDwarfArangesManager(aElfSectionManager, *this,iDwarfInfoManager, aRomDetails),
       
   650 		iDwarfRangesManager(aElfSectionManager, *this,iDwarfInfoManager, aRomDetails),
       
   651 		iDwarfStrManager(aElfSectionManager, *this, aRomDetails),
       
   652 		iRomDetails(aRomDetails),
       
   653 		iOutputFile(aOutputFile)
       
   654 	{}
       
   655 	
       
   656 	size_t GetLineSectionOffset(PathName & pname){
       
   657 		return iDwarfLineManager.GetSectionOffset(pname);
       
   658 	}
       
   659 	size_t GetLocListSectionOffset(PathName & pname){
       
   660 		return iDwarfLocManager.GetSectionOffset(pname);
       
   661 	}
       
   662 	size_t GetMacInfoSectionOffset(PathName & pname){
       
   663 		return iDwarfMacinfoManager.GetSectionOffset(pname);
       
   664 	}
       
   665 	size_t GetRangesSectionOffset(PathName & pname){
       
   666 		return iDwarfRangesManager.GetSectionOffset(pname);
       
   667 	}
       
   668 	size_t GetStrSectionOffset(PathName & pname){
       
   669 		return iDwarfStrManager.GetSectionOffset(pname);
       
   670 	}
       
   671 
       
   672 	OutputFile & GetOutputFile() { return iOutputFile; }
       
   673 	
       
   674 	void AddSection(XIPFileDetails & aXIPFileDetails, string aSectionName, Elf32_Shdr * aShdr);
       
   675 	void SetupSections();
       
   676 	
       
   677 private:
       
   678 	// Don't want one of these to be copied
       
   679 	DwarfManager(const DwarfManager & aDwarfManager);
       
   680 	
       
   681 	DwarfManager & operator=(const DwarfManager & aDwarfManager);
       
   682 	
       
   683 private:
       
   684 	DwarfAbbrevManager iDwarfAbbrevManager;
       
   685 	DwarfFrameManager iDwarfFrameManager;
       
   686 	DwarfMacinfoManager iDwarfMacinfoManager;
       
   687 	DwarfInfoManager iDwarfInfoManager;
       
   688 	DwarfLineManager iDwarfLineManager;
       
   689 	DwarfLocManager iDwarfLocManager;
       
   690 	DwarfPubnamesManager iDwarfPubnamesManager;
       
   691 	DwarfPubtypesManager iDwarfPubtypesManager;
       
   692 	DwarfArangesManager iDwarfArangesManager;
       
   693 	DwarfRangesManager iDwarfRangesManager;
       
   694 	DwarfStrManager iDwarfStrManager;
       
   695 	RomDetails * iRomDetails;
       
   696 	OutputFile & iOutputFile;
       
   697 };
       
   698 
       
   699 #endif /*DWARFMANAGER_H_*/