public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/5] Add operator< and operator== to linetable_entry
Date: Wed, 08 Mar 2023 08:42:45 -0700	[thread overview]
Message-ID: <20230308-submit-constify-linetable-v1-1-ca4057478141@tromey.com> (raw)
In-Reply-To: <20230308-submit-constify-linetable-v1-0-ca4057478141@tromey.com>

This adds a couple of comparison operators to linetable_entry, and
simplifies both the calls to sort and one other spot that checks for
equality.
---
 gdb/buildsym.c  | 14 +-------------
 gdb/disasm.c    |  2 +-
 gdb/symtab.h    | 13 +++++++++++++
 gdb/xcoffread.c |  4 +---
 4 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index dbc81727cb1..6594da68131 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -892,17 +892,6 @@ buildsym_compunit::end_compunit_symtab_with_blockvector
     {
       if (!subfile->line_vector_entries.empty ())
 	{
-	  const auto lte_is_less_than
-	    = [] (const linetable_entry &ln1,
-		  const linetable_entry &ln2) -> bool
-	      {
-		if (ln1.pc == ln2.pc
-		    && ((ln1.line == 0) != (ln2.line == 0)))
-		  return ln1.line == 0;
-
-		return (ln1.pc < ln2.pc);
-	      };
-
 	  /* Like the pending blocks, the line table may be scrambled in
 	     reordered executables.  Sort it if OBJF_REORDERED is true.  It
 	     is important to preserve the order of lines at the same
@@ -910,8 +899,7 @@ buildsym_compunit::end_compunit_symtab_with_blockvector
 	     relationships, this is why std::stable_sort is used.  */
 	  if (m_objfile->flags & OBJF_REORDERED)
 	    std::stable_sort (subfile->line_vector_entries.begin (),
-			      subfile->line_vector_entries.end (),
-			      lte_is_less_than);
+			      subfile->line_vector_entries.end ());
 	}
 
       /* Allocate a symbol table if necessary.  */
diff --git a/gdb/disasm.c b/gdb/disasm.c
index a0406377acc..49053dcfbad 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -604,7 +604,7 @@ do_mixed_source_and_assembly_deprecated
 
   for (; i < nlines - 1 && le[i].pc < high; i++)
     {
-      if (le[i].line == le[i + 1].line && le[i].pc == le[i + 1].pc)
+      if (le[i] == le[i + 1])
 	continue;		/* Ignore duplicates.  */
 
       /* Skip any end-of-function markers.  */
diff --git a/gdb/symtab.h b/gdb/symtab.h
index c565bc8eac4..69f0eaa0f88 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1547,6 +1547,19 @@ struct rust_vtable_symbol : public symbol
 
 struct linetable_entry
 {
+  bool operator< (const linetable_entry &other) const
+  {
+    if (pc == other.pc
+	&& (line != 0) != (other.line != 0))
+      return line == 0;
+    return pc < other.pc;
+  }
+
+  /* Two entries are equal if they have the same line and PC.  The
+     other members are ignored.  */
+  bool operator== (const linetable_entry &other) const
+  { return line == other.line && pc == other.pc; }
+
   /* The line number for this entry.  */
   int line;
 
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index b74b235ee87..93054bdeb19 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -439,9 +439,7 @@ arrange_linetable (std::vector<linetable_entry> &old_linetable)
   if (fentries.empty ())
     return;
 
-  std::sort (fentries.begin (), fentries.end (),
-	     [] (const linetable_entry &lte1, const linetable_entry& lte2)
-	     { return lte1.pc < lte2.pc; });
+  std::sort (fentries.begin (), fentries.end ());
 
   /* Allocate a new line table.  */
   std::vector<linetable_entry> new_linetable;

-- 
2.39.1


  reply	other threads:[~2023-03-08 15:42 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08 15:42 [PATCH 0/5] Make line tables independent of objfile Tom Tromey
2023-03-08 15:42 ` Tom Tromey [this message]
2023-03-11  3:21   ` [PATCH 1/5] Add operator< and operator== to linetable_entry Simon Marchi
2023-03-08 15:42 ` [PATCH 2/5] Change linetables to be objfile-independent Tom Tromey
2023-03-11  3:48   ` Simon Marchi
2023-03-11 15:36     ` Tom Tromey
2023-03-11 19:13       ` Simon Marchi
2023-03-12  3:24         ` Tom Tromey
2023-03-12 13:40           ` Simon Marchi
2023-03-16 14:02             ` Tom Tromey
2023-03-16 14:45               ` Simon Marchi
2023-03-16 23:43                 ` Tom Tromey
2023-03-17  2:45                   ` Simon Marchi
2023-03-17 13:09                     ` Tom Tromey
2023-03-17 22:21                       ` Tom Tromey
2023-03-20 14:57                         ` Simon Marchi
2023-03-08 15:42 ` [PATCH 3/5] Constify linetables Tom Tromey
2023-03-08 15:42 ` [PATCH 4/5] Remove extra scopes from objfile_relocate1 Tom Tromey
2023-03-08 15:42 ` [PATCH 5/5] Change linetable_entry::is_stmt to bool Tom Tromey
2023-03-11  3:51 ` [PATCH 0/5] Make line tables independent of objfile Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230308-submit-constify-linetable-v1-1-ca4057478141@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).