tools/elf4rom/src/dwarfnamemanager.cpp
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 #include <iostream>
       
    20 #include "dwarfmanager.h"
       
    21 #include "inputfile.h"
       
    22 
       
    23 const string DwarfPubnamesManager::iPubnamesSectionName(".debug_pubnames");
       
    24 const string DwarfPubtypesManager::iPubtypesSectionName(".debug_pubtypes");
       
    25 
       
    26 void DwarfNameManager::ProcessSection(FileShdrPair & aPair, Dwarf_Byte_Ptr aStart, Dwarf_Byte_Ptr aEnd){
       
    27 	Dwarf_Byte_Ptr start = aStart;
       
    28 	Dwarf_Byte_Ptr end = aEnd;
       
    29 	while (start < end){
       
    30 		Dwarf_Byte_Ptr data = start;
       
    31 		size_t offset_size, initial_length_size;
       
    32 
       
    33 		Dwarf_Word length = READ_UNALIGNED4(data); 
       
    34 		data += 4;
       
    35 
       
    36 		if (length >= 0xfffffff0u) {
       
    37 			cerr << "Error: 64 bit DWARF not supported\n";
       
    38 			exit(EXIT_FAILURE);
       
    39 		} else {	
       
    40 			offset_size = 4;
       
    41 			initial_length_size = 4;
       
    42 		}
       
    43 
       
    44 		Dwarf_Half version = READ_UNALIGNED2(data);
       
    45 		data += 2;
       
    46 
       
    47 		Dwarf_Word offset = GetValue(data, offset_size); 
       
    48 		Dwarf_Word newOffset = CheckNewOffset(iDwarfInfoManager.GetSectionOffset(aPair.iXIPFileDetails.iElfFile), offset);
       
    49 		if (offset != newOffset)
       
    50 			WriteValue(data, offset, offset_size);
       
    51 		data += offset_size;
       
    52 
       
    53 
       
    54 		//Dwarf_Word size = GetValue(data, offset_size);
       
    55 		// Don't need the length field
       
    56 		data += offset_size;
       
    57 
       
    58 		start += length + initial_length_size;
       
    59 
       
    60 		if (version != 2 && version != 3){
       
    61 			static bool warned = false;
       
    62 			if (!warned){
       
    63 				cerr << "Only DWARF 2 and 3 pubnames are currently supported\n";
       
    64 				warned = true;
       
    65 			}
       
    66 
       
    67 			continue;
       
    68 		}
       
    69 
       
    70 		do {
       
    71 			offset = GetValue(data, offset_size);
       
    72 
       
    73 			if (offset != 0)
       
    74 			{
       
    75 				data += offset_size;
       
    76 				data += strlen ((char *) data) + 1;
       
    77 			}
       
    78 		}
       
    79 		while (offset != 0);
       
    80 	}
       
    81 }