2 #include "Disassembler.h"
3 #include "platform/BidirectionalPipe.h"
4 #include "platform/ArgumentList.h"
5 #include "misc/String.h"
12 Disassembler::Disassembler(Misc::SmartPointer
<ELF::Parser
> elf_parser
) : elf_parser(elf_parser
) {
13 Platform::ArgumentList al
;
14 al
.add_argument("/usr/bin/objdump"); /* NOTE: hardcoded path . . . */
15 al
.add_argument("-dMintel");
16 al
.add_argument("--section=.text");
17 al
.add_argument(elf_parser
->get_filename());
19 bi_pipe
= new Platform::BidirectionalPipe(al
, true);
21 Message::Message(Aesalon::Monitor::Message::DEBUG_MESSAGE
, "Beginning disassembly of target");
22 parse_objdump_output();
23 Message::Message(Aesalon::Monitor::Message::DEBUG_MESSAGE
, "Disassembly of target completed");
27 void Disassembler::parse_objdump_output() {
29 Misc::SmartPointer
<ELF::Symbol
> symbol
= NULL
;
30 while(bi_pipe
->is_open()) {
31 line
= bi_pipe
->get_string();
32 if(line
== "") continue;
34 /*std::cout << "parsing objdump line \"" << line << "\"\n";*/
37 Misc::String::to
<Word
>(line
, address
, true);
38 if(address
< elf_parser
->get_section(".text")->get_virtual_address()) continue;
40 line
.erase(0, line
.find(" "));
41 while(line
[0] == ' ') line
.erase(0, 1);
45 line
.erase(line
.find(">"));
46 /* NOTE: ignores all symbols beginning with __ . . . */
47 if(line
.substr(0, 2) == "__") symbol
= NULL
;
49 symbol
= elf_parser
->get_symbol(line
);
50 /*std::cout << "\tSymbol name is \"" << line << "\"\n";*/
54 /* it's an instruction . . . */
55 if(!symbol
.is_valid()) continue; /* Continue if there's no resolved symbol ATM . . . */
56 if(line
.find("<") != std::string::npos
) line
.erase(line
.find("<"));
57 bool finished
= false;
60 Misc::String::to
<Byte
>(line
.substr(0, 2), value
, true);
64 while(line
.length() && line
[line
.length()-1] == ' ') line
.erase(line
.length()-1);
65 while(line
.length() && (line
[0] == ' ' || line
[0] == '\t')) {
68 if(line
== "") continue;
69 std::cout
<< "\tAssembly instruction is \"" << line
<< "\"\n";
70 /* Now parse the instruction and push it onto the InstructionList for the symbol . . . */
71 if(!symbol_to_il
[symbol
->get_symbol_name()].is_valid())
72 symbol_to_il
[symbol
->get_symbol_name()] = new InstructionList(symbol
->get_address());
74 symbol_to_il
[symbol
->get_symbol_name()]->add_instruction(new Instruction(line
));
79 } // namespace Monitor
80 } // namespace Aesalon