From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27670 invoked by alias); 30 Jun 2007 14:56:39 -0000 Received: (qmail 27661 invoked by uid 22791); 30 Jun 2007 14:56:39 -0000 X-Spam-Check-By: sourceware.org Received: from shell4.BAYAREA.NET (HELO shell4.bayarea.net) (209.128.82.1) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 30 Jun 2007 14:56:36 +0000 Received: (qmail 26707 invoked from network); 30 Jun 2007 07:56:33 -0700 Received: from 209-128-106-254.bayarea.net (HELO ?192.168.20.7?) (209.128.106.254) by shell4.bayarea.net with SMTP; 30 Jun 2007 07:56:33 -0700 Message-ID: <46866F20.2010902@eagercon.com> Date: Sat, 30 Jun 2007 14:56:00 -0000 From: Michael Eager User-Agent: Thunderbird 1.5.0.9 (X11/20070102) MIME-Version: 1.0 To: gdb@sources.redhat.com Subject: GDB in C++ Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2007-06/txt/msg00356.txt.bz2 I'd like to bring up what I think will be regarded as heresy: converting GDB to C++. First, let me say that I'm not a fan of C++. It's an overly complex language with many faults. That said, when I read and step through GDB code I see significant portions which are clearly written in a way which attempts to emulate classes, objects, and both data and member encapsulation. I also see some flaws in this emulation, some of which affect performance, others which affect logic. There are also places where the encapsulation is broken. All of this makes debugging more difficult. For example, in gdbarch handling, all (or almost all) routines start with one or more asserts which check that the routine is passed a pointer to an gdbarch specification. Actually, they don't validate that this is a gdbarch, only that the pointer is not NULL. These routines and the asserts are executed tens of thousands of times when running GDB. If this were a real class, many of these asserts would be unnecessary, since by construction, the "this" pointer would be valid. Inlining would also improve performance, since it would eliminate many function calls. I'm repeatedly surprised to step over an assert and find that either the state has changed or I hit a previously set breakpoint. There are significant side effects to executing these asserts, which changes the apparent flow of the program. While asserts are a "good thing", hidden side effects and especially side effects in asserts are a "bad thing". I think that many of these side effects would disappear or at least become apparent if real classes were used. Some additional history: many years ago I participated in a major re-write of Sun Microsystem's DBX. We converted it from K&R style C to ANSI C which was compatible with C++. I then re-wrote about 1/3 of DBX in a constrained subset of C++, essentially C with Classes. The handling of object files (a.out and ELF), symbols, stabs, and shared libraries was all converted to use classes. The rewrite was quite successful in adding new functionality and eliminating many bugs. There are vestiges of K&R support in GDB, such as the PARAMS function, but I believe that this is not universally used and is out of date. I think that concerns about availability of C++ on currently supported hosts are also out of date. As a side effect, if GDB were written in C++, I think that the support for C++ debugging would be forced to improve. I'm out of town at the moment, being fitted with asbestos undergarments and armor, getting ready for the anticipated flames and brickbats. I may be a bit slow in responding. -- Michael Eager eager@eagercon.com 1960 Park Blvd., Palo Alto, CA 94306 650-325-8077