[RFA] Fix crash with -D_GLIBCXX_DEBUG

Message ID 20180720041056.2831-1-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey July 20, 2018, 4:10 a.m. UTC
  I noticed a buildbot failure where gdb crashed in info-os.exp, when
compiled with -D_GLIBCXX_DEBUG:

    (gdb) info os procgroups
    /usr/include/c++/7/bits/stl_algo.h:4834:
    Error: comparison doesn't meet irreflexive requirements, assert(!(a < a)).
    Objects involved in the operation:
	iterator::value_type "< operator type" {
	  type = pid_pgid_entry;
	}

The bug here is that pid_pgid_entry::operator< violates the C++
irreflexivity rule; that is, that an object cannot be less than
itself.

Tested locally by re-running info-os.exp.

gdb/ChangeLog
2018-07-19  Tom Tromey  <tom@tromey.com>

	* nat/linux-osdata.c (pid_pgid_entry::operator<): Fix
	irreflexivity violation.
---
 gdb/ChangeLog          | 5 +++++
 gdb/nat/linux-osdata.c | 8 +++++---
 2 files changed, 10 insertions(+), 3 deletions(-)
  

Comments

Tom Tromey July 30, 2018, 2:39 p.m. UTC | #1
>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> gdb/ChangeLog
Tom> 2018-07-19  Tom Tromey  <tom@tromey.com>

Tom> 	* nat/linux-osdata.c (pid_pgid_entry::operator<): Fix
Tom> 	irreflexivity violation.

I'm checking this one in.

Tom
  

Patch

diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c
index 25e895df190..2323dcc878b 100644
--- a/gdb/nat/linux-osdata.c
+++ b/gdb/nat/linux-osdata.c
@@ -415,9 +415,11 @@  struct pid_pgid_entry
 
     /* Process group leaders always come first...  */
     if (this->is_leader ())
-      return true;
-
-    if (other.is_leader ())
+      {
+	if (!other.is_leader ())
+	  return true;
+      }
+    else if (other.is_leader ())
       return false;
 
     /* ...else sort by PID.  */