generic-tracing: add error handling

Instead of using assert() (which only does something in a Debug
build), explicitly fail when a user-specified symbol is not found.

Change-Id: I33ac59ca4483ee65ba70c264b5153a7766a919d2
This commit is contained in:
Horst Schirmeier
2018-07-13 09:30:33 +02:00
parent c11547a952
commit 3d292cb217

View File

@ -95,8 +95,12 @@ void GenericTracing::parseOptions() {
if (cmd[START_SYMBOL] && m_elf != NULL) {
start_symbol = cmd[START_SYMBOL].first()->arg;
assert(m_elf->getSymbol(start_symbol).isValid());
start_address = m_elf->getSymbol(start_symbol).getAddress();
const ElfSymbol& symbol = m_elf->getSymbol(start_symbol);
if (!symbol.isValid()) {
m_log << "Start symbol '" << start_symbol << "' not found." << std::endl;
exit(EXIT_FAILURE);
}
start_address = symbol.getAddress();
} else if (cmd[START_ADDRESS]) {
start_address = strtoul(cmd[START_ADDRESS].first()->arg, NULL, 16);
} else if (m_elf == NULL) {
@ -104,14 +108,22 @@ void GenericTracing::parseOptions() {
exit(EXIT_FAILURE);
} else {
start_symbol = "main";
assert(m_elf->getSymbol(start_symbol).isValid());
start_address = m_elf->getSymbol(start_symbol).getAddress();
const ElfSymbol& symbol = m_elf->getSymbol(start_symbol);
if (!symbol.isValid()) {
m_log << "Start symbol '" << start_symbol << "' not found." << std::endl;
exit(EXIT_FAILURE);
}
start_address = symbol.getAddress();
}
if (cmd[STOP_SYMBOL] && m_elf != NULL) {
stop_symbol = std::string(cmd[STOP_SYMBOL].first()->arg);
assert(m_elf->getSymbol(stop_symbol).isValid());
stop_address = m_elf->getSymbol(stop_symbol).getAddress();
const ElfSymbol& symbol = m_elf->getSymbol(stop_symbol);
if (!symbol.isValid()) {
m_log << "Stop symbol '" << start_symbol << "' not found." << std::endl;
exit(EXIT_FAILURE);
}
stop_address = symbol.getAddress();
} else if (cmd[STOP_ADDRESS]) {
stop_address = strtoul(cmd[STOP_ADDRESS].first()->arg, NULL, 16);
} else {
@ -149,7 +161,10 @@ void GenericTracing::parseOptions() {
while (opt != 0) {
const ElfSymbol& symbol = m_elf->getSymbol(opt->arg);
assert(symbol.isValid());
if (!symbol.isValid()) {
m_log << "Symbol '" << start_symbol << "' not found." << std::endl;
exit(EXIT_FAILURE);
}
m_log << "Adding '" << opt->arg << "' == 0x" << std::hex << symbol.getAddress()
<< "+" << std::dec << symbol.getSize() << " to trace map" << std::endl;