File: debug-info.c

package info (click to toggle)
babeltrace 1.5.11-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,296 kB
  • sloc: ansic: 37,923; sh: 5,225; yacc: 2,327; makefile: 529; lex: 142; python: 104
file content (805 lines) | stat: -rw-r--r-- 19,020 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
/*
 * Babeltrace - Debug Information State Tracker
 *
 * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
 * Copyright (c) 2015 Philippe Proulx <pproulx@efficios.com>
 * Copyright (c) 2015 Antoine Busque <abusque@efficios.com>
 * Copyright (c) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <assert.h>
#include <glib.h>
#include <babeltrace/types.h>
#include <babeltrace/ctf-ir/metadata.h>
#include <babeltrace/debug-info.h>
#include <babeltrace/bin-info.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/utils.h>

struct proc_debug_info_sources {
	/*
	 * Hash table: base address (pointer to uint64_t) to bin info; owned by
	 * proc_debug_info_sources.
	 */
	GHashTable *baddr_to_bin_info;

	/*
	 * Hash table: IP (pointer to uint64_t) to (struct debug_info_source *);
	 * owned by proc_debug_info_sources.
	 */
	GHashTable *ip_to_debug_info_src;
};

struct debug_info {
	/*
	 * Hash table of VPIDs (pointer to int64_t) to
	 * (struct ctf_proc_debug_infos*); owned by debug_info.
	 */
	GHashTable *vpid_to_proc_dbg_info_src;
	GQuark q_statedump_bin_info;
	GQuark q_statedump_debug_link;
	GQuark q_statedump_build_id;
	GQuark q_statedump_start;
	GQuark q_dl_open;
};

static
int debug_info_init(struct debug_info *info)
{
	info->q_statedump_bin_info = g_quark_from_string(
			"lttng_ust_statedump:bin_info");
	info->q_statedump_debug_link = g_quark_from_string(
			"lttng_ust_statedump:debug_link)");
	info->q_statedump_build_id = g_quark_from_string(
			"lttng_ust_statedump:build_id");
	info->q_statedump_start = g_quark_from_string(
			"lttng_ust_statedump:start");
	info->q_dl_open = g_quark_from_string("lttng_ust_dl:dlopen");

	return bin_info_init();
}

static
void debug_info_source_destroy(struct debug_info_source *debug_info_src)
{
	if (!debug_info_src) {
		return;
	}

	free(debug_info_src->func);
	free(debug_info_src->src_path);
	free(debug_info_src->bin_path);
	free(debug_info_src->bin_loc);
	g_free(debug_info_src);
}

static
struct debug_info_source *debug_info_source_create_from_bin(struct bin_info *bin,
		uint64_t ip)
{
	int ret;
	struct debug_info_source *debug_info_src = NULL;
	struct source_location *src_loc = NULL;

	debug_info_src = g_new0(struct debug_info_source, 1);

	if (!debug_info_src) {
		goto end;
	}

	/* Lookup function name */
	ret = bin_info_lookup_function_name(bin, ip, &debug_info_src->func);
	if (ret) {
		goto error;
	}

	/* Can't retrieve src_loc from ELF, or could not find binary, skip. */
	if (!bin->is_elf_only || !debug_info_src->func) {
		/* Lookup source location */
		ret = bin_info_lookup_source_location(bin, ip, &src_loc);
		printf_verbose("Failed to lookup source location (err: %i)\n", ret);
	}

	if (src_loc) {
		debug_info_src->line_no = src_loc->line_no;

		if (src_loc->filename) {
			debug_info_src->src_path = strdup(src_loc->filename);
			if (!debug_info_src->src_path) {
				goto error;
			}

			debug_info_src->short_src_path = get_filename_from_path(
					debug_info_src->src_path);
		}

		source_location_destroy(src_loc);
	}

	if (bin->elf_path) {
		debug_info_src->bin_path = strdup(bin->elf_path);
		if (!debug_info_src->bin_path) {
			goto error;
		}

		debug_info_src->short_bin_path = get_filename_from_path(
				debug_info_src->bin_path);

		ret = bin_info_get_bin_loc(bin, ip, &(debug_info_src->bin_loc));
		if (ret) {
			goto error;
		}
	}

end:
	return debug_info_src;

error:
	debug_info_source_destroy(debug_info_src);
	return NULL;
}

static
void proc_debug_info_sources_destroy(
		struct proc_debug_info_sources *proc_dbg_info_src)
{
	if (!proc_dbg_info_src) {
		return;
	}

