Commit | Line | Data |
---|---|---|
b5a8598f AB |
1 | /* |
2 | * Babeltrace - Debug Information State Tracker | |
3 | * | |
4 | * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation | |
5 | * Copyright (c) 2015 Philippe Proulx <pproulx@efficios.com> | |
6 | * Copyright (c) 2015 Antoine Busque <abusque@efficios.com> | |
458af89d | 7 | * Copyright (c) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
b5a8598f AB |
8 | * |
9 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
10 | * of this software and associated documentation files (the "Software"), to deal | |
11 | * in the Software without restriction, including without limitation the rights | |
12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
13 | * copies of the Software, and to permit persons to whom the Software is | |
14 | * furnished to do so, subject to the following conditions: | |
15 | * | |
16 | * The above copyright notice and this permission notice shall be included in | |
17 | * all copies or substantial portions of the Software. | |
18 | * | |
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
25 | * SOFTWARE. | |
26 | */ | |
27 | ||
28 | #include <assert.h> | |
29 | #include <glib.h> | |
30 | #include <babeltrace/types.h> | |
31 | #include <babeltrace/ctf-ir/metadata.h> | |
32 | #include <babeltrace/debuginfo.h> | |
33 | #include <babeltrace/so-info.h> | |
458af89d | 34 | #include <babeltrace/babeltrace-internal.h> |
beef86dc | 35 | #include <babeltrace/utils.h> |
b5a8598f AB |
36 | |
37 | struct proc_debug_info_sources { | |
38 | /* | |
71235b6d | 39 | * Hash table: base address (pointer to uint64_t) to so info; owned by |
b5a8598f AB |
40 | * proc_debug_info_sources. |
41 | */ | |
42 | GHashTable *baddr_to_so_info; | |
43 | ||
44 | /* | |
71235b6d JG |
45 | * Hash table: IP (pointer to uint64_t) to (struct debug_info_source *); |
46 | * owned by proc_debug_info_sources. | |
b5a8598f AB |
47 | */ |
48 | GHashTable *ip_to_debug_info_src; | |
49 | }; | |
50 | ||
51 | struct debug_info { | |
52 | /* | |
71235b6d JG |
53 | * Hash table of VPIDs (pointer to int64_t) to |
54 | * (struct ctf_proc_debug_infos*); owned by debug_info. | |
b5a8598f AB |
55 | */ |
56 | GHashTable *vpid_to_proc_dbg_info_src; | |
57 | GQuark q_statedump_soinfo; | |
58 | GQuark q_statedump_debug_link; | |
59 | GQuark q_statedump_build_id; | |
60 | GQuark q_statedump_start; | |
61 | GQuark q_dl_open; | |
62 | }; | |
63 | ||
64 | static | |
65 | int debug_info_init(struct debug_info *info) | |
66 | { | |
67 | info->q_statedump_soinfo = g_quark_from_string( | |
68 | "lttng_ust_statedump:soinfo"); | |
69 | info->q_statedump_debug_link = g_quark_from_string( | |
70 | "lttng_ust_statedump:debug_link)"); | |
71 | info->q_statedump_build_id = g_quark_from_string( | |
72 | "lttng_ust_statedump:build_id"); | |
73 | info->q_statedump_start = g_quark_from_string( | |
74 | "lttng_ust_statedump:start"); | |
75 | info->q_dl_open = g_quark_from_string("lttng_ust_dl:dlopen"); | |
76 | ||
77 | return so_info_init(); | |
78 | } | |
79 | ||
80 | static | |
81 | void debug_info_source_destroy(struct debug_info_source *debug_info_src) | |
82 | { | |
83 | if (!debug_info_src) { | |
84 | return; | |
85 | } | |
86 | ||
87 | free(debug_info_src->func); | |
ad2b5b38 JG |
88 | free(debug_info_src->src_path); |
89 | free(debug_info_src->bin_path); | |
b5a8598f AB |
90 | g_free(debug_info_src); |
91 | } | |
92 | ||
93 | static | |
94 | struct debug_info_source *debug_info_source_create_from_so(struct so_info *so, | |
95 | uint64_t ip) | |
96 | { | |
97 | int ret; | |
98 | struct debug_info_source *debug_info_src = NULL; | |
99 | struct source_location *src_loc = NULL; | |
100 | ||
101 | debug_info_src = g_new0(struct debug_info_source, 1); | |
102 | ||
103 | if (!debug_info_src) { | |
104 | goto end; | |
105 | } | |
106 | ||
107 | /* Lookup function name */ | |
108 | ret = so_info_lookup_function_name(so, ip, &debug_info_src->func); | |
109 | if (ret) { | |
110 | goto error; | |
111 | } | |
112 | ||
113 | /* Can't retrieve src_loc from ELF only, skip it */ | |
306dbb33 JG |
114 | if (!so->is_elf_only) { |
115 | /* Lookup source location */ | |
116 | ret = so_info_lookup_source_location(so, ip, &src_loc); | |
117 | if (ret) { | |
118 | goto error; | |
119 | } | |
b5a8598f AB |
120 | } |
121 | ||
122 | if (src_loc) { | |
123 | debug_info_src->line_no = src_loc->line_no; | |
124 | ||
125 | if (src_loc->filename) { | |
ad2b5b38 JG |
126 | debug_info_src->src_path = strdup(src_loc->filename); |
127 | if (!debug_info_src->src_path) { | |
b5a8598f AB |
128 | goto error; |
129 | } | |
458af89d | 130 | |
ad2b5b38 | 131 | debug_info_src->short_src_path = get_filename_from_path( |
ed02dbd5 | 132 | debug_info_src->src_path); |
b5a8598f AB |
133 | } |
134 | ||
135 | source_location_destroy(src_loc); | |
136 | } | |
137 | ||
ad2b5b38 JG |
138 | if (so->elf_path) { |
139 | debug_info_src->bin_path = strdup(so->elf_path); | |
140 | if (!debug_info_src->bin_path) { | |
141 | goto error; | |
142 | } | |
143 | ||
144 | debug_info_src->short_bin_path = get_filename_from_path( | |
145 | debug_info_src->bin_path); | |
146 | } | |
147 | ||
b5a8598f AB |
148 | end: |
149 | return debug_info_src; | |
150 | ||
151 | error: | |
152 | debug_info_source_destroy(debug_info_src); | |
153 | return NULL; | |
154 | } | |
155 | ||
156 | static | |
157 | void proc_debug_info_sources_destroy( | |
158 | struct proc_debug_info_sources *proc_dbg_info_src) | |
159 | { | |
160 | if (!proc_dbg_info_src) { | |
161 | return; | |
162 | } | |
163 | ||
164 | if (proc_dbg_info_src->baddr_to_so_info) { | |
165 | g_hash_table_destroy(proc_dbg_info_src->baddr_to_so_info); | |
166 | } | |
167 | ||
168 | if (proc_dbg_info_src->ip_to_debug_info_src) { | |
169 | g_hash_table_destroy(proc_dbg_info_src->ip_to_debug_info_src); | |
170 | } | |
171 | ||
172 | g_free(proc_dbg_info_src); | |
173 | } | |
174 | ||
175 | static | |
176 | struct proc_debug_info_sources *proc_debug_info_sources_create(void) | |
177 | { | |
178 | struct proc_debug_info_sources *proc_dbg_info_src = NULL; | |
179 | ||
180 | proc_dbg_info_src = g_new0(struct proc_debug_info_sources, 1); | |
181 | if (!proc_dbg_info_src) { | |
182 | goto end; | |
183 | } | |
184 | ||
185 | proc_dbg_info_src->baddr_to_so_info = g_hash_table_new_full( | |
71235b6d JG |
186 | g_int64_hash, g_int64_equal, (GDestroyNotify) g_free, |
187 | (GDestroyNotify) so_info_destroy); | |
b5a8598f AB |
188 | if (!proc_dbg_info_src->baddr_to_so_info) { |
189 | goto error; | |
190 | } | |
191 | ||
192 | proc_dbg_info_src->ip_to_debug_info_src = g_hash_table_new_full( | |
71235b6d | 193 | g_int64_hash, g_int64_equal, (GDestroyNotify) g_free, |
b5a8598f AB |
194 | (GDestroyNotify) debug_info_source_destroy); |
195 | if (!proc_dbg_info_src->ip_to_debug_info_src) { | |
196 | goto error; | |
197 | } | |
198 | ||
199 | end: | |
200 | return proc_dbg_info_src; | |
201 | ||
202 | error: | |
203 | proc_debug_info_sources_destroy(proc_dbg_info_src); | |
204 | return NULL; | |
205 | } | |
206 | ||
207 | static | |
208 | struct proc_debug_info_sources *proc_debug_info_sources_ht_get_entry( | |
209 | GHashTable *ht, int64_t vpid) | |
210 | { | |
71235b6d | 211 | gpointer key = g_new0(int64_t, 1); |
b5a8598f AB |
212 | struct proc_debug_info_sources *proc_dbg_info_src = NULL; |
213 | ||
71235b6d JG |
214 | if (!key) { |
215 | goto end; | |
216 | } | |
217 | ||
218 | *((int64_t *) key) = vpid; | |
219 | ||
b5a8598f AB |
220 | /* Exists? Return it */ |
221 | proc_dbg_info_src = g_hash_table_lookup(ht, key); | |
222 | if (proc_dbg_info_src) { | |
223 | goto end; | |
224 | } | |
225 | ||
226 | /* Otherwise, create and return it */ | |
227 | proc_dbg_info_src = proc_debug_info_sources_create(); | |
228 | if (!proc_dbg_info_src) { | |
229 | goto end; | |
230 | } | |
231 | ||
232 | g_hash_table_insert(ht, key, proc_dbg_info_src); | |
71235b6d JG |
233 | /* Ownership passed to ht */ |
234 | key = NULL; | |
b5a8598f | 235 | end: |
71235b6d | 236 | g_free(key); |
b5a8598f AB |
237 | return proc_dbg_info_src; |
238 | } | |
239 | ||
240 | static | |
241 | struct debug_info_source *proc_debug_info_sources_get_entry( | |
242 | struct proc_debug_info_sources *proc_dbg_info_src, uint64_t ip) | |
243 | { | |
244 | struct debug_info_source *debug_info_src = NULL; | |
71235b6d | 245 | gpointer key = g_new0(uint64_t, 1); |
b5a8598f AB |
246 | GHashTableIter iter; |
247 | gpointer baddr, value; | |
248 | ||
71235b6d JG |
249 | if (!key) { |
250 | goto end; | |
251 | } | |
252 | ||
253 | *((uint64_t *) key) = ip; | |
254 | ||
b5a8598f AB |
255 | /* Look in IP to debug infos hash table first. */ |
256 | debug_info_src = g_hash_table_lookup( | |
257 | proc_dbg_info_src->ip_to_debug_info_src, | |
71235b6d | 258 | key); |
b5a8598f AB |
259 | if (debug_info_src) { |
260 | goto end; | |
261 | } | |
262 | ||
263 | /* Check in all so_infos. */ | |
264 | g_hash_table_iter_init(&iter, proc_dbg_info_src->baddr_to_so_info); | |
265 | ||
266 | while (g_hash_table_iter_next(&iter, &baddr, &value)) | |
267 | { | |
268 | struct so_info *so = value; | |
269 | ||
270 | if (!so_info_has_address(value, ip)) { | |
271 | continue; | |
272 | } | |
273 | ||
71235b6d JG |
274 | /* |
275 | * Found; add it to cache. | |
276 | * | |
277 | * FIXME: this should be bounded in size (and implement | |
278 | * a caching policy), and entries should be prunned when | |
279 | * libraries are unmapped. | |
280 | */ | |
b5a8598f AB |
281 | debug_info_src = debug_info_source_create_from_so(so, ip); |
282 | if (debug_info_src) { | |
283 | g_hash_table_insert( | |
284 | proc_dbg_info_src->ip_to_debug_info_src, | |
71235b6d JG |
285 | key, debug_info_src); |
286 | /* Ownership passed to ht. */ | |
287 | key = NULL; | |
b5a8598f AB |
288 | } |
289 | break; | |
290 | } | |
291 | ||
292 | end: | |
71235b6d | 293 | free(key); |
b5a8598f AB |
294 | return debug_info_src; |
295 | } | |
296 | ||
297 | BT_HIDDEN | |
298 | struct debug_info_source *debug_info_query(struct debug_info *debug_info, | |
299 | int64_t vpid, uint64_t ip) | |
300 | { | |
301 | struct debug_info_source *dbg_info_src = NULL; | |
302 | struct proc_debug_info_sources *proc_dbg_info_src; | |
303 | ||
304 | proc_dbg_info_src = proc_debug_info_sources_ht_get_entry( | |
305 | debug_info->vpid_to_proc_dbg_info_src, vpid); | |
306 | if (!proc_dbg_info_src) { | |
307 | goto end; | |
308 | } | |
309 | ||
310 | dbg_info_src = proc_debug_info_sources_get_entry( | |
311 | proc_dbg_info_src, ip); | |
312 | if (!dbg_info_src) { | |
313 | goto end; | |
314 | } | |
315 | ||
316 | end: | |
317 | return dbg_info_src; | |
318 | } | |
319 | ||
320 | BT_HIDDEN | |
321 | struct debug_info *debug_info_create(void) | |
322 | { | |
323 | int ret; | |
324 | struct debug_info *debug_info; | |
325 | ||
326 | debug_info = g_new0(struct debug_info, 1); | |
327 | if (!debug_info) { | |
328 | goto end; | |
329 | } | |
330 | ||
71235b6d JG |
331 | debug_info->vpid_to_proc_dbg_info_src = g_hash_table_new_full( |
332 | g_int64_hash, g_int64_equal, (GDestroyNotify) g_free, | |
b5a8598f AB |
333 | (GDestroyNotify) proc_debug_info_sources_destroy); |
334 | if (!debug_info->vpid_to_proc_dbg_info_src) { | |
335 | goto error; | |
336 | } | |
337 | ||
338 | ret = debug_info_init(debug_info); | |
339 | if (ret) { | |
340 | goto error; | |
341 | } | |
342 | ||
343 | end: | |
344 | return debug_info; | |
345 | error: | |
346 | g_free(debug_info); | |
347 | return NULL; | |
348 | } | |
349 | ||
350 | BT_HIDDEN | |
351 | void debug_info_destroy(struct debug_info *debug_info) | |
352 | { | |
353 | if (!debug_info) { | |
354 | goto end; | |
355 | } | |
356 | ||
357 | if (debug_info->vpid_to_proc_dbg_info_src) { | |
358 | g_hash_table_destroy(debug_info->vpid_to_proc_dbg_info_src); | |
359 | } | |
360 | ||
361 | g_free(debug_info); | |
362 | end: | |
363 | return; | |
364 | } | |
365 | ||
366 | static | |
367 | void handle_statedump_build_id_event(struct debug_info *debug_info, | |
368 | struct ctf_event_definition *event_def) | |
369 | { | |
370 | struct proc_debug_info_sources *proc_dbg_info_src; | |
371 | struct bt_definition *event_fields_def = NULL; | |
372 | struct bt_definition *sec_def = NULL; | |
373 | struct bt_definition *baddr_def = NULL; | |
374 | struct bt_definition *vpid_def = NULL; | |
375 | struct bt_definition *build_id_def = NULL; | |
376 | struct definition_sequence *build_id_seq; | |
377 | struct so_info *so = NULL; | |
378 | int i; | |
379 | int64_t vpid; | |
380 | uint64_t baddr; | |
381 | uint8_t *build_id = NULL; | |
382 | uint64_t build_id_len; | |
383 | ||
384 | event_fields_def = (struct bt_definition *) event_def->event_fields; | |
385 | sec_def = (struct bt_definition *) | |
386 | event_def->stream->stream_event_context; | |
387 | ||
388 | if (!event_fields_def || !sec_def) { | |
389 | goto end; | |
390 | } | |
391 | ||
392 | baddr_def = bt_lookup_definition(event_fields_def, "_baddr"); | |
393 | if (!baddr_def) { | |
394 | goto end; | |
395 | } | |
396 | ||
397 | vpid_def = bt_lookup_definition(sec_def, "_vpid"); | |
398 | if (!vpid_def) { | |
399 | goto end; | |
400 | } | |
401 | ||
402 | build_id_def = bt_lookup_definition(event_fields_def, "_build_id"); | |
403 | if (!build_id_def) { | |
404 | goto end; | |
405 | } | |
406 | ||
407 | if (baddr_def->declaration->id != CTF_TYPE_INTEGER) { | |
408 | goto end; | |
409 | } | |
410 | ||
411 | if (vpid_def->declaration->id != CTF_TYPE_INTEGER) { | |
412 | goto end; | |
413 | } | |
414 | ||
415 | if (build_id_def->declaration->id != CTF_TYPE_SEQUENCE) { | |
416 | goto end; | |
417 | } | |
418 | ||
419 | baddr = bt_get_unsigned_int(baddr_def); | |
420 | vpid = bt_get_signed_int(vpid_def); | |
421 | build_id_seq = container_of(build_id_def, | |
422 | struct definition_sequence, p); | |
423 | build_id_len = build_id_seq->length->value._unsigned; | |
424 | ||
425 | build_id = g_malloc(build_id_len); | |
426 | if (!build_id) { | |
427 | goto end; | |
428 | } | |
429 | ||
430 | for (i = 0; i < build_id_len; ++i) { | |
431 | struct bt_definition **field; | |
432 | ||
433 | field = (struct bt_definition **) &g_ptr_array_index( | |
434 | build_id_seq->elems, i); | |
435 | build_id[i] = bt_get_unsigned_int(*field); | |
436 | } | |
437 | ||
438 | proc_dbg_info_src = proc_debug_info_sources_ht_get_entry( | |
439 | debug_info->vpid_to_proc_dbg_info_src, vpid); | |
440 | if (!proc_dbg_info_src) { | |
441 | goto end; | |
442 | } | |
443 | ||
444 | so = g_hash_table_lookup(proc_dbg_info_src->baddr_to_so_info, | |
445 | (gpointer) &baddr); | |
446 | if (!so) { | |
447 | /* | |
448 | * The build_id event comes after the so has been | |
449 | * created. If it isn't found, just ignore this event. | |
450 | */ | |
451 | goto end; | |
452 | } | |
453 | ||
454 | so_info_set_build_id(so, build_id, build_id_len); | |
455 | ||
456 | end: | |
457 | free(build_id); | |
458 | return; | |
459 | } | |
460 | ||
461 | static | |
462 | void handle_statedump_debug_link_event(struct debug_info *debug_info, | |
463 | struct ctf_event_definition *event_def) | |
464 | { | |
465 | struct proc_debug_info_sources *proc_dbg_info_src; | |
466 | struct bt_definition *event_fields_def = NULL; | |
467 | struct bt_definition *sec_def = NULL; | |
468 | struct bt_definition *baddr_def = NULL; | |
469 | struct bt_definition *vpid_def = NULL; | |
470 | struct bt_definition *filename_def = NULL; | |
471 | struct bt_definition *crc32_def = NULL; | |
472 | struct so_info *so = NULL; | |
473 | int64_t vpid; | |
474 | uint64_t baddr; | |
475 | char *filename = NULL; | |
476 | uint32_t crc32; | |
477 | ||
478 | event_fields_def = (struct bt_definition *) event_def->event_fields; | |
479 | sec_def = (struct bt_definition *) | |
480 | event_def->stream->stream_event_context; | |
481 | ||
482 | if (!event_fields_def || !sec_def) { | |
483 | goto end; | |
484 | } | |
485 | ||
486 | baddr_def = bt_lookup_definition(event_fields_def, "_baddr"); | |
487 | if (!baddr_def) { | |
488 | goto end; | |
489 | } | |
490 | ||
491 | vpid_def = bt_lookup_definition(sec_def, "_vpid"); | |
492 | if (!vpid_def) { | |
493 | goto end; | |
494 | } | |
495 | ||
496 | filename_def = bt_lookup_definition(event_fields_def, "_filename"); | |
497 | if (!filename_def) { | |
498 | goto end; | |
499 | } | |
500 | ||
501 | crc32_def = bt_lookup_definition(event_fields_def, "_crc32"); | |
502 | if (!crc32_def) { | |
503 | goto end; | |
504 | } | |
505 | ||
506 | if (baddr_def->declaration->id != CTF_TYPE_INTEGER) { | |
507 | goto end; | |
508 | } | |
509 | ||
510 | if (vpid_def->declaration->id != CTF_TYPE_INTEGER) { | |
511 | goto end; | |
512 | } | |
513 | ||
514 | if (filename_def->declaration->id != CTF_TYPE_STRING) { | |
515 | goto end; | |
516 | } | |
517 | ||
518 | if (crc32_def->declaration->id != CTF_TYPE_INTEGER) { | |
519 | goto end; | |
520 | } | |
521 | ||
522 | baddr = bt_get_unsigned_int(baddr_def); | |
523 | vpid = bt_get_signed_int(vpid_def); | |
524 | ||
525 | proc_dbg_info_src = proc_debug_info_sources_ht_get_entry( | |
526 | debug_info->vpid_to_proc_dbg_info_src, vpid); | |
527 | if (!proc_dbg_info_src) { | |
528 | goto end; | |
529 | } | |
530 | ||
531 | so = g_hash_table_lookup(proc_dbg_info_src->baddr_to_so_info, | |
532 | (gpointer) &baddr); | |
533 | if (!so) { | |
534 | /* | |
535 | * The debug_link event comes after the so has been | |
536 | * created. If it isn't found, just ignore this event. | |
537 | */ | |
538 | goto end; | |
539 | } | |
540 | ||
541 | filename = bt_get_string(filename_def); | |
542 | crc32 = bt_get_unsigned_int(crc32_def); | |
543 | ||
544 | so_info_set_debug_link(so, filename, crc32); | |
545 | ||
546 | end: | |
547 | return; | |
548 | } | |
549 | ||
550 | static | |
551 | void handle_statedump_soinfo_event(struct debug_info *debug_info, | |
552 | struct ctf_event_definition *event_def) | |
553 | { | |
554 | struct bt_definition *baddr_def = NULL; | |
555 | struct bt_definition *memsz_def = NULL; | |
556 | struct bt_definition *sopath_def = NULL; | |
557 | struct bt_definition *vpid_def = NULL; | |
558 | struct bt_definition *event_fields_def = NULL; | |
559 | struct bt_definition *sec_def = NULL; | |
560 | struct proc_debug_info_sources *proc_dbg_info_src; | |
561 | struct so_info *so; | |
562 | uint64_t baddr, memsz; | |
563 | int64_t vpid; | |
564 | const char *sopath; | |
71235b6d | 565 | gpointer key = NULL; |
b5a8598f AB |
566 | |
567 | event_fields_def = (struct bt_definition *) event_def->event_fields; | |
568 | sec_def = (struct bt_definition *) | |
569 | event_def->stream->stream_event_context; | |
570 | ||
571 | if (!event_fields_def || !sec_def) { | |
572 | goto end; | |
573 | } | |
574 | ||
575 | baddr_def = bt_lookup_definition(event_fields_def, "_baddr"); | |
576 | if (!baddr_def) { | |
577 | goto end; | |
578 | } | |
579 | ||
580 | memsz_def = bt_lookup_definition(event_fields_def, "_memsz"); | |
581 | if (!memsz_def) { | |
582 | goto end; | |
583 | } | |
584 | ||
585 | sopath_def = bt_lookup_definition(event_fields_def, "_sopath"); | |
586 | if (!sopath_def) { | |
587 | goto end; | |
588 | } | |
589 | ||
590 | vpid_def = bt_lookup_definition(sec_def, "_vpid"); | |
591 | if (!vpid_def) { | |
592 | goto end; | |
593 | } | |
594 | ||
595 | if (baddr_def->declaration->id != CTF_TYPE_INTEGER) { | |
596 | goto end; | |
597 | } | |
598 | ||
599 | if (memsz_def->declaration->id != CTF_TYPE_INTEGER) { | |
600 | goto end; | |
601 | } | |
602 | ||
603 | if (sopath_def->declaration->id != CTF_TYPE_STRING) { | |
604 | goto end; | |
605 | } | |
606 | ||
607 | if (vpid_def->declaration->id != CTF_TYPE_INTEGER) { | |
608 | goto end; | |
609 | } | |
610 | ||
611 | baddr = bt_get_unsigned_int(baddr_def); | |
612 | memsz = bt_get_unsigned_int(memsz_def); | |
613 | sopath = bt_get_string(sopath_def); | |
614 | vpid = bt_get_signed_int(vpid_def); | |
615 | ||
616 | if (!sopath) { | |
617 | goto end; | |
618 | } | |
619 | ||
620 | if (memsz == 0) { | |
621 | /* Ignore VDSO. */ | |
622 | goto end; | |
623 | } | |
624 | ||
625 | proc_dbg_info_src = proc_debug_info_sources_ht_get_entry( | |
626 | debug_info->vpid_to_proc_dbg_info_src, vpid); | |
627 | if (!proc_dbg_info_src) { | |
628 | goto end; | |
629 | } | |
630 | ||
71235b6d JG |
631 | key = g_new0(uint64_t, 1); |
632 | if (!key) { | |
633 | goto end; | |
634 | } | |
635 | ||
636 | *((uint64_t *) key) = baddr; | |
637 | ||
b5a8598f | 638 | so = g_hash_table_lookup(proc_dbg_info_src->baddr_to_so_info, |
71235b6d | 639 | key); |
b5a8598f AB |
640 | if (so) { |
641 | goto end; | |
642 | } | |
643 | ||
644 | so = so_info_create(sopath, baddr, memsz); | |
645 | if (!so) { | |
646 | goto end; | |
647 | } | |
648 | ||
649 | g_hash_table_insert(proc_dbg_info_src->baddr_to_so_info, | |
71235b6d JG |
650 | key, so); |
651 | /* Ownership passed to ht. */ | |
652 | key = NULL; | |
b5a8598f AB |
653 | |
654 | end: | |
71235b6d | 655 | g_free(key); |
b5a8598f AB |
656 | return; |
657 | } | |
658 | ||
659 | static | |
660 | void handle_statedump_start(struct debug_info *debug_info, | |
661 | struct ctf_event_definition *event_def) | |
662 | { | |
663 | struct bt_definition *vpid_def = NULL; | |
664 | struct bt_definition *sec_def = NULL; | |
665 | struct proc_debug_info_sources *proc_dbg_info_src; | |
666 | int64_t vpid; | |
667 | ||
668 | sec_def = (struct bt_definition *) | |
669 | event_def->stream->stream_event_context; | |
670 | if (!sec_def) { | |
671 | goto end; | |
672 | } | |
673 | ||
674 | vpid_def = bt_lookup_definition(sec_def, "_vpid"); | |
675 | if (!vpid_def) { | |
676 | goto end; | |
677 | } | |
678 | ||
679 | vpid = bt_get_signed_int(vpid_def); | |
680 | ||
681 | proc_dbg_info_src = proc_debug_info_sources_ht_get_entry( | |
682 | debug_info->vpid_to_proc_dbg_info_src, vpid); | |
683 | if (!proc_dbg_info_src) { | |
684 | goto end; | |
685 | } | |
686 | ||
687 | g_hash_table_remove_all(proc_dbg_info_src->baddr_to_so_info); | |
688 | g_hash_table_remove_all(proc_dbg_info_src->ip_to_debug_info_src); | |
689 | ||
690 | end: | |
691 | return; | |
692 | } | |
693 | ||
694 | static | |
695 | void register_event_debug_infos(struct debug_info *debug_info, | |
696 | struct ctf_event_definition *event) | |
697 | { | |
698 | struct bt_definition *ip_def, *vpid_def; | |
699 | int64_t vpid; | |
700 | uint64_t ip; | |
701 | struct bt_definition *sec_def; | |
702 | ||
703 | /* Get stream event context definition. */ | |
704 | sec_def = (struct bt_definition *) event->stream->stream_event_context; | |
705 | if (!sec_def) { | |
706 | goto end; | |
707 | } | |
708 | ||
709 | /* Get "ip" and "vpid" definitions. */ | |
710 | vpid_def = bt_lookup_definition((struct bt_definition *) sec_def, | |
711 | "_vpid"); | |
712 | ip_def = bt_lookup_definition((struct bt_definition *) sec_def, "_ip"); | |
713 | ||
714 | if (!vpid_def || !ip_def) { | |
715 | goto end; | |
716 | } | |
717 | ||
718 | vpid = bt_get_signed_int(vpid_def); | |
719 | ip = bt_get_unsigned_int(ip_def); | |
720 | ||
721 | /* Get debug info for this context. */ | |
722 | ((struct definition_integer *) ip_def)->debug_info_src = | |
723 | debug_info_query(debug_info, vpid, ip); | |
724 | ||
725 | end: | |
726 | return; | |
727 | } | |
728 | ||
729 | BT_HIDDEN | |
730 | void debug_info_handle_event(struct debug_info *debug_info, | |
731 | struct ctf_event_definition *event) | |
732 | { | |
733 | struct ctf_event_declaration *event_class; | |
734 | struct ctf_stream_declaration *stream_class; | |
735 | ||
736 | if (!debug_info || !event) { | |
737 | goto end; | |
738 | } | |
739 | ||
740 | stream_class = event->stream->stream_class; | |
741 | event_class = g_ptr_array_index(stream_class->events_by_id, | |
742 | event->stream->event_id); | |
743 | ||
744 | if (event_class->name == debug_info->q_statedump_soinfo || | |
745 | event_class->name == debug_info->q_dl_open) { | |
746 | /* State dump/dlopen() */ | |
747 | handle_statedump_soinfo_event(debug_info, event); | |
748 | } else if (event_class->name == debug_info->q_statedump_start) { | |
749 | /* Start state dump */ | |
750 | handle_statedump_start(debug_info, event); | |
751 | } else if (event_class->name == debug_info->q_statedump_debug_link) { | |
752 | /* Debug link info */ | |
753 | handle_statedump_debug_link_event(debug_info, event); | |
754 | } else if (event_class->name == debug_info->q_statedump_build_id) { | |
755 | /* Build ID info */ | |
756 | handle_statedump_build_id_event(debug_info, event); | |
757 | } else { | |
758 | /* Other events: register debug infos */ | |
759 | register_event_debug_infos(debug_info, event); | |
760 | } | |
761 | ||
762 | end: | |
763 | return; | |
764 | } |