News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Evaluate whole expression under cursor

Started by p2rkw, September 06, 2012, 03:10:23 AM

Previous topic - Next topic

p2rkw

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:

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.

ollydbg

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.

p2rkw

#2
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.

oBFusCATed

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

Quote from: p2rkw on September 06, 2012, 10:52:36 AM
... ( 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!]

ollydbg

Quote from: p2rkw on September 06, 2012, 10:52:36 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.

MortenMacFly

Quote from: p2rkw on September 06, 2012, 10:52:36 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

oBFusCATed

(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!]

MortenMacFly

Quote from: oBFusCATed on September 06, 2012, 11:59:12 AM
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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

oBFusCATed

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!]

MortenMacFly

Quote from: oBFusCATed on September 06, 2012, 01:08:54 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

p2rkw

#10
Maybe should CC have possibility to select expression under cursor?

oBFusCATed

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!]

Teybeo

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 ;)

p2rkw

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.

oBFusCATed

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!]