123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564 |
- import type {MouseEvent} from 'react';
- import {Fragment, useContext, useState} from 'react';
- import styled from '@emotion/styled';
- import scrollToElement from 'scroll-to-element';
- import {Button} from 'sentry/components/button';
- import ErrorBoundary from 'sentry/components/errorBoundary';
- import {OpenInContextLine} from 'sentry/components/events/interfaces/frame/openInContextLine';
- import {StacktraceLink} from 'sentry/components/events/interfaces/frame/stacktraceLink';
- import {
- getLeadHint,
- hasAssembly,
- hasContextRegisters,
- hasContextSource,
- hasContextVars,
- isExpandable,
- trimPackage,
- } from 'sentry/components/events/interfaces/frame/utils';
- import {formatAddress, parseAddress} from 'sentry/components/events/interfaces/utils';
- import {AnnotatedText} from 'sentry/components/events/meta/annotatedText';
- import {TraceEventDataSectionContext} from 'sentry/components/events/traceEventDataSection';
- import StrictClick from 'sentry/components/strictClick';
- import Tag from 'sentry/components/tag';
- import {Tooltip} from 'sentry/components/tooltip';
- import {SLOW_TOOLTIP_DELAY} from 'sentry/constants';
- import {IconChevron} from 'sentry/icons/iconChevron';
- import {IconFileBroken} from 'sentry/icons/iconFileBroken';
- import {IconRefresh} from 'sentry/icons/iconRefresh';
- import {IconWarning} from 'sentry/icons/iconWarning';
- import {t, tn} from 'sentry/locale';
- import DebugMetaStore from 'sentry/stores/debugMetaStore';
- import {space} from 'sentry/styles/space';
- import type {
- Frame,
- PlatformKey,
- SentryAppComponent,
- SentryAppSchemaStacktraceLink,
- } from 'sentry/types';
- import type {Event} from 'sentry/types/event';
- import {defined} from 'sentry/utils';
- import withSentryAppComponents from 'sentry/utils/withSentryAppComponents';
- import type DebugImage from './debugMeta/debugImage';
- import {combineStatus} from './debugMeta/utils';
- import Context from './frame/context';
- import {SymbolicatorStatus} from './types';
- type Props = {
- components: SentryAppComponent<SentryAppSchemaStacktraceLink>[];
- event: Event;
- frame: Frame;
- isUsedForGrouping: boolean;
- platform: PlatformKey;
- registers: Record<string, string>;
- emptySourceNotation?: boolean;
- frameMeta?: Record<any, any>;
- hiddenFrameCount?: number;
- image?: React.ComponentProps<typeof DebugImage>['image'];
- includeSystemFrames?: boolean;
- isExpanded?: boolean;
- isHoverPreviewed?: boolean;
- isOnlyFrame?: boolean;
- isShowFramesToggleExpanded?: boolean;
- /**
- * Frames that are hidden under the most recent non-InApp frame
- */
- isSubFrame?: boolean;
- maxLengthOfRelativeAddress?: number;
- nextFrame?: Frame;
- onShowFramesToggle?: (event: React.MouseEvent<HTMLElement>) => void;
- prevFrame?: Frame;
- registersMeta?: Record<any, any>;
- showStackedFrames?: boolean;
- };
- function NativeFrame({
- frame,
- nextFrame,
- prevFrame,
- includeSystemFrames,
- isUsedForGrouping,
- maxLengthOfRelativeAddress,
- image,
- registers,
- isOnlyFrame,
- event,
- components,
- hiddenFrameCount,
- isShowFramesToggleExpanded,
- isSubFrame,
- onShowFramesToggle,
- isExpanded,
- platform,
- registersMeta,
- frameMeta,
- emptySourceNotation = false,
- /**
- * Is the stack trace being previewed in a hovercard?
- */
- isHoverPreviewed = false,
- }: Props) {
- const traceEventDataSectionContext = useContext(TraceEventDataSectionContext);
- const absolute = traceEventDataSectionContext?.display.includes('absolute-addresses');
- const fullStackTrace = traceEventDataSectionContext?.fullStackTrace;
- const fullFunctionName = traceEventDataSectionContext?.display.includes(
- 'verbose-function-names'
- );
- const absoluteFilePaths =
- traceEventDataSectionContext?.display.includes('absolute-file-paths');
- const tooltipDelay = isHoverPreviewed ? SLOW_TOOLTIP_DELAY : undefined;
- const foundByStackScanning = frame.trust === 'scan' || frame.trust === 'cfi-scan';
- const startingAddress = image ? image.image_addr : null;
- const packageClickable =
- !!frame.symbolicatorStatus &&
- frame.symbolicatorStatus !== SymbolicatorStatus.UNKNOWN_IMAGE &&
- !isHoverPreviewed;
- const leadsToApp = !frame.inApp && (nextFrame?.inApp || !nextFrame);
- const expandable =
- !leadsToApp || includeSystemFrames
- ? isExpandable({
- frame,
- registers,
- platform,
- emptySourceNotation,
- isOnlyFrame,
- })
- : false;
- const inlineFrame =
- prevFrame &&
- platform === (prevFrame.platform || platform) &&
- frame.instructionAddr === prevFrame.instructionAddr;
- const functionNameHiddenDetails =
- defined(frame.rawFunction) &&
- defined(frame.function) &&
- frame.function !== frame.rawFunction;
- const [expanded, setExpanded] = useState(expandable ? isExpanded ?? false : false);
- const [isHovering, setHovering] = useState(false);
- const contextLine = (frame?.context || []).find(l => l[0] === frame.lineNo);
- const hasStacktraceLink = frame.inApp && !!frame.filename && (isHovering || expanded);
- const showSentryAppStacktraceLinkInFrame = hasStacktraceLink && components.length > 0;
- const handleMouseEnter = () => setHovering(true);
- const handleMouseLeave = () => setHovering(false);
- function getRelativeAddress() {
- if (!startingAddress) {
- return '';
- }
- const relativeAddress = formatAddress(
- parseAddress(frame.instructionAddr) - parseAddress(startingAddress),
- maxLengthOfRelativeAddress
- );
- return `+${relativeAddress}`;
- }
- function getAddressTooltip() {
- if (inlineFrame && foundByStackScanning) {
- return t('Inline frame, found by stack scanning');
- }
- if (inlineFrame) {
- return t('Inline frame');
- }
- if (foundByStackScanning) {
- return t('Found by stack scanning');
- }
- return undefined;
- }
- function getFunctionName() {
- if (functionNameHiddenDetails && fullFunctionName && frame.rawFunction) {
- return {
- value: frame.rawFunction,
- meta: frameMeta?.rawFunction?.[''],
- };
- }
- if (frame.function) {
- return {
- value: frame.function,
- meta: frameMeta?.function?.[''],
- };
- }
- return undefined;
- }
- // this is the status of image that belongs to this frame
- function getStatus() {
- // If a matching debug image doesn't exist, fall back to symbolicator_status
- if (!image) {
- switch (frame.symbolicatorStatus) {
- case SymbolicatorStatus.SYMBOLICATED:
- return 'success';
- case SymbolicatorStatus.MISSING:
- case SymbolicatorStatus.MALFORMED:
- return 'error';
- case SymbolicatorStatus.MISSING_SYMBOL:
- case SymbolicatorStatus.UNKNOWN_IMAGE:
- default:
- return undefined;
- }
- }
- const combinedStatus = combineStatus(image.debug_status, image.unwind_status);
- switch (combinedStatus) {
- case 'unused':
- return undefined;
- case 'found':
- return 'success';
- default:
- return 'error';
- }
- }
- function handleGoToImagesLoaded(e: MouseEvent) {
- e.stopPropagation(); // to prevent collapsing if collapsible
- if (frame.instructionAddr) {
- const searchTerm =
- !(!frame.addrMode || frame.addrMode === 'abs') && image
- ? `${image.debug_id}!${frame.instructionAddr}`
- : frame.instructionAddr;
- DebugMetaStore.updateFilter(searchTerm);
- }
- scrollToElement('#images-loaded');
- }
- function handleToggleContext(e: MouseEvent) {
- if (!expandable) {
- return;
- }
- e.preventDefault();
- setExpanded(!expanded);
- }
- const relativeAddress = getRelativeAddress();
- const addressTooltip = getAddressTooltip();
- const functionName = getFunctionName();
- const status = getStatus();
- return (
- <StackTraceFrame data-test-id="stack-trace-frame">
- <StrictClick onClick={handleToggleContext}>
- <RowHeader
- expandable={expandable}
- expanded={expanded}
- isInAppFrame={frame.inApp}
- isSubFrame={!!isSubFrame}
- onMouseEnter={handleMouseEnter}
- onMouseLeave={handleMouseLeave}
- >
- <SymbolicatorIcon>
- {status === 'error' ? (
- <Tooltip
- title={t(
- 'This frame has missing debug files and could not be symbolicated'
- )}
- >
- <IconFileBroken
- size="sm"
- color="errorText"
- data-test-id="symbolication-error-icon"
- />
- </Tooltip>
- ) : status === undefined ? (
- <Tooltip
- title={t(
- 'This frame has an unknown problem and could not be symbolicated'
- )}
- >
- <IconWarning
- size="sm"
- color="warningText"
- data-test-id="symbolication-warning-icon"
- />
- </Tooltip>
- ) : null}
- </SymbolicatorIcon>
- <div>
- {!fullStackTrace && !expanded && leadsToApp && (
- <Fragment>
- <PackageNote>
- {getLeadHint({event, hasNextFrame: defined(nextFrame)})}
- </PackageNote>
- </Fragment>
- )}
- <Tooltip
- title={frame.package ?? t('Go to images loaded')}
- position="bottom"
- containerDisplayMode="inline-flex"
- delay={tooltipDelay}
- >
- <Package>
- {frame.package ? trimPackage(frame.package) : `<${t('unknown')}>`}
- </Package>
- </Tooltip>
- </div>
- <GenericCellWrapper>
- <AddressCell onClick={packageClickable ? handleGoToImagesLoaded : undefined}>
- <Tooltip
- title={addressTooltip}
- disabled={!(foundByStackScanning || inlineFrame)}
- delay={tooltipDelay}
- >
- {!relativeAddress || absolute ? frame.instructionAddr : relativeAddress}
- </Tooltip>
- </AddressCell>
- </GenericCellWrapper>
- <FunctionNameCell>
- {functionName ? (
- <AnnotatedText value={functionName.value} meta={functionName.meta} />
- ) : (
- `<${t('unknown')}>`
- )}{' '}
- {frame.filename && (
- <Tooltip
- title={frame.absPath}
- disabled={!(defined(frame.absPath) && frame.absPath !== frame.filename)}
- delay={tooltipDelay}
- isHoverable
- >
- <FileName>
- {'('}
- {absoluteFilePaths ? frame.absPath : frame.filename}
- {frame.lineNo && `:${frame.lineNo}`}
- {')'}
- </FileName>
- </Tooltip>
- )}
- </FunctionNameCell>
- <GroupingCell>
- {isUsedForGrouping && (
- <Tooltip title={t('This frame is repeated in every event of this issue')}>
- <IconRefresh size="sm" color="textColor" />
- </Tooltip>
- )}
- </GroupingCell>
- {hiddenFrameCount ? (
- <ShowHideButton
- analyticsEventName="Stacktrace Frames: toggled"
- analyticsEventKey="stacktrace_frames.toggled"
- analyticsParams={{
- frame_count: hiddenFrameCount,
- is_frame_expanded: isShowFramesToggleExpanded,
- }}
- size="xs"
- borderless
- onClick={e => {
- onShowFramesToggle?.(e);
- }}
- >
- {isShowFramesToggleExpanded
- ? tn('Hide %s more frame', 'Hide %s more frames', hiddenFrameCount)
- : tn('Show %s more frame', 'Show %s more frames', hiddenFrameCount)}
- </ShowHideButton>
- ) : null}
- <GenericCellWrapper>
- {hasStacktraceLink && (
- <ErrorBoundary>
- <StacktraceLink
- frame={frame}
- line={contextLine ? contextLine[1] : ''}
- event={event}
- />
- </ErrorBoundary>
- )}
- {showSentryAppStacktraceLinkInFrame && (
- <ErrorBoundary mini>
- <OpenInContextLine
- lineNo={frame.lineNo}
- filename={frame.filename || ''}
- components={components}
- />
- </ErrorBoundary>
- )}
- <TypeCell>
- {frame.inApp ? <Tag type="info">{t('In App')}</Tag> : null}
- </TypeCell>
- </GenericCellWrapper>
- <ExpandCell>
- {expandable && (
- <ToggleButton
- size="zero"
- aria-label={t('Toggle Context')}
- tooltipProps={isHoverPreviewed ? {delay: SLOW_TOOLTIP_DELAY} : undefined}
- icon={
- <IconChevron legacySize="8px" direction={expanded ? 'up' : 'down'} />
- }
- />
- )}
- </ExpandCell>
- </RowHeader>
- </StrictClick>
- {expanded && (
- <Registers
- frame={frame}
- event={event}
- registers={registers}
- components={components}
- hasContextSource={hasContextSource(frame)}
- hasContextVars={hasContextVars(frame)}
- hasContextRegisters={hasContextRegisters(registers)}
- emptySourceNotation={emptySourceNotation}
- hasAssembly={hasAssembly(frame, platform)}
- isExpanded={expanded}
- registersMeta={registersMeta}
- frameMeta={frameMeta}
- />
- )}
- </StackTraceFrame>
- );
- }
- export default withSentryAppComponents(NativeFrame, {componentType: 'stacktrace-link'});
- const GenericCellWrapper = styled('div')`
- display: flex;
- `;
- const AddressCell = styled('div')`
- font-family: ${p => p.theme.text.familyMono};
- ${p => p.onClick && `cursor: pointer`};
- ${p => p.onClick && `color:` + p.theme.linkColor};
- `;
- const FunctionNameCell = styled('div')`
- word-break: break-all;
- @media (max-width: ${p => p.theme.breakpoints.small}) {
- grid-column: 2/6;
- }
- `;
- const GroupingCell = styled('div')`
- @media (max-width: ${p => p.theme.breakpoints.small}) {
- grid-row: 2/3;
- }
- `;
- const TypeCell = styled('div')`
- @media (max-width: ${p => p.theme.breakpoints.small}) {
- grid-column: 5/6;
- grid-row: 1/2;
- }
- `;
- const ExpandCell = styled('div')`
- @media (max-width: ${p => p.theme.breakpoints.small}) {
- grid-column: 6/7;
- grid-row: 1/2;
- }
- `;
- const ToggleButton = styled(Button)`
- width: 16px;
- height: 16px;
- `;
- const Registers = styled(Context)`
- border-bottom: 1px solid ${p => p.theme.border};
- padding: 0;
- margin: 0;
- `;
- const PackageNote = styled('div')`
- color: ${p => p.theme.subText};
- font-size: ${p => p.theme.fontSizeExtraSmall};
- `;
- const Package = styled('span')`
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- width: 100%;
- padding-right: 2px; /* Needed to prevent text cropping with italic font */
- `;
- const FileName = styled('span')`
- color: ${p => p.theme.subText};
- border-bottom: 1px dashed ${p => p.theme.border};
- `;
- const RowHeader = styled('span')<{
- expandable: boolean;
- expanded: boolean;
- isInAppFrame: boolean;
- isSubFrame: boolean;
- }>`
- display: grid;
- grid-template-columns: repeat(2, auto) 1fr repeat(2, auto) ${space(2)};
- grid-template-rows: repeat(2, auto);
- align-items: center;
- align-content: center;
- column-gap: ${space(1)};
- background-color: ${p =>
- !p.isInAppFrame && p.isSubFrame
- ? `${p.theme.surface100}`
- : `${p.theme.bodyBackground}`};
- font-size: ${p => p.theme.fontSizeSmall};
- padding: ${space(1)};
- color: ${p => (!p.isInAppFrame ? p.theme.subText : '')};
- font-style: ${p => (!p.isInAppFrame ? 'italic' : '')};
- ${p => p.expandable && `cursor: pointer;`};
- @media (min-width: ${p => p.theme.breakpoints.small}) {
- grid-template-columns: auto 150px 120px 4fr repeat(2, auto) ${space(2)};
- padding: ${space(0.5)} ${space(1.5)};
- min-height: 32px;
- }
- `;
- const StackTraceFrame = styled('li')`
- :not(:last-child) {
- ${RowHeader} {
- border-bottom: 1px solid ${p => p.theme.border};
- }
- }
- &:last-child {
- ${RowHeader} {
- border-bottom-right-radius: 5px;
- border-bottom-left-radius: 5px;
- }
- }
- &:first-child {
- ${RowHeader} {
- border-top-right-radius: 5px;
- }
- }
- `;
- const SymbolicatorIcon = styled('div')`
- width: ${p => p.theme.iconSizes.sm};
- `;
- const ShowHideButton = styled(Button)`
- color: ${p => p.theme.subText};
- font-style: italic;
- font-weight: normal;
- padding: ${space(0.25)} ${space(0.5)};
- &:hover {
- color: ${p => p.theme.subText};
- }
- `;
|