Пример #1
0
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(&lttngtop, 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);
		}
	}
}
Пример #2
0
static struct traceframe_info *
ctf_traceframe_info (struct target_ops *self)
{
  struct traceframe_info *info = XCNEW (struct traceframe_info);
  const char *name;
  struct bt_iter_pos *pos;

  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);

  do
    {
      struct bt_ctf_event *event
	= bt_ctf_iter_read_event (ctf_iter);

      name = bt_ctf_event_name (event);

      if (name == NULL || strcmp (name, "register") == 0
	  || strcmp (name, "frame") == 0)
	;
      else if (strcmp (name, "memory") == 0)
	{
	  const struct bt_definition *scope
	    = bt_ctf_get_top_level_scope (event,
					  BT_EVENT_FIELDS);
	  const struct bt_definition *def;
	  struct mem_range *r;

	  r = VEC_safe_push (mem_range_s, info->memory, NULL);
	  def = bt_ctf_get_field (event, scope, "address");
	  r->start = bt_ctf_get_uint64 (def);

	  def = bt_ctf_get_field (event, scope, "length");
	  r->length = (uint16_t) bt_ctf_get_uint64 (def);
	}
      else if (strcmp (name, "tsv") == 0)
	{
	  int vnum;
	  const struct bt_definition *scope
	    = bt_ctf_get_top_level_scope (event,
					  BT_EVENT_FIELDS);
	  const struct bt_definition *def;

	  def = bt_ctf_get_field (event, scope, "num");
	  vnum = (int) bt_ctf_get_int64 (def);
	  VEC_safe_push (int, info->tvars, vnum);
	}
      else
	{
	  warning (_("Unhandled trace block type (%s) "
		     "while building trace frame info."),
		   name);
	}

      if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
	break;
    }
Пример #3
0
static void
ctf_read_tsv (struct uploaded_tsv **uploaded_tsvs)
{
  gdb_assert (ctf_iter != NULL);

  while (1)
    {
      struct bt_ctf_event *event;
      const struct bt_definition *scope;
      const struct bt_definition *def;
      uint32_t event_id;
      struct uploaded_tsv *utsv = NULL;

      event = bt_ctf_iter_read_event (ctf_iter);
      scope = bt_ctf_get_top_level_scope (event,
					  BT_STREAM_EVENT_HEADER);
      event_id = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope,
						      "id"));
      if (event_id != CTF_EVENT_ID_TSV_DEF)
	break;

      scope = bt_ctf_get_top_level_scope (event,
					  BT_EVENT_FIELDS);

      def = bt_ctf_get_field (event, scope, "number");
      utsv = get_uploaded_tsv ((int32_t) bt_ctf_get_int64 (def),
			       uploaded_tsvs);

      def = bt_ctf_get_field (event, scope, "builtin");
      utsv->builtin = (int32_t) bt_ctf_get_int64 (def);
      def = bt_ctf_get_field (event, scope, "initial_value");
      utsv->initial_value = bt_ctf_get_int64 (def);

      def = bt_ctf_get_field (event, scope, "name");
      utsv->name =  xstrdup (bt_ctf_get_string (def));

      if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
	break;
    }

}
Пример #4
0
static void
ctf_read_tp (struct uploaded_tp **uploaded_tps)
{
  gdb_assert (ctf_iter != NULL);

  while (1)
    {
      struct bt_ctf_event *event;
      const struct bt_definition *scope;
      uint32_t u32;
      int32_t int32;
      uint64_t u64;
      struct uploaded_tp *utp = NULL;

      event = bt_ctf_iter_read_event (ctf_iter);
      scope = bt_ctf_get_top_level_scope (event,
					  BT_STREAM_EVENT_HEADER);
      u32 = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope,
						 "id"));
      if (u32 != CTF_EVENT_ID_TP_DEF)
	break;

      scope = bt_ctf_get_top_level_scope (event,
					  BT_EVENT_FIELDS);
      int32 = (int32_t) bt_ctf_get_int64 (bt_ctf_get_field (event,
							    scope,
							    "number"));
      u64 = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope,
						 "addr"));
      utp = get_uploaded_tp (int32, u64,  uploaded_tps);

      SET_INT32_FIELD (event, scope, utp, enabled);
      SET_INT32_FIELD (event, scope, utp, step);
      SET_INT32_FIELD (event, scope, utp, pass);
      SET_INT32_FIELD (event, scope, utp, hit_count);
      SET_INT32_FIELD (event, scope, utp, type);

      /* Read 'cmd_strings'.  */
      SET_ARRAY_FIELD (event, scope, utp, cmd_num, cmd_strings);
      /* Read 'actions'.  */
      SET_ARRAY_FIELD (event, scope, utp, action_num, actions);
      /* Read 'step_actions'.  */
      SET_ARRAY_FIELD (event, scope, utp, step_action_num,
		       step_actions);

      SET_STRING_FIELD(event, scope, utp, at_string);
      SET_STRING_FIELD(event, scope, utp, cond_string);

      if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
	break;
    }
}
Пример #5
0
uint64_t get_context_ppid(const struct bt_ctf_event *event)
{
	const struct definition *scope;
	uint64_t ppid;

	scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT);
	ppid = bt_ctf_get_int64(bt_ctf_get_field(event,
				scope, "_ppid"));
	if (bt_ctf_field_get_error()) {
		fprintf(stderr, "Missing ppid context info\n");
		return -1ULL;
	}

	return ppid;
}
Пример #6
0
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;
}
Пример #7
0
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;
}
Пример #8
0
/*
 * hook on each event to check the timestamp and refresh the display if
 * necessary
 */
