+ struct obj_section *section;
+ const char *name;
+ struct objfile *objfile;
+ struct gdbarch *gdbarch;
+ struct block *b, *function_block;
+
+ /* Do not change the SAL is PC was specified explicitly. */
+ if (sal->explicit_pc)
+ return;
+
+ old_chain = save_current_space_and_thread ();
+ switch_to_program_space_and_thread (sal->pspace);
+
+ sym = find_pc_sect_function (sal->pc, sal->section);
+ if (sym != NULL)
+ {
+ fixup_symbol_section (sym, NULL);
+
+ pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
+ section = SYMBOL_OBJ_SECTION (sym);
+ name = SYMBOL_LINKAGE_NAME (sym);
+ objfile = SYMBOL_SYMTAB (sym)->objfile;
+ }
+ else
+ {
+ struct minimal_symbol *msymbol
+ = lookup_minimal_symbol_by_pc_section (sal->pc, sal->section);
+ if (msymbol == NULL)
+ {
+ do_cleanups (old_chain);
+ return;
+ }
+
+ pc = SYMBOL_VALUE_ADDRESS (msymbol);
+ section = SYMBOL_OBJ_SECTION (msymbol);
+ name = SYMBOL_LINKAGE_NAME (msymbol);
+ objfile = msymbol_objfile (msymbol);
+ }
+
+ gdbarch = get_objfile_arch (objfile);
+
+ /* If the function is in an unmapped overlay, use its unmapped LMA address,
+ so that gdbarch_skip_prologue has something unique to work on. */
+ if (section_is_overlay (section) && !section_is_mapped (section))
+ pc = overlay_unmapped_address (pc, section);
+
+ /* Skip "first line" of function (which is actually its prologue). */
+ pc += gdbarch_deprecated_function_start_offset (gdbarch);
+ pc = gdbarch_skip_prologue (gdbarch, pc);
+
+ /* For overlays, map pc back into its mapped VMA range. */
+ pc = overlay_mapped_address (pc, section);
+
+ /* Calculate line number. */
+ start_sal = find_pc_sect_line (pc, section, 0);
+
+ /* Check if gdbarch_skip_prologue left us in mid-line, and the next
+ line is still part of the same function. */
+ if (start_sal.pc != pc
+ && (sym? (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) <= start_sal.end
+ && start_sal.end < BLOCK_END (SYMBOL_BLOCK_VALUE (sym)))
+ : (lookup_minimal_symbol_by_pc_section (start_sal.end, section)
+ == lookup_minimal_symbol_by_pc_section (pc, section))))
+ {
+ /* First pc of next line */
+ pc = start_sal.end;
+ /* Recalculate the line number (might not be N+1). */
+ start_sal = find_pc_sect_line (pc, section, 0);
+ }
+
+ /* On targets with executable formats that don't have a concept of
+ constructors (ELF with .init has, PE doesn't), gcc emits a call
+ to `__main' in `main' between the prologue and before user
+ code. */
+ if (gdbarch_skip_main_prologue_p (gdbarch)
+ && name && strcmp (name, "main") == 0)
+ {
+ pc = gdbarch_skip_main_prologue (gdbarch, pc);
+ /* Recalculate the line number (might not be N+1). */
+ start_sal = find_pc_sect_line (pc, section, 0);
+ }
+
+ /* If we still don't have a valid source line, try to find the first
+ PC in the lineinfo table that belongs to the same function. This
+ happens with COFF debug info, which does not seem to have an
+ entry in lineinfo table for the code after the prologue which has
+ no direct relation to source. For example, this was found to be
+ the case with the DJGPP target using "gcc -gcoff" when the
+ compiler inserted code after the prologue to make sure the stack
+ is aligned. */
+ if (sym && start_sal.symtab == NULL)
+ {
+ pc = skip_prologue_using_lineinfo (pc, SYMBOL_SYMTAB (sym));
+ /* Recalculate the line number. */
+ start_sal = find_pc_sect_line (pc, section, 0);
+ }
+
+ do_cleanups (old_chain);
+
+ /* If we're already past the prologue, leave SAL unchanged. Otherwise
+ forward SAL to the end of the prologue. */
+ if (sal->pc >= pc)
+ return;
+
+ sal->pc = pc;
+ sal->section = section;
+
+ /* Unless the explicit_line flag was set, update the SAL line
+ and symtab to correspond to the modified PC location. */
+ if (sal->explicit_line)
+ return;
+
+ sal->symtab = start_sal.symtab;
+ sal->line = start_sal.line;
+ sal->end = start_sal.end;