-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_mi.c
92 lines (82 loc) · 2.1 KB
/
test_mi.c
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MIList.h"
#include "MIString.h"
#include "MISession.h"
#include "MIError.h"
#include "MIResultRecord.h"
#include "MIBreakpoint.h"
void
cmd_callback(MIResultRecord *rr, void *sess)
{
MIString *str = MIResultRecordToString(rr);
printf("res> %s\n", MIStringToCString(str));
MIStringFree(str);
}
void
console_callback(char *str)
{
printf("cons> %s\n", str);
}
void
log_callback(char *str)
{
printf("log> %s\n", str);
}
void
sendcmd_wait(MISession *sess, MICommand *cmd)
{
MISessionSendCommand(sess, cmd);
do {
MISessionProgress(sess);
} while (!MICommandCompleted(cmd));
}
int main(int argc, char *argv[])
{
MISession *sess;
MICommand *cmd;
MIList *bpts;
MIBreakpoint *bpt;
sess = MISessionNew();
MISessionSetDebug(1);
if (MISessionStartLocal(sess, "test_mi") < 0) {
fprintf(stderr, "%s", MIGetErrorStr());
return 1;
}
MISessionRegisterConsoleCallback(sess, console_callback);
MISessionRegisterLogCallback(sess, log_callback);
printf("help command\n");
cmd = MICommandNew("help", MIResultRecordDONE);
MICommandRegisterCallback(cmd, cmd_callback, sess);
sendcmd_wait(sess, cmd);
if (!MICommandResultOK(cmd))
fprintf(stderr, "command failed\n");
MICommandFree(cmd);
printf("set command\n");
cmd = MIGDBSet("confirm", "off");
MICommandRegisterCallback(cmd, cmd_callback, sess);
sendcmd_wait(sess, cmd);
if (!MICommandResultOK(cmd))
fprintf(stderr, "command failed\n");
MICommandFree(cmd);
printf("break command\n");
cmd = MIBreakInsert(0, 0, NULL, 0, "4", 0);
MICommandRegisterCallback(cmd, cmd_callback, sess);
sendcmd_wait(sess, cmd);
if (!MICommandResultOK(cmd))
fprintf(stderr, "command failed\n");
bpts = MIBreakpointGetBreakInsertInfo(cmd);
if (bpts != NULL)
for (MIListSet(bpts); (bpt = (MIBreakpoint *)MIListGet(bpts)) != NULL; )
printf("bpt id = %d\n", bpt->number);
MICommandFree(cmd);
printf("quit command\n");
cmd = MIGDBExit();
MICommandRegisterCallback(cmd, cmd_callback, sess);
sendcmd_wait(sess, cmd);
if (!MICommandResultOK(cmd))
fprintf(stderr, "command failed\n");
MICommandFree(cmd);
return 0;
}