From patchwork Thu Feb 23 15:47:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 65525 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8EC123857C45 for ; Thu, 23 Feb 2023 15:48:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8EC123857C45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677167315; bh=Fvr05kuUZeDeoUz80R8A3CijhMZyoZNqGOV5z5Gjj8g=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=kBobC2yzNKUkIQ042BjVG6qNzkXHHrSjUNIF8HJL/ix6kAG/cec+vTayIG3CeVd4X fdZKNDmICHu711QFty9YejrYbZ8CWq3uqGDX9ZnkL/edyIdCjVXNor7zqVB/AH9Pih CeIrlofOqVvzdIEzkKAqLlknCgL8+RKRtvSabirY= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id CC8313857C45 for ; Thu, 23 Feb 2023 15:48:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CC8313857C45 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-589-DFyepkP_OCGryXMny1VKNQ-1; Thu, 23 Feb 2023 10:48:07 -0500 X-MC-Unique: DFyepkP_OCGryXMny1VKNQ-1 Received: by mail-wm1-f72.google.com with SMTP id x18-20020a1c7c12000000b003e1e7d3cf9fso5388598wmc.3 for ; Thu, 23 Feb 2023 07:48:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Fvr05kuUZeDeoUz80R8A3CijhMZyoZNqGOV5z5Gjj8g=; b=gecKbJKNI+Ei00oj88gdLVns4UP8JWIA3YtwIbLJRW8iveD/tLQERkOSo3O/6pbIx3 0Vg4zg/VOnKcx56GS6K9/yjN1TQd0een0tUJ+lIqpQV29uosk5w0mfnrHKYOd80uCJN8 miJimMQH/MVxq0rlHu3Q9SpEzhQi1wW745roETAUCicdw7M3M8+a58hTJ4zGh9fPqdoT xsf5gto5E0PRqEdwxtWx2t7VNImPHusHtDiDS8pLsEA+z81ROr3Kyz4jM90Lzxg8NqYb jV4QyqGseN/GiANhIF/nagVym3S3XSdYXe8ET+eGTIMa6jBNyT2VwW9iiFqYzVgila59 lpnA== X-Gm-Message-State: AO0yUKWcJl5UyN6EEGoKHwyTQJblEsXDgO17xBUhexMC0EP8IWSNMjqo JYH54Bw06nQyo1r7zBP6ZWWXW9Lg2qbLQFiAneFbZx6ZRW/F+ycFfuJyY69QvI5n1yMxcC+hi8B znDu3qPmkgKQqm6pwAqUVK9v+lzWvI1B3BSx0986yIJHGkPBqoMavaNoqdCGeNj1XS1AEKKq8qK kGTvg= X-Received: by 2002:a05:6000:98c:b0:2c5:68a9:843f with SMTP id by12-20020a056000098c00b002c568a9843fmr10065574wrb.4.1677167282487; Thu, 23 Feb 2023 07:48:02 -0800 (PST) X-Google-Smtp-Source: AK7set+Rmkygpit+jN8/cBLWsjvnxgnvcoLnqCidaPA3QDpJj1GRt1GEv1197o5t77PDzjh8MYr3WQ== X-Received: by 2002:a05:6000:98c:b0:2c5:68a9:843f with SMTP id by12-20020a056000098c00b002c568a9843fmr10065556wrb.4.1677167282148; Thu, 23 Feb 2023 07:48:02 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id r14-20020a05600c35ce00b003e1202744f2sm4273458wmq.31.2023.02.23.07.48.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 07:48:01 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH] gdb/amd64: replace xmalloc/alloca with gdb::byte_vector Date: Thu, 23 Feb 2023 15:47:59 +0000 Message-Id: <810b37f52627188ebfba31684dac71f910a960d7.1677167272.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 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-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Replace a couple of uses of xmalloc and alloc with a gdb::byte_vector local variable instead. There should be no user visible changes after this commit. Reviewed-By: Tom Tromey --- gdb/amd64-tdep.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) base-commit: 5e39600a691e3ba76acf6ab94edb24844c2e82b7 diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c index 0ae09dc7bfb..c4603e8252d 100644 --- a/gdb/amd64-tdep.c +++ b/gdb/amd64-tdep.c @@ -1648,16 +1648,13 @@ amd64_classify_insn_at (struct gdbarch *gdbarch, CORE_ADDR addr, int (*pred) (const struct amd64_insn *)) { struct amd64_insn details; - gdb_byte *buf; - int len, classification; - len = gdbarch_max_insn_length (gdbarch); - buf = (gdb_byte *) alloca (len); + gdb::byte_vector buf (gdbarch_max_insn_length (gdbarch)); - read_code (addr, buf, len); - amd64_get_insn_details (buf, &details); + read_code (addr, buf.data (), buf.size ()); + amd64_get_insn_details (buf.data (), &details); - classification = pred (&details); + int classification = pred (&details); return classification; } @@ -1836,21 +1833,21 @@ amd64_relocate_instruction (struct gdbarch *gdbarch, int len = gdbarch_max_insn_length (gdbarch); /* Extra space for sentinels. */ int fixup_sentinel_space = len; - gdb_byte *buf = (gdb_byte *) xmalloc (len + fixup_sentinel_space); + gdb::byte_vector buf (len + fixup_sentinel_space); struct amd64_insn insn_details; int offset = 0; LONGEST rel32, newrel; gdb_byte *insn; int insn_length; - read_memory (oldloc, buf, len); + read_memory (oldloc, buf.data (), len); /* Set up the sentinel space so we don't have to worry about running off the end of the buffer. An excessive number of leading prefixes could otherwise cause this. */ - memset (buf + len, 0, fixup_sentinel_space); + memset (buf.data () + len, 0, fixup_sentinel_space); - insn = buf; + insn = buf.data (); amd64_get_insn_details (insn, &insn_details); insn_length = gdb_buffered_insn_length (gdbarch, insn, len, oldloc); @@ -1945,7 +1942,7 @@ amd64_relocate_instruction (struct gdbarch *gdbarch, } /* Write the adjusted instruction into its displaced location. */ - append_insns (to, insn_length, buf); + append_insns (to, insn_length, buf.data ()); }