[Lldb-commits] [lldb] [LLDB/Coredump] Only take the Pthread from stack start to the stackpointer + red_zone (PR #92002)
Greg Clayton via lldb-commits
lldb-commits at lists.llvm.org
Thu May 16 10:37:11 PDT 2024
================
@@ -6410,12 +6410,20 @@ GetCoreFileSaveRangesStackOnly(Process &process,
if (!reg_ctx_sp)
continue;
const addr_t sp = reg_ctx_sp->GetSP();
+ const size_t red_zone = process.GetABI()->GetRedZoneSize();
lldb_private::MemoryRegionInfo sp_region;
if (process.GetMemoryRegionInfo(sp, sp_region).Success()) {
// Only add this region if not already added above. If our stack pointer
// is pointing off in the weeds, we will want this range.
- if (stack_bases.count(sp_region.GetRange().GetRangeBase()) == 0)
+ if (stack_bases.count(sp_region.GetRange().GetRangeBase()) == 0) {
+ // Take only the start of the stack to the stack pointer and include the redzone.
+ // Because stacks grow 'down' to include the red_zone we have to subtract it from the sp.
+ const size_t stack_head = (sp - red_zone);
----------------
clayborg wrote:
> It depends on where does the API get the value from. I haven't looked but it is likely `GetRedZoneSize()` value is fetched from dwarf, which can be bogus value generated from compiler/linker/BOLT etc...
>
> Simply sanity check that `if (stack_head > sp_region.GetRange().GetRangeBase())` will ensure we are not reading reading beyond valid memory region.
Red zone is gotten from the ABI plug-ins. This is correct behavior, but we should make sure that `(sp - red_zone)` is actually not before the start of the memory region.
```
const addr_t stack_head = (sp - red_zone) > sp_region.GetRange.GetRangeBase() ? (sp - red_zone) : sp_region.GetRange.GetRangeBase();
```
https://github.com/llvm/llvm-project/pull/92002
More information about the lldb-commits
mailing list