+ else if (msym.minsym != NULL
+ && MSYMBOL_TYPE (msym.minsym) == mst_solib_trampoline)
+ {
+ struct objfile *objfile;
+ struct minimal_symbol *msymbol;
+ int function_found = 0;
+
+ /* Go look if there is another minimal symbol with the same name as
+ this one, but with type mst_text. This would happen if the msym
+ is an actual trampoline, in which case there would be another
+ symbol with the same name corresponding to the real function. */
+
+ ALL_MSYMBOLS (objfile, msymbol)
+ {
+ if (MSYMBOL_TYPE (msymbol) == mst_text
+ && strcmp (SYMBOL_LINKAGE_NAME (msymbol),
+ SYMBOL_LINKAGE_NAME (msym.minsym)) == 0)
+ {
+ function_found = 1;
+ break;
+ }
+ }
+
+ if (function_found)
+ /* The type of msym is correct (mst_solib_trampoline), but
+ the unwind info is wrong, so set it to the correct value. */
+ u->stub_unwind.stub_type = EXPORT;
+ else
+ /* The stub type info in the unwind is correct (this is not a
+ trampoline), but the msym type information is wrong, it
+ should be mst_text. So we need to fix the msym, and also
+ get out of this function. */
+ {
+ MSYMBOL_TYPE (msym.minsym) = mst_text;
+ return orig_pc == pc ? 0 : pc & ~0x3;
+ }
+ }
+
+/*--------------------------------------------------------------------------*/
+ }
+
+ /* It's a stub. Search for a branch and figure out where it goes.
+ Note we have to handle multi insn branch sequences like ldil;ble.
+ Most (all?) other branches can be determined by examining the contents
+ of certain registers and the stack. */
+
+ loc = pc;
+ curr_inst = 0;
+ prev_inst = 0;
+ while (1)
+ {
+ /* Make sure we haven't walked outside the range of this stub. */
+ if (u != find_unwind_entry (loc))
+ {
+ warning (_("Unable to find branch in linker stub"));
+ return orig_pc == pc ? 0 : pc & ~0x3;
+ }
+
+ prev_inst = curr_inst;
+ curr_inst = read_memory_integer (loc, 4, byte_order);
+
+ /* Does it look like a branch external using %r1? Then it's the
+ branch from the stub to the actual function. */
+ if ((curr_inst & 0xffe0e000) == 0xe0202000)
+ {
+ /* Yup. See if the previous instruction loaded
+ a value into %r1. If so compute and return the jump address. */
+ if ((prev_inst & 0xffe00000) == 0x20200000)
+ return (hppa_extract_21 (prev_inst)
+ + hppa_extract_17 (curr_inst)) & ~0x3;
+ else
+ {
+ warning (_("Unable to find ldil X,%%r1 "
+ "before ble Y(%%sr4,%%r1)."));
+ return orig_pc == pc ? 0 : pc & ~0x3;
+ }
+ }
+
+ /* Does it look like a be 0(sr0,%r21)? OR
+ Does it look like a be, n 0(sr0,%r21)? OR
+ Does it look like a bve (r21)? (this is on PA2.0)
+ Does it look like a bve, n(r21)? (this is also on PA2.0)
+ That's the branch from an
+ import stub to an export stub.
+
+ It is impossible to determine the target of the branch via
+ simple examination of instructions and/or data (consider
+ that the address in the plabel may be the address of the
+ bind-on-reference routine in the dynamic loader).
+
+ So we have try an alternative approach.
+
+ Get the name of the symbol at our current location; it should
+ be a stub symbol with the same name as the symbol in the
+ shared library.
+
+ Then lookup a minimal symbol with the same name; we should
+ get the minimal symbol for the target routine in the shared
+ library as those take precedence of import/export stubs. */
+ if ((curr_inst == 0xe2a00000) ||
+ (curr_inst == 0xe2a00002) ||
+ (curr_inst == 0xeaa0d000) ||
+ (curr_inst == 0xeaa0d002))
+ {
+ struct bound_minimal_symbol stubsym;
+ struct minimal_symbol *libsym;
+
+ stubsym = lookup_minimal_symbol_by_pc (loc);
+ if (stubsym.minsym == NULL)
+ {
+ warning (_("Unable to find symbol for 0x%lx"), loc);
+ return orig_pc == pc ? 0 : pc & ~0x3;
+ }
+
+ libsym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (stubsym.minsym),
+ NULL, NULL);
+ if (libsym == NULL)
+ {
+ warning (_("Unable to find library symbol for %s."),
+ SYMBOL_PRINT_NAME (stubsym.minsym));
+ return orig_pc == pc ? 0 : pc & ~0x3;
+ }
+
+ return SYMBOL_VALUE (libsym);
+ }
+
+ /* Does it look like bl X,%rp or bl X,%r0? Another way to do a
+ branch from the stub to the actual function. */
+ /*elz */
+ else if ((curr_inst & 0xffe0e000) == 0xe8400000
+ || (curr_inst & 0xffe0e000) == 0xe8000000
+ || (curr_inst & 0xffe0e000) == 0xe800A000)
+ return (loc + hppa_extract_17 (curr_inst) + 8) & ~0x3;
+
+ /* Does it look like bv (rp)? Note this depends on the
+ current stack pointer being the same as the stack
+ pointer in the stub itself! This is a branch on from the
+ stub back to the original caller. */
+ /*else if ((curr_inst & 0xffe0e000) == 0xe840c000) */
+ else if ((curr_inst & 0xffe0f000) == 0xe840c000)
+ {
+ /* Yup. See if the previous instruction loaded
+ rp from sp - 8. */
+ if (prev_inst == 0x4bc23ff1)
+ {
+ CORE_ADDR sp;
+ sp = get_frame_register_unsigned (frame, HPPA_SP_REGNUM);
+ return read_memory_integer (sp - 8, 4, byte_order) & ~0x3;
+ }
+ else
+ {
+ warning (_("Unable to find restore of %%rp before bv (%%rp)."));
+ return orig_pc == pc ? 0 : pc & ~0x3;
+ }
+ }
+
+ /* elz: added this case to capture the new instruction
+ at the end of the return part of an export stub used by
+ the PA2.0: BVE, n (rp) */
+ else if ((curr_inst & 0xffe0f000) == 0xe840d000)
+ {
+ return (read_memory_integer
+ (get_frame_register_unsigned (frame, HPPA_SP_REGNUM) - 24,
+ word_size, byte_order)) & ~0x3;
+ }