.. | .. |
---|
7 | 7 | #include <stdlib.h> |
---|
8 | 8 | #include <err.h> |
---|
9 | 9 | #include <jvmti.h> |
---|
| 10 | +#ifdef HAVE_JVMTI_CMLR |
---|
10 | 11 | #include <jvmticmlr.h> |
---|
| 12 | +#endif |
---|
11 | 13 | #include <limits.h> |
---|
12 | 14 | |
---|
13 | 15 | #include "jvmti_agent.h" |
---|
.. | .. |
---|
28 | 30 | } |
---|
29 | 31 | } |
---|
30 | 32 | |
---|
| 33 | +#ifdef HAVE_JVMTI_CMLR |
---|
31 | 34 | static jvmtiError |
---|
32 | | -do_get_line_numbers(jvmtiEnv *jvmti, void *pc, jmethodID m, jint bci, |
---|
33 | | - jvmti_line_info_t *tab, jint *nr) |
---|
| 35 | +do_get_line_number(jvmtiEnv *jvmti, void *pc, jmethodID m, jint bci, |
---|
| 36 | + jvmti_line_info_t *tab) |
---|
34 | 37 | { |
---|
35 | | - jint i, lines = 0; |
---|
36 | | - jint nr_lines = 0; |
---|
| 38 | + jint i, nr_lines = 0; |
---|
37 | 39 | jvmtiLineNumberEntry *loc_tab = NULL; |
---|
38 | 40 | jvmtiError ret; |
---|
| 41 | + jint src_line = -1; |
---|
39 | 42 | |
---|
40 | 43 | ret = (*jvmti)->GetLineNumberTable(jvmti, m, &nr_lines, &loc_tab); |
---|
41 | | - if (ret != JVMTI_ERROR_NONE) { |
---|
| 44 | + if (ret == JVMTI_ERROR_ABSENT_INFORMATION || ret == JVMTI_ERROR_NATIVE_METHOD) { |
---|
| 45 | + /* No debug information for this method */ |
---|
| 46 | + return ret; |
---|
| 47 | + } else if (ret != JVMTI_ERROR_NONE) { |
---|
42 | 48 | print_error(jvmti, "GetLineNumberTable", ret); |
---|
43 | 49 | return ret; |
---|
44 | 50 | } |
---|
45 | 51 | |
---|
46 | | - for (i = 0; i < nr_lines; i++) { |
---|
47 | | - if (loc_tab[i].start_location < bci) { |
---|
48 | | - tab[lines].pc = (unsigned long)pc; |
---|
49 | | - tab[lines].line_number = loc_tab[i].line_number; |
---|
50 | | - tab[lines].discrim = 0; /* not yet used */ |
---|
51 | | - tab[lines].methodID = m; |
---|
52 | | - lines++; |
---|
53 | | - } else { |
---|
54 | | - break; |
---|
55 | | - } |
---|
| 52 | + for (i = 0; i < nr_lines && loc_tab[i].start_location <= bci; i++) { |
---|
| 53 | + src_line = i; |
---|
56 | 54 | } |
---|
| 55 | + |
---|
| 56 | + if (src_line != -1) { |
---|
| 57 | + tab->pc = (unsigned long)pc; |
---|
| 58 | + tab->line_number = loc_tab[src_line].line_number; |
---|
| 59 | + tab->discrim = 0; /* not yet used */ |
---|
| 60 | + tab->methodID = m; |
---|
| 61 | + |
---|
| 62 | + ret = JVMTI_ERROR_NONE; |
---|
| 63 | + } else { |
---|
| 64 | + ret = JVMTI_ERROR_ABSENT_INFORMATION; |
---|
| 65 | + } |
---|
| 66 | + |
---|
57 | 67 | (*jvmti)->Deallocate(jvmti, (unsigned char *)loc_tab); |
---|
58 | | - *nr = lines; |
---|
59 | | - return JVMTI_ERROR_NONE; |
---|
| 68 | + |
---|
| 69 | + return ret; |
---|
60 | 70 | } |
---|
61 | 71 | |
---|
62 | 72 | static jvmtiError |
---|
.. | .. |
---|
64 | 74 | { |
---|
65 | 75 | const jvmtiCompiledMethodLoadRecordHeader *hdr; |
---|
66 | 76 | jvmtiCompiledMethodLoadInlineRecord *rec; |
---|
67 | | - jvmtiLineNumberEntry *lne = NULL; |
---|
68 | 77 | PCStackInfo *c; |
---|
69 | | - jint nr, ret; |
---|
| 78 | + jint ret; |
---|
70 | 79 | int nr_total = 0; |
---|
71 | 80 | int i, lines_total = 0; |
---|
72 | 81 | |
---|
.. | .. |
---|
79 | 88 | for (hdr = compile_info; hdr != NULL; hdr = hdr->next) { |
---|
80 | 89 | if (hdr->kind == JVMTI_CMLR_INLINE_INFO) { |
---|
81 | 90 | rec = (jvmtiCompiledMethodLoadInlineRecord *)hdr; |
---|
82 | | - for (i = 0; i < rec->numpcs; i++) { |
---|
83 | | - c = rec->pcinfo + i; |
---|
84 | | - nr = 0; |
---|
85 | | - /* |
---|
86 | | - * unfortunately, need a tab to get the number of lines! |
---|
87 | | - */ |
---|
88 | | - ret = (*jvmti)->GetLineNumberTable(jvmti, c->methods[0], &nr, &lne); |
---|
89 | | - if (ret == JVMTI_ERROR_NONE) { |
---|
90 | | - /* free what was allocated for nothing */ |
---|
91 | | - (*jvmti)->Deallocate(jvmti, (unsigned char *)lne); |
---|
92 | | - nr_total += (int)nr; |
---|
93 | | - } else { |
---|
94 | | - print_error(jvmti, "GetLineNumberTable", ret); |
---|
95 | | - } |
---|
96 | | - } |
---|
| 91 | + nr_total += rec->numpcs; |
---|
97 | 92 | } |
---|
98 | 93 | } |
---|
99 | 94 | |
---|
.. | .. |
---|
112 | 107 | rec = (jvmtiCompiledMethodLoadInlineRecord *)hdr; |
---|
113 | 108 | for (i = 0; i < rec->numpcs; i++) { |
---|
114 | 109 | c = rec->pcinfo + i; |
---|
115 | | - nr = 0; |
---|
116 | | - ret = do_get_line_numbers(jvmti, c->pc, |
---|
117 | | - c->methods[0], |
---|
118 | | - c->bcis[0], |
---|
119 | | - *tab + lines_total, |
---|
120 | | - &nr); |
---|
| 110 | + /* |
---|
| 111 | + * c->methods is the stack of inlined method calls |
---|
| 112 | + * at c->pc. [0] is the leaf method. Caller frames |
---|
| 113 | + * are ignored at the moment. |
---|
| 114 | + */ |
---|
| 115 | + ret = do_get_line_number(jvmti, c->pc, |
---|
| 116 | + c->methods[0], |
---|
| 117 | + c->bcis[0], |
---|
| 118 | + *tab + lines_total); |
---|
121 | 119 | if (ret == JVMTI_ERROR_NONE) |
---|
122 | | - lines_total += nr; |
---|
| 120 | + lines_total++; |
---|
123 | 121 | } |
---|
124 | 122 | } |
---|
125 | 123 | } |
---|
126 | 124 | *nr_lines = lines_total; |
---|
127 | 125 | return JVMTI_ERROR_NONE; |
---|
128 | 126 | } |
---|
| 127 | +#else /* HAVE_JVMTI_CMLR */ |
---|
| 128 | + |
---|
| 129 | +static jvmtiError |
---|
| 130 | +get_line_numbers(jvmtiEnv *jvmti __maybe_unused, const void *compile_info __maybe_unused, |
---|
| 131 | + jvmti_line_info_t **tab __maybe_unused, int *nr_lines __maybe_unused) |
---|
| 132 | +{ |
---|
| 133 | + return JVMTI_ERROR_NONE; |
---|
| 134 | +} |
---|
| 135 | +#endif /* HAVE_JVMTI_CMLR */ |
---|
129 | 136 | |
---|
130 | 137 | static void |
---|
131 | 138 | copy_class_filename(const char * class_sign, const char * file_name, char * result, size_t max_length) |
---|
.. | .. |
---|
234 | 241 | char *class_sign = NULL; |
---|
235 | 242 | char *func_name = NULL; |
---|
236 | 243 | char *func_sign = NULL; |
---|
237 | | - char *file_name = NULL; |
---|
238 | | - char fn[PATH_MAX]; |
---|
239 | 244 | uint64_t addr = (uint64_t)(uintptr_t)code_addr; |
---|
240 | 245 | jvmtiError ret; |
---|
241 | 246 | int nr_lines = 0; /* in line_tab[] */ |
---|
.. | .. |
---|
252 | 257 | if (has_line_numbers && map && map_length) { |
---|
253 | 258 | ret = get_line_numbers(jvmti, compile_info, &line_tab, &nr_lines); |
---|
254 | 259 | if (ret != JVMTI_ERROR_NONE) { |
---|
255 | | - warnx("jvmti: cannot get line table for method"); |
---|
| 260 | + if (ret != JVMTI_ERROR_NOT_FOUND) { |
---|
| 261 | + warnx("jvmti: cannot get line table for method"); |
---|
| 262 | + } |
---|
256 | 263 | nr_lines = 0; |
---|
257 | 264 | } else if (nr_lines > 0) { |
---|
258 | 265 | line_file_names = malloc(sizeof(char*) * nr_lines); |
---|
.. | .. |
---|
270 | 277 | } |
---|
271 | 278 | } |
---|
272 | 279 | |
---|
273 | | - ret = (*jvmti)->GetSourceFileName(jvmti, decl_class, &file_name); |
---|
274 | | - if (ret != JVMTI_ERROR_NONE) { |
---|
275 | | - print_error(jvmti, "GetSourceFileName", ret); |
---|
276 | | - goto error; |
---|
277 | | - } |
---|
278 | | - |
---|
279 | 280 | ret = (*jvmti)->GetClassSignature(jvmti, decl_class, |
---|
280 | 281 | &class_sign, NULL); |
---|
281 | 282 | if (ret != JVMTI_ERROR_NONE) { |
---|
.. | .. |
---|
289 | 290 | print_error(jvmti, "GetMethodName", ret); |
---|
290 | 291 | goto error; |
---|
291 | 292 | } |
---|
292 | | - |
---|
293 | | - copy_class_filename(class_sign, file_name, fn, PATH_MAX); |
---|
294 | 293 | |
---|
295 | 294 | /* |
---|
296 | 295 | * write source line info record if we have it |
---|
.. | .. |
---|
311 | 310 | (*jvmti)->Deallocate(jvmti, (unsigned char *)func_name); |
---|
312 | 311 | (*jvmti)->Deallocate(jvmti, (unsigned char *)func_sign); |
---|
313 | 312 | (*jvmti)->Deallocate(jvmti, (unsigned char *)class_sign); |
---|
314 | | - (*jvmti)->Deallocate(jvmti, (unsigned char *)file_name); |
---|
315 | 313 | free(line_tab); |
---|
316 | 314 | while (line_file_names && (nr_lines > 0)) { |
---|
317 | 315 | if (line_file_names[nr_lines - 1]) { |
---|