From: David Carlton <carlton@math.stanford.edu>
To: gdb <gdb@sources.redhat.com>
Subject: struct environment
Date: Thu, 05 Sep 2002 13:50:00 -0000 [thread overview]
Message-ID: <ro1lm6gcg9r.fsf@jackfruit.Stanford.EDU> (raw)
As I e-mailed a couple of weeks ago, I'd like to work on reworking the
namespace support in GDB. But, before working on namespaces proper,
there's a fair amount of existing code in GDB that is relevant to this
task that I'd like to clean up. Specifically, I think that namespace
support will be much saner if all existing symbol lookup mechanisms
are unified into some sort of 'environment' interface.
The existing mechanisms in question are:
1) The members 'hashtable', 'nsyms', and 'sym' of 'struct block'.
2) The global environment: global symbols, partial symbols, minimal
symbols.
3) The members '{n,}fields' in 'struct type'.
Namespaces are similar in many ways to the global environment, so
taming the global environment code will be very helpful when reworking
namespaces. And once we handle 'using' declarations, symbol lookups
won't always proceed up a straightforward line of inheritance of
blocks that ends in the global environment, so I suspect that having
blocks, the global environment, and namespaces all be accessible via
the same sort of object will make code simpler. (Exactly why the
third case above should be handled in the same way is another story,
but I don't want to go into that now.)
So I want to add a type 'struct environment' to GDB. It will be
completely opaque, with a variety of internal implementations
available (similar to the way that 'struct block' allows you to use
either a hash table or a simple list of symbols) sharing a common
external interface. I want to start by converting 'struct block' over
to using this, then converting the global environment over to using
this, then (probably) 'struct type', and finally getting namespaces to
work well.
I think I'll soon be ready to start converting over 'struct block',
and I'd like feedback from people about whether or not this is a good
idea, and about what the parts of the interface to 'struct
environment' that are relevant to 'struct block' should look like.
Here are some design issues that arise:
* What constructors/destructors should there be? buildsym.c will need
constructors that create environments of a fixed size on an obstack
that are implemented using either a hashtable or a list. jv-lang.c
and mdebugread.c both need constructors for environments allocated
using xmalloc whose final size isn't known initially; these will
need destructors, and perhaps some sort of 'finalize' function to
call once we know everything's been added to the environments in
question. (I'll look into those situations more closely soon.)
* There needs to be a way to add symbols to an environment while
constructing it. Maybe
void env_add_symbol(struct environment *, struct symbol *);
* There should be a shallow lookup function, i.e. one that looks up a
symbol just in one environment, without going up to a parent
environment. (The latter will get added in once we get to
converting over the global environment.) Maybe
struct symbol *env_lookup_shallow(struct environment *,
const char *);
* There should probably be iterators that allow one to examine every
symbol in an environment. One possibility, to save on memory
management headaches, would be to allow only one active iterator per
environment, and have that stored as part of the environment; so we
would have
struct symbol *env_lookup_first(struct environment *);
struct symbol *env_lookup_next(struct environment *);
(Where these return NULL if we've seen all the symbols in the
environment.) I'll have to double-check to make sure that existing
use of iteration over symbols blocks is compatible with this, but
I'm almost positive it is.
* It's vaguely possible that some code might need to count the number
of symbols in an environment, but I don't think so; presumably
that's only used by iterators or by code that could be moved to the
inside of struct environment.
* When scanning GDB for uses of 'struct block', I noticed that some
code wants to sort symbols in the block. I'll have to look at where
and why that's happening, but I don't think it's anything serious.
(When it's necessary, it can presumably be added to a 'finalize'
function as in the discussion of constructors above.)
I think that's about it.
That describes how I would like things to look once I've switched
'struct block' over to using a 'struct environment' member (replacing
its current members 'hashtable', 'nsyms', and 'sym'). And presumably
most or all of this portion of the interface will remain once the
global environment has been converted over, though of course the
interface will grow in order to handle the global environment.
The question remains of how to get from here to there. I'm pretty
sure that I can convert 'struct block' over to using environments in
an incremental fashion. Describing that process will take a fair
amount of time, though, so I'll send it in a separate e-mail, probably
some time tomorrow but maybe Monday.
David Carlton
carlton@math.stanford.edu
next reply other threads:[~2002-09-05 20:50 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-09-05 13:50 David Carlton [this message]
2002-09-06 8:06 ` Daniel Jacobowitz
2002-09-06 10:20 ` David Carlton
2002-09-06 10:57 ` Daniel Jacobowitz
2002-09-06 11:56 ` David Carlton
2002-09-06 12:34 ` Daniel Berlin
2002-09-06 12:41 ` Daniel Jacobowitz
2002-09-06 12:55 ` Daniel Berlin
2002-09-11 11:33 ` David Carlton
2002-09-11 11:36 ` Daniel Jacobowitz
2002-09-11 12:27 ` David Carlton
2002-09-06 14:43 ` David Carlton
2002-09-06 14:46 ` Daniel Jacobowitz
2002-09-06 14:57 ` mdebugread.c (was Re: struct environment) David Carlton
2002-09-06 15:35 ` Daniel Jacobowitz
2002-09-10 17:25 ` struct environment David Carlton
2002-09-10 17:31 ` Daniel Jacobowitz
2002-09-11 10:29 ` David Carlton
2002-09-11 10:55 ` Daniel Jacobowitz
2002-09-11 12:33 ` Daniel Berlin
2002-09-10 17:36 ` David Carlton
2002-09-16 22:03 ` Andrew Cagney
2002-09-06 15:00 ` David Carlton
2002-09-06 16:37 ` Tom Tromey
2002-09-06 17:19 ` David Carlton
2002-09-07 10:26 ` Per Bothner
2002-09-07 10:32 ` Daniel Jacobowitz
2002-09-09 11:18 ` David Carlton
2002-09-12 12:26 ` Andrew Cagney
2002-09-13 9:44 ` David Carlton
2002-09-17 0:48 ` Andrew Cagney
2002-09-17 6:41 ` Daniel Jacobowitz
2002-09-17 8:59 ` Andrew Cagney
2002-09-17 9:07 ` Daniel Jacobowitz
2002-09-17 10:54 ` Andrew Cagney
2002-09-17 11:02 ` Daniel Jacobowitz
2002-09-17 12:37 ` Andrew Cagney
2002-09-17 12:41 ` Daniel Jacobowitz
2002-09-18 8:13 ` Andrew Cagney
2002-09-17 12:52 ` Daniel Berlin
2002-09-17 13:34 ` Daniel Jacobowitz
2002-09-17 21:51 ` Daniel Berlin
2002-09-18 7:26 ` Daniel Jacobowitz
2002-09-18 9:08 ` David Carlton
2002-09-17 12:18 ` David Carlton
2002-09-17 10:29 ` David Carlton
2002-09-17 12:50 ` Daniel Berlin
2002-09-17 13:24 ` David Carlton
2002-09-18 22:26 ` Eli Zaretskii
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=ro1lm6gcg9r.fsf@jackfruit.Stanford.EDU \
--to=carlton@math.stanford.edu \
--cc=gdb@sources.redhat.com \
/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