Skip to content

Commit

Permalink
pw_thread: Add missing top-of-stack value in thread stack snapshot
Browse files Browse the repository at this point in the history
Change-Id: Ibcda63cc31871af4d8c4c4902ea683b759c72d8f
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/123490
Reviewed-by: RJ Ascani <[email protected]>
Pigweed-Auto-Submit: Harish Kulkarni <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
Reviewed-by: Armando Montanez <[email protected]>
  • Loading branch information
Harish Kulkarni authored and CQ Bot Account committed Dec 12, 2022
1 parent 9746313 commit f93c974
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pw_thread/public/pw_thread/thread_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ class ThreadInfo {

void clear_stack_high_addr() { clear_stack_info_ptr(kStackHighAddress); }

constexpr std::optional<uintptr_t> stack_pointer() const {
return get_stack_info_ptr(kStackPointer);
}

void set_stack_pointer(uintptr_t val) {
set_stack_info_ptr(kStackPointer, val);
}

void clear_stack_pointer() { clear_stack_info_ptr(kStackPointer); }

constexpr std::optional<uintptr_t> stack_peak_addr() const {
return get_stack_info_ptr(kStackPeakAddress);
}
Expand All @@ -78,6 +88,7 @@ class ThreadInfo {
enum ThreadInfoIndex {
kStackLowAddress,
kStackHighAddress,
kStackPointer,
kStackPeakAddress,
kThreadName,
kMaxNumMembersDoNotUse,
Expand Down
5 changes: 5 additions & 0 deletions pw_thread/thread_snapshot_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ Status ProtoEncodeThreadInfo(SnapshotThreadInfo::StreamEncoder& encoder,
// Need stack start pointer to contextualize estimated peak.
return Status::FailedPrecondition();
}
if (thread_info.stack_pointer().has_value()) {
PW_TRY(
proto_encoder.WriteStackPointer(thread_info.stack_pointer().value()));
}

if (thread_info.stack_peak_addr().has_value()) {
PW_TRY(proto_encoder.WriteStackPointerEstPeak(
thread_info.stack_peak_addr().value()));
Expand Down
2 changes: 2 additions & 0 deletions pw_thread_freertos/thread_iteration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ bool StackInfoCollector(TaskHandle_t current_thread,
as_bytes(span(std::string_view(tcb.pcTaskName)));
thread_info.set_thread_name(current_name);

thread_info.set_stack_pointer(reinterpret_cast<uintptr_t>(tcb.pxTopOfStack));

// Current thread stack bounds.
thread_info.set_stack_low_addr(reinterpret_cast<uintptr_t>(tcb.pxStack));
#if configRECORD_STACK_HIGH_ADDRESS
Expand Down

0 comments on commit f93c974

Please sign in to comment.