From patchwork Mon Aug 19 01:15:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Harmstone X-Patchwork-Id: 1973630 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=harmstone.com header.i=@harmstone.com header.a=rsa-sha256 header.s=mail header.b=XiYJpfKG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WnF6Q4mFJz1yXg for ; Mon, 19 Aug 2024 11:16:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 826D7384DB45 for ; Mon, 19 Aug 2024 01:16:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.burntcomma.com (mail.burntcomma.com [IPv6:2a02:8012:8cf0:250::6d61:696c]) by sourceware.org (Postfix) with ESMTPS id 7719B3850203 for ; Mon, 19 Aug 2024 01:15:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7719B3850203 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=harmstone.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=harmstone.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7719B3850203 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a02:8012:8cf0:250::6d61:696c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724030143; cv=none; b=EIDVRRLRiz7/rVazkxAWnn8pjijmOy/YzdNSA+DyasdJ6BE8F7/hH+NRwUv3LS1pRC/o2vGWXXaG8jrwFP97fo7ziRR5Pea5nenuqqmIc+K9dETGhBbQYH1f/G442/0U23cfEOdXGCQ9nBi3R7rPFT161mQEf631KLir5D5AflM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724030143; c=relaxed/simple; bh=V059OkQNIHDoHSm3ByC82xWETxdo/MFYJGoTJaqaO9w=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:Mime-Version; b=OEnYSWWuxWJ8exagEKTk+sJGP69+1AcTALw2kejUU7nOR18fsQv/Tts69LjV9omDSyg+XnIUEhutUeOkua7C8doCBX3ls73Xeu0u+IBgFxukZ2L+k+f2km1qySipo76p27Jry3O5J6cztxDUSMCh6WW0Th7yrJD1BBjEt23D54Y= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost.localdomain (mail2.burntcomma.com [217.169.27.34]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by mail.burntcomma.com (Postfix) with ESMTPSA id 64A66A06A9; Mon, 19 Aug 2024 02:15:39 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=harmstone.com; s=mail; t=1724030139; bh=XzhHb/0Si3VCcPwZpnuPDRUkZ66ezKy9aiAbg0sgTOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XiYJpfKGH5e7uvxSZstyR0Dw14HbLjs418AHVPOEuvgeN/aHmW6pFZM1PsQpG27Gt CEymkkqRA7t5dh0Hh8r1ZBOwQX5sLxwl4dD6Bw4r1T0nbwNsKA1X/1Izmb3lsfyzei HgJpnh3DlNiMg/CKF6eFkiscKOxERTG1dCVjV7gk= From: Mark Harmstone To: gcc-patches@gcc.gnu.org Cc: Mark Harmstone Subject: [PATCH 3/4] Write CodeView S_FRAMEPROC symbols Date: Mon, 19 Aug 2024 02:15:29 +0100 Message-ID: <20240819011530.25488-3-mark@harmstone.com> In-Reply-To: <20240819011530.25488-1-mark@harmstone.com> References: <20240819011530.25488-1-mark@harmstone.com> Mime-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, SPF_HELO_NONE, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Write S_FRAMEPROC symbols, which aren't very useful but seem to be necessary for Microsoft debuggers to function properly. These symbols come after S_LOCAL symbols for optimized variables, but before S_REGISTER and S_REGREL32 for unoptimized variables. gcc/ * dwarf2codeview.cc (enum cv_sym_type): Add S_FRAMEPROC. (write_s_frameproc): New function. (write_function): Call write_s_frameproc. --- gcc/dwarf2codeview.cc | 80 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc index 74bbf6bc1d7..88310504cf7 100644 --- a/gcc/dwarf2codeview.cc +++ b/gcc/dwarf2codeview.cc @@ -71,6 +71,7 @@ along with GCC; see the file COPYING3. If not see enum cv_sym_type { S_END = 0x0006, + S_FRAMEPROC = 0x1012, S_BLOCK32 = 0x1103, S_REGISTER = 0x1106, S_LDATA32 = 0x110c, @@ -2822,6 +2823,74 @@ write_s_end (void) targetm.asm_out.internal_label (asm_out_file, SYMBOL_END_LABEL, label_num); } +/* Write the S_FRAMEPROC symbol, which is supposed to give information about + the function frame. It doesn't seem to be really used in modern versions of + MSVC, which is why we zero-out everything here. You still need to write it + though, otherwise windbg won't necessarily show all the local variables. */ + +static void +write_s_frameproc (void) +{ + unsigned int label_num = ++sym_label_num; + + /* This is struct FRAMEPROCSYM in Microsoft's cvinfo.h: + + struct frameprocsym + { + uint16_t size; + uint16_t kind; + uint32_t frame_size; + uint32_t padding_size; + uint32_t padding_offset; + uint32_t saved_registers_size; + uint32_t exception_handler_offset; + uint16_t exception_handler_section; + uint32_t flags; + } ATTRIBUTE_PACKED; + */ + + fputs (integer_asm_op (2, false), asm_out_file); + asm_fprintf (asm_out_file, + "%L" SYMBOL_END_LABEL "%u - %L" SYMBOL_START_LABEL "%u\n", + label_num, label_num); + + targetm.asm_out.internal_label (asm_out_file, SYMBOL_START_LABEL, label_num); + + fputs (integer_asm_op (2, false), asm_out_file); + fprint_whex (asm_out_file, S_FRAMEPROC); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, 0); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, 0); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, 0); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, 0); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, 0); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (2, false), asm_out_file); + fprint_whex (asm_out_file, 0); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, 0); + putc ('\n', asm_out_file); + + targetm.asm_out.internal_label (asm_out_file, SYMBOL_END_LABEL, label_num); +} + /* Loop through the DIEs in an unoptimized function, writing out any variables or blocks that we encounter. */ @@ -3070,9 +3139,16 @@ write_function (codeview_symbol *s) fbloc = frame_base->dw_attr_val.v.val_loc; if (flag_var_tracking) - write_optimized_function_vars (s->function.die, fbloc, rtx_low, rtx_high); + { + write_optimized_function_vars (s->function.die, fbloc, rtx_low, + rtx_high); + write_s_frameproc (); + } else - write_unoptimized_function_vars (s->function.die, fbloc); + { + write_s_frameproc (); + write_unoptimized_function_vars (s->function.die, fbloc); + } /* Output the S_PROC_ID_END record. */