/** * The <code>report()</code> method generates a textual report after the simulation is complete. * The text contains a breakdown each procedure called in the program and the corresponding * number of cycles spent in it during program execution. Addionally the number of cycles spent * in sleep mode is provided. */ public void report() { // log current state long cycles = simulator.getState().getCycles() - lastChange; if (cycles > 0) { if (currentMode != null) { // system not sleeping currentMode.cycles += cycles; } else { // system sleeping sleepCycles += cycles; } } // display data TermUtil.printSeparator("Energy breakdown for node " + simulator.getID()); Terminal.printCyan("notation: procedureName@Address: cycles\n"); Iterator it = profiles.iterator(); while (it.hasNext()) { EnergyProfile profile = (EnergyProfile) it.next(); if (profile.cycles > 0) { Terminal.println( " " + profile.location.name + '@' + profile.location.lma_addr + ": " + profile.cycles); } } if (sleepCycles > 0) Terminal.println(" sleeping: " + sleepCycles); Terminal.println(""); }
public void fireBefore(State s, int pc) { if (printer != null) { printer.println("--IN STARTUP PROBE @ " + StringUtil.addrToString(pc) + "--"); } Terminal.println("GDBServer listening on port " + port + "..."); Terminal.flush(); try { socket = serverSocket.accept(); input = socket.getInputStream(); output = socket.getOutputStream(); if (printer != null) printer.println( "Connection established with: " + socket.getInetAddress().getCanonicalHostName()); serverSocket.close(); } catch (IOException e) { throw Util.failure("Unexpected IOException: " + e); } commandLoop(null); }
/** * The <code>commandLoop()</code> method reads commands from the GDB socket and executes them * until a command causes the simulation to resume (e.g. a continue, step, etc). This method is * called from within probes inserted into the simulation. Optionally, a reply can be sent * before the command loop is entered. For example, a trap would need to send a "T05" reply to * the remote gdb to signal that the simulation has stopped before waiting for commands. * * @param reply a reply to send before executing commands, if any */ void commandLoop(String reply) { try { if (reply != null) { sendPacket(reply); } while (true) { String command = readCommand(); if (command == null) { Terminal.println("GDBServer: null command, stopping simulator"); simulator.stop(); break; } if (printer != null) { printer.println(" --> " + command); } // invoke the command: continue the program if the return value is true if (executeCommand(command)) break; } } catch (IOException e) { throw Util.failure("Unexpected IOException: " + e); } }
/** * The <code>executeCommand()</code> method executes a single command that has been read from * the socket and packaged as a string. If the command should resume the simulation, this method * will return <code>true</code>, and <code>false</code> otherwise. * * @param command the command packaged as a string * @return true if the simulation should resume; false otherwise * @throws IOException if there is a problem communicating over the socket */ boolean executeCommand(String command) throws IOException { CharacterIterator i = new StringCharacterIterator(command); if (i.current() == '+') i.next(); if (!StringUtil.peekAndEat(i, '$')) { commandError(); return false; } char c = i.current(); i.next(); switch (c) { case 'c': // CONTINUE WITH EXECUTION // TODO: implement continue at address sendPlus(); return true; case 'D': // DISCONNECT Terminal.println("GDBServer: disconnected"); sendPlus(); simulator.stop(); return true; case 'g': // READ REGISTERS readAllRegisters(); return false; case 'G': // WRITE REGISTERS // TODO: implement update of registers break; case 'H': // SET THREAD CONTEXT -- THERE IS ONLY ONE sendPacketOK("OK"); return false; case 'i': // STEP CYCLE isStepping = true; break; case 'k': // KILL Terminal.println("GDBServer: killed remotely"); sendPlus(); simulator.stop(); return true; case 'm': readMemory(i); return false; case 'M': // WRITE MEMORY // TODO: implement writes to memory break; case 'p': // READ SELECTED REGISTERS readOneRegister(i); return false; case 'P': // WRITE SELECTED REGISTERS // TODO: implement writes to selected registers break; case 'q': // QUERY A VARIABLE // TODO: implement queries to variables break; case 's': // STEP INSTRUCTION isStepping = true; sendPlus(); return true; case 'z': // REMOVE BREAKPOINT setBreakPoint(i, false); return false; case 'Z': // SET BREAKPOINT setBreakPoint(i, true); return false; case '?': // GET LAST SIGNAL sendPacketOK("S05"); return false; } // didn't understand the comand sendPacketOK(""); return false; }