-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathlibgdb.c
67 lines (53 loc) · 1.4 KB
/
libgdb.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
/**
* \file libgdb.c
* \brief GDB mode main loop
* \author Antoine Fraboulet
* \date 2007
**/
#include "arch/common/hardware.h"
#include "machine/machine.h"
#include "libselect/libselect_socket.h"
#include "gdbremote.h"
#include "gdbremote_utils.h"
#include "libgdb.h"
/* ************************************************** */
/* ************************************************** */
#define MAXPORT 200
int libgdb_target_mode_main(unsigned short port)
{
char tcpsocket[MAXPORT];
int retcode = GDB_CMD_DETACH;
struct gdbremote_t gdb;
snprintf(tcpsocket, MAXPORT, "tcp:s:localhost:%d", port);
if (libselect_skt_init(& gdb.skt, tcpsocket))
{
return GDB_INIT_ERROR;
}
machine_state_save();
do
{
if (libselect_skt_accept(& gdb.skt))
{
ERROR("** GDB accept error\n");
break;
}
while ((retcode = gdbremote_getcmd(& gdb)) == GDB_CMD_OK) ;
}
while (retcode != GDB_CMD_ERROR && retcode != GDB_CMD_KILL); // DETACH left
switch (retcode)
{
case GDB_CMD_ERROR:
ERROR("Main:GDB getcmd returned with an error\n");
break;
case GDB_CMD_KILL:
ERROR("Main:GDB simulator was killed by remote gdb\n");
break;
}
if (libselect_skt_close(& gdb.skt))
{
return GDB_CLOSE_ERROR;
}
return GDB_OK;
}
/* ************************************************** */
/* ************************************************** */