This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: "info locals" -- is variable initialized
Ramana Radhakrishnan wrote:
>
>>
>> When entering this function, KDevelop asks gdb via "info locals" what
>> locals vars are there. But, gdb reports all variables, even though at the
>> function entry 'i2' is not initialized (or, from C++ point of view, not
>> even visible yet). For pretty priting 'i2', I have to evaluate
>> 'i2.prettyURL(0)', which will just crash. I can use "set unwindonsignal
>> on", but generally, calling methods on uninitialized object can damage
>> random memory.
>
> GDB puts a breakpoint after the prologue of a function. Which means that
> all locals in scope have been created / allocated space for . Hence you
> would see i2 , right ?
Wrong, I think. Function progolue only allocates space for KURL, but does
not call the constructor.
Consider:
int main()
{
int i = 10;
std::vector<int> v2;
KURL url = "http://boost.org";
}
And assembler of it:
0x080487f4 <main+0>: push %ebp
0x080487f5 <main+1>: mov %esp,%ebp
0x080487f7 <main+3>: push %ebx
0x080487f8 <main+4>: sub $0x84,%esp
0x080487fe <main+10>: and $0xfffffff0,%esp
0x08048801 <main+13>: mov $0x0,%eax
0x08048806 <main+18>: sub %eax,%esp
<gdb sets breakpoint on the following instruction>
0x08048808 <main+20>: movl $0xa,0xfffffff4(%ebp)
<initialization of vector starts here>
0x0804880f <main+27>: lea 0xffffffc8(%ebp),%eax
0x08048812 <main+30>: mov %eax,(%esp)
0x08048815 <main+33>: call 0x8048924 <allocator>
0x0804881a <main+38>: lea 0xffffffc8(%ebp),%eax
0x0804881d <main+41>: mov %eax,0x4(%esp)
0x08048821 <main+45>: lea 0xffffffd8(%ebp),%eax
0x08048824 <main+48>: mov %eax,(%esp)
0x08048827 <main+51>: call 0x80489a0 <vector>
...........
and only here std::vector is initialized.
So, there's a window there variable does not exists according to C++, but
exists according to gdb.
- Volodya