Fix various problems in PC list handling
This commit is contained in:
parent
bc05e8270c
commit
52ea92dcf8
5 changed files with 14 additions and 4 deletions
|
@ -19,6 +19,7 @@ CodeGenerator::CodeGenerator(
|
|||
{
|
||||
if(!settings::pc_list.empty()) {
|
||||
pc_list = make_unique<PcListReader>(settings::pc_list);
|
||||
pc_list->read();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,6 +134,9 @@ void CodeGenerator::gen_case(uintptr_t low_bound, uintptr_t high_bound) {
|
|||
pc_list->get_list().end(),
|
||||
high_bound);
|
||||
|
||||
if(first_it == pc_list->get_list().end())
|
||||
throw CodeGenerator::InvalidPcList();
|
||||
|
||||
os << std::hex;
|
||||
for(auto it = first_it; it != last_it; ++it)
|
||||
os << "\t\tcase 0x" << *it << ":\n";
|
||||
|
|
|
@ -18,6 +18,8 @@ class CodeGenerator {
|
|||
/// Unimplemented case
|
||||
class NotImplementedCase: public std::exception {};
|
||||
|
||||
class InvalidPcList: public std::exception {};
|
||||
|
||||
/** Create a CodeGenerator to generate code for the given dwarf, on the
|
||||
* given std::ostream object (eg. cout). */
|
||||
CodeGenerator(const SimpleDwarf& dwarf, std::ostream& os,
|
||||
|
|
|
@ -18,8 +18,11 @@ void PcListReader::read() {
|
|||
|
||||
while(!handle.eof()) {
|
||||
handle.read((char*)buffer, 8);
|
||||
if(handle.gcount() != 8)
|
||||
if(handle.gcount() != 8) {
|
||||
if(handle.gcount() == 0)
|
||||
break;
|
||||
throw PcListReader::BadFormat();
|
||||
}
|
||||
|
||||
last_pc = 0;
|
||||
for(int shift = 0; shift < 8; ++shift) {
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
class PcListReader {
|
||||
public:
|
||||
/// Thrown when the file is somehow not readable
|
||||
class CannotReadFile: std::exception {};
|
||||
class CannotReadFile: public std::exception {};
|
||||
|
||||
/// Thrown when the file contains bad content (probably not aligned 8B)
|
||||
class BadFormat: std::exception {};
|
||||
class BadFormat: public std::exception {};
|
||||
|
||||
PcListReader(const std::string& path);
|
||||
|
||||
|
|
|
@ -73,7 +73,8 @@ MainOptions options_parse(int argc, char** argv) {
|
|||
if(print_helptext) {
|
||||
cerr << "Usage: "
|
||||
<< argv[0]
|
||||
<< " [--switch-per-func | --global-switch] elf_path"
|
||||
<< " [--switch-per-func | --global-switch] "
|
||||
<< "[--pc-list PC_LIST_FILE] elf_path"
|
||||
<< endl;
|
||||
}
|
||||
if(exit_status >= 0)
|
||||
|
|
Loading…
Reference in a new issue