Bug 6029 - Fetching enclosing frame yields bogus address
Summary: Fetching enclosing frame yields bogus address
Status: RESOLVED FIXED
Alias: None
Product: frysk
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Mark Wielaard
URL:
Keywords:
Depends on:
Blocks: 5959
  Show dependency treegraph
 
Reported: 2008-04-03 21:48 UTC by Petr Machata
Modified: 2008-04-11 17:31 UTC (History)
0 users

See Also:
Host: i686-pc-linux-gnu
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Machata 2008-04-03 21:48:03 UTC
The following code:
  StackFactory.createFrame(task).getOuter().getAddress()
when called in a situation where the task has just been stoppen at the entry of
the function "__libc_csu_init", returns number of commandline arguments instead
of the outer frame.  This happens when task's binary has no debuginfo.

The mentioned function is called early during process setup, before main.  I'm
not sure there is anything to fix, maybe it's just a limitation of the system. 
I discuvered that memory pointed to by the ESP register also contains bogus
address, so maybe there's no way out of this mess... and I will have to work
around this in ftrace.
Comment 1 Petr Machata 2008-04-03 21:52:05 UTC
I have a test case for this, but it depends on symtab.SymbolFactory being able
to answer Dwfl's symbol table, which is a patch that I currently have only
locally.  But I guess, for debugging purposes, it shouldn't be a big problem to
hardcode breakpoint address to fit entry point of __libc_csu_init in any
throwaway "hallo world" binary.
Comment 2 Mark Wielaard 2008-04-04 07:36:37 UTC
If there is no debug (or eh) frame info we fall back to heuristics. Like using
the frame pointer. Which of course might not be used, or might not yet have been
setup as is most likely the case here.

Test case appreciated. But I'll try to replicate by hand as soon as I have my
x86 machine up (on x86_64 __libc_csu_init seems to have eh_frame info available).
Comment 3 Mark Wielaard 2008-04-10 09:51:13 UTC
Test added as frysk.stack.TestFrame.testBogusAddressPrevFrame()

commit 1e6a205bbcbe119523df8e4a569a9aa3c9aa29b3
Author: Petr Machata <pmachata@redhat.com>
Date:   Fri Apr 4 12:38:38 2008 +0200

    Add test for #6029
Comment 4 Mark Wielaard 2008-04-11 17:31:38 UTC
It wasn't dependent on no debuginfo (there was still eh_frame info in this
specific case). The problem was because the pc was not yet adjusted for the
breakpoint address when the Code observer updateHit() method was called.

Fixed by:

commit 40fbefd8950ef47a338fd60e10ab6ed234330fc2
Author: Mark Wielaard <mwielaard@redhat.com>
Date:   Fri Apr 11 19:22:53 2008 +0200

    Set task pc before calling any Code observers on breakpoint. Fixes bug #6029
    
    frysk-core/frysk/proc/live/ChangeLog
    2008-04-11  Mark Wielaard  <mwielaard@redhat.com>
    
           * LinuxPtraceTaskState.java (Running.setupSteppingBreakpoint):
           Removed.
           (Running.handleTrappedEvent): Don't call
           setupSteppingBreakpoint().
           (Stepping.handleTrappedEvent): Don't do stepping breakpoint sanity
           check. Don't call setupSteppingBreakpoint().
           * LinuxPtraceTask.java (notifyCodeBreakpoint): Add stepping
           breakpoint sanity check. Set task pc when breakpoint found. Set
           steppingBreakpoint.
    
    frysk-core/frysk/stack/ChangeLog
    2008-04-11  Mark Wielaard  <mwielaard@redhat.com>
    
           * TestFrame.java (testBogusAddressPrevFrame): Resolved.