From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id x5W4LiuGyWeO5QYAWB0awg (envelope-from ) for ; Thu, 06 Mar 2025 06:25:31 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=RuYzRDD8; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id AA2F71E105; Thu, 6 Mar 2025 06:25:31 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FORGED_MUA_MOZILLA, FREEMAIL_REPLYTO_END_DIGIT,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 163D31E08E for ; Thu, 6 Mar 2025 06:25:31 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A98D03858C2C for ; Thu, 6 Mar 2025 11:25:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A98D03858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1741260330; bh=NdDP9THi5GW7cqltkj1h036c72p/nUua2YuKfJDL6xc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=RuYzRDD8IKDREKQlz7yapmqN/nPYxw1Rvr+znAsfngbDWueUYoqShZvdP+20XDWLk Ka9d+57pNTP21gnXPUHF7N1GTRUM2k6uwpZVOAyt6szb15ybHLuD5wzTXWRIejpeaD p7141RcAjhJTjVVG6J6kbEru+HBoyuGCFlflJKgU= Received: from out162-62-57-49.mail.qq.com (out162-62-57-49.mail.qq.com [162.62.57.49]) by sourceware.org (Postfix) with UTF8SMTPS id 8BB913858D28 for ; Thu, 6 Mar 2025 11:24:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8BB913858D28 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8BB913858D28 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741260289; cv=none; b=WFWKkKbEGehhBRSmaEl84G3mVAOQlz/J+17x+cpyyEV3gmU6iSjud4k6SnBkJjhD8PjlMseRFr3IAZ1TQDBa0nWeb0iAHHe27riElnGEceQKT7+uvGVwE+vg1oYtVbS84bHGCHG/Y21GmXF+r/g1u/SblfvTe0FGjHdbNYraPQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741260289; c=relaxed/simple; bh=RQi041xeU1iVpcys2t79jxIrlzv5zLczCkHj6509bHs=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=n0GAvDsS9J9M3RLZFbHtgLQGUdZTdDxfecgBRZLtr2pvgBsHQyUS0ScLGTlDBsy+RuWmawVLx+hDQtu2C4o8Tf7yAw0SO3316yhhmwnoBy+6LCjG4ElUICrywTe8bVcalkh8PNOLbs3ux0kQCaTp0UG0xKYBtRJ7I9JDFUvx/kg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8BB913858D28 Received: from [172.16.62.241] ([218.4.166.162]) by newxmesmtplogicsvrszc16-0.qq.com (NewEsmtp) with SMTP id 629A5E33; Thu, 06 Mar 2025 19:24:41 +0800 X-QQ-mid: xmsmtpt1741260281tqm1cnkzw Message-ID: X-QQ-XMAILINFO: OKKHiI6c9SH3uiMnvFFScADV5GJz7/MCgTRXa1nZkGQEmSvNDBMDsMttVcfpOz urxRbaO3+TiwbVTHY8hCff49x57t+xMXSK2Z5ZAOwANWIzx6uC+xi7IfZLC0lTL543f3aJWSbrcB txnzx+iQqiOlUVRucq2ncq1lPWqY6Cl7L8KakLg9PGFcpd+nVVmusFdJIEECECAr32QfMnvgt4J4 2vUUlsjtn/HWiSgykbjnEYk1lwOq39VY+KvhVBAi3N0paSCVi5xF2j/hrDCQv370YmHBK8bxvIOj +U62ahpOegBp2ImBqtNuqnuMD0kt6ekDbDfFVADjYlGfQHd5vp5UNgWyw1Nd3ChuEMvBh39qLGgB BTP728UIzkMtTaUySr+b5uvTU5brcwQEOzFiAJ2bjG7/QQSaBD5Q/TMkGSboHFv0GruGYK3mvLbW 5cC43BiI7s29MYOzA8a6PcadCTOvcCcqy0jKKAzEnx9P7NPDGU5QIWMeAeNz0Dn3JOvUZJw6gOD1 ietjQYyqExHXCvDwb3KZ9AcWJ5346FhAGQm32PDbR7b/+lgZgHvVTE7QiKGq/ts6XoxrevPvXyaB uRRsUTFLVmDrRDygFJQClgbPcyv4hgI8i0Ewz/UZ3dYN0LakCX7tde6mDk27Y+r4PqzT9S1A1M1R ars9gJt1gPSfuRDhpVgDkR9Szx9ZECJO5YDb2+jONkpJghwc1k7LuWRMK2SAWCSS+ZK2fED/tTfk bBcXuYRCLh/hY5adBwK1cW0Vg1ITAK3b4mju72GrSxvXblMgfIEXfEc28yX0sahMxmLFLZGVKu37 ba3khsNsz/J57kwg2/+0O4GujCLugZIGliR/awOwKMWDJ4gp9FbF5DxbdwvV2atqMWYKLfRygtzo gkEjeGYazpmekq6vbmI2jNgrHucEbNVwMoW/iuwdlsaPyFWZqaFid0rrAWl6MVug== X-QQ-XMRINFO: MSVp+SPm3vtS1Vd6Y4Mggwc= X-OQ-MSGID: <1a634492-ef67-4b88-8314-5bc943eae431@qq.com> Date: Thu, 6 Mar 2025 19:24:41 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gdb@sourceware.org Content-Language: en-US Subject: Question about printing cpp std::map element using "print map1[0]" Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: gdb@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Li Guilin via Gdb Reply-To: Li Guilin <262703720@qq.com> Errors-To: gdb-bounces~public-inbox=simark.ca@sourceware.org Sender: "Gdb" Hello, I want to print individual std::map element using operator[] instead of printing the whole map during debugging in gdb, but it is not working. In contrast, calling operator[] on std::vector and std::deque variables works fine. ``` (gdb) p map1 $1 = std::map with 1 element = {[0] = 2} (gdb) p map1[0] Attempt to take address of value not located in memory. ``` Besides, disabling xmethod and pretty printer does not affet the overall behavior. And through "info functions" output, I think gdb knows information about std::map::operator[], like this (shortened): ``` (gdb) info functions std::map.*operator\[\] All functions matching regular expression "std::map.*operator\[\]": File /usr/include/c++/14/bits/stl_map.h: 504:    std::map::mapped_type &std::map::operator[](int const&); 524:    std::map::mapped_type &std::map::operator[](int&&); ``` Below is the sample cpp code. ``` #include #include #include #include // instantiate all member functions. template class std::deque; template class std::map; template class std::vector; int main() {     std::deque deque1;     std::map map1;     std::vector vector1;     deque1.push_back(1);     std::cout << "deque1[0] = " << deque1[0] << "\n";     map1[0] = 2;     std::cout << "map1[0] = " << map1[0] << "\n";     vector1.push_back(1);     std::cout << "vector1[0] = " << vector1[0] << "\n"; } ``` How to make "print map1[0]" work? Where is the problem? Thanks a lot for reading this. Kind regards, liginity