Beispiel #1
0
void lttv_event_to_string(LttvEvent *event, GString *a_string,
				gboolean field_names, gboolean long_version)
{
	GString* processInfos = g_string_new("");
	GString* fields = g_string_new("");
	GString* cpuId_str = g_string_new("");

	getProcessInfosFromEvent(event, processInfos);
	getFieldsFromEvent(event->bt_event, fields, field_names);
	getCPUIdFromEvent(event, cpuId_str);

	g_string_set_size(a_string,0);
	if(long_version){
		g_string_append_printf(a_string,"%" PRIu64 " %s: ", 
				       bt_ctf_get_timestamp(event->bt_event), 
				       bt_ctf_event_name(event->bt_event));
	}
	g_string_append_printf(a_string, "{ %s }", cpuId_str->str);
	
	if (strcmp("", processInfos->str) < 0) {
		g_string_append_printf(a_string, ", { %s }", processInfos->str);
	}
	if (strcmp("", fields->str) < 0) {
		g_string_append_printf(a_string, ", { %s }", fields->str);
	}

	g_string_free(fields, TRUE);
	g_string_free(processInfos, TRUE);
	g_string_free(cpuId_str, TRUE);
}
Beispiel #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;
    }
Beispiel #3
0
static int
ctf_get_trace_state_variable_value (struct target_ops *self,
				    int tsvnum, LONGEST *val)
{
  struct bt_iter_pos *pos;
  int found = 0;

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

  /* Iterate through the traceframe's blocks, looking for 'V'
     block.  */
  while (1)
    {
      struct bt_ctf_event *event
	= bt_ctf_iter_read_event (ctf_iter);
      const char *name = bt_ctf_event_name (event);

      if (name == NULL || strcmp (name, "frame") == 0)
	break;
      else if (strcmp (name, "tsv") == 0)
	{
	  const struct bt_definition *scope;
	  const struct bt_definition *def;

	  scope = bt_ctf_get_top_level_scope (event,
					      BT_EVENT_FIELDS);

	  def = bt_ctf_get_field (event, scope, "num");
	  if (tsvnum == (int32_t) bt_ctf_get_uint64 (def))
	    {
	      def = bt_ctf_get_field (event, scope, "val");
	      *val = bt_ctf_get_uint64 (def);

	      found = 1;
	    }
	}

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

  return found;
}
Beispiel #4
0
static CORE_ADDR
ctf_get_traceframe_address (void)
{
  struct bt_ctf_event *event = NULL;
  struct bt_iter_pos *pos;
  CORE_ADDR addr = 0;

  gdb_assert (ctf_iter != NULL);
  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)
	break;
      else if (strcmp (name, "frame") == 0)
	{
	  event = event1;
	  break;
	}

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

  if (event != NULL)
    {
      int tpnum = ctf_get_tpnum_from_frame_event (event);
      struct tracepoint *tp
	= get_tracepoint_by_number_on_target (tpnum);

      if (tp && tp->base.loc)
	addr = tp->base.loc->address;
    }

  /* Restore the position.  */
  bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos);

  return addr;
}
Beispiel #5
0
static int
ctf_trace_find (struct target_ops *self, enum trace_find_type type, int num,
		CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
{
  int ret = -1;
  int tfnum = 0;
  int found = 0;
  struct bt_iter_pos pos;

  if (num == -1)
    {
      if (tpp != NULL)
	*tpp = -1;
      return -1;
    }

  gdb_assert (ctf_iter != NULL);
  /* Set iterator back to the start.  */
  bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), start_pos);

  while (1)
    {
      int id;
      struct bt_ctf_event *event;
      const char *name;

      event = bt_ctf_iter_read_event (ctf_iter);

      name = bt_ctf_event_name (event);

      if (event == NULL || name == NULL)
	break;

      if (strcmp (name, "frame") == 0)
	{
	  CORE_ADDR tfaddr;

	  if (type == tfind_number)
	    {
	      /* Looking for a specific trace frame.  */
	      if (tfnum == num)
		found = 1;
	    }
	  else
	    {
	      /* Start from the _next_ trace frame.  */
	      if (tfnum > get_traceframe_number ())
		{
		  switch (type)
		    {
		    case tfind_tp:
		      {
			struct tracepoint *tp = get_tracepoint (num);

			if (tp != NULL
			    && (tp->number_on_target
				== ctf_get_tpnum_from_frame_event (event)))
			  found = 1;
			break;
		      }
		    case tfind_pc:
		      tfaddr = ctf_get_traceframe_address ();
		      if (tfaddr == addr1)
			found = 1;
		      break;
		    case tfind_range:
		      tfaddr = ctf_get_traceframe_address ();
		      if (addr1 <= tfaddr && tfaddr <= addr2)
			found = 1;
		      break;
		    case tfind_outside:
		      tfaddr = ctf_get_traceframe_address ();
		      if (!(addr1 <= tfaddr && tfaddr <= addr2))
			found = 1;
		      break;
		    default:
		      internal_error (__FILE__, __LINE__, _("unknown tfind type"));
		    }
		}
	    }
	  if (found)
	    {
	      if (tpp != NULL)
		*tpp = ctf_get_tpnum_from_frame_event (event);

	      /* Skip the event "frame".  */
	      bt_iter_next (bt_ctf_get_iter (ctf_iter));

	      return tfnum;
	    }
	  tfnum++;
	}

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

  return -1;
}
Beispiel #6
0
static enum target_xfer_status
ctf_xfer_partial (struct target_ops *ops, enum target_object object,
		  const char *annex, gdb_byte *readbuf,
		  const gdb_byte *writebuf, ULONGEST offset,
		  ULONGEST len, ULONGEST *xfered_len)
{
  /* We're only doing regular memory for now.  */
  if (object != TARGET_OBJECT_MEMORY)
    return -1;

  if (readbuf == NULL)
    error (_("ctf_xfer_partial: trace file is read-only"));

  if (get_traceframe_number () != -1)
    {
      struct bt_iter_pos *pos;
      int i = 0;
      enum target_xfer_status res;
      /* Records the lowest available address of all blocks that
	 intersects the requested range.  */
      ULONGEST low_addr_available = 0;

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

      /* Iterate through the traceframe's blocks, looking for
	 memory.  */
      while (1)
	{
	  ULONGEST amt;
	  uint64_t maddr;
	  uint16_t mlen;
	  enum bfd_endian byte_order
	    = gdbarch_byte_order (target_gdbarch ());
	  const struct bt_definition *scope;
	  const struct bt_definition *def;
	  struct bt_ctf_event *event
	    = bt_ctf_iter_read_event (ctf_iter);
	  const char *name = bt_ctf_event_name (event);

	  if (name == NULL || strcmp (name, "frame") == 0)
	    break;
	  else if (strcmp (name, "memory") != 0)
	    {
	      if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
		break;

	      continue;
	    }

	  scope = bt_ctf_get_top_level_scope (event,
					      BT_EVENT_FIELDS);

	  def = bt_ctf_get_field (event, scope, "address");
	  maddr = bt_ctf_get_uint64 (def);
	  def = bt_ctf_get_field (event, scope, "length");
	  mlen = (uint16_t) bt_ctf_get_uint64 (def);

	  /* If the block includes the first part of the desired
	     range, return as much it has; GDB will re-request the
	     remainder, which might be in a different block of this
	     trace frame.  */
	  if (maddr <= offset && offset < (maddr + mlen))
	    {
	      const struct bt_definition *array
		= bt_ctf_get_field (event, scope, "contents");
	      const struct bt_declaration *decl
		= bt_ctf_get_decl_from_def (array);
	      gdb_byte *contents;
	      int k;

	      contents = xmalloc (mlen);

	      for (k = 0; k < mlen; k++)
		{
		  const struct bt_definition *element
		    = bt_ctf_get_index (event, array, k);

		  contents[k] = (gdb_byte) bt_ctf_get_uint64 (element);
		}

	      amt = (maddr + mlen) - offset;
	      if (amt > len)
		amt = len;

	      memcpy (readbuf, &contents[offset - maddr], amt);

	      xfree (contents);

	      /* Restore the position.  */
	      bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos);

	      if (amt == 0)
		return TARGET_XFER_EOF;
	      else
		{
		  *xfered_len = amt;
		  return TARGET_XFER_OK;
		}
	    }

	  if (offset < maddr && maddr < (offset + len))
	    if (low_addr_available == 0 || low_addr_available > maddr)
	      low_addr_available = maddr;

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

      /* Requested memory is unavailable in the context of traceframes,
	 and this address falls within a read-only section, fallback
	 to reading from executable, up to LOW_ADDR_AVAILABLE  */
      if (offset < low_addr_available)
	len = min (len, low_addr_available - offset);
      res = exec_read_partial_read_only (readbuf, offset, len, xfered_len);

      if (res == TARGET_XFER_OK)
	return TARGET_XFER_OK;
      else
	{
	  /* No use trying further, we know some memory starting
	     at MEMADDR isn't available.  */
	  *xfered_len = len;
	  return TARGET_XFER_UNAVAILABLE;
	}
    }
  else
    {
      /* Fallback to reading from read-only sections.  */
      return section_table_read_available_memory (readbuf, offset, len, xfered_len);
    }
}
Beispiel #7
0
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);
}
Beispiel #8
0
const char *lttv_traceset_get_name_from_event(LttvEvent *event)
{
  	return bt_ctf_event_name(event->bt_event);
}
Beispiel #9
0
void lttv_event_get_name(LttvEvent *event,GString *a_string)
{
	g_string_set_size(a_string,0);
	g_string_append_printf(a_string, " %s", bt_ctf_event_name(event->bt_event));
}
Beispiel #10
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) {