From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from CAN01-YQB-obe.outbound.protection.outlook.com (mail-yqbcan01on2059.outbound.protection.outlook.com [40.107.116.59]) by sourceware.org (Postfix) with ESMTPS id 45CAC3858C74 for ; Wed, 21 Sep 2022 15:34:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 45CAC3858C74 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HaFUe9OEzv7eku+8doyX7T6OMBTW7ltT2Fzyutp8jVaSdF5eG/ecV2NEV1s3S7Ghp4rBb6EPLyKGtvhRxjhNeq6WrValVzLEXWvxDB5RDakL2xWMbfO8QFgF5NmXUqWnbfovr/xJFgKK0NCtdIe2jE8WrUe+vPD8tQv4MS/ngxEQ/213PPci7hB96UQVCiT0yo6AaRdDsqOsRS98LxMm/5K4BeKTWyyZnNwpLdGRIABBJMaycRcWXvyIHVqX/o4Y70pKLWklgLw7A4kIAPz+5/Udhi2+o1ak/hlD5fk4l8xiER9D8IVaZRLzTSbKGGi1Ma9Vu5M3XMjY4esGD/hk5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZCLhrbexyygBMyf8PFHy/3Ka/6chnomXvdQ5jYyVjSg=; b=fhTTBfP/rqz+cCPA+H0ee6MFkAZTz5a1DXKAFEIPwci03RxwlM5Uozwqz1hX7MX2YCNTCCqsoHF4J/eGLxwZmV3Cps7pUw8p0xDirF/sUj9ixo67eqTw5wpm0iSdk7iF5I7HTNqrKXg0/LzdZzB2OSdULWbjUpDgoiXxLgeoUJZyUqah1X05RJzLHMLFlpEqvjGLHI4mhDJSEGDvpxdAG67F2jCu/4L6GfI1xvaURTWyzSGeGZNejovOC9izoN6uE7f0W5gBEspRocLenkDXJnXGOUSPCF8ysbvzM7bW9h+ppxWNrZn9xgoCxUP3CZfIttwGFVlBZBYyosHOgbrPHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=efficios.com; dmarc=pass action=none header.from=efficios.com; dkim=pass header.d=efficios.com; arc=none Received: from YT1PR01MB2828.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:a::23) by YQBPR0101MB6324.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:39::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.14; Wed, 21 Sep 2022 15:34:55 +0000 Received: from YT1PR01MB2828.CANPRD01.PROD.OUTLOOK.COM ([fe80::3d6b:f9bb:9d0c:d744]) by YT1PR01MB2828.CANPRD01.PROD.OUTLOOK.COM ([fe80::3d6b:f9bb:9d0c:d744%4]) with mapi id 15.20.5654.017; Wed, 21 Sep 2022 15:34:55 +0000 Message-ID: <35380269-80f6-2176-e376-70e974f30d43@efficios.com> Date: Wed, 21 Sep 2022 11:34:52 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH] gdbsupport: change path_join parameter to std::vector Content-Language: en-US To: Bruno Larsen , Simon Marchi , "gdb-patches@sourceware.org" References: <20220719142741.3307396-1-simon.marchi@polymtl.ca> <45e2fd55-0ef7-5275-9b42-7b8480d84328@redhat.com> From: Simon Marchi In-Reply-To: <45e2fd55-0ef7-5275-9b42-7b8480d84328@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: MN2PR06CA0009.namprd06.prod.outlook.com (2603:10b6:208:23d::14) To YT1PR01MB2828.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:a::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: YT1PR01MB2828:EE_|YQBPR0101MB6324:EE_ X-MS-Office365-Filtering-Correlation-Id: 8da030e5-aec3-446c-8bd0-08da9be6d52f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7jYuZ90dv95RoX7LxRqSJQXolusPY4OLB8vokMCV4WaySTIrmcU/s5f8qKXg34xvuiWVHiNiiy+PmhOoTgxAIybEGX+B+U5GVPmfVAJoZvrC+/H7XncJMOOGJRotxG7myhc3z5Gq/ObwBYZI+LfmRsnJJcFApUExjxk9Ir4qiJGPphqFDj8r3FVX4/LrThw9zI1QTHdmBPKLFr0ljNdU+gclm5piII17ZyxPCygz45ngTz9weHgEiBEn0DzwrTyhNDF3EEHRSYGHcVIO99MhDCxv9bZ0Pef8Y56NhB4p6uEFwJGsxBgXaGEcUd11UCqbbYDv4gq1QA7T8PRCVgCxOMu+UCGTCQFCrvpUlvj7ZgiHGlsHbabD16ZC2JniPpp4qJjVNKU9NjKPyy7XDTB/0zSbpvkWzCZ62SvMtXSk63Dq1ZMYaZ9HrubEWek2IhpvCynonp6CTo1FzSCzHKmOv8BQxxIrV2S3HLuv+GIj7qlWT7hAbrpFvqfmDV9GG+ohrPuSmNYTCI0MgJdOV/ne7yV5rSs12kL3q9oaFj9YMTxe3sVlKuWzhluRo0IRZuwNTX6mgWa4o0OkZ+Q2kkc4f3PAOsdQPgrulXZZjZb2sDUz7sJq/jyVM1xKxhEySta2KCUbx69IZ4ODUXrABWGnhngeT4gMoWEM38fYO0//oIUp4ohI4pynO0k7H6eJqULCaWIC3luWDTZEwro9xvs3TsUy/C7H8Kv3/ybSzNGKZeNFh9DOdB8JMDRrO2STHsz27LDlkGSTT6hMqjKsaUti5jcMp5n1v3AEfNGpljEMuLKi2eIdnNLl1o7rfvX+5uiN X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:YT1PR01MB2828.CANPRD01.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230022)(396003)(136003)(34096005)(376002)(346002)(39830400003)(34036004)(366004)(451199015)(26005)(6512007)(53546011)(41300700001)(6506007)(8936002)(6666004)(110136005)(5660300002)(186003)(2616005)(8676002)(44832011)(36756003)(84970400001)(31696002)(66946007)(66556008)(66476007)(2906002)(83380400001)(586005)(6486002)(498600001)(31686004)(38610400001)(41320700001)(38100700002)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?UG9ocUtLblZ0S1crdFppTy9HN1NsSmpUcGVFWkRqTnhvSnNMZU43Z1h6WWVw?= =?utf-8?B?UkRSUjA0V25xRnN4c0lNeGltY003K2VoNWxNUXVmeEZ4cEVMelp5QzFMM2U5?= =?utf-8?B?OE5qaWpvY3JGR0RTOXdoS3hGaDRTUW5GNk5tU1dWN2laOUYzMjFweUNwSXNX?= =?utf-8?B?VitJQTJLeTFoTzNJaTZ5RTVpbjJQcDZWSGRUVlZLSk84K1VjdjF6S3VUYk8v?= =?utf-8?B?eFVkT0daM2NyTmRhS3pxRGRiRmFuNjlvZVV0cVBiNWNZWmltMFVFMTFRZldR?= =?utf-8?B?NkdrWFZDblFsdEx3bWtKb3ppNVBqenhvYzdMemRQOGRIZ1N6ZkxNTlVZMXd3?= =?utf-8?B?bW1SMmwwcmxIU1hkVlJsT3h6dk8zeWRmelFOU3I5cDVSVGc0eXA2UUFrSzBo?= =?utf-8?B?VWFCTW5leTViejI4TVVRSytkZ0ZscVBxS0Q5OTR3WHZyUzJ4WXRjc3ZCSDJx?= =?utf-8?B?Vyt3ck9xSXdiTE5CREs5YnhHZGE0QjNTeGxNTmN0MEN4bTFuUWFibUpLTFhX?= =?utf-8?B?WjFib1JEeFp1d1RFTkRLL2lzT2tyOVcrSThBajNiUzYyV0pQekJua3RRRzdX?= =?utf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clBMZFNN?= =?utf-8?B?L3VzN1YxYlNmY3lNYmtPUGs0Q1hza0JNRnE5MFFJLzBGTDVWazVlNG9QTGN0?= =?utf-8?B?dVliWkxLNys4b2NFMmE1SVd2NXQzdE44TVI2a3VJOEFJM3h5bmtxNk42M0Vp?= =?utf-8?B?M0lEaXlwOVplbGZGb1U3ZWlWQzNVYWxGeDZ5MnA1Sm44U3JFYTZIYWhLWWRG?= =?utf-8?B?VGNjcGc0cnU1SWk5SVlJS2V1OGd0Z25OTUp2S05TYnY4ZzJKK0JscXd5LzEx?= =?utf-8?B?S1kyb1IxT2xBZTZ4dXRxbmVQRzJrdmxXRCtEWVVITXFFeXJHZWJCYkkxVlNT?= =?utf-8?B?NXhUTWxNejBoVmE1ei9IZlNFRnl2RFdDcWxZSEg3amFLRDVHam02OUFQeDJk?= =?utf-8?B?YTFWZjhKKzJlRWpCTnJwdTFoVEpaT3NJS1ZpK3RCM29GRU9YSjRyRVNCV0Nw?= =?utf-8?B?a3k5c3BITG0rVHNHcVZ0dTJLMDF0QUgvcnh5QUVzSy8xMTZrR1pXVC81bzlX?= =?utf-8?B?VmxLR3JidzVncE9KWFl3WWtIVklPWXV0ZEJxUVdld1dIRC94dzlTY0VzNGRB?= =?utf-8?B?VE5sMTVFQXRNcCtPNVBOVDFDc3JxV0xKNEdSQVVwd0ZITmN6bzVkYmxFWmJE?= =?utf-8?Q?zOnpAsYWWojCF/5C1lbr0NUAJ?= X-OriginatorOrg: efficios.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8da030e5-aec3-446c-8bd0-08da9be6d52f X-MS-Exchange-CrossTenant-AuthSource: YT1PR01MB2828.CANPRD01.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2022 15:34:54.9042 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4f278736-4ab6-415c-957e-1f55336bd31e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zV9B/V+T5vNTFKAJKCWY4tPLeJo3tEmFNdJngYoQA8WzkZEMlZ/VvHiRtHgs7sxqVlcSwNLO5lqYHHgvhnRRsA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: YQBPR0101MB6324 X-Spam-Status: No, score=-3042.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Sep 2022 15:35:00 -0000 On 2022-07-19 11:10, Bruno Larsen wrote: > > On 7/19/22 11:27, Simon Marchi via Gdb-patches wrote: >> From: Simon Marchi >> >> When a GDB built with -D_GLIBCXX_DEBUG=1 reads a binary with a single >> character name, we hit this assertion failure: >> >> $ ./gdb -q --data-directory=data-directory -nx ./x >> /usr/include/c++/12.1.0/string_view:239: constexpr const std::basic_string_view<_CharT, _Traits>::value_type& std::basic_string_view<_CharT, _Traits>::operator[](size_type) const [with _CharT = char; _Traits = std::char_traits; const_reference = const char&; size_type = long unsigned int]: Assertion '__pos < this->_M_len' failed. >> >> The backtrace: >> >> #3 0x00007ffff6c0f002 in std::__glibcxx_assert_fail (file=, line=, function=, condition=) at /usr/src/debug/gcc/libstdc++-v3/src/c++11/debug.cc:60 >> #4 0x000055555da8a864 in std::basic_string_view >::operator[] (this=0x7fffffffcc30, __pos=1) at /usr/include/c++/12.1.0/string_view:239 >> #5 0x00005555609dcb88 in path_join[abi:cxx11](gdb::array_view > const>) (paths=...) at /home/simark/src/binutils-gdb/gdbsupport/pathstuff.cc:203 >> #6 0x000055555e0443f4 in path_join () at /home/simark/src/binutils-gdb/gdb/../gdbsupport/pathstuff.h:84 >> #7 0x00005555609dc336 in gdb_realpath_keepfile[abi:cxx11](char const*) (filename=0x6060000a8d40 "/home/simark/build/binutils-gdb-one-target/gdb/./x") at /home/simark/src/binutils-gdb/gdbsupport/pathstuff.cc:122 >> #8 0x000055555ebd2794 in exec_file_attach (filename=0x7fffffffe0f9 "./x", from_tty=1) at /home/simark/src/binutils-gdb/gdb/exec.c:471 >> #9 0x000055555f2b3fb0 in catch_command_errors (command=0x55555ebd1ab6 , arg=0x7fffffffe0f9 "./x", from_tty=1, do_bp_actions=false) at /home/simark/src/binutils-gdb/gdb/main.c:513 >> #10 0x000055555f2b7e11 in captured_main_1 (context=0x7fffffffdb60) at /home/simark/src/binutils-gdb/gdb/main.c:1209 >> #11 0x000055555f2b9144 in captured_main (data=0x7fffffffdb60) at /home/simark/src/binutils-gdb/gdb/main.c:1319 >> #12 0x000055555f2b9226 in gdb_main (args=0x7fffffffdb60) at /home/simark/src/binutils-gdb/gdb/main.c:1344 >> #13 0x000055555d938c5e in main (argc=5, argv=0x7fffffffdcf8) at /home/simark/src/binutils-gdb/gdb/gdb.c:32 >> >> The problem is this line in path_join: >> >> gdb_assert (strlen (path) == 0 || !IS_ABSOLUTE_PATH (path)); >> >> ... where `path` is "x". IS_ABSOLUTE_PATH eventually calls >> HAS_DRIVE_SPEC_1: >> >> #define HAS_DRIVE_SPEC_1(dos_based, f) \ >> ((f)[0] && ((f)[1] == ':') && (dos_based)) >> >> This macro accesses indices 0 and 1 of the input string. However, `f` >> is a string_view of length 1, so it's incorrect to try to access index >> 1. We know that the string_view's underlying object is a null-terminated >> string, so in practice there's no harm. But as far as the string_view >> is concerned, index 1 is considered out of bounds. >> >> This patch makes the easy fix, that is to change the path_join parameter >> from a vector of to a vector of `const char *`. Another solution would >> be to introduce a non-standard gdb::cstring_view class, which would be a >> view over a null-terminated string. With that class, it would be >> correct to access index 1, it would yield the NUL character. If there >> is interest in having this class (it has been mentioned a few times in >> the past) I can do it and use it here. >> >> This was found by running tests such as gdb.ada/arrayidx.exp, which >> produce 1-char long filenames, so adding a new test is not necessary. >> >> Change-Id: Ia41a16c7243614636b18754fd98a41860756f7af >> --- >> gdbsupport/pathstuff.cc | 8 ++++---- >> gdbsupport/pathstuff.h | 8 ++++---- >> 2 files changed, 8 insertions(+), 8 deletions(-) >> >> diff --git a/gdbsupport/pathstuff.cc b/gdbsupport/pathstuff.cc >> index af10c6ebd2e8..390f10b1b5e4 100644 >> --- a/gdbsupport/pathstuff.cc >> +++ b/gdbsupport/pathstuff.cc >> @@ -191,21 +191,21 @@ child_path (const char *parent, const char *child) >> /* See gdbsupport/pathstuff.h. */ >> >> std::string >> -path_join (gdb::array_view paths) >> +path_join (gdb::array_view paths) >> { >> std::string ret; >> >> for (int i = 0; i < paths.size (); ++i) >> { >> - const gdb::string_view path = paths[i]; >> + const char *path = paths[i]; >> >> if (i > 0) >> - gdb_assert (path.empty () || !IS_ABSOLUTE_PATH (path)); >> + gdb_assert (strlen (path) == 0 || !IS_ABSOLUTE_PATH (path)); >> >> if (!ret.empty () && !IS_DIR_SEPARATOR (ret.back ())) >> ret += '/'; >> >> - ret.append (path.begin (), path.end ()); >> + ret.append (path); >> } >> >> return ret; >> diff --git a/gdbsupport/pathstuff.h b/gdbsupport/pathstuff.h >> index d01db89e085f..aa7b0ffa2fbd 100644 >> --- a/gdbsupport/pathstuff.h >> +++ b/gdbsupport/pathstuff.h >> @@ -67,7 +67,7 @@ extern const char *child_path (const char *parent, const char *child); >> The first element can be absolute or relative. All the others must be >> relative. */ >> >> -extern std::string path_join (gdb::array_view paths); >> +extern std::string path_join (gdb::array_view paths); >> >> /* Same as the above, but accept paths as distinct parameters. */ >> >> @@ -78,10 +78,10 @@ path_join (Args... paths) >> /* It doesn't make sense to join less than two paths. */ >> gdb_static_assert (sizeof... (Args) >= 2); >> >> - std::array views >> - { gdb::string_view (paths)... }; >> + std::array views >> + { paths... }; > > Very minor nit, this array used to be called "views" because it held string_views, the name > should probably be changed, maybe path_array or something? Done, thanks. Simon