Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Contributions to C::B => Topic started by: p2rkw on September 06, 2012, 03:10:23 am

Title: Evaluate whole expression under cursor
Post by: p2rkw on September 06, 2012, 03:10:23 am
Hi,
tonight I make patch that sends whole expression under cursor to debugger.
If you often debug code like: getSth()->doSth you will like it ;)

I hope everything in patch is all right because it's bit late.

Here's my test code:
Code
struct A1
{
A1() : selfRef( *this )
{
alsoMe = this;
}

A1* selfPtr(int a, int b)
{
return this;
}

template<class T>
A1& memTemp( const T& t1, const T& t2 )
{
return *this;
}

static A1* alsoMe;

int someVeryLongInt;
A1& selfRef;
};
A1* A1::alsoMe = 0;

A1 giveAtPlease(int a, int b)
{
return A1();
}

int main()
{
A1 someVeryLongA1;
giveAtPlease( 4,   5 ) . selfRef  . someVeryLongInt;
A1 array[5];
array[2].selfPtr(4, 2) -> selfRef . someVeryLongInt;
A1::alsoMe -> selfRef. memTemp< float> (4, 5.1f).someVeryLongInt;
someVeryLongA1.memTemp< float> (4, 5.1f).someVeryLongInt;
array[4].selfPtr(2,2);
return 0;
}
As usual I look forward to feedback.
Title: Re: Evaluate whole expression under cursor
Post by: ollydbg on September 06, 2012, 03:22:38 am
Why not just select the expression, and press "CTRL"? (I have set the option: hover and press ctrl to show the value)
Title: Re: Evaluate whole expression under cursor
Post by: p2rkw on September 06, 2012, 10:52:36 am
Now c::b can select text for me :) When I debugging step by step I had to select almost every expression, it started annoying me,
especially when I have to select expression like: object.member every time. Consider that when you select to much (for instance: semicolon at end of line) debugger will not be able to evaluate selected text. For me it's faster to point single word than selecting everything.

Thanks for tip with CTRL, I don't know about this feature, finally I don't have to wait for tooltip ( maybe tooltip delay should be customizable? ;) ).

edit: I forgot  about main reason: when I hover 'member' in expression 'object.member' I want to see value of object.member not value of local variable named member.
Title: Re: Evaluate whole expression under cursor
Post by: oBFusCATed on September 06, 2012, 11:07:09 am
Comments:
1. This is not the right way to do this. Because parsing c/c++ is not an easy task and errors could lead to some bad result as crashing the debugger or putting it in a loop -> crashing c::b. You have to use the code completion. I think there was a patch samewhere doing it. But this requires changes to the sdk.
2. Use spaces not tabs
3. Post your patch on the patch tracker

... ( maybe tooltip delay should be customizable? ;) )...
It is but it is global for all tooltips.
Title: Re: Evaluate whole expression under cursor
Post by: ollydbg on September 06, 2012, 11:16:33 am
edit: I forgot  about main reason: when I hover 'member' in expression 'object.member' I want to see value of object.member not value of local variable named member.

So, if you hover on "object", you will show the value of "object", if you hover on "member", you will did a left search and show the value "object.member"? This sounds great, but as obF said, how did you do the "left search", it could be complex (contains a lot of expressions), and maybe will cause the gdb to crash. :)
Title: Re: Evaluate whole expression under cursor
Post by: MortenMacFly on September 06, 2012, 11:50:01 am
edit: I forgot  about main reason: when I hover 'member' in expression 'object.member' I want to see value of object.member not value of local variable named member.
In previous versions of C::B there was the possibility to save a debugger "watch script". This would allow you not to type this again and again, but just load the expressions you use often from the script (it is no problem if the one or other is not present in the currently debugged frame btw). But in fact I don't know if we still have that option... oBFusCATed?!
Title: Re: Evaluate whole expression under cursor
Post by: oBFusCATed on September 06, 2012, 11:59:12 am
I think this is not currently possible.
Title: Re: Evaluate whole expression under cursor
Post by: MortenMacFly on September 06, 2012, 12:46:34 pm
I think this is not currently possible.
So it got lost. But it maybe easy to re-implement. IIRC it was just two simple methods (I did it years ago...).
Title: Re: Evaluate whole expression under cursor
Post by: oBFusCATed on September 06, 2012, 01:08:54 pm
Yes, it won't be hard, but I'm not sure it will help to make it easier to check the value of expression quickly and easily.
Title: Re: Evaluate whole expression under cursor
Post by: MortenMacFly on September 06, 2012, 01:34:16 pm
but I'm not sure it will help to make it easier to check the value of expression quickly and easily.
No, the use-case is a different one: To save you from entering a lot of watches again and again across sessions. However, this is somewhat "related" to not having to enter long watch expressions again and again.
Title: Re: Evaluate whole expression under cursor
Post by: p2rkw on January 15, 2013, 10:29:59 pm
Maybe should CC have possibility to select expression under cursor?
Title: Re: Evaluate whole expression under cursor
Post by: oBFusCATed on January 15, 2013, 10:57:56 pm
Yes, but we need public api -> something like CCManager->GetFullExpressionAtCursor.
But first we need CCManager...  :P
Title: Re: Evaluate whole expression under cursor
Post by: Teybeo on January 27, 2013, 02:02:42 pm
Me too, I have problems having to manually select the expression I want to see the value.
Most of the time, it is to watch the value of a struct member, you have to select all its parents for it work.
There are also times when, doing it quickly, I slide the mouse to the end of line and then, the semi-column breaks the evaluation ><

So yeah, I would love to see a bit more of intelligence put in the under cursor evaluation functionality ;)
Title: Re: Evaluate whole expression under cursor
Post by: p2rkw on March 13, 2013, 09:33:38 pm
I had moved this code to CC, added menu item, assign key shortcut and make KeyMacks macro that select call chain under cursor and 'presses' CTRL. It works quite nice now.
Title: Re: Evaluate whole expression under cursor
Post by: oBFusCATed on March 14, 2013, 12:44:05 am
p2rkw: I've understood almost nothing.... can you try to explain better or even provide demo patch?