#
# Copyright (C) 2012-2025 Intel Corporation.
# SPDX-License-Identifier: MIT
#

##############################################################
#
# This file is an extension to the testing framework specific
# to the Debugger tests directory.
# It contains additional variables used only by the Debugger tests.
# Below is a detailed list of the variables made available by this
# file:
#
# GDB						- Path to gdb. Relevant on Unix platforms only. On
#							  Windows this variable is empty.
# BARE_PIN					- Path to the Pin launcher without any additional
#							  flags.
# PINDB						- Path to the pindb test-debugger program.
# PINDB_LIBPATH				- Defines the locations of the necessary shared
#							  libraries when running the pindb program.
#							  Relevant on Unix platforms only. On Windows this
#							  variable is empty.
# PINDB_WITH_LIBPATH		- Path to the pindb test-debugger program, preceded
#							  by the library locations set in LOADER_LIBRARY_PATH.
#							  Relevant on Unix platforms only. On Windows this
#							  variable is identical to PINDB.
# PINDB_USERFLAGS			- Use this to add flags to the pindb program when
#							  running the tests.
#							  Usage: make PINDB_USERFLAGS=<extra flags> ...
# PINFLAGS_DEBUG			- Enable application debugging and stop in the
#							  debugger as soon as the application is launched.
# PINFLAGS_DEBUG_RUNFREE	- Enable application debugging bu do not stop in the
#							  debugger. Allows the user to attach a debugger at
#							  a later time.
# COMPARE_EXT				- Compare file extension depending on compiler used.
#
##############################################################

# We only support gdb on Unix platforms.
ifeq ($(OS_TYPE),unix)
	GDB := $(shell [ -f /usr/bin/gdb ] && echo "/usr/bin/gdb" || echo "gdb")
    ifeq ($(DIST_NAME_RHEL),1)
        # GDB 16.3 ditributed with RHEL 9.x has a bug. We provides a patched GDB version for lab machines.
        IS_RHEL_9_OR_LATER := $(shell $(TOOLS_ROOT)/Utils/testLinuxDistVersion ge 9.0)
        ifeq ($(IS_RHEL_9_OR_LATER),1)
            # PINT-6703
            IS_RHEL_MACHINE_WITH_GDB_BUG := $(shell $(TOOLS_ROOT)/Utils/testLinuxDistVersion lt 10.0)
            ifeq ($(IS_RHEL_MACHINE_WITH_GDB_BUG),1)
                IS_LAB_MACHINE := $(shell $(TOOLS_ROOT)/Utils/testHostName has bitl64-)
                ifeq ($(IS_LAB_MACHINE),1)
                    GDB := /nfs/iil/ptl/bistro/_common_tools/_CACHE/Linux/gdb-16.3.90_for_rhel/bin/gdb
                endif
            endif
        endif
    endif
endif

# Suffix for the pin-launcher and the pindb executables. It may be different than $(EXE_SUFFIX)
ifeq ($(TARGET_OS),windows)
    PINDB_SUFFIX := .exe
else
    PINDB_SUFFIX :=
endif

BARE_PIN := $(PIN_ROOT)/pin$(PINDB_SUFFIX)
# TODO on Windows after we will remove the old pincrt.dll and c++.dll from <TARGET>/bin folder, 
# we have to move back pind.exe out of pinrt (same as on Linux)
ifeq ($(TARGET_OS),windows)
    PINDB_PATH := $(PIN_ROOT)/$(TARGET)/pinrt/bin/
else
    PINDB_PATH := $(PIN_ROOT)/$(TARGET)/bin/
endif


# On Windows LOADER_LIBRARY_PATH is not available
ifeq ($(OS_TYPE),unix)
    PINDB_LIBPATH := $(PIN_ROOT)/extras/xed-$(TARGET)/lib$(PATHS_SEPERATOR)$(PIN_ROOT)/$(TARGET)/pinrt/lib
    PINDB_SET_LIBRARIES := $(LOADER_LIBRARY_PATH)=$(PINDB_LIBPATH)$(PATHS_SEPERATOR)$$$(LOADER_LIBRARY_PATH)
endif

ifeq ($(TARGET_OS),windows)
    PINDB := $(PINDB_PATH)pindb$(PINDB_SUFFIX)
else
    PINDB := $(PIN_ROOT)/$(TARGET)/pinrt/bin/pin.ld.so $(PINDB_PATH)pindb$(PINDB_SUFFIX)
endif
PINDB_WITH_LIBPATH := $(PINDB_SET_LIBRARIES) $(PINDB)

# These are the Pin flags needed to enable application debugging.
PINFLAGS_DEBUG := -appdebug
PINFLAGS_DEBUG_RUNFREE := -appdebug_enable

# Compare file extensions.
COMPARE_EXT := compare
