From: Daniel Jacobowitz <dan@codesourcery.com>
To: Mark Kettenis <mark.kettenis@xs4all.nl>
Cc: Nathan Sidwell <nathan@codesourcery.com>, gdb-patches@sourceware.org
Subject: Re: add vector container type
Date: Mon, 10 Jul 2006 12:54:00 -0000 [thread overview]
Message-ID: <20060710125419.GA8429@nevyn.them.org> (raw)
In-Reply-To: <24259.192.87.1.22.1152532444.squirrel@webmail.xs4all.nl>
On Mon, Jul 10, 2006 at 01:54:04PM +0200, Mark Kettenis wrote:
> Nathan, can you give a motivation why we need this in GDB? Just the fact
> that GCC uses it and CSL developed some stuff that's based on this, is
> hardly enough to justify introducing yet another API to do memory
> allocation in GDB. Why are the existing interfaces not good enough for
> implementing the flash programming stuff? If this interface is better,
> are we going to convert other bits of GDB to use these interfaces?
This isn't an API for memory allocation; it's more like the STL but for
C. Nathan's post was a little short of examples, but here's the one
from the comments:
+ An example of their use would be,
+
+ DEF_VEC_P(tree); // non-managed tree vector.
+
+ struct my_struct {
+ VEC(tree) *v; // A (pointer to) a vector of tree pointers.
+ };
+
+ struct my_struct *s;
+
+ if (VEC_length(tree, s->v)) { we have some contents }
+ VEC_safe_push(tree, s->v, decl); // append some decl onto the end
+ for (ix = 0; VEC_iterate(tree, s->v, ix, elt); ix++)
+ { do something with elt }
It's a mostly type-safe, dynamic, growable array. We've got at least a
handful of reimplementations of the same thing in GDB, and when we were
looking at needing another for memory maps, Nathan suggested we use
GCC's instead.
It offers both standard array access (you can get a pointer to the
first element) and iterators.
Easy-to-use generic data structures are a great thing and something I
think GDB is really short of. They make writing new code a lot
simpler.
Offhand, linux-nat.c:struct simple_pid_list could be replaced with a
VEC of ints. Other structures couldn't be entirely replaced, but could
have their linked list pointers removed, e.g. struct fork_info,
struct thread_info. And there are probably places where the VEC
types would be useful in the symbol table. For instance, struct
fn_fieldlist could use one; that would make the hairy code to
construct fieldlists in the dwarf reader a bit simpler. And
there's really no need for struct badness_vector or struct
vbase, which both want to be lists.
> Could you provide a few examples of how this would be used?
>
> Oh, and Eli will want you to write a paragraph on how to use this in
> gdbint.tex.
Me too!
--
Daniel Jacobowitz
CodeSourcery
next prev parent reply other threads:[~2006-07-10 12:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-10 10:09 Nathan Sidwell
2006-07-10 11:54 ` Mark Kettenis
2006-07-10 12:54 ` Daniel Jacobowitz [this message]
2006-07-10 19:59 ` Eli Zaretskii
2006-07-13 18:29 ` Nathan Sidwell
2006-07-13 19:25 ` Eli Zaretskii
2006-07-14 16:23 ` Nathan Sidwell
2006-07-14 19:31 ` Eli Zaretskii
2006-07-17 15:09 ` Nathan Sidwell
2006-07-17 18:07 ` Mark Kettenis
2006-07-17 18:15 ` Daniel Jacobowitz
2006-07-11 18:17 ` Jim Blandy
2006-07-11 18:19 ` Nathan Sidwell
2006-08-15 19:42 ` Daniel Jacobowitz
2006-09-21 13:48 ` Daniel Jacobowitz
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=20060710125419.GA8429@nevyn.them.org \
--to=dan@codesourcery.com \
--cc=gdb-patches@sourceware.org \
--cc=mark.kettenis@xs4all.nl \
--cc=nathan@codesourcery.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