Author: stepan
Date: 2009-11-26 20:27:31 +0100 (Thu, 26 Nov 2009)
New Revision: 73
Modified:
trunk/qemu-0.11.0/monitor.c
trunk/qemu-0.11.0/qemu-monitor.hx
trunk/qemu-0.11.0/serialice.c
trunk/qemu-0.11.0/serialice.h
Log:
initial version of "lua" command for qemu monitor. We should probably use a
separate thread for this, but it seems to work so far.
CTRL-ALT-2
QEMU 0.11.0 monitor - type 'help' for more information
(qemu) lua
(lua) printf "Hello\n"
---> output goes to "log"
(lua) quit
Exited LUA shell.
(qemu)
Signed-off-by: Stefan Reinauer <stepan(a)coresystems.de>
Modified: trunk/qemu-0.11.0/monitor.c
===================================================================
--- trunk/qemu-0.11.0/monitor.c 2009-11-26 15:52:41 UTC (rev 72)
+++ trunk/qemu-0.11.0/monitor.c 2009-11-26 19:27:31 UTC (rev 73)
@@ -38,6 +38,7 @@
#include "console.h"
#include "block.h"
#include "audio/audio.h"
+#include "serialice.h"
#include "disas.h"
#include "balloon.h"
#include "qemu-timer.h"
@@ -1239,6 +1240,37 @@
qemu_system_powerdown_request();
}
+#if defined(CONFIG_SERIALICE)
+static void monitor_command_lua(Monitor *mon, const char *cmdline, void *opaque)
+{
+ const char *errmsg;
+
+ if (!strncasecmp("quit", cmdline, 5)) {
+ monitor_printf(mon, "Exited LUA shell.\n");
+ readline_start(mon->rs, "(qemu) ", 0, monitor_command_cb, NULL);
+ readline_show_prompt(mon->rs);
+ return;
+ }
+
+ errmsg = serialice_lua_execute(cmdline);
+ if(errmsg) {
+ monitor_printf(mon, "Lua error: %s\n", errmsg);
+ free (errmsg);
+ }
+
+ readline_show_prompt(mon->rs);
+}
+
+static void do_lua(Monitor *mon)
+{
+ if (serialice_active) {
+ readline_start(mon->rs, "(lua) ", 0, monitor_command_lua, NULL);
+ } else {
+ monitor_printf(mon, "SerialICE is not active.\n");
+ }
+}
+#endif
+
#if defined(TARGET_I386)
static void print_pte(Monitor *mon, uint32_t addr, uint32_t pte, uint32_t mask)
{
Modified: trunk/qemu-0.11.0/qemu-monitor.hx
===================================================================
--- trunk/qemu-0.11.0/qemu-monitor.hx 2009-11-26 15:52:41 UTC (rev 72)
+++ trunk/qemu-0.11.0/qemu-monitor.hx 2009-11-26 19:27:31 UTC (rev 73)
@@ -170,6 +170,16 @@
Activate logging of the specified items to @file{/tmp/qemu.log}.
ETEXI
+#ifdef CONFIG_SERIALICE
+ { "lua", "", do_lua,
+ "", "go to lua shell" },
+#endif
+STEXI
+@item lua
+
+go to lua shell.
+ETEXI
+
{ "savevm", "s?", do_savevm,
"[tag|id]", "save a VM snapshot. If no tag or id are provided, a new snapshot is created" },
STEXI
Modified: trunk/qemu-0.11.0/serialice.c
===================================================================
--- trunk/qemu-0.11.0/serialice.c 2009-11-26 15:52:41 UTC (rev 72)
+++ trunk/qemu-0.11.0/serialice.c 2009-11-26 19:27:31 UTC (rev 73)
@@ -130,6 +130,20 @@
return 0;
}
+const char *serialice_lua_execute(const char *cmd)
+{
+ int error;
+ char *errstring = NULL;
+ error = luaL_loadbuffer(L, cmd, strlen(cmd), "line") ||
+ lua_pcall(L, 0, 0, 0);
+ if (error) {
+ errstring = strdup(lua_tostring(L, -1));
+ lua_pop(L, 1);
+ }
+
+ return errstring;
+}
+
static int serialice_io_read_filter(uint32_t *data, uint16_t port, int size)
{
int ret, result;
Modified: trunk/qemu-0.11.0/serialice.h
===================================================================
--- trunk/qemu-0.11.0/serialice.h 2009-11-26 15:52:41 UTC (rev 72)
+++ trunk/qemu-0.11.0/serialice.h 2009-11-26 19:27:31 UTC (rev 73)
@@ -32,6 +32,7 @@
void serialice_init(void);
void serialice_exit(void);
+const char *serialice_lua_execute(const char *cmd);
uint8_t serialice_inb(uint16_t port);
uint16_t serialice_inw(uint16_t port);