39 #include <sys/types.h>
61 if (close(fd) == -1) {
62 perror(
"unable to close pipe - ");
76 int cacao2gdbpipe[2],gdb2cacaopipe[2];
81 snprintf(gdbargs,20,
"--pid=%d",getppid());
85 fprintf(stderr,
"cacaodbgserver: fork error\n");
93 dup2(cacao2gdbpipe[0],0);
95 dup2(gdb2cacaopipe[1],1);
97 if (execlp(
"gdb",
"gdb",
"--interpreter=mi" ,gdbargs,(
char *) NULL)==-1){
98 fprintf(stderr,
"cacaodbgserver: unable to start gdb\n");
106 gdbin = fdopen(gdb2cacaopipe[0],
"r");
107 gdbout = fdopen(cacao2gdbpipe[1],
"w");
113 #define SENDCMD(CMD) \
114 fprintf(gdbout,"%s",CMD); \
122 i += strlen(&inbuf[i]);
123 if (fgets(&inbuf[i],buflen-i,
gdbin)==NULL) {
124 perror(
"cacaodbgserver: ");
138 char *match, inbuf[160];
140 fprintf(
gdbout,
"-data-evaluate-expression %s\n",expr);
145 fprintf(stderr,
"dataevaluate: no matching value\n");
159 int numberofbreakpoints,
i;
163 if ((match=strstr(sigbuf,
SIGADDR))==NULL) {
164 fprintf(stderr,
"commonbreakpointhandler: no matching address(%s)\n",
169 addr = strtoll(&match[strlen(
SIGADDR)],NULL,16);
173 numberofbreakpoints = (int)
dataevaluate(
"dbgcom->jvmtibrkpt.num");
178 snprintf(tmp,
INBUFLEN,
"dbgcom->jvmtibrkpt.brk[%d].addr",i);
179 }
while ((i<numberofbreakpoints) && (
dataevaluate(tmp) != addr));
181 assert(i<numberofbreakpoints);
197 fprintf(
gdbout,
"call jvmti_cacao_generic_breakpointhandler(%d)\n",i);
221 SENDCMD(
"handle SIGSEGV SIGPWR SIGXCPU SIGBUS noprint nostop\n");
233 if ((match=strstr(inbuf,
HCSIGTRAP))!=NULL) {
251 fprintf(stderr,
"gdbin not handled %s\n",inbuf);
254 fprintf(stderr,
"not handled 1\n");
257 fprintf(stderr,
"gdbin: %s\n",inbuf);
263 free(pending_brkpts);
272 int main(
int argc,
char **argv) {
#define CONSOLESTREAMOUTPUT
static void controlloop()
static void closepipeend(int fd)
static void getgdboutput(char *inbuf, int buflen)
int main(int argc, char **argv)
static unsigned long dataevaluate(char *expr)
Instruction::InstID tmp[]
#define CACAODBGSERVERQUIT
static bool commonbreakpointhandler(char *sigbuf, int sigtrap)
struct _pending_brkpt * pending_brkpts