From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: lersek@redhat.com) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Thu, 02 May 2019 03:03:21 -0700 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F2C9B30ADBBA; Thu, 2 May 2019 10:03:20 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-207.rdu2.redhat.com [10.10.120.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43FD55C26D; Thu, 2 May 2019 10:03:19 +0000 (UTC) Subject: Re: [edk2-devel] [Question] How to get debug or release information in codes. To: devel@edk2.groups.io, sssky307@163.com References: <6a2c1fe6.45d4.16a7677dd6a.Coremail.sssky307@163.com> From: "Laszlo Ersek" Message-ID: <91dd4045-6b70-8b92-bf95-bada93e358f9@redhat.com> Date: Thu, 2 May 2019 12:03:18 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <6a2c1fe6.45d4.16a7677dd6a.Coremail.sssky307@163.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 02 May 2019 10:03:21 +0000 (UTC) Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit On 05/02/19 04:55, krishnaLee wrote: > Hi, > > > I want to add some memory leak test in only in a module's debug mode, > if "build -p xxx.dsc -m xxx.inf -b DEBUG", the memoryleak test will work, > if "build -p xxx.dsc -m xxx.inf -b RELEASE", no memoryleak test. > > > /* the added codes for test only in debug mode. */ > #ifdef _DEBUG > #define AllocateZeroPool(x) LogMalloc(x) > #define FreePool(x) LogFree(x) > #define CHECK_MEMORY_LEAK(CheckPoint) CheckLogForMemoryLeak(CheckPoint) > #else > #define CHECK_MEMORY_LEAK(CheckPoint) > #endif // _DEBUG > > > the question is how to bind "_DEBUG" to debug-build-mode? > > > and I found something in ShellPkg.dsc,some API have both debug and release implementation for this,is this the only way? > !if $(TARGET) == RELEASE > DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf > !else > DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf > !endif IIRC one approach is to declare a new Feature PCD in your package DEC file (default FALSE), and set it to TRUE in the platform DSC if $(TARGET) is NOOPT or DEBUG. In the module source code, you can use FeaturePcdGet() to gate the memory leak test. When building for RELEASE, the debug code should be eliminated at build time (because FeaturePcdGet() can be evaluated at compile time). The same works with Fixed-at-Build PCDs, if you need integer values to gate the debug logic. MdePkg.dec has several examples: - PcdVerifyNodeInList - PcdValidateOrderedCollection - PcdMaximumUnicodeStringLength - PcdMaximumAsciiStringLength - PcdMaximumLinkedListLength Thanks Laszlo