[Lldb-commits] [PATCH] D139158: [LLDB][LoongArch] Make software single stepping work

Hui Li via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Dec 1 17:04:35 PST 2022


lh03061238 created this revision.
lh03061238 added reviewers: SixWeining, wangleiat, xen0n, xry111, MaskRay, DavidSpickett.
Herald added subscribers: StephenFan, s.egerton, simoncook.
Herald added a project: All.
lh03061238 requested review of this revision.
Herald added subscribers: lldb-commits, pcwang-thead.
Herald added a project: LLDB.

Hardware single stepping is not currently supported by the linux kernel. 
In order to support single step debugging, add EmulateInstructionLoongArch 
to implement the software Single Stepping. This patch only support the 
simplest single step execution of non-jump instructions.

Here is a simple test:

  loongson at linux:~$ cat test.c
  #include<stdio.h>
  
  int main()
  {
  	int i = 1;
  
  	i = i + 2;
  
  	return 0;
  }
  loongson at linux:~$ clang -g test.c  -o test

Without this patch:

  loongson at linux:~$ llvm-project/llvm/build/bin/lldb test
  (lldb) target create "test"
  Current executable set to '/home/loongson/test' (loongarch64).
  (lldb) b main
  Breakpoint 1: where = test`main + 24 at test.c:5:6, address = 0x0000000120000628
  (lldb) r
  Process 43090 launched: '/home/loongson/test' (loongarch64)
  Process 43090 exited with status = -1 (0xffffffff) lost connection
  (lldb)

With this patch:

  loongson at linux:~$ llvm-project/llvm/build/bin/lldb test
  (lldb) target create "test"
  Current executable set to '/home/loongson/test' (loongarch64).
  (lldb) b main
  Breakpoint 1: where = test`main + 24 at test.c:5:6, address = 0x0000000120000628
  (lldb) r
  Process 42467 launched: '/home/loongson/test' (loongarch64)
  Process 42467 stopped
  * thread #1, name = 'test', stop reason = breakpoint 1.1
      frame #0: 0x0000000120000628 test`main at test.c:5:6
     2   	
     3   	int main()
     4   	{
  -> 5   		int i = 1;
     6   	
     7   		i = i + 2;
     8   	
  (lldb) n
  Process 42467 stopped
  * thread #1, name = 'test', stop reason = step over
      frame #0: 0x000000012000062c test`main at test.c:7:6
     4   	{
     5   		int i = 1;
     6   	
  -> 7   		i = i + 2;
     8   	
     9   		return 0;
     10  	}
  (lldb) var i
  (int) i = 1
  (lldb) n
  Process 42467 stopped
  * thread #1, name = 'test', stop reason = step over
      frame #0: 0x000000012000063c test`main at test.c:9:2
     6   	
     7   		i = i + 2;
     8   	
  -> 9   		return 0;
     10  	}
  (lldb) var i
  (int) i = 3
  (lldb) n
  Process 42467 exited with status = 0 (0x00000000) 
  (lldb) q
  loongson at linux:~$


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139158

Files:
  lldb/source/Plugins/Instruction/CMakeLists.txt
  lldb/source/Plugins/Instruction/LoongArch/CMakeLists.txt
  lldb/source/Plugins/Instruction/LoongArch/EmulateInstructionLoongArch.cpp
  lldb/source/Plugins/Instruction/LoongArch/EmulateInstructionLoongArch.h
  lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/source/Plugins/Process/Utility/NativeProcessSoftwareSingleStep.cpp
  lldb/tools/lldb-server/CMakeLists.txt
  lldb/tools/lldb-server/SystemInitializerLLGS.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139158.479471.patch
Type: text/x-patch
Size: 12540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20221202/9cbfdd1f/attachment-0001.bin>


More information about the lldb-commits mailing list