From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id tj80KIqeyWcc+QYAWB0awg (envelope-from ) for ; Thu, 06 Mar 2025 08:09:30 -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=LXR+v1Cv; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 92D371E105; Thu, 6 Mar 2025 08:09:30 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 850271E08E for ; Thu, 6 Mar 2025 08:09:29 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0795D3858433 for ; Thu, 6 Mar 2025 13:09:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0795D3858433 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1741266569; bh=yfbC17/lkHW9M7bRcNTewYuk7qAe1kcnZfOavtD5vtk=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=LXR+v1CvfCT9lDY+W11bmJoOBU3OIjJnfYAYK9cM6QuzKSGGl9/Bi4ou+x18G9fLr A0X/ny0FcinwFwqGw6DBz5isxyRIICl+/y8y7sFIV5TVkaSheTRMiiLcAEWq7BoRrR BqpdCMvYdWLCAhqWJXhcHeHM4jh8C8N0v7rrHlxE= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 06D753858D26 for ; Thu, 6 Mar 2025 13:08:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 06D753858D26 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 06D753858D26 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741266522; cv=none; b=aUA95p7xtdM+sT4rosjJq+6JD4fFI3Y2oRhECzJfYQETOlsnXKDCTj9HHi+YOyAW2n9lNfEWbbEgRngciyO1+Mcro50NYsv0ZE5rpuVUCL9Rar5r93LeMI8xdYiiNYk4Rw1+g0eEf68lMgZ4iFeStFTTiM/2oL+/x/O+lpxDgJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741266522; c=relaxed/simple; bh=TCyLNueKBuUICPN02vRPswTiQOj1WXeXF8Fb48Nbj+8=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=l7zEWGLKsvFYOyLb6oFn+LrXsKGlbWJt8GJjfJyVM7A8l6cJdubehgGJh86FXffeyqPmCNs8BpGDOgQH8++XtyvyUpntgq7Bvu1J0Z2kP5IQ1th3697sUoc2WWS8uQnqeALbVb9oRaByzJeIhghxkYgEQt2c1mHMbxQQ29/9/jM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 06D753858D26 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-116-5lXWbu9APuWxOMVbnjlZQg-1; Thu, 06 Mar 2025 08:08:40 -0500 X-MC-Unique: 5lXWbu9APuWxOMVbnjlZQg-1 X-Mimecast-MFC-AGG-ID: 5lXWbu9APuWxOMVbnjlZQg_1741266519 Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-223f63b450eso13501525ad.2 for ; Thu, 06 Mar 2025 05:08:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741266519; x=1741871319; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yfbC17/lkHW9M7bRcNTewYuk7qAe1kcnZfOavtD5vtk=; b=AOqXgoDJaP+aPu+NsiSGLZMIIwh8DM+a18dPzYg31MdzavIw0xU6dfpHeTXvK7LwFJ 4i5RA6yZPczMLOoW9936NP0+BuFOphHbSCnuUJAav3M1QP46YwCCKsN3ECtmQSzqZ9Z7 T2+xdSwCGS5OzOoTnl5Ygv6cal8BXswC6RM006mvwC6BV4Dcz8qy7aV/Rk5zw7p2Kgj3 lMC30/YQSBtCj3Y5ETKDn6YLpbd/Fkqit79w/5vPX1xEqnYs1E9osc+O0f4k4A8HTSsp g15f1oIpOMHBAt/nul+QeOVXPELywtRV7o7XdwYV/Ew/aXBtyYkniX/2cIE7A4SiDMrT VwIA== X-Forwarded-Encrypted: i=1; AJvYcCVta7DOTdUbJI70kCuqptdMfkP7eizOZCjRqw9CRWY4CS+JZTnoqVWKoaAcCUk6/EbRMNw=@sourceware.org X-Gm-Message-State: AOJu0YxLncJ6sAd7XDA92k0knKMLRQgLU5RJ0ghOBgMAZIOErVhXDRc2 LTBYQMDRosSO8GHYPHVwVSgUE8CQpTdf8wTBSm6P8Xn+kQmdFAgRstsrH2AB1agJGWDZJ+arkwH WdOox9IV0Hx6Dr0O1N/PjFjMMVQVWyoOV8RoxQOLdnWeVzm0M X-Gm-Gg: ASbGncvhivAIp/2FeUUubwbFxqmZxuO+3NLX6QWOfJV4LxoxjSbmNZGYSa77MspDWnT T5FdzxGlo77AwSKrLhlb3n5yRZbqBb1dkLXddxxmOccs3jGpLR9Qwxj/eM1ncS8pIVt5GiwFmAj 5HrQEApWCoO2T1/z3DHH+qi40wEd/w1QMR6EypA3mIDtB7sqXaSXU5CLG4zob4J34+UpPyP0xss pyjy8RzxMKYOKHlaVAs4S8xpnBfQWvgIt+92zSlZBux3w1b0p7AX94u3KZWPrVU/LajWxQn1B/i S4Jqv/RWCpNetE2+JveB0uRwRws= X-Received: by 2002:a17:902:d487:b0:220:ea90:191e with SMTP id d9443c01a7336-223f1c672f3mr105995125ad.4.1741266519492; Thu, 06 Mar 2025 05:08:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IGTHr5fUPIP3BZi2Em0zqb4UatyRNsqCC2CcI4hfVjEVa8OVHkyoEdohXoP0uu/jqydjLRJbg== X-Received: by 2002:a17:902:d487:b0:220:ea90:191e with SMTP id d9443c01a7336-223f1c672f3mr105994845ad.4.1741266519017; Thu, 06 Mar 2025 05:08:39 -0800 (PST) Received: from ?IPV6:2804:14d:8084:9a69::1001? ([2804:14d:8084:9a69::1001]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-224109e98adsm11609215ad.90.2025.03.06.05.08.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 Mar 2025 05:08:38 -0800 (PST) Message-ID: Date: Thu, 6 Mar 2025 10:08:35 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Question about printing cpp std::map element using "print map1[0]" To: Li Guilin <262703720@qq.com>, gdb@sourceware.org References: In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: XCBb2qfP6R9-8Eu4IuxgcokSGzL2M2YTRiERlnAR7XA_1741266519 X-Mimecast-Originator: redhat.com Content-Language: en-US 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: Guinevere Larsen via Gdb Reply-To: Guinevere Larsen Errors-To: gdb-bounces~public-inbox=simark.ca@sourceware.org Sender: "Gdb" On 3/6/25 8:24 AM, Li Guilin via Gdb wrote: > 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. Hi! This is, unfortunately, a known issue. There's a bug that has been opened about this, here: https://sourceware.org/bugzilla/show_bug.cgi?id=25957 I'll bump that bug, and thanks for asking here, I hope someone who has time can fix this soon! -- Cheers, Guinevere Larsen She/Her/Hers > > Kind regards, > > liginity >