Skip to content

gdb freezes using cmd -var-list-children on unitialized std::vector #40

@AHeimberger

Description

@AHeimberger

gdb/mi freezes with pretty/printers enabled when a user access a not initialized vector. gdb/mi not directly freezes, but walks through all the memory it can access, as long as is doesn't access a not exisiting memory (segsev). for the user gdb/mi looks frozen because the size of the vector can be of different sizes (YMMS). This errors comes from calculating the size of the std::vector, which is calculated from vec._M_impl._M_finish - vec._M_impl._M_start. Size of the vector is not calculable, when the vector is not initialized.

Reported-Bug : http://sourceware.org/bugzilla/show_bug.cgi?id=14373

This issue gives an impression of this known but not avoidable bug under current versions:

  • Linux version 3.2.0-23-generic (buildd@crested)
  • GNU gdb (Ubuntu/Linaro 7.4-2012.02-0ubuntu2) 7.4-2012.02
  • gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
Install Pretty Printers:
  1. Download STL-Pretty-Printer http://sourceware.org/gdb/wiki/STLSupport
  2. Create a .gdbinit file, explained at http://sourceware.org/gdb/wiki/STLSupport
Create a Testprogram called main.cpp:
#include <vector>

int main() {
    std::vector<int> vec;

    vec.push_back(1);
    vec.push_back(1);
    vec.push_back(1);
    vec.push_back(1);
    vec.push_back(1);
    vec.push_back(1);
    vec.push_back(1);

    return 0;
}
Create the Objectfile:

g++ -g main.cpp -o main.o

Start GDB/MI:

gdb -i mi main.o

Execute following CMD's and GDB-Freezes:

-enable-pretty-printing
-break-insert main
-exec-run
-stack-list-variables --all-values
-var-create - * vec
-var-list-children var1

Execute following CMD's and GDB doesn't freeze but shows non existing values:

-enable-pretty-printing
-break-insert main
-exec-run
-stack-list-variables --all-values
-var-create - * vec
-var-list-children var1 0 10
^done,numchild="10",displayhint="array",children=[child={name="var2.[0]",exp="[0]",numchild="0",type="int",thread-id="1"},child={name="var2.[1]",exp="[1]",numchild="0",type="int",thread-id="1"},child={name="var2.[2]",exp="[2]",numchild="0",type="int",thread-id="1"},child={name="var2.[3]",exp="[3]",numchild="0",type="int",thread-id="1"},child={name="var2.[4]",exp="[4]",numchild="0",type="int",thread-id="1"},child={name="var2.[5]",exp="[5]",numchild="0",type="int",thread-id="1"},child={name="var2.[6]",exp="[6]",numchild="0",type="int",thread-id="1"},child={name="var2.[7]",exp="[7]",numchild="0",type="int",thread-id="1"},child={name="var2.[8]",exp="[8]",numchild="0",type="int",thread-id="1"},child={name="var2.[9]",exp="[9]",numchild="0",type="int",thread-id="1"}],has_more="1"

Further CMD's

Use these commands to evaluate that your pretty-printers are really enabled or disabled.
disable pretty-printer
enable pretty-printer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions