Code::Blocks

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: ollydbg on July 09, 2010, 03:23:36 am

Title: Suggest on the debugger plugin
Post by: ollydbg on July 09, 2010, 03:23:36 am
I haven't tested the debugger branch. so, I'm sorry if it is already exist.

See the image below:
(http://i683.photobucket.com/albums/vv194/ollydbg_cb/2010-07-09091531.png)

Is it possible to show the EIP Pointer on the Disassembly windows, so that the user can understand which is the next instruction.

By the way, I'm debugging ptest project(in the CCbranch), i found that one wxString can not show correctly, see the image :
(http://i683.photobucket.com/albums/vv194/ollydbg_cb/2010-07-09090421.png)

It seems gdb can not show a empty wxString correctly. Any ideas?

thanks.
Title: Re: Suggest on the debugger plugin
Post by: ollydbg on July 09, 2010, 03:31:23 am
Things becomes more wired, see the screen shot, I just create another wxString ,but it seems only one wxString works fine...

(http://i683.photobucket.com/albums/vv194/ollydbg_cb/2010-07-09092540.png)

I don't know why, it is too strange...
Title: Re: Suggest on the debugger plugin
Post by: ollydbg on July 09, 2010, 04:16:53 am
I just check the DWARF information in the parserthread.o

by using:

Code: [Select]
objdump -W parserthread.o >> aaaa.txt
Then I have found that there are two entries for templateArgument in the debug information.

The source code is like:
Code: [Select]
wxString ParserThread::ReadAncestorList()
{


    wxString ccc;
    wxString templateArgument;
    wxString aaa;
    aaa = m_Tokenizer.GetToken(); // eat ":"
    templateArgument = aaa;
    while (!TestDestroy())
    {

        //Peek the next token
        wxString next = m_Tokenizer.PeekToken();

        if (next.IsEmpty()
            || next==ParserConsts::opbrace
            || next==ParserConsts::semicolon ) // here, we are at the end of ancestor list
        {
            break;
        }
        else if (next==ParserConsts::lt)       // class AAA : BBB < int, float >
        {
            wxString arg = SkipAngleBraces();
            if(!arg.IsEmpty())                 // find a matching <>
            {
                templateArgument<<arg;
            }
            else
            {
                TRACE(_T("Not Matching <> find. Error!!!") );
            }
        }

                //check the returned Token is a simple Macro usage
        wxString tmp = GetClassFromMacro(m_Tokenizer.GetToken());

        //Handle Current token first
        //Skip the public, protected and private keyword, we don't care them
        if (tmp==ParserConsts::kw_public
            ||tmp==ParserConsts::kw_protected
            ||tmp==ParserConsts::kw_private   )
        {
            continue;
        }
        else
        {
            templateArgument<<tmp;
        }

    }

    TRACE(_T("ReadAncestorList() : Ancestors: ") + templateArgument);
    return templateArgument;
}

Then you can see, there is only one entry for wxString aaa, but two entry for wxString templateArgument.



(http://i683.photobucket.com/albums/vv194/ollydbg_cb/2010-07-09100534.png)

Is it possible a bug in GCC?

I have just tested in TDM GCC 4.5 and Loaden GCC 4.4.4.

Both of them has bad information about "wxString templateArgument".

Any suggestions?

Thanks.


Edit:

It seems some thing related to "return variables", because when I use "aaa" as a return variable, then, the wxString aaa shows badly, at this time, the wxString templateArgument shows correctly.

see the image:
(http://i683.photobucket.com/albums/vv194/ollydbg_cb/2010-07-09104153.png)
Title: Re: Suggest on the debugger plugin
Post by: oBFusCATed on July 09, 2010, 09:14:47 am
I think, I've seen the marker of the EIP Pointer in the disassembly window, but I remember that others were complaining too.
Can you check the debuggers branch and report back?
Title: Re: Suggest on the debugger plugin
Post by: ollydbg on July 09, 2010, 11:02:31 am
I think, I've seen the marker of the EIP Pointer in the disassembly window, but I remember that others were complaining too.
Can you check the debuggers branch and report back?

I just tested, and there is not EIP pointer in debugger branch.
Title: Re: Suggest on the debugger plugin
Post by: oBFusCATed on July 09, 2010, 01:57:29 pm
OK, I'll look in to it tonight...
Do you see this behavior on simple hello world projects?
Title: Re: Suggest on the debugger plugin
Post by: ollydbg on July 09, 2010, 02:41:09 pm
OK, I'll look in to it tonight...
Do you see this behavior on simple hello world projects?
Yes, I tested on a simple hello world projects.
Title: Re: Suggest on the debugger plugin
Post by: jens on July 09, 2010, 03:54:31 pm
It works here on linux with a wxWidgets project without problems.
It might be an issue with the regexes that parse the gdb output (or a possibly different output on newer gdb).
I use gdb 7.1 for x86_64.
Output is:
Code: [Select]
> info frame
Stack level 0, frame at 0x7fffffffd5c0:
 rip = 0x410158 in SPS_LogFrame::OnAbout (/home/jens/src/src/SPS_LogMain.cpp:326); saved rip 0x4105a4
 called by frame at 0x7fffffffd5e0
 source language c++.
 Arglist at 0x7fffffffd5b0, args: this=0x6e0060
 Locals at 0x7fffffffd5b0, Previous frame's sp is 0x7fffffffd5c0
 Saved registers:
  rbx at 0x7fffffffd5a0, rbp at 0x7fffffffd5b0, r12 at 0x7fffffffd5a8, rip at 0x7fffffffd5b8
>>>>>>cb_gdb:
Title: Re: Suggest on the debugger plugin
Post by: oBFusCATed on July 09, 2010, 04:20:24 pm
Or it could be an gdb for windows issue.

Ollydbg: can you paste the output from "info frame"?
Title: Re: Suggest on the debugger plugin
Post by: ollydbg on July 09, 2010, 04:28:42 pm
Ok, I just tested in the cc_branch.

Code: [Select]
>>>>>>cb_gdb:
> info frame
Stack level 0, frame at 0x22ff60:
 eip = 0x4013ce in main (E:\code\cb\codeblocks_test_code\forLoaden\main.cpp:6); saved eip 0x4010db
 source language c++.
 Arglist at 0x22ff58, args:
 Locals at 0x22ff58, Previous frame's sp is 0x22ff60
 Saved registers:
  ebp at 0x22ff58, eip at 0x22ff5c
>>>>>>cb_gdb:

So, it seems the eip value is correctly returned from gdb. But when I opened the Disassembly window, there is no "arrow" showing.

Sorry I don't have debugger_branch at home now.
Title: Re: Suggest on the debugger plugin
Post by: ollydbg on July 09, 2010, 04:35:35 pm
Hi, it seems there is a "=>" arrow in the debugger log. but this is not shown in the Disassemble window. See the image below:

(http://i683.photobucket.com/albums/vv194/ollydbg_cb/2010-07-09223056.png)
Title: Re: Suggest on the debugger plugin
Post by: oBFusCATed on July 09, 2010, 11:33:38 pm
Ollydbg: You'll have to debug this issue yourself. Please set breakpoints at the callers of SetActiveAddress() and investigate what is going wrong.
On my machine it works, unfortunately, and I can't test it on windows at the moment.

p.s. the => is not parsed and used...
p.p.s. tested on debuggers branch and with trunk on linux 64bit
p.p.p.s. you could test it with older gdb's 6.8 for example.
Title: Re: Suggest on the debugger plugin
Post by: ollydbg on July 10, 2010, 12:57:00 pm
Ollydbg: You'll have to debug this issue yourself. Please set breakpoints at the callers of SetActiveAddress() and investigate what is going wrong.
On my machine it works, unfortunately, and I can't test it on windows at the moment.

p.s. the => is not parsed and used...
p.p.s. tested on debuggers branch and with trunk on linux 64bit
p.p.p.s. you could test it with older gdb's 6.8 for example.

I just set a breakpoint in the first line of SetActiveAddress function, and found that this breakpoint never be hit. not sure what's the problem is. (I'm use the latest mingw cvs gdb 20100708, Loaden MinGW GCC 4.4.4, ccbranch).

By the way, it is quite cool to debug cb in cb.

That is CB->gdb->CB->gdb->test hello world app. (The arrow " ->" means function call) :D
Title: Re: Suggest on the debugger plugin
Post by: oBFusCATed on July 10, 2010, 10:58:05 pm
I just set a breakpoint in the first line of SetActiveAddress function, and found that this breakpoint never be hit

It is obvious that the breakpoint won't be hit. Set breakpoints around lines which call the SetActiveAddress() function. Most probably the regexes don't match as Jens suggested.
Have you tested the old gdbs?
Title: Re: Suggest on the debugger plugin
Post by: ollydbg on July 11, 2010, 03:47:12 am
Have you tested the old gdbs?
Ok, I have download an old gdb, which is: Release Candidate_ GDB 6.8-3 (http://sourceforge.net/projects/mingw/files/MinGW/BaseSystem/GDB/Release%20Candidate_%20GDB%206.8-3/), but it is the same result as the new gdb 7.2.50 cvs.

There is no "EIP instruction arrow" appeared in the Disassembly windows either.
Quote
It is obvious that the breakpoint won't be hit. Set breakpoints around lines which call the SetActiveAddress() function. Most probably the regexes don't match as Jens suggested.
I will do more test if I have time. Thanks for the help.
Title: Re: Suggest on the debugger plugin
Post by: ollydbg on July 11, 2010, 05:42:02 am
I have several problem when debugging debugger plugin.
1, it seems I can't set breakpoint.
See the log:
Quote
> break "E:/code/cb/cc_branch/src/plugins/debuggergdb/disassemblydlg.cpp:139"
No source file named E:/code/cb/cc_branch/src/plugins/debuggergdb/disassemblydlg.cpp.
Breakpoint 6 ("E:/code/cb/cc_branch/src/plugins/debuggergdb/disassemblydlg.cpp:139) pending.
>>>>>>cb_gdb:
> break "E:/code/cb/cc_branch/src/plugins/debuggergdb/debuggergdb.cpp:2852"
Breakpoint 7 at 0x6d895b46: file E:\code\cb\cc_branch\src\plugins\debuggergdb\debuggergdb.cpp, line 2852.
>>>>>>cb_gdb:

The line 139 in disassemblydlg.cpp is in the function body of:
Code: [Select]
void DisassemblyDlg::SetActiveAddress(unsigned long int addr)
{
    if (m_HasActiveAddr && addr == m_LastActiveAddr)
        return;
    m_HasActiveAddr = false;
    m_LastActiveAddr = addr;
    for (int i = 0; i < m_pCode->GetLineCount(); ++i)
    {
        wxString str = m_pCode->GetLine(i).AfterFirst(_T('x')).BeforeFirst(_T('\t'));
        unsigned long int lineaddr;
        if (str.ToULong(&lineaddr, 16) && lineaddr >= addr)  ////////////////////// this is line 139
        {
            m_pCode->MarkerDeleteAll(DEBUG_MARKER);
            m_pCode->MarkerAdd(i, DEBUG_MARKER);
            m_pCode->GotoLine(i);
            m_pCode->EnsureVisible(i);
            m_HasActiveAddr = true;
            break;
        }
    }
}

But it seems I can set a breakpoint in debuggergdb.cpp.

The other problem is: call stack information is not shown correctly.
see the image:
(http://i683.photobucket.com/albums/vv194/ollydbg_cb/2010-07-11112446.png)

The third issue is: it seems I can't view the value in this function:
Code: [Select]
wxString str = m_pCode->GetLine(i).AfterFirst(_T('x')).BeforeFirst(_T('\t'));
Here is the debugger log:
Quote
> p str
$2 = UnicodeEncodeError: 'gbk' codec can't encode character u'\ufeee' in position 0: illegal multibyte sequence
>>>>>>cb_gdb:
So, I still suspect that there are "two debug entries" for the autovariable "str", so gdb get confused.

BTW: I'm using TDM4.5 at home, with gdb cvs 0708.

It seems I need to use an old compiler like: gcc 4.4.1 or gcc 4.4.3??
Title: Re: Suggest on the debugger plugin
Post by: oBFusCATed on September 14, 2010, 09:32:19 pm
ollydbg: do you still experience this problem?
Title: Re: Suggest on the debugger plugin
Post by: ollydbg on September 15, 2010, 01:48:27 am
ollydbg: do you still experience this problem?
Ok, I will try it if I have time, which version should I test? the latest debugger_branch?

(currently, I'm mostly focus on cc_branch, and there are still crash problem on cc_branch :(), but the crash seldomly happened).


Title: Re: Suggest on the debugger plugin
Post by: oBFusCATed on September 15, 2010, 08:43:09 am
I'm talking about the disassembly problem...
Title: Re: Suggest on the debugger plugin
Post by: ollydbg on September 15, 2010, 10:35:33 am
I'm talking about the disassembly problem...
OK, I just test the latest debugger_branch, and the dis-assembly problem still exist. There is no arrow in the dis-assembly window.

I use TDM 4.5.1 and unofficial GDB 7.2 released myself.

Title: Re: Suggest on the debugger plugin
Post by: oBFusCATed on September 15, 2010, 10:52:02 am
Does this happen for simple hello world project?
Title: Re: Suggest on the debugger plugin
Post by: ollydbg on September 15, 2010, 11:11:27 am
Does this happen for simple hello world project?

Yes, much simpler than "hello world project",

see:

Code: [Select]
int main()
{
    int a =1;
    a ++;
    a =3;

}
:D
Title: Re: Suggest on the debugger plugin
Post by: oBFusCATed on September 15, 2010, 01:16:15 pm
OK, I hope I'll find some time to test with your versions of gcc/gdb
Title: Re: Suggest on the debugger plugin
Post by: cbexaminr on September 18, 2010, 05:26:06 am
possible difference in wxwidgets msw/*nix wxString::Printf("%p")?

Note that OllyDbg's disassembly lines have (instruction line location) hex addresses without leading 'x' or 0x.  (As do mine.)

The routine void cbDisassemblyDlg::AddAssemblerLine(unsigned long int addr, const wxString& line)
contains lines:
    wxString fmt;
    fmt.Printf(_T("%p\t%s\n"), (void*)addr, line.c_str());
    m_pCode->AppendText(fmt);

The routine (just beneath previous one) void cbDisassemblyDlg::SetActiveAddress(unsigned long int addr)
contains lines:
        wxString str = m_pCode->GetLine(i).AfterFirst(_T('x')).BeforeFirst(_T('\t'));
        unsigned long int lineaddr;
        if (str.ToULong(&lineaddr, 16) && lineaddr >= addr)

When I traced, it appeared that 'str' was either empty, or returning some random portion of the instruction line.

I'm guessing the *nix disassembly does have an 'x' immediately preceding the disassembly addresses resulting from %p, while the MSW disassembly (at least mine and OllyDbg's) does not have any such 'x'...???
Title: Re: Suggest on the debugger plugin
Post by: oBFusCATed on September 19, 2010, 09:36:44 pm
cbexaminr: versions of gcc and gdb?
Title: Re: Suggest on the debugger plugin
Post by: cbexaminr on September 20, 2010, 11:07:05 am
gcc (TDM-2 mingw32) 4.4.1
-from codelite ....4189.... version installation

GDB gnu (GDB) 7.1
-a)from  codelite ...4189... version installation
-b)locally built
(have used both GDB's)

[edit]
And ollydbg  reported several posts above:
"I use TDM 4.5.1 and unofficial GDB 7.2 released myself." - ollydbg
Title: Re: Suggest on the debugger plugin
Post by: oBFusCATed on September 20, 2010, 12:18:05 pm
I know, I was collecting more data :)

I'll try it tonight
Title: Re: Suggest on the debugger plugin
Post by: oBFusCATed on September 20, 2010, 11:45:33 pm
Please test the latest patch: http://forums.codeblocks.org/index.php/topic,10908.msg89814.html#msg89814
The bug should be fixed. At least for me it is (gdb 7.1.50.xxxxx, gcc 4.4.1 tdm or something like that, windows xp sp3 32bit)
Title: Re: Suggest on the debugger plugin
Post by: ollydbg on September 21, 2010, 01:59:28 am
Please test the latest patch: http://forums.codeblocks.org/index.php/topic,10908.msg89814.html#msg89814
The bug should be fixed. At least for me it is (gdb 7.1.50.xxxxx, gcc 4.4.1 tdm or something like that, windows xp sp3 32bit)

Hi, obf, I have just test your patch(TDM 4.5.1 and unofficial GDB 7.2 released myself), and confirm the fix, thank you very much!!!!