From patchwork Sun May 5 20:57:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Rossi X-Patchwork-Id: 89508 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 1E0CC3858426 for ; Sun, 5 May 2024 20:57:37 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by sourceware.org (Postfix) with ESMTPS id 3AA4B3858D28 for ; Sun, 5 May 2024 20:57:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3AA4B3858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=brasko.net Authentication-Results: sourceware.org; spf=none smtp.mailfrom=brasko.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3AA4B3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714942637; cv=none; b=m4XzaH2LGOk+8GspBXnb2T5ZeDz+oO1CclksU6aac5bxbrerVWVbtP9qkiJVQ1gyn8GYjvNjHoCi94RcWIXaPmlm/7zkWlIsLOtgbdvUysk7TgJvaHh9Qe1BXIBXC2nAO4FU19tUo5qaPRrHYUcl3AcMHj1NHettLUHyDjrm7o4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714942637; c=relaxed/simple; bh=uvlO0pUwmLlAQ2Os5ZanUDTJK5e4khQ5Na3KyuQYEgs=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=tg4T7egn1E6zQ1R3Xw6flGt9zwtdnOjEsuXGscuxb2YF3MQn+t7oUOo+Wq3vBxGeG169x0OVY5XWC8r8TVLmx4VUu0fC2tQDbGXGivd/5Wx0VbW6wMXcyOPWEmN8n9WS8/wdl08H7Q4JZE1m0BiVBKSDg7FwO1vMsB2+7okszCs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-51ffff16400so1556588e87.2 for ; Sun, 05 May 2024 13:57:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasko-net.20230601.gappssmtp.com; s=20230601; t=1714942632; x=1715547432; darn=sourceware.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=8scIq7QCFI0TMsaM2MpJFzbB+REvtAptYM7rmFrjnz4=; b=0PJ3ym/IACjYhHD6IV1pCM2+ekaeIeJZafnzs+NvNt+NyK3gQ+nhK3MeU+rj0f+zK+ CVXDIqu4lx3TY7aGUGV7P0APdFfMB7BgD5PjKkQoLxEgCsxj7WU0Nhr1hypPFYDP2MED 4JEYlDw9K1JEOWkPuuoibjW2do2nwHe9qM4wCSdNhcD/zMc5Rcdz/0b2NE2iVUkl9/7Y HnJ6vpy/2jFXCULW/dIxuDBXL3p7cLYkclvE6E2vGCC3bYnO2WvVCr2UAwkaQkQHD8+l 5OJAq6A9xKLbb0mCdw7cMswZ+httc5ppDmipAMIxVBluVo/nbGIcy4U1wsXZEzrh+SCB Utyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714942632; x=1715547432; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=8scIq7QCFI0TMsaM2MpJFzbB+REvtAptYM7rmFrjnz4=; b=e3oYsBbVOA+DJaD512OW6HTBhtAqmfI5osAQSXyzpTKQ0I6pOkIir7cQct8ShEHrVS 3kngk8UIqWRPHQU1w2A9FZ1m4bRT2mhPA1j0Nl24gLQlOuUPejQy8mcy4f2XDppHcGt6 RQweXDP+pO3bVgNLNbu0MCX/pa+gHvBBIotF90z8E4mNyLlCSjLx7hWYlePWCHK7yUf0 ivctVif33K/821ZqdPiIbelP9lXxx51bXPYEA94v/lT4TITidqXygqPZobODSGF+pZhY fzNQm4FFtAyl/CnQQbDGm/xfs3Gkl12Z4VDme6fhxvy6lhA16bEeFOOOr4CLbsYiZLe6 lwZg== X-Gm-Message-State: AOJu0YzBdbLBa+kahPZcSD2dFEq46Q1KFbb0FEG1sTEnEyfeOOtSSAHZ g7Jp+b6RRhOmld1BZ5KPfLAW021+fsPJ1eTx8PfmKtTcIOlJatF/ZNwNalf8LYzLHN1gv8NKv6o NMs9ok4EfAg5smTBjOIlQgOuB49x/T4rslErm+xIaflhhBxRHWvA= X-Google-Smtp-Source: AGHT+IG44lYMHhAzNDs8HNxkKiUAO+uH9B37ZCwgDPfsZPTUpkdqj8XjbgURvt49jqd2Zi2X8+DS7T3rUUFYML2iVAk= X-Received: by 2002:a05:6512:36cf:b0:51d:4c8a:bbdb with SMTP id e15-20020a05651236cf00b0051d4c8abbdbmr6212910lfs.3.1714942632049; Sun, 05 May 2024 13:57:12 -0700 (PDT) MIME-Version: 1.0 From: Robert Rossi Date: Sun, 5 May 2024 16:57:00 -0400 Message-ID: Subject: Optionally print source code to gdb console window To: gdb-patches@sourceware.org X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org A little history. When using --annotations, gdb did not print the source code to the gdb console window. When using mi with new-ui it does. When I reported this in the past, several people said it was a feature that gdb printed the source code lines to the console. I've had several users of cgdb say they do not want gdb to print the source code to the gdb console window as they can see the code in the code view. I've created and attached a patch that I hope makes it optional to have gdb print the source code to the gdb console window. Could I have some feedback? I've added a new print source option to control printing source code to the gdb console. (gdb) show print source Printing of source code to gdb console is on. You can turn the printing of the source code off as follows. (gdb) set print source off (gdb) When the printing of source code is on, (gdb) r Starting program: /home/bob/rcs/git/gdb/gdb-build/main .... Breakpoint 1, main (argc=1, argv=0x7fffffffe0c8) at test_main.cpp:42 42 { (gdb) n 43 int i = 3; (gdb) n 44 int j = 4; (gdb) n 47 long_func(); When the printing of source code is off, (gdb) r Starting program: /home/bob/rcs/git/gdb/gdb-build/main ... Breakpoint 1, main (argc=1, argv=0x7fffffffe098) at test_main.cpp:42 (gdb) n (gdb) n (gdb) n (gdb) I don't know gdb code well enough to understand if i've disabled functionality beyond what i was hoping to. I'm not sure how to control this from cgdb when using old versions of gdb. I get the following error when i run --ex "set print source off" when starting gdb. Undefined set print command: "source off". Try "help set print". Thanks, Bob Rossi diff -urNp gdb-14.2.orig/gdb/stack.c gdb-14.2/gdb/stack.c --- gdb-14.2.orig/gdb/stack.c 2024-03-03 00:55:00.000000000 -0500 +++ gdb-14.2/gdb/stack.c 2024-05-05 11:27:07.735576624 -0400 @@ -1161,7 +1161,9 @@ print_frame_info (const frame_print_opti uiout->text ("\t"); } - print_source_lines (sal.symtab, sal.line, sal.line + 1, 0); + + if (opts.sourceprint) + print_source_lines (sal.symtab, sal.line, sal.line + 1, 0); } /* If disassemble-next-line is set to on and there is line debug diff -urNp gdb-14.2.orig/gdb/valprint.c gdb-14.2/gdb/valprint.c --- gdb-14.2.orig/gdb/valprint.c 2024-03-03 00:55:00.000000000 -0500 +++ gdb-14.2/gdb/valprint.c 2024-05-05 11:24:32.447511834 -0400 @@ -113,6 +113,7 @@ struct value_print_options user_print_op true, /* addressprint */ false, /* nibblesprint */ false, /* objectprint */ + true, /* sourceprint */ PRINT_MAX_DEFAULT, /* print_max */ PRINT_MAX_CHARS_DEFAULT, /* print_max_chars */ 10, /* repeat_count_threshold */ @@ -2878,6 +2879,16 @@ Printing of C++ virtual function tables value); } +/* Controls printing of source code. */ +static void +show_sourceprint (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + gdb_printf (file, _("\ +Printing of source code to gdb console is %s.\n"), + value); +} + /* Controls looking up an object's derived type using what we find in its vtables. */ static void @@ -3088,6 +3099,14 @@ pretty-printers for that value.") N_("Show printing of C++ virtual function tables."), NULL, /* help_doc */ }, + boolean_option_def { + "source", + [] (value_print_options *opt) { return &opt->sourceprint; }, + show_sourceprint, /* show_cmd_cb */ + N_("Set printing of source code to gdb console."), + N_("Show printing of source code to gdb console."), + NULL, /* help_doc */ + }, }; /* See valprint.h. */ diff -urNp gdb-14.2.orig/gdb/valprint.h gdb-14.2/gdb/valprint.h --- gdb-14.2.orig/gdb/valprint.h 2024-03-03 00:55:00.000000000 -0500 +++ gdb-14.2/gdb/valprint.h 2024-05-05 11:16:22.418856087 -0400 @@ -62,6 +62,9 @@ struct value_print_options in its vtables. */ bool objectprint; + /* Controls printing of source to console. */ + bool sourceprint; + /* Maximum number of elements to print for vector contents, or UINT_MAX for no limit. Note that "set print elements 0" stores UINT_MAX in print_max, which displays in a show command as "unlimited". */