dbghelp: Pass an image_file_map to macho_enum_load_commands().

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2018-06-14 16:58:15 -05:00 committed by Alexandre Julliard
parent f2e38e1795
commit bf7681cb2f
1 changed files with 22 additions and 16 deletions

View File

@ -467,10 +467,11 @@ static const struct load_command* macho_next_load_command(const struct load_comm
* callback. If >=0, that's the count of load commands successfully * callback. If >=0, that's the count of load commands successfully
* processed. * processed.
*/ */
static int macho_enum_load_commands(struct macho_file_map* fmap, unsigned cmd, static int macho_enum_load_commands(struct image_file_map *ifm, unsigned cmd,
int (*cb)(struct macho_file_map*, const struct load_command*, void*), int (*cb)(struct image_file_map*, const struct load_command*, void*),
void* user) void* user)
{ {
struct macho_file_map* fmap = &ifm->u.macho;
const struct load_command* lc; const struct load_command* lc;
int i; int i;
int count = 0; int count = 0;
@ -488,7 +489,7 @@ static int macho_enum_load_commands(struct macho_file_map* fmap, unsigned cmd,
if (cmd && cmd != lc->cmd) continue; if (cmd && cmd != lc->cmd) continue;
count++; count++;
result = cb(fmap, lc, user); result = cb(ifm, lc, user);
TRACE("load_command[%d] (%p), cmd %u; callback => %d\n", i, lc, lc->cmd, result); TRACE("load_command[%d] (%p), cmd %u; callback => %d\n", i, lc, lc->cmd, result);
if (result) return (result < 0) ? result : count; if (result) return (result < 0) ? result : count;
} }
@ -503,13 +504,14 @@ static int macho_enum_load_commands(struct macho_file_map* fmap, unsigned cmd,
* significant sections in a Mach-O file. All commands are * significant sections in a Mach-O file. All commands are
* expected to be of LC_SEGMENT[_64] type. * expected to be of LC_SEGMENT[_64] type.
*/ */
static int macho_count_sections(struct macho_file_map* fmap, const struct load_command* lc, void* user) static int macho_count_sections(struct image_file_map* ifm, const struct load_command* lc, void* user)
{ {
const macho_segment_command* sc = (const macho_segment_command*)lc; const macho_segment_command* sc = (const macho_segment_command*)lc;
TRACE("(%p/%d, %p, %p) segment %s\n", fmap, fmap->fd, lc, user, debugstr_an(sc->segname, sizeof(sc->segname))); TRACE("(%p/%d, %p, %p) segment %s\n", ifm, ifm->u.macho.fd, lc, user,
debugstr_an(sc->segname, sizeof(sc->segname)));
fmap->num_sections += sc->nsects; ifm->u.macho.num_sections += sc->nsects;
return 0; return 0;
} }
@ -520,8 +522,9 @@ static int macho_count_sections(struct macho_file_map* fmap, const struct load_c
* range covered by the segments of a Mach-O file and builds the * range covered by the segments of a Mach-O file and builds the
* section map. All commands are expected to be of LC_SEGMENT[_64] type. * section map. All commands are expected to be of LC_SEGMENT[_64] type.
*/ */
static int macho_load_section_info(struct macho_file_map* fmap, const struct load_command* lc, void* user) static int macho_load_section_info(struct image_file_map* ifm, const struct load_command* lc, void* user)
{ {
struct macho_file_map* fmap = &ifm->u.macho;
const macho_segment_command* sc = (const macho_segment_command*)lc; const macho_segment_command* sc = (const macho_segment_command*)lc;
struct section_info* info = user; struct section_info* info = user;
BOOL ignore; BOOL ignore;
@ -576,9 +579,9 @@ static int macho_load_section_info(struct macho_file_map* fmap, const struct loa
* Callback for macho_enum_load_commands. Records the UUID load * Callback for macho_enum_load_commands. Records the UUID load
* command of a Mach-O file. * command of a Mach-O file.
*/ */
static int find_uuid(struct macho_file_map* fmap, const struct load_command* lc, void* user) static int find_uuid(struct image_file_map* ifm, const struct load_command* lc, void* user)
{ {
fmap->uuid = (const struct uuid_command*)lc; ifm->u.macho.uuid = (const struct uuid_command*)lc;
return 1; return 1;
} }
@ -700,7 +703,7 @@ static BOOL macho_map_file(struct process *pcs, const WCHAR *filenameW,
TRACE("... verified Mach header\n"); TRACE("... verified Mach header\n");
fmap->num_sections = 0; fmap->num_sections = 0;
if (macho_enum_load_commands(fmap, target_cmd, macho_count_sections, NULL) < 0) if (macho_enum_load_commands(ifm, target_cmd, macho_count_sections, NULL) < 0)
goto done; goto done;
TRACE("%d sections\n", fmap->num_sections); TRACE("%d sections\n", fmap->num_sections);
@ -713,7 +716,7 @@ static BOOL macho_map_file(struct process *pcs, const WCHAR *filenameW,
info.split_segs = split_segs; info.split_segs = split_segs;
info.section_index = 0; info.section_index = 0;
if (macho_enum_load_commands(fmap, target_cmd, macho_load_section_info, &info) < 0) if (macho_enum_load_commands(ifm, target_cmd, macho_load_section_info, &info) < 0)
{ {
fmap->num_sections = 0; fmap->num_sections = 0;
goto done; goto done;
@ -723,7 +726,7 @@ static BOOL macho_map_file(struct process *pcs, const WCHAR *filenameW,
TRACE("segs_start: 0x%08lx, segs_size: 0x%08lx\n", (unsigned long)fmap->segs_start, TRACE("segs_start: 0x%08lx, segs_size: 0x%08lx\n", (unsigned long)fmap->segs_start,
(unsigned long)fmap->segs_size); (unsigned long)fmap->segs_size);
if (macho_enum_load_commands(fmap, LC_UUID, find_uuid, NULL) < 0) if (macho_enum_load_commands(ifm, LC_UUID, find_uuid, NULL) < 0)
goto done; goto done;
if (fmap->uuid) if (fmap->uuid)
{ {
@ -857,9 +860,10 @@ static void macho_stabs_def_cb(struct module* module, unsigned long load_offset,
* Callback for macho_enum_load_commands. Processes the LC_SYMTAB * Callback for macho_enum_load_commands. Processes the LC_SYMTAB
* load commands from the Mach-O file. * load commands from the Mach-O file.
*/ */
static int macho_parse_symtab(struct macho_file_map* fmap, static int macho_parse_symtab(struct image_file_map* ifm,
const struct load_command* lc, void* user) const struct load_command* lc, void* user)
{ {
struct macho_file_map* fmap = &ifm->u.macho;
const struct symtab_command* sc = (const struct symtab_command*)lc; const struct symtab_command* sc = (const struct symtab_command*)lc;
struct macho_debug_info* mdi = user; struct macho_debug_info* mdi = user;
const macho_nlist* stab; const macho_nlist* stab;
@ -1219,6 +1223,7 @@ BOOL macho_load_debug_info(struct process *pcs, struct module* module)
BOOL ret = FALSE; BOOL ret = FALSE;
struct macho_debug_info mdi; struct macho_debug_info mdi;
int result; int result;
struct image_file_map *ifm;
struct macho_file_map *fmap; struct macho_file_map *fmap;
if (module->type != DMT_MACHO || !module->format_info[DFI_MACHO]->u.macho_info) if (module->type != DMT_MACHO || !module->format_info[DFI_MACHO]->u.macho_info)
@ -1227,7 +1232,8 @@ BOOL macho_load_debug_info(struct process *pcs, struct module* module)
return FALSE; return FALSE;
} }
fmap = &module->format_info[DFI_MACHO]->u.macho_info->file_map.u.macho; ifm = &module->format_info[DFI_MACHO]->u.macho_info->file_map;
fmap = &ifm->u.macho;
TRACE("(%p, %p/%d)\n", module, fmap, fmap->fd); TRACE("(%p, %p/%d)\n", module, fmap, fmap->fd);
@ -1246,7 +1252,7 @@ BOOL macho_load_debug_info(struct process *pcs, struct module* module)
mdi.module = module; mdi.module = module;
pool_init(&mdi.pool, 65536); pool_init(&mdi.pool, 65536);
hash_table_init(&mdi.pool, &mdi.ht_symtab, 256); hash_table_init(&mdi.pool, &mdi.ht_symtab, 256);
result = macho_enum_load_commands(fmap, LC_SYMTAB, macho_parse_symtab, &mdi); result = macho_enum_load_commands(ifm, LC_SYMTAB, macho_parse_symtab, &mdi);
if (result > 0) if (result > 0)
ret = TRUE; ret = TRUE;
else if (result < 0) else if (result < 0)
@ -1255,7 +1261,7 @@ BOOL macho_load_debug_info(struct process *pcs, struct module* module)
if (!(dbghelp_options & SYMOPT_PUBLICS_ONLY) && fmap->dsym) if (!(dbghelp_options & SYMOPT_PUBLICS_ONLY) && fmap->dsym)
{ {
mdi.fmap = &fmap->dsym->u.macho; mdi.fmap = &fmap->dsym->u.macho;
result = macho_enum_load_commands(mdi.fmap, LC_SYMTAB, macho_parse_symtab, &mdi); result = macho_enum_load_commands(fmap->dsym, LC_SYMTAB, macho_parse_symtab, &mdi);
if (result > 0) if (result > 0)
ret = TRUE; ret = TRUE;
else if (result < 0) else if (result < 0)