From a8bfee2a356a2e70f854bf6d0b364798f4183795 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20G=C3=B3rny?= Date: Wed, 11 Nov 2020 14:51:16 +0100 Subject: [PATCH] [lldb] [Process/Utility] Fix DR offsets for FreeBSD Fix Debug Register offsets to be specified relatively to UserArea on FreeBSD/amd64 and FreeBSD/i386, and add them to UserArea on i386. This fixes overlapping GPRs and DRs in gdb-remote protocol, making it impossible to correctly get and set debug registers from the LLDB client. Differential Revision: https://reviews.llvm.org/D91254 --- .../source/Plugins/Process/Utility/RegisterContextFreeBSD_i386.cpp | 7 +++++-- .../Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.cpp | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_i386.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_i386.cpp index 10d346a..acebe9d 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_i386.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_i386.cpp @@ -35,7 +35,7 @@ struct GPR { uint32_t gs; }; -struct dbreg { +struct DBG { uint32_t dr[8]; /* debug registers */ /* Index 0-3: debug address registers */ /* Index 4-5: reserved */ @@ -48,10 +48,13 @@ using FPR_i386 = FXSAVE; struct UserArea { GPR gpr; FPR_i386 i387; + DBG dbg; }; #define DR_SIZE sizeof(uint32_t) -#define DR_OFFSET(reg_index) (LLVM_EXTENSION offsetof(dbreg, dr[reg_index])) +#define DR_OFFSET(reg_index) \ + (LLVM_EXTENSION offsetof(UserArea, dbg) + \ + LLVM_EXTENSION offsetof(DBG, dr[reg_index])) // Include RegisterInfos_i386 to declare our g_register_infos_i386 structure. #define DECLARE_REGISTER_INFOS_I386_STRUCT diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.cpp index c1f390a..e0f3971 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.cpp @@ -59,7 +59,9 @@ struct UserArea { DBG dbg; }; -#define DR_OFFSET(reg_index) (LLVM_EXTENSION offsetof(DBG, dr[reg_index])) +#define DR_OFFSET(reg_index) \ + (LLVM_EXTENSION offsetof(UserArea, dbg) + \ + LLVM_EXTENSION offsetof(DBG, dr[reg_index])) // Include RegisterInfos_x86_64 to declare our g_register_infos_x86_64 // structure. -- 2.7.4