[Lldb-commits] [PATCH] D149224: Fix an off-by-one error with armv7 mach-o corefile register contexts (LC_THREADs)
Jason Molenda via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Apr 25 18:14:26 PDT 2023
jasonmolenda created this revision.
jasonmolenda added reviewers: fixathon, JDevlieghere.
jasonmolenda added a project: LLDB.
Herald added subscribers: omjavaid, kristof.beyls.
Herald added a project: All.
jasonmolenda requested review of this revision.
Herald added a subscriber: lldb-commits.
Slava was doing some fixups in ObjectFileMachO last August and one of the changes had a small off-by-one error, https://reviews.llvm.org/D131554 . A bunch of folks (including myself) looked at this specific bit of code and didn't see the issue, and there's no testsuite coverage for it.
This bit of code in `RegisterContextDarwin_arm_Mach::SetRegisterDataFrom_LC_THREAD` is reading the data for an ARM_THREAD_STATE register context, which has a fixed size for all practical purposes here. (the whole scheme of having ARM_THREAD_STATE + ARM_THREAD_STATE_COUNT is to allow for new registers to be added in the future and code to be able to detect which version it is based on size -- but I don't expect us to add additional register to the armv7 register context as this point).
Slava's change added a bounds check to ensure it was non-zero and within the max size of the ARM_THREAD_STATE state size. This bounds check didn't account for the cpsr register after the set of general purpose registers, so the register context wasn't being loaded from corefiles. We can simplify this by checking for equality for the total number of words for ARM_THREAD_STATE.
I also added a new test case that creates an empty armv7 and arm64 mach-o corefile with two register contexts, loads them into lldb and confirms that it could retrieve registers from both of the register contexts in both. I only have this test set to build & run on Darwin systems because I use Mach-O constants in the utility I wrote to create the nearly-empty corefiles. Too easy to miss a tiny problem like this when there's no test coverage.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149224
Files:
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/test/API/macosx/arm-corefile-regctx/Makefile
lldb/test/API/macosx/arm-corefile-regctx/TestArmMachoCorefileRegctx.py
lldb/test/API/macosx/arm-corefile-regctx/create-arm-corefiles.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149224.517005.patch
Type: text/x-patch
Size: 11589 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230426/64eff4ba/attachment-0001.bin>
More information about the lldb-commits
mailing list