Author Topic: Evaluate whole expression under cursor  (Read 19908 times)

Offline p2rkw

  • Almost regular
  • **
  • Posts: 142
Evaluate whole expression under cursor
« 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.
« Last Edit: March 13, 2013, 09:27:08 pm by p2rkw »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Evaluate whole expression under cursor
« Reply #1 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)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline p2rkw

  • Almost regular
  • **
  • Posts: 142
Re: Evaluate whole expression under cursor
« Reply #2 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.
« Last Edit: September 06, 2012, 11:07:20 am by p2rkw »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Evaluate whole expression under cursor
« Reply #3 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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Evaluate whole expression under cursor
« Reply #4 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. :)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Evaluate whole expression under cursor
« Reply #5 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?!
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Evaluate whole expression under cursor
« Reply #6 on: September 06, 2012, 11:59:12 am »
I think this is not currently possible.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Evaluate whole expression under cursor
« Reply #7 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...).
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Evaluate whole expression under cursor
« Reply #8 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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Evaluate whole expression under cursor
« Reply #9 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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline p2rkw

  • Almost regular
  • **
  • Posts: 142
Re: Evaluate whole expression under cursor
« Reply #10 on: January 15, 2013, 10:29:59 pm »
Maybe should CC have possibility to select expression under cursor?
« Last Edit: January 15, 2013, 10:34:34 pm by p2rkw »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Evaluate whole expression under cursor
« Reply #11 on: January 15, 2013, 10:57:56 pm »
Yes, but we need public api -> something like CCManager->GetFullExpressionAtCursor.
But first we need CCManager...  :P
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Teybeo

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: Evaluate whole expression under cursor
« Reply #12 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 ;)

Offline p2rkw

  • Almost regular
  • **
  • Posts: 142
Re: Evaluate whole expression under cursor
« Reply #13 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Evaluate whole expression under cursor
« Reply #14 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?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]