[Lldb-commits] [PATCH] D155256: Add fs_base/gs_base support for Linux

jeffrey tan via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Jul 13 19:56:59 PDT 2023


yinghuitan created this revision.
yinghuitan added reviewers: clayborg, labath, jingham, jdoerfert, JDevlieghere, kusmour, GeorgeHuyubo.
Herald added subscribers: pengfei, emaste.
Herald added a project: All.
yinghuitan requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This patch adds fs_base/gs_base support for Linux x86_64.

GDB supports fs_base/gs_base registers while LLDB does not. Since both linux coredump note section and ptrace
supports them it is a missing feature.

For context, this is a required feature to support getting pthread pointer on linux from both live and dump debugging.
See thread below for details:
https://discourse.llvm.org/t/how-to-get-pthread-pointer-from-lldb/70542/2?u=jeffreytan81

Implementation wise, we have initially tried `#ifdef` approach to reuse the code but it is introducing very tricky bugs and proves 
hard to maintain. Instead the diff completely separates the registers between x86_64 and x86_64_with_base so that non-linux related
implementations can use x86_64 registers while linux uses x86_64_with_base.
Here are the list of changes done in the patch:

- Registers in lldb-x86-register-enums.h are separated into two: x86_64 and x86_64_with_base
- fs_base/gs_base are added into x86_64_with_base
- All registers are renamed from lldb_xxx_x86_64 => x86_64::lldb_xxx across code base
- All macros are changed to use x86_64::lldb_xxx as well
- All linux files are change to use x86_64::lldb_xxx => x86_64_with_base::lldb_xxx
- Support linux elf-core:
  - A new RegisterContextLinuxCore_x86_64 class is added for ThreadElfCore
  - RegisterContextLinuxCore_x86_64 overrides and uses its own register set supports fs_base/gs_base
  - RegisterInfos_x86_64_with_base/RegisterInfos_x86_64_with_base_shared ared added to provide fs_base/gs_base for sharing.

[WIP] Add tests for the fs_base/gs_base.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155256

Files:
  lldb/source/Plugins/ObjectFile/PECOFF/PECallFrameInfo.cpp
  lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_x86_64.cpp
  lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_x86_64.cpp
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h
  lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp
  lldb/source/Plugins/Process/Utility/CMakeLists.txt
  lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_x86.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextNetBSD_x86_64.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.h
  lldb/source/Plugins/Process/Utility/RegisterContextWindows_x86_64.cpp
  lldb/source/Plugins/Process/Utility/RegisterContext_x86.h
  lldb/source/Plugins/Process/Utility/RegisterInfos_x86_64.h
  lldb/source/Plugins/Process/Utility/RegisterInfos_x86_64_with_base.h
  lldb/source/Plugins/Process/Utility/RegisterInfos_x86_64_with_base_shared.cpp
  lldb/source/Plugins/Process/Utility/RegisterInfos_x86_64_with_base_shared.h
  lldb/source/Plugins/Process/Utility/lldb-x86-register-enums.h
  lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_x86_64.cpp
  lldb/source/Plugins/Process/Windows/Common/x64/RegisterContextWindows_x64.cpp
  lldb/source/Plugins/Process/elf-core/CMakeLists.txt
  lldb/source/Plugins/Process/elf-core/RegisterContextLinuxCore_x86_64.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextLinuxCore_x86_64.h
  lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
  lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/CodeViewRegisterMapping.cpp
  lldb/unittests/ObjectFile/PECOFF/TestPECallFrameInfo.cpp
  lldb/unittests/Process/Utility/RegisterContextFreeBSDTest.cpp
  lldb/unittests/Process/Utility/RegisterContextNetBSDTest_x86_64.cpp
  lldb/unittests/Process/minidump/RegisterContextMinidumpTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155256.540255.patch
Type: text/x-patch
Size: 226033 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230714/396051d8/attachment-0001.bin>


More information about the lldb-commits mailing list