serialoutput: optional character limit

This prevents unlimited memory consumption in case the guest system
enters an endless loop.

Change-Id: Ia1bb178f7d8cb8ad8bf958210d90f6d7c2e11359
This commit is contained in:
Horst Schirmeier
2014-02-14 20:13:05 +01:00
parent c319f3458c
commit 455c088cd9
2 changed files with 7 additions and 2 deletions

View File

@ -10,7 +10,9 @@ bool SerialOutputLogger::run()
while (true) {
simulator.addListener(&ev_ioport);
simulator.resume();
m_output += ev_ioport.getData();
if (m_output.size() < m_limit) {
m_output += ev_ioport.getData();
}
}
return true;
}

View File

@ -22,6 +22,7 @@ class SerialOutputLogger : public fail::ExperimentFlow
private:
bool m_out; //!< Defines the direction of the listener.
unsigned m_port; //!< the port the listener is listening on
unsigned m_limit; //!< character limit
std::string m_output; //!< contains the traffic of ioport
public:
@ -29,11 +30,13 @@ public:
* Constructor of SerialOutput.
*
* @param port the port the listener is listening on
* @param char_limit limits the number of recorded characters (0 = no limit)
* @param out Defines the direction of the listener.
* \arg \c true Output on the given port is captured. This is default.
* \arg \c false Input on the given port is captured.
*/
SerialOutputLogger(unsigned port, bool out = true) : m_out(out), m_port(port) { }
SerialOutputLogger(unsigned port, unsigned char_limit = 0, bool out = true)
: m_out(out), m_port(port), m_limit(char_limit) { }
bool run();
/**
* Resets the output variable which contains the traffic of