public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Remove a use of print_expression
@ 2020-12-20 22:50 Tom Tromey
  2021-01-09 17:05 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2020-12-20 22:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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
2020-12-20  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    |  7 +++++++
 gdb/tracepoint.c | 17 ++++++++---------
 gdb/tracepoint.h |  2 +-
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index cb2b3b65c33..f1ddb2e79e7 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -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 */
diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h
index 56a1f92d9d0..83756f15419 100644
--- a/gdb/tracepoint.h
+++ b/gdb/tracepoint.h
@@ -257,7 +257,7 @@ class collection_list
 
   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);
-- 
2.17.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Remove a use of print_expression
  2020-12-20 22:50 [PATCH] Remove a use of print_expression Tom Tromey
@ 2021-01-09 17:05 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2021-01-09 17:05 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> The tracepoint code uses print_expression to reconstruct an expression
Tom> string.  However, the original expression is already available -- it
Tom> was just parsed a bit earlier in the same function.  This patch
Tom> changes this code to simply save the already-parsed expression, rather
Tom> than attempt to reconstruct it.

Tom> gdb/ChangeLog
Tom> 2020-12-20  Tom Tromey  <tom@tromey.com>

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

I'm checking this in now.

Tom

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-09 17:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-20 22:50 [PATCH] Remove a use of print_expression Tom Tromey
2021-01-09 17:05 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).