add debug build target (#4817)

* add debug build target

* fix maybe uninitialized error

* add option to undef NDEBUG

* debug for agbcc

* init instead of ignore to not break agbcc

* make clean removes modern and agbcc artifacts. explicit use of -O0 again for NOOPT

* automatically enable debug menu when building for debug

* automatically enable debug menu when building for debug

* automatically enable debug menu when building for debug

* clean up previous mess omg

* remove preproc around debug menus

* automatically enable debug menu when building for debug

* clean up previous mess omg

* Apply suggestions from code review

Co-authored-by: Bassoonian <iasperbassoonian@gmail.com>

* Update Makefile

* Update field_control_avatar.c

* make debug print independent

* remove unwanted changes

* remove trailing endif

---------

Co-authored-by: Bassoonian <iasperbassoonian@gmail.com>
This commit is contained in:
Salem 2024-09-07 16:13:22 +02:00 committed by GitHub
parent 5c86aa126f
commit 90089ecf51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 48 additions and 39 deletions

View File

@ -41,11 +41,16 @@ REVISION := 0
TEST ?= 0
ANALYZE ?= 0
UNUSED_ERROR ?= 0
DEBUG ?= 0
ifeq (check,$(MAKECMDGOALS))
TEST := 1
endif
ifeq (debug,$(MAKECMDGOALS))
DEBUG := 1
endif
CPP := $(PREFIX)cpp
ROM_NAME := pokeemerald.gba
@ -60,6 +65,7 @@ MAP = $(ROM:.gba=.map)
SYM = $(ROM:.gba=.sym)
TEST_OBJ_DIR_NAME := build/modern-test
DEBUG_OBJ_DIR_NAME := build/modern-debug
TESTELF = $(ROM:.gba=-test.elf)
HEADLESSELF = $(ROM:.gba=-test-headless.elf)
@ -86,7 +92,8 @@ TEST_BUILDDIR = $(OBJ_DIR)/$(TEST_SUBDIR)
ASFLAGS := -mcpu=arm7tdmi --defsym MODERN=1
CC1 = $(shell $(PATH_ARMCC) --print-prog-name=cc1) -quiet
override CFLAGS += -mthumb -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -Wno-pointer-to-int-cast -std=gnu17 -Werror -Wall -Wno-strict-aliasing -Wno-attribute-alias -Woverride-init
override CFLAGS += -mthumb -mthumb-interwork -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -Wno-pointer-to-int-cast -std=gnu17 -Werror -Wall -Wno-strict-aliasing -Wno-attribute-alias -Woverride-init
ifeq ($(ANALYZE),1)
override CFLAGS += -fanalyzer
endif
@ -101,6 +108,12 @@ OBJ_DIR := $(OBJ_DIR_NAME)
LIBPATH := -L "$(dir $(shell $(PATH_ARMCC) -mthumb -print-file-name=libgcc.a))" -L "$(dir $(shell $(PATH_ARMCC) -mthumb -print-file-name=libnosys.a))" -L "$(dir $(shell $(PATH_ARMCC) -mthumb -print-file-name=libc.a))"
LIB := $(LIBPATH) -lc -lnosys -lgcc -L../../libagbsyscall -lagbsyscall
ifeq ($(DEBUG),1)
override CFLAGS += -Og -g
else
override CFLAGS += -O2
endif
ifeq ($(TESTELF),$(MAKECMDGOALS))
TEST := 1
endif
@ -108,6 +121,10 @@ endif
ifeq ($(TEST),1)
OBJ_DIR := $(TEST_OBJ_DIR_NAME)
endif
ifeq ($(DEBUG),1)
OBJ_DIR := $(DEBUG_OBJ_DIR_NAME)
endif
CPPFLAGS := -iquote include -iquote $(GFLIB_SUBDIR) -Wno-trigraphs -DMODERN=1 -DTESTING=$(TEST)
@ -146,7 +163,7 @@ MAKEFLAGS += --no-print-directory
# Secondary expansion is required for dependency variables in object rules.
.SECONDEXPANSION:
.PHONY: all rom clean compare tidy tools check-tools mostlyclean clean-tools clean-check-tools $(TOOLDIRS) $(CHECKTOOLDIRS) libagbsyscall agbcc modern tidymodern tidynonmodern check history
.PHONY: all rom clean compare tidy tools check-tools mostlyclean clean-tools clean-check-tools $(TOOLDIRS) $(CHECKTOOLDIRS) libagbsyscall agbcc modern tidymodern tidynonmodern check history debug
infoshell = $(foreach line, $(shell $1 | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line))))
@ -154,7 +171,7 @@ infoshell = $(foreach line, $(shell $1 | sed "s/ /__SPACE__/g"), $(info $(subst
# Disable dependency scanning for clean/tidy/tools
# Use a separate minimal makefile for speed
# Since we don't need to reload most of this makefile
ifeq (,$(filter-out all rom compare agbcc modern check libagbsyscall syms $(TESTELF),$(MAKECMDGOALS)))
ifeq (,$(filter-out all rom compare agbcc modern check libagbsyscall syms $(TESTELF) debug,$(MAKECMDGOALS)))
$(call infoshell, $(MAKE) -f make_tools.mk)
else
NODEP ?= 1
@ -246,7 +263,7 @@ clean-tools:
clean-check-tools:
@$(foreach tooldir,$(CHECKTOOLDIRS),$(MAKE) clean -C $(tooldir);)
mostlyclean: tidynonmodern tidymodern tidycheck
mostlyclean: tidynonmodern tidymodern tidycheck tidydebug
find sound -iname '*.bin' -exec rm {} +
rm -f $(MID_SUBDIR)/*.s
find . \( -iname '*.1bpp' -o -iname '*.4bpp' -o -iname '*.8bpp' -o -iname '*.gbapal' -o -iname '*.lz' -o -iname '*.rl' -o -iname '*.latfont' -o -iname '*.hwjpnfont' -o -iname '*.fwjpnfont' \) -exec rm {} +
@ -256,7 +273,7 @@ mostlyclean: tidynonmodern tidymodern tidycheck
rm -f $(AUTO_GEN_TARGETS)
@$(MAKE) clean -C libagbsyscall
tidy: tidymodern tidycheck
tidy: tidymodern tidycheck tidydebug
tidymodern:
rm -f $(ROM_NAME) $(ELF_NAME) $(MAP_NAME)
@ -266,6 +283,8 @@ tidycheck:
rm -f $(TESTELF) $(HEADLESSELF)
rm -rf $(TEST_OBJ_DIR_NAME)
tidydebug:
rm -rf $(DEBUG_OBJ_DIR_NAME)
include graphics_file_rules.mk
include map_data_rules.mk
@ -305,6 +324,11 @@ ifeq ($(DINFO),1)
override CFLAGS += -g
endif
ifeq ($(NOOPT),1)
override CFLAGS := $(filter-out -O1 -Og -O2,$(CFLAGS))
override CFLAGS += -O0
endif
# The dep rules have to be explicit or else missing files won't be reported.
# As a side effect, they're evaluated immediately instead of when the rule is invoked.
# It doesn't look like $(shell) can be deferred so there might not be a better way.
@ -443,6 +467,8 @@ agbcc:
modern: all
debug: all
LD_SCRIPT_TEST := ld_script_test.ld
$(OBJ_DIR)/ld_script_test.ld: $(LD_SCRIPT_TEST) $(LD_SCRIPT_DEPS)

View File

@ -1,4 +1,3 @@
.if DEBUG_OVERWORLD_MENU == TRUE
Debug_MessageEnd:
waitmessage
waitbuttonpress
@ -448,5 +447,3 @@ Debug_EventScript_EWRAMCounters::
Debug_EventScript_EWRAMCounters_Text::
.string "Follower Steps: {STR_VAR_1}.\n"
.string "Fishing Chain: {STR_VAR_2}.$"
.endif

View File

@ -196,14 +196,12 @@ void BattleAI_SetupFlags(void)
else
AI_THINKING_STRUCT->aiFlags[B_POSITION_PLAYER_LEFT] = 0; // player has no AI
#if DEBUG_OVERWORLD_MENU == TRUE
if (gIsDebugBattle)
if (DEBUG_OVERWORLD_MENU && gIsDebugBattle)
{
AI_THINKING_STRUCT->aiFlags[B_POSITION_OPPONENT_LEFT] = gDebugAIFlags;
AI_THINKING_STRUCT->aiFlags[B_POSITION_OPPONENT_RIGHT] = gDebugAIFlags;
return;
}
#endif
if (IsWildMonSmart() && !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_TRAINER)))
{

View File

@ -517,9 +517,7 @@ static void CB2_InitBattleInternal(void)
gBattle_BG3_X = 0;
gBattle_BG3_Y = 0;
#if DEBUG_OVERWORLD_MENU == TRUE
if (!gIsDebugBattle)
#endif
if (!DEBUG_OVERWORLD_MENU || (DEBUG_OVERWORLD_MENU && !gIsDebugBattle))
{
gBattleTerrain = BattleSetup_GetTerrainId();
}
@ -552,9 +550,7 @@ static void CB2_InitBattleInternal(void)
else
SetMainCallback2(CB2_HandleStartBattle);
#if DEBUG_OVERWORLD_MENU == TRUE
if (!gIsDebugBattle)
#endif
if (!DEBUG_OVERWORLD_MENU || (DEBUG_OVERWORLD_MENU && !gIsDebugBattle))
{
if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED)))
{

View File

@ -68,7 +68,6 @@
#include "constants/weather.h"
#include "save.h"
#if DEBUG_OVERWORLD_MENU == TRUE
// *******************************
enum DebugMenu
{
@ -5129,5 +5128,3 @@ static void DebugAction_Util_CheckEWRAMCounters(u8 taskId)
{
Debug_DestroyMenu_Full_Script(taskId, Debug_EventScript_EWRAMCounters);
}
#endif //DEBUG_OVERWORLD_MENU == TRUE

View File

@ -135,13 +135,14 @@ void FieldGetPlayerInput(struct FieldInput *input, u16 newKeys, u16 heldKeys)
else if (heldKeys & DPAD_RIGHT)
input->dpadDirection = DIR_EAST;
#if DEBUG_OVERWORLD_MENU == TRUE && DEBUG_OVERWORLD_IN_MENU == FALSE
if ((heldKeys & DEBUG_OVERWORLD_HELD_KEYS) && input->DEBUG_OVERWORLD_TRIGGER_EVENT)
if(DEBUG_OVERWORLD_MENU && !DEBUG_OVERWORLD_IN_MENU)
{
input->input_field_1_2 = TRUE;
input->DEBUG_OVERWORLD_TRIGGER_EVENT = FALSE;
if ((heldKeys & DEBUG_OVERWORLD_HELD_KEYS) && input->DEBUG_OVERWORLD_TRIGGER_EVENT)
{
input->input_field_1_2 = TRUE;
input->DEBUG_OVERWORLD_TRIGGER_EVENT = FALSE;
}
}
#endif
}
int ProcessPlayerFieldInput(struct FieldInput *input)
@ -201,15 +202,13 @@ int ProcessPlayerFieldInput(struct FieldInput *input)
if (input->pressedSelectButton && UseRegisteredKeyItemOnField() == TRUE)
return TRUE;
#if DEBUG_OVERWORLD_MENU == TRUE && DEBUG_OVERWORLD_IN_MENU == FALSE
if (input->input_field_1_2)
if(input->input_field_1_2 && DEBUG_OVERWORLD_MENU && !DEBUG_OVERWORLD_IN_MENU)
{
PlaySE(SE_WIN_OPEN);
FreezeObjectEvents();
Debug_ShowMainMenu();
return TRUE;
}
#endif
return FALSE;
}

View File

@ -762,7 +762,7 @@ static void rfu_CB_pollConnectParent(u8 reqCommand, u16 reqResult)
u16 id;
u8 slot;
u8 bm_slot_flag, i;
struct RfuTgtData *target_p;
struct RfuTgtData *target_p = NULL;
struct RfuTgtData target_local;
if (reqResult == 0)

View File

@ -41,7 +41,6 @@
#include "constants/items.h"
#include "constants/event_objects.h"
#if DEBUG_POKEMON_SPRITE_VISUALIZER == TRUE
extern const struct BattleBackground sBattleTerrainTable[];
extern const struct CompressedSpriteSheet gSpriteSheet_EnemyShadow;
extern const struct SpriteTemplate gSpriteTemplate_EnemyShadow;
@ -1763,5 +1762,3 @@ static void Exit_PokemonSpriteVisualizer(u8 taskId)
m4aMPlayVolumeControl(&gMPlayInfo_BGM, TRACKS_ALL, 0x100);
}
}
#endif

View File

@ -1640,15 +1640,13 @@ static void Task_HandleInput(u8 taskId)
PlaySE(SE_SELECT);
BeginCloseSummaryScreen(taskId);
}
#if DEBUG_POKEMON_SPRITE_VISUALIZER == TRUE
else if (JOY_NEW(SELECT_BUTTON) && !gMain.inBattle)
else if (DEBUG_POKEMON_SPRITE_VISUALIZER && JOY_NEW(SELECT_BUTTON) && !gMain.inBattle)
{
sMonSummaryScreen->callback = CB2_Pokemon_Sprite_Visualizer;
StopPokemonAnimations();
PlaySE(SE_SELECT);
CloseSummaryScreen(taskId);
}
#endif
}
}

View File

@ -784,10 +784,11 @@ static bool8 StartMenuDebugCallback(void)
RemoveExtraStartMenuWindows();
HideStartMenuDebug(); // Hide start menu without enabling movement
#if DEBUG_OVERWORLD_MENU == TRUE
FreezeObjectEvents();
Debug_ShowMainMenu();
#endif
if (DEBUG_OVERWORLD_MENU)
{
FreezeObjectEvents();
Debug_ShowMainMenu();
}
return TRUE;
}