@@ -1750,112 +1750,124 @@ Status CommandInterpreter::PreprocessCommand(std::string &command) {
17501750
17511751 std::string expr_str (command, expr_content_start,
17521752 end_backtick - expr_content_start);
1753+ error = PreprocessToken (expr_str);
1754+ // We always stop at the first error:
1755+ if (error.Fail ())
1756+ break ;
17531757
1754- ExecutionContext exe_ctx (GetExecutionContext ());
1758+ command.erase (start_backtick, end_backtick - start_backtick + 1 );
1759+ command.insert (start_backtick, std::string (expr_str));
1760+ pos = start_backtick + expr_str.size ();
1761+ }
1762+ return error;
1763+ }
17551764
1756- // Get a dummy target to allow for calculator mode while processing
1757- // backticks. This also helps break the infinite loop caused when target is
1758- // null.
1759- Target *exe_target = exe_ctx.GetTargetPtr ();
1760- Target &target = exe_target ? *exe_target : m_debugger.GetDummyTarget ();
1761-
1762- ValueObjectSP expr_result_valobj_sp;
1763-
1764- EvaluateExpressionOptions options;
1765- options.SetCoerceToId (false );
1766- options.SetUnwindOnError (true );
1767- options.SetIgnoreBreakpoints (true );
1768- options.SetKeepInMemory (false );
1769- options.SetTryAllThreads (true );
1770- options.SetTimeout (std::nullopt );
1771-
1772- ExpressionResults expr_result =
1773- target.EvaluateExpression (expr_str.c_str (), exe_ctx.GetFramePtr (),
1774- expr_result_valobj_sp, options);
1775-
1776- if (expr_result == eExpressionCompleted) {
1777- Scalar scalar;
1778- if (expr_result_valobj_sp)
1779- expr_result_valobj_sp =
1780- expr_result_valobj_sp->GetQualifiedRepresentationIfAvailable (
1781- expr_result_valobj_sp->GetDynamicValueType (), true );
1782- if (expr_result_valobj_sp->ResolveValue (scalar)) {
1783- command.erase (start_backtick, end_backtick - start_backtick + 1 );
1784- StreamString value_strm;
1785- const bool show_type = false ;
1786- scalar.GetValue (&value_strm, show_type);
1787- size_t value_string_size = value_strm.GetSize ();
1788- if (value_string_size) {
1789- command.insert (start_backtick, std::string (value_strm.GetString ()));
1790- pos = start_backtick + value_string_size;
1791- continue ;
1792- } else {
1793- error.SetErrorStringWithFormat (" expression value didn't result "
1794- " in a scalar value for the "
1795- " expression '%s'" ,
1796- expr_str.c_str ());
1797- break ;
1798- }
1799- } else {
1800- error.SetErrorStringWithFormat (" expression value didn't result "
1801- " in a scalar value for the "
1802- " expression '%s'" ,
1803- expr_str.c_str ());
1804- break ;
1805- }
1765+ Status
1766+ CommandInterpreter::PreprocessToken (std::string &expr_str) {
1767+ Status error;
1768+ ExecutionContext exe_ctx (GetExecutionContext ());
18061769
1807- continue ;
1808- }
1770+ // Get a dummy target to allow for calculator mode while processing
1771+ // backticks. This also helps break the infinite loop caused when target is
1772+ // null.
1773+ Target *exe_target = exe_ctx.GetTargetPtr ();
1774+ Target &target = exe_target ? *exe_target : m_debugger.GetDummyTarget ();
18091775
1810- if (expr_result_valobj_sp)
1811- error = expr_result_valobj_sp->GetError ();
1776+ ValueObjectSP expr_result_valobj_sp;
18121777
1813- if (error.Success ()) {
1814- switch (expr_result) {
1815- case eExpressionSetupError:
1816- error.SetErrorStringWithFormat (
1817- " expression setup error for the expression '%s'" , expr_str.c_str ());
1818- break ;
1819- case eExpressionParseError:
1820- error.SetErrorStringWithFormat (
1821- " expression parse error for the expression '%s'" , expr_str.c_str ());
1822- break ;
1823- case eExpressionResultUnavailable:
1824- error.SetErrorStringWithFormat (
1825- " expression error fetching result for the expression '%s'" ,
1826- expr_str.c_str ());
1827- break ;
1828- case eExpressionCompleted:
1829- break ;
1830- case eExpressionDiscarded:
1831- error.SetErrorStringWithFormat (
1832- " expression discarded for the expression '%s'" , expr_str.c_str ());
1833- break ;
1834- case eExpressionInterrupted:
1835- error.SetErrorStringWithFormat (
1836- " expression interrupted for the expression '%s'" , expr_str.c_str ());
1837- break ;
1838- case eExpressionHitBreakpoint:
1839- error.SetErrorStringWithFormat (
1840- " expression hit breakpoint for the expression '%s'" ,
1841- expr_str.c_str ());
1842- break ;
1843- case eExpressionTimedOut:
1844- error.SetErrorStringWithFormat (
1845- " expression timed out for the expression '%s'" , expr_str.c_str ());
1846- break ;
1847- case eExpressionStoppedForDebug:
1848- error.SetErrorStringWithFormat (" expression stop at entry point "
1849- " for debugging for the "
1778+ EvaluateExpressionOptions options;
1779+ options.SetCoerceToId (false );
1780+ options.SetUnwindOnError (true );
1781+ options.SetIgnoreBreakpoints (true );
1782+ options.SetKeepInMemory (false );
1783+ options.SetTryAllThreads (true );
1784+ options.SetTimeout (std::nullopt );
1785+
1786+ ExpressionResults expr_result =
1787+ target.EvaluateExpression (expr_str.c_str (), exe_ctx.GetFramePtr (),
1788+ expr_result_valobj_sp, options);
1789+
1790+ if (expr_result == eExpressionCompleted) {
1791+ Scalar scalar;
1792+ if (expr_result_valobj_sp)
1793+ expr_result_valobj_sp =
1794+ expr_result_valobj_sp->GetQualifiedRepresentationIfAvailable (
1795+ expr_result_valobj_sp->GetDynamicValueType (), true );
1796+ if (expr_result_valobj_sp->ResolveValue (scalar)) {
1797+
1798+ StreamString value_strm;
1799+ const bool show_type = false ;
1800+ scalar.GetValue (&value_strm, show_type);
1801+ size_t value_string_size = value_strm.GetSize ();
1802+ if (value_string_size) {
1803+ expr_str = value_strm.GetData ();
1804+ } else {
1805+ error.SetErrorStringWithFormat (" expression value didn't result "
1806+ " in a scalar value for the "
18501807 " expression '%s'" ,
18511808 expr_str.c_str ());
1852- break ;
1853- case eExpressionThreadVanished:
1854- error.SetErrorStringWithFormat (
1855- " expression thread vanished for the expression '%s'" ,
1856- expr_str.c_str ());
1857- break ;
18581809 }
1810+ } else {
1811+ error.SetErrorStringWithFormat (" expression value didn't result "
1812+ " in a scalar value for the "
1813+ " expression '%s'" ,
1814+ expr_str.c_str ());
1815+ }
1816+ return error;
1817+ }
1818+
1819+ // If we have an error from the expression evaluation it will be in the
1820+ // ValueObject error, which won't be success and we will just report it.
1821+ // But if for some reason we didn't get a value object at all, then we will
1822+ // make up some helpful errors from the expression result.
1823+ if (expr_result_valobj_sp)
1824+ error = expr_result_valobj_sp->GetError ();
1825+
1826+ if (error.Success ()) {
1827+ switch (expr_result) {
1828+ case eExpressionSetupError:
1829+ error.SetErrorStringWithFormat (
1830+ " expression setup error for the expression '%s'" , expr_str.c_str ());
1831+ break ;
1832+ case eExpressionParseError:
1833+ error.SetErrorStringWithFormat (
1834+ " expression parse error for the expression '%s'" , expr_str.c_str ());
1835+ break ;
1836+ case eExpressionResultUnavailable:
1837+ error.SetErrorStringWithFormat (
1838+ " expression error fetching result for the expression '%s'" ,
1839+ expr_str.c_str ());
1840+ break ;
1841+ case eExpressionCompleted:
1842+ break ;
1843+ case eExpressionDiscarded:
1844+ error.SetErrorStringWithFormat (
1845+ " expression discarded for the expression '%s'" , expr_str.c_str ());
1846+ break ;
1847+ case eExpressionInterrupted:
1848+ error.SetErrorStringWithFormat (
1849+ " expression interrupted for the expression '%s'" , expr_str.c_str ());
1850+ break ;
1851+ case eExpressionHitBreakpoint:
1852+ error.SetErrorStringWithFormat (
1853+ " expression hit breakpoint for the expression '%s'" ,
1854+ expr_str.c_str ());
1855+ break ;
1856+ case eExpressionTimedOut:
1857+ error.SetErrorStringWithFormat (
1858+ " expression timed out for the expression '%s'" , expr_str.c_str ());
1859+ break ;
1860+ case eExpressionStoppedForDebug:
1861+ error.SetErrorStringWithFormat (" expression stop at entry point "
1862+ " for debugging for the "
1863+ " expression '%s'" ,
1864+ expr_str.c_str ());
1865+ break ;
1866+ case eExpressionThreadVanished:
1867+ error.SetErrorStringWithFormat (
1868+ " expression thread vanished for the expression '%s'" ,
1869+ expr_str.c_str ());
1870+ break ;
18591871 }
18601872 }
18611873 return error;
0 commit comments