[all-commits] [llvm/llvm-project] 49b3c3: [lldb][x86_64] Support fs_base/gs_base register in...

jeffreytan81 via All-commits all-commits at lists.llvm.org
Thu Jul 20 16:33:06 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 49b3c3355f9c36a023e04bba509ac89d15da6ff9
      https://github.com/llvm/llvm-project/commit/49b3c3355f9c36a023e04bba509ac89d15da6ff9
  Author: Jeffrey Tan <jeffreytan at fb.com>
  Date:   2023-07-20 (Thu, 20 Jul 2023)

  Changed paths:
    M lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
    M lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h
    M lldb/source/Plugins/Process/Utility/CMakeLists.txt
    M lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_x86.h
    M lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp
    M lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp
    M lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.h
    M lldb/source/Plugins/Process/Utility/RegisterContext_x86.h
    A lldb/source/Plugins/Process/Utility/RegisterInfos_x86_64_with_base.h
    A lldb/source/Plugins/Process/Utility/RegisterInfos_x86_64_with_base_shared.cpp
    A lldb/source/Plugins/Process/Utility/RegisterInfos_x86_64_with_base_shared.h
    M lldb/source/Plugins/Process/Utility/lldb-x86-register-enums.h
    M lldb/source/Plugins/Process/elf-core/CMakeLists.txt
    A lldb/source/Plugins/Process/elf-core/RegisterContextLinuxCore_x86_64.cpp
    A lldb/source/Plugins/Process/elf-core/RegisterContextLinuxCore_x86_64.h
    M lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
    M lldb/test/API/commands/register/register/register_command/TestRegisters.py
    M lldb/test/API/functionalities/postmortem/elf-core/thread_crash/TestLinuxCoreThreads.py

  Log Message:
  -----------
  [lldb][x86_64] Support fs_base/gs_base register in Linux

Summary:
[lldb][x86_64] This patch adds fs_base/gs_base support for Linux x86_64.

Originally, I plan to split the diff into two parts, one to refactoring lldb_xxx_x86_64 => x86_64::lldb_xxx across code base and the other one for adding fs_base/gs_base, but it turns out to be a non-trivial effort to split and very error prone so I decided to keep a single diff to get feedback.

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 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 g_contained_XXX/g_invalidate_XXX and RegInfo related code sharing.
* `RegisterContextPOSIX_x86 ::m_gpr_x86_64` seems to be unused so I removed it.
* `NativeRegisterContextDBReg_x86::GetDR()` is overridden in `NativeRegisterContextLinux_x86_64` to make watchpoint work.

Reviewers:clayborg,labath,jingham,jdoerfert,JDevlieghere,kusmour,GeorgeHuyubo

Subscribers:

Tasks:

Tags:

Differential Revision: https://reviews.llvm.org/D155256




More information about the All-commits mailing list