1 /* src/native/jvmti/cacaodbgserver.c - contains the cacaodbgserver process. This
2 process controls the debuggee/cacao vm.
4 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
5 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
6 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
7 J. Wenninger, Institut f. Computersprachen - TU Wien
9 This file is part of CACAO.
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2, or (at
14 your option) any later version.
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 Contact: cacao@complang.tuwien.ac.at
28 Authors: Martin Platter
30 Changes: Edwin Steiner
33 $Id: cacao.c,v 3.165 2006/01/03 23:44:38 twisti Exp $
37 #include "native/jvmti/cacaodbgserver.h"
38 #include "native/jvmti/cacaodbg.h"
39 #include "native/jvmti/dbg.h"
40 #include <sys/types.h>
49 /* getchildprocptrace *********************************************************
51 Get data count number of bytes from address addr for child process address
52 space. Requested data is stored in the array pointed to by ptr.
54 *******************************************************************************/
55 static void getchildprocptrace (char *ptr, void* addr, int cnt) {
57 long *p = (long*) ptr;
59 longcnt = cnt/sizeof(long);
60 for (i=0; i<longcnt; i++) {
61 p[i]=GETMEM(debuggee,addr);
64 fprintf(stderr,"cacaodbgserver process: getchildprocptrace: %ld\n",i);
65 perror("cacaodbgserver process: getchildprocptrace:");
70 i = GETMEM(debuggee,addr);
71 memcpy(p+longcnt,&i,cnt%sizeof(long));
75 /* waitloop *******************************************************************
77 waits and handles signals from debuggee/child process. Returns true if
78 cacaodbgserver should exit.
80 *******************************************************************************/
82 static bool waitloop(void* dbgcvm) {
83 int status,retval,signal;
86 cacaodbgcommunication vm;
90 fprintf(stderr,"waitloop\n");
92 retval = wait(&status);
94 fprintf(stderr,"cacaodbgserver: waitloop we got something to do\n");
96 fprintf(stderr,"error in waitloop\n");
97 perror("cacaodbgserver process: waitloop: ");
101 if (retval != debuggee) {
102 fprintf(stderr,"cacaodbgserver got signal from process other then debuggee/cacao vm\n");
106 if (WIFSTOPPED(status)) {
107 signal = WSTOPSIG(status);
109 /* ignore SIGSEGV, SIGPWR, SIGBUS and SIGXCPU for now.
110 todo: in future this signals could be used to detect Garbage
111 Collection Start/Finish or NullPointerException Events */
112 if ((signal == SIGSEGV) || (signal == SIGPWR) ||
113 (signal == SIGBUS) || (signal == SIGXCPU)) {
114 fprintf(stderr,"cacaodbgserver: ignore internal signal (%d)\n",signal);
115 CONT(debuggee,signal);
119 if (signal == SIGABRT) {
120 fprintf(stderr,"cacaodbgserver: got SIGABRT from debugee - exit\n");
124 ip = getip(debuggee);
125 ip--; /* EIP has already been incremented */
126 fprintf(stderr,"got signal: %d IP %X\n",signal,ip);
132 /* handle breakpoint */
133 getchildprocptrace((char*)&vm,dbgcvm,sizeof(cacaodbgcommunication));
136 /* set a breakpoint */
137 setbrk(debuggee, vm.brkaddr, &vm.brkorig);
142 if (signal == SIGTRAP) {
143 /* Breakpoint hit. Place original instruction and notify cacao vm to
145 fprintf(stderr,"breakpoint hit\n");
151 if (WIFEXITED(status)) {
152 fprintf(stderr,"cacaodbgserver: debuggee/cacao vm exited.\n");
156 if (WIFSIGNALED(status)) {
157 fprintf(stderr,"cacaodbgserver: child terminated by signal %d\n",WTERMSIG(status));
161 if (WIFCONTINUED(status)) {
162 fprintf(stderr,"cacaodbgserver: continued\n");
167 fprintf(stderr,"wait not handled(child not exited or stopped)\n");
168 fprintf(stderr,"retval: %d status: %d\n",retval,status);
173 /* main (cacaodbgserver) ******************************************************
175 main function for cacaodbgserver process.
177 *******************************************************************************/
179 int main(int argc, char **argv) {
185 fprintf(stderr,"cacaodbgserver: not enough arguments\n");
186 fprintf(stderr, "cacaodbgserver cacaodbgcommunicationaddress\n");
188 fprintf(stderr,"argc %d argv[0] %s\n",argc,argv[0]);
192 dbgcvm=(cacaodbgcommunication*)strtol(argv[1],NULL,16);
194 fprintf(stderr,"cacaodbgserver started pid %d ppid %d\n",getpid(), getppid());
196 debuggee = getppid();
198 if (TRACEATTACH(debuggee) == -1) perror("cacaodbgserver: ");
200 fprintf(stderr,"cacaovm attached\n");
202 if (wait(&status) == -1) {
203 fprintf(stderr,"error initial wait\n");
204 perror("cacaodbgserver: ");
208 if (WIFSTOPPED(status))
209 if (WSTOPSIG(status) == SIGSTOP)
213 running = !waitloop(dbgcvm);
215 fprintf(stderr,"cacaodbgserver exit\n");
220 * These are local overrides for various environment variables in Emacs.
221 * Please do not remove this and leave it at the end of the file, where
222 * Emacs will automagically detect them.
223 * ---------------------------------------------------------------------
226 * indent-tabs-mode: t
230 * vim:noexpandtab:sw=4:ts=4: