void print_fields(struct bt_ctf_event *event, const char *procname, int pid) { unsigned int cnt, i; const struct bt_definition *const * list; const struct bt_declaration *l; const struct bt_definition *scope; enum ctf_type_id type; const char *str; struct processtop *current_proc; struct files *current_file; int fd, fd_value = -1; scope = bt_ctf_get_top_level_scope(event, BT_EVENT_FIELDS); bt_ctf_get_field_list(event, scope, &list, &cnt); for (i = 0; i < cnt; i++) { if (i != 0) fprintf(output, ", "); fprintf(output, "%s = ", bt_ctf_field_name(list[i])); l = bt_ctf_get_decl_from_def(list[i]); if (strncmp(bt_ctf_field_name(list[i]), "fd", 2) == 0) fd = 1; else fd = 0; type = bt_ctf_field_type(l); if (type == CTF_TYPE_INTEGER) { if (bt_ctf_get_int_signedness(l) == 0) { fd_value = bt_ctf_get_uint64(list[i]); fprintf(output, "%" PRIu64, bt_ctf_get_uint64(list[i])); } else { fd_value = bt_ctf_get_int64(list[i]); fprintf(output, "%" PRId64, bt_ctf_get_int64(list[i])); } } else if (type == CTF_TYPE_STRING) { fprintf(output, "%s", bt_ctf_get_string(list[i])); } else if (type == CTF_TYPE_ARRAY) { str = bt_ctf_get_char_array(list[i]); if (!bt_ctf_field_get_error() && str) fprintf(output, "%s", str); } if (fd) { current_proc = find_process_tid(<tngtop, pid, procname); if (!current_proc) continue; current_file = get_file(current_proc, fd_value); if (!current_file || !current_file->name) continue; fprintf(output, "<%s>", current_file->name); } } }
char *get_context_comm(const struct bt_ctf_event *event) { const struct definition *scope; char *comm; scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT); comm = bt_ctf_get_char_array(bt_ctf_get_field(event, scope, "_procname")); if (bt_ctf_field_get_error()) { fprintf(stderr, "Missing comm context info\n"); return NULL; } return comm; }
int getFields(struct bt_ctf_event *ctf_event, struct bt_definition const *fields, GString* fieldsStr) { enum ctf_type_id fieldType = bt_ctf_field_type(bt_ctf_get_decl_from_def(fields)); int ret = 0, isSigned = -1, len = 0, i = 0; const struct bt_definition *index_def; switch (fieldType) { case CTF_TYPE_INTEGER: isSigned = bt_ctf_get_int_signedness(bt_ctf_get_decl_from_def(fields)); if (isSigned == 1) { g_string_append_printf(fieldsStr, "%lu", bt_ctf_get_int64(fields)); } else if (isSigned == 0) { g_string_append_printf(fieldsStr, "%" PRIu64 , bt_ctf_get_uint64(fields)); } break; case CTF_TYPE_STRING: g_string_append_printf(fieldsStr, "%s", bt_ctf_get_string(fields)); break; case CTF_TYPE_ARRAY: g_string_append_printf(fieldsStr, "[ "); len = bt_ctf_get_array_len(bt_ctf_get_decl_from_def(fields)); if ((index_def = bt_ctf_get_index(ctf_event, fields, i))) { for (i = 0; i < len; i++) { if (i > 0) { g_string_append_printf(fieldsStr, ", "); } //bt_ctf_field_type( bt_ctf_get_index(ctf_event, fields, i)); g_string_append_printf(fieldsStr, " "); g_string_append_printf(fieldsStr, "[%d] = ",i); getFields(ctf_event, bt_ctf_get_index(ctf_event, fields, i), fieldsStr); } } else { g_string_append_printf(fieldsStr, "%s", bt_ctf_get_char_array(fields)); } g_string_append_printf(fieldsStr, " ]"); break; case CTF_TYPE_UNKNOWN: g_string_append_printf(fieldsStr, "TYPE UNKNOWN"); default: g_string_append_printf(fieldsStr, "TYPE UNIMP %i",fieldType ); break; } return ret; }
static void ctf_fetch_registers (struct target_ops *ops, struct regcache *regcache, int regno) { struct gdbarch *gdbarch = get_regcache_arch (regcache); struct bt_ctf_event *event = NULL; struct bt_iter_pos *pos; /* An uninitialized reg size says we're not going to be successful at getting register blocks. */ if (trace_regblock_size == 0) return; gdb_assert (ctf_iter != NULL); /* Save the current position. */ pos = bt_iter_get_pos (bt_ctf_get_iter (ctf_iter)); gdb_assert (pos->type == BT_SEEK_RESTORE); while (1) { const char *name; struct bt_ctf_event *event1; event1 = bt_ctf_iter_read_event (ctf_iter); name = bt_ctf_event_name (event1); if (name == NULL || strcmp (name, "frame") == 0) break; else if (strcmp (name, "register") == 0) { event = event1; break; } if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0) break; } /* Restore the position. */ bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos); if (event != NULL) { int offset, regsize, regn; const struct bt_definition *scope = bt_ctf_get_top_level_scope (event, BT_EVENT_FIELDS); const struct bt_definition *array = bt_ctf_get_field (event, scope, "contents"); gdb_byte *regs = (gdb_byte *) bt_ctf_get_char_array (array); /* Assume the block is laid out in GDB register number order, each register with the size that it has in GDB. */ offset = 0; for (regn = 0; regn < gdbarch_num_regs (gdbarch); regn++) { regsize = register_size (gdbarch, regn); /* Make sure we stay within block bounds. */ if (offset + regsize >= trace_regblock_size) break; if (regcache_register_status (regcache, regn) == REG_UNKNOWN) { if (regno == regn) { regcache_raw_supply (regcache, regno, regs + offset); break; } else if (regno == -1) { regcache_raw_supply (regcache, regn, regs + offset); } } offset += regsize; } } else tracefile_fetch_registers (regcache, regno); }
int getProcessInfosFromEvent(LttvEvent *event, GString* processInfos) { int pid=0, tid=0, ppid=0; const char *procname; unsigned long timestamp; int ret = 0; gboolean noError = TRUE; guint cpu; LttvTraceState *state = event->state; LttvProcessState *process; struct bt_ctf_event *ctf_event = event->bt_event; cpu = lttv_traceset_get_cpuid_from_event(event); process = state->running_process[cpu]; timestamp = bt_ctf_get_timestamp(ctf_event); pid = process->pid; tid = process->tgid; ppid = process->ppid; procname = g_quark_to_string(process->name); if (timestamp == -1ULL) { noError = FALSE; } #if 0 if (noError) { scope = bt_ctf_get_top_level_scope(ctf_event, BT_STREAM_EVENT_CONTEXT); if (bt_ctf_field_get_error()) { noError = FALSE; } } if (noError) { pid = bt_ctf_get_int64(bt_ctf_get_field(ctf_event, scope, "_pid")); if (bt_ctf_field_get_error()) { noError = FALSE; } } if (noError) { tid = bt_ctf_get_int64(bt_ctf_get_field(ctf_event, scope, "_tid")); if (bt_ctf_field_get_error()) { noError = FALSE; } } if (noError) { ppid = bt_ctf_get_int64(bt_ctf_get_field(ctf_event, scope, "_ppid")); if (bt_ctf_field_get_error()) { noError = FALSE; } } if (noError) { procname = bt_ctf_get_char_array(bt_ctf_get_field(ctf_event, scope, "_procname")); if (bt_ctf_field_get_error()) { noError = FALSE; } } #endif if (noError||1) { g_string_append_printf(processInfos, "%u, %u, %s, %u. %s, %s", pid, tid, procname, ppid, g_quark_to_string(process->state->t), g_quark_to_string(process->state->s)); } else { ret = -1; } return ret; }