Remove a use of print_expression
authorTom Tromey <tom@tromey.com>
Sat, 9 Jan 2021 17:06:25 +0000 (10:06 -0700)
committerTom Tromey <tom@tromey.com>
Sat, 9 Jan 2021 17:06:25 +0000 (10:06 -0700)
The tracepoint code uses print_expression to reconstruct an expression
string.  However, the original expression is already available -- it
was just parsed a bit earlier in the same function.  This patch
changes this code to simply save the already-parsed expression, rather
than attempt to reconstruct it.

gdb/ChangeLog
2021-01-09  Tom Tromey  <tom@tromey.com>

* tracepoint.h (class collection_list) <append_exp>: Take a
std::string.
* tracepoint.c (collection_list::append_exp): Take a std::string.
(encode_actions_1): Update.

gdb/ChangeLog
gdb/tracepoint.c
gdb/tracepoint.h

index d567830b1fa12183a5fdd7dc5dc8a0b044339480..2751dfe64a09db61b6e85ee8cc4ebfc702682fe1 100644 (file)
@@ -1,3 +1,10 @@
+2021-01-09  Tom Tromey  <tom@tromey.com>
+
+       * tracepoint.h (class collection_list) <append_exp>: Take a
+       std::string.
+       * tracepoint.c (collection_list::append_exp): Take a std::string.
+       (encode_actions_1): Update.
+
 2021-01-08  Tom Tromey  <tromey@adacore.com>
 
        * parse.c (parse_expression): Add void_context_p parameter.  Use
index 7109fd8cb9dfc98977edde4bd76a4b1a0440e127..17d70a6a8d420f038f5169d5e591d77fdf4878c3 100644 (file)
@@ -1266,16 +1266,12 @@ collection_list::stringify ()
   return str_list;
 }
 
-/* Add the printed expression EXP to *LIST.  */
+/* Add the expression STR to M_COMPUTED.  */
 
 void
-collection_list::append_exp (struct expression *exp)
+collection_list::append_exp (std::string &&str)
 {
-  string_file tmp_stream;
-
-  print_expression (exp, &tmp_stream);
-
-  m_computed.push_back (std::move (tmp_stream.string ()));
+  m_computed.push_back (std::move (str));
 }
 
 void
@@ -1379,6 +1375,7 @@ encode_actions_1 (struct command_line *action,
                {
                  unsigned long addr;
 
+                 const char *exp_start = action_exp;
                  expression_up exp = parse_exp_1 (&action_exp, tloc->address,
                                                   block_for_pc (tloc->address),
                                                   1);
@@ -1412,7 +1409,8 @@ encode_actions_1 (struct command_line *action,
                                             memrange_absolute, addr,
                                             TYPE_LENGTH (exp->elts[1].type),
                                             tloc->address);
-                     collect->append_exp (exp.get ());
+                     collect->append_exp (std::string (exp_start,
+                                                       action_exp));
                      break;
 
                    case OP_VAR_VALUE:
@@ -1441,7 +1439,8 @@ encode_actions_1 (struct command_line *action,
                      collect->add_ax_registers (aexpr.get ());
 
                      collect->add_aexpr (std::move (aexpr));
-                     collect->append_exp (exp.get ());
+                     collect->append_exp (std::string (exp_start,
+                                                       action_exp));
                      break;
                    }           /* switch */
                }               /* do */
index 294f011fe955b7ae422aa37072b83845016497c8..b32dd61fdfc874bf5bebbe6af9971efb49cc9e02 100644 (file)
@@ -257,7 +257,7 @@ public:
 
   void add_wholly_collected (const char *print_name);
 
-  void append_exp (struct expression *exp);
+  void append_exp (std::string &&exp);
 
   /* Add AEXPR to the list, taking ownership.  */
   void add_aexpr (agent_expr_up aexpr);