diff options
author | Jason Molenda <jmolenda@apple.com> | 2025-06-30 21:27:53 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-30 21:27:53 -0700 |
commit | e94c6091c93a72e9b81cf8d6394495d043b409d4 (patch) | |
tree | 52484d0fb2037ce2b89c08e56cad890030b582ae /lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | |
parent | ce159d20e52add25e51f2aa8c504726221b204ba (diff) | |
download | llvm-e94c6091c93a72e9b81cf8d6394495d043b409d4.zip llvm-e94c6091c93a72e9b81cf8d6394495d043b409d4.tar.gz llvm-e94c6091c93a72e9b81cf8d6394495d043b409d4.tar.bz2 |
[lldb][Mach-O] Fix several bugs in x86_64 Mach-O corefile (#146460)
reading, and one bug in the new RegisterContextUnifiedCore class.
The PR I landed a few days ago to allow Mach-O corefiles to augment
their registers with additional per-thread registers in metadata exposed
a few bugs in the x86_64 corefile reader when running under different CI
environments. It also showed a bug in my RegisterContextUnifiedCore
class where I wasn't properly handling lookups of unknown registers
(e.g. the LLDB_GENERIC_RA when debugging an intel target).
The Mach-O x86_64 corefile support would say that it had fpu & exc
registers available in every corefile, regardless of whether they were
actually present. It would only read the bytes for the first register
flavor in the LC_THREAD, the GPRs, but it read them incorrectly, so
sometimes you got more register context than you'd expect. The LC_THREAD
register context specifies a flavor and the number of uint32_t words;
the ObjectFileMachO method would read that number of uint64_t's,
exceeding the GPR register space, but it was followed by FPU and then
EXC register space so it didn't crash. If you had a corefile with GPR
and EXC register bytes, it would be written into the GPR and then FPU
register areas, with zeroes filling out the rest of the context.
Diffstat (limited to 'lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp')
-rw-r--r-- | lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | 66 |
1 files changed, 26 insertions, 40 deletions
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 4394caf..70f954c 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -184,46 +184,32 @@ public: SetError(GPRRegSet, Read, -1); SetError(FPURegSet, Read, -1); SetError(EXCRegSet, Read, -1); - bool done = false; - while (!done) { + while (offset < data.GetByteSize()) { int flavor = data.GetU32(&offset); if (flavor == 0) - done = true; - else { - uint32_t i; - uint32_t count = data.GetU32(&offset); - switch (flavor) { - case GPRRegSet: - for (i = 0; i < count; ++i) - (&gpr.rax)[i] = data.GetU64(&offset); - SetError(GPRRegSet, Read, 0); - done = true; - - break; - case FPURegSet: - // TODO: fill in FPU regs.... - // SetError (FPURegSet, Read, -1); - done = true; - - break; - case EXCRegSet: - exc.trapno = data.GetU32(&offset); - exc.err = data.GetU32(&offset); - exc.faultvaddr = data.GetU64(&offset); - SetError(EXCRegSet, Read, 0); - done = true; - break; - case 7: - case 8: - case 9: - // fancy flavors that encapsulate of the above flavors... - break; - - default: - done = true; - break; - } + break; + uint32_t count = data.GetU32(&offset); + switch (flavor) { + case GPRRegSet: { + uint32_t *gpr_data = reinterpret_cast<uint32_t *>(&gpr.rax); + for (uint32_t i = 0; i < count && offset < data.GetByteSize(); ++i) + gpr_data[i] = data.GetU32(&offset); + SetError(GPRRegSet, Read, 0); + } break; + case FPURegSet: + // TODO: fill in FPU regs.... + SetError(FPURegSet, Read, -1); + break; + case EXCRegSet: + exc.trapno = data.GetU32(&offset); + exc.err = data.GetU32(&offset); + exc.faultvaddr = data.GetU64(&offset); + SetError(EXCRegSet, Read, 0); + break; + default: + offset += count * 4; + break; } } } @@ -353,11 +339,11 @@ public: } protected: - int DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) override { return 0; } + int DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) override { return -1; } - int DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) override { return 0; } + int DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) override { return -1; } - int DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) override { return 0; } + int DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) override { return -1; } int DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr) override { return 0; |