nmtest.cc revision 2
12SN/A/*
21762SN/A * Copyright (c) 2003 The Regents of The University of Michigan
32SN/A * All rights reserved.
42SN/A *
52SN/A * Redistribution and use in source and binary forms, with or without
62SN/A * modification, are permitted provided that the following conditions are
72SN/A * met: redistributions of source code must retain the above copyright
82SN/A * notice, this list of conditions and the following disclaimer;
92SN/A * redistributions in binary form must reproduce the above copyright
102SN/A * notice, this list of conditions and the following disclaimer in the
112SN/A * documentation and/or other materials provided with the distribution;
122SN/A * neither the name of the copyright holders nor the names of its
132SN/A * contributors may be used to endorse or promote products derived from
142SN/A * this software without specific prior written permission.
152SN/A *
162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu */
282665Ssaidi@eecs.umich.edu
292SN/A#include <iostream>
302SN/A#include <string>
316216Snate@binkert.org#include <vector>
322439SN/A
336216Snate@binkert.org#include "ecoff.hh"
34146SN/A#include "object_file.hh"
35146SN/A#include "str.hh"
36146SN/A#include "symtab.hh"
37146SN/A
38146SN/ATick curTick;
39146SN/A
401717SN/Aint
41146SN/Amain(int argc, char *argv[])
426216Snate@binkert.org{
431717SN/A    EcoffObject obj;
44146SN/A    if (argc != 3) {
451977SN/A        cout << "usage: " << argv[0] << " <filename> <symbol>\n";
462623SN/A        return 1;
472683Sktlim@umich.edu    }
481717SN/A
49146SN/A    if (!obj.open(argv[1])) {
502683Sktlim@umich.edu        cout << "file not found\n";
513348Sbinkertn@umich.edu        return 1;
526105Ssteve.reinhardt@amd.com    }
536216Snate@binkert.org
542036SN/A    SymbolTable symtab;
55146SN/A    obj.loadGlobals(&symtab);
5656SN/A
5756SN/A    string symbol = argv[2];
58695SN/A    Addr address;
592901Ssaidi@eecs.umich.edu
602SN/A    if (symbol[0] == '0' && symbol[1] == 'x') {
611858SN/A        if (to_number(symbol, address) && symtab.findSymbol(address, symbol))
623565Sgblack@eecs.umich.edu            cout << "address = 0x" << hex << address
633565Sgblack@eecs.umich.edu                 << ", symbol = " << symbol << "\n";
642171SN/A        else
652170SN/A            cout << "address = 0x" << hex << address << " was not found\n";
663562Sgblack@eecs.umich.edu    } else {
67146SN/A        if (symtab.findAddress(symbol, address))
682462SN/A            cout << "symbol = " << symbol << ", address = 0x" << hex
69146SN/A                 << address << "\n";
702SN/A        else
712SN/A            cout << "symbol = " << symbol << " was not found\n";
722449SN/A    }
731355SN/A
745529Snate@binkert.org    return 0;
754495Sacolyte@umich.edu}
76224SN/A