diff --git a/monitor.c b/monitor.c
index 5659991..2b2005b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1187,13 +1187,26 @@ static void do_log(Monitor *mon, const QDict *qdict)
     cpu_set_log(mask);
 }

+/* flush all the TBs to force new code generation */
+static void flush_all_tb(void)
+{
+    CPUState *env;
+
+    for (env = first_cpu; env != NULL; env = env->next_cpu) {
+        tb_flush(env);
+    }
+}
+
 static void do_singlestep(Monitor *mon, const QDict *qdict)
 {
     const char *option = qdict_get_try_str(qdict, "option");
+
     if (!option || !strcmp(option, "on")) {
         singlestep = 1;
+        flush_all_tb();
     } else if (!strcmp(option, "off")) {
         singlestep = 0;
+        flush_all_tb();
     } else {
         monitor_printf(mon, "unexpected option %s\n", option);
     }
