[all-commits] [llvm/llvm-project] 0a840e: [lldb] Copy m_behaves_like_zeroth_frame on stack f...

Tatyana Krasnukha via All-commits all-commits at lists.llvm.org
Mon Mar 16 06:20:27 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 0a840ef80059c761109f5988590a3616c00906a1
      https://github.com/llvm/llvm-project/commit/0a840ef80059c761109f5988590a3616c00906a1
  Author: Tatyana Krasnukha <tatyana at synopsys.com>
  Date:   2020-03-16 (Mon, 16 Mar 2020)

  Changed paths:
    M lldb/source/Target/StackFrame.cpp
    A lldb/test/API/functionalities/unwind/zeroth_frame/Makefile
    A lldb/test/API/functionalities/unwind/zeroth_frame/TestZerothFrame.py
    A lldb/test/API/functionalities/unwind/zeroth_frame/main.c

  Log Message:
  -----------
  [lldb] Copy m_behaves_like_zeroth_frame on stack frame update

Fix to code from https://reviews.llvm.org/D64993.

Field StackFrame::m_behaves_like_zeroth_frame was introduced in commit
[1], however that commit hasn't added a copying of the field to
UpdatePreviousFrameFromCurrentFrame, therefore the value wouldn't change
when updating frames to reflect the current situation.

The particular scenario, where this matters is following. Assume we have
function main that invokes function func1. We set breakpoint at
func1 entry and in main after the func1 call, and do not stop at
the main entry. Therefore, when debugger stops for the first time,
func1 is frame#0, while main is frame#1, thus
m_behaves_like_zeroth_frame is set to 0 for main frame. Execution is
resumed, and stops now in main, where it is now frame#0. However while
updating the frame object, m_behaves_like_zeroth_frame remains false.
This field plays an important role when calculating line information for
backtrace: for frame#0, PC is the current line, therefore line
information is retrieved for PC, however for all other frames this is
not the case - calculated PC is a return-PC, i.e. instruction after the
function call line, therefore for those frames LLDB needs to step back
by one instruction. Initial implementation did this strictly for frames
that have index != 0 (and index is updated properly in
UpdatePreviousFrameFromCurrentFrame), but m_behaves_like_zeroth_frame
added a capability for middle-of-stack frames to behave in a similar
manner. But because current code now doesn't check frame idx,
m_behaves_like_zeroth_frame must be set to true for frames with 0 index,
not only for frame that behave like one. In the described test case,
after stopping in main, LLDB would still consider frame#0 as
non-zeroth, and would subtract instruction from the PC, and would report
previous like as current line.

The error doesn't manifest itself in LLDB interpreter though - it can be
reproduced through LLDB-MI and when using SB API, but not when we
interpreter command "continue" is executed. Honestly, I didn't fully
understand why it works in interpreter, I did found that bug "fixes"
itself if I enable DEBUG_STACK_FRAMES in StackFrameList.cpp, because
that calls StackFrame::Dump and that calls
GetSymbolContext(eSymbolContextEverything), which fills the context of
frame on the first breakpoint, therefore it doesn't have to be
recalculated (improperly) on a second frame. However, on first
breakpoint symbol context is calculated for the "call" line, not the
next one, therefore it should be recalculated anyway on a second
breakpoint, and it is done correctly, even though
m_behaves_like_zeroth_frame is still incorrect, as long as
GetSymbolContext(eSymbolContextEverything) has been called.

[1] 31e6dbe1c6a6 Fix PC adjustment in StackFrame::GetSymbolContext

Differential Revision: https://reviews.llvm.org/D75975

Patch by Anton Kolesov <Anton.Kolesov at synopsys.com>


  Commit: 332edcc6bd1dc1fd8fc33a0fb2f215a996d967fa
      https://github.com/llvm/llvm-project/commit/332edcc6bd1dc1fd8fc33a0fb2f215a996d967fa
  Author: Tatyana Krasnukha <tatyana at synopsys.com>
  Date:   2020-03-16 (Mon, 16 Mar 2020)

  Changed paths:
    M lldb/include/lldb/Target/StackFrame.h

  Log Message:
  -----------
  [lldb] Remove unimplemented StackFrame::BehavesLikeZerothFrame

Commit [1] added a declaration of function-member
StackFrame::BehavesLikeZerothFrame but hasn't added an implementation
for the function. This commit removes this declation, because the
function is not used anywhere.

[1] 31e6dbe1c6a6 Fix PC adjustment in StackFrame::GetSymbolContext

Differential Revision: https://reviews.llvm.org/D75979

Patch by Anton Kolesov <Anton.Kolesov at synopsys.com>


Compare: https://github.com/llvm/llvm-project/compare/acdcd23b7b07...332edcc6bd1d


More information about the All-commits mailing list