	if (proc_dbg_info_src->baddr_to_bin_info) {
		g_hash_table_destroy(proc_dbg_info_src->baddr_to_bin_info);
	}

	if (proc_dbg_info_src->ip_to_debug_info_src) {
		g_hash_table_destroy(proc_dbg_info_src->ip_to_debug_info_src);
	}

	g_free(proc_dbg_info_src);
}

static
struct proc_debug_info_sources *proc_debug_info_sources_create(void)
{
	struct proc_debug_info_sources *proc_dbg_info_src = NULL;

	proc_dbg_info_src = g_new0(struct proc_debug_info_sources, 1);
	if (!proc_dbg_info_src) {
		goto end;
	}

	proc_dbg_info_src->baddr_to_bin_info = g_hash_table_new_full(
			g_int64_hash, g_int64_equal, (GDestroyNotify) g_free,
			(GDestroyNotify) bin_info_destroy);
	if (!proc_dbg_info_src->baddr_to_bin_info) {
		goto error;
	}

	proc_dbg_info_src->ip_to_debug_info_src = g_hash_table_new_full(
			g_int64_hash, g_int64_equal, (GDestroyNotify) g_free,
			(GDestroyNotify) debug_info_source_destroy);
	if (!proc_dbg_info_src->ip_to_debug_info_src) {
		goto error;
	}

end:
	return proc_dbg_info_src;

error:
	proc_debug_info_sources_destroy(proc_dbg_info_src);
	return NULL;
}

static
struct proc_debug_info_sources *proc_debug_info_sources_ht_get_entry(
		GHashTable *ht, int64_t vpid)
{
	gpointer key = g_new0(int64_t, 1);
	struct proc_debug_info_sources *proc_dbg_info_src = NULL;

	if (!key) {
		goto end;
	}

	*((int64_t *) key) = vpid;

	/* Exists? Return it */
	proc_dbg_info_src = g_hash_table_lookup(ht, key);
	if (proc_dbg_info_src) {
		goto end;
	}

	/* Otherwise, create and return it */
	proc_dbg_info_src = proc_debug_info_sources_create();
	if (!proc_dbg_info_src) {
		goto end;
	}

	g_hash_table_insert(ht, key, proc_dbg_info_src);
	/* Ownership passed to ht */
	key = NULL;
end:
	g_free(key);
	return proc_dbg_info_src;
}

static
struct debug_info_source *proc_debug_info_sources_get_entry(
		struct proc_debug_info_sources *proc_dbg_info_src, uint64_t ip)
{
	struct debug_info_source *debug_info_src = NULL;
	gpointer key = g_new0(uint64_t, 1);
	GHashTableIter iter;
	gpointer baddr, value;

	if (!key) {
		goto end;
	}

	*((uint64_t *) key) = ip;

	/* Look in IP to debug infos hash table first. */
	debug_info_src = g_hash_table_lookup(
			proc_dbg_info_src->ip_to_debug_info_src,
			key);
	if (debug_info_src) {
		goto end;
	}

	/* Check in all bin_infos. */
	g_hash_table_iter_init(&iter, proc_dbg_info_src->baddr_to_bin_info);

	while (g_hash_table_iter_next(&iter, &baddr, &value))
	{
		struct bin_info *bin = value;

		if (!bin_info_has_address(value, ip)) {
			continue;
		}

		/*
		 * Found; add it to cache.
		 *
		 * FIXME: this should be bounded in size (and implement
		 * a caching policy), and entries should be prunned when
		 * libraries are unmapped.
		 */
		debug_info_src = debug_info_source_create_from_bin(bin, ip);
		if (debug_info_src) {
			g_hash_table_insert(
					proc_dbg_info_src->ip_to_debug_info_src,
					key, debug_info_src);
			/* Ownership passed to ht. */
			key = NULL;
		}
		break;
	}

end:
	free(key);
	return debug_info_src;
}

BT_HIDDEN
struct debug_info_source *debug_info_query(struct debug_info *debug_info,
		int64_t vpid, uint64_t ip)
{
	struct debug_info_source *dbg_info_src = NULL;
	struct proc_debug_info_sources *proc_dbg_info_src;

	proc_dbg_info_src = proc_debug_info_sources_ht_get_entry(
			debug_info->vpid_to_proc_dbg_info_src, vpid);
	if (!proc_dbg_info_src) {
		goto end;
	}

	dbg_info_src = proc_debug_info_sources_get_entry(
			proc_dbg_info_src, ip);
	if (!dbg_info_src) {
		goto end;
	}

end:
	return dbg_info_src;
}

