Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/reducers/url-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,12 +606,21 @@ const assemblyView: Reducer<AssemblyViewState> = (
const { nativeSymbols, currentNativeSymbol, shouldOpenAssemblyView } =
action;
const shouldScroll = action.scrollToInstructionAddress !== undefined;

// Clamp currentNativeSymbol to null if it is out of bounds, so that
// "currentNativeSymbol is always in-bounds or null" holds.
const clampedNativeSymbol =
currentNativeSymbol !== null &&
currentNativeSymbol < nativeSymbols.length
? currentNativeSymbol
: null;

return {
scrollGeneration: shouldScroll
? state.scrollGeneration + 1
: state.scrollGeneration,
nativeSymbols,
currentNativeSymbol,
currentNativeSymbol: clampedNativeSymbol,
isOpen: state.isOpen || shouldOpenAssemblyView,
scrollToInstructionAddress: action.scrollToInstructionAddress,
highlightedInstruction: action.highlightedInstructionAddress,
Expand Down
23 changes: 23 additions & 0 deletions src/test/store/bottom-box.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,29 @@ describe('bottom box', function () {
).toBeOneOf([0x40, 0x45]);
});

it('returns null for getAssemblyViewNativeSymbol when nativeSymbols is empty but initialNativeSymbol is 0', function () {
// initialNativeSymbol = 0, even when nativeSymbols is empty
// (e.g., when the frame has no native symbol).
// The selector must return null (not undefined)
// to avoid a crash when downstream code accesses .libIndex on it.
const { dispatch, getState } = setup();

dispatch(
updateBottomBoxContentsAndMaybeOpen('calltree', {
libIndex: null,
sourceIndex: null,
nativeSymbols: [],
initialNativeSymbol: 0,
highlightedLineNumber: null,
highlightedInstructionAddress: null,
})
);

expect(
UrlStateSelectors.getAssemblyViewNativeSymbol(getState())
).toBeNull();
});

// Further ideas for tests:
//
// - A test with multiple threads: Open the assembly view for a symbol, switch
Expand Down