enum bt_cb_ret textdump(struct bt_ctf_event *call_data, void *private_data)
{
	unsigned long timestamp;
	uint64_t delta;
	struct tm start;
	uint64_t ts_nsec_start;
	int pid, cpu_id, tid, ret, lookup, current_syscall = 0;
	const struct bt_definition *scope;
	const char *hostname, *procname;
	struct cputime *cpu;
	char *from_syscall = NULL;
	int syscall_exit = 0;

	timestamp = bt_ctf_get_timestamp(call_data);

	/* can happen in network live when tracing is idle */
	if (timestamp < last_event_ts)
		goto end_stop;

	last_event_ts = timestamp;

	start = format_timestamp(timestamp);
	ts_nsec_start = timestamp % NSEC_PER_SEC;

	pid = get_context_pid(call_data);
	if (pid == -1ULL && opt_tid) {
		goto error;
	}

	tid = get_context_tid(call_data);
	
	hostname = get_context_hostname(call_data);
	if (opt_child)
		lookup = pid;
	else
		lookup = tid;
	if (opt_tid || opt_procname || opt_exec_name) {
		if (!lookup_filter_tid_list(lookup)) {
			/* To display when a process of ours in getting scheduled in */
			if (strcmp(bt_ctf_event_name(call_data), "sched_switch") == 0) {
				int next_tid;

				scope = bt_ctf_get_top_level_scope(call_data,
						BT_EVENT_FIELDS);
				next_tid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
							scope, "_next_tid"));
				if (bt_ctf_field_get_error()) {
					fprintf(stderr, "Missing next_tid field\n");
					goto error;
				}
				if (!lookup_filter_tid_list(next_tid)) {
					if (!opt_all)
						goto end;
				} else {
					if (opt_all)
						fprintf(output, "%c[1m", 27);
				}
			} else if (!opt_all) {
				goto end;
			}
		} else {
			if (opt_all)
				fprintf(output, "%c[1m", 27);
		}
	}

	if (((strncmp(bt_ctf_event_name(call_data),
						"exit_syscall", 12)) == 0) ||
			((strncmp(bt_ctf_event_name(call_data),
				 "syscall_exit", 12)) == 0)) {
		syscall_exit = 1;
	}

	if (last_syscall && !syscall_exit) {
		last_syscall = NULL;
		fprintf(output, " ...interrupted...\n");
	}

	cpu_id = get_cpu_id(call_data);
	procname = get_context_comm(call_data);
	if ((strncmp(bt_ctf_event_name(call_data), "sys_", 4) == 0) ||
			(strncmp(bt_ctf_event_name(call_data), "syscall_entry", 13) == 0)){
		cpu = get_cpu(cpu_id);
		cpu->current_syscall = g_new0(struct syscall, 1);
		cpu->current_syscall->name = strdup(bt_ctf_event_name(call_data));
		cpu->current_syscall->ts_start = timestamp;
		cpu->current_syscall->cpu_id = cpu_id;
		last_syscall = cpu->current_syscall;
		current_syscall = 1;
	} else if (syscall_exit) {