Bit of a design issue here, regarding the GDB::Controller class.
[aesalon.git] / src / interface / gdb / SymbolParser.cpp
blob275a945250388ca3015e0674e47d0aa2c5c17f10
1 #include <sstream>
2 #include <iomanip>
3 #include <iostream>
5 #include "SymbolParser.h"
6 #include "Controller.h"
8 namespace Aesalon {
9 namespace Interface {
10 namespace GDB {
12 SymbolParser::SymbolParser(Misc::SmartPointer<Controller> controller) : StreamHandler(controller) {
13 assembly_parser = new AssemblyParser();
14 in_scope = true;
15 first = true;
18 SymbolParser::~SymbolParser() {
21 void SymbolParser::parse_symbol(Misc::SmartPointer<Platform::Symbol> symbol) {
22 if(symbol->is_parsed()) return;
23 current_symbol = symbol;
24 first = true;
25 in_scope = true; /* it's assumed that the first instruction is within the scope. */
26 get_controller()->send_command(Misc::StreamAsString() << "-interpreter-exec console \"x/i " << symbol->get_address() << "\"");
27 while(true) {
28 was_stream = false;
29 while(!was_stream) get_controller()->listen();
30 if(in_scope) get_controller()->send_command(Misc::StreamAsString() << "-interpreter-exec console \"x/i\"");
31 else break;
34 symbol->set_parsed(true);
37 bool SymbolParser::handle(Misc::SmartPointer<StreamOutput> stream) {
38 std::cout << "SymbolParser::handle_stream: stream content is: " << stream->get_stream_data() << std::endl;
39 was_stream = true;
40 if(!in_scope) return true;
41 if(first) {
42 first = false;
43 std::stringstream ss;
44 ss << stream->get_stream_data();
45 ss >> address;
46 std::string symbol_name;
47 ss >> symbol_name;
48 scope = symbol_name.substr(1, symbol_name.length()-3);
49 /*std::cout << "Scope is: \"" << scope << "\"\n";*/
51 else {
52 std::stringstream ss;
53 ss << stream->get_stream_data();
54 ss >> address;
55 std::string symbol_name;
56 ss >> symbol_name;
57 std::string temporary_scope;
58 temporary_scope = symbol_name.substr(1, symbol_name.length()-3);
59 temporary_scope = temporary_scope.substr(0, temporary_scope.find("+"));
60 if(scope != temporary_scope) {
61 /*std::cout << "Scope \"" << temporary_scope << "\" does not match original of \"" << scope << "\"" << std::endl;*/
62 in_scope = false;
63 return true;
67 /* Add one to get rid of the tab that comes before the instruction . . . */
68 std::string asm_instruction = stream->get_stream_data().substr(stream->get_stream_data().find(":")+2);
69 asm_instruction.erase(asm_instruction.length()-1, 1);
71 if(assembly_parser->changes_memory(asm_instruction)) add_breakpoint();
72 return true;
75 void SymbolParser::add_breakpoint() {
76 get_controller()->send_command(Misc::StreamAsString() << "-break-insert *" << address << "\"");
79 } // namespace GDB
80 } // namespace Interface
81 } // namespace Aesalon