BT_HIDDEN
struct debug_info *debug_info_create(void)
{
	int ret;
	struct debug_info *debug_info;

	debug_info = g_new0(struct debug_info, 1);
	if (!debug_info) {
		goto end;
	}

	debug_info->vpid_to_proc_dbg_info_src = g_hash_table_new_full(
			g_int64_hash, g_int64_equal, (GDestroyNotify) g_free,
			(GDestroyNotify) proc_debug_info_sources_destroy);
	if (!debug_info->vpid_to_proc_dbg_info_src) {
		goto error;
	}

	ret = debug_info_init(debug_info);
	if (ret) {
		goto error;
	}

end:
	return debug_info;
error:
	g_free(debug_info);
	return NULL;
}

BT_HIDDEN
void debug_info_destroy(struct debug_info *debug_info)
{
	if (!debug_info) {
		goto end;
	}

	if (debug_info->vpid_to_proc_dbg_info_src) {
		g_hash_table_destroy(debug_info->vpid_to_proc_dbg_info_src);
	}

	g_free(debug_info);
end:
	return;
}

static
void handle_statedump_build_id_event(struct debug_info *debug_info,
		struct ctf_event_definition *event_def)
{
	struct proc_debug_info_sources *proc_dbg_info_src;
	struct bt_definition *event_fields_def = NULL;
	struct bt_definition *sec_def = NULL;
	struct bt_definition *baddr_def = NULL;
	struct bt_definition *vpid_def = NULL;
	struct bt_definition *build_id_def = NULL;
	struct definition_sequence *build_id_seq;
	struct bin_info *bin = NULL;
	int i;
	int64_t vpid;
	uint64_t baddr;
	uint8_t *build_id = NULL;
	uint64_t build_id_len;

	event_fields_def = (struct bt_definition *) event_def->event_fields;
	sec_def = (struct bt_definition *)
			event_def->stream->stream_event_context;

	if (!event_fields_def || !sec_def) {
		goto end;
	}

	baddr_def = bt_lookup_definition(event_fields_def, "_baddr");
	if (!baddr_def) {
		goto end;
	}

	vpid_def = bt_lookup_definition(sec_def, "_vpid");
	if (!vpid_def) {
		goto end;
	}

	build_id_def = bt_lookup_definition(event_fields_def, "_build_id");
	if (!build_id_def) {
		goto end;
	}

	if (baddr_def->declaration->id != CTF_TYPE_INTEGER) {
		goto end;
	}

	if (vpid_def->declaration->id != CTF_TYPE_INTEGER) {
		goto end;
	}

	if (build_id_def->declaration->id != CTF_TYPE_SEQUENCE) {
		goto end;
	}

	baddr = bt_get_unsigned_int(baddr_def);
	vpid = bt_get_signed_int(vpid_def);
	build_id_seq = container_of(build_id_def,
			struct definition_sequence, p);
	build_id_len = build_id_seq->length->value._unsigned;

	build_id = g_malloc(build_id_len);
	if (!build_id) {
		goto end;
	}

	for (i = 0; i < build_id_len; ++i) {
		struct bt_definition **field;

		field = (struct bt_definition **) &g_ptr_array_index(
				build_id_seq->elems, i);
		build_id[i] = bt_get_unsigned_int(*field);
	}

	proc_dbg_info_src = proc_debug_info_sources_ht_get_entry(
			debug_info->vpid_to_proc_dbg_info_src, vpid);
	if (!proc_dbg_info_src) {
		goto end;
	}

	bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info,
			(gpointer) &baddr);
	if (!bin) {
		/*
		 * The build_id event comes after the bin has been
		 * created. If it isn't found, just ignore this event.
		 */
		goto end;
	}

	bin_info_set_build_id(bin, build_id, build_id_len);

end:
	free(build_id);
	return;
}

static
void handle_statedump_debug_link_event(struct debug_info *debug_info,
		struct ctf_event_definition *event_def)
{
	struct proc_debug_info_sources *proc_dbg_info_src;
	struct bt_definition *event_fields_def = NULL;
	struct bt_definition *sec_def = NULL;
	struct bt_definition *baddr_def = NULL;
	struct bt_definition *vpid_def = NULL;
	struct bt_definition *filename_def = NULL;
	struct bt_definition *crc32_def = NULL;
	struct bin_info *bin = NULL;
	int64_t vpid;
	uint64_t baddr;
	char *filename = NULL;
	uint32_t crc32;

