Esempio n. 1
0
int main(int argc, char *argv[])
{
    mod_t *m;
    void (*init) (int, char **);
    int (*deinit) (void);

    m = module_open(argv[1]);
    if (!m) {
        fprintf(stderr, "unable to open module %s: %s\n", argv[1], module_error());
        return 1;
    }

    if (!module_symbol(m, "init", (void **)&init)) {
        fprintf(stderr, "unable to find init function: %s\n", module_error());
        return 1;
    }

    init(argc - 2, &argv[2]);
    if (!module_symbol(m, "deinit", (void **)&deinit)) {
        fprintf(stderr, "unable to find deinit function: %s\n", module_error());
        return 1;
    }

    return deinit();
}
Esempio n. 2
0
/*
 *  Try to set a crash scope block based upon the vaddr.   
 */
int
gdb_set_crash_scope(ulong vaddr, char *arg)
{
        struct gnu_request request, *req = &request;
	char name[BUFSIZE];
	struct load_module *lm;

	if (!is_kernel_text(vaddr)) {
		error(INFO, "invalid text address: %s\n", arg);
		return FALSE;
	}

	if (module_symbol(vaddr, NULL, &lm, name, 0)) {
		if (!(lm->mod_flags & MOD_LOAD_SYMS)) {
			error(INFO, "attempting to find/load \"%s\" module debuginfo\n", 
				lm->mod_name);
			if (!load_module_symbols_helper(lm->mod_name)) {
				error(INFO, "cannot find/load \"%s\" module debuginfo\n", 
					lm->mod_name);
				return FALSE;
			}
		}
	}

	req->command = GNU_SET_CRASH_BLOCK;
	req->addr = vaddr;
	req->flags = 0;
	req->addr2 = 0;
	gdb_command_funnel(req);    

	if (CRASHDEBUG(1))
		fprintf(fp, 
		    "gdb_set_crash_scope: %s  addr: %lx  block: %lx\n",
			req->flags & GNU_COMMAND_FAILED ? "FAILED" : "OK",  
			req->addr, req->addr2);

	if (req->flags & GNU_COMMAND_FAILED) {
		error(INFO, 
			"gdb cannot find text block for address: %s\n", arg);
		return FALSE;
	}

	return TRUE;
}
Esempio n. 3
0
int
loadVpiModule (const char* modulename)
{
  static void *libghdlvpi_mod;
  int i;
  void *vpimod;

  fprintf (stderr, "loading VPI module '%s'\n", modulename);

  /* TODO: on windows, use SetDllDirectory with:
     - install dir (libdir) => add -DLIBDIR=xxx
     - exec path\lib => see windows_default_path
  */

  vpimod = module_open (modulename);

  if (vpimod == NULL)
    {
      const char *msg = module_error ();

      fprintf (stderr, "%s\n", msg == NULL ? "unknown dlopen error" : msg);
      return -1;
    }

  /* Try to load the libghdlvpi library and set the thunk.
     No need to load the library several times.  */
  if (libghdlvpi_mod == NULL)
    {
      libghdlvpi_mod = module_open (libghdlvpi_name);
      if (libghdlvpi_mod != NULL)
	{
	  vpi_thunk **vpi_thunk_ptr;

	  for (i = 0; i < 2; i++)
	    {
	      vpi_thunk_ptr = module_symbol (libghdlvpi_mod, &"_VPI_THUNK"[i]);

	      if (vpi_thunk_ptr != NULL)
		{
		  *vpi_thunk_ptr = &__ghdl_vpi_thunk_v1;
		  break;
		}
	    }
	  if (vpi_thunk_ptr == NULL)
	    fprintf (stderr, "warning: VPI_THUNK not found in %s\n",
		     libghdlvpi_name);
	}
    }

  for (i = 0; i < 2; i++) // try with and w/o leading underscores
    {
      void *vpitable = module_symbol (vpimod, &"_vlog_startup_routines"[i]);

      if (vpitable)
	{
	  unsigned int j;
	  typedef void (*vlog_startup_routines_t)(void);
	  vlog_startup_routines_t *vpifuns;

	  vpifuns = (vlog_startup_routines_t*)vpitable;
	  for (j = 0; vpifuns[j]; j++)
	    vpifuns[j]();

	  fprintf (stderr, "VPI module loaded!\n");
	  return 0; // successfully registered VPI module
	}
    }
  fprintf (stderr, "vlog_startup_routines not found\n");
  return -1; // failed to register VPI module
}