Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* How much should I cleanup?
@ 2003-02-11 23:40 David Carlton
  2003-02-17 14:58 ` Andrew Cagney
  0 siblings, 1 reply; 3+ messages in thread
From: David Carlton @ 2003-02-11 23:40 UTC (permalink / raw)
  To: gdb

When is it important to make sure that I have cleanups in place?  My
understanding is that it's important if I have control of a block of
memory that I want to xfree() after doing some work, but where that
xfree() might not be reached because of exceptional circumstances.

So, if that's correct: what are 'exceptional circumstances'?  I assume
error() and related functions count.  I don't know exactly what QUIT
does; do I have to be careful if there are QUIT's in between the
xmalloc() and the xfree()?  (Are those the only places where GDB pays
attention to ^C's?)  Any other situations?

Sigh.  C has its benefits, but ease of memory management isn't one of
them.  Every time I have to write a cleanup function, every time I
have to think about whether to alloca() memory for a string or to
xmalloc() it (and every time I can't alloca() it because I'm returning
the string in question), I get another grey hair.  (Though the grey
hair falls out soon thereafter, for better or for worse.)

David Carlton
carlton@math.stanford.edu


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How much should I cleanup?
  2003-02-11 23:40 How much should I cleanup? David Carlton
@ 2003-02-17 14:58 ` Andrew Cagney
  2003-02-17 16:46   ` David Carlton
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Cagney @ 2003-02-17 14:58 UTC (permalink / raw)
  To: David Carlton; +Cc: gdb

> When is it important to make sure that I have cleanups in place?  My
> understanding is that it's important if I have control of a block of
> memory that I want to xfree() after doing some work, but where that
> xfree() might not be reached because of exceptional circumstances.

Just assume the exception is the norm - you're going to need to do a 
clean-up.  The internals doco suggests several conventions.

> So, if that's correct: what are 'exceptional circumstances'?  I assume
> error() and related functions count.  I don't know exactly what QUIT
> does; do I have to be careful if there are QUIT's in between the
> xmalloc() and the xfree()?  (Are those the only places where GDB pays
> attention to ^C's?)  Any other situations?

Failed memory read, no frame.

> Sigh.  C has its benefits, but ease of memory management isn't one of
> them.  Every time I have to write a cleanup function, every time I
> have to think about whether to alloca() memory for a string or to
> xmalloc() it (and every time I can't alloca() it because I'm returning
> the string in question), I get another grey hair.  (Though the grey
> hair falls out soon thereafter, for better or for worse.)

Ah, yes.  C++ `is the answer' :-^

> David Carlton
> carlton@math.stanford.edu

Andrew



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How much should I cleanup?
  2003-02-17 14:58 ` Andrew Cagney
@ 2003-02-17 16:46   ` David Carlton
  0 siblings, 0 replies; 3+ messages in thread
From: David Carlton @ 2003-02-17 16:46 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb

On Sun, 16 Feb 2003 10:22:38 +0100, Andrew Cagney <ac131313@redhat.com> said:

>> So, if that's correct: what are 'exceptional circumstances'?  I assume
>> error() and related functions count.  I don't know exactly what QUIT
>> does; do I have to be careful if there are QUIT's in between the
>> xmalloc() and the xfree()?  (Are those the only places where GDB pays
>> attention to ^C's?)  Any other situations?

> Failed memory read, no frame.

Thanks.

>> Sigh.  C has its benefits, but ease of memory management isn't one
>> of them.  Every time I have to write a cleanup function, every time
>> I have to think about whether to alloca() memory for a string or to
>> xmalloc() it (and every time I can't alloca() it because I'm
>> returning the string in question), I get another grey hair.
>> (Though the grey hair falls out soon thereafter, for better or for
>> worse.)

> Ah, yes.  C++ `is the answer' :-^

Well, to handle this particular situation, a language with actual
garbage collection would be the most pleasant to program in.  (Let's
rewrite GDB in Scheme!)  But yes, C++'s improved support for
exceptions, memory management, and strings makes it much more pleasant
to program in compared to C when dealing with this sort of stuff.  (At
least once you have your old C pointer-usage habits drilled out of
you: writing exception-safe code in C++ isn't hard, it just doesn't
look quite like C code.)  Getting C++ to play well with GDB's existing
memory management/exception handling mechanisms would take a little
thought, though I don't see any reason why it couldn't be done.

David Carlton
carlton@math.stanford.edu


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-02-17 16:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-11 23:40 How much should I cleanup? David Carlton
2003-02-17 14:58 ` Andrew Cagney
2003-02-17 16:46   ` David Carlton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox