diff -r 000000000000 -r 638b9c697799 apicompatanamdw/compatanalysercmd/libraryanalyser/src/la_getters.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/apicompatanamdw/compatanalysercmd/libraryanalyser/src/la_getters.cpp Tue Jan 12 14:52:39 2010 +0530 @@ -0,0 +1,436 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Utility functions for getting data via 3rd party tools +* +*/ + + +#include "la.hpp" + +// ---------------------------------------------------------------------------------------------------------- +// TIP: Use The Regex Coach (http://weitz.de/regex-coach/) to check that the regular expressions are working correctly +// Note that in C/C++ code \ has been replaced with \\ and " with \". +// ---------------------------------------------------------------------------------------------------------- + +void GetSymbolTableWithNM(const string& nm_location, const string& lib_name, vector& symbol_table) +{ + symbol_table.clear(); + vector tempVector; + vector ordinals; + + // execute nm + string cmd = nm_location + " --demangle \"" + lib_name + "\""; + ExecuteCommand(cmd, tempVector); + + + // parse the results of the command + for (unsigned int j=0; j& symbol_table) +{ + symbol_table.clear(); + vector tempVector; + vector ordinals; + + // execute readelf + // note: 2>NUL is used here to redirect standard error output to NULL since readelf seems to output lots of unwanted warning messages + string cmd = readelf_location + " -s -W \"" + lib_name + "\" " + CERR_TO_NULL; + ExecuteCommand(cmd, tempVector); + + + // parse the results of the command + for (unsigned int j=0; j& symbol_table) +{ + symbol_table.clear(); + vector tempVector; + vector ordinals; + + // execute armar + string cmd = armar_location + " --zs \"" + lib_name + "\""; + ExecuteCommand(cmd, tempVector); + + + // parse the results of the command + for (unsigned int j=0; j& symbol_table) +{ + symbol_table.clear(); + vector tempVector; + vector ordinals; + + // execute fromelf + string cmd = fromelf_location + " -s \"" + lib_name + "\""; + ExecuteCommand(cmd, tempVector); + + // parse the results of the command + for (unsigned int j=0; j& ordinals, vector& symbol_table, const string& lib_path) +{ + // remove any invalid ordinals from the list + vector ordinalVectorCopy; + ordinalVectorCopy.reserve(ordinals.size()); + + for (unsigned int i=0; i 32000) + { + cerr << "Error: Invalid ordinal " << ordinals.at(i).funcname << " @ " << Int2Str(ordinals.at(i).funcpos) << endl; + } + else + { + ordinalVectorCopy.push_back(ordinals.at(i)); + } + } + + // sort the ordinal list + sort(ordinalVectorCopy.begin(), ordinalVectorCopy.end(), OrdinalCompare); + + // now check that there are no missing ordinals in the list + unsigned int previous_ordnumber = 0; + unsigned int current_ordnumber = 1; + for (unsigned int i=0; i25000) + { + cerr << endl << "Something went horribly wrong when trying to parse " << lib_path << ". Aborting." << endl; + exit(10); + } + } + + // finally copy data from the ordinal list to the symbol table + if (symbol_table.size() < ordinalVectorCopy.size()) + { + symbol_table.reserve(ordinalVectorCopy.size()); + } + for (unsigned int i=0; i& symbol_table) +{ + ofstream f(_tempfile_location.c_str(), ios::trunc); + if (f.is_open()) + { + // create a temp file which contain all the function names + for (unsigned int k=0; k cfilt_result_set; + string tempfile_loc = _tempfile_location; + InsertQuotesToFilePath(tempfile_loc); + string cmd = cfilt_location + " < " + tempfile_loc; + ExecuteCommand(cmd, cfilt_result_set); + + // check that all functions exist and then replace the symbol table with demangled functions + if (cfilt_result_set.size() == symbol_table.size()) + { + symbol_table = cfilt_result_set; + } + } + else + { + f.close(); + } +} + +// ---------------------------------------------------------------------------------------------------------- + +bool OrdinalCompare(const ordinal& left, const ordinal& right) +{ + return left.funcpos < right.funcpos; +} + +// ---------------------------------------------------------------------------------------------------------- + +