symtest.cc revision 2
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright (c) 2003 The Regents of The University of Michigan 36145Snate@binkert.org * All rights reserved. 46145Snate@binkert.org * 56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66145Snate@binkert.org * modification, are permitted provided that the following conditions are 76145Snate@binkert.org * met: redistributions of source code must retain the above copyright 86145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116145Snate@binkert.org * documentation and/or other materials provided with the distribution; 126145Snate@binkert.org * neither the name of the copyright holders nor the names of its 136145Snate@binkert.org * contributors may be used to endorse or promote products derived from 146145Snate@binkert.org * this software without specific prior written permission. 156145Snate@binkert.org * 166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145Snate@binkert.org */ 286145Snate@binkert.org 296145Snate@binkert.org#include <iostream.h> 306154Snate@binkert.org 316154Snate@binkert.org#include "str.hh" 326154Snate@binkert.org#include "symtab.hh" 336154Snate@binkert.org 346154Snate@binkert.orgTick curTick = 0; 356154Snate@binkert.org 366285Snate@binkert.orgvoid 376285Snate@binkert.orgusage(const char *progname) 386154Snate@binkert.org{ 396154Snate@binkert.org cout << "Usage: " << progname << " <symbol file> <symbol>" << endl; 406154Snate@binkert.org 416285Snate@binkert.org exit(1); 426285Snate@binkert.org} 436145Snate@binkert.org 446285Snate@binkert.orgint 456145Snate@binkert.orgmain(int argc, char *argv[]) 466355Spdudnik@gmail.com{ 476355Spdudnik@gmail.com SymbolTable symtab; 486285Snate@binkert.org 496285Snate@binkert.org if (argc != 3) 506285Snate@binkert.org usage(argv[0]); 516285Snate@binkert.org 526285Snate@binkert.org if (!symtab.load(argv[1])) { 536285Snate@binkert.org cout << "could not load symbol file: " << argv[1] << endl; 546285Snate@binkert.org exit(1); 556145Snate@binkert.org } 566145Snate@binkert.org 576145Snate@binkert.org string symbol = argv[2]; 586285Snate@binkert.org Addr address; 596285Snate@binkert.org 606285Snate@binkert.org if (!to_number(symbol, address)) { 616285Snate@binkert.org if (!symtab.findAddress(symbol, address)) { 626285Snate@binkert.org cout << "could not find symbol: " << symbol << endl; 636285Snate@binkert.org exit(1); 646505Spdudnik@gmail.com } 656505Spdudnik@gmail.com 666285Snate@binkert.org cout << symbol << " -> " << "0x" << hex << address << endl; 676285Snate@binkert.org } else { 686285Snate@binkert.org if (!symtab.findSymbol(address, symbol)) { 696285Snate@binkert.org cout << "could not find address: " << address << endl; 706285Snate@binkert.org exit(1); 716285Snate@binkert.org } 726285Snate@binkert.org 736285Snate@binkert.org cout << "0x" << hex << address << " -> " << symbol<< endl; 746285Snate@binkert.org } 756285Snate@binkert.org 766285Snate@binkert.org return 0; 776285Snate@binkert.org} 786285Snate@binkert.org