[PATCH] D42582: [lldb][PPC64] Fixed step-in stopping in the wrong line

Leandro Lupori via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 29 03:21:03 PST 2018


luporl added a comment.

In https://reviews.llvm.org/D42582#989512, @jingham wrote:

> BTW, do you also need to handle breakpoint setting here?  If you set a breakpoint on a name, does it get both the global & local entry point?  Or do you always go through one or the other?  And again, when pushing the breakpoint past the prologue, do we need to handle the different entry points differently?  I don't know why these local entry points are there, so maybe this question is off base, but abstractly it seems like you would have to worry about that.


Yes, I probably also need to handle breakpoint setting here. Right now, breakpoints are set only in the global entry point. But it would be better to set breakpoints at both global & local entry points, to avoid loosing local calls. However, this could cause the program to stop twice, in the case of entering through the local entry point. Unless we always skip the prologue after hitting either breakpoint, then it should be ok.

About the bytes that have to be skipped, at least for PPC64, they will always be the same, as long as you add it to the function start address (a.k.a. global entry point), that is what was already being done in the code.
If it needs to be calculated based on the current address instead, then we just need to subtract the local entry point offset from the prologue byte size.

I think the PPC64 assembly code below may help in understanding a little better its global & local function entry points:

  #  template<typename T> T
  #  max_value(const T& lhs, const T& rhs)
  #  {
  #      return std::max(lhs, rhs); // In max_value template
  #  }
  # (code for T = int)
  
      .section    .text._Z9max_valueIiET_RKS0_S2_,"axG", at progbits,_Z9max_valueIiET_RKS0_S2_,comdat
      .weak    _Z9max_valueIiET_RKS0_S2_ # -- Begin function _Z9max_valueIiET_RKS0_S2_
      .p2align    4
      .type    _Z9max_valueIiET_RKS0_S2_, at function
  _Z9max_valueIiET_RKS0_S2_:              # @_Z9max_valueIiET_RKS0_S2_
  .Lfunc_begin9:
      .loc    1 104 0 is_stmt 1       # calling.cpp:104:0
      .cfi_startproc
  .Lfunc_gep9:
      addis 2, 12, .TOC.-.Lfunc_gep9 at ha
      addi 2, 2, .TOC.-.Lfunc_gep9 at l
  .Lfunc_lep9:
      .localentry    _Z9max_valueIiET_RKS0_S2_, .Lfunc_lep9-.Lfunc_gep9
  # %bb.0:                                # %entry
      mflr 0
      std 31, -8(1)
      std 0, 16(1)
      stdu 1, -128(1)
      .cfi_def_cfa_offset 128
      .cfi_offset r31, -8
      .cfi_offset lr, 16
      mr 31, 1
      .cfi_def_cfa_register r31
      std 3, 112(31)
      std 4, 104(31)
  .Ltmp36:
      .loc    1 105 21 prologue_end   # calling.cpp:105:21
      ld 3, 112(31)
      .loc    1 105 26 is_stmt 0      # calling.cpp:105:26
      ld 4, 104(31)
      .loc    1 105 12                # calling.cpp:105:12
      bl _ZSt3maxIiERKT_S2_S2_
      nop
      lwa 3, 0(3)
      .loc    1 105 5                 # calling.cpp:105:5
      addi 1, 1, 128
      ld 0, 16(1)
      ld 31, -8(1)
      mtlr 0
      blr
  .Ltmp37:
      .long    0
      .quad    0
  .Lfunc_end9:
      .size    _Z9max_valueIiET_RKS0_S2_, .Lfunc_end9-.Lfunc_begin9
      .cfi_endproc

.Lfunc_gep9 is the global entry point, that will always match with address of the function symbol.

.Lfunc_lep9 is the local entry point, that, AFAIK, will always be at the start address of the function plus a byte offset corresponding to instructions that should be skipped when entering the function locally.
In this example, it is skipping the 2 instructions that set the TOC (Table Of Contents), as it will already have been set to the correct value if this is a local call (from a module that shares the same TOC).
The .localentry directive is what instructs the assembler to save the local entry point offset in the st_other field of the function symbol in an ELF file.


Repository:
  rL LLVM

https://reviews.llvm.org/D42582





More information about the llvm-commits mailing list