Boost logo

Boost :

Subject: Re: [boost] Interest check: Boost.Debug
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2009-06-02 20:33:08


On Tue, Jun 2, 2009 at 4:42 PM, Zachary Turner <divisortheory_at_[hidden]> wrote:
> On Tue, Jun 2, 2009 at 6:28 PM, Emil Dotchevski <emildotchevski_at_[hidden]>wrote:
>
>> > Also, I think it's useful to at the very least be able to iterate the
>> stack
>> > frames and find source/line number information for each call in stack.
>>
>> Provided I have a function that gets me a string that contains that
>> information, I personally don't have a use case for such iteration. I
>> can't think of what else I'd want to do with this data other than dump
>> it somewhere as text. Can you?
>>
>
> Well, if you're saying that iterating over the frames to get source/line
> information when the to_string() already contains formatted source/line
> information is unnecessary since one could implement a parser to extract it,
> then eh, I'm not sure.

No, I meant that I can't think of a use case for extracting any
semantic data from a stack trace.

> The main use case I had for knowing source / line information I described in
> my second post in this thread.  In short it allows a more powerful
> implementation of the __FILE__ and __LINE__ pre-defined compiler macros.  If
> you wanted to provide an overloaded global new/delete to, for example,
> provide cross platform memory diagnostics then __FILE__ and __LINE__ are
> insufficient since they would point inside the implementation of the
> operator.  With stack frame iteration your operator new / delete could
> simply create a stack trace, move backward 1 level, and what you end up with
> is the equivalent of a __FILE__ / __LINE__ for the previous function, which
> is the only thing that would be helpful in that case.

Although in most cases knowing how I ended up calling the function is
also useful information, I agree that needing to go (possibly constant
number) K levels up is a valid use case. I'd still prefer a simpler
interface:

typedef <unspecified> stack_frame;
std::string to_string( stack_frame const & );

class stack_trace
{
public:
  stack_trace();
  bool empty() const;
  stack_frame top() const;
  void pop();
};
std::string to_string( stack_trace const & );

Simple use:

std::string s=to_string(boost::stack_trace());

Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk