This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 3/3] btrace: Remove ui_out cleanups


On 2018-03-05 07:39, Metzger, Markus T wrote:
Hello Simon,


This patch replaces the cleanups that close the list and tuple of the
btrace instruction history output with ui_out_emit_tuple and
ui_out_emit_list.

This allows removing make_cleanup_ui_out_tuple_begin_end and
make_cleanup_ui_out_list_begin_end.

This patch (along with the previous ones in the series) was regtested on
the buildbot.


diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 15ce760f5a..ddd15c4781 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -620,26 +620,25 @@ btrace_find_line_range (CORE_ADDR pc)

 static void
btrace_print_lines (struct btrace_line_range lines, struct ui_out *uiout,
-		    struct cleanup **ui_item_chain, int flags)
+		    gdb::optional<ui_out_emit_tuple> *src_and_asm_tuple,
+		    gdb::optional<ui_out_emit_list> *asm_list,

Reference instead of pointer?

I once pointed this out on one of Tom's patches, and he said that in the caller code, it's more obvious that object is meant to be modified if you do:

  function_that_modifies_object (&object);

instead of

  function_that_modifies_object (object);

And I kind of agree with that it is, which is why I've been using pointers when references would have worked (ok, here the function name makes it obvious but it's not always the case). In the implementation of the function, since you use object->field instead of object.field, it also hints that you're not modifying a local object. But I also agree that it's really not C++-y to do it this way, so I'll happily change it.

-  for (line = lines.begin; line < lines.end; ++line)
+  for (int line = lines.begin; line < lines.end; ++line)
     {
-      if (*ui_item_chain != NULL)
-	do_cleanups (*ui_item_chain);
+      asm_list->reset ();
+      src_and_asm_tuple->reset ();

The SRC_AND_ASM_TUPLE reset () shouldn't be necessary; it is reset ()
in emplace ().

Ok.

-      *ui_item_chain
-	= make_cleanup_ui_out_tuple_begin_end (uiout, "src_and_asm_line");
+      src_and_asm_tuple->emplace (uiout, "src_and_asm_line");

       print_source_lines (lines.symtab, line, line + 1, psl_flags);

-      make_cleanup_ui_out_list_begin_end (uiout, "line_asm_insn");
+      asm_list->emplace (uiout, "line_asm_insn");
     }
 }

Looks good to me, otherwise.

I have not tested it, though. Did you run the gdb.btrace test suite? You said you ran buildbot but that might skip gdb.btrace when run on VMs or on old
hardware.

Please let me know if you want me to run the gdb.btrace tests for you. A user
branch would be nice in that case.

Yes, I have ran the gdb.btrace/*.exp tests locally on two different machines and saw no regressions. However, the processors may be a bit old (Q6600 from 2007 and i5-4310U from 2014), so it's possible that not all required features are available, and therefore some tests may be skipped. So if you want to be sure, here's a branch for you to test:

users/simark/btrace-cleanups
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=shortlog;h=refs/heads/users/simark/btrace-cleanups

Thanks!

Simon


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]