From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by sourceware.org (Postfix) with ESMTPS id 1C3403858426 for ; Thu, 24 Aug 2023 17:12:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1C3403858426 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-il1-x132.google.com with SMTP id e9e14a558f8ab-34ca63f6a27so171055ab.1 for ; Thu, 24 Aug 2023 10:12:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1692897144; x=1693501944; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=+az5E3RvBikGhXKzBuLr/+Cc8CftvxohDjVdemEhh/M=; b=VkXRYE2EH8itZgUO/PoGfM300AEa0f/RwK5khOb/VAy5gIOfJCpeG8Y3oJlrO8PVqG /MO7ZrPPm+40Cm2TeARB0yfCKH1axfuqZ1BOoV/xsrCGE48qVerPgFdOM/MvOBL6xBop vwrtihp4oTJypanLkFZXFk29OoRz5gysB48pNQmY8ActmWfS+DiohT50lMakj5rXW5eE zq6CLmhBP4ZVPgWEVLhL6b2Ltb2sdEIDK73+aPUJxO0NZRLaPQQlsRCW0khx1bDP7icf LiwpGnIgPgQ7hjxeHmoZXKx9tRLpkMZF1vCV077z2bPzKJwALAKK5MT4BEWqaMDGLVSo XvKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692897144; x=1693501944; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+az5E3RvBikGhXKzBuLr/+Cc8CftvxohDjVdemEhh/M=; b=VHdc5VjlXziuGqQMwmY1VJvzFwqh6DUHKr1XDcCjNu3KFN3QxKxoKauUFUi1+8mGCr b1soZ1/IJ+OsFfuV8Tk8/0SIAfoh7mMGqk/ZksbiQEODi5Vb4va8F7NAcglXnhD6zFtQ knwsPI6i1e4gbGj17U8Q0FGp1wzp1P5lV1VDaQwiyC4aqxiU7kWh9CmKGFf4Fs2bA0q8 P7TX1txeb7lWAdnj2Y1QY4qvYmqXgzUQsqlWSc08+nV+cflZy7srteOMQCX3TOJ+F6LY 1zU9iJSgP6yktscvBiBCxT6T6RI4qnzIJ4WVv+WNxL0/0Mo4uGc6FaN+6QIelNRr3olV s6oA== X-Gm-Message-State: AOJu0Yysr+e0zEXo41ZjsfqIGCh3cdvtrU3ce4W/sjnB7RY89ia/Ei9o 61X57N3XBlRbsjXKDv4hBso3HQtwavI7bdeFgiLxQw== X-Google-Smtp-Source: AGHT+IFuyAFJ8SrdbU9CyppESkGuNIJzm0OQajX0hFGOdo1wlW66hEj/rb6Kh1GGLRa52ipjhj8pLg== X-Received: by 2002:a92:d1d2:0:b0:345:d4da:41d with SMTP id u18-20020a92d1d2000000b00345d4da041dmr6352104ilg.8.1692897144089; Thu, 24 Aug 2023 10:12:24 -0700 (PDT) Received: from localhost.localdomain (75-166-142-177.hlrn.qwest.net. [75.166.142.177]) by smtp.gmail.com with ESMTPSA id n8-20020a92d9c8000000b0034986f6d9a9sm4722515ilq.78.2023.08.24.10.12.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 10:12:23 -0700 (PDT) From: Tom Tromey Date: Thu, 24 Aug 2023 11:12:22 -0600 Subject: [PATCH 5/7] Convert minidebug to new type-safe gdb_bfd_openr_iovec MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230824-gdb-bfd-vec-v1-5-850e4e907ed1@adacore.com> References: <20230824-gdb-bfd-vec-v1-0-850e4e907ed1@adacore.com> In-Reply-To: <20230824-gdb-bfd-vec-v1-0-850e4e907ed1@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This converts the minidebug BFD iovec implementation to the new type-safe gdb_bfd_openr_iovec. --- gdb/minidebug.c | 98 +++++++++++++++++++++++---------------------------------- 1 file changed, 40 insertions(+), 58 deletions(-) diff --git a/gdb/minidebug.c b/gdb/minidebug.c index 979e569e639..e2b60fb959c 100644 --- a/gdb/minidebug.c +++ b/gdb/minidebug.c @@ -57,7 +57,7 @@ static lzma_allocator gdb_lzma_allocator = { alloc_lzma, free_lzma, NULL }; a section. This keeps only the last decompressed block in memory to allow larger data without using to much memory. */ -struct gdb_lzma_stream +struct gdb_lzma_stream : public gdb_bfd_iovec_base { /* Section of input BFD from which we are decoding data. */ asection *section = nullptr; @@ -69,19 +69,25 @@ struct gdb_lzma_stream bfd_size_type data_start = 0; bfd_size_type data_end = 0; gdb::byte_vector data; -}; -/* bfd_openr_iovec OPEN_P implementation for - find_separate_debug_file_in_section. OPEN_CLOSURE is 'asection *' - of the section to decompress. - Return 'struct gdb_lzma_stream *' must be freed by caller by delete, - together with its INDEX lzma data. */ + ~gdb_lzma_stream () + { + lzma_index_end (index, &gdb_lzma_allocator); + } -static void * -lzma_open (struct bfd *nbfd, void *open_closure) + file_ptr read (bfd *abfd, void *buffer, file_ptr nbytes, + file_ptr offset) override; + + int stat (struct bfd *abfd, struct stat *sb) override; +}; + +/* bfd_openr_iovec implementation helper for + find_separate_debug_file_in_section. */ + +static gdb_lzma_stream * +lzma_open (struct bfd *nbfd, asection *section) { - asection *section = (asection *) open_closure; bfd_size_type size, offset; lzma_stream_flags options; gdb_byte footer[LZMA_STREAM_HEADER_SIZE]; @@ -127,15 +133,13 @@ lzma_open (struct bfd *nbfd, void *open_closure) return lstream; } -/* bfd_openr_iovec PREAD_P implementation for - find_separate_debug_file_in_section. Passed STREAM - is 'struct gdb_lzma_stream *'. */ +/* bfd_openr_iovec read implementation for + find_separate_debug_file_in_section. */ -static file_ptr -lzma_pread (struct bfd *nbfd, void *stream, void *buf, file_ptr nbytes, - file_ptr offset) +file_ptr +gdb_lzma_stream::read (struct bfd *nbfd, void *buf, file_ptr nbytes, + file_ptr offset) { - struct gdb_lzma_stream *lstream = (struct gdb_lzma_stream *) stream; bfd_size_type chunk_size; lzma_index_iter iter; file_ptr block_offset; @@ -147,12 +151,9 @@ lzma_pread (struct bfd *nbfd, void *stream, void *buf, file_ptr nbytes, res = 0; while (nbytes > 0) { - if (lstream->data.empty () - || lstream->data_start > offset || offset >= lstream->data_end) + if (data.empty () || data_start > offset || offset >= data_end) { - asection *section = lstream->section; - - lzma_index_iter_init (&iter, lstream->index); + lzma_index_iter_init (&iter, index); if (lzma_index_iter_locate (&iter, offset)) break; @@ -184,15 +185,14 @@ lzma_pread (struct bfd *nbfd, void *stream, void *buf, file_ptr nbytes, != LZMA_OK) break; - lstream->data = std::move (uncompressed); - lstream->data_start = iter.block.uncompressed_file_offset; - lstream->data_end = (iter.block.uncompressed_file_offset - + iter.block.uncompressed_size); + data = std::move (uncompressed); + data_start = iter.block.uncompressed_file_offset; + data_end = (iter.block.uncompressed_file_offset + + iter.block.uncompressed_size); } - chunk_size = std::min (nbytes, (file_ptr) lstream->data_end - offset); - memcpy (buf, lstream->data.data () + offset - lstream->data_start, - chunk_size); + chunk_size = std::min (nbytes, (file_ptr) data_end - offset); + memcpy (buf, data.data () + offset - data_start, chunk_size); buf = (gdb_byte *) buf + chunk_size; offset += chunk_size; nbytes -= chunk_size; @@ -202,36 +202,14 @@ lzma_pread (struct bfd *nbfd, void *stream, void *buf, file_ptr nbytes, return res; } -/* bfd_openr_iovec CLOSE_P implementation for - find_separate_debug_file_in_section. Passed STREAM - is 'struct gdb_lzma_stream *'. */ - -static int -lzma_close (struct bfd *nbfd, - void *stream) -{ - struct gdb_lzma_stream *lstream = (struct gdb_lzma_stream *) stream; - - lzma_index_end (lstream->index, &gdb_lzma_allocator); - delete lstream; - - /* Zero means success. */ - return 0; -} - -/* bfd_openr_iovec STAT_P implementation for - find_separate_debug_file_in_section. Passed STREAM - is 'struct gdb_lzma_stream *'. */ +/* bfd_openr_iovec stat implementation for + find_separate_debug_file_in_section. */ -static int -lzma_stat (struct bfd *abfd, - void *stream, - struct stat *sb) +int +gdb_lzma_stream::stat (struct bfd *abfd, struct stat *sb) { - struct gdb_lzma_stream *lstream = (struct gdb_lzma_stream *) stream; - memset (sb, 0, sizeof (struct stat)); - sb->st_size = lzma_index_uncompressed_size (lstream->index); + sb->st_size = lzma_index_uncompressed_size (index); return 0; } @@ -265,8 +243,12 @@ find_separate_debug_file_in_section (struct objfile *objfile) std::string filename = string_printf (_(".gnu_debugdata for %s"), objfile_name (objfile)); - abfd = gdb_bfd_openr_iovec (filename.c_str (), gnutarget, lzma_open, - section, lzma_pread, lzma_close, lzma_stat); + auto open = [&] (bfd *nbfd) -> gdb_lzma_stream * + { + return lzma_open (nbfd, section); + }; + + abfd = gdb_bfd_openr_iovec (filename.c_str (), gnutarget, open); if (abfd == NULL) return NULL; -- 2.40.1