Beispiel #1
0
void
tui_field_string (struct ui_out *uiout,
		  int fldno,
		  int width,
		  enum ui_align align,
		  const char *fldname,
		  const char *string)
{
  int before = 0;
  int after = 0;

  tui_out_data *data = ui_out_data (uiout);
  if (data->suppress_output)
    return;

  if (fldname && data->line > 0 && strcmp (fldname, "file") == 0)
    {
      data->start_of_line ++;
      if (data->line > 0)
        {
          tui_show_source (string, data->line);
        }
      return;
    }
  
  data->start_of_line ++;
  if ((align != ui_noalign) && string)
    {
      before = width - strlen (string);
      if (before <= 0)
	before = 0;
      else
	{
	  if (align == ui_right)
	    after = 0;
	  else if (align == ui_left)
	    {
	      after = before;
	      before = 0;
	    }
	  else
	    /* ui_center */
	    {
	      after = before / 2;
	      before -= after;
	    }
	}
    }

  if (before)
    ui_out_spaces (uiout, before);
  if (string)
    out_field_fmt (uiout, fldno, fldname, "%s", string);
  if (after)
    ui_out_spaces (uiout, after);

  if (align != ui_noalign)
    field_separator ();
}
Beispiel #2
0
void
cli_field_string (struct ui_out *uiout,
		  int fldno,
		  int width,
		  enum ui_align align,
		  const char *fldname,
		  const char *string)
{
  int before = 0;
  int after = 0;

  struct ui_out_data *data = ui_out_data (uiout);
  if (data->suppress_output)
    return;

  if ((align != ui_noalign) && string)
    {
      before = width - strlen (string);
      if (before <= 0)
	before = 0;
      else
	{
	  if (align == ui_right)
	    after = 0;
	  else if (align == ui_left)
	    {
	      after = before;
	      before = 0;
	    }
	  else
	    /* ui_center */
	    {
	      after = before / 2;
	      before -= after;
	    }
	}
    }

  if (before)
    ui_out_spaces (uiout, before);
  if (string)
    out_field_fmt (uiout, fldno, fldname, "%s", string);
  if (after)
    ui_out_spaces (uiout, after);

  if (align != ui_noalign)
    field_separator ();
}
Beispiel #3
0
void
print_command_lines (struct ui_out *uiout, struct command_line *cmd,
		     unsigned int depth)
{
  struct command_line *list;

  list = cmd;
  while (list)
    {
      if (depth)
	ui_out_spaces (uiout, 2 * depth);

      /* A simple command, print it and continue.  */
      if (list->control_type == simple_control)
	{
	  ui_out_field_string (uiout, NULL, list->line);
	  ui_out_text (uiout, "\n");
	  list = list->next;
	  continue;
	}

      /* loop_continue to jump to the start of a while loop, print it
         and continue. */
      if (list->control_type == continue_control)
	{
	  ui_out_field_string (uiout, NULL, "loop_continue");
	  ui_out_text (uiout, "\n");
	  list = list->next;
	  continue;
	}

      /* loop_break to break out of a while loop, print it and
	 continue.  */
      if (list->control_type == break_control)
	{
	  ui_out_field_string (uiout, NULL, "loop_break");
	  ui_out_text (uiout, "\n");
	  list = list->next;
	  continue;
	}

      /* A while command.  Recursively print its subcommands and
	 continue.  */
      if (list->control_type == while_control
	  || list->control_type == while_stepping_control)
	{
	  /* For while-stepping, the line includes the 'while-stepping'
	     token.  See comment in process_next_line for explanation.
	     Here, take care not print 'while-stepping' twice.  */
	  if (list->control_type == while_control)
	    ui_out_field_fmt (uiout, NULL, "while %s", list->line);
	  else
	    ui_out_field_string (uiout, NULL, list->line);
	  ui_out_text (uiout, "\n");
	  print_command_lines (uiout, *list->body_list, depth + 1);
	  if (depth)
	    ui_out_spaces (uiout, 2 * depth);
	  ui_out_field_string (uiout, NULL, "end");
	  ui_out_text (uiout, "\n");
	  list = list->next;
	  continue;
	}

      /* An if command.  Recursively print both arms before
	 continueing.  */
      if (list->control_type == if_control)
	{
	  ui_out_field_fmt (uiout, NULL, "if %s", list->line);
	  ui_out_text (uiout, "\n");
	  /* The true arm.  */
	  print_command_lines (uiout, list->body_list[0], depth + 1);

	  /* Show the false arm if it exists.  */
	  if (list->body_count == 2)
	    {
	      if (depth)
		ui_out_spaces (uiout, 2 * depth);
	      ui_out_field_string (uiout, NULL, "else");
	      ui_out_text (uiout, "\n");
	      print_command_lines (uiout, list->body_list[1], depth + 1);
	    }

	  if (depth)
	    ui_out_spaces (uiout, 2 * depth);
	  ui_out_field_string (uiout, NULL, "end");
	  ui_out_text (uiout, "\n");
	  list = list->next;
	  continue;
	}

      /* A commands command.  Print the breakpoint commands and
	 continue.  */
      if (list->control_type == commands_control)
	{
	  if (*(list->line))
	    ui_out_field_fmt (uiout, NULL, "commands %s", list->line);
	  else
	    ui_out_field_string (uiout, NULL, "commands");
	  ui_out_text (uiout, "\n");
	  print_command_lines (uiout, *list->body_list, depth + 1);
	  if (depth)
	    ui_out_spaces (uiout, 2 * depth);
	  ui_out_field_string (uiout, NULL, "end");
	  ui_out_text (uiout, "\n");
	  list = list->next;
	  continue;
	}

      if (list->control_type == python_control)
	{
	  ui_out_field_string (uiout, NULL, "python");
	  ui_out_text (uiout, "\n");
	  /* Don't indent python code at all.  */
	  print_command_lines (uiout, *list->body_list, 0);
	  if (depth)
	    ui_out_spaces (uiout, 2 * depth);
	  ui_out_field_string (uiout, NULL, "end");
	  ui_out_text (uiout, "\n");
	  list = list->next;
	  continue;
	}

      /* Ignore illegal command type and try next.  */
      list = list->next;
    }				/* while (list) */
}
Beispiel #4
0
/*
 * Display a disassembled instruction with annotation
 */
static void print_one_insn(struct ca_dis_insn* insn, struct ui_out* uiout)
{
	int i, pos;
	struct ca_operand* dst_op;

	ui_out_text(uiout, insn->dis_string);

	pos = strlen(insn->dis_string);
	if (pos < MAX_SPACING)
		ui_out_spaces(uiout, MAX_SPACING - pos);
	ui_out_text(uiout, " ## ");

	if (insn->num_operand == 0)
	{
		ui_out_text(uiout, "\n");
		return;
	}

	// special case
	/*if (insn->call)
	{
		// reminder that $rax is set to return value after a "call" instruction
		// if the called function has an integer return value
		// (unfortunately return type is not known for a function)
		ui_out_text(uiout, "(%rax=? on return) ");
	}*/

	dst_op = &insn->operands[0];
	// annotation of object context
	if (insn->annotate)
	{
		size_t ptr_sz = g_ptr_bit >> 3;
		int has_value = 0;
		size_t val = 0xcdcdcdcd;
		int op_size = insn->op_size;
		const char* symname = NULL;
		struct win_type type = {0,0};
		int is_vptr         = 0;
		char* name_to_free = NULL;

		// update register context by "pc"
		set_current_reg_pointers(insn);

		// Get the instruction's destination value/symbol/type
		if (dst_op->type == CA_OP_MEMORY)
		{
			// if the destination is a known local variable
			if (is_stack_address(dst_op))
			{
				address_t addr = get_address(dst_op);
				struct ca_stack_var* sval = get_stack_var(addr);
				if (sval)
				{
					symname = sval->sym_name;
					type = sval->type;
				}
				else
				{
					/*struct symbol* sym;
					struct object_reference aref;
					memset(&aref, 0, sizeof(aref));
					aref.vaddr = addr;
					aref.value = 0;
					aref.target_index = -1;
					sym = get_stack_sym(&aref, NULL, NULL);
					if (sym)
					{
						symname = SYMBOL_PRINT_NAME (sym);
						type = SYMBOL_TYPE(sym);
					}*/
					get_stack_sym_and_type(addr, &symname, &type);
				}
			}
			// could it be a known heap object
			if (!symname && !type.mod_base)
			{
				// this function will allocate buffer for the symbol name if any, remember to free it
				get_op_symbol_type(dst_op, 0, &name_to_free, &type, NULL);
				symname = name_to_free;
			}
			// Since flag insn->annotate is set, dst_op's value should be calculated
			val = get_op_value(dst_op, op_size);
			has_value = 1;
		}
		else if (dst_op->type == CA_OP_REGISTER)
		{
			struct ca_reg_value* dst_reg = get_reg_at_pc(dst_op->reg.index, insn->pc);
			if (dst_reg)
			{
				symname = dst_reg->sym_name;
				type    = dst_reg->type;
				is_vptr = dst_reg->vptr;
				if (dst_reg->has_value)
				{
					has_value = 1;
					val = dst_reg->value;
				}
			}
		}
		else if (dst_op->type == CA_OP_IMMEDIATE)
		{
			val = get_op_value(dst_op, op_size);
			has_value = 1;
		}

		if (dst_op->type != CA_OP_IMMEDIATE)
		{
			// Name and value (if known) of destination
			print_one_operand(uiout, dst_op, op_size);
			if (has_value)
				ui_out_message(uiout, 0, "="PRINT_FORMAT_POINTER, val);
			else
				ui_out_text(uiout, "=?");
		}

		// Symbol or type of destination
		if (dst_op->type == CA_OP_REGISTER
			&& dst_op->reg.index == RSP)
		{
			if (val == g_debug_context.sp)
				ui_out_text(uiout, " End of function prologue");
			ui_out_text(uiout, "\n");
		}
		else
		{
			// symbol or type is known
			if (symname || type.mod_base)
			{
				ui_out_text(uiout, "(");
				if (symname)
				{
					ui_out_message(uiout, 0, "symbol=\"%s\"", symname);
				}
				if (type.mod_base)
				{
					//CHECK_TYPEDEF(type);
					if (symname)
						ui_out_text(uiout, " ");
					ui_out_text(uiout, "type=\"");
					/*if (is_vptr)
					{
						const char * type_name = type_name_no_tag(type);
						if (type_name)
							ui_out_message(uiout, 0, "vtable for %s", type_name);
						else
						{
							ui_out_text(uiout, "vtable for ");
							print_type_name (type);
						}
					}
					else*/
						print_type_name (type);
					ui_out_text(uiout, "\"");
				}
				ui_out_text(uiout, ")\n");
			}
			// whatever we can get form the value
			else
			{
				address_t location = 0;
				int offset = 0;

				//if (insn->num_operand > 1)
				//{
				//	struct ca_operand* src_op = &insn->operands[1];
				//	get_location(src_op, &location, &offset);
				//}

				print_op_value_context (val,
						op_size > 0 ? op_size : ptr_sz,
						location, offset, insn->lea);
			}
		}
		if (name_to_free)
			free (name_to_free);
	}