nmtest.cc revision 1919
114039Sstacze01@arm.com/*
214039Sstacze01@arm.com * Copyright (c) 2002-2005 The Regents of The University of Michigan
314039Sstacze01@arm.com * All rights reserved.
414039Sstacze01@arm.com *
514039Sstacze01@arm.com * Redistribution and use in source and binary forms, with or without
614039Sstacze01@arm.com * modification, are permitted provided that the following conditions are
714039Sstacze01@arm.com * met: redistributions of source code must retain the above copyright
814039Sstacze01@arm.com * notice, this list of conditions and the following disclaimer;
914039Sstacze01@arm.com * redistributions in binary form must reproduce the above copyright
1014039Sstacze01@arm.com * notice, this list of conditions and the following disclaimer in the
1114039Sstacze01@arm.com * documentation and/or other materials provided with the distribution;
1214039Sstacze01@arm.com * neither the name of the copyright holders nor the names of its
1314039Sstacze01@arm.com * contributors may be used to endorse or promote products derived from
1414039Sstacze01@arm.com * this software without specific prior written permission.
1514039Sstacze01@arm.com *
1614039Sstacze01@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1714039Sstacze01@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1814039Sstacze01@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1914039Sstacze01@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2014039Sstacze01@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2114039Sstacze01@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2214039Sstacze01@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2314039Sstacze01@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2414039Sstacze01@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2514039Sstacze01@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2614039Sstacze01@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2714039Sstacze01@arm.com */
2814039Sstacze01@arm.com
2914039Sstacze01@arm.com#include <iostream>
3014039Sstacze01@arm.com#include <string>
3114039Sstacze01@arm.com#include <vector>
3214039Sstacze01@arm.com
3314039Sstacze01@arm.com#include "base/loader/object_file.hh"
3414039Sstacze01@arm.com#include "base/loader/symtab.hh"
3514039Sstacze01@arm.com#include "base/misc.hh"
3614039Sstacze01@arm.com#include "base/str.hh"
3714039Sstacze01@arm.com
3814039Sstacze01@arm.comusing namespace std;
3914039Sstacze01@arm.comTick curTick;
4014039Sstacze01@arm.com
4114039Sstacze01@arm.comostream *outputStream = &cout;
4214039Sstacze01@arm.com
4314039Sstacze01@arm.comint
4414039Sstacze01@arm.commain(int argc, char *argv[])
4514039Sstacze01@arm.com{
4614039Sstacze01@arm.com    if (argc != 2 && argc != 3)
4714039Sstacze01@arm.com        panic("usage: %s <filename> <symbol>\n", argv[0]);
4814039Sstacze01@arm.com
4914039Sstacze01@arm.com    ObjectFile *obj = createObjectFile(argv[1]);
5014039Sstacze01@arm.com    if (!obj)
5114039Sstacze01@arm.com        panic("file not found\n");
5214039Sstacze01@arm.com
5314039Sstacze01@arm.com    SymbolTable symtab;
5414039Sstacze01@arm.com    obj->loadGlobalSymbols(&symtab);
5514039Sstacze01@arm.com    obj->loadLocalSymbols(&symtab);
5614039Sstacze01@arm.com
5714039Sstacze01@arm.com    if (argc == 2) {
5814039Sstacze01@arm.com        SymbolTable::ATable::const_iterator i = symtab.getAddrTable().begin();
5914039Sstacze01@arm.com        SymbolTable::ATable::const_iterator end = symtab.getAddrTable().end();
6014039Sstacze01@arm.com        while (i != end) {
6114039Sstacze01@arm.com            cprintf("%#x %s\n", i->first, i->second);
6214039Sstacze01@arm.com            ++i;
6314039Sstacze01@arm.com        }
6414039Sstacze01@arm.com    } else {
6514039Sstacze01@arm.com        string symbol = argv[2];
6614039Sstacze01@arm.com        Addr address;
6714039Sstacze01@arm.com
6814039Sstacze01@arm.com        if (symbol[0] == '0' && symbol[1] == 'x') {
6914039Sstacze01@arm.com            if (to_number(symbol, address) &&
7014039Sstacze01@arm.com                symtab.findSymbol(address, symbol))
7114039Sstacze01@arm.com                cprintf("address = %#x, symbol = %s\n", address, symbol);
7214039Sstacze01@arm.com            else
7314039Sstacze01@arm.com                cprintf("address = %#x was not found\n", address);
7414039Sstacze01@arm.com        } else {
7514039Sstacze01@arm.com            if (symtab.findAddress(symbol, address))
7614039Sstacze01@arm.com                cprintf("symbol = %s address = %#x\n", symbol, address);
7714039Sstacze01@arm.com            else
7814039Sstacze01@arm.com                cprintf("symbol = %s was not found\n", symbol);
7914039Sstacze01@arm.com        }
8014039Sstacze01@arm.com    }
8114063Sadrian.herrera@arm.com
8214063Sadrian.herrera@arm.com    return 0;
8314063Sadrian.herrera@arm.com}
8414063Sadrian.herrera@arm.com