Page 1 of 1

pointer address of fn arg not updated in debugger

Posted: Thu Mar 07, 2013 1:50 am
by NetForce1
When the address of a pointer function argument is updated, this is fact not reflected in the debugger.
Code example:

Code: Select all

void test1(int *arg1)
{
    arg1 = 200;
    return;
}

int main(int argc, char **argv)
{
    int *p_var1 = (int *)malloc(sizeof(int));
    test1(p_var1);
    return 0;
}
When you step through this code, you'll see that the address of arg1 is not updated in the locals panel, or the debugger popup.

Re: pointer address of fn arg not updated in debugger

Posted: Thu Mar 07, 2013 9:36 am
by eranif
I tested your code with debugger log enabled (something that you should have done)

Here is gdb's output when inside main:

Code: Select all

DEBUG>>00000174^done,name="var3",numchild="1",value="0x2c1758",type="int *",thread-id="1",has_more="0"
DEBUG>>00000175-var-list-children "var3"
DEBUG>>00000175^done,numchild="1",children=[child={name="var3.*p_var1",exp="*p_var1",numchild="0",type="int",thread-id="1"}],has_more="0"
DEBUG>>00000176-var-evaluate-expression "var3.*p_var1"
and the output when quering it about arg1 inside the function:

Code: Select all

DEBUG>>00000189-var-create - @ "arg1"
DEBUG>>00000188^done,ndeleted="1"
DEBUG>>00000189^done,name="var5",numchild="1",value="0x2c1758",type="int *",thread-id="1",has_more="0"
DEBUG>>00000190-var-list-children "var5"
As you can see the problem is not within codelite (as it reports what gdb instructs it to)

If you want to assign a value, you need to do this:

Code: Select all

*arg1= 200
Or if you want to update the pointer (which I can't imagine why), you need to pass it as '**'

In anycase, this is not a codelite bug
Eran