DLPX-95965 _framestr() parsing is fragile - should use drgn StackFrame API properties #356
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
DLPX-95965 Replace fragile string parsing in _framestr() with drgn StackFrame API
Problem
@mmaybee called out in #352 that the
_framestr()function was using string parsing onstr(frame)output to extract frame information. This approach was brittle and could break if drgn's string representation format changed.Solution
This PR replaces the string parsing with direct use of drgn StackFrame API properties:
frame.pc- Program counter (address)frame.function_name- Function name (or None if unavailable)frame.symbol()- Symbol object for fallback name lookupframe.source()- Returns(filename, line, column)tupleframe.is_inline- Boolean for inline frame detectionChanges
Updated
_framestr()signature: Added requiredframe_index: intparameter.Rewrote frame formatting logic: Uses API properties directly with error handling via try/except for
LookupErrorUpdated call sites:
for frame in stack_trace:tofor frame_index, frame in enumerate(stack_trace):_framestr(frame, False)to_framestr(frame, False, frame_index)_framestr(frame, True)to_framestr(frame, True, self.frame_id)Testing
Tested with crash dump from kernel 6.14.0-27-dx2025082915-8ba235c2d-generic:
All features working correctly:
frame.pcframe.function_nameframe.source()showingfile:line:colframe.is_inlineBenefits
Ensuring no regressions
Verified Command Compatibility
All related stack inspection commands continue to work correctly with the updated
_framestr()implementation:tracecommand - Displays full stack trace with frame indices, addresses, functions, and source locations:framecommand - Shows detailed frame information with function arguments (uses_framestr()withargs=True):localscommand - Displays local variables in the current frame:registerscommand - Shows CPU register values at the current frame:These commands demonstrate that the refactored
_framestr()function maintains full backward compatibility while providing more robust frame formatting through the drgn StackFrame API.