On Monday 30 November 2009, Zachary T Welch wrote:
> Adds a fully-documented API for dynamically loading libraries and
> looking up symbols or addresses in them.

Seems to me I've seen one or two or three or four of these
before ... must there be another??  I know that portability
of such things to non-UNIXey environments has been painful.

I'm used to seeing systems either stick to the "libdl" stuff,
or use some multiplatform beast which tracks all of the
platform-specific annoyances.

Also, I'm a bit uneasy at the notion of adding this, so I hope
this doesn't merge unless it gets a lot better understood.

What's the intended change which will have us loading
modules?  What modules  would be loaded?


Plus:

> +struct module_symbol *module_symbol_by_addr(void *addr)
> +{
> +     struct module_symbol *sym = calloc(1, sizeof(*sym));
> +     if (NULL == sym)
> +             return NULL;
> +
> +     Dl_info info;
> +     int retval = dladdr(addr, &info);

As noted, not very portable ...


> +     if (0 == retval)
> +     {
> +             free(sym);
> +             return NULL;
> +     }
> +
> +     sym->so_name = info.dli_fname;
> +     sym->so_addr = info.dli_fbase;
> +     sym->sym_name = info.dli_sname;
> +     if (NULL != sym->sym_name) {
> +             sym->sym_addr = info.dli_saddr;
> +             sym->sym_offset = addr - sym->sym_addr;
> +     } else {
> +             sym->sym_addr = addr;
> +             sym->sym_offset = 0;

This looks wrong/dangerous.  Surely better to just fail?


> +     }
> +
> +     if (NULL == sym->so_name)
> +             sym->so_name =  "<unknown>";
> +     if (NULL == sym->sym_name)
> +             sym->sym_name = "<unknown>";

... and this even more so; those names aren't valid.


> +     return sym;
> +}
> +
> +struct module_symbol *module_symbol_by_name(struct module_instance *module,
> +             const char *name)
> +{
> +     void *addr = dlsym(module->dlhandle, name);

But dlsym can fail...

> +     return module_symbol_by_addr(addr);
> +}

_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to