Skip to content

Commit

Permalink
monitor: Rework API (Jan Kiszka)
Browse files Browse the repository at this point in the history
Refactor the monitor API and prepare it for decoupled terminals:
term_print functions are renamed to monitor_* and all monitor services
gain a new parameter (mon) that will once refer to the monitor instance
the output is supposed to appear on. However, the argument remains
unused for now. All monitor command callbacks are also extended by a mon
parameter so that command handlers are able to pass an appropriate
reference to monitor output services.

For the case that monitor outputs so far happen without clearly
identifiable context, the global variable cur_mon is introduced that
shall once provide a pointer either to the current active monitor (while
processing commands) or to the default one. On the mid or long term,
those use case will be obsoleted so that this variable can be removed
again.

Due to the broad usage of the monitor interface, this patch mostly deals
with converting users of the monitor API. A few of them are already
extended to pass 'mon' from the command handler further down to internal
functions that invoke monitor_printf.

At this chance, monitor-related prototypes are moved from console.h to
a new monitor.h. The same is done for the readline API.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6711 c046a42c-6fe2-441c-8c8c-71466251a162
  • Loading branch information
aliguori committed Mar 5, 2009
1 parent bb5fc20 commit 376253e
Show file tree
Hide file tree
Showing 45 changed files with 830 additions and 719 deletions.
6 changes: 3 additions & 3 deletions audio/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
#include "hw/hw.h"
#include "audio.h"
#include "console.h"
#include "monitor.h"
#include "qemu-timer.h"
#include "sysemu.h"

