From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2041.outbound.protection.outlook.com [40.107.96.41]) by sourceware.org (Postfix) with ESMTPS id 1B7953858424 for ; Wed, 5 Oct 2022 23:19:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1B7953858424 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=netapp.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=netapp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oZDWI40ikhYguXSxEqs2t6leGMJuZe/OY4SZKXBfhqZ1z1WKhqI3Mm9T5epObHQRiHqMahkkkaWchNerMYRzTLzTuJJbcGLaynqxJvhOPY3kPdSPv0IH8CrOGcv/O1RPHWfRQCJhM61/Dv90Epznv2t1pIBJmjjol3hyoZi+i0DClUBcuctwtMf6X6Vg0jHAy22rPP4iv4kimdD38t61LIJmnGkemINR/o/hNNAacl9Bw1IiEJmqMdMcUySCnj6HlvOA1w+x7l/F4DoU4qHQNcghYl3nxZ9dPK+9rErAyLtV6KOQtLfM3BARPVDxwRPWFI4qxiXh2vz0sxGCBelddw== 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=fIDV0ld0PaMLnP2ln8fZmnvhPfofZeXjCM+Us/6LMMo=; b=boovD79cpgYmPoq5rjeZbZnDdRUi6SQ3zoNjRJ/KzsUp8VMHkqGckD0Nr5iBsehD1PhiroSl7G/VwGICfEneeIqgf34Jazub7ieAVGJr2dwHY24y4zpYgUmh1PYPjt4vAsvaNlkoM77Y6/vKyDH+C3fRtZSNuNcp6CXOKCw6k5W/6DCzFaKravnxTp5gPFZ8Twt0Fvud5OldsqZMazTzu0jwRCbR4VZV/GVdn2UWSK8upwiypoSVH8ufe6Skte+0+H9nBsR1XdfQXDl73+nzhx5f/vd0g4fd5dU6CTs37/FSgwLECtTddU1NiRuDun5vmtvvUnDC3bBJl++xoJqfuQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=netapp.com; dmarc=pass action=none header.from=netapp.com; dkim=pass header.d=netapp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netapp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fIDV0ld0PaMLnP2ln8fZmnvhPfofZeXjCM+Us/6LMMo=; b=y2JcuIwGSxCub4aH6k25ynC5ofcNLtUdfjZj2INcsFapGcb5t+BW1/fPEZa17oMfM9bZVs8yTSE4z/zl/t2vv4R1CwHw06uOAWxYV/zRbGLYSoTaRNcfjSW8v9Yn2vt2tSO5ZA86F8rl8ctMm4zqGFGpjg8tCsUrdS7ckPaUYb5z2BYnrL4l4zz49cKPpROnhVnu92id+52n66trlVVDvneBHnGnJx0FT6SO3CjCv8aZg2MlCn7RZ+jj2umc50Nfnabz1I8bmtTux4ZafIJgWkrJGMsaNzHfRcbnV6Yo4+C2r/pvgjJUwggxSUhG44ujG9O9uxioc+aAW8lbICbiKQ== Received: from BYAPR06MB6117.namprd06.prod.outlook.com (2603:10b6:a03:e1::19) by PH0PR06MB9060.namprd06.prod.outlook.com (2603:10b6:510:16f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.19; Wed, 5 Oct 2022 23:19:28 +0000 Received: from BYAPR06MB6117.namprd06.prod.outlook.com ([fe80::348f:cca0:3514:e3f8]) by BYAPR06MB6117.namprd06.prod.outlook.com ([fe80::348f:cca0:3514:e3f8%2]) with mapi id 15.20.5676.032; Wed, 5 Oct 2022 23:19:28 +0000 From: "Peikes, Wendy" To: "gdb-patches@sourceware.org" CC: "Peikes, Wendy" Subject: [PATCH] gdb: allow env var specifications in cmds 'set log', 'source', 'shell' Thread-Topic: [PATCH] gdb: allow env var specifications in cmds 'set log', 'source', 'shell' Thread-Index: AQHY2RCs2zv58aPQ20CxGE85eMWHBq4Ab7HQ Date: Wed, 5 Oct 2022 23:19:27 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.6.600.2 dlp-reaction: no-action authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=netapp.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BYAPR06MB6117:EE_|PH0PR06MB9060:EE_ x-ms-office365-filtering-correlation-id: 40792fd0-d631-4003-5bfc-08daa7280cb9 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 4QcvTiyPnhQUeLkh3CGZZMxUPjyff78AodJHzcFBKNMuEjknYIhqx/dvwHdQkGqlQEhig+Ya6IO8Wq4Kl9J3MpFWP3waagaI7/XT76jHNoBZo6TOH+zJcLcIn/xOWowAip1ubDFut8NmehpPcSlKk5afVoYC/7HfK1yjRQSfYrtKw3XeLDXxyPGixMtwK/rBosBOivmeyaHZ6qsoNrwPk4mlwFvYwgs5Noh7cpP1/Qapd3ZhQk47ZIgYKAHd+lezIStH/uDJUWKr7wcNncyCKcBK4XOBe6lKhr+9xus98vkWpEutUInBBQk1e/NaCrFDx2b7jNv2GONVSvGQMOvO/mRha6izysP8r/N1wbj6y0t8QnTBM9OViFSCFVDZSiLbQFTNInh1pAwcDbTDLG+e5w/Jtg5NMYBoStoyiLKRs7ALY0e/h5NRkQB1JAnJaSR+hky5DTfOK1OrUWENgQ66xhD+GMTtx5moQ+q/ospRCgaPegr/US4MpSm0BQ945/PS6XTm6IlKU6FOgYg7XeIRD5MwoXWg0h7wjYWrJGzliYY/8jtfRr117zfyYMxvLYkNWdj2j20XFJ0xIy5FiM9woBUk6IsC12pDGMkqSJPMhUhgdX87ZIVflUtnRmu3/B1i7LNbjGm2xwofFeUQJkQOKRf5pycWnpEhtuSzwSRadtpeM95+2+HYMY+cRQpsJaT+8pPPimGpRkp6JXL9vchHnbqeq21Wvh5grwXHR68f1KdYel3CKhgssVbsB0VeFSxECVPs6h4LaKw/TPgeBpax1k1sqTwqJ6OLVAwHOLuAxmI= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR06MB6117.namprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(396003)(346002)(376002)(366004)(39860400002)(136003)(451199015)(2906002)(186003)(7696005)(6506007)(8936002)(41300700001)(26005)(52536014)(9686003)(5660300002)(2940100002)(122000001)(33656002)(38100700002)(55016003)(38070700005)(86362001)(6916009)(316002)(76116006)(66446008)(8676002)(64756008)(66476007)(4326008)(66946007)(66556008)(107886003)(71200400001)(478600001)(2004002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?wQEA3SXHWEAwjZDkn0H073guiQ5Rkq8+wRIYO7EZB17fIswNzilr+obVzzhS?= =?us-ascii?Q?VYhRKR0XnxBmanKBBvuircEB3eJUP0UnCcHxfjHyB5+Y5eXDjqQlxzDfoJQ/?= =?us-ascii?Q?E7qNIA/CFmKsqrPn3+OxToFV9Aih83CJF8FsVNdBZ4nDx86exMBkU0DEGs47?= =?us-ascii?Q?QHa5l4mtYcHUXnjohIVFFTYryeUo+YQHrIJ9Qcizx+XsTW+Ku7j1uTvY+62v?= =?us-ascii?Q?ugttbMKkqNNg9sppsFBN/Ijc32C5vf1f9s0ae/zPuYpq4132OKWnTZVPGI/5?= =?us-ascii?Q?IlF1C/IanFZ/DeQ229Z9rlXYbz9ge3hu5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xer//SkeZ4ALv60XogQhXkMV1AdaVI6RoPTmZ1y2S7SrKs?= =?us-ascii?Q?ulQIfoyVbuiL0o9NI++ntGpBJu5evgZhPSaFjJPy2UI5DWEv08JGq80sApJP?= =?us-ascii?Q?zBl1TlxOve8rQqVMSN9YdNKYaCZo9DUPs2q0fJYpnR4FDI7kESAUcEo2Btlf?= =?us-ascii?Q?duMX0b/favxtWTlyAbBTa5o6V9yYmaoGOpVgkq04yGUthvMk9ohK84jJ6skH?= =?us-ascii?Q?B0Cbr37qtLt+rdSDzVopIORTb+zIsCGulHRbJsbIuNBqmR/ZRA58UaVQ+Vhw?= =?us-ascii?Q?bOhW7ENnWZq1cZk++4plEuwnv4w5DcLNIQRbrLNfDkM5OnTIBepjNQunPZsp?= =?us-ascii?Q?otfhWiahVOik6wRs4WE=3D?= Content-Type: multipart/alternative; boundary="_000_BYAPR06MB61177EF001EF3D6D4B4C0720E55D9BYAPR06MB6117namp_" MIME-Version: 1.0 X-OriginatorOrg: netapp.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR06MB6117.namprd06.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 40792fd0-d631-4003-5bfc-08daa7280cb9 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Oct 2022 23:19:28.0194 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4b0911a0-929b-4715-944b-c03745165b3a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: a/RArJ4io1tmvVRO7eSHZtRxlrwrv/WUC5rJ016o+R+paVHu0Wrz5IFyR+Xm3baJe69vjS5GQTyjuRQAFWt3kQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR06MB9060 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Message-ID: <20221005231927.SYcBO16oPGI2wb_AyWSJx_qy2VNHh5eglcQRR-BPkxQ@z> --_000_BYAPR06MB61177EF001EF3D6D4B4C0720E55D9BYAPR06MB6117namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Rationale: We at NetApp added a gdb feature allowing users to specify environment vari= able names when invoking gdb commands 'set logging file', 'source' & 'shell= '. This has been a big help especially in gdb macros since it allows macro wri= ters to customize macro behavior with environment var settings. We've implemented this feature for the above three gdb commands but it can = easily be extended to other commands such as 'set substitute-path' Usage example below. setenv LOG_DIR /tmp setenv SCRIPT_DIR "." I've created a script 'macroScript' in the current directory ("."); it is r= eferenced in the gdb session. Now, run the gdb with the new env var feature: gdbWithEnvVarFeature .... GNU gdb (GDB) 9.1 Copyright (C) 2020 Free Software Foundation, Inc. ... (gdb) shell head ${SCRIPT_DIR}/macroScript define macro1 echo macro1\n end define macro2 echo macro2\n end macro1 macro2 gdb) source ${SCRIPT_DIR}/macroScript macro1 macro2 (gdb) set logging file ${LOG_DIR}/logFile (gdb) show logging file The current logfile is "${LOG_DIR}/logFile". (gdb) set logging on Copying output to /tmp/logFile. Copying debug output to /tmp/logFile. (gdb) help set Evaluate expression EXP and assign result to variable VAR. Usage: set VAR =3D EXP This uses assignment syntax appropriate for the current language (VAR =3D EXP or VAR :=3D EXP for example) ... set architecture -- Set architecture of target. ... (gdb) set var $i =3D 1 (gdb) printf "i:%d\n", $i i:1 (gdb) shell tail ${LOG_DIR}/logFile set watchdog -- Set watchdog timer. set width -- Set number of characters where GDB should wrap lines of its ou= tput. set write -- Set writing into executable and core files. .... Command name abbreviations are allowed if unambiguous. ... i:1 The patch to gdb9.1 is here; the changed lines are bracket by #if defined ALLOW_ENV_VARS #endif patch: *** fsf/cli-cmds.c 2022-09-22 15:59:17.238371000 -0700 --- modifiedFsf/cli-cmds.c 2022-09-22 16:29:59.506242000 -0700 *************** *** 660,665 **** --- 660,744 ---- script_from_file (stream, file); } + #define ALLOW_ENV_VARS 1 + #if defined ALLOW_ENV_VARS + /* return true if s uses one or more env vars, specified as ${VARNAME} */ + extern int + contains_env_var(const char *s0) + { + return s0 && (strlen (s0) > 1) && (strstr(s0, "${") !=3D NULL) && + (strchr(s0, '}') !=3D NULL); + } + + /* substitute_env_var - given a string, return a copy of the string with + env vars interpolated (if any). env vars are recognized by the + syntax ...${VARNAME}... + */ + + + extern char * + substitute_env_var(const char *s0, const char* msg, const int from_tty) + { + int slen, i; + + char *s =3D xstrdup(s0); + slen =3D strlen(s); + + for (i=3D0; i opened =3D find_and_open_script (file, searc= h_path); if (!opened) { *************** *** 844,849 **** --- 931,945 ---- if (!arg) execl (user_shell, p, (char *) 0); else + #if defined ALLOW_ENV_VARS + /* support interpolation of env vars in shell arg */ + if (contains_env_var(arg)) + { + char* newArg =3D substitute_env_var(arg, "exec'ing cmd", from_t= ty); + execl (user_shell, p, "-c", newArg, (char *) 0); //do as usual + xfree(newArg); + } else + #endif //ALLOW_ENV_VARS execl (user_shell, p, "-c", arg, (char *) 0); fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", user_she= ll, *** fsf/cli-logging.c 2022-09-22 15:59:17.250302000 -0700 --- modifiedFsf/cli-logging.c 2022-09-22 16:26:12.482260000 -0700 *************** *** 139,144 **** --- 139,151 ---- current_uiout->redirect (gdb_stdout); } + #define ALLOW_ENV_VARS 1 + #if defined (ALLOW_ENV_VARS) + extern int contains_env_var(const char *s0); + extern char * substitute_env_var + (const char *s0, const char* msg, const int from_tty); + #endif + static void set_logging_on (const char *args, int from_tty) { *************** *** 149,154 **** --- 156,173 ---- xfree (logging_filename); logging_filename =3D xstrdup (rest); } + + #if defined (ALLOW_ENV_VARS) + // recognize ${} in log file name + else + { + if (contains_env_var(logging_filename)) + { + logging_filename =3D substitute_env_var + (logging_filename, "Logging to", from_tty); + } + } + #endif // ALLOW_ENV_VARS handle_redirections (from_tty); } --_000_BYAPR06MB61177EF001EF3D6D4B4C0720E55D9BYAPR06MB6117namp_--