123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491 |
- import {Fragment, MouseEvent, useContext, useState} from 'react';
- import {css} from '@emotion/react';
- import styled from '@emotion/styled';
- import scrollToElement from 'scroll-to-element';
- import Button from 'sentry/components/button';
- import {
- hasAssembly,
- hasContextRegisters,
- hasContextSource,
- hasContextVars,
- isDotnet,
- 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 Tooltip from 'sentry/components/tooltip';
- import {SLOW_TOOLTIP_DELAY} from 'sentry/constants';
- import {IconChevron} from 'sentry/icons/iconChevron';
- import {IconInfo} from 'sentry/icons/iconInfo';
- import {IconQuestion} from 'sentry/icons/iconQuestion';
- import {IconWarning} from 'sentry/icons/iconWarning';
- import {t} from 'sentry/locale';
- import DebugMetaStore from 'sentry/stores/debugMetaStore';
- import space from 'sentry/styles/space';
- import {Frame, PlatformType, SentryAppComponent} from 'sentry/types';
- import {Event} from 'sentry/types/event';
- import {defined} from 'sentry/utils';
- import {ColorOrAlias} from 'sentry/utils/theme';
- import withSentryAppComponents from 'sentry/utils/withSentryAppComponents';
- import DebugImage from './debugMeta/debugImage';
- import {combineStatus} from './debugMeta/utils';
- import Context from './frame/context';
- import {SymbolicatorStatus} from './types';
- type Props = {
- components: Array<SentryAppComponent>;
- event: Event;
- frame: Frame;
- isUsedForGrouping: boolean;
- platform: PlatformType;
- registers: Record<string, string>;
- emptySourceNotation?: boolean;
- frameMeta?: Record<any, any>;
- image?: React.ComponentProps<typeof DebugImage>['image'];
- includeSystemFrames?: boolean;
- isExpanded?: boolean;
- isHoverPreviewed?: boolean;
- isOnlyFrame?: boolean;
- maxLengthOfRelativeAddress?: number;
- nextFrame?: Frame;
- prevFrame?: Frame;
- registersMeta?: Record<any, any>;
- };
- function NativeFrame({
- frame,
- nextFrame,
- prevFrame,
- includeSystemFrames,
- isUsedForGrouping,
- maxLengthOfRelativeAddress,
- image,
- registers,
- isOnlyFrame,
- event,
- components,
- 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 && 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);
- 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;
- }
- function getStatus() {
- // this is the status of image that belongs to this frame
- if (!image) {
- 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 (
- <GridRow
- inApp={frame.inApp}
- expandable={expandable}
- expanded={expanded}
- className="frame"
- data-test-id="stack-trace-frame"
- >
- <StrictClick onClick={handleToggleContext}>
- <StrictClickContent>
- <StatusCell>
- {(status === 'error' || status === undefined) &&
- (packageClickable ? (
- <PackageStatusButton
- onClick={handleGoToImagesLoaded}
- title={t('Go to images loaded')}
- aria-label={t('Go to images loaded')}
- icon={
- status === 'error' ? (
- <IconQuestion size="sm" color="errorText" />
- ) : (
- <IconWarning size="sm" color="errorText" />
- )
- }
- size="zero"
- borderless
- />
- ) : status === 'error' ? (
- <IconQuestion size="sm" color="errorText" />
- ) : (
- <IconWarning size="sm" color="errorText" />
- ))}
- </StatusCell>
- <PackageCell>
- {!fullStackTrace && !expanded && leadsToApp && (
- <Fragment>
- {!nextFrame ? t('Crashed in non-app') : t('Called from')}
- {':'}
- </Fragment>
- )}
- <span>
- <Tooltip
- title={frame.package ?? t('Go to images loaded')}
- delay={tooltipDelay}
- disabled={frame.package ? false : !packageClickable}
- containerDisplayMode="inline-flex"
- >
- <Package
- color={
- status === undefined || status === 'error'
- ? 'errorText'
- : packageClickable
- ? 'linkColor'
- : undefined
- }
- onClick={packageClickable ? handleGoToImagesLoaded : undefined}
- >
- {frame.package ? trimPackage(frame.package) : `<${t('unknown')}>`}
- </Package>
- </Tooltip>
- </span>
- </PackageCell>
- <AddressCell>
- <Tooltip
- title={addressTooltip}
- disabled={!(foundByStackScanning || inlineFrame)}
- delay={tooltipDelay}
- >
- {!relativeAddress || absolute ? frame.instructionAddr : relativeAddress}
- </Tooltip>
- </AddressCell>
- <GroupingCell>
- {isUsedForGrouping && (
- <Tooltip
- title={t('This frame appears in all other events related to this issue')}
- containerDisplayMode="inline-flex"
- >
- <IconInfo size="sm" color="subText" />
- </Tooltip>
- )}
- </GroupingCell>
- <FunctionNameCell>
- <FunctionName>
- {functionName ? (
- <AnnotatedText value={functionName.value} meta={functionName.meta} />
- ) : (
- `<${t('unknown')}>`
- )}
- </FunctionName>
- {frame.filename && (
- <Tooltip
- title={frame.absPath}
- disabled={!(defined(frame.absPath) && frame.absPath !== frame.filename)}
- delay={tooltipDelay}
- containerDisplayMode="inline-flex"
- >
- <FileName>
- {'('}
- {absoluteFilePaths ? frame.absPath : frame.filename}
- {frame.lineNo && `:${frame.lineNo}`}
- {')'}
- </FileName>
- </Tooltip>
- )}
- </FunctionNameCell>
- <ExpandCell>
- {expandable && (
- <ToggleButton
- size="zero"
- css={isDotnet(platform) && {display: 'block !important'}} // remove important once we get rid of css files
- title={t('Toggle Context')}
- aria-label={t('Toggle Context')}
- tooltipProps={isHoverPreviewed ? {delay: SLOW_TOOLTIP_DELAY} : undefined}
- icon={<IconChevron size="8px" direction={expanded ? 'up' : 'down'} />}
- />
- )}
- </ExpandCell>
- </StrictClickContent>
- </StrictClick>
- <RegistersCell>
- {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)}
- expandable={expandable}
- isExpanded={expanded}
- registersMeta={registersMeta}
- frameMeta={frameMeta}
- />
- )}
- </RegistersCell>
- </GridRow>
- );
- }
- export default withSentryAppComponents(NativeFrame, {componentType: 'stacktrace-link'});
- const Cell = styled('div')`
- padding: ${space(0.5)};
- display: flex;
- flex-wrap: wrap;
- word-break: break-all;
- align-items: flex-start;
- `;
- const StatusCell = styled(Cell)`
- @media (max-width: ${p => p.theme.breakpoints.small}) {
- grid-column: 1/1;
- grid-row: 1/1;
- }
- `;
- const PackageCell = styled(Cell)`
- color: ${p => p.theme.subText};
- @media (max-width: ${p => p.theme.breakpoints.small}) {
- grid-column: 2/2;
- grid-row: 1/1;
- display: grid;
- grid-template-columns: 1fr;
- grid-template-rows: repeat(2, auto);
- }
- `;
- const AddressCell = styled(Cell)`
- font-family: ${p => p.theme.text.familyMono};
- @media (max-width: ${p => p.theme.breakpoints.small}) {
- grid-column: 3/3;
- grid-row: 1/1;
- }
- `;
- const GroupingCell = styled(Cell)`
- @media (max-width: ${p => p.theme.breakpoints.small}) {
- grid-column: 1/1;
- grid-row: 2/2;
- }
- `;
- const FunctionNameCell = styled(Cell)`
- color: ${p => p.theme.textColor};
- @media (max-width: ${p => p.theme.breakpoints.small}) {
- grid-column: 2/-1;
- grid-row: 2/2;
- }
- `;
- const ExpandCell = styled(Cell)``;
- const RegistersCell = styled('div')`
- grid-column: 1/-1;
- margin-left: -${space(0.5)};
- margin-right: -${space(0.5)};
- margin-bottom: -${space(0.5)};
- cursor: default;
- `;
- const Registers = styled(Context)`
- padding: 0;
- margin: 0;
- `;
- const ToggleButton = styled(Button)`
- width: 16px;
- height: 16px;
- `;
- const Package = styled('span')<{color?: ColorOrAlias}>`
- border-bottom: 1px dashed ${p => p.theme.border};
- ${p => p.color && `color: ${p.theme[p.color]}`};
- ${p => p.onClick && `cursor: pointer;`}
- `;
- const FunctionName = styled('div')`
- color: ${p => p.theme.headingColor};
- margin-right: ${space(1)};
- `;
- const FileName = styled('span')`
- color: ${p => p.theme.subText};
- border-bottom: 1px dashed ${p => p.theme.border};
- `;
- const PackageStatusButton = styled(Button)`
- padding: 0;
- border: none;
- `;
- const GridRow = styled('li')<{expandable: boolean; expanded: boolean; inApp: boolean}>`
- ${p => p.expandable && `cursor: pointer;`};
- ${p => p.inApp && `background: ${p.theme.bodyBackground};`};
- ${p =>
- !p.inApp &&
- css`
- color: ${p.theme.subText};
- ${FunctionName} {
- color: ${p.theme.subText};
- }
- ${FunctionNameCell} {
- color: ${p.theme.subText};
- }
- `};
- display: grid;
- align-items: flex-start;
- padding: ${space(0.5)};
- :not(:last-child) {
- border-bottom: 1px solid ${p => p.theme.border};
- }
- && {
- border-top: 0;
- }
- grid-template-columns: 24px 132px 138px 24px 1fr 24px;
- grid-template-rows: 1fr;
- @media (max-width: ${p => p.theme.breakpoints.small}) {
- grid-template-columns: 24px auto minmax(138px, 1fr) 24px;
- grid-template-rows: repeat(2, auto);
- }
- `;
- const StrictClickContent = styled('div')`
- display: contents;
- `;
|