Skip to content

Commit

Permalink
lldb-netbsd: Implement unwinding of code that caused interruption
Browse files Browse the repository at this point in the history
Changes:
 - porting NativeRegisters on x86 64-bit
 - fix code reading memory from tracee's address space

Trace of the following program:

int
main(int argc, char **argv)
{
        printf("Hello world!\n");

        __asm__ __volatile__("int3;\n");

        return 0;
}

$ lldb
(lldb) process connect connect://localhost:1234
Process 21323 stopped
* thread #1, stop reason = The signal Stopped (signal) was caught
    frame #0: 0x00007f7f3c800740
->  0x7f7f3c800740: subq   $0x10, %rsp
    0x7f7f3c800744: movq   %rsp, %r12
    0x7f7f3c800747: pushq  %rbx
    0x7f7f3c800748: andq   $-0x10, %rsp
(lldb) c
Process 21323 resuming
Hello world!
Process 21323 stopped
* thread #1, stop reason = signal SIGTRAP
    frame #0: 0x000000000040088a
->  0x40088a: movl   $0x0, %eax
    0x40088f: leave
    0x400890: retq
    0x400891: addb   %al, (%rax)
(lldb) c
Process 21323 resuming
Process 21323 exited with status = 0 (0x00000000)
(lldb)

Sponsored by <The NetBSD Foundation>
  • Loading branch information
krytarowski committed Mar 11, 2017
1 parent 547bcaf commit 8207a0e
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 745 deletions.
10 changes: 5 additions & 5 deletions lldb-netbsd/distinfo
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ SHA1 (patch-source_Host_netbsd_ThisThread.cpp) = f0d32c81bc1b8fe9aeb86519ea46ba2
SHA1 (patch-source_Initialization_SystemInitializerCommon.cpp) = dc270227e68c655753ef5f5168e3fa9a8dab3696
SHA1 (patch-source_Plugins_Process_CMakeLists.txt) = c689ff4ec455234f8d506dc9eb8e0ed7f750d426
SHA1 (patch-source_Plugins_Process_NetBSD_CMakeLists.txt) = a77f397020ab752875813a7a93b53ccd3a130e6f
SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp) = 64ad94ee859712090bebd1e9dbf79d4add4de448
SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp) = 533e215f48d9d5569771082611be3fee059744ec
SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h) = c48bb2dd45682164ab904b8b3f7664b91ac35d5b
SHA1 (patch-source_Plugins_Process_NetBSD_NativeRegisterContextNetBSD.cpp) = d3ba093e776ce3af1a6d6f5f5263e5535f8cdec9
SHA1 (patch-source_Plugins_Process_NetBSD_NativeRegisterContextNetBSD.h) = c9bd447b3a5e70475d1b857c5441a59c7b2a54ba
SHA1 (patch-source_Plugins_Process_NetBSD_NativeRegisterContextNetBSD__x86__64.cpp) = e937316bee978570c9fe27caa859ba5d35763761
SHA1 (patch-source_Plugins_Process_NetBSD_NativeRegisterContextNetBSD__x86__64.h) = 58803697f65411d1ad62e45c6af68c9271633bac
SHA1 (patch-source_Plugins_Process_NetBSD_NativeRegisterContextNetBSD.cpp) = c503ae3b197da1c9555e314d17cb88b4ce2b4ba9
SHA1 (patch-source_Plugins_Process_NetBSD_NativeRegisterContextNetBSD.h) = 8c0e41f16445e894a18eee6cae8d3d31ba7c8dd9
SHA1 (patch-source_Plugins_Process_NetBSD_NativeRegisterContextNetBSD__x86__64.cpp) = 196f33520950262d2ca59f1dc6a019e0ba2e3e7c
SHA1 (patch-source_Plugins_Process_NetBSD_NativeRegisterContextNetBSD__x86__64.h) = fa3980158bfe07b476c883b2354329dac9eb0c22
SHA1 (patch-source_Plugins_Process_NetBSD_NativeThreadNetBSD.cpp) = cb8757705327e62273bfe9a84dbdbf9cb9b0751a
SHA1 (patch-source_Plugins_Process_NetBSD_NativeThreadNetBSD.h) = c675af8495a75f99bb60cb4ab3fa36223f1cb6f4
SHA1 (patch-source_Plugins_Process_gdb-remote_GDBRemoteCommunicationServerCommon.cpp) = 76e3f6a3e0a24a28a2f5a30e8812906f8a2b2649
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$NetBSD$

--- source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp.orig 2017-03-03 15:35:02.252988829 +0000
--- source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp.orig 2017-03-11 07:50:19.309994898 +0000
+++ source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
@@ -0,0 +1,1307 @@
+//===-- NativeProcessNetBSD.cpp -------------------------------- -*- C++ -*-===//
Expand Down Expand Up @@ -1126,7 +1126,7 @@
+
+ do {
+ io.piod_offs = (void *)(addr + bytes_read);
+ io.piod_offs = dst + bytes_read;
+ io.piod_addr = dst + bytes_read;
+
+ Error error = NativeProcessNetBSD::PtraceWrapper(
+ PT_IO, GetID(), &io);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
$NetBSD$

--- source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp.orig 2017-03-03 15:35:02.265865750 +0000
--- source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp.orig 2017-03-11 07:50:19.322535530 +0000
+++ source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp
@@ -0,0 +1,111 @@
@@ -0,0 +1,112 @@
+//===-- NativeRegisterContextNetBSD.cpp --------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
Expand Down Expand Up @@ -31,7 +31,8 @@
+ NativeThreadProtocol &native_thread, uint32_t concrete_frame_idx,
+ RegisterInfoInterface *reg_info_interface_p)
+ : NativeRegisterContextRegisterInfo(native_thread, concrete_frame_idx,
+ reg_info_interface_p) {}
+ reg_info_interface_p) {
+}
+
+lldb::ByteOrder NativeRegisterContextNetBSD::GetByteOrder() const {
+ // Get the target process whose privileged thread was used for the register
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
$NetBSD$

--- source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h.orig 2017-03-03 15:35:02.272170791 +0000
--- source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h.orig 2017-03-11 07:50:19.328597210 +0000
+++ source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h
@@ -0,0 +1,76 @@
@@ -0,0 +1,78 @@
+//===-- NativeRegisterContextNetBSD.h ----------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
Expand Down Expand Up @@ -60,6 +60,8 @@
+
+ virtual void *GetFPRBuffer() { return nullptr; }
+
+ virtual void *GetDBRBuffer() { return nullptr; }
+
+ virtual size_t GetFPRSize() { return 0; }
+
+ virtual Error DoReadGPR(void *buf);
Expand Down
Loading

0 comments on commit 8207a0e

Please sign in to comment.