	event_fields_def = (struct bt_definition *) event_def->event_fields;
	sec_def = (struct bt_definition *)
			event_def->stream->stream_event_context;

	if (!event_fields_def || !sec_def) {
		goto end;
	}

	baddr_def = bt_lookup_definition(event_fields_def, "_baddr");
	if (!baddr_def) {
		goto end;
	}

	vpid_def = bt_lookup_definition(sec_def, "_vpid");
	if (!vpid_def) {
		goto end;
	}

	filename_def = bt_lookup_definition(event_fields_def, "_filename");
	if (!filename_def) {
		goto end;
	}

	crc32_def = bt_lookup_definition(event_fields_def, "_crc32");
	if (!crc32_def) {
		goto end;
	}

	if (baddr_def->declaration->id != CTF_TYPE_INTEGER) {
		goto end;
	}

	if (vpid_def->declaration->id != CTF_TYPE_INTEGER) {
		goto end;
	}

	if (filename_def->declaration->id != CTF_TYPE_STRING) {
		goto end;
	}

	if (crc32_def->declaration->id != CTF_TYPE_INTEGER) {
		goto end;
	}

	baddr = bt_get_unsigned_int(baddr_def);
	vpid = bt_get_signed_int(vpid_def);

	proc_dbg_info_src = proc_debug_info_sources_ht_get_entry(
			debug_info->vpid_to_proc_dbg_info_src, vpid);
	if (!proc_dbg_info_src) {
		goto end;
	}

	bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info,
			(gpointer) &baddr);
	if (!bin) {
		/*
		 * The debug_link event comes after the bin has been
		 * created. If it isn't found, just ignore this event.
		 */
		goto end;
	}

	filename = bt_get_string(filename_def);
	crc32 = bt_get_unsigned_int(crc32_def);

	bin_info_set_debug_link(bin, filename, crc32);

end:
	return;
}

static
void handle_bin_info_event(struct debug_info *debug_info,
		struct ctf_event_definition *event_def, bool has_pic_field)
{
	struct bt_definition *baddr_def = NULL;
	struct bt_definition *memsz_def = NULL;
	struct bt_definition *path_def = NULL;
	struct bt_definition *is_pic_def = NULL;
	struct bt_definition *vpid_def = NULL;
	struct bt_definition *event_fields_def = NULL;
	struct bt_definition *sec_def = NULL;
	struct proc_debug_info_sources *proc_dbg_info_src;
	struct bin_info *bin;
	uint64_t baddr, memsz;
	int64_t vpid;
	const char *path;
	gpointer key = NULL;
	bool is_pic;

	event_fields_def = (struct bt_definition *) event_def->event_fields;
	sec_def = (struct bt_definition *)
		event_def->stream->stream_event_context;

	if (!event_fields_def || !sec_def) {
		goto end;
	}

	baddr_def = bt_lookup_definition(event_fields_def, "_baddr");
	if (!baddr_def) {
		goto end;
	}

	memsz_def = bt_lookup_definition(event_fields_def, "_memsz");
	if (!memsz_def) {
		goto end;
	}

	path_def = bt_lookup_definition(event_fields_def, "_path");
	if (!path_def) {
		goto end;
	}

	if (has_pic_field) {
		is_pic_def = bt_lookup_definition(event_fields_def, "_is_pic");
		if (!is_pic_def) {
			goto end;
		}

		if (is_pic_def->declaration->id != CTF_TYPE_INTEGER) {
			goto end;
		}

		is_pic = (bt_get_unsigned_int(is_pic_def) == 1);
	} else {
		/*
		 * dlopen has no is_pic field, because the shared
		 * object is always PIC.
		 */
		is_pic = true;
	}

	vpid_def = bt_lookup_definition(sec_def, "_vpid");
	if (!vpid_def) {
		goto end;
	}

	if (baddr_def->declaration->id != CTF_TYPE_INTEGER) {
		goto end;
	}

	if (memsz_def->declaration->id != CTF_TYPE_INTEGER) {
		goto end;
	}

	if (path_def->declaration->id != CTF_TYPE_STRING) {
		goto end;
	}

	if (vpid_def->declaration->id != CTF_TYPE_INTEGER) {
		goto end;
	}

	baddr = bt_get_unsigned_int(baddr_def);
	memsz = bt_get_unsigned_int(memsz_def);
	path = bt_get_string(path_def);
	vpid = bt_get_signed_int(vpid_def);

	if (!path) {
		goto end;
	}

