1 /*
2 Copyright (c) 1998--2006 Benhur Stein
3
4 This file is part of Paj�.
5
6 Paj� is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10
11 Paj� is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with Paj�; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
19 */
20
21
22 //////////////////////////////////////////////////
23 /* Author: Geovani Ricardo Wiedenhoft */
24 /* Email: grw@inf.ufsm.br */
25 //////////////////////////////////////////////////
26
27
28
29 #include "JRastro.h"
30
31 /*Funcao que descreve nome do erro*/
jrst_describe_error(jvmtiEnv * jvmtiLocate,jvmtiError error)32 void jrst_describe_error(jvmtiEnv *jvmtiLocate, jvmtiError error)
33 {
34 char *describe;
35 jvmtiError err;
36
37 describe=NULL;
38 err=(*jvmtiLocate)->GetErrorName(jvmtiLocate, error, &describe);
39 if(err != JVMTI_ERROR_NONE){
40 printf("\n[JRastro ERROR]: Cannot Get Error:(%d) Name\n",error);
41 return;
42 }
43
44 printf("\n[JRastro ERROR](%d): <%s>\n",error,(describe==NULL?"Unknown":describe));
45 err=(*jvmtiLocate)->Deallocate(jvmtiLocate, (unsigned char *)describe);
46 if(err != JVMTI_ERROR_NONE){
47 printf("\n[JRastro ERROR]: Cannot Deallocate\n");
48 return;
49 }
50 }
51
52 /*Funcao que verifica se exite erro no retorno da JVMTI*/
jrst_check_error(jvmtiEnv * jvmtiLocate,jvmtiError error,const char * frase)53 void jrst_check_error(jvmtiEnv *jvmtiLocate, jvmtiError error, const char *frase)
54 {
55 if (error!= JVMTI_ERROR_NONE){
56 jrst_describe_error(jvmtiLocate,error);
57 if(frase != NULL){
58 printf("\t%s\n",frase);
59 }
60 exit(1);
61 }
62 }
63
64 /*Entra na regiao critica*/
jrst_enter_critical_section(jvmtiEnv * jvmtiLocate,jrawMonitorID monitor)65 void jrst_enter_critical_section(jvmtiEnv *jvmtiLocate, jrawMonitorID monitor)
66 {
67 jvmtiError error;
68 error=(*jvmtiLocate)->RawMonitorEnter(jvmtiLocate, monitor);
69 jrst_check_error(jvmtiLocate, error, "Cannot enter with raw monitor");
70 }
71
72 /*Sai da regiao critica*/
jrst_exit_critical_section(jvmtiEnv * jvmtiLocate,jrawMonitorID monitor)73 void jrst_exit_critical_section(jvmtiEnv *jvmtiLocate, jrawMonitorID monitor)
74 {
75 jvmtiError error;
76 error=(*jvmtiLocate)->RawMonitorExit(jvmtiLocate, monitor);
77 jrst_check_error(jvmtiLocate, error, "Cannot exit with raw monitor");
78 }
79
80 /*Devolve o nome da Thread desejada*/
jrst_get_thread_name(jvmtiEnv * jvmtiLocate,jthread thread,char * name,int numMax)81 void jrst_get_thread_name(jvmtiEnv *jvmtiLocate, jthread thread, char *name, int numMax)
82 {
83 jvmtiThreadInfo infoThread;
84 jvmtiError error;
85
86 (void)memset(&infoThread, 0, sizeof(infoThread));
87 error=(*jvmtiLocate)->GetThreadInfo(jvmtiLocate, thread, &infoThread);
88 jrst_check_error(jvmtiLocate, error, "Cannot get Thread Info");
89 if(infoThread.name != NULL){
90 int len;
91 len = (int)strlen(infoThread.name);
92 if(len < numMax){
93 (void)strcpy(name, infoThread.name);
94 }else {
95 (void)strcpy(name,"Unknown");
96
97 }
98 error=(*jvmtiLocate)->Deallocate(jvmtiLocate, (unsigned char *)infoThread.name);
99 jrst_check_error(jvmtiLocate, error,"Cannot deallocate memory");
100 return;
101 }
102 (void)strcpy(name,"Unknown");
103 }
104
jrst_trace_class(char * className)105 bool jrst_trace_class(char *className)
106 {
107 if(tracesAll || hash_find(&h_options, "*") || hash_find(&h_options, className)){
108 return true;
109 }
110 return false;
111 }
112
jrst_trace_methods()113 bool jrst_trace_methods()
114 {
115 if(tracesAll){
116 return true;
117 }
118 return false;
119 }
120
121 /*
122 bool jrst_trace(void *key)
123 {
124 printf("jrst_trace\n");
125 if(hash_find(&h, key)){
126 return true;
127 }
128 return false;
129 }
130 */
131
132