Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/elftoolchain/libdwarf/libdwarf_lineno.c
Show All 27 Lines | |||||
ELFTC_VCSID("$Id: libdwarf_lineno.c 3164 2015-02-19 01:20:12Z kaiwang27 $"); | ELFTC_VCSID("$Id: libdwarf_lineno.c 3164 2015-02-19 01:20:12Z kaiwang27 $"); | ||||
static int | static int | ||||
_dwarf_lineno_add_file(Dwarf_LineInfo li, uint8_t **p, const char *compdir, | _dwarf_lineno_add_file(Dwarf_LineInfo li, uint8_t **p, const char *compdir, | ||||
Dwarf_Error *error, Dwarf_Debug dbg) | Dwarf_Error *error, Dwarf_Debug dbg) | ||||
{ | { | ||||
Dwarf_LineFile lf; | Dwarf_LineFile lf; | ||||
const char *dirname; | FILE *filepath; | ||||
const char *incdir; | |||||
uint8_t *src; | uint8_t *src; | ||||
int slen; | size_t slen; | ||||
src = *p; | src = *p; | ||||
if ((lf = malloc(sizeof(struct _Dwarf_LineFile))) == NULL) { | if ((lf = malloc(sizeof(struct _Dwarf_LineFile))) == NULL) { | ||||
DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY); | DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY); | ||||
return (DW_DLE_MEMORY); | return (DW_DLE_MEMORY); | ||||
} | } | ||||
lf->lf_fullpath = NULL; | lf->lf_fullpath = NULL; | ||||
lf->lf_fname = (char *) src; | lf->lf_fname = (char *) src; | ||||
src += strlen(lf->lf_fname) + 1; | src += strlen(lf->lf_fname) + 1; | ||||
lf->lf_dirndx = _dwarf_decode_uleb128(&src); | lf->lf_dirndx = _dwarf_decode_uleb128(&src); | ||||
if (lf->lf_dirndx > li->li_inclen) { | if (lf->lf_dirndx > li->li_inclen) { | ||||
free(lf); | free(lf); | ||||
DWARF_SET_ERROR(dbg, error, DW_DLE_DIR_INDEX_BAD); | DWARF_SET_ERROR(dbg, error, DW_DLE_DIR_INDEX_BAD); | ||||
return (DW_DLE_DIR_INDEX_BAD); | return (DW_DLE_DIR_INDEX_BAD); | ||||
} | } | ||||
/* Make full pathname if need. */ | /* Make a full pathname if needed. */ | ||||
if (*lf->lf_fname != '/') { | if (*lf->lf_fname != '/') { | ||||
dirname = compdir; | filepath = open_memstream(&lf->lf_fullpath, &slen); | ||||
if (lf->lf_dirndx > 0) | if (filepath == NULL) { | ||||
dirname = li->li_incdirs[lf->lf_dirndx - 1]; | |||||
if (dirname != NULL) { | |||||
slen = strlen(dirname) + strlen(lf->lf_fname) + 2; | |||||
if ((lf->lf_fullpath = malloc(slen)) == NULL) { | |||||
free(lf); | free(lf); | ||||
DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY); | DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY); | ||||
return (DW_DLE_MEMORY); | return (DW_DLE_MEMORY); | ||||
} | } | ||||
snprintf(lf->lf_fullpath, slen, "%s/%s", dirname, | |||||
lf->lf_fname); | if (lf->lf_dirndx > 0) | ||||
incdir = li->li_incdirs[lf->lf_dirndx - 1]; | |||||
else | |||||
incdir = NULL; | |||||
/* | |||||
* Prepend the compilation directory if the directory table | |||||
* entry is relative. | |||||
*/ | |||||
if (incdir == NULL || *incdir != '/') | |||||
fprintf(filepath, "%s/", compdir); | |||||
if (incdir != NULL) | |||||
fprintf(filepath, "%s/", incdir); | |||||
fprintf(filepath, "%s", lf->lf_fname); | |||||
if (fclose(filepath) != 0) { | |||||
free(lf); | |||||
DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY); | |||||
return (DW_DLE_MEMORY); | |||||
} | } | ||||
} | } | ||||
lf->lf_mtime = _dwarf_decode_uleb128(&src); | lf->lf_mtime = _dwarf_decode_uleb128(&src); | ||||
lf->lf_size = _dwarf_decode_uleb128(&src); | lf->lf_size = _dwarf_decode_uleb128(&src); | ||||
STAILQ_INSERT_TAIL(&li->li_lflist, lf, lf_next); | STAILQ_INSERT_TAIL(&li->li_lflist, lf, lf_next); | ||||
li->li_lflen++; | li->li_lflen++; | ||||
▲ Show 20 Lines • Show All 699 Lines • Show Last 20 Lines |