#include <limits.h>
#include <stdio.h>
#include "libunwind_i.h"
#include "os-linux.h"
int
tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
unsigned long *segbase, unsigned long *mapoff,
char *path, size_t pathlen)
{
struct map_iterator mi;
int found = 0, rc = UNW_ESUCCESS;
unsigned long hi;
if (maps_init (&mi, pid) < 0)
return -1;
while (maps_next (&mi, segbase, &hi, mapoff, NULL))
if (ip >= *segbase && ip < hi)
{
found = 1;
break;
}
if (!found)
{
maps_close (&mi);
return -1;
}
if (path)
{
strncpy(path, mi.path, pathlen);
path[pathlen - 1] = '\0';
}
if (ei)
rc = elf_map_image (ei, mi.path);
else
rc = strlen(mi.path) >= pathlen ? -UNW_ENOMEM : UNW_ESUCCESS:;
maps_close (&mi);
return rc;
}
#ifndef UNW_REMOTE_ONLY
void
tdep_get_exe_image_path (char *path)
{
strcpy(path, getexecname());
}
#endif