diff options
| author | Ravitheja Addepally <ravitheja.addepally@intel.com> | 2015-08-13 09:05:11 +0000 |
|---|---|---|
| committer | Ravitheja Addepally <ravitheja.addepally@intel.com> | 2015-08-13 09:05:11 +0000 |
| commit | 4778e410d0b33dc6f5837683ccd0e439a9b69d9e (patch) | |
| tree | 919751d5ea3ac51757137b987c8ce97a79447991 /lldb/source | |
| parent | 0164b8ff70e814cd60621b0fcfbc5b86637efbb3 (diff) | |
| download | bcm5719-llvm-4778e410d0b33dc6f5837683ccd0e439a9b69d9e.tar.gz bcm5719-llvm-4778e410d0b33dc6f5837683ccd0e439a9b69d9e.zip | |
Set orig_eax to -1 for Linux x86 platforms
Summary:
For Linux x86 based environments the orig_eax/orig_rax
register should be set to -1 to prevent the instruction pointer
to be decremented, which was the cause for the SIGILL exception.
Fix for Bug 23659
Reviewers: zturner, ashok.thirumurthi, mikesart, jingham, clayborg
Subscribers: clayborg, labath
Differential Revision: http://reviews.llvm.org/D11411
llvm-svn: 244875
Diffstat (limited to 'lldb/source')
6 files changed, 79 insertions, 2 deletions
diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp index 5abafec5a32..1cf115af2a6 100644 --- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp @@ -706,6 +706,34 @@ NativeRegisterContextLinux_x86_64::ReadAllRegisterValues (lldb::DataBufferSP &da assert (false && "how do we save the floating point registers?"); error.SetErrorString ("unsure how to save the floating point registers"); } + /** The following code is specific to Linux x86 based architectures, + * where the register orig_eax (32 bit)/orig_rax (64 bit) is set to + * -1 to solve the bug 23659, such a setting prevents the automatic + * decrement of the instruction pointer which was causing the SIGILL + * exception. + * **/ + llvm::Triple t_triple = GetRegisterInfoInterface().GetTargetArchitecture().GetTriple(); + + if (t_triple.getOS() == llvm::Triple::Linux && + (t_triple.getArch() == llvm::Triple::x86 || + t_triple.getArch() == llvm::Triple::x86_64)) + { + RegisterValue value((uint64_t) -1); + const RegisterInfo *reg_info = GetRegisterInfoInterface().GetDynamicRegisterInfo("orig_eax"); + if (reg_info == nullptr) + reg_info = GetRegisterInfoInterface().GetDynamicRegisterInfo("orig_rax"); + + if (reg_info != nullptr) { + NativeProcessProtocolSP process_sp(m_thread.GetProcess()); + if (!process_sp) + return Error("NativeProcessProtocol is NULL"); + + NativeProcessLinux* process_p = static_cast<NativeProcessLinux*>(process_sp.get()); + return process_p->DoOperation([&] { + return DoWriteRegisterValue(reg_info->byte_offset,reg_info->name,value); + }); + } + } return error; } diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp index 4f6bbc8f8ab..de35f591ae2 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp @@ -26,7 +26,7 @@ struct GPR uint32_t es; uint32_t fs; uint32_t gs; - uint32_t orig_ax; + uint32_t orig_eax; uint32_t eip; uint32_t cs; uint32_t eflags; @@ -98,6 +98,9 @@ struct UserArea RegisterContextLinux_i386::RegisterContextLinux_i386(const ArchSpec &target_arch) : RegisterInfoInterface(target_arch) { + RegisterInfo orig_ax = { "orig_eax", NULL, sizeof(((GPR*)NULL)->orig_eax), (LLVM_EXTENSION offsetof(GPR, orig_eax)), eEncodingUint, \ + eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, NULL, NULL }; + d_register_infos.push_back(orig_ax); } size_t @@ -131,3 +134,9 @@ RegisterContextLinux_i386::GetUserRegisterCount () const { return static_cast<uint32_t> (k_num_user_registers_i386); } + +const std::vector<lldb_private::RegisterInfo> * +RegisterContextLinux_i386::GetDynamicRegisterInfoP() const +{ + return &d_register_infos; +} diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.h b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.h index cb71d7993e1..dfe6b6b39d0 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.h +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.h @@ -29,6 +29,12 @@ public: uint32_t GetUserRegisterCount () const override; + + const std::vector<lldb_private::RegisterInfo> * + GetDynamicRegisterInfoP() const override; + +private: + std::vector<lldb_private::RegisterInfo> d_register_infos; }; #endif diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp index c0993b47a12..78afe72fcfa 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp @@ -32,7 +32,7 @@ typedef struct _GPR uint64_t rdx; uint64_t rsi; uint64_t rdi; - uint64_t orig_ax; + uint64_t orig_rax; uint64_t rip; uint64_t cs; uint64_t rflags; @@ -171,6 +171,9 @@ RegisterContextLinux_x86_64::RegisterContextLinux_x86_64(const ArchSpec &target_ m_register_info_count (GetRegisterInfoCount (target_arch)), m_user_register_count (GetUserRegisterInfoCount (target_arch)) { + RegisterInfo orig_ax = { "orig_rax", NULL, sizeof(((GPR*)NULL)->orig_rax), (LLVM_EXTENSION offsetof(GPR, orig_rax)), eEncodingUint, \ + eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, NULL, NULL }; + d_register_infos.push_back(orig_ax); } size_t @@ -179,6 +182,12 @@ RegisterContextLinux_x86_64::GetGPRSize() const return sizeof(GPR); } +const std::vector<lldb_private::RegisterInfo> * +RegisterContextLinux_x86_64::GetDynamicRegisterInfoP() const +{ + return &d_register_infos; +} + const RegisterInfo * RegisterContextLinux_x86_64::GetRegisterInfo() const { diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h index 0cdfae9ac94..87439a41260 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h @@ -30,10 +30,15 @@ public: uint32_t GetUserRegisterCount () const override; + const std::vector<lldb_private::RegisterInfo> * + GetDynamicRegisterInfoP() const override; + private: const lldb_private::RegisterInfo *m_register_info_p; uint32_t m_register_info_count; uint32_t m_user_register_count; + std::vector<lldb_private::RegisterInfo> d_register_infos; + }; #endif diff --git a/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h b/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h index 94cb5cc791c..5055efc4f2e 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h +++ b/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h @@ -50,6 +50,26 @@ namespace lldb_private GetTargetArchitecture() const { return m_target_arch; } + virtual const lldb_private::RegisterInfo * + GetDynamicRegisterInfo(const char *reg_name) const + { + const std::vector <lldb_private::RegisterInfo> * d_register_infos = GetDynamicRegisterInfoP(); + if(d_register_infos != nullptr) + { + std::vector <lldb_private::RegisterInfo> ::const_iterator pos = d_register_infos->begin(); + for(; pos < d_register_infos->end() ; pos++) + { + if(::strcmp(reg_name, pos->name) == 0) + return(d_register_infos->data() + (pos - d_register_infos->begin()) ); + } + } + return nullptr; + } + + virtual const std::vector<lldb_private::RegisterInfo> * + GetDynamicRegisterInfoP() const + { return nullptr; } + public: // FIXME make private. lldb_private::ArchSpec m_target_arch; |

