public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io, sssky307@163.com
Subject: Re: [edk2-devel] [Question] How to get debug or release information in codes.
Date: Thu, 2 May 2019 12:03:18 +0200	[thread overview]
Message-ID: <91dd4045-6b70-8b92-bf95-bada93e358f9@redhat.com> (raw)
In-Reply-To: <6a2c1fe6.45d4.16a7677dd6a.Coremail.sssky307@163.com>

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

      reply	other threads:[~2019-05-02 10:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-02  2:55 [edk2-devel] [Question] How to get debug or release information in codes krishnaLee
2019-05-02 10:03 ` Laszlo Ersek [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=91dd4045-6b70-8b92-bf95-bada93e358f9@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox