Esempio n. 1
0
int main(int argc, char *argv[])
{
	WSADATA data;
	int index;
	DBG *d = dbg_init();

	WSAStartup(MAKEWORD(2, 2), &data);
	dbg_open_stream(d, stderr);
	dbg_open_stream(d, stdout);
	dbg_open_dummy(d);
	index = dbg_open_net(d, "localhost", 8888);
	dbg_open_file(d, "log.txt");

	dbg_open_stream(d, stderr);

	dbg_open_custom(d, WriteToMessageBox);
	dbg_printf_raw(d, "Hello %s", "World");
	dbg_hexdump_ascii(d, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", strlen("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
	dbg_switch(d, 0);
	dbg_hexdump(d, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", strlen("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
	dbg_switch(d, 1);
	dbg_hexdump_ascii(d, (const unsigned char *) d, sizeof(*d));
	dbg_close(d);
	return 0;
}
Esempio n. 2
0
File: edbg.c Progetto: arv3/edbg
//-----------------------------------------------------------------------------
void error_exit(char *fmt, ...)
{
  va_list args;

  dbg_close();

  va_start(args, fmt);
  fprintf(stderr, "Error: ");
  vfprintf(stderr, fmt, args);
  fprintf(stderr, "\n");
  va_end(args);

  exit(1);
}
Esempio n. 3
0
File: edbg.c Progetto: arv3/edbg
//-----------------------------------------------------------------------------
void check(bool cond, char *fmt, ...)
{
  if (!cond)
  {
    va_list args;

    dbg_close();

    va_start(args, fmt);
    fprintf(stderr, "Error: ");
    vfprintf(stderr, fmt, args);
    fprintf(stderr, "\n");
    va_end(args);

    exit(1);
  }
}
Esempio n. 4
0
/**
 * Set debug logfile
 *
 * @param name Name of the logfile, NULL to close
 *
 * @return 0 if success, otherwise errorcode
 */
int dbg_logfile_set(const char *name)
{
	time_t t;

	dbg_close();

	if (!name)
		return 0;

	dbg.f = fopen(name, "a+");
	if (!dbg.f)
		return errno;

	(void)time(&t);
	(void)re_fprintf(dbg.f, "\n===== Log Started: %s", ctime(&t));
	(void)fflush(dbg.f);

	return 0;
}
Esempio n. 5
0
File: edbg.c Progetto: arv3/edbg
//-----------------------------------------------------------------------------
int main(int argc, char **argv)
{
  debugger_t debuggers[MAX_DEBUGGERS];
  int n_debuggers = 0;
  int debugger = -1;
  target_t *target;

  parse_command_line(argc, argv);

  if (!(g_erase || g_program || g_verify || g_lock || g_read || g_list || g_target))
    error_exit("no actions specified");

  if (g_read && (g_erase || g_program || g_verify || g_lock))
    error_exit("mutually exclusive actions specified");

  n_debuggers = dbg_enumerate(debuggers, MAX_DEBUGGERS);

  if (g_list)
  {
    printf("Attached debuggers:\n");
    for (int i = 0; i < n_debuggers; i++)
      printf("  %s - %s %s\n", debuggers[i].serial, debuggers[i].manufacturer, debuggers[i].product);
    return 0;
  }

  if (NULL == g_target)
    error_exit("no target type specified (use '-t' option)");

  if (0 == strcmp("list", g_target))
  {
    target_list();
    return 0;
  }

  target = target_get_ops(g_target);

  if (g_serial)
  {
    for (int i = 0; i < n_debuggers; i++)
    {
      if (0 == strcmp(debuggers[i].serial, g_serial))
      {
        debugger = i;
        break;
      }
    }

    if (-1 == debugger)
      error_exit("unable to find a debugger with a specified serial number");
  }

  if (0 == n_debuggers)
    error_exit("no debuggers found");
  else if (1 == n_debuggers)
    debugger = 0;
  else if (n_debuggers > 1 && -1 == debugger)
    error_exit("more than one debugger found, please specify a serial number");

  dbg_open(&debuggers[debugger]);

  dap_disconnect();
  dap_get_debugger_info();
  dap_connect();
  dap_transfer_configure(0, 128, 128);
  dap_swd_configure(0);
  dap_led(0, 1);
  dap_reset_link();
  dap_swj_clock(DAP_FREQ);
  dap_target_prepare();

  target->ops->select();

  if (g_erase)
    target->ops->erase();

  if (g_program)
    target->ops->program(g_file);

  if (g_verify)
    target->ops->verify(g_file);

  if (g_lock)
    target->ops->lock();

  if (g_read)
    target->ops->read(g_file);

  target->ops->deselect();

  dap_disconnect();
  dap_led(0, 0);

  dbg_close();

  return 0;
}
Esempio n. 6
0
File: edbg.c Progetto: arv3/edbg
//-----------------------------------------------------------------------------
void perror_exit(char *text)
{
  dbg_close();
  perror(text);
  exit(1);
}