From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb@sourceware.org
Subject: Will therefore GDB utilize C++ or not?
Date: Fri, 30 Mar 2012 16:14:00 -0000 [thread overview]
Message-ID: <20120330161403.GA17891@host2.jankratochvil.net> (raw)
Hi,
there is now new patch:
Re: [PATCH] Allow 64-bit enum values
http://sourceware.org/ml/gdb-patches/2012-03/msg00932.html
which is a pre-requisite for GDB inferior type fields safety similar to what
I already checked in as:
[commit] [patch 2/2] typedef-checking for CU relative vs. absolute offsets
http://sourceware.org/ml/gdb-patches/2012-03/msg00721.html
But compared to the [commit] patch of only 282 '+' lines limited to dwarf*
files only above the type fields safety patch will be huge and thorough the
whole GDB codebase (TYPE_LENGTH: 1103 lines, FIELD_BITPOS: 22 lines, sure the
patch will be larger)..
->
This whole effort is wrong if GDB was in C++ which allows to use:
http://en.wikipedia.org/wiki/Object_type_%28object-oriented_programming%29#Boxing
so that one can directly use type->length as long as it is safe, an example of
C++ solution is given below.
It no longer needs to patch every use of TYPE_LENGTH into some TYPE_LENGTH_VAL
or to append '.cu_off' to every use of the "integer" like I did in the
[commit] patch above.
There are sure many other cases I still wait to solve using C++. There was
some plan to have GDB exceptions and cleanups converted to C++ exceptions and
RAII
http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization
automatic allocation/deallocation which would automatically solve many other
bugs being fixed by hand here and there. I have filed also
crashes from stale frame_info *
http://sourceware.org/bugzilla/show_bug.cgi?id=13866
which would be easily sanity-protected by mandatory referencing frame_info *
by C++ smart-pointer and during reinit_frame_cache just assert there are no
live instances of frame_info references out there etc. etc.
For switching GDB compilation to C++ there is needed to resolve some name
clashes first
http://sourceware.org/gdb/wiki/ArcherBranchManagement
Enabling gdb to compile with the -Wc++-compat flag to gcc.
archer-ratmice-compile-Wc++-compat
but there is enough workforce to do this mechanical type of work as long as
there is an agreement to switch to C++.
To C++ or not to C++? Unfortunately the discussion was here already before
and I am aware several contributors are not welcome with it, I think it does
not need to affect readability of C code much, there is not enough workforce
to rewrite all the GDB code into C++ style anyway. Still C++ would help
a lot, some kinds of bugs are not solvable without it.
I am open to suggestions of static analysis tools to use instead but at least
according to the experience of Tom Tromey it is not so easy / safe / foolproof
to use, IIUC his words.
Thanks,
Jan
#include <stdint.h>
class Length
{
int64_t _x;
public:
Length(int64_t x) { _x = x; }
operator int64_t() { return _x; }
private:
operator int() { return _x; }
};
void ok (int64_t l) {}
void bad (int l) {}
void bad2 (long long l) {}
int
main()
{
Length l(10);
// great, no errors
ok (l);
// error: ‘Length::operator int()’ is private
// error: within this context
// note: candidates are:
// note: Length::operator int()
// note: Length::operator int64_t()
// error: initializing argument 1 of ‘void bad2(long long int)’
bad (l);
// error: conversion from ‘Length’ to ‘long long int’ is ambiguous
bad2 (l);
}
next reply other threads:[~2012-03-30 16:14 UTC|newest]
Thread overview: 115+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-30 16:14 Jan Kratochvil [this message]
2012-04-04 20:48 ` Tom Tromey
2012-04-04 21:55 ` Mark Kettenis
2012-04-05 3:31 ` Sergio Durigan Junior
2012-04-05 11:46 ` Phil Muldoon
2012-04-06 0:35 ` Will therefore GDB utilize C++? Not John Gilmore
2012-04-06 1:35 ` Russell Shaw
2012-04-06 13:16 ` Joel Brobecker
2012-04-06 14:43 ` Russell Shaw
2012-04-06 15:34 ` Michael Eager
2012-04-06 23:32 ` John Gilmore
2012-04-07 1:04 ` Robert Dewar
2012-04-07 1:52 ` Thomas Dineen
2012-04-07 16:54 ` Michael Eager
2012-04-09 23:59 ` Stan Shebs
2012-04-05 0:22 ` Will therefore GDB utilize C++ or not? asmwarrior
2012-04-09 18:41 ` Pedro Alves
2012-04-09 19:05 ` Jan Kratochvil
2012-04-09 19:49 ` Pedro Alves
2012-04-09 20:15 ` Paul Smith
2012-04-12 20:06 ` Daniel Jacobowitz
2012-04-12 21:28 ` Paul_Koning
2012-04-13 0:04 ` Doug Evans
2012-04-18 14:10 ` Pedro Alves
2012-04-18 20:27 ` Tom Tromey
2012-04-18 14:08 ` Pedro Alves
2012-04-21 17:24 ` Daniel Jacobowitz
2012-04-16 6:55 ` Jan Kratochvil
2012-04-18 14:11 ` Pedro Alves
2012-04-18 15:16 ` Jan Kratochvil
2012-04-18 15:28 ` Pedro Alves
2012-04-18 15:54 ` Jan Kratochvil
2012-04-18 16:01 ` Pedro Alves
2012-04-18 16:07 ` Joel Brobecker
2012-04-18 16:13 ` Jan Kratochvil
2012-04-18 16:23 ` Joel Brobecker
2012-04-18 16:31 ` Joel Sherrill
2012-04-18 16:50 ` Pedro Alves
2012-04-18 16:57 ` Joel Brobecker
2012-04-18 17:28 ` Joel Sherrill
2012-04-18 17:40 ` Paul_Koning
2012-04-18 20:37 ` Frank Ch. Eigler
2012-04-18 20:38 ` Paul_Koning
2012-04-18 20:36 ` Tom Tromey
2012-04-18 17:48 ` John Gilmore
2012-04-18 19:07 ` Tom Tromey
2012-04-18 23:10 ` John Gilmore
2012-05-18 18:36 ` Tom Tromey
2012-05-18 18:47 ` Paul_Koning
2012-05-18 19:36 ` Tom Tromey
2012-05-18 19:44 ` Paul_Koning
2012-05-18 20:07 ` Tom Tromey
2012-05-18 20:41 ` Aurelian Melinte
2012-05-18 18:51 ` Lazy CU expansion (Was: Will therefore GDB utilize C++ or not?) Tom Tromey
2012-04-18 20:34 ` Will therefore GDB utilize C++ or not? Tom Tromey
2012-04-18 19:18 ` Will C++ proponents spend 20 minutes to try what they're proposing? John Gilmore
2012-04-18 19:23 ` Jan Kratochvil
2012-04-18 20:40 ` Tom Tromey
2012-04-18 20:56 ` Mike Frysinger
2012-04-18 20:31 ` Will therefore GDB utilize C++ or not? Tom Tromey
2012-04-18 20:25 ` Tom Tromey
2012-05-21 18:11 ` Pedro Alves
2012-05-21 18:36 ` Jan Kratochvil
2012-11-21 20:18 ` Jan Kratochvil
2012-04-10 0:23 ` Yao Qi
2012-04-10 9:47 ` Yao Qi
2012-04-18 20:11 ` Tom Tromey
2012-04-18 20:31 ` Can it really be ok to map GPL'd code into any old process? John Gilmore
2012-04-18 20:36 ` Pedro Alves
2012-04-23 18:03 ` Will therefore GDB utilize C++ or not? Tom Tromey
2012-05-18 19:55 ` Tom Tromey
2012-05-18 21:56 ` Joel Brobecker
2012-05-19 2:17 ` Tom Tromey
2012-05-19 15:21 ` Daniel Jacobowitz
2012-05-19 21:36 ` Joel Brobecker
2012-05-20 12:16 ` Frank Ch. Eigler
2012-05-21 15:56 ` Pedro Alves
2012-05-21 16:15 ` Jan Kratochvil
2012-05-21 17:37 ` Paul_Koning
2012-05-21 17:58 ` Jan Kratochvil
2012-05-22 18:03 ` Paul_Koning
2012-05-21 18:08 ` Pedro Alves
2012-05-21 18:08 ` Tom Tromey
2012-05-21 18:10 ` Jan Kratochvil
2012-05-21 18:54 ` Matt Rice
2012-05-26 15:50 ` Jan Kratochvil
2012-06-02 7:01 ` Russell Shaw
2012-06-02 7:13 ` Jan Kratochvil
2012-06-02 10:47 ` Russell Shaw
2012-06-02 11:10 ` Jan Kratochvil
2012-06-02 11:15 ` Jan Kratochvil
2012-06-02 11:15 ` Russell Shaw
2012-11-22 18:46 ` Jan Kratochvil
2012-11-22 21:42 ` John Gilmore
2012-11-23 15:26 ` Jan Kratochvil
2012-11-27 1:29 ` Stan Shebs
2012-11-27 2:02 ` Paul_Koning
2012-11-27 2:59 ` Stan Shebs
2012-11-27 15:17 ` Paul_Koning
2012-11-27 21:14 ` Tom Tromey
2012-04-09 23:23 ` Stan Shebs
2012-04-18 14:22 ` Pedro Alves
2012-04-18 18:12 ` Stan Shebs
2012-04-18 18:32 ` Paul_Koning
2012-04-18 18:37 ` Pedro Alves
2012-04-19 8:43 ` Yao Qi
2012-12-04 14:17 ` Jan Kratochvil
2012-12-04 14:44 ` Mark Kettenis
2012-12-04 14:52 ` Jan Kratochvil
[not found] ` <CACTLOFof0v6NJe8WemS--Q3iMSXjHciwASxBAED5ki3scaNZuw@mail.gmail.com>
2012-12-07 12:57 ` Jan Kratochvil
2012-12-07 13:25 ` Yao Qi
2012-12-11 6:25 ` Matt Rice
2012-12-13 15:12 ` Jan Kratochvil
2012-12-14 11:03 ` Matt Rice
2012-12-14 12:16 ` Jan Kratochvil
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=20120330161403.GA17891@host2.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb@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