Fix: Use list rather than ptr array for trace streams
[babeltrace.git] / lib / debug-info.c
CommitLineData
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>
eb75a494 32#include <babeltrace/debug-info.h>
dae52e76 33#include <babeltrace/bin-info.h>
458af89d 34#include <babeltrace/babeltrace-internal.h>
beef86dc 35#include <babeltrace/utils.h>
b5a8598f
AB
36
37struct proc_debug_info_sources {
38 /*
dae52e76 39 * Hash table: base address (pointer to uint64_t) to bin info; owned by
b5a8598f
AB
40 * proc_debug_info_sources.
41 */
dae52e76 42 GHashTable *baddr_to_bin_info;
b5a8598f
AB
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
51struct 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;
685bd918 57 GQuark q_statedump_bin_info;
b5a8598f
AB
58 GQuark q_statedump_debug_link;
59 GQuark q_statedump_build_id;
60 GQuark q_statedump_start;
61 GQuark q_dl_open;
62};
63
64static
65int debug_info_init(struct debug_info *info)
66{
685bd918
AB
67 info->q_statedump_bin_info = g_quark_from_string(
68 "lttng_ust_statedump:bin_info");
b5a8598f
AB
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
dae52e76 77 return bin_info_init();
b5a8598f
AB
78}
79
80static
81void 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);
dc419b6c 90 free(debug_info_src->bin_loc);
b5a8598f
AB
91 g_free(debug_info_src);
92}
93
94static
dae52e76 95struct debug_info_source *debug_info_source_create_from_bin(struct bin_info *bin,
b5a8598f
AB
96 uint64_t ip)
97{
98 int ret;
99 struct debug_info_source *debug_info_src = NULL;
100 struct source_location *src_loc = NULL;
101
102 debug_info_src = g_new0(struct debug_info_source, 1);
103
104 if (!debug_info_src) {
105 goto end;
106 }
107
108 /* Lookup function name */
dae52e76 109 ret = bin_info_lookup_function_name(bin, ip, &debug_info_src->func);
b5a8598f
AB
110 if (ret) {
111 goto error;
112 }
113
6a2908b2
JG
114 /* Can't retrieve src_loc from ELF, or could not find binary, skip. */
115 if (!bin->is_elf_only || !debug_info_src->func) {
306dbb33 116 /* Lookup source location */
dae52e76 117 ret = bin_info_lookup_source_location(bin, ip, &src_loc);
6a2908b2 118 printf_verbose("Failed to lookup source location (err: %i)\n", ret);
b5a8598f
AB
119 }
120
121 if (src_loc) {
122 debug_info_src->line_no = src_loc->line_no;
123
124 if (src_loc->filename) {
ad2b5b38
JG
125 debug_info_src->src_path = strdup(src_loc->filename);
126 if (!debug_info_src->src_path) {
b5a8598f
AB
127 goto error;
128 }
458af89d 129
ad2b5b38 130 debug_info_src->short_src_path = get_filename_from_path(
ed02dbd5 131 debug_info_src->src_path);
b5a8598f
AB
132 }
133
134 source_location_destroy(src_loc);
135 }
136
dae52e76
AB
137 if (bin->elf_path) {
138 debug_info_src->bin_path = strdup(bin->elf_path);
ad2b5b38
JG
139 if (!debug_info_src->bin_path) {
140 goto error;
141 }
142
143 debug_info_src->short_bin_path = get_filename_from_path(
144 debug_info_src->bin_path);
dc419b6c 145
dae52e76 146 ret = bin_info_get_bin_loc(bin, ip, &(debug_info_src->bin_loc));
dc419b6c
AB
147 if (ret) {
148 goto error;
149 }
ad2b5b38
JG
150 }
151
b5a8598f
AB
152end:
153 return debug_info_src;
154
155error:
156 debug_info_source_destroy(debug_info_src);
157 return NULL;
158}
159
160static
161void proc_debug_info_sources_destroy(
162 struct proc_debug_info_sources *proc_dbg_info_src)
163{
164 if (!proc_dbg_info_src) {
165 return;
166 }
167
dae52e76
AB
168 if (proc_dbg_info_src->baddr_to_bin_info) {
169 g_hash_table_destroy(proc_dbg_info_src->baddr_to_bin_info);
b5a8598f
AB
170 }
171
172 if (proc_dbg_info_src->ip_to_debug_info_src) {
173 g_hash_table_destroy(proc_dbg_info_src->ip_to_debug_info_src);
174 }
175
176 g_free(proc_dbg_info_src);
177}
178
179static
180struct proc_debug_info_sources *proc_debug_info_sources_create(void)
181{
182 struct proc_debug_info_sources *proc_dbg_info_src = NULL;
183
184 proc_dbg_info_src = g_new0(struct proc_debug_info_sources, 1);
185 if (!proc_dbg_info_src) {
186 goto end;
187 }
188
dae52e76 189 proc_dbg_info_src->baddr_to_bin_info = g_hash_table_new_full(
71235b6d 190 g_int64_hash, g_int64_equal, (GDestroyNotify) g_free,
dae52e76
AB
191 (GDestroyNotify) bin_info_destroy);
192 if (!proc_dbg_info_src->baddr_to_bin_info) {
b5a8598f
AB
193 goto error;
194 }
195
196 proc_dbg_info_src->ip_to_debug_info_src = g_hash_table_new_full(
71235b6d 197 g_int64_hash, g_int64_equal, (GDestroyNotify) g_free,
b5a8598f
AB
198 (GDestroyNotify) debug_info_source_destroy);
199 if (!proc_dbg_info_src->ip_to_debug_info_src) {
200 goto error;
201 }
202
203end:
204 return proc_dbg_info_src;
205
206error:
207 proc_debug_info_sources_destroy(proc_dbg_info_src);
208 return NULL;
209}
210
211static
212struct proc_debug_info_sources *proc_debug_info_sources_ht_get_entry(
213 GHashTable *ht, int64_t vpid)
214{
71235b6d 215 gpointer key = g_new0(int64_t, 1);
b5a8598f
AB
216 struct proc_debug_info_sources *proc_dbg_info_src = NULL;
217
71235b6d
JG
218 if (!key) {
219 goto end;
220 }
221
222 *((int64_t *) key) = vpid;
223
b5a8598f
AB
224 /* Exists? Return it */
225 proc_dbg_info_src = g_hash_table_lookup(ht, key);
226 if (proc_dbg_info_src) {
227 goto end;
228 }
229
230 /* Otherwise, create and return it */
231 proc_dbg_info_src = proc_debug_info_sources_create();
232 if (!proc_dbg_info_src) {
233 goto end;
234 }
235
236 g_hash_table_insert(ht, key, proc_dbg_info_src);
71235b6d
JG
237 /* Ownership passed to ht */
238 key = NULL;
b5a8598f 239end:
71235b6d 240 g_free(key);
b5a8598f
AB
241 return proc_dbg_info_src;
242}
243
244static
245struct debug_info_source *proc_debug_info_sources_get_entry(
246 struct proc_debug_info_sources *proc_dbg_info_src, uint64_t ip)
247{
248 struct debug_info_source *debug_info_src = NULL;
71235b6d 249 gpointer key = g_new0(uint64_t, 1);
b5a8598f
AB
250 GHashTableIter iter;
251 gpointer baddr, value;
252
71235b6d
JG
253 if (!key) {
254 goto end;
255 }
256
257 *((uint64_t *) key) = ip;
258
b5a8598f
AB
259 /* Look in IP to debug infos hash table first. */
260 debug_info_src = g_hash_table_lookup(
261 proc_dbg_info_src->ip_to_debug_info_src,
71235b6d 262 key);
b5a8598f
AB
263 if (debug_info_src) {
264 goto end;
265 }
266
dae52e76
AB
267 /* Check in all bin_infos. */
268 g_hash_table_iter_init(&iter, proc_dbg_info_src->baddr_to_bin_info);
b5a8598f
AB
269
270 while (g_hash_table_iter_next(&iter, &baddr, &value))
271 {
dae52e76 272 struct bin_info *bin = value;
b5a8598f 273
dae52e76 274 if (!bin_info_has_address(value, ip)) {
b5a8598f
AB
275 continue;
276 }
277
71235b6d
JG
278 /*
279 * Found; add it to cache.
280 *
281 * FIXME: this should be bounded in size (and implement
282 * a caching policy), and entries should be prunned when
283 * libraries are unmapped.
284 */
dae52e76 285 debug_info_src = debug_info_source_create_from_bin(bin, ip);
b5a8598f
AB
286 if (debug_info_src) {
287 g_hash_table_insert(
288 proc_dbg_info_src->ip_to_debug_info_src,
71235b6d
JG
289 key, debug_info_src);
290 /* Ownership passed to ht. */
291 key = NULL;
b5a8598f
AB
292 }
293 break;
294 }
295
296end:
71235b6d 297 free(key);
b5a8598f
AB
298 return debug_info_src;
299}
300
301BT_HIDDEN
302struct debug_info_source *debug_info_query(struct debug_info *debug_info,
303 int64_t vpid, uint64_t ip)
304{
305 struct debug_info_source *dbg_info_src = NULL;
306 struct proc_debug_info_sources *proc_dbg_info_src;
307
308 proc_dbg_info_src = proc_debug_info_sources_ht_get_entry(
309 debug_info->vpid_to_proc_dbg_info_src, vpid);
310 if (!proc_dbg_info_src) {
311 goto end;
312 }
313
314 dbg_info_src = proc_debug_info_sources_get_entry(
315 proc_dbg_info_src, ip);
316 if (!dbg_info_src) {
317 goto end;
318 }
319
320end:
321 return dbg_info_src;
322}
323
324BT_HIDDEN
325struct debug_info *debug_info_create(void)
326{
327 int ret;
328 struct debug_info *debug_info;
329
330 debug_info = g_new0(struct debug_info, 1);
331 if (!debug_info) {
332 goto end;
333 }
334
71235b6d
JG
335 debug_info->vpid_to_proc_dbg_info_src = g_hash_table_new_full(
336 g_int64_hash, g_int64_equal, (GDestroyNotify) g_free,
b5a8598f
AB
337 (GDestroyNotify) proc_debug_info_sources_destroy);
338 if (!debug_info->vpid_to_proc_dbg_info_src) {
339 goto error;
340 }
341
342 ret = debug_info_init(debug_info);
343 if (ret) {
344 goto error;
345 }
346
347end:
348 return debug_info;
349error:
350 g_free(debug_info);
351 return NULL;
352}
353
354BT_HIDDEN
355void debug_info_destroy(struct debug_info *debug_info)
356{
357 if (!debug_info) {
358 goto end;
359 }
360
361 if (debug_info->vpid_to_proc_dbg_info_src) {
362 g_hash_table_destroy(debug_info->vpid_to_proc_dbg_info_src);
363 }
364
365 g_free(debug_info);
366end:
367 return;
368}
369
370static
371void handle_statedump_build_id_event(struct debug_info *debug_info,
372 struct ctf_event_definition *event_def)
373{
374 struct proc_debug_info_sources *proc_dbg_info_src;
375 struct bt_definition *event_fields_def = NULL;
376 struct bt_definition *sec_def = NULL;
377 struct bt_definition *baddr_def = NULL;
378 struct bt_definition *vpid_def = NULL;
379 struct bt_definition *build_id_def = NULL;
380 struct definition_sequence *build_id_seq;
dae52e76 381 struct bin_info *bin = NULL;
b5a8598f
AB
382 int i;
383 int64_t vpid;
384 uint64_t baddr;
385 uint8_t *build_id = NULL;
386 uint64_t build_id_len;
387
388 event_fields_def = (struct bt_definition *) event_def->event_fields;
389 sec_def = (struct bt_definition *)
390 event_def->stream->stream_event_context;
391
392 if (!event_fields_def || !sec_def) {
393 goto end;
394 }
395
396 baddr_def = bt_lookup_definition(event_fields_def, "_baddr");
397 if (!baddr_def) {
398 goto end;
399 }
400
401 vpid_def = bt_lookup_definition(sec_def, "_vpid");
402 if (!vpid_def) {
403 goto end;
404 }
405
406 build_id_def = bt_lookup_definition(event_fields_def, "_build_id");
407 if (!build_id_def) {
408 goto end;
409 }
410
411 if (baddr_def->declaration->id != CTF_TYPE_INTEGER) {
412 goto end;
413 }
414
415 if (vpid_def->declaration->id != CTF_TYPE_INTEGER) {
416 goto end;
417 }
418
419 if (build_id_def->declaration->id != CTF_TYPE_SEQUENCE) {
420 goto end;
421 }
422
423 baddr = bt_get_unsigned_int(baddr_def);
424 vpid = bt_get_signed_int(vpid_def);
425 build_id_seq = container_of(build_id_def,
426 struct definition_sequence, p);
427 build_id_len = build_id_seq->length->value._unsigned;
428
429 build_id = g_malloc(build_id_len);
430 if (!build_id) {
431 goto end;
432 }
433
434 for (i = 0; i < build_id_len; ++i) {
435 struct bt_definition **field;
436
437 field = (struct bt_definition **) &g_ptr_array_index(
438 build_id_seq->elems, i);
439 build_id[i] = bt_get_unsigned_int(*field);
440 }
441
442 proc_dbg_info_src = proc_debug_info_sources_ht_get_entry(
443 debug_info->vpid_to_proc_dbg_info_src, vpid);
444 if (!proc_dbg_info_src) {
445 goto end;
446 }
447
dae52e76 448 bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info,
b5a8598f 449 (gpointer) &baddr);
dae52e76 450 if (!bin) {
b5a8598f 451 /*
dae52e76 452 * The build_id event comes after the bin has been
b5a8598f
AB
453 * created. If it isn't found, just ignore this event.
454 */
455 goto end;
456 }
457
dae52e76 458 bin_info_set_build_id(bin, build_id, build_id_len);
b5a8598f
AB
459
460end:
461 free(build_id);
462 return;
463}
464
465static
466void handle_statedump_debug_link_event(struct debug_info *debug_info,
467 struct ctf_event_definition *event_def)
468{
469 struct proc_debug_info_sources *proc_dbg_info_src;
470 struct bt_definition *event_fields_def = NULL;
471 struct bt_definition *sec_def = NULL;
472 struct bt_definition *baddr_def = NULL;
473 struct bt_definition *vpid_def = NULL;
474 struct bt_definition *filename_def = NULL;
475 struct bt_definition *crc32_def = NULL;
dae52e76 476 struct bin_info *bin = NULL;
b5a8598f
AB
477 int64_t vpid;
478 uint64_t baddr;
479 char *filename = NULL;
480 uint32_t crc32;
481
482 event_fields_def = (struct bt_definition *) event_def->event_fields;
483 sec_def = (struct bt_definition *)
484 event_def->stream->stream_event_context;
485
486 if (!event_fields_def || !sec_def) {
487 goto end;
488 }
489
490 baddr_def = bt_lookup_definition(event_fields_def, "_baddr");
491 if (!baddr_def) {
492 goto end;
493 }
494
495 vpid_def = bt_lookup_definition(sec_def, "_vpid");
496 if (!vpid_def) {
497 goto end;
498 }
499
500 filename_def = bt_lookup_definition(event_fields_def, "_filename");
501 if (!filename_def) {
502 goto end;
503 }
504
505 crc32_def = bt_lookup_definition(event_fields_def, "_crc32");
506 if (!crc32_def) {
507 goto end;
508 }
509
510 if (baddr_def->declaration->id != CTF_TYPE_INTEGER) {
511 goto end;
512 }
513
514 if (vpid_def->declaration->id != CTF_TYPE_INTEGER) {
515 goto end;
516 }
517
518 if (filename_def->declaration->id != CTF_TYPE_STRING) {
519 goto end;
520 }
521
522 if (crc32_def->declaration->id != CTF_TYPE_INTEGER) {
523 goto end;
524 }
525
526 baddr = bt_get_unsigned_int(baddr_def);
527 vpid = bt_get_signed_int(vpid_def);
528
529 proc_dbg_info_src = proc_debug_info_sources_ht_get_entry(
530 debug_info->vpid_to_proc_dbg_info_src, vpid);
531 if (!proc_dbg_info_src) {
532 goto end;
533 }
534
dae52e76 535 bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info,
b5a8598f 536 (gpointer) &baddr);
dae52e76 537 if (!bin) {
b5a8598f 538 /*
dae52e76 539 * The debug_link event comes after the bin has been
b5a8598f
AB
540 * created. If it isn't found, just ignore this event.
541 */
542 goto end;
543 }
544
545 filename = bt_get_string(filename_def);
546 crc32 = bt_get_unsigned_int(crc32_def);
547
dae52e76 548 bin_info_set_debug_link(bin, filename, crc32);
b5a8598f
AB
549
550end:
551 return;
552}
553
554static
1a4a1345
AB
555void handle_bin_info_event(struct debug_info *debug_info,
556 struct ctf_event_definition *event_def, bool has_pic_field)
b5a8598f
AB
557{
558 struct bt_definition *baddr_def = NULL;
559 struct bt_definition *memsz_def = NULL;
685bd918 560 struct bt_definition *path_def = NULL;
1a4a1345 561 struct bt_definition *is_pic_def = NULL;
b5a8598f
AB
562 struct bt_definition *vpid_def = NULL;
563 struct bt_definition *event_fields_def = NULL;
564 struct bt_definition *sec_def = NULL;
565 struct proc_debug_info_sources *proc_dbg_info_src;
dae52e76 566 struct bin_info *bin;
b5a8598f
AB
567 uint64_t baddr, memsz;
568 int64_t vpid;
685bd918 569 const char *path;
71235b6d 570 gpointer key = NULL;
1a4a1345 571 bool is_pic;
b5a8598f
AB
572
573 event_fields_def = (struct bt_definition *) event_def->event_fields;
574 sec_def = (struct bt_definition *)
575 event_def->stream->stream_event_context;
576
577 if (!event_fields_def || !sec_def) {
578 goto end;
579 }
580
581 baddr_def = bt_lookup_definition(event_fields_def, "_baddr");
582 if (!baddr_def) {
583 goto end;
584 }
585
586 memsz_def = bt_lookup_definition(event_fields_def, "_memsz");
587 if (!memsz_def) {
588 goto end;
589 }
590
685bd918
AB
591 path_def = bt_lookup_definition(event_fields_def, "_path");
592 if (!path_def) {
b5a8598f
AB
593 goto end;
594 }
595
1a4a1345
AB
596 if (has_pic_field) {
597 is_pic_def = bt_lookup_definition(event_fields_def, "_is_pic");
598 if (!is_pic_def) {
599 goto end;
600 }
601
602 if (is_pic_def->declaration->id != CTF_TYPE_INTEGER) {
603 goto end;
604 }
605
606 is_pic = (bt_get_unsigned_int(is_pic_def) == 1);
607 } else {
608 /*
609 * dlopen has no is_pic field, because the shared
610 * object is always PIC.
611 */
612 is_pic = true;
613 }
614
b5a8598f
AB
615 vpid_def = bt_lookup_definition(sec_def, "_vpid");
616 if (!vpid_def) {
617 goto end;
618 }
619
620 if (baddr_def->declaration->id != CTF_TYPE_INTEGER) {
621 goto end;
622 }
623
624 if (memsz_def->declaration->id != CTF_TYPE_INTEGER) {
625 goto end;
626 }
627
685bd918 628 if (path_def->declaration->id != CTF_TYPE_STRING) {
b5a8598f
AB
629 goto end;
630 }
631
632 if (vpid_def->declaration->id != CTF_TYPE_INTEGER) {
633 goto end;
634 }
635
636 baddr = bt_get_unsigned_int(baddr_def);
637 memsz = bt_get_unsigned_int(memsz_def);
685bd918 638 path = bt_get_string(path_def);
b5a8598f
AB
639 vpid = bt_get_signed_int(vpid_def);
640
685bd918 641 if (!path) {
b5a8598f
AB
642 goto end;
643 }
644
645 if (memsz == 0) {
646 /* Ignore VDSO. */
647 goto end;
648 }
649
650 proc_dbg_info_src = proc_debug_info_sources_ht_get_entry(
651 debug_info->vpid_to_proc_dbg_info_src, vpid);
652 if (!proc_dbg_info_src) {
653 goto end;
654 }
655
71235b6d
JG
656 key = g_new0(uint64_t, 1);
657 if (!key) {
658 goto end;
659 }
660
661 *((uint64_t *) key) = baddr;
662
dae52e76 663 bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info,
71235b6d 664 key);
dae52e76 665 if (bin) {
b5a8598f
AB
666 goto end;
667 }
668
dae52e76
AB
669 bin = bin_info_create(path, baddr, memsz, is_pic);
670 if (!bin) {
b5a8598f
AB
671 goto end;
672 }
673
dae52e76
AB
674 g_hash_table_insert(proc_dbg_info_src->baddr_to_bin_info,
675 key, bin);
71235b6d
JG
676 /* Ownership passed to ht. */
677 key = NULL;
b5a8598f
AB
678
679end:
71235b6d 680 g_free(key);
b5a8598f
AB
681 return;
682}
683
1a4a1345 684static inline
685bd918 685void handle_statedump_bin_info_event(struct debug_info *debug_info,
1a4a1345
AB
686 struct ctf_event_definition *event_def)
687{
688 handle_bin_info_event(debug_info, event_def, true);
689}
690
691static inline
692void handle_dlopen_event(struct debug_info *debug_info,
693 struct ctf_event_definition *event_def)
694{
695 handle_bin_info_event(debug_info, event_def, false);
696}
697
698
b5a8598f
AB
699static
700void handle_statedump_start(struct debug_info *debug_info,
701 struct ctf_event_definition *event_def)
702{
703 struct bt_definition *vpid_def = NULL;
704 struct bt_definition *sec_def = NULL;
705 struct proc_debug_info_sources *proc_dbg_info_src;
706 int64_t vpid;
707
708 sec_def = (struct bt_definition *)
709 event_def->stream->stream_event_context;
710 if (!sec_def) {
711 goto end;
712 }
713
714 vpid_def = bt_lookup_definition(sec_def, "_vpid");
715 if (!vpid_def) {
716 goto end;
717 }
718
719 vpid = bt_get_signed_int(vpid_def);
720
721 proc_dbg_info_src = proc_debug_info_sources_ht_get_entry(
722 debug_info->vpid_to_proc_dbg_info_src, vpid);
723 if (!proc_dbg_info_src) {
724 goto end;
725 }
726
dae52e76 727 g_hash_table_remove_all(proc_dbg_info_src->baddr_to_bin_info);
b5a8598f
AB
728 g_hash_table_remove_all(proc_dbg_info_src->ip_to_debug_info_src);
729
730end:
731 return;
732}
733
734static
735void register_event_debug_infos(struct debug_info *debug_info,
736 struct ctf_event_definition *event)
737{
738 struct bt_definition *ip_def, *vpid_def;
739 int64_t vpid;
740 uint64_t ip;
741 struct bt_definition *sec_def;
742
743 /* Get stream event context definition. */
744 sec_def = (struct bt_definition *) event->stream->stream_event_context;
745 if (!sec_def) {
746 goto end;
747 }
748
749 /* Get "ip" and "vpid" definitions. */
750 vpid_def = bt_lookup_definition((struct bt_definition *) sec_def,
751 "_vpid");
752 ip_def = bt_lookup_definition((struct bt_definition *) sec_def, "_ip");
753
754 if (!vpid_def || !ip_def) {
755 goto end;
756 }
757
758 vpid = bt_get_signed_int(vpid_def);
759 ip = bt_get_unsigned_int(ip_def);
760
761 /* Get debug info for this context. */
762 ((struct definition_integer *) ip_def)->debug_info_src =
763 debug_info_query(debug_info, vpid, ip);
764
765end:
766 return;
767}
768
769BT_HIDDEN
770void debug_info_handle_event(struct debug_info *debug_info,
771 struct ctf_event_definition *event)
772{
773 struct ctf_event_declaration *event_class;
774 struct ctf_stream_declaration *stream_class;
775
776 if (!debug_info || !event) {
777 goto end;
778 }
779
780 stream_class = event->stream->stream_class;
781 event_class = g_ptr_array_index(stream_class->events_by_id,
782 event->stream->event_id);
783
685bd918 784 if (event_class->name == debug_info->q_statedump_bin_info) {
1a4a1345 785 /* State dump */
685bd918 786 handle_statedump_bin_info_event(debug_info, event);
1a4a1345
AB
787 } else if (event_class->name == debug_info->q_dl_open) {
788 handle_dlopen_event(debug_info, event);
b5a8598f
AB
789 } else if (event_class->name == debug_info->q_statedump_start) {
790 /* Start state dump */
791 handle_statedump_start(debug_info, event);
792 } else if (event_class->name == debug_info->q_statedump_debug_link) {
793 /* Debug link info */
794 handle_statedump_debug_link_event(debug_info, event);
795 } else if (event_class->name == debug_info->q_statedump_build_id) {
796 /* Build ID info */
797 handle_statedump_build_id_event(debug_info, event);
b5a8598f
AB
798 }
799
09c9a6e8
SM
800 /* All events: register debug infos */
801 register_event_debug_infos(debug_info, event);
802
b5a8598f
AB
803end:
804 return;
805}
This page took 0.091983 seconds and 4 git commands to generate.