Standardise spelling of debug info
[babeltrace.git] / lib / debug-info.c
CommitLineData
c40a57e5
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>
ff9ce920 7 * Copyright (c) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
c40a57e5
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>
2748fb3b 32#include <babeltrace/debug-info.h>
d5ddf820 33#include <babeltrace/bin-info.h>
ff9ce920 34#include <babeltrace/babeltrace-internal.h>
55cd033d 35#include <babeltrace/utils.h>
c40a57e5
AB
36
37struct proc_debug_info_sources {
38 /*
d5ddf820 39 * Hash table: base address (pointer to uint64_t) to bin info; owned by
c40a57e5
AB
40 * proc_debug_info_sources.
41 */
d5ddf820 42 GHashTable *baddr_to_bin_info;
c40a57e5
AB
43
44 /*
47857613
JG
45 * Hash table: IP (pointer to uint64_t) to (struct debug_info_source *);
46 * owned by proc_debug_info_sources.
c40a57e5
AB
47 */
48 GHashTable *ip_to_debug_info_src;
49};
50
51struct debug_info {
52 /*
47857613
JG
53 * Hash table of VPIDs (pointer to int64_t) to
54 * (struct ctf_proc_debug_infos*); owned by debug_info.
c40a57e5
AB
55 */
56 GHashTable *vpid_to_proc_dbg_info_src;
9c713367 57 GQuark q_statedump_bin_info;
c40a57e5
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{
9c713367
AB
67 info->q_statedump_bin_info = g_quark_from_string(
68 "lttng_ust_statedump:bin_info");
c40a57e5
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
d5ddf820 77 return bin_info_init();
c40a57e5
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);
a7a607cf
JG
88 free(debug_info_src->src_path);
89 free(debug_info_src->bin_path);
36ae9941 90 free(debug_info_src->bin_loc);
c40a57e5
AB
91 g_free(debug_info_src);
92}
93
94static
d5ddf820 95struct debug_info_source *debug_info_source_create_from_bin(struct bin_info *bin,
c40a57e5
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 */
d5ddf820 109 ret = bin_info_lookup_function_name(bin, ip, &debug_info_src->func);
c40a57e5
AB
110 if (ret) {
111 goto error;
112 }
113
545e1e92
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) {
44148130 116 /* Lookup source location */
d5ddf820 117 ret = bin_info_lookup_source_location(bin, ip, &src_loc);
545e1e92 118 printf_verbose("Failed to lookup source location (err: %i)\n", ret);
c40a57e5
AB
119 }
120
121 if (src_loc) {
122 debug_info_src->line_no = src_loc->line_no;
123
124 if (src_loc->filename) {
a7a607cf
JG
125 debug_info_src->src_path = strdup(src_loc->filename);
126 if (!debug_info_src->src_path) {
c40a57e5
AB
127 goto error;
128 }
ff9ce920 129
a7a607cf 130 debug_info_src->short_src_path = get_filename_from_path(
51a9f65d 131 debug_info_src->src_path);
c40a57e5
AB
132 }
133
134 source_location_destroy(src_loc);
135 }
136
d5ddf820
AB
137 if (bin->elf_path) {
138 debug_info_src->bin_path = strdup(bin->elf_path);
a7a607cf
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);
36ae9941 145
d5ddf820 146 ret = bin_info_get_bin_loc(bin, ip, &(debug_info_src->bin_loc));
36ae9941
AB
147 if (ret) {
148 goto error;
149 }
a7a607cf
JG
150 }
151
c40a57e5
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
d5ddf820
AB
168 if (proc_dbg_info_src->baddr_to_bin_info) {
169 g_hash_table_destroy(proc_dbg_info_src->baddr_to_bin_info);
c40a57e5
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
d5ddf820 189 proc_dbg_info_src->baddr_to_bin_info = g_hash_table_new_full(
47857613 190 g_int64_hash, g_int64_equal, (GDestroyNotify) g_free,
d5ddf820
AB
191 (GDestroyNotify) bin_info_destroy);
192 if (!proc_dbg_info_src->baddr_to_bin_info) {
c40a57e5
AB
193 goto error;
194 }
195
196 proc_dbg_info_src->ip_to_debug_info_src = g_hash_table_new_full(
47857613 197 g_int64_hash, g_int64_equal, (GDestroyNotify) g_free,
c40a57e5
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{
47857613 215 gpointer key = g_new0(int64_t, 1);
c40a57e5
AB
216 struct proc_debug_info_sources *proc_dbg_info_src = NULL;
217
47857613
JG
218 if (!key) {
219 goto end;
220 }
221
222 *((int64_t *) key) = vpid;
223
c40a57e5
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);
47857613
JG
237 /* Ownership passed to ht */
238 key = NULL;
c40a57e5 239end:
47857613 240 g_free(key);
c40a57e5
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;
47857613 249 gpointer key = g_new0(uint64_t, 1);
c40a57e5
AB
250 GHashTableIter iter;
251 gpointer baddr, value;
252
47857613
JG
253 if (!key) {
254 goto end;
255 }
256
257 *((uint64_t *) key) = ip;
258
c40a57e5
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,
47857613 262 key);
c40a57e5
AB
263 if (debug_info_src) {
264 goto end;
265 }
266
d5ddf820
AB
267 /* Check in all bin_infos. */
268 g_hash_table_iter_init(&iter, proc_dbg_info_src->baddr_to_bin_info);
c40a57e5
AB
269
270 while (g_hash_table_iter_next(&iter, &baddr, &value))
271 {
d5ddf820 272 struct bin_info *bin = value;
c40a57e5 273
d5ddf820 274 if (!bin_info_has_address(value, ip)) {
c40a57e5
AB
275 continue;
276 }
277
47857613
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 */
d5ddf820 285 debug_info_src = debug_info_source_create_from_bin(bin, ip);
c40a57e5
AB
286 if (debug_info_src) {
287 g_hash_table_insert(
288 proc_dbg_info_src->ip_to_debug_info_src,
47857613
JG
289 key, debug_info_src);
290 /* Ownership passed to ht. */
291 key = NULL;
c40a57e5
AB
292 }
293 break;
294 }
295
296end:
47857613 297 free(key);
c40a57e5
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
47857613
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,
c40a57e5
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;
d5ddf820 381 struct bin_info *bin = NULL;
c40a57e5
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 != BT_CTF_TYPE_ID_INTEGER) {
412 goto end;
413 }
414
415 if (vpid_def->declaration->id != BT_CTF_TYPE_ID_INTEGER) {
416 goto end;
417 }
418
419 if (build_id_def->declaration->id != BT_CTF_TYPE_ID_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
d5ddf820 448 bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info,
c40a57e5 449 (gpointer) &baddr);
d5ddf820 450 if (!bin) {
c40a57e5 451 /*
d5ddf820 452 * The build_id event comes after the bin has been
c40a57e5
AB
453 * created. If it isn't found, just ignore this event.
454 */
455 goto end;
456 }
457
d5ddf820 458 bin_info_set_build_id(bin, build_id, build_id_len);
c40a57e5
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;
d5ddf820 476 struct bin_info *bin = NULL;
c40a57e5
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 != BT_CTF_TYPE_ID_INTEGER) {
511 goto end;
512 }
513
514 if (vpid_def->declaration->id != BT_CTF_TYPE_ID_INTEGER) {
515 goto end;
516 }
517
518 if (filename_def->declaration->id != BT_CTF_TYPE_ID_STRING) {
519 goto end;
520 }
521
522 if (crc32_def->declaration->id != BT_CTF_TYPE_ID_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
d5ddf820 535 bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info,
c40a57e5 536 (gpointer) &baddr);
d5ddf820 537 if (!bin) {
c40a57e5 538 /*
d5ddf820 539 * The debug_link event comes after the bin has been
c40a57e5
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
d5ddf820 548 bin_info_set_debug_link(bin, filename, crc32);
c40a57e5
AB
549
550end:
551 return;
552}
553
554static
9f2b13ca
AB
555void handle_bin_info_event(struct debug_info *debug_info,
556 struct ctf_event_definition *event_def, bool has_pic_field)
c40a57e5
AB
557{
558 struct bt_definition *baddr_def = NULL;
559 struct bt_definition *memsz_def = NULL;
9c713367 560 struct bt_definition *path_def = NULL;
9f2b13ca 561 struct bt_definition *is_pic_def = NULL;
c40a57e5
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;
d5ddf820 566 struct bin_info *bin;
c40a57e5
AB
567 uint64_t baddr, memsz;
568 int64_t vpid;
9c713367 569 const char *path;
47857613 570 gpointer key = NULL;
9f2b13ca 571 bool is_pic;
c40a57e5
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
9c713367
AB
591 path_def = bt_lookup_definition(event_fields_def, "_path");
592 if (!path_def) {
c40a57e5
AB
593 goto end;
594 }
595
9f2b13ca
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 != BT_CTF_TYPE_ID_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
c40a57e5
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 != BT_CTF_TYPE_ID_INTEGER) {
621 goto end;
622 }
623
624 if (memsz_def->declaration->id != BT_CTF_TYPE_ID_INTEGER) {
625 goto end;
626 }
627
9c713367 628 if (path_def->declaration->id != BT_CTF_TYPE_ID_STRING) {
c40a57e5
AB
629 goto end;
630 }
631
632 if (vpid_def->declaration->id != BT_CTF_TYPE_ID_INTEGER) {
633 goto end;
634 }
635
636 baddr = bt_get_unsigned_int(baddr_def);
637 memsz = bt_get_unsigned_int(memsz_def);
9c713367 638 path = bt_get_string(path_def);
c40a57e5
AB
639 vpid = bt_get_signed_int(vpid_def);
640
9c713367 641 if (!path) {
c40a57e5
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
47857613
JG
656 key = g_new0(uint64_t, 1);
657 if (!key) {
658 goto end;
659 }
660
661 *((uint64_t *) key) = baddr;
662
d5ddf820 663 bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info,
47857613 664 key);
d5ddf820 665 if (bin) {
c40a57e5
AB
666 goto end;
667 }
668
d5ddf820
AB
669 bin = bin_info_create(path, baddr, memsz, is_pic);
670 if (!bin) {
c40a57e5
AB
671 goto end;
672 }
673
d5ddf820
AB
674 g_hash_table_insert(proc_dbg_info_src->baddr_to_bin_info,
675 key, bin);
47857613
JG
676 /* Ownership passed to ht. */
677 key = NULL;
c40a57e5
AB
678
679end:
47857613 680 g_free(key);
c40a57e5
AB
681 return;
682}
683
9f2b13ca 684static inline
9c713367 685void handle_statedump_bin_info_event(struct debug_info *debug_info,
9f2b13ca
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
c40a57e5
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
d5ddf820 727 g_hash_table_remove_all(proc_dbg_info_src->baddr_to_bin_info);
c40a57e5
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
9c713367 784 if (event_class->name == debug_info->q_statedump_bin_info) {
9f2b13ca 785 /* State dump */
9c713367 786 handle_statedump_bin_info_event(debug_info, event);
9f2b13ca
AB
787 } else if (event_class->name == debug_info->q_dl_open) {
788 handle_dlopen_event(debug_info, event);
c40a57e5
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);
798 } else {
799 /* Other events: register debug infos */
800 register_event_debug_infos(debug_info, event);
801 }
802
803end:
804 return;
805}
This page took 0.05542 seconds and 4 git commands to generate.