Index: gdb/win32-nat.c =================================================================== RCS file: /cvs/src/src/gdb/win32-nat.c,v retrieving revision 1.131 diff -u -p -r1.131 win32-nat.c --- gdb/win32-nat.c 31 May 2007 17:32:21 -0000 1.131 +++ gdb/win32-nat.c 12 Jun 2007 20:17:19 -0000 @@ -541,6 +541,9 @@ struct safe_symbol_file_add_args struct lm_info { DWORD load_addr; + + /* The ImageBase, aka the prefered load address. */ + CORE_ADDR image_base; }; static struct so_list solib_start, *solib_end; @@ -659,6 +662,7 @@ solib_symbols_add (struct so_list *so, C static struct objfile *result = NULL; char *name = so->so_name; bfd *abfd = NULL; + asection *text = NULL; char *p; /* The symbols in a dll are offset by 0x1000, which is the @@ -701,10 +705,19 @@ solib_symbols_add (struct so_list *so, C do_cleanups (my_cleanups); } + if (abfd != NULL) + text = bfd_get_section_by_name (abfd, ".text"); + + /* Compute the ImageBase of our DLL. For that, we assume that + it is identical to the VMA of the ".text" section. This is + an assumption that is being made in other places already, + so this should be ok. */ + if (text != NULL) + so->lm_info->image_base = bfd_section_vma (abfd, text); + p = strchr (so->so_name, '\0') - (sizeof ("/cygwin1.dll") - 1); if (p >= so->so_name && strcasecmp (p, "/cygwin1.dll") == 0) { - asection *text = bfd_get_section_by_name (abfd, ".text"); cygwin_load_start = bfd_section_vma (abfd, text); cygwin_load_end = cygwin_load_start + bfd_section_size (abfd, text); } @@ -752,6 +765,7 @@ register_loaded_dll (const char *name, D so = XZALLOC (struct so_list); so->lm_info = (struct lm_info *) xmalloc (sizeof (struct lm_info)); so->lm_info->load_addr = load_addr; + so->lm_info->image_base = 0; /* Will be filled in later. */ cygwin_conv_to_posix_path (buf, so->so_name); strcpy (so->so_original_name, so->so_name); @@ -842,8 +856,18 @@ static void win32_relocate_section_addresses (struct so_list *so, struct section_table *sec) { - /* FIXME */ - return; + const DWORD load_addr = so->lm_info->load_addr; + const CORE_ADDR image_base = so->lm_info->image_base; + + /* If we couldn't determine the DLL prefered load address (image base), + then we can't adjust the section addresses. Assume that the DLL was + loaded at the prefered load address, which means that the second + addresses do not need to be adjusted. */ + if (image_base == 0) + return; + + sec->addr = sec->addr - image_base + load_addr; + sec->endaddr = sec->endaddr - image_base + load_addr; } static void @@ -2231,6 +2255,8 @@ win32_current_sos (void) struct so_list *new = XZALLOC (struct so_list); strcpy (new->so_name, sop->so_name); strcpy (new->so_original_name, sop->so_original_name); + new->lm_info = xmalloc (sizeof (struct lm_info)); + memcpy (new->lm_info, sop->lm_info, sizeof (struct lm_info)); if (!start) last = start = new; else