Menu

Segfault when using std::map (and pair)

Help
2004-09-17
2004-09-18
  • Nobody/Anonymous

    When following the example of using map I get a segfault in my own code:

    using std::map;
    using std::pair;
    using std::less;
    using pooled_allocator::Pool_alloc;

    extern const char key[] = "/proc.key";
    extern const char address[] = "0x400D0000";

    typedef Pool_alloc<pair<pid_t, void*>, key, address> shm_alloc;
    typedef map<pid_t, void*, less<const pid_t>, shm_alloc> shm_map;

    ..

    shm_map table;
    pair<pid_t, void*> entry (getpid (), some_object);

    table.insert (entry);

    ...

    When I execute the program (no problems compiling) I get a segv:

    [Thread debugging using libthread_db enabled]
    [New Thread -151108960 (LWP 6809)]

    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread -151108960 (LWP 6809)]
    _______________________________________________________________________________
         eax:00000004 ebx:FEE90420  ecx:00000000  edx:FEE90264     eflags:00210286
         esi:00000000 edi:00879D00  esp:FEE8FFC0  ebp:FEE90028     eip:0805921C
         cs:0073  ds:007B  es:007B  fs:0000  gs:0033  ss:007B    o d I t S z a P c
    [007B:FEE8FFC0]---------------------------------------------------------[stack]
    FEE8FFF0 : DC FF C7 00  BC 03 06 08 - 00 00 00 00  00 9D 87 00 ................
    FEE8FFE0 : C0 02 E9 FE  8C C4 0A 08 - 10 00 E9 FE  30 9E 04 08 ............0...
    FEE8FFD0 : 60 02 E9 FE  4C C2 D2 00 - 28 00 E9 FE  7B C1 CF 00 `...L...(...{...
    FEE8FFC0 : 00 00 E9 FE  4C C2 D2 00 - 18 00 E9 FE  7B C1 CF 00 ....L.......{...
    [007B:FEE8FFC0]---------------------------------------------------------[ data]
    FEE8FFC0 : 00 00 E9 FE  4C C2 D2 00 - 18 00 E9 FE  7B C1 CF 00 ....L.......{...
    FEE8FFD0 : 60 02 E9 FE  4C C2 D2 00 - 28 00 E9 FE  7B C1 CF 00 `...L...(...{...
    [0073:0805921C]---------------------------------------------------------[ code]
    0x805921c <_ZNSt8_Rb_treeISsSt4pairIKSsS0_IPv4statEESt10_Select1stIS5_ESt4lessISsESaIS5_EE13insert_uniqueERKS5_+28>:   
        mov    (%eax),%eax
    0x805921e <_ZNSt8_Rb_treeISsSt4pairIKSsS0_IPv4statEESt10_Select1stIS5_ESt4lessISsESaIS5_EE13insert_uniqueERKS5_+30>:   
        mov    %eax,0xfffffff0(%ebp)
    0x8059221 <_ZNSt8_Rb_treeISsSt4pairIKSsS0_IPv4statEESt10_Select1stIS5_ESt4lessISsESaIS5_EE13insert_uniqueERKS5_+33>:   
        movb   $0x1,0xffffffef(%ebp)
    0x8059225 <_ZNSt8_Rb_treeISsSt4pairIKSsS0_IPv4statEESt10_Select1stIS5_ESt4lessISsESaIS5_EE13insert_uniqueERKS5_+37>:   
        cmpl   $0x0,0xfffffff0(%ebp)
    0x8059229 <_ZNSt8_Rb_treeISsSt4pairIKSsS0_IPv4statEESt10_Select1stIS5_ESt4lessISsESaIS5_EE13insert_uniqueERKS5_+41>:   
        jne    0x805922d <_ZNSt8_Rb_treeISsSt4pairIKSsS0_IPv4statEESt10_Select1stIS5_ESt4lessISsESaIS5_EE13insert_uniqueERKS5_+45>
    0x805922b <_ZNSt8_Rb_treeISsSt4pairIKSsS0_IPv4statEESt10_Select1stIS5_ESt4lessISsESaIS5_EE13insert_uniqueERKS5_+43>:   
        jmp    0x805929d <_ZNSt8_Rb_treeISsSt4pairIKSsS0_IPv4statEESt10_Select1stIS5_ESt4lessISsESaIS5_EE13insert_uniqueERKS5_+157>
    ------------------------------------------------------------------------------
    0x0805921c in std::_Rb_tree<std::string, std::pair<std::string const, std::pair<void*, stat> >, std::_Select1st<std::pair<std::string const, std::pair<void*, stat> > >, std::less<std::string>, std::allocator<std::pair<std::string const, std::pair<void*, stat> > > >::insert_unique (this=0x8060b00, __v=@0xfee902c0) at stl_tree.h:1037
    1037          _Link_type __x = _M_root();
    gdb> bt
    #0  0x0805921c in std::_Rb_tree<std::string, std::pair<std::string const, std::pair<void*, stat> >, std::_Select1st<std::pair<std::string const, std::pair<void*, stat> > >, std::less<std::string>, std::allocator<std::pair<std::string const, std::pair<void*, stat> > > >::insert_unique (this=0x8060b00, __v=@0xfee902c0) at stl_tree.h:1037
    #1  0x080570a7 in std::map<std::string, std::pair<void*, stat>, std::less<std::string>, std::allocator<std::pair<std::string const, std::pair<void*, stat> > > >::insert (this=0x8060b00, __x=@0xfee902c0) at stl_map.h:340
    #2  0x08055ac9 in mem_space::shared<&(key), &(address)>::allocate (this=0xfee90d6c, proj_id=@0xfee90a6c)
        at shared_memory.h:961
    #3  0x08054633 in pooled_allocator::Pool<std::pair<int const, void*>, &(key), &(address)>::find_shared_memory (
        this=0xfee90d64, requested_pages=0x1) at pooled_allocator.h:741
    #4  0x0805264b in pooled_allocator::Pool<std::pair<int const, void*>, &(key), &(address)>::grow (this=0xfee90d64)
        at pooled_allocator.h:990
    #5  0x08051998 in Pool (this=0xfee90d64) at pooled_allocator.h:362
    #6  0x08051948 in Pool_alloc (this=0xfee90d60) at pooled_allocator.h:1233
    #7  0x0805179c in map (this=0x8060aa0) at stl_map.h:144
    #8  0x08050efe in __static_initialization_and_destruction_0 (__initialize_p=0x1, __priority=0xffff)
        at /home/jimv/code/projects/test/daemon/src/test.cpp:37
    #9  0x08050fbd in global constructors keyed to key () at stl_map.h:120
    #10 0x0805ae01 in __do_global_ctors_aux ()
    #11 0x0804c765 in _init ()
    #12 0x0805ad76 in __libc_csu_init ()
    #13 0x00891a87 in __libc_start_main () from /lib/tls/libc.so.6
    #14 0x0804d219 in _start ()
    gdb>

    Any ideas why? Why doesn't the allocator use ftruncate to zero the shm too? Or did it not just get this far?

    Regards

    Jim Vanns

     
    • Marc Bumble

      Marc Bumble - 2004-09-18

      Jim,

      There are examples in the test directory of using std::map with strings.  That example might be helpful.  I would use a debugger to step through the code.  Perhaps you are having a string problem.  See the test directory for examples of creating shared strings of characters.

      Marc

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.