Re: [lldb-dev] gdb-remote protocol questions

2020-01-28 Thread Pavel Labath via lldb-dev
On 27/01/2020 19:43, Alexander Zhang via lldb-dev wrote:
> Hi,
> 
> Thanks for pointing me towards stack unwinding. I don't have debug
> information much of the time, so I'm depending on the architecture rules
> for backtracing. A look at the mips ABI plugin shows it uses dwarf
> register numbers to get the register values it needs, and I wasn't
> including them in my qRegisterInfo responses. After fixing this, step
> over and step out appear to work correctly, which is a great help.
> 
> However, backtraces only show 2 frames with the current pc and ra
> values, no matter where I am, so it seems there's some problem getting
> stack frame info from the actual stack. I've attached an unwind log from
> running bt inside a function that should have a deeper backtrace. The
> afa value of 0x looks suspicious to me, but I don't
> really understand where it comes from. The frame before 0x8002ee70
> should, I think, be 0x80026a6c, as that's the pc after stepping out twice.
> 
> Thanks,
> Alexander 
> 

Hi Alexander,

I am pretty sure the AFA is a red herring and you needn't worry about
it. It is only used in some very specific circumstances, when a function
realigns the stack pointer (e.g. when you have a over-aligned local
variable), and only on x86 I believe. Everyone else gets a 0xfff...f
value, and that's fine.

pl
___
lldb-dev mailing list
lldb-dev@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev


[lldb-dev] [Bug 44690] Include guards missing for compression.h

2020-01-28 Thread via lldb-dev
https://bugs.llvm.org/show_bug.cgi?id=44690

Gabor Greif  changed:

   What|Removed |Added

 Resolution|INVALID |---
 Status|RESOLVED|REOPENED

--- Comment #2 from Gabor Greif  ---
(In reply to Jonas Devlieghere from comment #1)
> This code is in debugserver which is macOS-only. We always have
> libcompresion there. Furthermore it entirely separate from the rest of LLDB
> and doesn't read the header that defines HAVE_LIBCOMPRESSION. 
> 
> I don't think you want to build debugserver for NixOS. It should only be a
> target on Darwin. See tools/CMakeLists.txt:
> 
>  13 if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
>  14   add_lldb_tool_subdirectory(darwin-debug)
>  15   if(NOT LLDB_USE_SYSTEM_DEBUGSERVER)
>  16 add_lldb_tool_subdirectory(debugserver)
>  17   endif()
>  18 endif()

Hi Jonas, thanks for your reply!

NixOS and `Nixpkgs` are often confused. The former is a Linux-based OS, the
latter a package collection like fink, macports or homebrew.

Indeed Nixpkgs has a Darwin target, and LLDB is installable on it. I just
looked:

$ ls /nix/store/bypgwpzl5i88ncmr65hnifjlmwp69kj6-lldb-7.1.0/bin/
darwin-debug  lldb  lldb-argdumper  lldb-mi  lldb-server  lldb-test

Unfortunately LLDB 8 (and later) won't compile from source any more. This is
why I am reaching out.

https://github.com/llvm/llvm-project/blob/release/7.x/lldb/tools/debugserver/source/RNBRemote.cpp

still has the guards, they were removed in

https://github.com/llvm/llvm-project/commit/681f6c2f552fb9b57380f4bfd453e1fc9b6a099e#diff-302e60b129d98a39031cd9f6b2d855c7

I see some options going forward:
- Nixpkgs could patch the file, restoring compilability (somehow)
- Nixpkgs could include libcompression (new package) and depend Darwin `lldb`
on it
- LLVM-project could make `lldb-server` compilable again for sandboxed,
no-compression-lib environments
- Nixpkgs could disable the `llvmPackages_{8,9,10}.lldb` sets.


In any case CMAKE configury should detect the absence of libcompression and
error out early if it is a hard compilation requirement.

-- 
You are receiving this mail because:
You are the assignee for the bug.___
lldb-dev mailing list
lldb-dev@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev


[lldb-dev] [Bug 44059] The LLDB test for the entry values will fail due to changes in the compiler

2020-01-28 Thread via lldb-dev
https://bugs.llvm.org/show_bug.cgi?id=44059

Djordje Todorovic  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|NEW |RESOLVED

-- 
You are receiving this mail because:
You are the assignee for the bug.___
lldb-dev mailing list
lldb-dev@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev


Re: [lldb-dev] gdb-remote protocol questions

2020-01-28 Thread Jason Molenda via lldb-dev
Hi Alexander, sorry for the delay in replying.

The attached unwind log shows that lldb is using the architectural default 
unwind plan for this target.  You can see where this unwind plan in constructed 
at

ABISysV_mips::CreateDefaultUnwindPlan

it says to find the caller's pc value at *($r29),

  // Our Call Frame Address is the stack pointer value
  row->GetCFAValue().SetIsRegisterPlusOffset(dwarf_r29, 0);

The default unwind plan says to find the caller's pc value in $r31,

  // The previous PC is in the RA
  row->SetRegisterLocationToRegister(dwarf_pc, dwarf_r31, true);
  unwind_plan.AppendRow(row);

which is fine for frame 0, we can look at $r31, but as soon as we move off of 
frame 0, we have to find the saved $r31 value on the stack (frame 0 had to 
spill it to the stack, right).  

Unfortunately we don't have the function bounds of frame 0, we only have the 
architectural default unwind plan.  This default unwind plan cannot do the 
right thing except on frame 0.


On other architectures where a return address register is used, like arm, the 
default unwind plan assumes that the pc and saved frame pointer have been 
spilled to stack, and there is a convention that they're the first two things 
spilled to stack.  So we see in ABISysV_arm::CreateDefaultUnwindPlan,

  row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, ptr_size * -2, true);
  row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1, true);

We also have a ABISysV_arm::CreateFunctionEntryUnwindPlan unwind plan that is 
guaranteed to be valid at the first instruction of a function; it says that the 
saved PC is in the return address register,

  // Our Call Frame Address is the stack pointer value
  row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);

  // The previous PC is in the LR
  row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true);
  unwind_plan.AppendRow(row);

although I should warn that I'm 99% sure that "nexti" doesn't currently record 
the fact that it is potentially stepping into a function, so lldb doesn't know 
to use the FunctionEntryUnwindPlan.  We prob should.


fwiw the 0x value is lldb's LLDB_INVALID_ADDRESS.

J



> On Jan 27, 2020, at 10:43 AM, Alexander Zhang via lldb-dev 
>  wrote:
> 
> Hi,
> 
> Thanks for pointing me towards stack unwinding. I don't have debug 
> information much of the time, so I'm depending on the architecture rules for 
> backtracing. A look at the mips ABI plugin shows it uses dwarf register 
> numbers to get the register values it needs, and I wasn't including them in 
> my qRegisterInfo responses. After fixing this, step over and step out appear 
> to work correctly, which is a great help.
> 
> However, backtraces only show 2 frames with the current pc and ra values, no 
> matter where I am, so it seems there's some problem getting stack frame info 
> from the actual stack. I've attached an unwind log from running bt inside a 
> function that should have a deeper backtrace. The afa value of 
> 0x looks suspicious to me, but I don't really understand 
> where it comes from. The frame before 0x8002ee70 should, I think, be 
> 0x80026a6c, as that's the pc after stepping out twice.
> 
> Thanks,
> Alexander 
> 
> On Sun, Jan 26, 2020 at 4:21 PM Jason Molenda  wrote:
> I suspect your problem may be related to lldb not knowing how to walk the 
> stack on this target.  Is  mips-unknown-linux-gnu correct?  What do you see 
> if you turn on unwind logging, 'log enable lldb unwind'.  You can also have 
> lldb show you the unwind rules at the current pc value with 'image 
> show-unwind -a $pc'.  I don't know what unwinders we have defined for this 
> target in lldb right now -- if you have eh_frame information in your binary, 
> lldb should read & use that.  Otherwise, if you have an assembly instruction 
> profiler in lldb for mips, and start addresses for your functions, lldb 
> should be able to inspect the instruction stream and figure out how to unwind 
> out of the function correctly.  As a last resort, it will fall back to 
> architecture rules for how to backtrace out of a function (defined in the ABI 
> plugin) but those are often incorrect in prologue/epilogues (start & end of a 
> function).
> 
> 
> 
> (btw if you support no-ack mode, there's a lot less packet traffic between 
> your stub and lldb - recommended.)
> 
> 
> J
> 
> 
> 
> 
> > On Jan 25, 2020, at 3:08 PM, Alexander Zhang via lldb-dev 
> >  wrote:
> > 
> > Hi,
> > 
> > I've been implementing a basic RSP protocol server for remotely debugging a 
> > MIPS simulator, and have been having some trouble getting certain lldb 
> > features to work there, in particular backtraces (bt) and instruction step 
> > over (ni). Does someone know what packets these commands rely on to work? 
> > I've attached some communication logs, and if it helps my code is at 
> > https://github.com/CQCumbers/nmulator/blob/master/src/debugger.h
> > 
> > Please forgive me if this isn't the right