	if (memsz == 0) {
		/* Ignore VDSO. */
		goto end;
	}

	proc_dbg_info_src = proc_debug_info_sources_ht_get_entry(
			debug_info->vpid_to_proc_dbg_info_src, vpid);
	if (!proc_dbg_info_src) {
		goto end;
	}

	key = g_new0(uint64_t, 1);
	if (!key) {
		goto end;
	}

	*((uint64_t *) key) = baddr;

	bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info,
			key);
	if (bin) {
		goto end;
	}

	bin = bin_info_create(path, baddr, memsz, is_pic);
	if (!bin) {
		goto end;
	}

	g_hash_table_insert(proc_dbg_info_src->baddr_to_bin_info,
			key, bin);
	/* Ownership passed to ht. */
	key = NULL;

end:
	g_free(key);
	return;
}

static inline
void handle_statedump_bin_info_event(struct debug_info *debug_info,
		struct ctf_event_definition *event_def)
{
	handle_bin_info_event(debug_info, event_def, true);
}

static inline
void handle_dlopen_event(struct debug_info *debug_info,
		struct ctf_event_definition *event_def)
{
	handle_bin_info_event(debug_info, event_def, false);
}


static
void handle_statedump_start(struct debug_info *debug_info,
		struct ctf_event_definition *event_def)
{
	struct bt_definition *vpid_def = NULL;
	struct bt_definition *sec_def = NULL;
	struct proc_debug_info_sources *proc_dbg_info_src;
	int64_t vpid;

	sec_def = (struct bt_definition *)
			event_def->stream->stream_event_context;
	if (!sec_def) {
		goto end;
	}

	vpid_def = bt_lookup_definition(sec_def, "_vpid");
	if (!vpid_def) {
		goto end;
	}

	vpid = bt_get_signed_int(vpid_def);

	proc_dbg_info_src = proc_debug_info_sources_ht_get_entry(
			debug_info->vpid_to_proc_dbg_info_src, vpid);
	if (!proc_dbg_info_src) {
		goto end;
	}

	g_hash_table_remove_all(proc_dbg_info_src->baddr_to_bin_info);
	g_hash_table_remove_all(proc_dbg_info_src->ip_to_debug_info_src);

end:
	return;
}

static
void register_event_debug_infos(struct debug_info *debug_info,
		struct ctf_event_definition *event)
{
	struct bt_definition *ip_def, *vpid_def;
	int64_t vpid;
	uint64_t ip;
	struct bt_definition *sec_def;

	/* Get stream event context definition. */
	sec_def = (struct bt_definition *) event->stream->stream_event_context;
	if (!sec_def) {
		goto end;
	}

	/* Get "ip" and "vpid" definitions. */
	vpid_def = bt_lookup_definition((struct bt_definition *) sec_def,
			 "_vpid");
	ip_def = bt_lookup_definition((struct bt_definition *) sec_def, "_ip");

	if (!vpid_def || !ip_def) {
		 goto end;
	}

	vpid = bt_get_signed_int(vpid_def);
	ip = bt_get_unsigned_int(ip_def);

	/* Get debug info for this context. */
	((struct definition_integer *) ip_def)->debug_info_src =
			debug_info_query(debug_info, vpid, ip);

end:
	return;
}

BT_HIDDEN
void debug_info_handle_event(struct debug_info *debug_info,
		struct ctf_event_definition *event)
{
	struct ctf_event_declaration *event_class;
	struct ctf_stream_declaration *stream_class;

	if (!debug_info || !event) {
		goto end;
	}

	stream_class = event->stream->stream_class;
	event_class = g_ptr_array_index(stream_class->events_by_id,
			event->stream->event_id);

	if (event_class->name == debug_info->q_statedump_bin_info) {
		/* State dump */
		handle_statedump_bin_info_event(debug_info, event);
	} else if (event_class->name == debug_info->q_dl_open) {
		handle_dlopen_event(debug_info, event);
	} else if (event_class->name == debug_info->q_statedump_start) {
		/* Start state dump */
		handle_statedump_start(debug_info, event);
	} else if (event_class->name == debug_info->q_statedump_debug_link) {
		/* Debug link info */
		handle_statedump_debug_link_event(debug_info, event);
	} else if (event_class->name == debug_info->q_statedump_build_id) {
		/* Build ID info */
		handle_statedump_build_id_event(debug_info, event);
	}

	/* All events: register debug infos */
	register_event_debug_infos(debug_info, event);

end:
	return;
}