| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 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> |
| 7 | * Copyright (c) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 8 | * Copyright (c) 2019 Francis Deslauriers <francis.deslauriers@efficios.com> |
| 9 | * |
| 10 | * Babeltrace - Debug Information State Tracker |
| 11 | */ |
| 12 | |
| 13 | #define BT_COMP_LOG_SELF_COMP self_comp |
| 14 | #define BT_LOG_OUTPUT_LEVEL log_level |
| 15 | #define BT_LOG_TAG "PLUGIN/FLT.LTTNG-UTILS.DEBUG-INFO" |
| 16 | #include "logging/comp-logging.h" |
| 17 | |
| 18 | #include <stdbool.h> |
| 19 | |
| 20 | #include <glib.h> |
| 21 | |
| 22 | #include "common/assert.h" |
| 23 | #include "common/common.h" |
| 24 | #include "fd-cache/fd-cache.h" |
| 25 | |
| 26 | #include "bin-info.h" |
| 27 | #include "debug-info.h" |
| 28 | #include "trace-ir-data-copy.h" |
| 29 | #include "trace-ir-mapping.h" |
| 30 | #include "trace-ir-metadata-copy.h" |
| 31 | #include "utils.h" |
| 32 | #include "plugins/common/param-validation/param-validation.h" |
| 33 | |
| 34 | #define DEFAULT_DEBUG_INFO_FIELD_NAME "debug_info" |
| 35 | #define LTTNG_UST_STATEDUMP_PREFIX "lttng_ust" |
| 36 | |
| 37 | struct debug_info_component { |
| 38 | bt_logging_level log_level; |
| 39 | bt_self_component *self_comp; |
| 40 | bt_self_component_filter *self_comp_filter; |
| 41 | gchar *arg_debug_dir; |
| 42 | gchar *arg_debug_info_field_name; |
| 43 | gchar *arg_target_prefix; |
| 44 | bt_bool arg_full_path; |
| 45 | }; |
| 46 | |
| 47 | struct debug_info_msg_iter { |
| 48 | bt_logging_level log_level; |
| 49 | struct debug_info_component *debug_info_component; |
| 50 | bt_self_message_iterator *input_iterator; |
| 51 | bt_self_component *self_comp; |
| 52 | bt_message_iterator *msg_iter; |
| 53 | |
| 54 | struct trace_ir_maps *ir_maps; |
| 55 | /* in_trace -> debug_info_mapping. */ |
| 56 | GHashTable *debug_info_map; |
| 57 | |
| 58 | struct bt_fd_cache fd_cache; |
| 59 | }; |
| 60 | |
| 61 | struct debug_info_source { |
| 62 | /* Strings are owned by debug_info_source. */ |
| 63 | gchar *func; |
| 64 | /* |
| 65 | * Store the line number as a string so that the allocation and |
| 66 | * conversion to string is only done once. |
| 67 | */ |
| 68 | gchar *line_no; |
| 69 | gchar *src_path; |
| 70 | /* short_src_path points inside src_path, no need to free. */ |
| 71 | const gchar *short_src_path; |
| 72 | gchar *bin_path; |
| 73 | /* short_bin_path points inside bin_path, no need to free. */ |
| 74 | const gchar *short_bin_path; |
| 75 | /* |
| 76 | * Location within the binary. Either absolute (@0x1234) or |
| 77 | * relative (+0x4321). |
| 78 | */ |
| 79 | gchar *bin_loc; |
| 80 | }; |
| 81 | |
| 82 | struct proc_debug_info_sources { |
| 83 | /* |
| 84 | * Hash table: base address (pointer to uint64_t) to bin info; owned by |
| 85 | * proc_debug_info_sources. |
| 86 | */ |
| 87 | GHashTable *baddr_to_bin_info; |
| 88 | |
| 89 | /* |
| 90 | * Hash table: IP (pointer to uint64_t) to (struct debug_info_source *); |
| 91 | * owned by proc_debug_info_sources. |
| 92 | */ |
| 93 | GHashTable *ip_to_debug_info_src; |
| 94 | }; |
| 95 | |
| 96 | struct debug_info { |
| 97 | bt_logging_level log_level; |
| 98 | bt_self_component *self_comp; |
| 99 | struct debug_info_component *comp; |
| 100 | const bt_trace *input_trace; |
| 101 | bt_listener_id destruction_listener_id; |
| 102 | |
| 103 | /* |
| 104 | * Hash table of VPIDs (pointer to int64_t) to |
| 105 | * (struct proc_debug_info_sources*); owned by debug_info. |
| 106 | */ |
| 107 | GHashTable *vpid_to_proc_dbg_info_src; |
| 108 | GQuark q_statedump_bin_info; |
| 109 | GQuark q_statedump_debug_link; |
| 110 | GQuark q_statedump_build_id; |
| 111 | GQuark q_statedump_start; |
| 112 | GQuark q_dl_open; |
| 113 | GQuark q_lib_load; |
| 114 | GQuark q_lib_unload; |
| 115 | struct bt_fd_cache *fd_cache; /* Weak ref. Owned by the iterator. */ |
| 116 | }; |
| 117 | |
| 118 | static |
| 119 | int debug_info_init(struct debug_info *info) |
| 120 | { |
| 121 | info->q_statedump_bin_info = g_quark_from_string( |
| 122 | "lttng_ust_statedump:bin_info"); |
| 123 | info->q_statedump_debug_link = g_quark_from_string( |
| 124 | "lttng_ust_statedump:debug_link"); |
| 125 | info->q_statedump_build_id = g_quark_from_string( |
| 126 | "lttng_ust_statedump:build_id"); |
| 127 | info->q_statedump_start = g_quark_from_string( |
| 128 | "lttng_ust_statedump:start"); |
| 129 | info->q_dl_open = g_quark_from_string("lttng_ust_dl:dlopen"); |
| 130 | info->q_lib_load = g_quark_from_string("lttng_ust_lib:load"); |
| 131 | info->q_lib_unload = g_quark_from_string("lttng_ust_lib:unload"); |
| 132 | |
| 133 | return bin_info_init(info->log_level, info->self_comp); |
| 134 | } |
| 135 | |
| 136 | static |
| 137 | void debug_info_source_destroy(struct debug_info_source *debug_info_src) |
| 138 | { |
| 139 | if (!debug_info_src) { |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | g_free(debug_info_src->func); |
| 144 | g_free(debug_info_src->line_no); |
| 145 | g_free(debug_info_src->src_path); |
| 146 | g_free(debug_info_src->bin_path); |
| 147 | g_free(debug_info_src->bin_loc); |
| 148 | g_free(debug_info_src); |
| 149 | } |
| 150 | |
| 151 | static |
| 152 | struct debug_info_source *debug_info_source_create_from_bin( |
| 153 | struct bin_info *bin, uint64_t ip, |
| 154 | bt_self_component *self_comp) |
| 155 | { |
| 156 | int ret; |
| 157 | struct debug_info_source *debug_info_src = NULL; |
| 158 | struct source_location *src_loc = NULL; |
| 159 | bt_logging_level log_level; |
| 160 | |
| 161 | BT_ASSERT(bin); |
| 162 | |
| 163 | log_level = bin->log_level; |
| 164 | |
| 165 | debug_info_src = g_new0(struct debug_info_source, 1); |
| 166 | |
| 167 | if (!debug_info_src) { |
| 168 | goto end; |
| 169 | } |
| 170 | |
| 171 | /* Lookup function name */ |
| 172 | ret = bin_info_lookup_function_name(bin, ip, &debug_info_src->func); |
| 173 | if (ret) { |
| 174 | goto error; |
| 175 | } |
| 176 | |
| 177 | /* Can't retrieve src_loc from ELF, or could not find binary, skip. */ |
| 178 | if (!bin->is_elf_only || !debug_info_src->func) { |
| 179 | /* Lookup source location */ |
| 180 | ret = bin_info_lookup_source_location(bin, ip, &src_loc); |
| 181 | if (ret) { |
| 182 | BT_COMP_LOGI("Failed to lookup source location: ret=%d", ret); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | if (src_loc) { |
| 187 | debug_info_src->line_no = |
| 188 | g_strdup_printf("%"PRId64, src_loc->line_no); |
| 189 | if (!debug_info_src->line_no) { |
| 190 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 191 | "Error occurred when setting `line_no` field."); |
| 192 | goto error; |
| 193 | } |
| 194 | |
| 195 | if (src_loc->filename) { |
| 196 | debug_info_src->src_path = g_strdup(src_loc->filename); |
| 197 | if (!debug_info_src->src_path) { |
| 198 | goto error; |
| 199 | } |
| 200 | |
| 201 | debug_info_src->short_src_path = get_filename_from_path( |
| 202 | debug_info_src->src_path); |
| 203 | } |
| 204 | source_location_destroy(src_loc); |
| 205 | } |
| 206 | |
| 207 | if (bin->elf_path) { |
| 208 | debug_info_src->bin_path = g_strdup(bin->elf_path); |
| 209 | if (!debug_info_src->bin_path) { |
| 210 | goto error; |
| 211 | } |
| 212 | |
| 213 | debug_info_src->short_bin_path = get_filename_from_path( |
| 214 | debug_info_src->bin_path); |
| 215 | |
| 216 | ret = bin_info_get_bin_loc(bin, ip, &(debug_info_src->bin_loc)); |
| 217 | if (ret) { |
| 218 | goto error; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | end: |
| 223 | return debug_info_src; |
| 224 | |
| 225 | error: |
| 226 | debug_info_source_destroy(debug_info_src); |
| 227 | return NULL; |
| 228 | } |
| 229 | |
| 230 | static |
| 231 | void proc_debug_info_sources_destroy( |
| 232 | struct proc_debug_info_sources *proc_dbg_info_src) |
| 233 | { |
| 234 | if (!proc_dbg_info_src) { |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | if (proc_dbg_info_src->baddr_to_bin_info) { |
| 239 | g_hash_table_destroy(proc_dbg_info_src->baddr_to_bin_info); |
| 240 | } |
| 241 | |
| 242 | if (proc_dbg_info_src->ip_to_debug_info_src) { |
| 243 | g_hash_table_destroy(proc_dbg_info_src->ip_to_debug_info_src); |
| 244 | } |
| 245 | |
| 246 | g_free(proc_dbg_info_src); |
| 247 | } |
| 248 | |
| 249 | static |
| 250 | struct proc_debug_info_sources *proc_debug_info_sources_create(void) |
| 251 | { |
| 252 | struct proc_debug_info_sources *proc_dbg_info_src = NULL; |
| 253 | |
| 254 | proc_dbg_info_src = g_new0(struct proc_debug_info_sources, 1); |
| 255 | if (!proc_dbg_info_src) { |
| 256 | goto end; |
| 257 | } |
| 258 | |
| 259 | proc_dbg_info_src->baddr_to_bin_info = g_hash_table_new_full( |
| 260 | g_int64_hash, g_int64_equal, (GDestroyNotify) g_free, |
| 261 | (GDestroyNotify) bin_info_destroy); |
| 262 | if (!proc_dbg_info_src->baddr_to_bin_info) { |
| 263 | goto error; |
| 264 | } |
| 265 | |
| 266 | proc_dbg_info_src->ip_to_debug_info_src = g_hash_table_new_full( |
| 267 | g_int64_hash, g_int64_equal, (GDestroyNotify) g_free, |
| 268 | (GDestroyNotify) debug_info_source_destroy); |
| 269 | if (!proc_dbg_info_src->ip_to_debug_info_src) { |
| 270 | goto error; |
| 271 | } |
| 272 | |
| 273 | end: |
| 274 | return proc_dbg_info_src; |
| 275 | |
| 276 | error: |
| 277 | proc_debug_info_sources_destroy(proc_dbg_info_src); |
| 278 | return NULL; |
| 279 | } |
| 280 | |
| 281 | static |
| 282 | struct proc_debug_info_sources *proc_debug_info_sources_ht_get_entry( |
| 283 | GHashTable *ht, int64_t vpid) |
| 284 | { |
| 285 | gpointer key = g_new0(int64_t, 1); |
| 286 | struct proc_debug_info_sources *proc_dbg_info_src = NULL; |
| 287 | |
| 288 | if (!key) { |
| 289 | goto end; |
| 290 | } |
| 291 | |
| 292 | *((int64_t *) key) = vpid; |
| 293 | |
| 294 | /* Exists? Return it */ |
| 295 | proc_dbg_info_src = g_hash_table_lookup(ht, key); |
| 296 | if (proc_dbg_info_src) { |
| 297 | goto end; |
| 298 | } |
| 299 | |
| 300 | /* Otherwise, create and return it */ |
| 301 | proc_dbg_info_src = proc_debug_info_sources_create(); |
| 302 | if (!proc_dbg_info_src) { |
| 303 | goto end; |
| 304 | } |
| 305 | |
| 306 | g_hash_table_insert(ht, key, proc_dbg_info_src); |
| 307 | /* Ownership passed to ht */ |
| 308 | key = NULL; |
| 309 | end: |
| 310 | g_free(key); |
| 311 | return proc_dbg_info_src; |
| 312 | } |
| 313 | |
| 314 | static inline |
| 315 | const bt_field *event_borrow_payload_field(const bt_event *event, |
| 316 | const char *field_name) |
| 317 | { |
| 318 | const bt_field *event_payload, *field; |
| 319 | |
| 320 | event_payload = bt_event_borrow_payload_field_const(event); |
| 321 | BT_ASSERT_DBG(event_payload); |
| 322 | |
| 323 | field = bt_field_structure_borrow_member_field_by_name_const( |
| 324 | event_payload, field_name); |
| 325 | return field; |
| 326 | } |
| 327 | |
| 328 | static inline |
| 329 | const bt_field *event_borrow_common_context_field(const bt_event *event, |
| 330 | const char *field_name) |
| 331 | { |
| 332 | const bt_field *event_common_ctx, *field = NULL; |
| 333 | |
| 334 | event_common_ctx = bt_event_borrow_common_context_field_const(event); |
| 335 | if (!event_common_ctx) { |
| 336 | goto end; |
| 337 | } |
| 338 | |
| 339 | field = bt_field_structure_borrow_member_field_by_name_const( |
| 340 | event_common_ctx, field_name); |
| 341 | |
| 342 | end: |
| 343 | return field; |
| 344 | } |
| 345 | |
| 346 | static inline |
| 347 | void event_get_common_context_signed_integer_field_value( |
| 348 | const bt_event *event, const char *field_name, int64_t *value) |
| 349 | { |
| 350 | *value = bt_field_integer_signed_get_value( |
| 351 | event_borrow_common_context_field(event, field_name)); |
| 352 | } |
| 353 | |
| 354 | static inline |
| 355 | void event_get_payload_build_id_length(const bt_event *event, |
| 356 | const char *field_name, uint64_t *build_id_len) |
| 357 | { |
| 358 | const bt_field *build_id_field; |
| 359 | const bt_field_class *build_id_field_class; |
| 360 | |
| 361 | build_id_field = event_borrow_payload_field(event, field_name); |
| 362 | build_id_field_class = bt_field_borrow_class_const(build_id_field); |
| 363 | |
| 364 | BT_ASSERT(bt_field_class_get_type(build_id_field_class) == |
| 365 | BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD || |
| 366 | bt_field_class_get_type(build_id_field_class) == |
| 367 | BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD); |
| 368 | BT_ASSERT(bt_field_class_get_type( |
| 369 | bt_field_class_array_borrow_element_field_class_const( |
| 370 | build_id_field_class)) == |
| 371 | BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER); |
| 372 | |
| 373 | *build_id_len = bt_field_array_get_length(build_id_field); |
| 374 | } |
| 375 | |
| 376 | static inline |
| 377 | void event_get_payload_build_id_value(const bt_event *event, |
| 378 | const char *field_name, uint8_t *build_id) |
| 379 | { |
| 380 | const bt_field *curr_field, *build_id_field; |
| 381 | const bt_field_class *build_id_field_class; |
| 382 | uint64_t i, build_id_len; |
| 383 | |
| 384 | build_id_field = event_borrow_payload_field(event, field_name); |
| 385 | build_id_field_class = bt_field_borrow_class_const(build_id_field); |
| 386 | |
| 387 | BT_ASSERT(bt_field_class_get_type(build_id_field_class) == |
| 388 | BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD || |
| 389 | bt_field_class_get_type(build_id_field_class) == |
| 390 | BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD); |
| 391 | BT_ASSERT(bt_field_class_get_type( |
| 392 | bt_field_class_array_borrow_element_field_class_const( |
| 393 | build_id_field_class)) == |
| 394 | BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER); |
| 395 | |
| 396 | build_id_len = bt_field_array_get_length(build_id_field); |
| 397 | |
| 398 | for (i = 0; i < build_id_len; i++) { |
| 399 | curr_field = bt_field_array_borrow_element_field_by_index_const( |
| 400 | build_id_field, i); |
| 401 | |
| 402 | build_id[i] = bt_field_integer_unsigned_get_value(curr_field); |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | static |
| 407 | void event_get_payload_unsigned_integer_field_value(const bt_event *event, |
| 408 | const char *field_name, uint64_t *value) |
| 409 | { |
| 410 | *value = bt_field_integer_unsigned_get_value( |
| 411 | event_borrow_payload_field(event, field_name)); |
| 412 | } |
| 413 | |
| 414 | static |
| 415 | void event_get_payload_string_field_value(const bt_event *event, |
| 416 | const char *field_name, const char **value) |
| 417 | { |
| 418 | *value = bt_field_string_get_value( |
| 419 | event_borrow_payload_field(event, field_name)); |
| 420 | } |
| 421 | |
| 422 | static inline |
| 423 | bool event_has_payload_field(const bt_event *event, |
| 424 | const char *field_name) |
| 425 | { |
| 426 | return event_borrow_payload_field(event, field_name); |
| 427 | } |
| 428 | |
| 429 | static |
| 430 | struct debug_info_source *proc_debug_info_sources_get_entry( |
| 431 | struct debug_info *debug_info, |
| 432 | struct proc_debug_info_sources *proc_dbg_info_src, uint64_t ip) |
| 433 | { |
| 434 | struct debug_info_source *debug_info_src = NULL; |
| 435 | gpointer key = g_new0(uint64_t, 1); |
| 436 | GHashTableIter iter; |
| 437 | gpointer baddr, value; |
| 438 | |
| 439 | if (!key) { |
| 440 | goto end; |
| 441 | } |
| 442 | |
| 443 | *((uint64_t *) key) = ip; |
| 444 | |
| 445 | /* Look in IP to debug infos hash table first. */ |
| 446 | debug_info_src = g_hash_table_lookup( |
| 447 | proc_dbg_info_src->ip_to_debug_info_src, key); |
| 448 | if (debug_info_src) { |
| 449 | goto end; |
| 450 | } |
| 451 | |
| 452 | /* Check in all bin_infos. */ |
| 453 | g_hash_table_iter_init(&iter, proc_dbg_info_src->baddr_to_bin_info); |
| 454 | |
| 455 | while (g_hash_table_iter_next(&iter, &baddr, &value)) |
| 456 | { |
| 457 | struct bin_info *bin = value; |
| 458 | |
| 459 | if (!bin_info_has_address(value, ip)) { |
| 460 | continue; |
| 461 | } |
| 462 | |
| 463 | /* |
| 464 | * Found; add it to cache. |
| 465 | * |
| 466 | * FIXME: this should be bounded in size (and implement |
| 467 | * a caching policy), and entries should be prunned when |
| 468 | * libraries are unmapped. |
| 469 | */ |
| 470 | debug_info_src = debug_info_source_create_from_bin(bin, ip, |
| 471 | debug_info->self_comp); |
| 472 | if (debug_info_src) { |
| 473 | g_hash_table_insert( |
| 474 | proc_dbg_info_src->ip_to_debug_info_src, key, |
| 475 | debug_info_src); |
| 476 | /* Ownership passed to ht. */ |
| 477 | key = NULL; |
| 478 | } |
| 479 | break; |
| 480 | } |
| 481 | |
| 482 | end: |
| 483 | free(key); |
| 484 | return debug_info_src; |
| 485 | } |
| 486 | |
| 487 | static |
| 488 | struct debug_info_source *debug_info_query(struct debug_info *debug_info, |
| 489 | int64_t vpid, uint64_t ip) |
| 490 | { |
| 491 | struct debug_info_source *dbg_info_src = NULL; |
| 492 | struct proc_debug_info_sources *proc_dbg_info_src; |
| 493 | |
| 494 | proc_dbg_info_src = proc_debug_info_sources_ht_get_entry( |
| 495 | debug_info->vpid_to_proc_dbg_info_src, vpid); |
| 496 | if (!proc_dbg_info_src) { |
| 497 | goto end; |
| 498 | } |
| 499 | |
| 500 | dbg_info_src = proc_debug_info_sources_get_entry(debug_info, |
| 501 | proc_dbg_info_src, ip); |
| 502 | |
| 503 | end: |
| 504 | return dbg_info_src; |
| 505 | } |
| 506 | |
| 507 | static |
| 508 | struct debug_info *debug_info_create(struct debug_info_component *comp, |
| 509 | const bt_trace *trace, struct bt_fd_cache *fdc) |
| 510 | { |
| 511 | int ret; |
| 512 | struct debug_info *debug_info; |
| 513 | |
| 514 | BT_ASSERT(comp); |
| 515 | BT_ASSERT(trace); |
| 516 | BT_ASSERT(fdc); |
| 517 | |
| 518 | debug_info = g_new0(struct debug_info, 1); |
| 519 | if (!debug_info) { |
| 520 | goto end; |
| 521 | } |
| 522 | |
| 523 | debug_info->log_level = comp->log_level; |
| 524 | debug_info->self_comp = comp->self_comp; |
| 525 | debug_info->vpid_to_proc_dbg_info_src = g_hash_table_new_full( |
| 526 | g_int64_hash, g_int64_equal, (GDestroyNotify) g_free, |
| 527 | (GDestroyNotify) proc_debug_info_sources_destroy); |
| 528 | if (!debug_info->vpid_to_proc_dbg_info_src) { |
| 529 | goto error; |
| 530 | } |
| 531 | |
| 532 | debug_info->comp = comp; |
| 533 | ret = debug_info_init(debug_info); |
| 534 | if (ret) { |
| 535 | goto error; |
| 536 | } |
| 537 | |
| 538 | debug_info->input_trace = trace; |
| 539 | debug_info->fd_cache = fdc; |
| 540 | |
| 541 | end: |
| 542 | return debug_info; |
| 543 | error: |
| 544 | g_free(debug_info); |
| 545 | return NULL; |
| 546 | } |
| 547 | |
| 548 | static |
| 549 | void debug_info_destroy(struct debug_info *debug_info) |
| 550 | { |
| 551 | bt_logging_level log_level; |
| 552 | bt_self_component *self_comp; |
| 553 | bt_trace_remove_listener_status remove_listener_status; |
| 554 | if (!debug_info) { |
| 555 | goto end; |
| 556 | } |
| 557 | |
| 558 | log_level = debug_info->log_level; |
| 559 | self_comp = debug_info->self_comp; |
| 560 | |
| 561 | if (debug_info->vpid_to_proc_dbg_info_src) { |
| 562 | g_hash_table_destroy(debug_info->vpid_to_proc_dbg_info_src); |
| 563 | } |
| 564 | |
| 565 | remove_listener_status = bt_trace_remove_destruction_listener( |
| 566 | debug_info->input_trace, |
| 567 | debug_info->destruction_listener_id); |
| 568 | if (remove_listener_status != BT_TRACE_REMOVE_LISTENER_STATUS_OK) { |
| 569 | BT_COMP_LOGE("Trace destruction listener removal failed."); |
| 570 | bt_current_thread_clear_error(); |
| 571 | } |
| 572 | |
| 573 | g_free(debug_info); |
| 574 | end: |
| 575 | return; |
| 576 | } |
| 577 | |
| 578 | static |
| 579 | void handle_event_statedump_build_id(struct debug_info *debug_info, |
| 580 | const bt_event *event) |
| 581 | { |
| 582 | struct proc_debug_info_sources *proc_dbg_info_src; |
| 583 | uint64_t build_id_len, baddr; |
| 584 | uint8_t *build_id = NULL; |
| 585 | struct bin_info *bin; |
| 586 | int64_t vpid; |
| 587 | int ret = 0; |
| 588 | |
| 589 | event_get_common_context_signed_integer_field_value(event, |
| 590 | VPID_FIELD_NAME, &vpid); |
| 591 | event_get_payload_unsigned_integer_field_value(event, |
| 592 | BADDR_FIELD_NAME, &baddr); |
| 593 | |
| 594 | proc_dbg_info_src = proc_debug_info_sources_ht_get_entry( |
| 595 | debug_info->vpid_to_proc_dbg_info_src, vpid); |
| 596 | if (!proc_dbg_info_src) { |
| 597 | goto end; |
| 598 | } |
| 599 | |
| 600 | bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info, |
| 601 | (gpointer) &baddr); |
| 602 | if (!bin) { |
| 603 | /* |
| 604 | * The build_id event comes after the bin has been |
| 605 | * created. If it isn't found, just ignore this event. |
| 606 | */ |
| 607 | goto end; |
| 608 | } |
| 609 | |
| 610 | event_get_payload_build_id_length(event, BUILD_ID_FIELD_NAME, |
| 611 | &build_id_len); |
| 612 | |
| 613 | build_id = g_new0(uint8_t, build_id_len); |
| 614 | if (!build_id) { |
| 615 | goto end; |
| 616 | } |
| 617 | |
| 618 | event_get_payload_build_id_value(event, BUILD_ID_FIELD_NAME, build_id); |
| 619 | |
| 620 | ret = bin_info_set_build_id(bin, build_id, build_id_len); |
| 621 | if (ret) { |
| 622 | goto end; |
| 623 | } |
| 624 | |
| 625 | /* |
| 626 | * Reset the is_elf_only flag in case it had been set |
| 627 | * previously, because we might find separate debug info using |
| 628 | * the new build id information. |
| 629 | */ |
| 630 | bin->is_elf_only = false; |
| 631 | |
| 632 | end: |
| 633 | g_free(build_id); |
| 634 | return; |
| 635 | } |
| 636 | |
| 637 | static |
| 638 | void handle_event_statedump_debug_link(struct debug_info *debug_info, |
| 639 | const bt_event *event) |
| 640 | { |
| 641 | struct proc_debug_info_sources *proc_dbg_info_src; |
| 642 | struct bin_info *bin = NULL; |
| 643 | int64_t vpid; |
| 644 | uint64_t baddr; |
| 645 | const char *filename = NULL; |
| 646 | uint32_t crc32; |
| 647 | uint64_t crc_field_value; |
| 648 | |
| 649 | event_get_common_context_signed_integer_field_value(event, |
| 650 | VPID_FIELD_NAME, &vpid); |
| 651 | |
| 652 | event_get_payload_unsigned_integer_field_value(event, |
| 653 | BADDR_FIELD_NAME, &baddr); |
| 654 | |
| 655 | event_get_payload_unsigned_integer_field_value(event, |
| 656 | CRC32_FIELD_NAME, &crc_field_value); |
| 657 | |
| 658 | crc32 = (uint32_t) crc_field_value; |
| 659 | |
| 660 | event_get_payload_string_field_value(event, |
| 661 | FILENAME_FIELD_NAME, &filename); |
| 662 | |
| 663 | proc_dbg_info_src = proc_debug_info_sources_ht_get_entry( |
| 664 | debug_info->vpid_to_proc_dbg_info_src, vpid); |
| 665 | if (!proc_dbg_info_src) { |
| 666 | goto end; |
| 667 | } |
| 668 | |
| 669 | bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info, |
| 670 | (gpointer) &baddr); |
| 671 | if (!bin) { |
| 672 | /* |
| 673 | * The debug_link event comes after the bin has been |
| 674 | * created. If it isn't found, just ignore this event. |
| 675 | */ |
| 676 | goto end; |
| 677 | } |
| 678 | |
| 679 | bin_info_set_debug_link(bin, filename, crc32); |
| 680 | |
| 681 | end: |
| 682 | return; |
| 683 | } |
| 684 | |
| 685 | static |
| 686 | void handle_bin_info_event(struct debug_info *debug_info, |
| 687 | const bt_event *event, bool has_pic_field) |
| 688 | { |
| 689 | struct proc_debug_info_sources *proc_dbg_info_src; |
| 690 | struct bin_info *bin; |
| 691 | uint64_t baddr, memsz; |
| 692 | int64_t vpid; |
| 693 | const char *path; |
| 694 | gpointer key = NULL; |
| 695 | bool is_pic; |
| 696 | |
| 697 | event_get_payload_unsigned_integer_field_value(event, |
| 698 | MEMSZ_FIELD_NAME, &memsz); |
| 699 | if (memsz == 0) { |
| 700 | /* Ignore VDSO. */ |
| 701 | goto end; |
| 702 | } |
| 703 | |
| 704 | event_get_payload_unsigned_integer_field_value(event, |
| 705 | BADDR_FIELD_NAME, &baddr); |
| 706 | |
| 707 | /* |
| 708 | * This field is not produced by the dlopen event emitted before |
| 709 | * lttng-ust 2.9. |
| 710 | */ |
| 711 | if (!event_has_payload_field(event, PATH_FIELD_NAME)) { |
| 712 | goto end; |
| 713 | } |
| 714 | event_get_payload_string_field_value(event, PATH_FIELD_NAME, &path); |
| 715 | |
| 716 | if (has_pic_field) { |
| 717 | uint64_t is_pic_field_value; |
| 718 | |
| 719 | event_get_payload_unsigned_integer_field_value(event, |
| 720 | IS_PIC_FIELD_NAME, &is_pic_field_value); |
| 721 | is_pic = is_pic_field_value == 1; |
| 722 | } else { |
| 723 | /* |
| 724 | * dlopen has no is_pic field, because the shared |
| 725 | * object is always PIC. |
| 726 | */ |
| 727 | is_pic = true; |
| 728 | } |
| 729 | |
| 730 | event_get_common_context_signed_integer_field_value(event, |
| 731 | VPID_FIELD_NAME, &vpid); |
| 732 | |
| 733 | proc_dbg_info_src = proc_debug_info_sources_ht_get_entry( |
| 734 | debug_info->vpid_to_proc_dbg_info_src, vpid); |
| 735 | if (!proc_dbg_info_src) { |
| 736 | goto end; |
| 737 | } |
| 738 | |
| 739 | key = g_new0(uint64_t, 1); |
| 740 | if (!key) { |
| 741 | goto end; |
| 742 | } |
| 743 | |
| 744 | *((uint64_t *) key) = baddr; |
| 745 | |
| 746 | bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info, key); |
| 747 | if (bin) { |
| 748 | goto end; |
| 749 | } |
| 750 | |
| 751 | bin = bin_info_create(debug_info->fd_cache, path, baddr, memsz, is_pic, |
| 752 | debug_info->comp->arg_debug_dir, |
| 753 | debug_info->comp->arg_target_prefix, |
| 754 | debug_info->log_level, debug_info->self_comp); |
| 755 | if (!bin) { |
| 756 | goto end; |
| 757 | } |
| 758 | |
| 759 | g_hash_table_insert(proc_dbg_info_src->baddr_to_bin_info, key, bin); |
| 760 | /* Ownership passed to ht. */ |
| 761 | key = NULL; |
| 762 | |
| 763 | end: |
| 764 | g_free(key); |
| 765 | return; |
| 766 | } |
| 767 | |
| 768 | static inline |
| 769 | void handle_event_statedump_bin_info(struct debug_info *debug_info, |
| 770 | const bt_event *event) |
| 771 | { |
| 772 | handle_bin_info_event(debug_info, event, true); |
| 773 | } |
| 774 | |
| 775 | static inline |
| 776 | void handle_event_lib_load(struct debug_info *debug_info, |
| 777 | const bt_event *event) |
| 778 | { |
| 779 | handle_bin_info_event(debug_info, event, false); |
| 780 | } |
| 781 | |
| 782 | static |
| 783 | void handle_event_lib_unload(struct debug_info *debug_info, |
| 784 | const bt_event *event) |
| 785 | { |
| 786 | gboolean ret; |
| 787 | struct proc_debug_info_sources *proc_dbg_info_src; |
| 788 | uint64_t baddr; |
| 789 | int64_t vpid; |
| 790 | |
| 791 | event_get_payload_unsigned_integer_field_value(event, BADDR_FIELD_NAME, |
| 792 | &baddr); |
| 793 | |
| 794 | event_get_common_context_signed_integer_field_value(event, |
| 795 | VPID_FIELD_NAME, &vpid); |
| 796 | |
| 797 | proc_dbg_info_src = proc_debug_info_sources_ht_get_entry( |
| 798 | debug_info->vpid_to_proc_dbg_info_src, vpid); |
| 799 | if (!proc_dbg_info_src) { |
| 800 | /* |
| 801 | * It's an unload event for a library for which no load event |
| 802 | * was previously received. |
| 803 | */ |
| 804 | goto end; |
| 805 | } |
| 806 | |
| 807 | ret = g_hash_table_remove(proc_dbg_info_src->baddr_to_bin_info, |
| 808 | (gpointer) &baddr); |
| 809 | BT_ASSERT(ret); |
| 810 | end: |
| 811 | return; |
| 812 | } |
| 813 | |
| 814 | static |
| 815 | void handle_event_statedump_start(struct debug_info *debug_info, |
| 816 | const bt_event *event) |
| 817 | { |
| 818 | struct proc_debug_info_sources *proc_dbg_info_src; |
| 819 | int64_t vpid; |
| 820 | |
| 821 | event_get_common_context_signed_integer_field_value( |
| 822 | event, VPID_FIELD_NAME, &vpid); |
| 823 | |
| 824 | proc_dbg_info_src = proc_debug_info_sources_ht_get_entry( |
| 825 | debug_info->vpid_to_proc_dbg_info_src, vpid); |
| 826 | if (!proc_dbg_info_src) { |
| 827 | goto end; |
| 828 | } |
| 829 | |
| 830 | g_hash_table_remove_all(proc_dbg_info_src->baddr_to_bin_info); |
| 831 | g_hash_table_remove_all(proc_dbg_info_src->ip_to_debug_info_src); |
| 832 | |
| 833 | end: |
| 834 | return; |
| 835 | } |
| 836 | |
| 837 | static |
| 838 | void trace_debug_info_remove_func(const bt_trace *in_trace, void *data) |
| 839 | { |
| 840 | struct debug_info_msg_iter *debug_it = data; |
| 841 | if (debug_it->debug_info_map) { |
| 842 | gboolean ret; |
| 843 | ret = g_hash_table_remove(debug_it->debug_info_map, |
| 844 | (gpointer) in_trace); |
| 845 | BT_ASSERT(ret); |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | static |
| 850 | void handle_event_statedump(struct debug_info_msg_iter *debug_it, |
| 851 | const bt_event *event) |
| 852 | { |
| 853 | const bt_event_class *event_class; |
| 854 | const char *event_name; |
| 855 | GQuark q_event_name; |
| 856 | const bt_trace *trace; |
| 857 | struct debug_info *debug_info; |
| 858 | |
| 859 | BT_ASSERT(debug_it); |
| 860 | BT_ASSERT(event); |
| 861 | |
| 862 | event_class = bt_event_borrow_class_const(event); |
| 863 | |
| 864 | event_name = bt_event_class_get_name(event_class); |
| 865 | |
| 866 | trace = bt_stream_borrow_trace_const( |
| 867 | bt_event_borrow_stream_const(event)); |
| 868 | |
| 869 | debug_info = g_hash_table_lookup(debug_it->debug_info_map, trace); |
| 870 | if (!debug_info) { |
| 871 | bt_trace_add_listener_status add_listener_status; |
| 872 | |
| 873 | debug_info = debug_info_create(debug_it->debug_info_component, |
| 874 | trace, &debug_it->fd_cache); |
| 875 | g_hash_table_insert(debug_it->debug_info_map, (gpointer) trace, |
| 876 | debug_info); |
| 877 | add_listener_status = bt_trace_add_destruction_listener( |
| 878 | trace, trace_debug_info_remove_func, debug_it, |
| 879 | &debug_info->destruction_listener_id); |
| 880 | BT_ASSERT(add_listener_status == BT_TRACE_ADD_LISTENER_STATUS_OK); |
| 881 | } |
| 882 | |
| 883 | q_event_name = g_quark_try_string(event_name); |
| 884 | |
| 885 | if (q_event_name == debug_info->q_statedump_bin_info) { |
| 886 | /* State dump */ |
| 887 | handle_event_statedump_bin_info(debug_info, event); |
| 888 | } else if (q_event_name == debug_info->q_dl_open || |
| 889 | q_event_name == debug_info->q_lib_load) { |
| 890 | /* |
| 891 | * dl_open and lib_load events are both checked for since |
| 892 | * only dl_open was produced as of lttng-ust 2.8. |
| 893 | * |
| 894 | * lib_load, which is produced from lttng-ust 2.9+, is a lot |
| 895 | * more reliable since it will be emitted when other functions |
| 896 | * of the dlopen family are called (e.g. dlmopen) and when |
| 897 | * library are transitively loaded. |
| 898 | */ |
| 899 | handle_event_lib_load(debug_info, event); |
| 900 | } else if (q_event_name == debug_info->q_statedump_start) { |
| 901 | /* Start state dump */ |
| 902 | handle_event_statedump_start(debug_info, event); |
| 903 | } else if (q_event_name == debug_info->q_statedump_debug_link) { |
| 904 | /* Debug link info */ |
| 905 | handle_event_statedump_debug_link(debug_info, event); |
| 906 | } else if (q_event_name == debug_info->q_statedump_build_id) { |
| 907 | /* Build ID info */ |
| 908 | handle_event_statedump_build_id(debug_info, event); |
| 909 | } else if (q_event_name == debug_info->q_lib_unload) { |
| 910 | handle_event_lib_unload(debug_info, event); |
| 911 | } |
| 912 | |
| 913 | return; |
| 914 | } |
| 915 | |
| 916 | static |
| 917 | void destroy_debug_info_comp(struct debug_info_component *debug_info) |
| 918 | { |
| 919 | if (!debug_info) { |
| 920 | return; |
| 921 | } |
| 922 | |
| 923 | g_free(debug_info->arg_debug_dir); |
| 924 | g_free(debug_info->arg_debug_info_field_name); |
| 925 | g_free(debug_info->arg_target_prefix); |
| 926 | g_free(debug_info); |
| 927 | } |
| 928 | |
| 929 | static |
| 930 | void fill_debug_info_bin_field(struct debug_info_source *dbg_info_src, |
| 931 | bool full_path, bt_field *curr_field, |
| 932 | bt_logging_level log_level, bt_self_component *self_comp) |
| 933 | { |
| 934 | bt_field_string_set_value_status set_status; |
| 935 | bt_field_string_append_status append_status; |
| 936 | |
| 937 | BT_ASSERT_DBG(bt_field_get_class_type(curr_field) == |
| 938 | BT_FIELD_CLASS_TYPE_STRING); |
| 939 | |
| 940 | if (dbg_info_src) { |
| 941 | if (full_path) { |
| 942 | set_status = bt_field_string_set_value(curr_field, |
| 943 | dbg_info_src->bin_path); |
| 944 | } else { |
| 945 | set_status = bt_field_string_set_value(curr_field, |
| 946 | dbg_info_src->short_bin_path); |
| 947 | } |
| 948 | if (set_status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { |
| 949 | BT_COMP_LOGE("Cannot set path component of `bin` " |
| 950 | "curr_field field's value: str-fc-addr=%p", |
| 951 | curr_field); |
| 952 | bt_current_thread_clear_error(); |
| 953 | } |
| 954 | |
| 955 | append_status = bt_field_string_append(curr_field, |
| 956 | dbg_info_src->bin_loc); |
| 957 | if (append_status != BT_FIELD_STRING_APPEND_STATUS_OK) { |
| 958 | BT_COMP_LOGE("Cannot set bin location component of `bin` " |
| 959 | "curr_field field's value: str-fc-addr=%p", |
| 960 | curr_field); |
| 961 | bt_current_thread_clear_error(); |
| 962 | } |
| 963 | } else { |
| 964 | set_status = bt_field_string_set_value(curr_field, ""); |
| 965 | if (set_status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { |
| 966 | BT_COMP_LOGE("Cannot set `bin` curr_field field's value: " |
| 967 | "str-fc-addr=%p", curr_field); |
| 968 | bt_current_thread_clear_error(); |
| 969 | } |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | static |
| 974 | void fill_debug_info_func_field(struct debug_info_source *dbg_info_src, |
| 975 | bt_field *curr_field, bt_logging_level log_level, |
| 976 | bt_self_component *self_comp) |
| 977 | { |
| 978 | bt_field_string_set_value_status status; |
| 979 | |
| 980 | BT_ASSERT_DBG(bt_field_get_class_type(curr_field) == |
| 981 | BT_FIELD_CLASS_TYPE_STRING); |
| 982 | if (dbg_info_src && dbg_info_src->func) { |
| 983 | status = bt_field_string_set_value(curr_field, |
| 984 | dbg_info_src->func); |
| 985 | } else { |
| 986 | status = bt_field_string_set_value(curr_field, ""); |
| 987 | } |
| 988 | if (status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { |
| 989 | BT_COMP_LOGE("Cannot set `func` curr_field field's value: " |
| 990 | "str-fc-addr=%p", curr_field); |
| 991 | bt_current_thread_clear_error(); |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | static |
| 996 | void fill_debug_info_src_field(struct debug_info_source *dbg_info_src, |
| 997 | bool full_path, bt_field *curr_field, |
| 998 | bt_logging_level log_level, |
| 999 | bt_self_component *self_comp) |
| 1000 | { |
| 1001 | bt_field_string_set_value_status set_status; |
| 1002 | bt_field_string_append_status append_status; |
| 1003 | |
| 1004 | BT_ASSERT_DBG(bt_field_get_class_type(curr_field) == |
| 1005 | BT_FIELD_CLASS_TYPE_STRING); |
| 1006 | |
| 1007 | if (dbg_info_src && dbg_info_src->src_path) { |
| 1008 | if (full_path) { |
| 1009 | set_status = bt_field_string_set_value(curr_field, |
| 1010 | dbg_info_src->src_path); |
| 1011 | } else { |
| 1012 | set_status = bt_field_string_set_value(curr_field, |
| 1013 | dbg_info_src->short_src_path); |
| 1014 | } |
| 1015 | if (set_status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { |
| 1016 | BT_COMP_LOGE("Cannot set path component of `src` " |
| 1017 | "curr_field field's value: str-fc-addr=%p", |
| 1018 | curr_field); |
| 1019 | bt_current_thread_clear_error(); |
| 1020 | } |
| 1021 | |
| 1022 | append_status = bt_field_string_append(curr_field, ":"); |
| 1023 | if (append_status != BT_FIELD_STRING_APPEND_STATUS_OK) { |
| 1024 | BT_COMP_LOGE("Cannot set colon component of `src` " |
| 1025 | "curr_field field's value: str-fc-addr=%p", |
| 1026 | curr_field); |
| 1027 | bt_current_thread_clear_error(); |
| 1028 | } |
| 1029 | |
| 1030 | append_status = bt_field_string_append(curr_field, |
| 1031 | dbg_info_src->line_no); |
| 1032 | if (append_status != BT_FIELD_STRING_APPEND_STATUS_OK) { |
| 1033 | BT_COMP_LOGE("Cannot set line number component of `src` " |
| 1034 | "curr_field field's value: str-fc-addr=%p", |
| 1035 | curr_field); |
| 1036 | bt_current_thread_clear_error(); |
| 1037 | } |
| 1038 | } else { |
| 1039 | set_status = bt_field_string_set_value(curr_field, ""); |
| 1040 | if (set_status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { |
| 1041 | BT_COMP_LOGE("Cannot set `src` curr_field field's value: " |
| 1042 | "str-fc-addr=%p", curr_field); |
| 1043 | bt_current_thread_clear_error(); |
| 1044 | } |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | static |
| 1049 | void fill_debug_info_field_empty(bt_field *debug_info_field, |
| 1050 | bt_logging_level log_level, bt_self_component *self_comp) |
| 1051 | { |
| 1052 | bt_field_string_set_value_status status; |
| 1053 | bt_field *bin_field, *func_field, *src_field; |
| 1054 | |
| 1055 | BT_ASSERT_DBG(bt_field_get_class_type(debug_info_field) == |
| 1056 | BT_FIELD_CLASS_TYPE_STRUCTURE); |
| 1057 | |
| 1058 | bin_field = bt_field_structure_borrow_member_field_by_name( |
| 1059 | debug_info_field, "bin"); |
| 1060 | func_field = bt_field_structure_borrow_member_field_by_name( |
| 1061 | debug_info_field, "func"); |
| 1062 | src_field = bt_field_structure_borrow_member_field_by_name( |
| 1063 | debug_info_field, "src"); |
| 1064 | |
| 1065 | BT_ASSERT_DBG(bt_field_get_class_type(bin_field) == |
| 1066 | BT_FIELD_CLASS_TYPE_STRING); |
| 1067 | BT_ASSERT_DBG(bt_field_get_class_type(func_field) == |
| 1068 | BT_FIELD_CLASS_TYPE_STRING); |
| 1069 | BT_ASSERT_DBG(bt_field_get_class_type(src_field) == |
| 1070 | BT_FIELD_CLASS_TYPE_STRING); |
| 1071 | |
| 1072 | status = bt_field_string_set_value(bin_field, ""); |
| 1073 | if (status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { |
| 1074 | BT_COMP_LOGE("Cannot set `bin` field's value: " |
| 1075 | "str-fc-addr=%p", bin_field); |
| 1076 | bt_current_thread_clear_error(); |
| 1077 | } |
| 1078 | |
| 1079 | status = bt_field_string_set_value(func_field, ""); |
| 1080 | if (status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { |
| 1081 | BT_COMP_LOGE("Cannot set `func` field's value: " |
| 1082 | "str-fc-addr=%p", func_field); |
| 1083 | bt_current_thread_clear_error(); |
| 1084 | } |
| 1085 | |
| 1086 | status = bt_field_string_set_value(src_field, ""); |
| 1087 | if (status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { |
| 1088 | BT_COMP_LOGE("Cannot set `src` field's value: " |
| 1089 | "str-fc-addr=%p", src_field); |
| 1090 | bt_current_thread_clear_error(); |
| 1091 | } |
| 1092 | } |
| 1093 | static |
| 1094 | void fill_debug_info_field(struct debug_info *debug_info, int64_t vpid, |
| 1095 | uint64_t ip, bt_field *debug_info_field) |
| 1096 | { |
| 1097 | struct debug_info_source *dbg_info_src; |
| 1098 | const bt_field_class *debug_info_fc; |
| 1099 | |
| 1100 | BT_ASSERT_DBG(bt_field_get_class_type(debug_info_field) == |
| 1101 | BT_FIELD_CLASS_TYPE_STRUCTURE); |
| 1102 | |
| 1103 | debug_info_fc = bt_field_borrow_class_const(debug_info_field); |
| 1104 | |
| 1105 | BT_ASSERT_DBG(bt_field_class_structure_get_member_count( |
| 1106 | debug_info_fc) == 3); |
| 1107 | |
| 1108 | dbg_info_src = debug_info_query(debug_info, vpid, ip); |
| 1109 | |
| 1110 | fill_debug_info_bin_field(dbg_info_src, |
| 1111 | debug_info->comp->arg_full_path, |
| 1112 | bt_field_structure_borrow_member_field_by_name( |
| 1113 | debug_info_field, "bin"), |
| 1114 | debug_info->log_level, debug_info->self_comp); |
| 1115 | fill_debug_info_func_field(dbg_info_src, |
| 1116 | bt_field_structure_borrow_member_field_by_name( |
| 1117 | debug_info_field, "func"), |
| 1118 | debug_info->log_level, debug_info->self_comp); |
| 1119 | fill_debug_info_src_field(dbg_info_src, |
| 1120 | debug_info->comp->arg_full_path, |
| 1121 | bt_field_structure_borrow_member_field_by_name( |
| 1122 | debug_info_field, "src"), |
| 1123 | debug_info->log_level, debug_info->self_comp); |
| 1124 | } |
| 1125 | |
| 1126 | static |
| 1127 | void fill_debug_info_event_if_needed(struct debug_info_msg_iter *debug_it, |
| 1128 | const bt_event *in_event, bt_event *out_event) |
| 1129 | { |
| 1130 | bt_field *out_common_ctx_field, *out_debug_info_field; |
| 1131 | const bt_field *vpid_field, *ip_field, *in_common_ctx_field; |
| 1132 | const bt_field_class *in_common_ctx_fc; |
| 1133 | struct debug_info *debug_info; |
| 1134 | uint64_t vpid; |
| 1135 | int64_t ip; |
| 1136 | gchar *debug_info_field_name = |
| 1137 | debug_it->debug_info_component->arg_debug_info_field_name; |
| 1138 | bt_logging_level log_level = debug_it->log_level; |
| 1139 | bt_self_component *self_comp = debug_it->self_comp; |
| 1140 | |
| 1141 | in_common_ctx_field = bt_event_borrow_common_context_field_const( |
| 1142 | in_event); |
| 1143 | if (!in_common_ctx_field) { |
| 1144 | /* |
| 1145 | * There is no event common context so no need to add debug |
| 1146 | * info field. |
| 1147 | */ |
| 1148 | goto end; |
| 1149 | } |
| 1150 | |
| 1151 | in_common_ctx_fc = bt_field_borrow_class_const(in_common_ctx_field); |
| 1152 | if (!is_event_common_ctx_dbg_info_compatible(in_common_ctx_fc, |
| 1153 | debug_it->ir_maps->debug_info_field_class_name)) { |
| 1154 | /* |
| 1155 | * The input event common context does not have the necessary |
| 1156 | * fields to resolve debug information. |
| 1157 | */ |
| 1158 | goto end; |
| 1159 | } |
| 1160 | |
| 1161 | /* Borrow the debug-info field. */ |
| 1162 | out_common_ctx_field = bt_event_borrow_common_context_field(out_event); |
| 1163 | if (!out_common_ctx_field) { |
| 1164 | goto end; |
| 1165 | } |
| 1166 | |
| 1167 | out_debug_info_field = bt_field_structure_borrow_member_field_by_name( |
| 1168 | out_common_ctx_field, debug_info_field_name); |
| 1169 | |
| 1170 | vpid_field = bt_field_structure_borrow_member_field_by_name_const( |
| 1171 | out_common_ctx_field, VPID_FIELD_NAME); |
| 1172 | ip_field = bt_field_structure_borrow_member_field_by_name_const( |
| 1173 | out_common_ctx_field, IP_FIELD_NAME); |
| 1174 | |
| 1175 | vpid = bt_field_integer_signed_get_value(vpid_field); |
| 1176 | ip = bt_field_integer_unsigned_get_value(ip_field); |
| 1177 | |
| 1178 | /* |
| 1179 | * Borrow the debug_info structure needed for the source |
| 1180 | * resolving. |
| 1181 | */ |
| 1182 | debug_info = g_hash_table_lookup(debug_it->debug_info_map, |
| 1183 | bt_stream_borrow_trace_const( |
| 1184 | bt_event_borrow_stream_const(in_event))); |
| 1185 | |
| 1186 | if (debug_info) { |
| 1187 | /* |
| 1188 | * Perform the debug-info resolving and set the event fields |
| 1189 | * accordingly. |
| 1190 | */ |
| 1191 | fill_debug_info_field(debug_info, vpid, ip, out_debug_info_field); |
| 1192 | } else { |
| 1193 | BT_COMP_LOGD("No debug information for this trace. Setting debug " |
| 1194 | "info fields to empty strings."); |
| 1195 | fill_debug_info_field_empty(out_debug_info_field, |
| 1196 | log_level, self_comp); |
| 1197 | } |
| 1198 | end: |
| 1199 | return; |
| 1200 | } |
| 1201 | |
| 1202 | static |
| 1203 | void update_event_statedump_if_needed(struct debug_info_msg_iter *debug_it, |
| 1204 | const bt_event *in_event) |
| 1205 | { |
| 1206 | const bt_field *event_common_ctx; |
| 1207 | const bt_field_class *event_common_ctx_fc; |
| 1208 | const bt_event_class *in_event_class = bt_event_borrow_class_const(in_event); |
| 1209 | |
| 1210 | /* |
| 1211 | * If the event is an lttng_ust_statedump event AND has the right event |
| 1212 | * common context fields update the debug-info view for this process. |
| 1213 | */ |
| 1214 | event_common_ctx = bt_event_borrow_common_context_field_const(in_event); |
| 1215 | if (!event_common_ctx) { |
| 1216 | goto end; |
| 1217 | } |
| 1218 | |
| 1219 | event_common_ctx_fc = bt_field_borrow_class_const(event_common_ctx); |
| 1220 | if (is_event_common_ctx_dbg_info_compatible(event_common_ctx_fc, |
| 1221 | debug_it->ir_maps->debug_info_field_class_name)) { |
| 1222 | /* Checkout if it might be a one of lttng ust statedump events. */ |
| 1223 | const char *in_event_name = bt_event_class_get_name(in_event_class); |
| 1224 | if (strncmp(in_event_name, LTTNG_UST_STATEDUMP_PREFIX, |
| 1225 | strlen(LTTNG_UST_STATEDUMP_PREFIX)) == 0) { |
| 1226 | /* Handle statedump events. */ |
| 1227 | handle_event_statedump(debug_it, in_event); |
| 1228 | } |
| 1229 | } |
| 1230 | end: |
| 1231 | return; |
| 1232 | } |
| 1233 | |
| 1234 | static |
| 1235 | bt_message *handle_event_message(struct debug_info_msg_iter *debug_it, |
| 1236 | const bt_message *in_message) |
| 1237 | { |
| 1238 | const bt_clock_snapshot *cs; |
| 1239 | const bt_clock_class *default_cc; |
| 1240 | const bt_packet *in_packet; |
| 1241 | const bt_stream *in_stream; |
| 1242 | const bt_stream *out_stream; |
| 1243 | bt_event_class *out_event_class; |
| 1244 | bt_packet *out_packet = NULL; |
| 1245 | bt_event *out_event; |
| 1246 | bt_logging_level log_level = debug_it->log_level; |
| 1247 | bt_self_component *self_comp = debug_it->self_comp; |
| 1248 | |
| 1249 | bt_message *out_message = NULL; |
| 1250 | |
| 1251 | /* Borrow the input event and its event class. */ |
| 1252 | const bt_event *in_event = |
| 1253 | bt_message_event_borrow_event_const(in_message); |
| 1254 | const bt_event_class *in_event_class = |
| 1255 | bt_event_borrow_class_const(in_event); |
| 1256 | |
| 1257 | update_event_statedump_if_needed(debug_it, in_event); |
| 1258 | |
| 1259 | out_event_class = trace_ir_mapping_borrow_mapped_event_class( |
| 1260 | debug_it->ir_maps, in_event_class); |
| 1261 | if (!out_event_class) { |
| 1262 | out_event_class = trace_ir_mapping_create_new_mapped_event_class( |
| 1263 | debug_it->ir_maps, in_event_class); |
| 1264 | } |
| 1265 | BT_ASSERT_DBG(out_event_class); |
| 1266 | |
| 1267 | /* Borrow the input stream. */ |
| 1268 | in_stream = bt_event_borrow_stream_const(in_event); |
| 1269 | BT_ASSERT_DBG(in_stream); |
| 1270 | out_stream = trace_ir_mapping_borrow_mapped_stream(debug_it->ir_maps, |
| 1271 | in_stream); |
| 1272 | BT_ASSERT_DBG(in_stream); |
| 1273 | |
| 1274 | /* Borrow the input and output packets. */ |
| 1275 | in_packet = bt_event_borrow_packet_const(in_event); |
| 1276 | if (in_packet) { |
| 1277 | out_packet = trace_ir_mapping_borrow_mapped_packet( |
| 1278 | debug_it->ir_maps, in_packet); |
| 1279 | } |
| 1280 | |
| 1281 | default_cc = bt_stream_class_borrow_default_clock_class_const( |
| 1282 | bt_event_class_borrow_stream_class_const(in_event_class)); |
| 1283 | if (default_cc) { |
| 1284 | /* Borrow event clock snapshot. */ |
| 1285 | cs = bt_message_event_borrow_default_clock_snapshot_const( |
| 1286 | in_message); |
| 1287 | |
| 1288 | /* Create an output event message. */ |
| 1289 | if (out_packet) { |
| 1290 | out_message = |
| 1291 | bt_message_event_create_with_packet_and_default_clock_snapshot( |
| 1292 | debug_it->input_iterator, |
| 1293 | out_event_class, out_packet, |
| 1294 | bt_clock_snapshot_get_value(cs)); |
| 1295 | } else { |
| 1296 | out_message = |
| 1297 | bt_message_event_create_with_default_clock_snapshot( |
| 1298 | debug_it->input_iterator, |
| 1299 | out_event_class, out_stream, |
| 1300 | bt_clock_snapshot_get_value(cs)); |
| 1301 | } |
| 1302 | } else { |
| 1303 | if (out_packet) { |
| 1304 | out_message = bt_message_event_create_with_packet( |
| 1305 | debug_it->input_iterator, out_event_class, |
| 1306 | out_packet); |
| 1307 | } else { |
| 1308 | out_message = bt_message_event_create( |
| 1309 | debug_it->input_iterator, out_event_class, |
| 1310 | out_stream); |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | if (!out_message) { |
| 1315 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 1316 | "Error creating output event message."); |
| 1317 | goto error; |
| 1318 | } |
| 1319 | |
| 1320 | out_event = bt_message_event_borrow_event(out_message); |
| 1321 | |
| 1322 | /* Copy the original fields to the output event. */ |
| 1323 | if (copy_event_content(in_event, out_event, log_level, self_comp) != |
| 1324 | DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
| 1325 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 1326 | "Error copying event message content output event message: " |
| 1327 | "in-ev-addr=%p, out-ev-addr=%p", in_event, out_event); |
| 1328 | goto error; |
| 1329 | } |
| 1330 | |
| 1331 | /* |
| 1332 | * Try to set the debug-info fields based on debug information that is |
| 1333 | * gathered so far. |
| 1334 | */ |
| 1335 | fill_debug_info_event_if_needed(debug_it, in_event, out_event); |
| 1336 | |
| 1337 | goto end; |
| 1338 | |
| 1339 | error: |
| 1340 | BT_MESSAGE_PUT_REF_AND_RESET(out_message); |
| 1341 | end: |
| 1342 | return out_message; |
| 1343 | } |
| 1344 | |
| 1345 | static |
| 1346 | bt_message *handle_stream_begin_message(struct debug_info_msg_iter *debug_it, |
| 1347 | const bt_message *in_message) |
| 1348 | { |
| 1349 | const bt_stream *in_stream; |
| 1350 | bt_message *out_message; |
| 1351 | bt_stream *out_stream; |
| 1352 | bt_logging_level log_level = debug_it->log_level; |
| 1353 | bt_self_component *self_comp = debug_it->self_comp; |
| 1354 | |
| 1355 | in_stream = bt_message_stream_beginning_borrow_stream_const(in_message); |
| 1356 | BT_ASSERT(in_stream); |
| 1357 | |
| 1358 | /* Create a duplicated output stream. */ |
| 1359 | out_stream = trace_ir_mapping_create_new_mapped_stream( |
| 1360 | debug_it->ir_maps, in_stream); |
| 1361 | if (!out_stream) { |
| 1362 | out_message = NULL; |
| 1363 | goto error; |
| 1364 | } |
| 1365 | |
| 1366 | /* Create an output stream beginning message. */ |
| 1367 | out_message = bt_message_stream_beginning_create( |
| 1368 | debug_it->input_iterator, out_stream); |
| 1369 | if (!out_message) { |
| 1370 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 1371 | "Error creating output stream beginning message: " |
| 1372 | "out-s-addr=%p", out_stream); |
| 1373 | } |
| 1374 | error: |
| 1375 | return out_message; |
| 1376 | } |
| 1377 | |
| 1378 | static |
| 1379 | bt_message *handle_stream_end_message(struct debug_info_msg_iter *debug_it, |
| 1380 | const bt_message *in_message) |
| 1381 | { |
| 1382 | const bt_stream *in_stream; |
| 1383 | bt_message *out_message = NULL; |
| 1384 | bt_stream *out_stream; |
| 1385 | bt_logging_level log_level = debug_it->log_level; |
| 1386 | bt_self_component *self_comp = debug_it->self_comp; |
| 1387 | |
| 1388 | in_stream = bt_message_stream_end_borrow_stream_const(in_message); |
| 1389 | BT_ASSERT(in_stream); |
| 1390 | |
| 1391 | out_stream = trace_ir_mapping_borrow_mapped_stream( |
| 1392 | debug_it->ir_maps, in_stream); |
| 1393 | BT_ASSERT(out_stream); |
| 1394 | |
| 1395 | /* Create an output stream end message. */ |
| 1396 | out_message = bt_message_stream_end_create(debug_it->input_iterator, |
| 1397 | out_stream); |
| 1398 | if (!out_message) { |
| 1399 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 1400 | "Error creating output stream end message: " |
| 1401 | "out-s-addr=%p", out_stream); |
| 1402 | goto end; |
| 1403 | } |
| 1404 | |
| 1405 | /* Remove stream from trace mapping hashtable. */ |
| 1406 | trace_ir_mapping_remove_mapped_stream(debug_it->ir_maps, in_stream); |
| 1407 | |
| 1408 | end: |
| 1409 | return out_message; |
| 1410 | } |
| 1411 | |
| 1412 | static |
| 1413 | bt_message *handle_packet_begin_message(struct debug_info_msg_iter *debug_it, |
| 1414 | const bt_message *in_message) |
| 1415 | { |
| 1416 | bool has_default_clock_snapshot; |
| 1417 | const bt_clock_snapshot *cs; |
| 1418 | bt_message *out_message = NULL; |
| 1419 | bt_packet *out_packet; |
| 1420 | bt_logging_level log_level = debug_it->log_level; |
| 1421 | bt_self_component *self_comp = debug_it->self_comp; |
| 1422 | |
| 1423 | const bt_packet *in_packet = |
| 1424 | bt_message_packet_beginning_borrow_packet_const(in_message); |
| 1425 | BT_ASSERT(in_packet); |
| 1426 | |
| 1427 | /* This packet should not be already mapped. */ |
| 1428 | BT_ASSERT(!trace_ir_mapping_borrow_mapped_packet( |
| 1429 | debug_it->ir_maps, in_packet)); |
| 1430 | |
| 1431 | out_packet = trace_ir_mapping_create_new_mapped_packet(debug_it->ir_maps, |
| 1432 | in_packet); |
| 1433 | |
| 1434 | BT_ASSERT(out_packet); |
| 1435 | |
| 1436 | has_default_clock_snapshot = |
| 1437 | bt_stream_class_packets_have_beginning_default_clock_snapshot( |
| 1438 | bt_stream_borrow_class_const( |
| 1439 | bt_packet_borrow_stream_const(in_packet))); |
| 1440 | if (has_default_clock_snapshot) { |
| 1441 | /* Borrow clock snapshot. */ |
| 1442 | cs = bt_message_packet_beginning_borrow_default_clock_snapshot_const( |
| 1443 | in_message); |
| 1444 | |
| 1445 | /* Create an output packet beginning message. */ |
| 1446 | out_message = bt_message_packet_beginning_create_with_default_clock_snapshot( |
| 1447 | debug_it->input_iterator, out_packet, |
| 1448 | bt_clock_snapshot_get_value(cs)); |
| 1449 | } else { |
| 1450 | out_message = bt_message_packet_beginning_create( |
| 1451 | debug_it->input_iterator, out_packet); |
| 1452 | } |
| 1453 | if (!out_message) { |
| 1454 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 1455 | "Error creating output packet beginning message: " |
| 1456 | "out-p-addr=%p", out_packet); |
| 1457 | } |
| 1458 | |
| 1459 | return out_message; |
| 1460 | } |
| 1461 | |
| 1462 | static |
| 1463 | bt_message *handle_packet_end_message(struct debug_info_msg_iter *debug_it, |
| 1464 | const bt_message *in_message) |
| 1465 | { |
| 1466 | bool has_default_clock_snapshot; |
| 1467 | const bt_clock_snapshot *cs; |
| 1468 | const bt_packet *in_packet; |
| 1469 | bt_message *out_message = NULL; |
| 1470 | bt_packet *out_packet; |
| 1471 | bt_logging_level log_level = debug_it->log_level; |
| 1472 | bt_self_component *self_comp = debug_it->self_comp; |
| 1473 | |
| 1474 | in_packet = bt_message_packet_end_borrow_packet_const(in_message); |
| 1475 | BT_ASSERT(in_packet); |
| 1476 | |
| 1477 | out_packet = trace_ir_mapping_borrow_mapped_packet(debug_it->ir_maps, in_packet); |
| 1478 | BT_ASSERT(out_packet); |
| 1479 | |
| 1480 | has_default_clock_snapshot = |
| 1481 | bt_stream_class_packets_have_end_default_clock_snapshot( |
| 1482 | bt_stream_borrow_class_const( |
| 1483 | bt_packet_borrow_stream_const(in_packet))); |
| 1484 | if (has_default_clock_snapshot) { |
| 1485 | /* Borrow clock snapshot. */ |
| 1486 | cs = bt_message_packet_end_borrow_default_clock_snapshot_const( |
| 1487 | in_message); |
| 1488 | |
| 1489 | /* Create an outpute packet end message. */ |
| 1490 | out_message = bt_message_packet_end_create_with_default_clock_snapshot( |
| 1491 | debug_it->input_iterator, out_packet, |
| 1492 | bt_clock_snapshot_get_value(cs)); |
| 1493 | } else { |
| 1494 | out_message = bt_message_packet_end_create( |
| 1495 | debug_it->input_iterator, out_packet); |
| 1496 | } |
| 1497 | |
| 1498 | if (!out_message) { |
| 1499 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 1500 | "Error creating output packet end message: " |
| 1501 | "out-p-addr=%p", out_packet); |
| 1502 | goto end; |
| 1503 | } |
| 1504 | |
| 1505 | /* Remove packet from data mapping hashtable. */ |
| 1506 | trace_ir_mapping_remove_mapped_packet(debug_it->ir_maps, in_packet); |
| 1507 | |
| 1508 | end: |
| 1509 | return out_message; |
| 1510 | } |
| 1511 | |
| 1512 | static |
| 1513 | bt_message *handle_msg_iterator_inactivity(struct debug_info_msg_iter *debug_it, |
| 1514 | const bt_message *in_message) |
| 1515 | { |
| 1516 | /* |
| 1517 | * This message type can be forwarded directly because it does |
| 1518 | * not refer to any objects in the trace class. |
| 1519 | */ |
| 1520 | bt_message_get_ref(in_message); |
| 1521 | return (bt_message*) in_message; |
| 1522 | } |
| 1523 | |
| 1524 | static |
| 1525 | bt_message *handle_discarded_events_message(struct debug_info_msg_iter *debug_it, |
| 1526 | const bt_message *in_message) |
| 1527 | { |
| 1528 | const bt_clock_snapshot *begin_cs, *end_cs; |
| 1529 | const bt_stream *in_stream; |
| 1530 | bool has_default_clock_snapshots; |
| 1531 | uint64_t discarded_events, begin_cs_value, end_cs_value; |
| 1532 | bt_property_availability prop_avail; |
| 1533 | bt_message *out_message = NULL; |
| 1534 | bt_stream *out_stream; |
| 1535 | bt_logging_level log_level = debug_it->log_level; |
| 1536 | bt_self_component *self_comp = debug_it->self_comp; |
| 1537 | |
| 1538 | in_stream = bt_message_discarded_events_borrow_stream_const( |
| 1539 | in_message); |
| 1540 | BT_ASSERT(in_stream); |
| 1541 | |
| 1542 | out_stream = trace_ir_mapping_borrow_mapped_stream( debug_it->ir_maps, |
| 1543 | in_stream); |
| 1544 | BT_ASSERT(out_stream); |
| 1545 | |
| 1546 | has_default_clock_snapshots = |
| 1547 | bt_stream_class_discarded_events_have_default_clock_snapshots( |
| 1548 | bt_stream_borrow_class_const(in_stream)); |
| 1549 | if (has_default_clock_snapshots) { |
| 1550 | begin_cs = bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const( |
| 1551 | in_message); |
| 1552 | end_cs = bt_message_discarded_events_borrow_end_default_clock_snapshot_const( |
| 1553 | in_message); |
| 1554 | |
| 1555 | begin_cs_value = bt_clock_snapshot_get_value(begin_cs); |
| 1556 | end_cs_value = bt_clock_snapshot_get_value(end_cs); |
| 1557 | |
| 1558 | out_message = bt_message_discarded_events_create_with_default_clock_snapshots( |
| 1559 | debug_it->input_iterator, out_stream, |
| 1560 | begin_cs_value, end_cs_value); |
| 1561 | } else { |
| 1562 | out_message = bt_message_discarded_events_create( |
| 1563 | debug_it->input_iterator, out_stream); |
| 1564 | } |
| 1565 | if (!out_message) { |
| 1566 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 1567 | "Error creating output discarded events message: " |
| 1568 | "out-s-addr=%p", out_stream); |
| 1569 | goto error; |
| 1570 | } |
| 1571 | |
| 1572 | prop_avail = bt_message_discarded_events_get_count(in_message, |
| 1573 | &discarded_events); |
| 1574 | |
| 1575 | if (prop_avail == BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE) { |
| 1576 | bt_message_discarded_events_set_count(out_message, |
| 1577 | discarded_events); |
| 1578 | } |
| 1579 | |
| 1580 | error: |
| 1581 | return out_message; |
| 1582 | } |
| 1583 | |
| 1584 | static |
| 1585 | bt_message *handle_discarded_packets_message(struct debug_info_msg_iter *debug_it, |
| 1586 | const bt_message *in_message) |
| 1587 | { |
| 1588 | const bt_clock_snapshot *begin_cs, *end_cs; |
| 1589 | bool has_default_clock_snapshots; |
| 1590 | const bt_stream *in_stream; |
| 1591 | uint64_t discarded_packets, begin_cs_value, end_cs_value; |
| 1592 | bt_property_availability prop_avail; |
| 1593 | bt_message *out_message = NULL; |
| 1594 | bt_stream *out_stream; |
| 1595 | bt_logging_level log_level = debug_it->log_level; |
| 1596 | bt_self_component *self_comp = debug_it->self_comp; |
| 1597 | |
| 1598 | in_stream = bt_message_discarded_packets_borrow_stream_const( |
| 1599 | in_message); |
| 1600 | BT_ASSERT(in_stream); |
| 1601 | |
| 1602 | out_stream = trace_ir_mapping_borrow_mapped_stream( debug_it->ir_maps, |
| 1603 | in_stream); |
| 1604 | BT_ASSERT(out_stream); |
| 1605 | |
| 1606 | has_default_clock_snapshots = |
| 1607 | bt_stream_class_discarded_packets_have_default_clock_snapshots( |
| 1608 | bt_stream_borrow_class_const(in_stream)); |
| 1609 | if (has_default_clock_snapshots) { |
| 1610 | begin_cs = bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const( |
| 1611 | in_message); |
| 1612 | |
| 1613 | end_cs = bt_message_discarded_packets_borrow_end_default_clock_snapshot_const( |
| 1614 | in_message); |
| 1615 | |
| 1616 | begin_cs_value = bt_clock_snapshot_get_value(begin_cs); |
| 1617 | end_cs_value = bt_clock_snapshot_get_value(end_cs); |
| 1618 | |
| 1619 | out_message = bt_message_discarded_packets_create_with_default_clock_snapshots( |
| 1620 | debug_it->input_iterator, out_stream, |
| 1621 | begin_cs_value, end_cs_value); |
| 1622 | } else { |
| 1623 | out_message = bt_message_discarded_packets_create( |
| 1624 | debug_it->input_iterator, out_stream); |
| 1625 | } |
| 1626 | if (!out_message) { |
| 1627 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 1628 | "Error creating output discarded packet message: " |
| 1629 | "out-s-addr=%p", out_stream); |
| 1630 | goto error; |
| 1631 | } |
| 1632 | |
| 1633 | prop_avail = bt_message_discarded_packets_get_count(in_message, |
| 1634 | &discarded_packets); |
| 1635 | if (prop_avail == BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE) { |
| 1636 | bt_message_discarded_packets_set_count(out_message, |
| 1637 | discarded_packets); |
| 1638 | } |
| 1639 | |
| 1640 | error: |
| 1641 | return out_message; |
| 1642 | } |
| 1643 | |
| 1644 | static |
| 1645 | const bt_message *handle_message(struct debug_info_msg_iter *debug_it, |
| 1646 | const bt_message *in_message) |
| 1647 | { |
| 1648 | bt_message *out_message = NULL; |
| 1649 | |
| 1650 | switch (bt_message_get_type(in_message)) { |
| 1651 | case BT_MESSAGE_TYPE_EVENT: |
| 1652 | out_message = handle_event_message(debug_it, in_message); |
| 1653 | break; |
| 1654 | case BT_MESSAGE_TYPE_PACKET_BEGINNING: |
| 1655 | out_message = handle_packet_begin_message(debug_it, in_message); |
| 1656 | break; |
| 1657 | case BT_MESSAGE_TYPE_PACKET_END: |
| 1658 | out_message = handle_packet_end_message(debug_it, in_message); |
| 1659 | break; |
| 1660 | case BT_MESSAGE_TYPE_STREAM_BEGINNING: |
| 1661 | out_message = handle_stream_begin_message(debug_it, in_message); |
| 1662 | break; |
| 1663 | case BT_MESSAGE_TYPE_STREAM_END: |
| 1664 | out_message = handle_stream_end_message(debug_it, in_message); |
| 1665 | break; |
| 1666 | case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY: |
| 1667 | out_message = handle_msg_iterator_inactivity(debug_it, in_message); |
| 1668 | break; |
| 1669 | case BT_MESSAGE_TYPE_DISCARDED_EVENTS: |
| 1670 | out_message = handle_discarded_events_message(debug_it, in_message); |
| 1671 | break; |
| 1672 | case BT_MESSAGE_TYPE_DISCARDED_PACKETS: |
| 1673 | out_message = handle_discarded_packets_message(debug_it, in_message); |
| 1674 | break; |
| 1675 | default: |
| 1676 | bt_common_abort(); |
| 1677 | break; |
| 1678 | } |
| 1679 | |
| 1680 | return out_message; |
| 1681 | } |
| 1682 | |
| 1683 | static |
| 1684 | struct bt_param_validation_map_value_entry_descr debug_info_params[] = { |
| 1685 | { "debug-info-field-name", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_STRING } }, |
| 1686 | { "debug-info-dir", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_STRING } }, |
| 1687 | { "target-prefix", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_STRING } }, |
| 1688 | { "full-path", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 1689 | BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END |
| 1690 | }; |
| 1691 | |
| 1692 | static |
| 1693 | bt_component_class_initialize_method_status init_from_params( |
| 1694 | struct debug_info_component *debug_info_component, |
| 1695 | const bt_value *params) |
| 1696 | { |
| 1697 | const bt_value *value; |
| 1698 | bt_component_class_initialize_method_status status; |
| 1699 | bt_logging_level log_level = debug_info_component->log_level; |
| 1700 | enum bt_param_validation_status validation_status; |
| 1701 | gchar *validate_error = NULL; |
| 1702 | |
| 1703 | validation_status = bt_param_validation_validate(params, |
| 1704 | debug_info_params, &validate_error); |
| 1705 | if (validation_status == BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR) { |
| 1706 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; |
| 1707 | goto end; |
| 1708 | } else if (validation_status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR) { |
| 1709 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; |
| 1710 | BT_COMP_LOGE_APPEND_CAUSE(debug_info_component->self_comp, |
| 1711 | "%s", validate_error); |
| 1712 | goto end; |
| 1713 | } |
| 1714 | |
| 1715 | BT_ASSERT(params); |
| 1716 | |
| 1717 | value = bt_value_map_borrow_entry_value_const(params, |
| 1718 | "debug-info-field-name"); |
| 1719 | if (value) { |
| 1720 | debug_info_component->arg_debug_info_field_name = |
| 1721 | g_strdup(bt_value_string_get(value)); |
| 1722 | } else { |
| 1723 | debug_info_component->arg_debug_info_field_name = |
| 1724 | g_strdup(DEFAULT_DEBUG_INFO_FIELD_NAME); |
| 1725 | } |
| 1726 | |
| 1727 | value = bt_value_map_borrow_entry_value_const(params, "debug-info-dir"); |
| 1728 | if (value) { |
| 1729 | debug_info_component->arg_debug_dir = |
| 1730 | g_strdup(bt_value_string_get(value)); |
| 1731 | } else { |
| 1732 | debug_info_component->arg_debug_dir = NULL; |
| 1733 | } |
| 1734 | |
| 1735 | |
| 1736 | value = bt_value_map_borrow_entry_value_const(params, "target-prefix"); |
| 1737 | if (value) { |
| 1738 | debug_info_component->arg_target_prefix = |
| 1739 | g_strdup(bt_value_string_get(value)); |
| 1740 | } else { |
| 1741 | debug_info_component->arg_target_prefix = NULL; |
| 1742 | } |
| 1743 | |
| 1744 | value = bt_value_map_borrow_entry_value_const(params, "full-path"); |
| 1745 | if (value) { |
| 1746 | debug_info_component->arg_full_path = bt_value_bool_get(value); |
| 1747 | } else { |
| 1748 | debug_info_component->arg_full_path = BT_FALSE; |
| 1749 | } |
| 1750 | |
| 1751 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK; |
| 1752 | |
| 1753 | end: |
| 1754 | g_free(validate_error); |
| 1755 | |
| 1756 | return status; |
| 1757 | } |
| 1758 | |
| 1759 | BT_HIDDEN |
| 1760 | bt_component_class_initialize_method_status debug_info_comp_init( |
| 1761 | bt_self_component_filter *self_comp_flt, |
| 1762 | bt_self_component_filter_configuration *config, |
| 1763 | const bt_value *params, __attribute__((unused)) void *init_method_data) |
| 1764 | { |
| 1765 | struct debug_info_component *debug_info_comp; |
| 1766 | bt_component_class_initialize_method_status status = |
| 1767 | BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK; |
| 1768 | bt_self_component_add_port_status add_port_status; |
| 1769 | bt_self_component *self_comp = |
| 1770 | bt_self_component_filter_as_self_component(self_comp_flt); |
| 1771 | bt_logging_level log_level = bt_component_get_logging_level( |
| 1772 | bt_self_component_as_component(self_comp)); |
| 1773 | |
| 1774 | BT_COMP_LOGI("Initializing debug_info component: " |
| 1775 | "comp-addr=%p, params-addr=%p", self_comp, params); |
| 1776 | |
| 1777 | debug_info_comp = g_new0(struct debug_info_component, 1); |
| 1778 | if (!debug_info_comp) { |
| 1779 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 1780 | "Failed to allocate one debug_info component."); |
| 1781 | goto error; |
| 1782 | } |
| 1783 | |
| 1784 | debug_info_comp->log_level = log_level; |
| 1785 | debug_info_comp->self_comp = self_comp; |
| 1786 | debug_info_comp->self_comp_filter = self_comp_flt; |
| 1787 | bt_self_component_set_data(self_comp, debug_info_comp); |
| 1788 | |
| 1789 | add_port_status = bt_self_component_filter_add_input_port( |
| 1790 | self_comp_flt, "in", NULL, NULL); |
| 1791 | if (add_port_status != BT_SELF_COMPONENT_ADD_PORT_STATUS_OK) { |
| 1792 | status = (int) add_port_status; |
| 1793 | goto error; |
| 1794 | } |
| 1795 | |
| 1796 | add_port_status = bt_self_component_filter_add_output_port( |
| 1797 | self_comp_flt, "out", NULL, NULL); |
| 1798 | if (add_port_status != BT_SELF_COMPONENT_ADD_PORT_STATUS_OK) { |
| 1799 | status = (int) add_port_status; |
| 1800 | goto error; |
| 1801 | } |
| 1802 | |
| 1803 | status = init_from_params(debug_info_comp, params); |
| 1804 | if (status != BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK) { |
| 1805 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 1806 | "Cannot configure debug_info component: " |
| 1807 | "debug_info-comp-addr=%p, params-addr=%p", |
| 1808 | debug_info_comp, params); |
| 1809 | goto error; |
| 1810 | } |
| 1811 | |
| 1812 | goto end; |
| 1813 | |
| 1814 | error: |
| 1815 | destroy_debug_info_comp(debug_info_comp); |
| 1816 | bt_self_component_set_data(self_comp, NULL); |
| 1817 | |
| 1818 | if (status == BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK) { |
| 1819 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; |
| 1820 | } |
| 1821 | end: |
| 1822 | return status; |
| 1823 | } |
| 1824 | |
| 1825 | BT_HIDDEN |
| 1826 | void debug_info_comp_finalize(bt_self_component_filter *self_comp_flt) |
| 1827 | { |
| 1828 | struct debug_info_component *debug_info = |
| 1829 | bt_self_component_get_data( |
| 1830 | bt_self_component_filter_as_self_component( |
| 1831 | self_comp_flt)); |
| 1832 | bt_logging_level log_level = debug_info->log_level; |
| 1833 | bt_self_component *self_comp = debug_info->self_comp; |
| 1834 | |
| 1835 | BT_COMP_LOGI("Finalizing debug_info self_component: comp-addr=%p", |
| 1836 | self_comp); |
| 1837 | |
| 1838 | destroy_debug_info_comp(debug_info); |
| 1839 | } |
| 1840 | |
| 1841 | BT_HIDDEN |
| 1842 | bt_message_iterator_class_next_method_status debug_info_msg_iter_next( |
| 1843 | bt_self_message_iterator *self_msg_iter, |
| 1844 | const bt_message_array_const msgs, uint64_t capacity, |
| 1845 | uint64_t *count) |
| 1846 | { |
| 1847 | bt_message_iterator *upstream_iterator = NULL; |
| 1848 | bt_message_iterator_next_status upstream_iterator_ret_status; |
| 1849 | struct debug_info_msg_iter *debug_info_msg_iter; |
| 1850 | struct debug_info_component *debug_info = NULL; |
| 1851 | bt_message_iterator_class_next_method_status status; |
| 1852 | bt_self_component *self_comp = NULL; |
| 1853 | bt_message_array_const input_msgs; |
| 1854 | const bt_message *out_message; |
| 1855 | uint64_t curr_msg_idx, i; |
| 1856 | |
| 1857 | status = BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK; |
| 1858 | |
| 1859 | self_comp = bt_self_message_iterator_borrow_component(self_msg_iter); |
| 1860 | BT_ASSERT_DBG(self_comp); |
| 1861 | |
| 1862 | debug_info = bt_self_component_get_data(self_comp); |
| 1863 | BT_ASSERT_DBG(debug_info); |
| 1864 | |
| 1865 | debug_info_msg_iter = bt_self_message_iterator_get_data(self_msg_iter); |
| 1866 | BT_ASSERT_DBG(debug_info_msg_iter); |
| 1867 | |
| 1868 | upstream_iterator = debug_info_msg_iter->msg_iter; |
| 1869 | BT_ASSERT_DBG(upstream_iterator); |
| 1870 | |
| 1871 | upstream_iterator_ret_status = |
| 1872 | bt_message_iterator_next( |
| 1873 | upstream_iterator, &input_msgs, count); |
| 1874 | if (upstream_iterator_ret_status != |
| 1875 | BT_MESSAGE_ITERATOR_NEXT_STATUS_OK) { |
| 1876 | /* |
| 1877 | * No messages were returned. Not necessarily an error. |
| 1878 | * Convert the upstream message iterator status to a |
| 1879 | * self status. |
| 1880 | */ |
| 1881 | status = (int) upstream_iterator_ret_status; |
| 1882 | goto end; |
| 1883 | } |
| 1884 | |
| 1885 | /* |
| 1886 | * There should never be more received messages than the capacity we |
| 1887 | * provided. |
| 1888 | */ |
| 1889 | BT_ASSERT_DBG(*count <= capacity); |
| 1890 | |
| 1891 | for (curr_msg_idx = 0; curr_msg_idx < *count; curr_msg_idx++) { |
| 1892 | out_message = handle_message(debug_info_msg_iter, |
| 1893 | input_msgs[curr_msg_idx]); |
| 1894 | if (!out_message) { |
| 1895 | goto handle_msg_error; |
| 1896 | } |
| 1897 | |
| 1898 | msgs[curr_msg_idx] = out_message; |
| 1899 | /* |
| 1900 | * Drop our reference of the input message as we are done with |
| 1901 | * it and created a output copy. |
| 1902 | */ |
| 1903 | bt_message_put_ref(input_msgs[curr_msg_idx]); |
| 1904 | } |
| 1905 | |
| 1906 | goto end; |
| 1907 | |
| 1908 | handle_msg_error: |
| 1909 | /* |
| 1910 | * Drop references of all the output messages created before the |
| 1911 | * failure. |
| 1912 | */ |
| 1913 | for (i = 0; i < curr_msg_idx; i++) { |
| 1914 | bt_message_put_ref(msgs[i]); |
| 1915 | } |
| 1916 | |
| 1917 | /* |
| 1918 | * Drop references of all the input messages not dropped before the |
| 1919 | * failure. |
| 1920 | */ |
| 1921 | for (i = curr_msg_idx; i < *count; i++) { |
| 1922 | bt_message_put_ref(input_msgs[i]); |
| 1923 | } |
| 1924 | |
| 1925 | status = BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_MEMORY_ERROR; |
| 1926 | |
| 1927 | end: |
| 1928 | return status; |
| 1929 | } |
| 1930 | |
| 1931 | static |
| 1932 | void debug_info_msg_iter_destroy(struct debug_info_msg_iter *debug_info_msg_iter) |
| 1933 | { |
| 1934 | if (!debug_info_msg_iter) { |
| 1935 | goto end; |
| 1936 | } |
| 1937 | |
| 1938 | if (debug_info_msg_iter->msg_iter) { |
| 1939 | bt_message_iterator_put_ref( |
| 1940 | debug_info_msg_iter->msg_iter); |
| 1941 | } |
| 1942 | |
| 1943 | if (debug_info_msg_iter->ir_maps) { |
| 1944 | trace_ir_maps_destroy(debug_info_msg_iter->ir_maps); |
| 1945 | } |
| 1946 | |
| 1947 | if (debug_info_msg_iter->debug_info_map) { |
| 1948 | g_hash_table_destroy(debug_info_msg_iter->debug_info_map); |
| 1949 | } |
| 1950 | |
| 1951 | bt_fd_cache_fini(&debug_info_msg_iter->fd_cache); |
| 1952 | g_free(debug_info_msg_iter); |
| 1953 | |
| 1954 | end: |
| 1955 | return; |
| 1956 | } |
| 1957 | |
| 1958 | BT_HIDDEN |
| 1959 | bt_message_iterator_class_initialize_method_status debug_info_msg_iter_init( |
| 1960 | bt_self_message_iterator *self_msg_iter, |
| 1961 | bt_self_message_iterator_configuration *config, |
| 1962 | bt_self_component_port_output *self_port) |
| 1963 | { |
| 1964 | bt_message_iterator_class_initialize_method_status status; |
| 1965 | bt_message_iterator_create_from_message_iterator_status |
| 1966 | msg_iter_status; |
| 1967 | struct bt_self_component_port_input *input_port = NULL; |
| 1968 | bt_message_iterator *upstream_iterator = NULL; |
| 1969 | struct debug_info_msg_iter *debug_info_msg_iter = NULL; |
| 1970 | gchar *debug_info_field_name; |
| 1971 | int ret; |
| 1972 | bt_self_component *self_comp = |
| 1973 | bt_self_message_iterator_borrow_component(self_msg_iter); |
| 1974 | bt_logging_level log_level = bt_component_get_logging_level( |
| 1975 | bt_self_component_as_component(self_comp)); |
| 1976 | |
| 1977 | debug_info_msg_iter = g_new0(struct debug_info_msg_iter, 1); |
| 1978 | if (!debug_info_msg_iter) { |
| 1979 | status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; |
| 1980 | goto error; |
| 1981 | } |
| 1982 | |
| 1983 | debug_info_msg_iter->log_level = log_level; |
| 1984 | debug_info_msg_iter->self_comp = self_comp; |
| 1985 | |
| 1986 | debug_info_msg_iter->debug_info_component = |
| 1987 | bt_self_component_get_data(self_comp); |
| 1988 | |
| 1989 | /* Borrow the upstream input port. */ |
| 1990 | input_port = bt_self_component_filter_borrow_input_port_by_name( |
| 1991 | debug_info_msg_iter->debug_info_component->self_comp_filter, |
| 1992 | "in"); |
| 1993 | if (!input_port) { |
| 1994 | status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR; |
| 1995 | goto error; |
| 1996 | } |
| 1997 | |
| 1998 | /* Create an iterator on the upstream component. */ |
| 1999 | msg_iter_status = bt_message_iterator_create_from_message_iterator( |
| 2000 | self_msg_iter, input_port, &upstream_iterator); |
| 2001 | if (msg_iter_status != BT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_OK) { |
| 2002 | status = (int) msg_iter_status; |
| 2003 | goto error; |
| 2004 | } |
| 2005 | |
| 2006 | BT_MESSAGE_ITERATOR_MOVE_REF( |
| 2007 | debug_info_msg_iter->msg_iter, upstream_iterator); |
| 2008 | |
| 2009 | /* Create hashtable that will contain debug info mapping. */ |
| 2010 | debug_info_msg_iter->debug_info_map = g_hash_table_new_full( |
| 2011 | g_direct_hash, g_direct_equal, (GDestroyNotify) NULL, |
| 2012 | (GDestroyNotify) debug_info_destroy); |
| 2013 | if (!debug_info_msg_iter->debug_info_map) { |
| 2014 | status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; |
| 2015 | goto error; |
| 2016 | } |
| 2017 | |
| 2018 | debug_info_field_name = |
| 2019 | debug_info_msg_iter->debug_info_component->arg_debug_info_field_name; |
| 2020 | |
| 2021 | debug_info_msg_iter->ir_maps = trace_ir_maps_create(self_comp, |
| 2022 | debug_info_field_name, log_level); |
| 2023 | if (!debug_info_msg_iter->ir_maps) { |
| 2024 | status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; |
| 2025 | goto error; |
| 2026 | } |
| 2027 | |
| 2028 | ret = bt_fd_cache_init(&debug_info_msg_iter->fd_cache, log_level); |
| 2029 | if (ret) { |
| 2030 | status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; |
| 2031 | goto error; |
| 2032 | } |
| 2033 | |
| 2034 | bt_self_message_iterator_configuration_set_can_seek_forward(config, |
| 2035 | bt_message_iterator_can_seek_forward( |
| 2036 | debug_info_msg_iter->msg_iter)); |
| 2037 | |
| 2038 | bt_self_message_iterator_set_data(self_msg_iter, debug_info_msg_iter); |
| 2039 | debug_info_msg_iter->input_iterator = self_msg_iter; |
| 2040 | |
| 2041 | status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_OK; |
| 2042 | goto end; |
| 2043 | |
| 2044 | error: |
| 2045 | debug_info_msg_iter_destroy(debug_info_msg_iter); |
| 2046 | |
| 2047 | end: |
| 2048 | return status; |
| 2049 | } |
| 2050 | |
| 2051 | BT_HIDDEN |
| 2052 | bt_message_iterator_class_can_seek_beginning_method_status |
| 2053 | debug_info_msg_iter_can_seek_beginning(bt_self_message_iterator *self_msg_iter, |
| 2054 | bt_bool *can_seek) |
| 2055 | { |
| 2056 | struct debug_info_msg_iter *debug_info_msg_iter = |
| 2057 | bt_self_message_iterator_get_data(self_msg_iter); |
| 2058 | BT_ASSERT(debug_info_msg_iter); |
| 2059 | |
| 2060 | return (int) bt_message_iterator_can_seek_beginning( |
| 2061 | debug_info_msg_iter->msg_iter, can_seek); |
| 2062 | } |
| 2063 | |
| 2064 | BT_HIDDEN |
| 2065 | bt_message_iterator_class_seek_beginning_method_status |
| 2066 | debug_info_msg_iter_seek_beginning(bt_self_message_iterator *self_msg_iter) |
| 2067 | { |
| 2068 | struct debug_info_msg_iter *debug_info_msg_iter = |
| 2069 | bt_self_message_iterator_get_data(self_msg_iter); |
| 2070 | bt_message_iterator_class_seek_beginning_method_status status = |
| 2071 | BT_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHOD_STATUS_OK; |
| 2072 | bt_message_iterator_seek_beginning_status seek_beg_status; |
| 2073 | |
| 2074 | BT_ASSERT(debug_info_msg_iter); |
| 2075 | |
| 2076 | /* Ask the upstream component to seek to the beginning. */ |
| 2077 | seek_beg_status = bt_message_iterator_seek_beginning( |
| 2078 | debug_info_msg_iter->msg_iter); |
| 2079 | if (seek_beg_status != BT_MESSAGE_ITERATOR_SEEK_BEGINNING_STATUS_OK) { |
| 2080 | status = (int) seek_beg_status; |
| 2081 | goto end; |
| 2082 | } |
| 2083 | |
| 2084 | /* Clear this iterator data. */ |
| 2085 | trace_ir_maps_clear(debug_info_msg_iter->ir_maps); |
| 2086 | g_hash_table_remove_all(debug_info_msg_iter->debug_info_map); |
| 2087 | |
| 2088 | end: |
| 2089 | return status; |
| 2090 | } |
| 2091 | |
| 2092 | BT_HIDDEN |
| 2093 | void debug_info_msg_iter_finalize(bt_self_message_iterator *it) |
| 2094 | { |
| 2095 | struct debug_info_msg_iter *debug_info_msg_iter; |
| 2096 | |
| 2097 | debug_info_msg_iter = bt_self_message_iterator_get_data(it); |
| 2098 | BT_ASSERT(debug_info_msg_iter); |
| 2099 | |
| 2100 | debug_info_msg_iter_destroy(debug_info_msg_iter); |
| 2101 | } |