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