From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id E6CCF3858D1E; Sat, 11 Mar 2023 15:56:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E6CCF3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678550160; bh=r7wEMyOQbOqNsyMPQf2qtkbhjUBgsuuRFLHqAfOoYjw=; h=From:To:Subject:Date:From; b=RDI95V0gBsMsOSfKyRaeLGR+koofXmEAl/J+lhDkfrPbpNwSGqKzaOlWyFRjei09n lT8BWaC6j4W5mJI/b2jJg3qvdc3lmrJsmkQUZoGnqdpxsNrQ+Wfh3J2gh7wyWfhv79 S3SRmyxK/CoTcMA4ErF2Pgw7ZSEiU7B1MVqzoXLM= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Add operator< and operator== to linetable_entry X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 1afdbb1e986157a73a7bf1cf4fa03b9426e824e8 X-Git-Newrev: 6e6ac32dde61fd3019b05adaeec372eb16c12bff Message-Id: <20230311155600.E6CCF3858D1E@sourceware.org> Date: Sat, 11 Mar 2023 15:56:00 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D6e6ac32dde61= fd3019b05adaeec372eb16c12bff commit 6e6ac32dde61fd3019b05adaeec372eb16c12bff Author: Tom Tromey Date: Tue Mar 7 18:24:14 2023 -0700 Add operator< and operator=3D=3D to linetable_entry =20 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. =20 Approved-By: Simon Marchi Diff: --- 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 712ca4bbd7a..459bc848c67 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -891,25 +891,13 @@ buildsym_compunit::end_compunit_symtab_with_blockvect= or { if (!subfile->line_vector_entries.empty ()) { - const auto lte_is_less_than - =3D [] (const linetable_entry &ln1, - const linetable_entry &ln2) -> bool - { - if (ln1.pc =3D=3D ln2.pc - && ((ln1.line =3D=3D 0) !=3D (ln2.line =3D=3D 0))) - return ln1.line =3D=3D 0; - - return (ln1.pc < ln2.pc); - }; - /* Like the pending blocks, the line table may be scrambled in reordered executables. Sort it. It is important to preserve the order of lines at the same address, as this maintains the inline function caller/callee relationships, this is why std::stable_sort is used. */ std::stable_sort (subfile->line_vector_entries.begin (), - subfile->line_vector_entries.end (), - lte_is_less_than); + subfile->line_vector_entries.end ()); } =20 /* 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 =20 for (; i < nlines - 1 && le[i].pc < high; i++) { - if (le[i].line =3D=3D le[i + 1].line && le[i].pc =3D=3D le[i + 1].pc) + if (le[i] =3D=3D le[i + 1]) continue; /* Ignore duplicates. */ =20 /* 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 =20 struct linetable_entry { + bool operator< (const linetable_entry &other) const + { + if (pc =3D=3D other.pc + && (line !=3D 0) !=3D (other.line !=3D 0)) + return line =3D=3D 0; + return pc < other.pc; + } + + /* Two entries are equal if they have the same line and PC. The + other members are ignored. */ + bool operator=3D=3D (const linetable_entry &other) const + { return line =3D=3D other.line && pc =3D=3D other.pc; } + /* The line number for this entry. */ int line; =20 diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index 78aa9539d78..819735d62db 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -439,9 +439,7 @@ arrange_linetable (std::vector &old_li= netable) if (fentries.empty ()) return; =20 - std::sort (fentries.begin (), fentries.end (), - [] (const linetable_entry <e1, const linetable_entry& lte2) - { return lte1.pc < lte2.pc; }); + std::sort (fentries.begin (), fentries.end ()); =20 /* Allocate a new line table. */ std::vector new_linetable;