Author Topic: DDD-like watches  (Read 26919 times)

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: DDD-like watches
« Reply #15 on: January 11, 2006, 10:21:53 am »
Quote from: lord mandrav
I see no reason for graphical gizmos in a debugger. Really, what do you need that for?

It isn't a need, I just like to "visualize" things better, and it seems I'mn't alone :)

No you are not alone :). I think it is important (at least for me :)) to provide a clear, easy-to-understand, scalable view of the debugger info.

(Code::Blocks 7.0 maybe?) :)

C::B 7.0? :D

Michael

Offline m.29

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: DDD-like watches
« Reply #16 on: January 22, 2011, 01:36:31 pm »
Hi, I'm opening this old topic because I would like to implement some functionality of DDD to Code::Blocks. As I noticed, new features to debugger are added by editing the code in plugins/debuggergdb/ directory. But I try add new functionality by pure new plugin. This is my test code:
Code: [Select]
void DDDLikeWatches::OnAttach()
{
    cbDebuggerPlugin *debugger = reinterpret_cast<cbDebuggerPlugin *>(
      Manager::Get()->GetPluginManager()->FindPluginByName(wxT("Debugger"))
    );
    DebuggerGDB *gdb = reinterpret_cast<DebuggerGDB *>(debugger);
    DebuggerDriver *driver = gdb->GetState().GetDriver();
}
When I try compile this, I get undefined reference to `DebuggerState::GetDriver()'. My question is: Where is the problem? Can I access debugger's functions from debugger.dll from other plugin or must modify original debugger plugin's code to add this functionality to debugger? I link debugger.dll to my project.

Windows XP SP3, wxWidgets 2.8.11, C::B DEBUGGER BRANCH nightly builds

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9508
Re: DDD-like watches
« Reply #17 on: January 22, 2011, 02:35:26 pm »
Where is the problem? Can I access debugger's functions from debugger.dll from other plugin or must modify original debugger plugin's code to add this functionality to debugger? I link debugger.dll to my project.
You should link against the SDK, not the plugin. BTW: If you are working on the debugger, make sure you are using the debugger branch as:
1.) Your features might already have been implemented there
2.) We will sooner or later switch to this branch, so your changes to trunk might be very hard to integrate later.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline m.29

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: DDD-like watches
« Reply #18 on: January 22, 2011, 10:33:41 pm »
Thanks for your reply. I'm linking against SDK too (codeblocks.dll).
1.) Feature that I try implement is Graphical Inspection of Data Structures and viewing them like oriented graphs. This feature isn't implemented there.
2.) As I noticed in SVN:
Quote
debugger_branch: merged with trunk (trunk to debugger_branch)
So I use trunk.

Because, I don't know how to link debugger's functions, I'll try edit original sources to add this functionality.
Windows XP SP3, wxWidgets 2.8.11, C::B DEBUGGER BRANCH nightly builds

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9508
Re: DDD-like watches
« Reply #19 on: January 22, 2011, 10:50:16 pm »
2.) As I noticed in SVN:
Quote
debugger_branch: merged with trunk (trunk to debugger_branch)
So I use trunk.
Please read carefully, it's written there: trunk to debugger_branch. Thus, features implemented in trunk not yet in the debugger branch have been merged. Still it will always be as : debugger branch = trunk + debugger related modifications. Thats what the branch is for, it has a way different (re-factored) implementation of th debugger.
Once the debugger branch comes merged into trunk, there won't be a need for this branch anymore and it'll be closed. For now, all debugger related development is there and only there.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12125
    • Travis build status
Re: DDD-like watches
« Reply #20 on: January 22, 2011, 11:36:39 pm »
m.29:
Probably you need to modify the sdk and put most of the drawing code and data structures there.
If you do so all plugins can implement this graphical mode, not only the current one and there will be minimal code duplication.
See how it is done for the other features (watches, breakpoints, etc).
(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 m.29

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: DDD-like watches
« Reply #21 on: March 03, 2011, 03:31:52 pm »
Thanks for your replies and sorry for my inattention. I use debugger_branch (/branches/wxpropgrid_debugger/) now.

I'm still implementing this feature to C::B and have one question. I try to add functionality that after double click on pointer element in structure dereferences pointer and join nodes of graph by edge. Here is relevant part of my event handler for that:
Code: [Select]
cbDebuggerPlugin* debugger = Manager::Get()->GetDebuggerManager()->GetActiveDebugger();
wxString watchString; watch->GetFullWatchString(watchString);

watch = debugger->AddWatch(wxT("(*") + watchString + wxT(')'));
if(!watch) { return; }

ViewNode* node = new ViewNode(
    this->GetParent(),
    watch,
    this->GetPosition() + wxPoint(this->GetSize().GetWidth() + 20, 0)  // TODO (m.29##): automatic graph layouts
);
this->GetParent()->AddChild(node);
ViewNode::JoinNodes(this, node);
But in ViewNode's constructor I get uninitialized watch (e.g. watch->GetChildCount() == 0 if watch is structure type). I know it is because watch is parsed in parallel to my code. I don't know how to wait for end of parsing. Or how can I find out that watch was parsed yet? I tried find answer in C::B codes but it seems nothing special is done after calling cbDebuggerPlugin::AddWatch() there.  
Windows XP SP3, wxWidgets 2.8.11, C::B DEBUGGER BRANCH nightly builds

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12125
    • Travis build status
Re: DDD-like watches
« Reply #22 on: March 03, 2011, 03:46:31 pm »
When watches are updated WatchesDlg::UpdateWatches() is called
(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 m.29

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: DDD-like watches
« Reply #23 on: March 14, 2011, 10:06:38 pm »
Thanks, it helps. I'm implementing "index out of bounds" checking now. I noticed some things during exploring C::B sources:

1) Function ParseCDBWatchValue has some strange (for me) condition
Code: [Select]
if (tokens[0] == wxT("class") || tokens[0] == wxT("class"))I think it should be
Code: [Select]
if (tokens[0] == wxT("struct") || tokens[0] == wxT("class")) as it is a few rows below.

2) I edited GDBWatch::GetFullWatchString function 'cause for arrays it always gave me ArrayName.[index].

3) Because I would like to check indexing out of bounds I added size to array watches in GdbCmd_Watch class.

4) In GdbCmd_FindWatchType class there was "whatis &" instead of "whatis " string used to finding type of watch and then tmp.substr(0, tmp.length() - 1); used to removing last "*". But this was bad for arrays or functions:
  • int (*)[4] -> int (*)[4
  • int (*)(int) -> int (*)(int
  • ...

I made the patch for this things, but if I done something wrong someone explain me what and why, please.
Windows XP SP3, wxWidgets 2.8.11, C::B DEBUGGER BRANCH nightly builds

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12125
    • Travis build status
Re: DDD-like watches
« Reply #24 on: March 14, 2011, 10:52:07 pm »
1. Have you tried it with real CDB and can you provide a test case (see debuggergdb_test_parser.cpp)
2. This seems unused in current code, so it was not tested
3. SetArray and SetArrayParams are called by the GUI, so set the properties of the watch, then this properties are used to execute the correct commands.
    So your usage is wrong, because you'll override the choice made by the user (probably you need to add more members).
    Also GetFullWatchString should not call contains, but use some member to check if the symbol is array.
4. This is a workaround for a problem in GDB -> "const wxString &" passed as parameter was not watchable...

But the main problem is that I don't get the whole picture, why you need this changes.
'index out of bounds checking' means nothing to me.
Can you explain in more details, please?

(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 m.29

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: DDD-like watches
« Reply #25 on: March 15, 2011, 03:22:45 pm »
1) I didn't test it, but that condition is really weird. Why there is test for the same thing twice? Here is the test case:
Code: [Select]
TEST(CDBSingleLineStructPointer)
{
    GDBWatch w(wxT("t"));
    CHECK(ParseCDBWatchValue(w, wxT("struct t * 0x123456"));
    CHECK_EQUAL(wxT("t*=0x123456"), w);
}

TEST(CDBSingleLineClassPointer)
{
    GDBWatch w(wxT("t"));
    CHECK(ParseCDBWatchValue(w, wxT("class t * 0x123456"));
    CHECK_EQUAL(wxT("t*=0x123456"), w);
}

2) In my code there is functionality that dereferences pointer on double click on variable. There is array of structures
Code: [Select]
struct s {
  payload_t payload;
  struct s* next;
} item1, item2, ...;

struct s array[] = {
  item1,
  item2,
  ...
};
Then I try dereference pointer next in structure on index 0 I get (*array.[0].next) instead of (*array[0].next). This expression is not valid and gdb can't return right result.

3) I don't override user's choice because there is a condition that allows set parameters only 1st time. If my code overrides user's choice there is watch->SetArray(true); what also overrides user's choice. But no. As I tested if I change properties of watch everything stay set according to my new choice. Only if watch format is Undefined and it is array with size (int array[29];) but GDBWatch::IsArray returns false everything is set to default. I hope it is  understandable - my English and speech aren't good :-(
I changed GDBWatch::GetFullWatchString into test if parent is array - hope it's OK now.

4) For me it is good. Can you provide some example when it is not watchable? Or it is issue of any specific platform?

I graphical representation of watches programmer can see actual indexed item of array in bold. My idea is, if i know index and size of array I can check if index is not bigger than size of array. Then C::B warns programmer about it. There is some complications now and I want to do on automatic graph layout of oriented graphs so I return to this later, but I think is not good if size of array will be available anyway.

In my code, there is many changes, but these seem to be bugs and useful changes that affect functionality of C::B. But I want to find out if some of them is not intention (like "whatis &" issue) because there is no explanation in comments. That's why I put them here.
« Last Edit: March 15, 2011, 03:25:42 pm by m.29 »
Windows XP SP3, wxWidgets 2.8.11, C::B DEBUGGER BRANCH nightly builds

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12125
    • Travis build status
Re: DDD-like watches
« Reply #26 on: March 15, 2011, 03:35:35 pm »
Can you provide a complete patch of your progress?
Probably we can integrate some parts of it already.
The least we can do is to stop you from doing wrong things/designs at the beginning...

p.s. I'll answer to you questions in tonight, no time now.
(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 m.29

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: DDD-like watches
« Reply #27 on: March 15, 2011, 10:52:02 pm »
Hmm, I  don't want to provide my complete work, because it is my school project and I don't know if I won't violate some of school rules. But I'll ask my supervisor if it will be problem. I certainly want to provide my work after my project will be finished.
Windows XP SP3, wxWidgets 2.8.11, C::B DEBUGGER BRANCH nightly builds

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12125
    • Travis build status
Re: DDD-like watches
« Reply #28 on: March 15, 2011, 11:24:01 pm »
Reply to the previous post:

1. Not a real test, run it through CDB or you should wait for me find time to run it myself.  :lol:
2. Looks good :) (except for the scrollbars), but auto dereferencing in current plugin is hard (many special cases will be broken)
3. If it works, OK, I'll give it a try...
4. Debugging C::B under linux. With older gdb's this was a problem. Probably I should remove the hack and see if it works correctly, with 7.2+ ...

This index out of bounds is pretty much uses, because most of the time (in real world code) you get bare pointers not arrays. If I were you I wouldn't bother with this feature too much, because it has very little value.

p.s. Please test you patch on a modern linux machine (64bit if possible). The sooner you do it the better :)
p.p.s. You can send me the patch on e-mail, so it will stay private, but you'll get some feedback on it.
(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 m.29

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: DDD-like watches
« Reply #29 on: March 17, 2011, 02:31:49 pm »
1) I don't like waiting and I did some test. Here is relevant screen. As you can see from log, structure type would be HWND__* and value 0x0000000. But it is wrong in the watches window. For similar class is everything fine.

2) Auto derefencing isn't my aim so far. Only user dereferences pointers by double click. I don't how to hide scrollbars and set size of wxTreeCtrl according to visible children :-( I want concentrate on functionality so I lay aside by now but I'm asking in the appropriate forum for it.

4) Yes, I try it on Linux with gdb 7.1 and it really doesn't work. But with some RE it would be correct on function and array. I try something.

But I plan to add functionality that allows assign variable to array. Variable that store the array size. If there is realloc in program, it would be good to assign variable storing the size of array and this array will have correct size whole time. Now I must every time change size in context menu according to new reallocated size. In my school C::B is used as additional teaching aid and this could be good for beginners but not only for them.

I tried my patch on Ubuntu 10.04 LTS (64bit) but it crashed down. Even clean svn checkout. I only open codeblocks-unix project, compile and after ./update run. Code::Blocks crashed immediately. I'll try find out why.

My supervisor allows me to publish sources so after some changes I can provide it. Thanks for your help :-)
« Last Edit: March 17, 2011, 02:34:04 pm by m.29 »
Windows XP SP3, wxWidgets 2.8.11, C::B DEBUGGER BRANCH nightly builds