Expand Down Expand Up @@ -328,10 +328,10 @@ void AUD_vlog (const char *cap, const char *fmt, va_list ap)
{
if (conf.log_to_monitor) {
if (cap) {
term_printf ("%s: ", cap);
monitor_printf(cur_mon, "%s: ", cap);
}

term_vprintf (fmt, ap);
monitor_vprintf(cur_mon, fmt, ap);
}
else {
if (cap) {
Expand Down
21 changes: 11 additions & 10 deletions audio/wavcapture.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "hw/hw.h"
#include "console.h"
#include "monitor.h"
#include "audio.h"

typedef struct {
Expand Down Expand Up @@ -71,9 +71,9 @@ static void wav_capture_info (void *opaque)
WAVState *wav = opaque;
char *path = wav->path;

term_printf ("Capturing audio(%d,%d,%d) to %s: %d bytes\n",
wav->freq, wav->bits, wav->nchannels,
path ? path : "<not available>", wav->bytes);
monitor_printf(cur_mon, "Capturing audio(%d,%d,%d) to %s: %d bytes\n",
wav->freq, wav->bits, wav->nchannels,
path ? path : "<not available>", wav->bytes);
}

static struct capture_ops wav_capture_ops = {
Expand All @@ -84,6 +84,7 @@ static struct capture_ops wav_capture_ops = {
int wav_start_capture (CaptureState *s, const char *path, int freq,
int bits, int nchannels)
{
Monitor *mon = cur_mon;
WAVState *wav;
uint8_t hdr[] = {
0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56,
Expand All @@ -97,13 +98,13 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
CaptureVoiceOut *cap;

if (bits != 8 && bits != 16) {
term_printf ("incorrect bit count %d, must be 8 or 16\n", bits);
monitor_printf(mon, "incorrect bit count %d, must be 8 or 16\n", bits);
return -1;
}

if (nchannels != 1 && nchannels != 2) {
term_printf ("incorrect channel count %d, must be 1 or 2\n",
nchannels);
monitor_printf(mon, "incorrect channel count %d, must be 1 or 2\n",
nchannels);
return -1;
}

Expand Down Expand Up @@ -131,8 +132,8 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,

wav->f = qemu_fopen (path, "wb");
if (!wav->f) {
term_printf ("Failed to open wave file `%s'\nReason: %s\n",
path, strerror (errno));
monitor_printf(mon, "Failed to open wave file `%s'\nReason: %s\n",
path, strerror (errno));
qemu_free (wav);
return -1;
}
Expand All @@ -146,7 +147,7 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,

cap = AUD_add_capture (NULL, &as, &ops, wav);
if (!cap) {
term_printf ("Failed to add audio capture\n");
monitor_printf(mon, "Failed to add audio capture\n");
qemu_free (wav->path);
qemu_fclose (wav->f);
qemu_free (wav);
Expand Down
66 changes: 33 additions & 33 deletions block.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#endif

#include "qemu-common.h"
#include "console.h"
#include "monitor.h"
#include "block_int.h"

#ifdef _BSD
Expand Down Expand Up @@ -1091,66 +1091,66 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
return bs->drv->bdrv_is_allocated(bs, sector_num, nb_sectors, pnum);
}

void bdrv_info(void)
void bdrv_info(Monitor *mon)
{
BlockDriverState *bs;

for (bs = bdrv_first; bs != NULL; bs = bs->next) {
term_printf("%s:", bs->device_name);
term_printf(" type=");
monitor_printf(mon, "%s:", bs->device_name);
monitor_printf(mon, " type=");
switch(bs->type) {
case BDRV_TYPE_HD:
term_printf("hd");
monitor_printf(mon, "hd");
break;
case BDRV_TYPE_CDROM:
term_printf("cdrom");
monitor_printf(mon, "cdrom");
break;
case BDRV_TYPE_FLOPPY:
term_printf("floppy");
monitor_printf(mon, "floppy");
break;
}
term_printf(" removable=%d", bs->removable);
monitor_printf(mon, " removable=%d", bs->removable);
if (bs->removable) {
term_printf(" locked=%d", bs->locked);
monitor_printf(mon, " locked=%d", bs->locked);
}
if (bs->drv) {
term_printf(" file=");
term_print_filename(bs->filename);
monitor_printf(mon, " file=");
monitor_print_filename(mon, bs->filename);
if (bs->backing_file[0] != '\0') {
term_printf(" backing_file=");
term_print_filename(bs->backing_file);
}
term_printf(" ro=%d", bs->read_only);
term_printf(" drv=%s", bs->drv->format_name);
term_printf(" encrypted=%d", bdrv_is_encrypted(bs));
monitor_printf(mon, " backing_file=");
monitor_print_filename(mon, bs->backing_file);
}
monitor_printf(mon, " ro=%d", bs->read_only);
monitor_printf(mon, " drv=%s", bs->drv->format_name);
monitor_printf(mon, " encrypted=%d", bdrv_is_encrypted(bs));
} else {
term_printf(" [not inserted]");
monitor_printf(mon, " [not inserted]");
}
term_printf("\n");
monitor_printf(mon, "\n");
}
}

/* The "info blockstats" command. */
void bdrv_info_stats (void)
void bdrv_info_stats(Monitor *mon)
{
BlockDriverState *bs;
BlockDriverInfo bdi;

for (bs = bdrv_first; bs != NULL; bs = bs->next) {
term_printf ("%s:"
" rd_bytes=%" PRIu64
" wr_bytes=%" PRIu64
" rd_operations=%" PRIu64
" wr_operations=%" PRIu64
,
bs->device_name,
bs->rd_bytes, bs->wr_bytes,
bs->rd_ops, bs->wr_ops);
monitor_printf(mon, "%s:"
" rd_bytes=%" PRIu64
" wr_bytes=%" PRIu64
" rd_operations=%" PRIu64
" wr_operations=%" PRIu64
,
bs->device_name,
bs->rd_bytes, bs->wr_bytes,
bs->rd_ops, bs->wr_ops);
if (bdrv_get_info(bs, &bdi) == 0)
term_printf(" high=%" PRId64
" bytes_free=%" PRId64,
bdi.highest_alloc, bdi.num_free_bytes);
term_printf("\n");
monitor_printf(mon, " high=%" PRId64
" bytes_free=%" PRId64,
bdi.highest_alloc, bdi.num_free_bytes);
monitor_printf(mon, "\n");
}
}

Expand Down
4 changes: 2 additions & 2 deletions block.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ typedef struct QEMUSnapshotInfo {

#define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_CACHE_DEF)

void bdrv_info(void);
void bdrv_info_stats(void);
void bdrv_info(Monitor *mon);
void bdrv_info_stats(Monitor *mon);

void bdrv_init(void);
BlockDriver *bdrv_find_format(const char *format_name);
Expand Down
36 changes: 3 additions & 33 deletions console.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ struct mouse_transform_info_s {
int a[7];
};

void do_info_mice(void);
void do_mouse_set(int index);
void do_info_mice(Monitor *mon);
void do_mouse_set(Monitor *mon, int index);

/* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
constants) */
Expand Down Expand Up @@ -287,39 +287,9 @@ void vnc_display_init(DisplayState *ds);
void vnc_display_close(DisplayState *ds);
int vnc_display_open(DisplayState *ds, const char *display);
int vnc_display_password(DisplayState *ds, const char *password);
void do_info_vnc(void);
void do_info_vnc(Monitor *mon);

/* curses.c */
void curses_display_init(DisplayState *ds, int full_screen);

/* FIXME: term_printf et al should probably go elsewhere so everything
does not need to include console.h */
/* monitor.c */
void monitor_init(CharDriverState *hd, int show_banner);
void term_puts(const char *str);
void term_vprintf(const char *fmt, va_list ap);
void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
void term_print_filename(const char *filename);
void term_flush(void);
void term_print_help(void);
void monitor_suspend(void);
void monitor_resume(void);

#include "block.h"
void monitor_read_bdrv_key_start(BlockDriverState *bs,
BlockDriverCompletionFunc *completion_cb,
void *opaque);

/* readline.c */
typedef void ReadLineFunc(void *opaque, const char *str);

extern int completion_index;
void add_completion(const char *str);
void readline_handle_byte(int ch);
void readline_find_completion(const char *cmdline);
const char *readline_get_history(unsigned int index);
void readline_start(const char *prompt, int is_password,
ReadLineFunc *readline_func, void *opaque);
void readline_show_prompt(void);

#endif
17 changes: 8 additions & 9 deletions disas.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,7 @@ const char *lookup_symbol(target_ulong orig_addr)

#if !defined(CONFIG_USER_ONLY)

void term_vprintf(const char *fmt, va_list ap);
void term_printf(const char *fmt, ...);
#include "monitor.h"

static int monitor_disas_is_physical;
static CPUState *monitor_disas_env;
Expand All @@ -330,19 +329,19 @@ static int monitor_fprintf(FILE *stream, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
term_vprintf(fmt, ap);
monitor_vprintf((Monitor *)stream, fmt, ap);
va_end(ap);
return 0;
}

void monitor_disas(CPUState *env,
void monitor_disas(Monitor *mon, CPUState *env,
target_ulong pc, int nb_insn, int is_physical, int flags)
{
int count, i;
struct disassemble_info disasm_info;
int (*print_insn)(bfd_vma pc, disassemble_info *info);

INIT_DISASSEMBLE_INFO(disasm_info, NULL, monitor_fprintf);
INIT_DISASSEMBLE_INFO(disasm_info, (FILE *)mon, monitor_fprintf);

monitor_disas_env = env;
monitor_disas_is_physical = is_physical;
Expand Down Expand Up @@ -388,15 +387,15 @@ void monitor_disas(CPUState *env,
print_insn = print_insn_little_mips;
#endif
#else
term_printf("0x" TARGET_FMT_lx
": Asm output not supported on this arch\n", pc);
monitor_printf(mon, "0x" TARGET_FMT_lx
": Asm output not supported on this arch\n", pc);
return;
#endif

for(i = 0; i < nb_insn; i++) {
term_printf("0x" TARGET_FMT_lx ": ", pc);
monitor_printf(mon, "0x" TARGET_FMT_lx ": ", pc);
count = print_insn(pc, &disasm_info);
term_printf("\n");
monitor_printf(mon, "\n");
if (count < 0)
break;
pc += count;
Expand Down
8 changes: 7 additions & 1 deletion disas.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#ifndef _QEMU_DISAS_H
#define _QEMU_DISAS_H

#include "qemu-common.h"

/* Disassemble this for me please... (debugging). */
void disas(FILE *out, void *code, unsigned long size);
void target_disas(FILE *out, target_ulong code, target_ulong size, int flags);
void monitor_disas(CPUState *env,

/* The usual mess... FIXME: Remove this condition once dyngen-exec.h is gone */
#ifndef __DYNGEN_EXEC_H__
void monitor_disas(Monitor *mon, CPUState *env,
target_ulong pc, int nb_insn, int is_physical, int flags);
#endif

/* Look up symbol for debugging purpose. Returns "" if unknown. */
const char *lookup_symbol(target_ulong orig_addr);
Expand Down
5 changes: 3 additions & 2 deletions hw/an5206.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include "hw.h"
#include "pc.h"
#include "mcf.h"
#include "sysemu.h"
#include "boards.h"
Expand All @@ -16,11 +17,11 @@
#define AN5206_RAMBAR_ADDR 0x20000000

/* Stub functions for hardware that doesn't exist. */
void pic_info(void)
void pic_info(Monitor *mon)
{
}

void irq_info(void)
void irq_info(Monitor *mon)
{
}

Expand Down
5 changes: 3 additions & 2 deletions hw/arm_pic.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
*/

#include "hw.h"
#include "pc.h"
#include "arm-misc.h"

/* Stub functions for hardware that doesn't exist. */
void pic_info(void)
void pic_info(Monitor *mon)
{
}

void irq_info(void)
void irq_info(Monitor *mon)
{
}

Expand Down
5 changes: 3 additions & 2 deletions hw/etraxfs_pic.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <stdio.h>
#include "hw.h"
#include "pc.h"
#include "etraxfs.h"

#define D(x)
Expand Down Expand Up @@ -135,11 +136,11 @@ static CPUWriteMemoryFunc *pic_write[] = {
&pic_writel,
};

void pic_info(void)
void pic_info(Monitor *mon)
{
}

void irq_info(void)
void irq_info(Monitor *mon)
{
}

Expand Down
Loading

0 comments on commit 376253e

Please sign in to comment.