From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80078.outbound.protection.outlook.com [40.107.8.78]) by sourceware.org (Postfix) with ESMTPS id 814713858D28 for ; Fri, 12 Aug 2022 06:14:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 814713858D28 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L+x15Jufm4My2dGPJQXahtuL+0Yr0UqQdadhKxwsI5k+++dVcddMU9r8g6AMw1llDUlqm2XwCQAYGfQV2pX+kRyesnu8J+KdIMhNesGqZL6MB7z7vZ35IK4wX8ybwWhjXOY7cZ8ScYE5BFAeQZ4z9Sm4LvSOCc5disPWNf+ATNev54yPh5dvSVGQUr7aTIht/xpf9eTt8MmTl5rcrVHmHGfm6/jsCTEaudfkO/HzU6jfnrUD37ad8iIoYrJED5eQAvkUHanLczRPjlttIIjfz1FcpRIdPnViaFffnHWKxpHK/7NqIIEdPSLCvoR6Oj6sOA9L1cG7bEtKjCv8xZQy1A== 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=4GRwYAXC8tGaWGzAULa7vK3ONeaW4wtz0dRa3Av8abc=; b=By17ws53HPfnNhP3CW5Anww5NnMvZ4VCkrhcr6A6vCFIOlytv7OgSPIvAJC/Z6ua6eGsBFIQW6nJAuRVqZtO3EUjkJC0ZEcJkt6SqJ9Pp592ZU15cluh+ShPkhq6FbOVJWZt6m5f9jdn/NiAuf14F0L5p/DZMy+YnPR4iRTip2AJ9Ju5GMdk1XCyoittW6ryNwaM0qnMkk8Hgw24xZl11Rk8LJ9f/zNGdCb15u4WK94qahVcG/8onj/bODl4lDOVaFmdy9152xVrKUiph3UZj2+v7tM5/s2o7ypbSNcScEHY80T0WTg68O5+FbZ/pyaif86OyBTHJhHGL3pRAS0mXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by AM5PR0402MB2833.eurprd04.prod.outlook.com (2603:10a6:203:99::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.11; Fri, 12 Aug 2022 06:14:11 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2d5d:bae0:430f:70ad]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2d5d:bae0:430f:70ad%4]) with mapi id 15.20.5525.010; Fri, 12 Aug 2022 06:14:11 +0000 Message-ID: Date: Fri, 12 Aug 2022 08:14:09 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH] Add pdb archive target Content-Language: en-US To: Mark Harmstone Cc: binutils@sourceware.org References: <20220725234405.19880-1-mark@harmstone.com> <182ff63d-9b76-3897-4da0-9641ac27f5c9@harmstone.com> From: Jan Beulich In-Reply-To: <182ff63d-9b76-3897-4da0-9641ac27f5c9@harmstone.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: FR3P281CA0134.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:94::18) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a86998bc-2e7f-4c83-9225-08da7c29df94 X-MS-TrafficTypeDiagnostic: AM5PR0402MB2833:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fqKcwalR03om4qg+Tb0v7BIdi8Y3MYBwjlvaK1Q7EkA+CZFMz0YhxNBsM/48mNo6Ldq3prtUzqABzdFrwu/8Gswwrc5BwTlz1/r1PCuCJwhCbQfUWXPZneSKuHjUxmdVN+2RvVMcWU4/Jn9g/mtJIPYmpbRlKU1iwNx/7OTiv4CYOcGbmtVpDiBH2wEPSokAtBbjdtFu/X2GAhuvx7ppBsMvg7En4OOGBKIg0Ts1Gy6zDCuubWnbWbhdOvSGSdenyGnXGZ9ACo04dCRZsy7aXBT/UNddPsEQImdZbHy4bmiADISA2f35C0urKjVNr6JfZWTgbn3iAGrJIeNxg7RspaewMJpHQrTsdwcyyFYO3nlnSRhJ+Z/lrzx7hZjedE0ZNj9dcLb0+yWlZT1fOJtAVcCeZphxa7j60hFIV17fbZaO36/9maHcIeN49NAMuzvr7wo+Olgq0CCEYPTXKemukJk0IKMx0UiVYQJ+eY3CiuxMcGCmiJPbGZEHMgTqf8cjbQy/9+RO9dRBAJMuNSQ1n/BbeGXoZAYIBpmMwszVTtY+ILOwRQmQYUB6Jp1HTmVytZgy76QGP4arng1oEpn1ij5hhqCGGRHEtMQhan7OEimBz1t4LpUQ9HELS9M/uyOQ7BKW9FvYT0ohd3Zh5ABmcqExJS1Ur6BFaUwcbqtIKAeG803q569Bq9fS/9smHvZNbPYF4CmDhsoNiKok9kiFDr+ANkT/JiuvAwKAqGnrN2PYsqFEucoZaBhSLEtppop00oEvPv6Zv8/KapkR5Eci8ZWwzVL00gbhzISn4iceu9ZE4msOc7Qd5VP+YkvoTkbWsLBIbb37zEkJZnMlAZ5J4pQcdQ65KoFQmN77a9EV0WiNszlUjlVGcg2k2OjHfwza X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR04MB6560.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(39860400002)(376002)(346002)(366004)(136003)(396003)(26005)(6512007)(38100700002)(966005)(30864003)(6486002)(5660300002)(53546011)(8936002)(86362001)(478600001)(6506007)(31696002)(66946007)(41300700001)(4326008)(66476007)(2906002)(66556008)(45080400002)(6916009)(8676002)(36756003)(83380400001)(2616005)(186003)(31686004)(316002)(2004002)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?dkdERzEySlppSUZNRFdoVUhkY1prSy9CSGZxQ2xBZmZ3OTJkZTY4RXo3MG56?= =?utf-8?B?aU5SQlYrT3Z5b1EvbE5pRGdzM2lUT2hpdG9RdEFXZGRpQnhPMlNxR2R3dmlN?= =?utf-8?B?S3g4SXRuMWkveU1CWG5pTDlXUXJLeCtWSVFaM3dvaXBUZmZzcXgyUVRINkcv?= =?utf-8?B?QS9uSUluSHNaUHQ1UTdHSW1IRGE2VlJDVG1NWmRUSkdPNzV1VlpCZGlRUWN6?= =?utf-8?B?S0ZxdkpRN3lOUndsZFE0NzUzM2hSWmd4b3djdGFLRVhSLzZzcC9qTk1NajU3?= =?utf-8?B?T3RiaVM3U3A0RTl3MURKa1lRRE1jSll5dlJDK0lRTW1KalFDMVBYZURmTks1?= =?utf-8?B?TTZTNkpFK2Q4cnVxZVQ0M3VLM040eWhhcFBtblFDN1hrTm9JY3dkV1diM0dy?= =?utf-8?B?djlwdXlnVmdCNDhSN3F2SHg5c3pBSHdVdndhTVpYYUpsZWFWbDFaKzZ6QUVS?= =?utf-8?B?dWIzQVdqa2tYeFIzdWlwVlRTKzZ0SUJhcFFVKytoamo4bVZQRVFLdVRqcVlB?= =?utf-8?B?REZ1WkNtQWZVcXRTUEdTTzkwSiswZVJPUk9jaHdtQlBQM2RVYmFMSC8zbVBQ?= =?utf-8?B?bTlrK2p2c0RyVm9FcWpFb2tCUlFVWXNYSEcyVDdZSXA2Ymc0emlxSDdMNnBz?= =?utf-8?B?cGlDa0JNeDN6VTQxTDNHSkd6YU1NNUpQMFhPYUhvVk9wR1ZBTm9GYmUxNUxW?= =?utf-8?B?bTRreEdPV2p1R3J3bWhnY0RtaHRLWXZNNVVvN1R6ZVgyODR0Tm0xSkRycS9i?= =?utf-8?B?YitGRW1lei91cUVqYzR2YTlKZDM3VG9OKy92alBzZEswUGxUZVdNTkhoS0xG?= =?utf-8?B?QXgxWE1WMGIyZ0dIR3MwWWtCNncvMnhTQm5Lc3h2UHBTSHJBNDNNdy96cnBq?= =?utf-8?B?ckk2Um5tTXJxUW44bWVOVVYvNzV5Sy9DREthYURCeDJPZVZPeHpzWmdzOW5B?= =?utf-8?B?L0phRGxNL3g2QVNJc0JrOE5oREgxaStHT0lFd2VoUW44V0hya0JMOWRNdjcr?= =?utf-8?B?NUFKdEs2U0dIc1JwR21VMUhjRFIwM1drUURQMlBDbnpVR283SHZkYXh2WUp0?= =?utf-8?B?MitRUmtmb3Rya1BoNy82MFJFR2puWVAxOVhnUm5hR1UzVUFpOWxkMVp5bkVF?= =?utf-8?B?VlAyeWxuUllCQWJ4Rkx6dVNFV0JvOFloeUpQb3NGQlcwZWRnRnpmQi9uWk1s?= =?utf-8?B?Y056eXhXWWpHR1d1VzdPR2cwQkwyRGNiSmMyL3ErZ24xSllhWW9YMzNxN2dr?= =?utf-8?B?Rk5yakVFODJNNU9WMkVodUQ5UWM2dFJSb0p5TUZ6OTRvMWFQTExKSXBmekxm?= =?utf-8?B?UVc5NVRlYU5YcUsveHFlV3VWQVA0b3JjNExUNFZoak1DMjFmTlhmcE5DVEdm?= =?utf-8?B?eGEydEVEQkJmcmF4S3ZjTm8zdnBLOFhidHN1czNaY1V1WnNJRFhYdnpFa1dF?= =?utf-8?B?bWtHL3U5WWgvRkxIaGZ6dmlRUGZsL0MyM2VmU21MK29sSDQxL0RIMk5wV2hV?= =?utf-8?B?N1R5b1UzTmlSZTc0VzFiR1ZCSkJZV3JwQ0NxUzZKb1EzeC8zOVFkZmNGdkpL?= =?utf-8?B?dE1Ubkg1WTZMVithM2VpWHhnS0toRFdkT3VodUlTOENtZVNEZ1pwa3ErZEha?= =?utf-8?B?UmpVd0J0UDNsYnkwdWJ0OUlvbFVFWGlaaldLYkY0bnpROE5LNHJQN1dIcjNN?= =?utf-8?B?SlNzMHBIRld0QkUzbkNKK2huL3g1UUI1Ym9MeDFFWTVuNUl3a0NWelpiOG9U?= =?utf-8?B?TXI0dmQxakNQUzJ5SHNWS0xoTEFxVWVvTFpxM2xRVkNSaDJDUnh4ZHVUUGl6?= =?utf-8?B?YUFkSzV0MWtUSDNCSGM3NFRtcFV6ZXhZT0FIODRubVBUVm5mVmhxMmxtZUpq?= =?utf-8?B?elhtR3hrTkx5ZEl6ZFVMTGZIc3ROMTZsUGpaNnUyUm1YYjJHbG9tOTA3eGpt?= =?utf-8?B?NFA2anQ4UmhjUWk0TjJhNklUUG1vQ2xMZzQ3bGFHYnNaV1hsN2IzTXpOcHhz?= =?utf-8?B?aTc5OCtYZ3NXU0paeXNIcVh6TGYyWXRIeldObTZHOUpDWStVSnJzaVYrVXZt?= =?utf-8?B?NkM5UlNOZkNDYkNnd1JJWU1wRFR0RDAxMkl1bXNZODU4L1J6Y2FKUkJQM0wz?= =?utf-8?Q?UbKWiOTi/FdIiN5sCIBL1s1b2?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: a86998bc-2e7f-4c83-9225-08da7c29df94 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2022 06:14:11.4155 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: KEoPNPozgtOBTWlOwpCcP6uH93N4vfCuVSw86YYp16XS6YWUwQixmWaWW4/WJ7cS9IDrDTXKbh+uO/QUMI/f8Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0402MB2833 X-Spam-Status: No, score=-3028.8 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Aug 2022 06:14:17 -0000 On 12.08.2022 01:26, Mark Harmstone wrote: > On 11/8/22 14:02, Jan Beulich wrote: > > On 26.07.2022 01:44, Mark Harmstone wrote: > >> This adds support for the "Multi-Stream Format" container format that > >> MSVC uses for its PDB debugging files, as documented at > >> https://llvm.org/docs/PDB/MsfFile.html. > > > > Looking at binutils/testsuite/binutils-all/pdb*.d I wonder what "support" > > here means: What is dumped is the binary contents of the file (claimed > > to be coming from section .data) rather than the inner file structure. > > I'm not quite sure what you're getting at. This is purely for PDB files as > archives, there is no inner file structure. The tests check that the hex > dump of the files matches one possible way to represent an archive of the > dummy files. If it's an archive (and hence can hold multiple files), then surely it has an internal structure. Or else your patch also wouldn't be needed, btw. Dumping a *.a file gives you an idea what's in the file. I would have expected the same for *.pdb (to a reasonable extent at least). One might then easily see number of members, block size, etc. Perhaps even the sizes of the individual members. > > Also this looks to cover only one of several flavors/versions, which may > > want calling out here and which also may influence the naming of certain > > things throughout the patch. > > I assume you're basing this off the "Microsoft C/C++ MSF 7.00" in the header. > MSVC++ 7 came out in 2002, and it's been the same since... there's only one > living version of the format. Well, bad luck with my picking of an older version of VC then - I ended up checking a VC6 PDB file, which is version 2.00. > >> --- /dev/null > >> +++ b/bfd/pdb.c > >> @@ -0,0 +1,804 @@ > >> +/* BFD back-end for PDB Multi-Stream Format archives. > >> +   Copyright (C) 2022 Free Software Foundation, Inc. > >> + > >> +   This file is part of BFD, the Binary File Descriptor library. > >> + > >> +   This program is free software; you can redistribute it and/or modify > >> +   it under the terms of the GNU General Public License as published by > >> +   the Free Software Foundation; either version 3 of the License, or > >> +   (at your option) any later version. > >> + > >> +   This program is distributed in the hope that it will be useful, > >> +   but WITHOUT ANY WARRANTY; without even the implied warranty of > >> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > >> +   GNU General Public License for more details. > >> + > >> +   You should have received a copy of the GNU General Public License > >> +   along with this program; if not, write to the Free Software > >> +   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, > >> +   MA 02110-1301, USA. */ > >> + > >> +/* This describes the MSF file archive format, which is used for the > >> +   PDB debug info generated by MSVC. See https://llvm.org/docs/PDB/MsfFile.html > >> +   for a full description of the format. */ > >> + > >> +#include "sysdep.h" > >> +#include "bfd.h" > >> +#include "libbfd.h" > >> + > >> +/* "Microsoft C/C++ MSF 7.00\r\n\x1a\x44\x53\0\0\0" */ > >> +static const uint8_t pdb_magic[] = > >> +{ 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, > >> +  0x74, 0x20, 0x43, 0x2f, 0x43, 0x2b, 0x2b, 0x20, > >> +  0x4d, 0x53, 0x46, 0x20, 0x37, 0x2e, 0x30, 0x30, > >> +  0x0d, 0x0a, 0x1a, 0x44, 0x53, 0x00, 0x00, 0x00 }; > >> + > >> +#define arch_eltdata(bfd) ((struct areltdata *) ((bfd)->arelt_data)) > >> + > >> +static bfd_cleanup > >> +pdb_archive_p (bfd *abfd) > >> +{ > >> +  int ret; > >> +  char magic[sizeof (pdb_magic)]; > >> + > >> +  ret = bfd_bread (magic, sizeof (magic), abfd); > >> +  if (ret != sizeof (magic)) > >> +    { > >> +      bfd_set_error (bfd_error_wrong_format); > >> +      return NULL; > >> +    } > >> + > >> +  if (memcmp (magic, pdb_magic, sizeof (magic))) > >> +    { > >> +      bfd_set_error (bfd_error_wrong_format); > >> +      return NULL; > >> +    } > >> + > >> +  return _bfd_no_cleanup; > >> +} > >> + > >> +static bfd * > >> +pdb_get_elt_at_index (bfd *abfd, symindex sym_index) > >> +{ > >> +  char int_buf[sizeof (uint32_t)]; > >> +  uint32_t block_size, block_map_addr, block, num_files; > >> +  uint32_t first_dir_block, dir_offset, file_size, block_off, left; > >> +  char name[10]; > >> +  bfd *file; > >> +  char *buf; > >> + > >> +  /* get block_size */ > >> + > >> +  if (bfd_seek (abfd, sizeof (pdb_magic), SEEK_SET)) > >> +    return NULL; > >> + > >> +  if (bfd_bread (int_buf, sizeof (uint32_t), abfd) != sizeof (uint32_t)) > >> +    { > >> +      bfd_set_error (bfd_error_malformed_archive); > >> +      return NULL; > >> +    } > >> + > >> +  block_size = bfd_getl32 (int_buf); > >> + > >> +  /* get block_map_addr */ > >> + > >> +  if (bfd_seek (abfd, 4 * sizeof (uint32_t), SEEK_CUR)) > >> +    return NULL; > >> + > >> +  if (bfd_bread (int_buf, sizeof (uint32_t), abfd) != sizeof (uint32_t)) > >> +    { > >> +      bfd_set_error (bfd_error_malformed_archive); > >> +      return NULL; > >> +    } > >> + > >> +  block_map_addr = bfd_getl32 (int_buf); > >> + > >> +  /* get num_files */ > >> + > >> +  if (bfd_seek (abfd, block_map_addr * block_size, SEEK_SET)) > >> +    return NULL; > >> + > >> +  if (bfd_bread (int_buf, sizeof (uint32_t), abfd) != sizeof (uint32_t)) > >> +    { > >> +      bfd_set_error (bfd_error_malformed_archive); > >> +      return NULL; > >> +    } > >> + > >> +  first_dir_block = bfd_getl32 (int_buf); > >> + > >> +  if (bfd_seek (abfd, first_dir_block * block_size, SEEK_SET)) > >> +    return NULL; > >> + > >> +  if (bfd_bread (int_buf, sizeof (uint32_t), abfd) != sizeof (uint32_t)) > >> +    { > >> +      bfd_set_error (bfd_error_malformed_archive); > >> +      return NULL; > >> +    } > >> + > >> +  num_files = bfd_getl32 (int_buf); > >> + > >> +  if (sym_index >= num_files) > >> +    { > >> +      bfd_set_error (bfd_error_no_more_archived_files); > >> +      return NULL; > >> +    } > >> + > >> +  /* read file size */ > >> + > >> +  dir_offset = sizeof (uint32_t) * (sym_index + 1); > >> + > >> +  if (dir_offset >= block_size) > >> +    { > >> +      uint32_t block_map_addr_off; > >> + > >> +      block_map_addr_off = ((dir_offset / block_size) * sizeof (uint32_t)); > >> + > >> +      if (bfd_seek (abfd, (block_map_addr * block_size) + block_map_addr_off, > >> +            SEEK_SET)) > >> +    return NULL; > >> + > >> +      if (bfd_bread (int_buf, sizeof (uint32_t), abfd) != sizeof (uint32_t)) > >> +    { > >> +      bfd_set_error (bfd_error_malformed_archive); > >> +      return NULL; > >> +    } > >> + > >> +      block = bfd_getl32 (int_buf); > >> +    } > >> +  else > >> +    { > >> +      block = first_dir_block; > >> +    } > >> + > >> +  if (bfd_seek (abfd, (block * block_size) + (dir_offset % block_size), > >> +        SEEK_SET)) > >> +    return NULL; > >> + > >> +  if (bfd_bread (int_buf, sizeof (uint32_t), abfd) != sizeof (uint32_t)) > >> +    { > >> +      bfd_set_error (bfd_error_malformed_archive); > >> +      return NULL; > >> +    } > >> + > >> +  file_size = bfd_getl32 (int_buf); > >> + > >> +  /* create BFD */ > >> + > >> +  sprintf (name, "%04lx", sym_index); > > > > Is there a reason for this 4-or-more digits naming of the file? Would > > it make sense to use 8 digits (beyond which the index apparently > > cannot grow)? > > In practice, 4 digits is plenty. The number of files in the archive is > proportional to the number of object files linked into the image... for the > NT kernel, which is probably the most complicated EXE out there, the PDB > has 1,100 files. I can't imagine anybody will ever go over 65,535 - and it's > not visible anyway, unless you play around with ar. Since you know the number of files in the archive, may I suggest that you base the number of digits on that number of members, such that all elements would be extracted to files with names of identical length? > >> --- /dev/null > >> +++ b/binutils/testsuite/binutils-all/pdb.exp > >> @@ -0,0 +1,157 @@ > >> +#   Copyright (C) 2022 Free Software Foundation, Inc. > >> + > >> +# This file is part of the GNU Binutils. > >> +# > >> +# This program is free software; you can redistribute it and/or modify > >> +# it under the terms of the GNU General Public License as published by > >> +# the Free Software Foundation; either version 3 of the License, or > >> +# (at your option) any later version. > >> +# > >> +# This program is distributed in the hope that it will be useful, > >> +# but WITHOUT ANY WARRANTY; without even the implied warranty of > >> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > >> +# GNU General Public License for more details. > >> +# > >> +# You should have received a copy of the GNU General Public License > >> +# along with this program; if not, write to the Free Software > >> +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. > >> + > >> +proc pdb_archive_1 { } { > >> +    global AR > >> +    global OBJDUMP > >> +    global srcdir > >> +    global subdir > >> + > >> +    set testname "pdb archive 1" > >> + > >> +    file delete tmpdir/test.pdb > >> + > >> +    # add short file (less than block size) > >> + > >> +    set got [binutils_run $AR "cr --target=pdb tmpdir/test.pdb $srcdir/$subdir/pdbfile1"] > >> +    if ![string match "" $got] { > >> +    fail $testname > >> +    return > >> +    } > >> + > >> +    set got [binutils_run $AR "tv tmpdir/test.pdb"] > >> +    if ![string match "rw-r--r-- 0/0      3 *0000*" $got] { > >> +    fail $testname > >> +    return > >> +    } > >> + > >> +    set got [binutils_run $OBJDUMP "-s --target=binary tmpdir/test.pdb"] > >> +    set exp [file_contents "$srcdir/$subdir/pdb1.d"] > >> +    if ![string equal $got $exp] { > >> +    fail $testname > >> +    return > >> +    } > >> + > >> +    set got [binutils_run $AR "x tmpdir/test.pdb 0000 --output=tmpdir"] > >> +    if ![string match "" $got] { > >> +    fail $testname > >> +    return > >> +    } > >> + > >> +    set got [file_contents tmpdir/0000] > >> +    set exp [file_contents "$srcdir/$subdir/pdbfile1"] > >> +    if ![string equal $got $exp] { > >> +    fail $testname > >> +    return > >> +    } > >> + > >> +    pass $testname > >> +} > >> + > >> +proc pdb_archive_2 { } { > >> +    global AR > >> +    global OBJDUMP > >> +    global srcdir > >> +    global subdir > >> + > >> +    set testname "pdb archive 2" > >> + > >> +    # add empty file > >> + > >> +    set got [binutils_run $AR "cr --target=pdb tmpdir/test.pdb /dev/null"] > >> +    if ![string match "" $got] { > >> +    fail $testname > >> +    return > >> +    } > >> + > >> +    set got [binutils_run $AR "tv tmpdir/test.pdb"] > >> +    if ![string match "*\nrw-r--r-- 0/0      0 *0001*" $got] { > >> +    fail $testname > >> +    return > >> +    } > >> + > >> +    set got [binutils_run $OBJDUMP "-s --target=binary tmpdir/test.pdb"] > >> +    set exp [file_contents "$srcdir/$subdir/pdb2.d"] > >> +    if ![string equal $got $exp] { > >> +    fail $testname > >> +    return > >> +    } > >> + > >> +    set got [binutils_run $AR "x tmpdir/test.pdb 0001 --output=tmpdir"] > >> +    if ![string match "" $got] { > >> +    fail $testname > >> +    return > >> +    } > >> + > >> +    set got [file_contents tmpdir/0001] > >> +    if ![string equal $got ""] { > >> +    fail $testname > >> +    return > >> +    } > >> + > >> +    pass $testname > >> +} > >> + > >> +proc pdb_archive_3 { } { > >> +    global AR > >> +    global OBJDUMP > >> +    global srcdir > >> +    global subdir > >> + > >> +    set testname "pdb archive 3" > >> + > >> +    # add long file (greater than block size) > >> + > >> +    set got [binutils_run $AR "cr --target=pdb tmpdir/test.pdb $srcdir/$subdir/pdbfile2"] > >> +    if ![string match "" $got] { > >> +    fail $testname > >> +    return > >> +    } > >> + > >> +    set got [binutils_run $AR "tv tmpdir/test.pdb"] > >> +    if ![string match "*\nrw-r--r-- 0/0   1032 *0002*" $got] { > >> +    fail $testname > >> +    return > >> +    } > >> + > >> +    set got [binutils_run $OBJDUMP "-s --target=binary tmpdir/test.pdb"] > >> +    set exp [file_contents "$srcdir/$subdir/pdb3.d"] > >> +    if ![string equal $got $exp] { > >> +    fail $testname > >> +    return > >> +    } > >> + > >> +    set got [binutils_run $AR "x tmpdir/test.pdb 0002 --output=tmpdir"] > >> +    if ![string match "" $got] { > >> +    fail $testname > >> +    return > >> +    } > >> + > >> +    set got [file_contents tmpdir/0002] > >> +    set exp [file_contents "$srcdir/$subdir/pdbfile2"] > >> +    if ![string equal $got $exp] { > >> +    fail $testname > >> +    return > >> +    } > >> + > >> +    pass $testname > >> +} > >> + > >> +pdb_archive_1 > >> +pdb_archive_2 > >> +pdb_archive_3 > > > > The three functions look pretty similar. Any chance of folding them into > > just one, suitably parametrized? > > I'm not sure - to my mind, that would imply that the functions were > independent, when they need to be run one after the other. Oh, that wasn't obvious to me at all. Would you mind adding a comment to that effect then? > I think we do need to test a small file, an empty file, and a long file, but > could I get away with just having one test, which adds all three files? This certainly makes sense. Jan