-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuiltin-debug.c
More file actions
77 lines (58 loc) · 1.32 KB
/
builtin-debug.c
File metadata and controls
77 lines (58 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <kvm/util.h>
#include <kvm/builtin-debug.h>
#include <kvm/kvm.h>
#include <kvm/parse-options.h>
#include <kvm/kvm-ipc.h>
#include <kvm/read-write.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#define BUFFER_SIZE 100
static bool all;
static int nmi = -1;
static bool dump;
static const char *instance_name;
static const char *sysrq;
static int do_debug(const char *name, int sock)
{
char buff[BUFFER_SIZE];
struct debug_cmd_params cmd = {.dbg_type = 0};
int r;
if (dump)
cmd.dbg_type |= KVM_DEBUG_CMD_TYPE_DUMP;
if (nmi != -1) {
cmd.dbg_type |= KVM_DEBUG_CMD_TYPE_NMI;
cmd.cpu = nmi;
}
if (sysrq) {
cmd.dbg_type |= KVM_DEBUG_CMD_TYPE_SYSRQ;
cmd.sysrq = sysrq[0];
}
r = kvm_ipc__send_msg(sock, KVM_IPC_DEBUG, sizeof(cmd), (u8 *)&cmd);
if (r < 0)
return r;
if (!dump)
return 0;
do {
r = xread(sock, buff, BUFFER_SIZE);
if (r < 0)
return 0;
printf("%.*s", r, buff);
} while (r > 0);
return 0;
}
int kvm_cmd_debug(int argc, const char **argv, const char *prefix)
{
int instance;
int r;
if (all)
return kvm__enumerate_instances(do_debug);
if (instance_name == NULL)
return 1; // TODO: panic
instance = kvm__get_sock_by_instance(instance_name);
if (instance <= 0)
die("Failed locating instance");
r = do_debug(instance_name, instance);
close(instance);
return r;
}